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// Qt-Security score:significant reason:default
4
5//
6// W A R N I N G
7// -------------
8//
9// This file is not part of the Qt API. It exists for the convenience
10// of Qt Designer. This header
11// file may change from version to version without notice, or even be removed.
12//
13// We mean it.
14//
15
16#ifndef QDESIGNER_PROPERTYCOMMAND_H
17#define QDESIGNER_PROPERTYCOMMAND_H
18
20
21#include <QtCore/qvariant.h>
22#include <QtCore/qhash.h>
23#include <QtCore/qlist.h>
24#include <QtCore/qpointer.h>
25#include <QtCore/qsharedpointer.h>
26
27#include <utility>
28
30
31class QDesignerFormWindowInterface;
33class QDesignerIntegration;
34
35namespace qdesigner_internal {
36
42
43//Determine special property
44enum SpecialProperty getSpecialProperty(const QString& propertyName);
45
46// A helper class for applying properties to objects.
47// Can be used for Set commands (setValue(), restoreOldValue()) or
48// Reset Commands restoreDefaultValue(), restoreOldValue()).
49//
52public:
53 // A pair of Value and changed flag
54 using Value = std::pair<QVariant, bool>;
55
57
58 PropertyHelper(QObject* object,
59 SpecialProperty specialProperty,
61 int index);
62 virtual ~PropertyHelper() = default;
63
64 QObject *object() const { return m_object; }
65 SpecialProperty specialProperty() const { return m_specialProperty; }
66 // set a new value. Can be overwritten to perform a transformation (see
67 // handling of Arrow key move in FormWindow class).
68 virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value,
69 bool changed, quint64 subPropertyMask);
70
71 // restore old value
72 Value restoreOldValue(QDesignerFormWindowInterface *fw);
73 // set default value
74 Value restoreDefaultValue(QDesignerFormWindowInterface *fw);
75
76 inline QVariant oldValue() const
77 { return m_oldValue.first; }
78
79 inline void setOldValue(const QVariant &oldValue)
80 { m_oldValue.first = oldValue; }
81
82 // required updates for this property (bit mask)
84 unsigned updateMask() const;
85
86 // can be merged into one command (that is, object and name match)
87 bool canMerge(const PropertyHelper &other) const;
88 QDesignerIntegration *integration(QDesignerFormWindowInterface *fw) const;
89
90 static void triggerActionChanged(QAction *a);
91
92private:
93 // Apply the value and update. Returns corrected value
95
96 static void checkApplyWidgetValue(QDesignerFormWindowInterface *fw, QWidget* w,
97 SpecialProperty specialProperty, QVariant &v);
98
99 void updateObject(QDesignerFormWindowInterface *fw, const QVariant &oldValue, const QVariant &newValue);
100 QVariant findDefaultValue(QDesignerFormWindowInterface *fw) const;
101 void ensureUniqueObjectName(QDesignerFormWindowInterface *fw, QObject *object) const;
102 SpecialProperty m_specialProperty;
103
104 QPointer<QObject> m_object;
105 ObjectType m_objectType;
106 QPointer<QWidget> m_parentWidget;
107
108 QDesignerPropertySheetExtension *m_propertySheet;
109 int m_index;
110
111 Value m_oldValue;
112};
113
114// Base class for commands that can be applied to several widgets
115
116class QDESIGNER_SHARED_EXPORT PropertyListCommand : public QDesignerFormWindowCommand {
117public:
118 explicit PropertyListCommand(QDesignerFormWindowInterface *formWindow, QUndoCommand *parent = nullptr);
119
120 QObject* object(int index = 0) const;
121
122 QVariant oldValue(int index = 0) const;
123
124 void setOldValue(const QVariant &oldValue, int index = 0);
125
126 // Calls restoreDefaultValue() and update()
127 void undo() override;
128
129protected:
130 using PropertyHelperPtr = std::unique_ptr<PropertyHelper>;
131 using PropertyHelperList = std::vector<PropertyHelperPtr>;
132
133 // add an object
134 bool add(QObject *object, const QString &propertyName);
135
136 // Init from a list and make sure referenceObject is added first to obtain the right property group
137 bool initList(const QObjectList &list, const QString &apropertyName, QObject *referenceObject = nullptr);
138
139 // set a new value, return update mask
140 unsigned setValue(const QVariant &value, bool changed, quint64 subPropertyMask);
141
142 // restore old value, return update mask
143 unsigned restoreOldValue();
144 // set default value, return update mask
145 unsigned restoreDefaultValue();
146
147 // update designer
148 void update(unsigned updateMask);
149
150 // check if lists are aequivalent for command merging (same widgets and props)
151 bool canMergeLists(const PropertyHelperList& other) const;
152
153 PropertyHelperList& propertyHelperList() { return m_propertyHelperList; }
154 const PropertyHelperList& propertyHelperList() const { return m_propertyHelperList; }
155
156 const QString propertyName() const;
157 SpecialProperty specialProperty() const;
158
159 // Helper struct describing a property used for checking whether
160 // properties of different widgets are equivalent
161 struct PropertyDescription {
162 public:
163 PropertyDescription() = default;
164 PropertyDescription(const QString &propertyName, QDesignerPropertySheetExtension *propertySheet, int index);
165 bool equals(const PropertyDescription &p) const;
166 void debug() const;
167
168 QString m_propertyName;
169 QString m_propertyGroup;
170 int m_propertyType = QMetaType::UnknownType;
171 SpecialProperty m_specialProperty = SP_None;
172 };
173 const PropertyDescription &propertyDescription() const { return m_propertyDescription; }
174
175protected:
176 virtual std::unique_ptr<PropertyHelper>
177 createPropertyHelper(QObject *o, SpecialProperty sp,
178 QDesignerPropertySheetExtension *sheet, int sheetIndex) const;
179
180private:
181 PropertyDescription m_propertyDescription;
182 PropertyHelperList m_propertyHelperList;
183};
184
185class QDESIGNER_SHARED_EXPORT SetPropertyCommand: public PropertyListCommand
186{
187
188public:
189 explicit SetPropertyCommand(QDesignerFormWindowInterface *formWindow, QUndoCommand *parent = nullptr);
190
191 bool init(QObject *object, const QString &propertyName, const QVariant &newValue);
192 bool init(const QObjectList &list, const QString &propertyName, const QVariant &newValue,
193 QObject *referenceObject = nullptr, bool enableSubPropertyHandling = true);
194
195
196 inline QVariant newValue() const
197 { return m_newValue; }
198
199 inline void setNewValue(const QVariant &newValue)
200 { m_newValue = newValue; }
201
202 int id() const override;
203 bool mergeWith(const QUndoCommand *other) override;
204
205 void redo() override;
206
207protected:
208 virtual QVariant mergeValue(const QVariant &newValue);
209
210private:
211 quint64 subPropertyMask(const QVariant &newValue, QObject *referenceObject);
212 void setDescription();
213 QVariant m_newValue;
214 quint64 m_subPropertyMask;
215};
216
217class QDESIGNER_SHARED_EXPORT ResetPropertyCommand: public PropertyListCommand
218{
219
220public:
221 explicit ResetPropertyCommand(QDesignerFormWindowInterface *formWindow);
222
223 bool init(QObject *object, const QString &propertyName);
224 bool init(const QObjectList &list, const QString &propertyName, QObject *referenceObject = nullptr);
225
226 void redo() override;
227
228protected:
229 bool mergeWith(const QUndoCommand *) override { return false; }
230
231private:
232 void setDescription();
233 QString m_propertyName;
234};
235
236
237class QDESIGNER_SHARED_EXPORT AddDynamicPropertyCommand: public QDesignerFormWindowCommand
238{
239
240public:
241 explicit AddDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow);
242
243 bool init(const QObjectList &selection, QObject *current, const QString &propertyName, const QVariant &value);
244
245 void redo() override;
246 void undo() override;
247private:
248 void setDescription();
249 QString m_propertyName;
250 QObjectList m_selection;
251 QVariant m_value;
252};
253
254class QDESIGNER_SHARED_EXPORT RemoveDynamicPropertyCommand: public QDesignerFormWindowCommand
255{
256
257public:
258 explicit RemoveDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow);
259
260 bool init(const QObjectList &selection, QObject *current, const QString &propertyName);
261
262 void redo() override;
263 void undo() override;
264private:
265 void setDescription();
266 QString m_propertyName;
267 QHash<QObject *, std::pair<QVariant, bool> > m_objectToValueAndChanged;
268};
269
270} // namespace qdesigner_internal
271
272QT_END_NAMESPACE
273
274#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:432
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.
enum SpecialProperty getSpecialProperty(const QString &propertyName)
QDESIGNER_SHARED_EXPORT void getFormLayoutItemPosition(const QFormLayout *formLayout, int index, int *rowPtr, int *columnPtr=nullptr, int *rowspanPtr=nullptr, int *colspanPtr=nullptr)
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)
Q_CORE_EXPORT QDebug operator<<(QDebug debug, QDir::Filters filters)
Definition qdir.cpp:2618
QT_END_NAMESPACE Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QtOhos::enums::kit::ShareKit::systemShare::SelectionMode))
#define QDESIGNER_SHARED_EXPORT