1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2016 The Qt Company Ltd. 4 ** Contact: https://www.qt.io/licensing/ 5 ** 6 ** This file is part of the Qt Designer of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see https://www.qt.io/terms-conditions. For further 15 ** information use the contact form at https://www.qt.io/contact-us. 16 ** 17 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 // 30 // W A R N I N G 31 // ------------- 32 // 33 // This file is not part of the Qt API. It exists for the convenience 34 // of Qt Designer. This header 35 // file may change from version to version without notice, or even be removed. 36 // 37 // We mean it. 38 // 39 40 #ifndef OBJECTINSPECTORMODEL_H 41 #define OBJECTINSPECTORMODEL_H 42 43 #include <layoutinfo_p.h> 44 45 #include <QtGui/qstandarditemmodel.h> 46 #include <QtGui/qicon.h> 47 #include <QtCore/qstring.h> 48 #include <QtCore/qlist.h> 49 #include <QtCore/qmap.h> 50 #include <QtCore/qpointer.h> 51 #include <QtCore/qvector.h> 52 53 QT_BEGIN_NAMESPACE 54 55 class QDesignerFormWindowInterface; 56 57 namespace qdesigner_internal { 58 59 // Data structure containing the fixed item type icons 60 struct ObjectInspectorIcons { 61 QIcon layoutIcons[LayoutInfo::UnknownLayout + 1]; 62 }; 63 64 struct ModelRecursionContext; 65 66 // Data structure representing one item of the object inspector. 67 class ObjectData { 68 public: 69 enum Type { 70 Object, 71 Action, 72 SeparatorAction, 73 ChildWidget, // A child widget 74 LayoutableContainer, // A container that can be laid out 75 LayoutWidget, // A QLayoutWidget 76 ExtensionContainer // QTabWidget and the like, container extension 77 }; 78 79 using StandardItemList = QList<QStandardItem *>; 80 81 explicit ObjectData(QObject *parent, QObject *object, const ModelRecursionContext &ctx); 82 ObjectData(); 83 type()84 inline Type type() const { return m_type; } object()85 inline QObject *object() const { return m_object; } parent()86 inline QObject *parent() const { return m_parent; } objectName()87 inline QString objectName() const { return m_objectName; } 88 89 bool equals(const ObjectData & me) const; 90 91 enum ChangedMask { ClassNameChanged = 1, ObjectNameChanged = 2, 92 ClassIconChanged = 4, TypeChanged = 8, 93 LayoutTypeChanged = 16}; 94 95 unsigned compare(const ObjectData & me) const; 96 97 // Initially set up a row 98 void setItems(const StandardItemList &row, const ObjectInspectorIcons &icons) const; 99 // Update row data according to change mask 100 void setItemsDisplayData(const StandardItemList &row, const ObjectInspectorIcons &icons, unsigned mask) const; 101 102 private: 103 void initObject(const ModelRecursionContext &ctx); 104 void initWidget(QWidget *w, const ModelRecursionContext &ctx); 105 106 QObject *m_parent = nullptr; 107 QObject *m_object = nullptr; 108 Type m_type = Object; 109 QString m_className; 110 QString m_objectName; 111 QIcon m_classIcon; 112 LayoutInfo::Type m_managedLayoutType = LayoutInfo::NoLayout; 113 }; 114 115 inline bool operator==(const ObjectData &e1, const ObjectData &e2) { return e1.equals(e2); } 116 inline bool operator!=(const ObjectData &e1, const ObjectData &e2) { return !e1.equals(e2); } 117 118 using ObjectModel = QVector<ObjectData>; 119 120 // QStandardItemModel for ObjectInspector. Uses ObjectData/ObjectModel 121 // internally for its updates. 122 class ObjectInspectorModel : public QStandardItemModel { 123 public: 124 using StandardItemList = QList<QStandardItem *>; 125 enum { ObjectNameColumn, ClassNameColumn, NumColumns }; 126 127 explicit ObjectInspectorModel(QObject *parent); 128 129 enum UpdateResult { NoForm, Rebuilt, Updated }; 130 UpdateResult update(QDesignerFormWindowInterface *fw); 131 indexesOf(QObject * o)132 const QModelIndexList indexesOf(QObject *o) const { return m_objectIndexMultiMap.values(o); } 133 QObject *objectAt(const QModelIndex &index) const; 134 135 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; 136 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override; 137 138 private: 139 typedef QMultiMap<QObject *,QModelIndex> ObjectIndexMultiMap; 140 141 void rebuild(const ObjectModel &newModel); 142 void updateItemContents(ObjectModel &oldModel, const ObjectModel &newModel); 143 void clearItems(); 144 StandardItemList rowAt(QModelIndex index) const; 145 146 ObjectInspectorIcons m_icons; 147 ObjectIndexMultiMap m_objectIndexMultiMap; 148 ObjectModel m_model; 149 QPointer<QDesignerFormWindowInterface> m_formWindow; 150 }; 151 } // namespace qdesigner_internal 152 153 #endif // OBJECTINSPECTORMODEL_H 154 155 QT_END_NAMESPACE 156