Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qdesigner_propertycommand_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists for the convenience
9// of Qt Designer. This header
10// file may change from version to version without notice, or even be removed.
11//
12// We mean it.
13//
14
15#ifndef QDESIGNER_PROPERTYCOMMAND_H
16#define QDESIGNER_PROPERTYCOMMAND_H
17
19
20#include <QtCore/qvariant.h>
21#include <QtCore/qhash.h>
22#include <QtCore/qlist.h>
23#include <QtCore/qpair.h>
24#include <QtCore/qpointer.h>
25#include <QtCore/qsharedpointer.h>
26
28
29class QDesignerFormWindowInterface;
31class QDesignerIntegration;
32
33namespace qdesigner_internal {
34
40
41//Determine special property
42enum SpecialProperty getSpecialProperty(const QString& propertyName);
43
44// A helper class for applying properties to objects.
45// Can be used for Set commands (setValue(), restoreOldValue()) or
46// Reset Commands restoreDefaultValue(), restoreOldValue()).
47//
50public:
51 // A pair of Value and changed flag
52 using Value = std::pair<QVariant, bool>;
53
55
56 PropertyHelper(QObject* object,
57 SpecialProperty specialProperty,
59 int index);
60 virtual ~PropertyHelper() = default;
61
62 QObject *object() const { return m_object; }
63 SpecialProperty specialProperty() const { return m_specialProperty; }
64 // set a new value. Can be overwritten to perform a transformation (see
65 // handling of Arrow key move in FormWindow class).
66 virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value,
67 bool changed, quint64 subPropertyMask);
68
69 // restore old value
70 Value restoreOldValue(QDesignerFormWindowInterface *fw);
71 // set default value
72 Value restoreDefaultValue(QDesignerFormWindowInterface *fw);
73
74 inline QVariant oldValue() const
75 { return m_oldValue.first; }
76
77 inline void setOldValue(const QVariant &oldValue)
78 { m_oldValue.first = oldValue; }
79
80 // required updates for this property (bit mask)
82 unsigned updateMask() const;
83
84 // can be merged into one command (that is, object and name match)
85 bool canMerge(const PropertyHelper &other) const;
86 QDesignerIntegration *integration(QDesignerFormWindowInterface *fw) const;
87
88 static void triggerActionChanged(QAction *a);
89
90private:
91 // Apply the value and update. Returns corrected value
93
94 static void checkApplyWidgetValue(QDesignerFormWindowInterface *fw, QWidget* w,
95 SpecialProperty specialProperty, QVariant &v);
96
97 void updateObject(QDesignerFormWindowInterface *fw, const QVariant &oldValue, const QVariant &newValue);
98 QVariant findDefaultValue(QDesignerFormWindowInterface *fw) const;
99 void ensureUniqueObjectName(QDesignerFormWindowInterface *fw, QObject *object) const;
100 SpecialProperty m_specialProperty;
101
102 QPointer<QObject> m_object;
103 ObjectType m_objectType;
104 QPointer<QWidget> m_parentWidget;
105
106 QDesignerPropertySheetExtension *m_propertySheet;
107 int m_index;
108
109 Value m_oldValue;
110};
111
112// Base class for commands that can be applied to several widgets
113
114class QDESIGNER_SHARED_EXPORT PropertyListCommand : public QDesignerFormWindowCommand {
115public:
116 explicit PropertyListCommand(QDesignerFormWindowInterface *formWindow, QUndoCommand *parent = nullptr);
117
118 QObject* object(int index = 0) const;
119
120 QVariant oldValue(int index = 0) const;
121
122 void setOldValue(const QVariant &oldValue, int index = 0);
123
124 // Calls restoreDefaultValue() and update()
125 void undo() override;
126
127protected:
128 using PropertyHelperPtr = std::unique_ptr<PropertyHelper>;
129 using PropertyHelperList = std::vector<PropertyHelperPtr>;
130
131 // add an object
132 bool add(QObject *object, const QString &propertyName);
133
134 // Init from a list and make sure referenceObject is added first to obtain the right property group
135 bool initList(const QObjectList &list, const QString &apropertyName, QObject *referenceObject = nullptr);
136
137 // set a new value, return update mask
138 unsigned setValue(const QVariant &value, bool changed, quint64 subPropertyMask);
139
140 // restore old value, return update mask
141 unsigned restoreOldValue();
142 // set default value, return update mask
143 unsigned restoreDefaultValue();
144
145 // update designer
146 void update(unsigned updateMask);
147
148 // check if lists are aequivalent for command merging (same widgets and props)
149 bool canMergeLists(const PropertyHelperList& other) const;
150
151 PropertyHelperList& propertyHelperList() { return m_propertyHelperList; }
152 const PropertyHelperList& propertyHelperList() const { return m_propertyHelperList; }
153
154 const QString propertyName() const;
155 SpecialProperty specialProperty() const;
156
157 // Helper struct describing a property used for checking whether
158 // properties of different widgets are equivalent
159 struct PropertyDescription {
160 public:
161 PropertyDescription() = default;
162 PropertyDescription(const QString &propertyName, QDesignerPropertySheetExtension *propertySheet, int index);
163 bool equals(const PropertyDescription &p) const;
164 void debug() const;
165
166 QString m_propertyName;
167 QString m_propertyGroup;
168 int m_propertyType = QMetaType::UnknownType;
169 SpecialProperty m_specialProperty = SP_None;
170 };
171 const PropertyDescription &propertyDescription() const { return m_propertyDescription; }
172
173protected:
174 virtual std::unique_ptr<PropertyHelper>
175 createPropertyHelper(QObject *o, SpecialProperty sp,
176 QDesignerPropertySheetExtension *sheet, int sheetIndex) const;
177
178private:
179 PropertyDescription m_propertyDescription;
180 PropertyHelperList m_propertyHelperList;
181};
182
183class QDESIGNER_SHARED_EXPORT SetPropertyCommand: public PropertyListCommand
184{
185
186public:
187 explicit SetPropertyCommand(QDesignerFormWindowInterface *formWindow, QUndoCommand *parent = nullptr);
188
189 bool init(QObject *object, const QString &propertyName, const QVariant &newValue);
190 bool init(const QObjectList &list, const QString &propertyName, const QVariant &newValue,
191 QObject *referenceObject = nullptr, bool enableSubPropertyHandling = true);
192
193
194 inline QVariant newValue() const
195 { return m_newValue; }
196
197 inline void setNewValue(const QVariant &newValue)
198 { m_newValue = newValue; }
199
200 int id() const override;
201 bool mergeWith(const QUndoCommand *other) override;
202
203 void redo() override;
204
205protected:
206 virtual QVariant mergeValue(const QVariant &newValue);
207
208private:
209 quint64 subPropertyMask(const QVariant &newValue, QObject *referenceObject);
210 void setDescription();
211 QVariant m_newValue;
212 quint64 m_subPropertyMask;
213};
214
215class QDESIGNER_SHARED_EXPORT ResetPropertyCommand: public PropertyListCommand
216{
217
218public:
219 explicit ResetPropertyCommand(QDesignerFormWindowInterface *formWindow);
220
221 bool init(QObject *object, const QString &propertyName);
222 bool init(const QObjectList &list, const QString &propertyName, QObject *referenceObject = nullptr);
223
224 void redo() override;
225
226protected:
227 bool mergeWith(const QUndoCommand *) override { return false; }
228
229private:
230 void setDescription();
231 QString m_propertyName;
232};
233
234
235class QDESIGNER_SHARED_EXPORT AddDynamicPropertyCommand: public QDesignerFormWindowCommand
236{
237
238public:
239 explicit AddDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow);
240
241 bool init(const QObjectList &selection, QObject *current, const QString &propertyName, const QVariant &value);
242
243 void redo() override;
244 void undo() override;
245private:
246 void setDescription();
247 QString m_propertyName;
248 QObjectList m_selection;
249 QVariant m_value;
250};
251
252class QDESIGNER_SHARED_EXPORT RemoveDynamicPropertyCommand: public QDesignerFormWindowCommand
253{
254
255public:
256 explicit RemoveDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow);
257
258 bool init(const QObjectList &selection, QObject *current, const QString &propertyName);
259
260 void redo() override;
261 void undo() override;
262private:
263 void setDescription();
264 QString m_propertyName;
265 QHash<QObject *, std::pair<QVariant, bool> > m_objectToValueAndChanged;
266};
267
268} // namespace qdesigner_internal
269
270QT_END_NAMESPACE
271
272#endif // QDESIGNER_PROPERTYCOMMAND_H
static bool canBeBuddy(QWidget *w, QDesignerFormWindowInterface *form)
static QString buddy(QLabel *label, QDesignerFormEditorInterface *core)
static constexpr auto buddyPropertyC
#define QT_BUDDYEDITOR_EXPORT
The QDesignerMetaDataBaseItemInterface class provides an interface to individual items in \QD's meta ...
friend class QWidget
Definition qpainter.h:421
void init(QWidget *parentWidget, QAction *action, QAction *beforeAction=nullptr, bool update=true)
ActionInsertionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
AddStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QStackedWidget *stackedWidget, InsertionMode mode)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void init(QTabWidget *tabWidget, InsertionMode mode)
AddTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
AddToolBarCommand(QDesignerFormWindowInterface *formWindow)
void init(QMainWindow *mainWindow, Qt::ToolBarArea area)
void undo() override
Reverts a change to the document.
AddToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, InsertionMode mode)
void undo() override
Reverts a change to the document.
void setBackground(QWidget *background) override
QDesignerFormWindowInterface * formWindow() const
void endConnection(QWidget *target, const QPoint &pos) override
void widgetRemoved(QWidget *w) override
QWidget * widgetAt(const QPoint &pos) const override
Connection * createConnection(QWidget *source, QWidget *destination) override
void createContextMenu(QMenu &menu) override
CreateMenuBarCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
CreateStatusBarCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void init(QDesignerMenu *menu, QAction *action, QObject *m_objectToSelect=nullptr)
CreateSubmenuCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void restore(QDesignerFormWindowInterface *formWindow) const
void save(const QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteMenuBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteStackedWidgetPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DeleteTabPageCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
DeleteToolBarCommand(QDesignerFormWindowInterface *formWindow)
DeleteToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
DockWidgetCommand(const QString &description, QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
InsertActionIntoCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QAction *action, QAction *actionBefore, QWidget *associatedWidget, QWidget *objectToSelect)
MenuActionCommand(const QString &text, QDesignerFormWindowInterface *formWindow)
const KeyToValueMap & keyToValueMap() const
const QStringList & keys() const
const QString & scope() const
void addKey(IntType value, const QString &name)
const QString & enumName() const
IntType keyToValue(QStringView key, bool *ok=nullptr) const
void appendQualifiedName(const QString &key, SerializationMode sm, QString &target) const
const QString & separator() const
QString valueToKey(IntType value, bool *ok=nullptr) const
MetaEnum(const QString &enumName, const QString &scope, const QString &separator)
void init(QStackedWidget *stackedWidget, QWidget *page, int newIndex)
MoveStackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
void undo() override
Reverts a change to the document.
MoveTabPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QTabWidget *tabWidget, QWidget *page, const QIcon &icon, const QString &label, int index, int newIndex)
MoveToolBoxPageCommand(QDesignerFormWindowInterface *formWindow)
void redo() override
Applies a change to the document.
void init(QToolBox *toolBox, QWidget *page, int newIndex)
void undo() override
Reverts a change to the document.
QDesignerIntegration * integration(QDesignerFormWindowInterface *fw) const
PropertyHelper(QObject *object, SpecialProperty specialProperty, QDesignerPropertySheetExtension *sheet, int index)
void setOldValue(const QVariant &oldValue)
Value restoreDefaultValue(QDesignerFormWindowInterface *fw)
Value restoreOldValue(QDesignerFormWindowInterface *fw)
bool canMerge(const PropertyHelper &other) const
virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, quint64 subPropertyMask)
RemoveActionFromCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
RemoveMenuActionCommand(QDesignerFormWindowInterface *formWindow)
void undo() override
Reverts a change to the document.
void redo() override
Applies a change to the document.
StackedWidgetCommand(QDesignerFormWindowInterface *formWindow)
void init(QStackedWidget *stackedWidget)
TabWidgetCommand(QDesignerFormWindowInterface *formWindow)
ToolBoxCommand(QDesignerFormWindowInterface *formWindow)
Combined button and popup list for selecting options.
int valueOf(const QVariant &value, bool *ok=nullptr)
bool isObjectAncestorOf(QObject *ancestor, QObject *child)
bool isCentralWidget(QDesignerFormWindowInterface *fw, QWidget *widget)
Auxiliary methods to store/retrieve settings.
QDESIGNER_SHARED_EXPORT void getFormLayoutItemPosition(const QFormLayout *formLayout, int index, int *rowPtr, int *columnPtr=nullptr, int *rowspanPtr=nullptr, int *colspanPtr=nullptr)
QDESIGNER_SHARED_EXPORT QDebug operator<<(QDebug, const PropertySheetIconValue &)
static QUndoCommand * createBuddyCommand(QDesignerFormWindowInterface *fw, QLabel *label, QWidget *buddy)
QDESIGNER_SHARED_EXPORT void formLayoutAddWidget(QFormLayout *formLayout, QWidget *w, const QRect &r, bool insert)
QDESIGNER_SHARED_EXPORT void designerWarning(const QString &message)
QDESIGNER_SHARED_EXPORT void reloadIconResources(DesignerIconCache *iconCache, QObject *object)
QDESIGNER_SHARED_EXPORT bool runUIC(const QString &fileName, UicLanguage language, QByteArray &ba, QString &errorMessage)
#define QDESIGNER_SHARED_EXPORT