1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
|
/****************************************************************************
**
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the Qt Designer of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of Qt Designer. This header
// file may change from version to version without notice, or even be removed.
//
// We mean it.
//
#ifndef QDESIGNER_PROPERTYCOMMAND_H
#define QDESIGNER_PROPERTYCOMMAND_H
#include "qdesigner_formwindowcommand_p.h"
#include <QtCore/QVariant>
#include <QtCore/QList>
#include <QtCore/QPair>
#include <QtCore/QSharedPointer>
QT_BEGIN_NAMESPACE
class QDesignerFormWindowInterface;
class QDesignerPropertySheetExtension;
namespace qdesigner_internal {
class QDesignerIntegration;
enum SpecialProperty {
SP_None, SP_ObjectName, SP_LayoutName, SP_SpacerName,SP_WindowTitle,
SP_MinimumSize, SP_MaximumSize, SP_Geometry, SP_Icon, SP_CurrentTabName, SP_CurrentItemName, SP_CurrentPageName,
SP_AutoDefault, SP_Alignment, SP_Shortcut, SP_Orientation
};
//Determine special property
enum SpecialProperty getSpecialProperty(const QString& propertyName);
// A helper class for applying properties to objects.
// Can be used for Set commands (setValue(), restoreOldValue()) or
// Reset Commands restoreDefaultValue(), restoreOldValue()).
//
class QDESIGNER_SHARED_EXPORT PropertyHelper {
Q_DISABLE_COPY(PropertyHelper)
public:
// A pair of Value and changed flag
typedef QPair<QVariant, bool> Value;
enum ObjectType {OT_Object, OT_FreeAction, OT_AssociatedAction, OT_Widget};
PropertyHelper(QObject* object,
SpecialProperty specialProperty,
QDesignerPropertySheetExtension *sheet,
int index);
virtual ~PropertyHelper() {}
QObject *object() const { return m_object; }
SpecialProperty specialProperty() const { return m_specialProperty; }
// set a new value. Can be overwritten to perform a transformation (see
// handling of Arrow key move in FormWindow class).
virtual Value setValue(QDesignerFormWindowInterface *fw, const QVariant &value, bool changed, unsigned subPropertyMask);
// restore old value
Value restoreOldValue(QDesignerFormWindowInterface *fw);
// set default value
Value restoreDefaultValue(QDesignerFormWindowInterface *fw);
inline QVariant oldValue() const
{ return m_oldValue.first; }
inline void setOldValue(const QVariant &oldValue)
{ m_oldValue.first = oldValue; }
// required updates for this property (bit mask)
enum UpdateMask { UpdatePropertyEditor=1, UpdateObjectInspector=2 };
unsigned updateMask() const;
// can be merged into one command (that is, object and name match)
bool canMerge(const PropertyHelper &other) const;
QDesignerIntegration *integration(QDesignerFormWindowInterface *fw) const;
static void triggerActionChanged(QAction *a);
private:
// Apply the value and update. Returns corrected value
Value applyValue(QDesignerFormWindowInterface *fw, const QVariant &oldValue, Value newValue);
static void checkApplyWidgetValue(QDesignerFormWindowInterface *fw, QWidget* w,
SpecialProperty specialProperty, QVariant &v);
void updateObject(QDesignerFormWindowInterface *fw, const QVariant &oldValue, const QVariant &newValue);
QVariant findDefaultValue(QDesignerFormWindowInterface *fw) const;
void ensureUniqueObjectName(QDesignerFormWindowInterface *fw, QObject *object) const;
SpecialProperty m_specialProperty;
QPointer<QObject> m_object;
ObjectType m_objectType;
QPointer<QWidget> m_parentWidget;
QDesignerPropertySheetExtension *m_propertySheet;
int m_index;
Value m_oldValue;
};
// Base class for commands that can be applied to several widgets
class QDESIGNER_SHARED_EXPORT PropertyListCommand : public QDesignerFormWindowCommand {
public:
typedef QList<QObject *> ObjectList;
explicit PropertyListCommand(QDesignerFormWindowInterface *formWindow, QUndoCommand *parent = 0);
QObject* object(int index = 0) const;
QVariant oldValue(int index = 0) const;
void setOldValue(const QVariant &oldValue, int index = 0);
// Calls restoreDefaultValue() and update()
virtual void undo();
protected:
typedef QSharedPointer<PropertyHelper> PropertyHelperPtr;
typedef QList<PropertyHelperPtr> PropertyHelperList;
// add an object
bool add(QObject *object, const QString &propertyName);
// Init from a list and make sure referenceObject is added first to obtain the right property group
bool initList(const ObjectList &list, const QString &apropertyName, QObject *referenceObject = 0);
// set a new value, return update mask
unsigned setValue(QVariant value, bool changed, unsigned subPropertyMask);
// restore old value, return update mask
unsigned restoreOldValue();
// set default value, return update mask
unsigned restoreDefaultValue();
// update designer
void update(unsigned updateMask);
// check if lists are aequivalent for command merging (same widgets and props)
bool canMergeLists(const PropertyHelperList& other) const;
PropertyHelperList& propertyHelperList() { return m_propertyHelperList; }
const PropertyHelperList& propertyHelperList() const { return m_propertyHelperList; }
const QString propertyName() const;
SpecialProperty specialProperty() const;
// Helper struct describing a property used for checking whether
// properties of different widgets are equivalent
struct PropertyDescription {
public:
PropertyDescription();
PropertyDescription(const QString &propertyName, QDesignerPropertySheetExtension *propertySheet, int index);
bool equals(const PropertyDescription &p) const;
void debug() const;
QString m_propertyName;
QString m_propertyGroup;
QVariant::Type m_propertyType;
SpecialProperty m_specialProperty;
};
const PropertyDescription &propertyDescription() const { return m_propertyDescription; }
protected:
virtual PropertyHelper *createPropertyHelper(QObject *o, SpecialProperty sp,
QDesignerPropertySheetExtension *sheet, int sheetIndex) const;
private:
PropertyDescription m_propertyDescription;
PropertyHelperList m_propertyHelperList;
};
class QDESIGNER_SHARED_EXPORT SetPropertyCommand: public PropertyListCommand
{
public:
typedef QList<QObject *> ObjectList;
explicit SetPropertyCommand(QDesignerFormWindowInterface *formWindow, QUndoCommand *parent = 0);
bool init(QObject *object, const QString &propertyName, const QVariant &newValue);
bool init(const ObjectList &list, const QString &propertyName, const QVariant &newValue,
QObject *referenceObject = 0, bool enableSubPropertyHandling = true);
inline QVariant newValue() const
{ return m_newValue; }
inline void setNewValue(const QVariant &newValue)
{ m_newValue = newValue; }
int id() const;
bool mergeWith(const QUndoCommand *other);
virtual void redo();
protected:
virtual QVariant mergeValue(const QVariant &newValue);
private:
unsigned subPropertyMask(const QVariant &newValue, QObject *referenceObject);
void setDescription();
QVariant m_newValue;
unsigned m_subPropertyMask;
};
class QDESIGNER_SHARED_EXPORT ResetPropertyCommand: public PropertyListCommand
{
public:
typedef QList<QObject *> ObjectList;
explicit ResetPropertyCommand(QDesignerFormWindowInterface *formWindow);
bool init(QObject *object, const QString &propertyName);
bool init(const ObjectList &list, const QString &propertyName, QObject *referenceObject = 0);
virtual void redo();
protected:
virtual bool mergeWith(const QUndoCommand *) { return false; }
private:
void setDescription();
QString m_propertyName;
};
class QDESIGNER_SHARED_EXPORT AddDynamicPropertyCommand: public QDesignerFormWindowCommand
{
public:
explicit AddDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow);
bool init(const QList<QObject *> &selection, QObject *current, const QString &propertyName, const QVariant &value);
virtual void redo();
virtual void undo();
private:
void setDescription();
QString m_propertyName;
QList<QObject *> m_selection;
QVariant m_value;
};
class QDESIGNER_SHARED_EXPORT RemoveDynamicPropertyCommand: public QDesignerFormWindowCommand
{
public:
explicit RemoveDynamicPropertyCommand(QDesignerFormWindowInterface *formWindow);
bool init(const QList<QObject *> &selection, QObject *current, const QString &propertyName);
virtual void redo();
virtual void undo();
private:
void setDescription();
QString m_propertyName;
QMap<QObject *, QPair<QVariant, bool> > m_objectToValueAndChanged;
};
} // namespace qdesigner_internal
QT_END_NAMESPACE
#endif // QDESIGNER_PROPERTYCOMMAND_H
|