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 ITEMLISTEDITOR_H |
30 | #define ITEMLISTEDITOR_H |
31 | |
32 | #include "ui_itemlisteditor.h" |
33 | |
34 | #include <QtWidgets/qdialog.h> |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | class QDesignerFormWindowInterface; |
39 | class QtProperty; |
40 | class QtVariantProperty; |
41 | class QtTreePropertyBrowser; |
42 | class QSplitter; |
43 | class QVBoxLayout; |
44 | |
45 | namespace qdesigner_internal { |
46 | |
47 | class DesignerIconCache; |
48 | class DesignerPropertyManager; |
49 | class DesignerEditorFactory; |
50 | |
51 | // Utility class that ensures a bool is true while in scope. |
52 | // Courtesy of QBoolBlocker in qobject_p.h |
53 | class BoolBlocker |
54 | { |
55 | public: |
56 | inline BoolBlocker(bool &b):block(b), reset(b){block = true;} |
57 | inline ~BoolBlocker(){block = reset; } |
58 | private: |
59 | bool █ |
60 | bool reset; |
61 | }; |
62 | |
63 | class AbstractItemEditor: public QWidget |
64 | { |
65 | Q_OBJECT |
66 | |
67 | public: |
68 | explicit AbstractItemEditor(QDesignerFormWindowInterface *form, QWidget *parent); |
69 | ~AbstractItemEditor(); |
70 | |
71 | DesignerIconCache *iconCache() const { return m_iconCache; } |
72 | |
73 | struct PropertyDefinition { |
74 | int role; |
75 | int type; |
76 | int (*typeFunc)(); |
77 | const char *name; |
78 | }; |
79 | |
80 | public slots: |
81 | void cacheReloaded(); |
82 | |
83 | private slots: |
84 | void propertyChanged(QtProperty *property); |
85 | void resetProperty(QtProperty *property); |
86 | |
87 | protected: |
88 | virtual int defaultItemFlags() const = 0; |
89 | void setupProperties(const PropertyDefinition *propList, |
90 | Qt::Alignment alignDefault = Qt::AlignLeading | Qt::AlignVCenter); |
91 | void setupObject(QWidget *object); |
92 | void setupEditor(QWidget *object, const PropertyDefinition *propDefs, |
93 | Qt::Alignment alignDefault = Qt::AlignLeading | Qt::AlignVCenter); |
94 | void injectPropertyBrowser(QWidget *parent, QWidget *widget); |
95 | void updateBrowser(); |
96 | virtual void setItemData(int role, const QVariant &v) = 0; |
97 | virtual QVariant getItemData(int role) const = 0; |
98 | |
99 | DesignerIconCache *m_iconCache; |
100 | DesignerPropertyManager *m_propertyManager; |
101 | DesignerEditorFactory *m_editorFactory; |
102 | QSplitter *m_propertySplitter = nullptr; |
103 | QtTreePropertyBrowser *m_propertyBrowser; |
104 | QList<QtVariantProperty*> m_properties; |
105 | QList<QtVariantProperty*> m_rootProperties; |
106 | QHash<QtVariantProperty*, int> m_propertyToRole; |
107 | bool m_updatingBrowser = false; |
108 | }; |
109 | |
110 | class ItemListEditor: public AbstractItemEditor |
111 | { |
112 | Q_OBJECT |
113 | |
114 | public: |
115 | explicit ItemListEditor(QDesignerFormWindowInterface *form, QWidget *parent); |
116 | |
117 | void setupEditor(QWidget *object, const PropertyDefinition *propDefs, |
118 | Qt::Alignment alignDefault = Qt::AlignLeading | Qt::AlignVCenter); |
119 | QListWidget *listWidget() const { return ui.listWidget; } |
120 | void setNewItemText(const QString &tpl) { m_newItemText = tpl; } |
121 | QString newItemText() const { return m_newItemText; } |
122 | void setCurrentIndex(int idx); |
123 | |
124 | uint alignDefault() const; |
125 | void setAlignDefault(uint newAlignDefault); |
126 | |
127 | signals: |
128 | void indexChanged(int idx); |
129 | void itemChanged(int idx, int role, const QVariant &v); |
130 | void itemInserted(int idx); |
131 | void itemDeleted(int idx); |
132 | void itemMovedUp(int idx); |
133 | void itemMovedDown(int idx); |
134 | |
135 | private slots: |
136 | void on_newListItemButton_clicked(); |
137 | void on_deleteListItemButton_clicked(); |
138 | void on_moveListItemUpButton_clicked(); |
139 | void on_moveListItemDownButton_clicked(); |
140 | void on_listWidget_currentRowChanged(); |
141 | void on_listWidget_itemChanged(QListWidgetItem * item); |
142 | void togglePropertyBrowser(); |
143 | void cacheReloaded(); |
144 | |
145 | protected: |
146 | void setItemData(int role, const QVariant &v) override; |
147 | QVariant getItemData(int role) const override; |
148 | int defaultItemFlags() const override; |
149 | |
150 | private: |
151 | void setPropertyBrowserVisible(bool v); |
152 | void updateEditor(); |
153 | Ui::ItemListEditor ui; |
154 | uint m_alignDefault = 0; |
155 | bool m_updating; |
156 | QString m_newItemText; |
157 | }; |
158 | |
159 | } // namespace qdesigner_internal |
160 | |
161 | QT_END_NAMESPACE |
162 | |
163 | #endif // ITEMLISTEDITOR_H |
164 | |