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 | #ifndef PROPERTYEDITOR_H |
30 | #define PROPERTYEDITOR_H |
31 | |
32 | #include "propertyeditor_global.h" |
33 | #include <qdesigner_propertyeditor_p.h> |
34 | |
35 | #include <QtCore/qpointer.h> |
36 | #include <QtCore/qmap.h> |
37 | #include <QtCore/qvector.h> |
38 | #include <QtCore/qset.h> |
39 | |
40 | QT_BEGIN_NAMESPACE |
41 | |
42 | class DomProperty; |
43 | class QDesignerMetaDataBaseItemInterface; |
44 | class QDesignerPropertySheetExtension; |
45 | class QLineEdit; |
46 | |
47 | class QtAbstractPropertyBrowser; |
48 | class QtButtonPropertyBrowser; |
49 | class QtTreePropertyBrowser; |
50 | class QtProperty; |
51 | class QtVariantProperty; |
52 | class QtBrowserItem; |
53 | class QStackedWidget; |
54 | |
55 | namespace qdesigner_internal { |
56 | |
57 | class StringProperty; |
58 | class DesignerPropertyManager; |
59 | class DesignerEditorFactory; |
60 | class ElidingLabel; |
61 | |
62 | class QT_PROPERTYEDITOR_EXPORT PropertyEditor: public QDesignerPropertyEditor |
63 | { |
64 | Q_OBJECT |
65 | public: |
66 | explicit PropertyEditor(QDesignerFormEditorInterface *core, QWidget *parent = nullptr, Qt::WindowFlags flags = {}); |
67 | ~PropertyEditor() override; |
68 | |
69 | QDesignerFormEditorInterface *core() const override; |
70 | |
71 | bool isReadOnly() const override; |
72 | void setReadOnly(bool readOnly) override; |
73 | void setPropertyValue(const QString &name, const QVariant &value, bool changed = true) override; |
74 | void updatePropertySheet() override; |
75 | |
76 | void setObject(QObject *object) override; |
77 | |
78 | void reloadResourceProperties() override; |
79 | |
80 | QObject *object() const override |
81 | { return m_object; } |
82 | |
83 | QString currentPropertyName() const override; |
84 | |
85 | protected: |
86 | |
87 | bool event(QEvent *event) override; |
88 | |
89 | private slots: |
90 | void slotResetProperty(QtProperty *property); |
91 | void slotValueChanged(QtProperty *property, const QVariant &value, bool enableSubPropertyHandling); |
92 | void slotViewTriggered(QAction *action); |
93 | void slotAddDynamicProperty(QAction *action); |
94 | void slotRemoveDynamicProperty(); |
95 | void slotSorting(bool sort); |
96 | void slotColoring(bool color); |
97 | void slotCurrentItemChanged(QtBrowserItem*); |
98 | void setFilter(const QString &pattern); |
99 | |
100 | private: |
101 | void updateBrowserValue(QtVariantProperty *property, const QVariant &value); |
102 | void updateToolBarLabel(); |
103 | int toBrowserType(const QVariant &value, const QString &propertyName) const; |
104 | QString removeScope(const QString &value) const; |
105 | QDesignerMetaDataBaseItemInterface *metaDataBaseItem() const; |
106 | void setupStringProperty(QtVariantProperty *property, bool isMainContainer); |
107 | void setupPaletteProperty(QtVariantProperty *property); |
108 | QString realClassName(QObject *object) const; |
109 | void storeExpansionState(); |
110 | void applyExpansionState(); |
111 | void storePropertiesExpansionState(const QList<QtBrowserItem *> &items); |
112 | void applyPropertiesExpansionState(const QList<QtBrowserItem *> &items); |
113 | void applyFilter(); |
114 | int applyPropertiesFilter(const QList<QtBrowserItem *> &items); |
115 | void setExpanded(QtBrowserItem *item, bool expanded); |
116 | bool isExpanded(QtBrowserItem *item) const; |
117 | void setItemVisible(QtBrowserItem *item, bool visible); |
118 | bool isItemVisible(QtBrowserItem *item) const; |
119 | void collapseAll(); |
120 | void clearView(); |
121 | void fillView(); |
122 | bool isLayoutGroup(QtProperty *group) const; |
123 | void updateColors(); |
124 | void updateForegroundBrightness(); |
125 | QColor propertyColor(QtProperty *property) const; |
126 | void updateActionsState(); |
127 | QtBrowserItem *nonFakePropertyBrowserItem(QtBrowserItem *item) const; |
128 | void saveSettings() const; |
129 | void editProperty(const QString &name); |
130 | bool isDynamicProperty(const QtBrowserItem* item) const; |
131 | |
132 | struct Strings { |
133 | Strings(); |
134 | QSet<QString> m_alignmentProperties; |
135 | const QString m_fontProperty; |
136 | const QString m_qLayoutWidget; |
137 | const QString m_designerPrefix; |
138 | const QString m_layout; |
139 | const QString m_validationModeAttribute; |
140 | const QString m_fontAttribute; |
141 | const QString m_superPaletteAttribute; |
142 | const QString m_enumNamesAttribute; |
143 | const QString m_resettableAttribute; |
144 | const QString m_flagsAttribute; |
145 | }; |
146 | |
147 | const Strings m_strings; |
148 | QDesignerFormEditorInterface *m_core; |
149 | QDesignerPropertySheetExtension *m_propertySheet = nullptr; |
150 | QtAbstractPropertyBrowser *m_currentBrowser = nullptr; |
151 | QtButtonPropertyBrowser *m_buttonBrowser; |
152 | QtTreePropertyBrowser *m_treeBrowser = nullptr; |
153 | DesignerPropertyManager *m_propertyManager; |
154 | DesignerEditorFactory *m_treeFactory; |
155 | DesignerEditorFactory *m_groupFactory; |
156 | QPointer<QObject> m_object; |
157 | QMap<QString, QtVariantProperty*> m_nameToProperty; |
158 | QMap<QtProperty*, QString> m_propertyToGroup; |
159 | QMap<QString, QtVariantProperty*> m_nameToGroup; |
160 | QList<QtProperty *> m_groups; |
161 | QtProperty *m_dynamicGroup = nullptr; |
162 | QString m_recentlyAddedDynamicProperty; |
163 | bool m_updatingBrowser = false; |
164 | |
165 | QStackedWidget *m_stackedWidget; |
166 | QLineEdit *m_filterWidget; |
167 | int m_buttonIndex = -1; |
168 | int m_treeIndex = -1; |
169 | QAction *m_addDynamicAction; |
170 | QAction *m_removeDynamicAction; |
171 | QAction *m_sortingAction; |
172 | QAction *m_coloringAction; |
173 | QAction *m_treeAction; |
174 | QAction *m_buttonAction; |
175 | ElidingLabel *m_classLabel; |
176 | |
177 | bool m_sorting = false; |
178 | bool m_coloring = false; |
179 | |
180 | QMap<QString, bool> m_expansionState; |
181 | |
182 | QString m_filterPattern; |
183 | QVector<QPair<QColor, QColor> > m_colors; |
184 | QPair<QColor, QColor> m_dynamicColor; |
185 | QPair<QColor, QColor> m_layoutColor; |
186 | |
187 | bool m_brightness = false; |
188 | }; |
189 | |
190 | } // namespace qdesigner_internal |
191 | |
192 | QT_END_NAMESPACE |
193 | |
194 | #endif // PROPERTYEDITOR_H |
195 | |