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