1 /* This file is part of the KDE project 2 Copyright (C) 2003 Lucijan Busch <lucijan@gmx.at> 3 Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr> 4 Copyright (C) 2006-2010 Jarosław Staniek <staniek@kde.org> 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Library General Public 8 License as published by the Free Software Foundation; either 9 version 2 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Library General Public License for more details. 15 16 You should have received a copy of the GNU Library General Public License 17 along with this library; see the file COPYING.LIB. If not, write to 18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 19 * Boston, MA 02110-1301, USA. 20 */ 21 22 #ifndef KFORMDESIGNEROBJECTTREE_H 23 #define KFORMDESIGNEROBJECTTREE_H 24 25 #include "kformdesigner_export.h" 26 #include "container.h" 27 28 #include <QList> 29 #include <QHash> 30 #include <QVariant> 31 #include <QString> 32 #include <QByteArray> 33 34 class QWidget; 35 class QDomElement; 36 37 namespace KFormDesigner 38 { 39 40 class ObjectTreeItem; 41 42 //! @short An list of ObjectTreeItem pointers. 43 typedef QList<ObjectTreeItem*> ObjectTreeList; 44 45 //! @short A QString-based disctionary of ObjectTreeItem pointers. 46 typedef QHash<QString, ObjectTreeItem*> ObjectTreeHash; 47 48 /*! 49 @short An item representing a widget 50 Holds the properties of a widget (classname, name, parent, children ..). 51 */ 52 class KFORMDESIGNER_EXPORT ObjectTreeItem 53 { 54 public: 55 ObjectTreeItem(const QString &className, const QString &name, QWidget *widget, Container *parentContainer, Container *container = 0); 56 virtual ~ObjectTreeItem(); 57 58 QString name() const; 59 QString className() const; 60 QWidget* widget() const; 61 EventEater* eventEater() const; 62 ObjectTreeItem* parent() const; 63 ObjectTreeList* children(); 64 65 /*! \return a QHash<QString, QVariant> of all modified properties for this widget. 66 The QVariant is the old value (ie first value) of the property whose name is the QString. */ 67 const QHash<QString, QVariant>* modifiedProperties() const; 68 69 //! \return the widget's Container, or 0 if the widget is not a Container. 70 Container* container() const; 71 72 void setWidget(QWidget *w); 73 void setParent(ObjectTreeItem *parent); 74 75 void debug(int ident); 76 void rename(const QString &name); 77 78 void addChild(ObjectTreeItem *it); 79 void removeChild(ObjectTreeItem *it); 80 81 /*! Adds \a property in the list of the modified properties for this object. 82 These modified properties are written in the .ui files when saving the form. 83 */ 84 void addModifiedProperty(const QByteArray &property, const QVariant &oldValue); 85 void storeUnknownProperty(QDomElement &el); 86 87 /*! Adds subproperty \a property value \a value (a property of subwidget). 88 Remembering it for delayed setting is needed because on loading 89 the subwidget could be not created yet (true e.g. for KexiDBAutoField). */ 90 void addSubproperty(const QByteArray &property, const QVariant& value); 91 92 /*! \return subproperties for this item, added by addSubproperty() 93 or 0 is there are no subproperties. */ 94 QHash<QString, QVariant>* subproperties() const; 95 96 void setPixmapName(const QByteArray &property, const QString &name); 97 QString pixmapName(const QByteArray &property); 98 99 void setEnabled(bool enabled); 100 bool isEnabled() const; 101 102 int gridRow() const; 103 int gridCol() const; 104 int gridRowSpan() const; 105 int gridColSpan() const; 106 bool spanMultipleCells() const; 107 void setGridPos(int row, int col, int rowspan, int colspan); 108 QString unknownProperties(); 109 void setUnknownProperties(const QString& set); 110 private: 111 class Private; 112 113 Private* const d; 114 friend class ObjectTree; 115 friend class FormIO; 116 }; 117 118 /*! @short Represents all the objects available within a form. 119 This class holds ObjectTreeItem for each widget in a Form. */ 120 class KFORMDESIGNER_EXPORT ObjectTree : public ObjectTreeItem 121 { 122 public: 123 ObjectTree(const QString &className = QString(), const QString &name = QString(), 124 QWidget *widget = 0, Container *container = 0); 125 virtual ~ObjectTree(); 126 127 /*! Renames the item named \a oldname to \a newname. \return false if widget named \a newname 128 already exists and renaming failed. */ 129 bool rename(const QString &oldname, const QString &newname); 130 /*! Sets \a newparent as new parent for the item whose name is \a name. */ 131 bool reparent(const QString &name, const QString &newparent); 132 133 /*! \return the ObjectTreeItem named \a name, or 0 if doesn't exist. */ 134 ObjectTreeItem* lookup(const QString &name); 135 136 /*! \return a hash containing all ObjectTreeItem in this ObjectTree. */ 137 ObjectTreeHash* hash(); 138 139 void addItem(ObjectTreeItem *parent, ObjectTreeItem *c); 140 void removeItem(const QString &name); 141 void removeItem(ObjectTreeItem *c); 142 143 /*! Generates a new, unique name for a new widget using prefix \a prefix 144 (e.g. if \a prefix is "lineEdit", "lineEdit1" is returned). 145 \a prefix must be a valid identifier. 146 If \a numberSuffixRequired is true (the default) a number suffix is mandatory. 147 If \a numberSuffixRequired is false and there's a widget prefix \a prefix, 148 then \a prefix is returned (e.g. if \a prefix is "lineEdit", and "lineEdit" doesn't exist yet, 149 "lineEdit" is returned). */ 150 QByteArray generateUniqueName(const QByteArray &prefix, bool numberSuffixRequired = true); 151 152 private: 153 class Private; 154 155 Private* const d; 156 }; 157 158 } 159 160 #endif 161