File indexing completed on 2024-05-12 16:39:50
0001 /* This file is part of the KDE project 0002 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at> 0003 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> 0004 Copyright (C) 2006-2010 Jarosław Staniek <staniek@kde.org> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Library General Public 0008 License as published by the Free Software Foundation; either 0009 version 2 of the License, or (at your option) any later version. 0010 0011 This library is distributed in the hope that it will be useful, 0012 but WITHOUT ANY WARRANTY; without even the implied warranty of 0013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0014 Library General Public License for more details. 0015 0016 You should have received a copy of the GNU Library General Public License 0017 along with this library; see the file COPYING.LIB. If not, write to 0018 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0019 * Boston, MA 02110-1301, USA. 0020 */ 0021 0022 #ifndef KFORMDESIGNEROBJECTTREE_H 0023 #define KFORMDESIGNEROBJECTTREE_H 0024 0025 #include "kformdesigner_export.h" 0026 #include "container.h" 0027 0028 #include <QList> 0029 #include <QHash> 0030 #include <QVariant> 0031 #include <QString> 0032 #include <QByteArray> 0033 0034 class QWidget; 0035 class QDomElement; 0036 0037 namespace KFormDesigner 0038 { 0039 0040 class ObjectTreeItem; 0041 0042 //! @short An list of ObjectTreeItem pointers. 0043 typedef QList<ObjectTreeItem*> ObjectTreeList; 0044 0045 //! @short A QString-based disctionary of ObjectTreeItem pointers. 0046 typedef QHash<QString, ObjectTreeItem*> ObjectTreeHash; 0047 0048 /*! 0049 @short An item representing a widget 0050 Holds the properties of a widget (classname, name, parent, children ..). 0051 */ 0052 class KFORMDESIGNER_EXPORT ObjectTreeItem 0053 { 0054 public: 0055 ObjectTreeItem(const QString &className, const QString &name, QWidget *widget, Container *parentContainer, Container *container = 0); 0056 virtual ~ObjectTreeItem(); 0057 0058 QString name() const; 0059 QString className() const; 0060 QWidget* widget() const; 0061 EventEater* eventEater() const; 0062 ObjectTreeItem* parent() const; 0063 ObjectTreeList* children(); 0064 0065 /*! \return a QHash<QString, QVariant> of all modified properties for this widget. 0066 The QVariant is the old value (ie first value) of the property whose name is the QString. */ 0067 const QHash<QString, QVariant>* modifiedProperties() const; 0068 0069 //! \return the widget's Container, or 0 if the widget is not a Container. 0070 Container* container() const; 0071 0072 void setWidget(QWidget *w); 0073 void setParent(ObjectTreeItem *parent); 0074 0075 void debug(int ident); 0076 void rename(const QString &name); 0077 0078 void addChild(ObjectTreeItem *it); 0079 void removeChild(ObjectTreeItem *it); 0080 0081 /*! Adds \a property in the list of the modified properties for this object. 0082 These modified properties are written in the .ui files when saving the form. 0083 */ 0084 void addModifiedProperty(const QByteArray &property, const QVariant &oldValue); 0085 void storeUnknownProperty(QDomElement &el); 0086 0087 /*! Adds subproperty \a property value \a value (a property of subwidget). 0088 Remembering it for delayed setting is needed because on loading 0089 the subwidget could be not created yet (true e.g. for KexiDBAutoField). */ 0090 void addSubproperty(const QByteArray &property, const QVariant& value); 0091 0092 /*! \return subproperties for this item, added by addSubproperty() 0093 or 0 is there are no subproperties. */ 0094 QHash<QString, QVariant>* subproperties() const; 0095 0096 void setPixmapName(const QByteArray &property, const QString &name); 0097 QString pixmapName(const QByteArray &property); 0098 0099 void setEnabled(bool enabled); 0100 bool isEnabled() const; 0101 0102 int gridRow() const; 0103 int gridCol() const; 0104 int gridRowSpan() const; 0105 int gridColSpan() const; 0106 bool spanMultipleCells() const; 0107 void setGridPos(int row, int col, int rowspan, int colspan); 0108 QString unknownProperties(); 0109 void setUnknownProperties(const QString& set); 0110 private: 0111 class Private; 0112 0113 Private* const d; 0114 friend class ObjectTree; 0115 friend class FormIO; 0116 }; 0117 0118 /*! @short Represents all the objects available within a form. 0119 This class holds ObjectTreeItem for each widget in a Form. */ 0120 class KFORMDESIGNER_EXPORT ObjectTree : public ObjectTreeItem 0121 { 0122 public: 0123 ObjectTree(const QString &className = QString(), const QString &name = QString(), 0124 QWidget *widget = 0, Container *container = 0); 0125 virtual ~ObjectTree(); 0126 0127 /*! Renames the item named \a oldname to \a newname. \return false if widget named \a newname 0128 already exists and renaming failed. */ 0129 bool rename(const QString &oldname, const QString &newname); 0130 /*! Sets \a newparent as new parent for the item whose name is \a name. */ 0131 bool reparent(const QString &name, const QString &newparent); 0132 0133 /*! \return the ObjectTreeItem named \a name, or 0 if doesn't exist. */ 0134 ObjectTreeItem* lookup(const QString &name); 0135 0136 /*! \return a hash containing all ObjectTreeItem in this ObjectTree. */ 0137 ObjectTreeHash* hash(); 0138 0139 void addItem(ObjectTreeItem *parent, ObjectTreeItem *c); 0140 void removeItem(const QString &name); 0141 void removeItem(ObjectTreeItem *c); 0142 0143 /*! Generates a new, unique name for a new widget using prefix \a prefix 0144 (e.g. if \a prefix is "lineEdit", "lineEdit1" is returned). 0145 \a prefix must be a valid identifier. 0146 If \a numberSuffixRequired is true (the default) a number suffix is mandatory. 0147 If \a numberSuffixRequired is false and there's a widget prefix \a prefix, 0148 then \a prefix is returned (e.g. if \a prefix is "lineEdit", and "lineEdit" doesn't exist yet, 0149 "lineEdit" is returned). */ 0150 QByteArray generateUniqueName(const QByteArray &prefix, bool numberSuffixRequired = true); 0151 0152 private: 0153 class Private; 0154 0155 Private* const d; 0156 }; 0157 0158 } 0159 0160 #endif