author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Tue, 06 Jul 2010 15:10:48 +0300 | |
changeset 30 | 5dc02b23752f |
parent 18 | 2f34d5167611 |
child 33 | 3e2da88830cd |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 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 |
#include "qdesigner_propertysheet_p.h" |
|
43 |
#include "qdesigner_utils_p.h" |
|
44 |
#include "formwindowbase_p.h" |
|
45 |
#include "layoutinfo_p.h" |
|
46 |
#include "qlayout_widget_p.h" |
|
47 |
#include "qdesigner_introspection_p.h" |
|
48 |
||
49 |
#include <formbuilderextra_p.h> |
|
50 |
||
51 |
#include <QtDesigner/QDesignerFormWindowInterface> |
|
52 |
#include <QtDesigner/QDesignerFormEditorInterface> |
|
53 |
#include <QtDesigner/QDesignerWidgetDataBaseInterface> |
|
54 |
||
55 |
#include <QtCore/QDebug> |
|
56 |
||
57 |
#include <QtGui/QLayout> |
|
58 |
#include <QtGui/QDockWidget> |
|
59 |
#include <QtGui/QDialog> |
|
60 |
#include <QtGui/QLabel> |
|
61 |
#include <QtGui/QGroupBox> |
|
62 |
#include <QtGui/QStyle> |
|
63 |
#include <QtGui/QApplication> |
|
64 |
#include <QtGui/QToolBar> |
|
65 |
#include <QtGui/QMainWindow> |
|
66 |
#include <QtGui/QMenuBar> |
|
67 |
||
68 |
QT_BEGIN_NAMESPACE |
|
69 |
||
70 |
#define USE_LAYOUT_SIZE_CONSTRAINT |
|
71 |
||
72 |
static const QDesignerMetaObjectInterface *propertyIntroducedBy(const QDesignerMetaObjectInterface *meta, int index) |
|
73 |
{ |
|
74 |
if (index >= meta->propertyOffset()) |
|
75 |
return meta; |
|
76 |
||
77 |
if (meta->superClass()) |
|
78 |
return propertyIntroducedBy(meta->superClass(), index); |
|
79 |
||
80 |
return 0; |
|
81 |
} |
|
82 |
||
83 |
// Layout fake properties (prefixed by 'layout' to distinguish them from other 'margins' |
|
84 |
// that might be around. These are forwarded to the layout sheet (after name transformation). |
|
85 |
// |
|
86 |
// 'layoutObjectName' is new for 4.4. It is the name of the actual layout. |
|
87 |
// Up to 4.3, QLayoutWidget's name was displayed in the objectinspector. |
|
88 |
// This changes with 4.4; the layout name is displayed. This means that for |
|
89 |
// old forms, QLayoutWidget will show up as ''; however, the uic code will |
|
90 |
// still use 'verticalLayout' (in case someone accesses it). New Layouts get autogenerated names, |
|
91 |
// legacy forms will keep their empty names (unless someone types in a new name). |
|
92 |
static const char *layoutObjectNameC = "layoutName"; |
|
93 |
static const char *layoutLeftMarginC = "layoutLeftMargin"; |
|
94 |
static const char *layoutTopMarginC = "layoutTopMargin"; |
|
95 |
static const char *layoutRightMarginC = "layoutRightMargin"; |
|
96 |
static const char *layoutBottomMarginC = "layoutBottomMargin"; |
|
97 |
static const char *layoutSpacingC = "layoutSpacing"; |
|
98 |
static const char *layoutHorizontalSpacingC = "layoutHorizontalSpacing"; |
|
99 |
static const char *layoutVerticalSpacingC = "layoutVerticalSpacing"; |
|
100 |
static const char *layoutSizeConstraintC = "layoutSizeConstraint"; |
|
101 |
// form layout |
|
102 |
static const char *layoutFieldGrowthPolicyC = "layoutFieldGrowthPolicy"; |
|
103 |
static const char *layoutRowWrapPolicyC = "layoutRowWrapPolicy"; |
|
104 |
static const char *layoutLabelAlignmentC = "layoutLabelAlignment"; |
|
105 |
static const char *layoutFormAlignmentC = "layoutFormAlignment"; |
|
106 |
// stretches |
|
107 |
static const char *layoutboxStretchPropertyC = "layoutStretch"; |
|
108 |
static const char *layoutGridRowStretchPropertyC = "layoutRowStretch"; |
|
109 |
static const char *layoutGridColumnStretchPropertyC = "layoutColumnStretch"; |
|
110 |
static const char *layoutGridRowMinimumHeightC = "layoutRowMinimumHeight"; |
|
111 |
static const char *layoutGridColumnMinimumWidthC = "layoutColumnMinimumWidth"; |
|
112 |
||
113 |
// Find the form editor in the hierarchy. |
|
114 |
// We know that the parent of the sheet is the extension manager |
|
115 |
// whose parent is the core. |
|
116 |
||
117 |
static QDesignerFormEditorInterface *formEditorForObject(QObject *o) { |
|
118 |
do { |
|
119 |
if (QDesignerFormEditorInterface* core = qobject_cast<QDesignerFormEditorInterface*>(o)) |
|
120 |
return core; |
|
121 |
o = o->parent(); |
|
122 |
} while(o); |
|
123 |
Q_ASSERT(o); |
|
124 |
return 0; |
|
125 |
} |
|
126 |
||
127 |
static bool hasLayoutAttributes(QDesignerFormEditorInterface *core, QObject *object) |
|
128 |
{ |
|
129 |
if (!object->isWidgetType()) |
|
130 |
return false; |
|
131 |
||
132 |
QWidget *w = qobject_cast<QWidget *>(object); |
|
133 |
if (const QDesignerWidgetDataBaseInterface *db = core->widgetDataBase()) { |
|
134 |
if (db->isContainer(w)) |
|
135 |
return true; |
|
136 |
} |
|
137 |
return false; |
|
138 |
} |
|
139 |
||
140 |
// Cache DesignerMetaEnum by scope/name of a QMetaEnum |
|
141 |
static const qdesigner_internal::DesignerMetaEnum &designerMetaEnumFor(const QDesignerMetaEnumInterface *me) |
|
142 |
{ |
|
143 |
typedef QPair<QString, QString> ScopeNameKey; |
|
144 |
typedef QMap<ScopeNameKey, qdesigner_internal::DesignerMetaEnum> DesignerMetaEnumCache; |
|
145 |
static DesignerMetaEnumCache cache; |
|
146 |
||
147 |
const QString name = me->name(); |
|
148 |
const QString scope = me->scope(); |
|
149 |
||
150 |
const ScopeNameKey key = ScopeNameKey(scope, name); |
|
151 |
DesignerMetaEnumCache::iterator it = cache.find(key); |
|
152 |
if (it == cache.end()) { |
|
153 |
qdesigner_internal::DesignerMetaEnum dme = qdesigner_internal::DesignerMetaEnum(name, scope, me->separator()); |
|
154 |
const int keyCount = me->keyCount(); |
|
155 |
for (int i=0; i < keyCount; ++i) |
|
156 |
dme.addKey(me->value(i), me->key(i)); |
|
157 |
it = cache.insert(key, dme); |
|
158 |
} |
|
159 |
return it.value(); |
|
160 |
} |
|
161 |
||
162 |
// Cache DesignerMetaFlags by scope/name of a QMetaEnum |
|
163 |
static const qdesigner_internal::DesignerMetaFlags &designerMetaFlagsFor(const QDesignerMetaEnumInterface *me) |
|
164 |
{ |
|
165 |
typedef QPair<QString, QString> ScopeNameKey; |
|
166 |
typedef QMap<ScopeNameKey, qdesigner_internal::DesignerMetaFlags> DesignerMetaFlagsCache; |
|
167 |
static DesignerMetaFlagsCache cache; |
|
168 |
||
169 |
const QString name = me->name(); |
|
170 |
const QString scope = me->scope(); |
|
171 |
||
172 |
const ScopeNameKey key = ScopeNameKey(scope, name); |
|
173 |
DesignerMetaFlagsCache::iterator it = cache.find(key); |
|
174 |
if (it == cache.end()) { |
|
175 |
qdesigner_internal::DesignerMetaFlags dme = qdesigner_internal::DesignerMetaFlags(name, scope, me->separator()); |
|
176 |
const int keyCount = me->keyCount(); |
|
177 |
for (int i=0; i < keyCount; ++i) |
|
178 |
dme.addKey(me->value(i), me->key(i)); |
|
179 |
it = cache.insert(key, dme); |
|
180 |
} |
|
181 |
return it.value(); |
|
182 |
} |
|
183 |
||
184 |
// ------------ QDesignerMemberSheetPrivate |
|
185 |
class QDesignerPropertySheetPrivate { |
|
186 |
public: |
|
187 |
typedef QDesignerPropertySheet::PropertyType PropertyType; |
|
188 |
typedef QDesignerPropertySheet::ObjectType ObjectType; |
|
189 |
||
190 |
explicit QDesignerPropertySheetPrivate(QDesignerPropertySheet *sheetPublic, QObject *object, QObject *sheetParent); |
|
191 |
||
192 |
bool invalidIndex(const char *functionName, int index) const; |
|
193 |
inline int count() const { return m_meta->propertyCount() + m_addProperties.count(); } |
|
194 |
||
195 |
PropertyType propertyType(int index) const; |
|
196 |
QString transformLayoutPropertyName(int index) const; |
|
197 |
QLayout* layout(QDesignerPropertySheetExtension **layoutPropertySheet = 0) const; |
|
198 |
static ObjectType objectType(const QObject *o); |
|
199 |
||
200 |
bool isReloadableProperty(int index) const; |
|
201 |
bool isResourceProperty(int index) const; |
|
202 |
void addResourceProperty(int index, QVariant::Type type); |
|
203 |
QVariant resourceProperty(int index) const; |
|
204 |
void setResourceProperty(int index, const QVariant &value); |
|
205 |
QVariant emptyResourceProperty(int index) const; // of type PropertySheetPixmapValue / PropertySheetIconValue |
|
206 |
QVariant defaultResourceProperty(int index) const; // of type QPixmap / QIcon (maybe it can be generalized for all types, not resource only) |
|
207 |
||
208 |
bool isStringProperty(int index) const; |
|
209 |
void addStringProperty(int index); |
|
210 |
qdesigner_internal::PropertySheetStringValue stringProperty(int index) const; |
|
211 |
void setStringProperty(int index, const qdesigner_internal::PropertySheetStringValue &value); |
|
212 |
||
213 |
bool isKeySequenceProperty(int index) const; |
|
214 |
void addKeySequenceProperty(int index); |
|
215 |
qdesigner_internal::PropertySheetKeySequenceValue keySequenceProperty(int index) const; |
|
216 |
void setKeySequenceProperty(int index, const qdesigner_internal::PropertySheetKeySequenceValue &value); |
|
217 |
||
218 |
enum PropertyKind { NormalProperty, FakeProperty, DynamicProperty, DefaultDynamicProperty }; |
|
219 |
class Info { |
|
220 |
public: |
|
221 |
Info(); |
|
222 |
||
223 |
QString group; |
|
224 |
QVariant defaultValue; |
|
225 |
bool changed; |
|
226 |
bool visible; |
|
227 |
bool attribute; |
|
228 |
bool reset; |
|
229 |
PropertyType propertyType; |
|
230 |
PropertyKind kind; |
|
231 |
}; |
|
232 |
||
233 |
Info &ensureInfo(int index); |
|
234 |
||
235 |
QDesignerPropertySheet *q; |
|
236 |
QDesignerFormEditorInterface *m_core; |
|
237 |
const QDesignerMetaObjectInterface *m_meta; |
|
238 |
const ObjectType m_objectType; |
|
239 |
||
240 |
typedef QHash<int, Info> InfoHash; |
|
241 |
InfoHash m_info; |
|
242 |
QHash<int, QVariant> m_fakeProperties; |
|
243 |
QHash<int, QVariant> m_addProperties; |
|
244 |
QHash<QString, int> m_addIndex; |
|
245 |
QHash<int, QVariant> m_resourceProperties; // only PropertySheetPixmapValue snd PropertySheetIconValue here |
|
246 |
QHash<int, qdesigner_internal::PropertySheetStringValue> m_stringProperties; // only PropertySheetStringValue |
|
247 |
QHash<int, qdesigner_internal::PropertySheetKeySequenceValue> m_keySequenceProperties; // only PropertySheetKeySequenceValue |
|
248 |
||
249 |
const bool m_canHaveLayoutAttributes; |
|
250 |
||
251 |
// Variables used for caching the layout, access via layout(). |
|
252 |
QPointer<QObject> m_object; |
|
253 |
mutable QPointer<QLayout> m_lastLayout; |
|
254 |
mutable QDesignerPropertySheetExtension *m_lastLayoutPropertySheet; |
|
255 |
mutable bool m_LastLayoutByDesigner; |
|
256 |
||
257 |
qdesigner_internal::DesignerPixmapCache *m_pixmapCache; |
|
258 |
qdesigner_internal::DesignerIconCache *m_iconCache; |
|
259 |
QPointer<qdesigner_internal::FormWindowBase> m_fwb; |
|
260 |
||
261 |
// Enable Qt's internal properties starting with prefix "_q_" |
|
262 |
static bool m_internalDynamicPropertiesEnabled; |
|
263 |
}; |
|
264 |
||
265 |
bool QDesignerPropertySheetPrivate::m_internalDynamicPropertiesEnabled = false; |
|
266 |
||
267 |
/* |
|
268 |
The property is reloadable if its contents depends on resource. |
|
269 |
*/ |
|
270 |
bool QDesignerPropertySheetPrivate::isReloadableProperty(int index) const |
|
271 |
{ |
|
272 |
return isResourceProperty(index) |
|
273 |
|| propertyType(index) == QDesignerPropertySheet::PropertyStyleSheet |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
274 |
|| propertyType(index) == QDesignerPropertySheet::PropertyText |
0 | 275 |
|| q->property(index).type() == QVariant::Url; |
276 |
} |
|
277 |
||
278 |
/* |
|
279 |
Resource properties are those which: |
|
280 |
1) are reloadable |
|
281 |
2) their state is associated with a file which can be taken from resources |
|
282 |
3) we don't store them in Qt meta object system (because designer keeps different data structure for them) |
|
283 |
*/ |
|
284 |
||
285 |
bool QDesignerPropertySheetPrivate::isResourceProperty(int index) const |
|
286 |
{ |
|
287 |
return m_resourceProperties.contains(index); |
|
288 |
} |
|
289 |
||
290 |
void QDesignerPropertySheetPrivate::addResourceProperty(int index, QVariant::Type type) |
|
291 |
{ |
|
292 |
if (type == QVariant::Pixmap) |
|
293 |
m_resourceProperties.insert(index, qVariantFromValue(qdesigner_internal::PropertySheetPixmapValue())); |
|
294 |
else if (type == QVariant::Icon) |
|
295 |
m_resourceProperties.insert(index, qVariantFromValue(qdesigner_internal::PropertySheetIconValue())); |
|
296 |
} |
|
297 |
||
298 |
QVariant QDesignerPropertySheetPrivate::emptyResourceProperty(int index) const |
|
299 |
{ |
|
300 |
QVariant v = m_resourceProperties.value(index); |
|
301 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetPixmapValue>(v)) |
|
302 |
return qVariantFromValue(qdesigner_internal::PropertySheetPixmapValue()); |
|
303 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetIconValue>(v)) |
|
304 |
return qVariantFromValue(qdesigner_internal::PropertySheetIconValue()); |
|
305 |
return v; |
|
306 |
} |
|
307 |
||
308 |
QVariant QDesignerPropertySheetPrivate::defaultResourceProperty(int index) const |
|
309 |
{ |
|
310 |
return m_info.value(index).defaultValue; |
|
311 |
} |
|
312 |
||
313 |
QVariant QDesignerPropertySheetPrivate::resourceProperty(int index) const |
|
314 |
{ |
|
315 |
return m_resourceProperties.value(index); |
|
316 |
} |
|
317 |
||
318 |
void QDesignerPropertySheetPrivate::setResourceProperty(int index, const QVariant &value) |
|
319 |
{ |
|
320 |
Q_ASSERT(isResourceProperty(index)); |
|
321 |
||
322 |
QVariant &v = m_resourceProperties[index]; |
|
323 |
if ((qVariantCanConvert<qdesigner_internal::PropertySheetPixmapValue>(value) && qVariantCanConvert<qdesigner_internal::PropertySheetPixmapValue>(v)) |
|
324 |
|| (qVariantCanConvert<qdesigner_internal::PropertySheetIconValue>(value) && qVariantCanConvert<qdesigner_internal::PropertySheetIconValue>(v))) |
|
325 |
v = value; |
|
326 |
} |
|
327 |
||
328 |
bool QDesignerPropertySheetPrivate::isStringProperty(int index) const |
|
329 |
{ |
|
330 |
return m_stringProperties.contains(index); |
|
331 |
} |
|
332 |
||
333 |
void QDesignerPropertySheetPrivate::addStringProperty(int index) |
|
334 |
{ |
|
335 |
m_stringProperties.insert(index, qdesigner_internal::PropertySheetStringValue()); |
|
336 |
} |
|
337 |
||
338 |
qdesigner_internal::PropertySheetStringValue QDesignerPropertySheetPrivate::stringProperty(int index) const |
|
339 |
{ |
|
340 |
return m_stringProperties.value(index); |
|
341 |
} |
|
342 |
||
343 |
void QDesignerPropertySheetPrivate::setStringProperty(int index, const qdesigner_internal::PropertySheetStringValue &value) |
|
344 |
{ |
|
345 |
Q_ASSERT(isStringProperty(index)); |
|
346 |
||
347 |
m_stringProperties[index] = value; |
|
348 |
} |
|
349 |
||
350 |
bool QDesignerPropertySheetPrivate::isKeySequenceProperty(int index) const |
|
351 |
{ |
|
352 |
return m_keySequenceProperties.contains(index); |
|
353 |
} |
|
354 |
||
355 |
void QDesignerPropertySheetPrivate::addKeySequenceProperty(int index) |
|
356 |
{ |
|
357 |
m_keySequenceProperties.insert(index, qdesigner_internal::PropertySheetKeySequenceValue()); |
|
358 |
} |
|
359 |
||
360 |
qdesigner_internal::PropertySheetKeySequenceValue QDesignerPropertySheetPrivate::keySequenceProperty(int index) const |
|
361 |
{ |
|
362 |
return m_keySequenceProperties.value(index); |
|
363 |
} |
|
364 |
||
365 |
void QDesignerPropertySheetPrivate::setKeySequenceProperty(int index, const qdesigner_internal::PropertySheetKeySequenceValue &value) |
|
366 |
{ |
|
367 |
Q_ASSERT(isKeySequenceProperty(index)); |
|
368 |
||
369 |
m_keySequenceProperties[index] = value; |
|
370 |
} |
|
371 |
||
372 |
QDesignerPropertySheetPrivate::Info::Info() : |
|
373 |
changed(false), |
|
374 |
visible(true), |
|
375 |
attribute(false), |
|
376 |
reset(true), |
|
377 |
propertyType(QDesignerPropertySheet::PropertyNone), |
|
378 |
kind(NormalProperty) |
|
379 |
{ |
|
380 |
} |
|
381 |
||
382 |
QDesignerPropertySheetPrivate::QDesignerPropertySheetPrivate(QDesignerPropertySheet *sheetPublic, QObject *object, QObject *sheetParent) : |
|
383 |
q(sheetPublic), |
|
384 |
m_core(formEditorForObject(sheetParent)), |
|
385 |
m_meta(m_core->introspection()->metaObject(object)), |
|
386 |
m_objectType(QDesignerPropertySheet::objectTypeFromObject(object)), |
|
387 |
m_canHaveLayoutAttributes(hasLayoutAttributes(m_core, object)), |
|
388 |
m_object(object), |
|
389 |
m_lastLayout(0), |
|
390 |
m_lastLayoutPropertySheet(0), |
|
391 |
m_LastLayoutByDesigner(false), |
|
392 |
m_pixmapCache(0), |
|
393 |
m_iconCache(0) |
|
394 |
{ |
|
395 |
} |
|
396 |
||
397 |
qdesigner_internal::FormWindowBase *QDesignerPropertySheet::formWindowBase() const |
|
398 |
{ |
|
399 |
return d->m_fwb; |
|
400 |
} |
|
401 |
||
402 |
bool QDesignerPropertySheetPrivate::invalidIndex(const char *functionName, int index) const |
|
403 |
{ |
|
404 |
if (index < 0 || index >= count()) { |
|
405 |
qWarning() << "** WARNING " << functionName << " invoked for " << m_object->objectName() << " was passed an invalid index " << index << '.'; |
|
406 |
return true; |
|
407 |
} |
|
408 |
return false; |
|
409 |
} |
|
410 |
||
411 |
QLayout* QDesignerPropertySheetPrivate::layout(QDesignerPropertySheetExtension **layoutPropertySheet) const |
|
412 |
{ |
|
413 |
// Return the layout and its property sheet |
|
414 |
// only if it is managed by designer and not one created on a custom widget. |
|
415 |
// (attempt to cache the value as this requires some hoops). |
|
416 |
if (layoutPropertySheet) |
|
417 |
*layoutPropertySheet = 0; |
|
418 |
||
419 |
if (!m_object->isWidgetType() || !m_canHaveLayoutAttributes) |
|
420 |
return 0; |
|
421 |
||
422 |
QWidget *widget = qobject_cast<QWidget*>(m_object); |
|
423 |
QLayout *widgetLayout = qdesigner_internal::LayoutInfo::internalLayout(widget); |
|
424 |
if (!widgetLayout) { |
|
425 |
m_lastLayout = 0; |
|
426 |
m_lastLayoutPropertySheet = 0; |
|
427 |
return 0; |
|
428 |
} |
|
429 |
// Smart logic to avoid retrieving the meta DB from the widget every time. |
|
430 |
if (widgetLayout != m_lastLayout) { |
|
431 |
m_lastLayout = widgetLayout; |
|
432 |
m_LastLayoutByDesigner = false; |
|
433 |
m_lastLayoutPropertySheet = 0; |
|
434 |
// Is this a layout managed by designer or some layout on a custom widget? |
|
435 |
if (qdesigner_internal::LayoutInfo::managedLayout(m_core ,widgetLayout)) { |
|
436 |
m_LastLayoutByDesigner = true; |
|
437 |
m_lastLayoutPropertySheet = qt_extension<QDesignerPropertySheetExtension*>(m_core->extensionManager(), m_lastLayout); |
|
438 |
} |
|
439 |
} |
|
440 |
if (!m_LastLayoutByDesigner) |
|
441 |
return 0; |
|
442 |
||
443 |
if (layoutPropertySheet) |
|
444 |
*layoutPropertySheet = m_lastLayoutPropertySheet; |
|
445 |
||
446 |
return m_lastLayout; |
|
447 |
} |
|
448 |
||
449 |
QDesignerPropertySheetPrivate::Info &QDesignerPropertySheetPrivate::ensureInfo(int index) |
|
450 |
{ |
|
451 |
InfoHash::iterator it = m_info.find(index); |
|
452 |
if (it == m_info.end()) |
|
453 |
it = m_info.insert(index, Info()); |
|
454 |
return it.value(); |
|
455 |
} |
|
456 |
||
457 |
QDesignerPropertySheet::PropertyType QDesignerPropertySheetPrivate::propertyType(int index) const |
|
458 |
{ |
|
459 |
const InfoHash::const_iterator it = m_info.constFind(index); |
|
460 |
if (it == m_info.constEnd()) |
|
461 |
return QDesignerPropertySheet::PropertyNone; |
|
462 |
return it.value().propertyType; |
|
463 |
} |
|
464 |
||
465 |
QString QDesignerPropertySheetPrivate::transformLayoutPropertyName(int index) const |
|
466 |
{ |
|
467 |
typedef QMap<QDesignerPropertySheet::PropertyType, QString> TypeNameMap; |
|
468 |
static TypeNameMap typeNameMap; |
|
469 |
if (typeNameMap.empty()) { |
|
470 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutObjectName, QLatin1String("objectName")); |
|
471 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutLeftMargin, QLatin1String("leftMargin")); |
|
472 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutTopMargin, QLatin1String("topMargin")); |
|
473 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutRightMargin, QLatin1String("rightMargin")); |
|
474 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutBottomMargin, QLatin1String("bottomMargin")); |
|
475 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutSpacing, QLatin1String("spacing")); |
|
476 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutHorizontalSpacing, QLatin1String("horizontalSpacing")); |
|
477 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutVerticalSpacing, QLatin1String("verticalSpacing")); |
|
478 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutSizeConstraint, QLatin1String("sizeConstraint")); |
|
479 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutFieldGrowthPolicy, QLatin1String("fieldGrowthPolicy")); |
|
480 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutRowWrapPolicy, QLatin1String("rowWrapPolicy")); |
|
481 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutLabelAlignment, QLatin1String("labelAlignment")); |
|
482 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutFormAlignment, QLatin1String("formAlignment")); |
|
483 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutBoxStretch, QLatin1String("stretch")); |
|
484 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridRowStretch, QLatin1String("rowStretch")); |
|
485 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridColumnStretch, QLatin1String("columnStretch")); |
|
486 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridRowMinimumHeight, QLatin1String("rowMinimumHeight")); |
|
487 |
typeNameMap.insert(QDesignerPropertySheet::PropertyLayoutGridColumnMinimumWidth, QLatin1String("columnMinimumWidth")); |
|
488 |
} |
|
489 |
const TypeNameMap::const_iterator it = typeNameMap.constFind(propertyType(index)); |
|
490 |
if (it != typeNameMap.constEnd()) |
|
491 |
return it.value(); |
|
492 |
return QString(); |
|
493 |
} |
|
494 |
||
495 |
// ----------- QDesignerPropertySheet |
|
496 |
||
497 |
QDesignerPropertySheet::ObjectType QDesignerPropertySheet::objectTypeFromObject(const QObject *o) |
|
498 |
{ |
|
499 |
if (qobject_cast<const QLayout *>(o)) |
|
500 |
return ObjectLayout; |
|
501 |
||
502 |
if (!o->isWidgetType()) |
|
503 |
return ObjectNone; |
|
504 |
||
505 |
if (qobject_cast<const QLayoutWidget *>(o)) |
|
506 |
return ObjectLayoutWidget; |
|
507 |
||
508 |
if (qobject_cast<const QLabel*>(o)) |
|
509 |
return ObjectLabel; |
|
510 |
||
511 |
if (o->inherits("Q3GroupBox")) |
|
512 |
return ObjectQ3GroupBox; |
|
513 |
||
514 |
return ObjectNone; |
|
515 |
} |
|
516 |
||
517 |
QDesignerPropertySheet::PropertyType QDesignerPropertySheet::propertyTypeFromName(const QString &name) |
|
518 |
{ |
|
519 |
typedef QHash<QString, PropertyType> PropertyTypeHash; |
|
520 |
static PropertyTypeHash propertyTypeHash; |
|
521 |
if (propertyTypeHash.empty()) { |
|
522 |
propertyTypeHash.insert(QLatin1String(layoutObjectNameC), PropertyLayoutObjectName); |
|
523 |
propertyTypeHash.insert(QLatin1String(layoutLeftMarginC), PropertyLayoutLeftMargin); |
|
524 |
propertyTypeHash.insert(QLatin1String(layoutTopMarginC), PropertyLayoutTopMargin); |
|
525 |
propertyTypeHash.insert(QLatin1String(layoutRightMarginC), PropertyLayoutRightMargin); |
|
526 |
propertyTypeHash.insert(QLatin1String(layoutBottomMarginC), PropertyLayoutBottomMargin); |
|
527 |
propertyTypeHash.insert(QLatin1String(layoutSpacingC), PropertyLayoutSpacing); |
|
528 |
propertyTypeHash.insert(QLatin1String(layoutHorizontalSpacingC), PropertyLayoutHorizontalSpacing); |
|
529 |
propertyTypeHash.insert(QLatin1String(layoutVerticalSpacingC), PropertyLayoutVerticalSpacing); |
|
530 |
propertyTypeHash.insert(QLatin1String(layoutSizeConstraintC), PropertyLayoutSizeConstraint); |
|
531 |
propertyTypeHash.insert(QLatin1String(layoutFieldGrowthPolicyC), PropertyLayoutFieldGrowthPolicy); |
|
532 |
propertyTypeHash.insert(QLatin1String(layoutRowWrapPolicyC), PropertyLayoutRowWrapPolicy); |
|
533 |
propertyTypeHash.insert(QLatin1String(layoutLabelAlignmentC), PropertyLayoutLabelAlignment); |
|
534 |
propertyTypeHash.insert(QLatin1String(layoutFormAlignmentC), PropertyLayoutFormAlignment); |
|
535 |
propertyTypeHash.insert(QLatin1String(layoutboxStretchPropertyC), PropertyLayoutBoxStretch); |
|
536 |
propertyTypeHash.insert(QLatin1String(layoutGridRowStretchPropertyC), PropertyLayoutGridRowStretch); |
|
537 |
propertyTypeHash.insert(QLatin1String(layoutGridColumnStretchPropertyC), PropertyLayoutGridColumnStretch); |
|
538 |
propertyTypeHash.insert(QLatin1String(layoutGridRowMinimumHeightC), PropertyLayoutGridRowMinimumHeight); |
|
539 |
propertyTypeHash.insert(QLatin1String(layoutGridColumnMinimumWidthC), PropertyLayoutGridColumnMinimumWidth); |
|
540 |
propertyTypeHash.insert(QLatin1String("buddy"), PropertyBuddy); |
|
541 |
propertyTypeHash.insert(QLatin1String("geometry"), PropertyGeometry); |
|
542 |
propertyTypeHash.insert(QLatin1String("checkable"), PropertyCheckable); |
|
543 |
propertyTypeHash.insert(QLatin1String("accessibleName"), PropertyAccessibility); |
|
544 |
propertyTypeHash.insert(QLatin1String("accessibleDescription"), PropertyAccessibility); |
|
545 |
propertyTypeHash.insert(QLatin1String("windowTitle"), PropertyWindowTitle); |
|
546 |
propertyTypeHash.insert(QLatin1String("windowIcon"), PropertyWindowIcon); |
|
547 |
propertyTypeHash.insert(QLatin1String("windowFilePath"), PropertyWindowFilePath); |
|
548 |
propertyTypeHash.insert(QLatin1String("windowOpacity"), PropertyWindowOpacity); |
|
549 |
propertyTypeHash.insert(QLatin1String("windowIconText"), PropertyWindowIconText); |
|
550 |
propertyTypeHash.insert(QLatin1String("windowModality"), PropertyWindowModality); |
|
551 |
propertyTypeHash.insert(QLatin1String("windowModified"), PropertyWindowModified); |
|
552 |
propertyTypeHash.insert(QLatin1String("styleSheet"), PropertyStyleSheet); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
553 |
propertyTypeHash.insert(QLatin1String("text"), PropertyText); |
0 | 554 |
} |
555 |
return propertyTypeHash.value(name, PropertyNone); |
|
556 |
} |
|
557 |
||
558 |
QDesignerPropertySheet::QDesignerPropertySheet(QObject *object, QObject *parent) : |
|
559 |
QObject(parent), |
|
560 |
d(new QDesignerPropertySheetPrivate(this, object, parent)) |
|
561 |
{ |
|
562 |
typedef QDesignerPropertySheetPrivate::Info Info; |
|
563 |
const QDesignerMetaObjectInterface *baseMeta = d->m_meta; |
|
564 |
||
565 |
while (baseMeta &&baseMeta->className().startsWith(QLatin1String("QDesigner"))) { |
|
566 |
baseMeta = baseMeta->superClass(); |
|
567 |
} |
|
568 |
Q_ASSERT(baseMeta != 0); |
|
569 |
||
570 |
QDesignerFormWindowInterface *formWindow = QDesignerFormWindowInterface::findFormWindow(d->m_object); |
|
571 |
d->m_fwb = qobject_cast<qdesigner_internal::FormWindowBase *>(formWindow); |
|
572 |
if (d->m_fwb) { |
|
573 |
d->m_pixmapCache = d->m_fwb->pixmapCache(); |
|
574 |
d->m_iconCache = d->m_fwb->iconCache(); |
|
575 |
d->m_fwb->addReloadablePropertySheet(this, object); |
|
576 |
} |
|
577 |
||
578 |
for (int index=0; index<count(); ++index) { |
|
579 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
580 |
const QString name = p->name(); |
|
581 |
if (p->type() == QVariant::KeySequence) { |
|
582 |
createFakeProperty(name); |
|
583 |
} else { |
|
584 |
setVisible(index, false); // use the default for `real' properties |
|
585 |
} |
|
586 |
||
587 |
QString pgroup = baseMeta->className(); |
|
588 |
||
589 |
if (const QDesignerMetaObjectInterface *pmeta = propertyIntroducedBy(baseMeta, index)) { |
|
590 |
pgroup = pmeta->className(); |
|
591 |
} |
|
592 |
||
593 |
Info &info = d->ensureInfo(index); |
|
594 |
info.group = pgroup; |
|
595 |
info.propertyType = propertyTypeFromName(name); |
|
596 |
||
597 |
if (p->type() == QVariant::Cursor || p->type() == QVariant::Icon || p->type() == QVariant::Pixmap) { |
|
598 |
info.defaultValue = p->read(d->m_object); |
|
599 |
if (p->type() == QVariant::Icon || p->type() == QVariant::Pixmap) |
|
600 |
d->addResourceProperty(index, p->type()); |
|
601 |
} else if (p->type() == QVariant::String) { |
|
602 |
d->addStringProperty(index); |
|
603 |
} else if (p->type() == QVariant::KeySequence) { |
|
604 |
d->addKeySequenceProperty(index); |
|
605 |
} |
|
606 |
} |
|
607 |
||
608 |
if (object->isWidgetType()) { |
|
609 |
createFakeProperty(QLatin1String("focusPolicy")); |
|
610 |
createFakeProperty(QLatin1String("cursor")); |
|
611 |
createFakeProperty(QLatin1String("toolTip")); |
|
612 |
createFakeProperty(QLatin1String("whatsThis")); |
|
613 |
createFakeProperty(QLatin1String("acceptDrops")); |
|
614 |
createFakeProperty(QLatin1String("dragEnabled")); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
615 |
// windowModality/Opacity is visible only for the main container, in which case the form windows enables it on loading |
0 | 616 |
setVisible(createFakeProperty(QLatin1String("windowModality")), false); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
617 |
setVisible(createFakeProperty(QLatin1String("windowOpacity"), double(1.0)), false); |
0 | 618 |
if (qobject_cast<const QToolBar *>(d->m_object)) { // prevent toolbars from being dragged off |
619 |
createFakeProperty(QLatin1String("floatable"), QVariant(true)); |
|
620 |
} else { |
|
621 |
if (qobject_cast<const QMenuBar *>(d->m_object)) { |
|
622 |
// Keep the menu bar editable in the form even if a native menu bar is used. |
|
623 |
const bool nativeMenuBarDefault = !qApp->testAttribute(Qt::AA_DontUseNativeMenuBar); |
|
624 |
createFakeProperty(QLatin1String("nativeMenuBar"), QVariant(nativeMenuBarDefault)); |
|
625 |
} |
|
626 |
} |
|
627 |
if (d->m_canHaveLayoutAttributes) { |
|
628 |
static const QString layoutGroup = QLatin1String("Layout"); |
|
629 |
const char* fakeLayoutProperties[] = { |
|
630 |
layoutObjectNameC, layoutLeftMarginC, layoutTopMarginC, layoutRightMarginC, layoutBottomMarginC, layoutSpacingC, layoutHorizontalSpacingC, layoutVerticalSpacingC, |
|
631 |
layoutFieldGrowthPolicyC, layoutRowWrapPolicyC, layoutLabelAlignmentC, layoutFormAlignmentC, |
|
632 |
layoutboxStretchPropertyC, layoutGridRowStretchPropertyC, layoutGridColumnStretchPropertyC, |
|
633 |
layoutGridRowMinimumHeightC, layoutGridColumnMinimumWidthC |
|
634 |
#ifdef USE_LAYOUT_SIZE_CONSTRAINT |
|
635 |
, layoutSizeConstraintC |
|
636 |
#endif |
|
637 |
}; |
|
638 |
const int fakeLayoutPropertyCount = sizeof(fakeLayoutProperties)/sizeof(const char*); |
|
639 |
const int size = count(); |
|
640 |
for (int i = 0; i < fakeLayoutPropertyCount; i++) { |
|
641 |
createFakeProperty(QLatin1String(fakeLayoutProperties[i]), 0); |
|
642 |
setAttribute(size + i, true); |
|
643 |
setPropertyGroup(size + i, layoutGroup); |
|
644 |
} |
|
645 |
} |
|
646 |
||
647 |
if (d->m_objectType == ObjectLabel) |
|
648 |
createFakeProperty(QLatin1String("buddy"), QVariant(QByteArray())); |
|
649 |
/* We need to create a fake property since the property does not work |
|
650 |
* for non-toplevel windows or on other systems than Mac and only if |
|
651 |
* it is above a certain Mac OS version. */ |
|
652 |
if (qobject_cast<const QMainWindow *>(d->m_object)) |
|
653 |
createFakeProperty(QLatin1String("unifiedTitleAndToolBarOnMac"), false); |
|
654 |
} |
|
655 |
||
656 |
if (qobject_cast<const QDialog*>(object)) { |
|
657 |
createFakeProperty(QLatin1String("modal")); |
|
658 |
} |
|
659 |
if (qobject_cast<const QDockWidget*>(object)) { |
|
660 |
createFakeProperty(QLatin1String("floating")); |
|
661 |
} |
|
662 |
||
663 |
typedef QList<QByteArray> ByteArrayList; |
|
664 |
const ByteArrayList names = object->dynamicPropertyNames(); |
|
665 |
if (!names.empty()) { |
|
666 |
const ByteArrayList::const_iterator cend = names.constEnd(); |
|
667 |
for (ByteArrayList::const_iterator it = names.constBegin(); it != cend; ++it) { |
|
668 |
const char* cName = it->constData(); |
|
669 |
const QString name = QString::fromLatin1(cName); |
|
670 |
const int idx = addDynamicProperty(name, object->property(cName)); |
|
671 |
if (idx != -1) |
|
672 |
d->ensureInfo(idx).kind = QDesignerPropertySheetPrivate::DefaultDynamicProperty; |
|
673 |
} |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
QDesignerPropertySheet::~QDesignerPropertySheet() |
|
678 |
{ |
|
679 |
if (d->m_fwb) |
|
680 |
d->m_fwb->removeReloadablePropertySheet(this); |
|
681 |
delete d; |
|
682 |
} |
|
683 |
||
684 |
QObject *QDesignerPropertySheet::object() const |
|
685 |
{ |
|
686 |
return d->m_object; |
|
687 |
} |
|
688 |
||
689 |
bool QDesignerPropertySheet::dynamicPropertiesAllowed() const |
|
690 |
{ |
|
691 |
return true; |
|
692 |
} |
|
693 |
||
694 |
bool QDesignerPropertySheet::canAddDynamicProperty(const QString &propName) const |
|
695 |
{ |
|
696 |
const int index = d->m_meta->indexOfProperty(propName); |
|
697 |
if (index != -1) |
|
698 |
return false; // property already exists and is not a dynamic one |
|
699 |
if (d->m_addIndex.contains(propName)) { |
|
700 |
const int idx = d->m_addIndex.value(propName); |
|
701 |
if (isVisible(idx)) |
|
702 |
return false; // dynamic property already exists |
|
703 |
else |
|
704 |
return true; |
|
705 |
} |
|
706 |
if (!QDesignerPropertySheet::internalDynamicPropertiesEnabled() && propName.startsWith(QLatin1String("_q_"))) |
|
707 |
return false; |
|
708 |
return true; |
|
709 |
} |
|
710 |
||
711 |
int QDesignerPropertySheet::addDynamicProperty(const QString &propName, const QVariant &value) |
|
712 |
{ |
|
713 |
typedef QDesignerPropertySheetPrivate::Info Info; |
|
714 |
if (!value.isValid()) |
|
715 |
return -1; // property has invalid type |
|
716 |
if (!canAddDynamicProperty(propName)) |
|
717 |
return -1; |
|
718 |
||
719 |
QVariant v = value; |
|
720 |
if (value.type() == QVariant::Icon) |
|
721 |
v = qVariantFromValue(qdesigner_internal::PropertySheetIconValue()); |
|
722 |
else if (value.type() == QVariant::Pixmap) |
|
723 |
v = qVariantFromValue(qdesigner_internal::PropertySheetPixmapValue()); |
|
724 |
else if (value.type() == QVariant::String) |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
725 |
v = qVariantFromValue(qdesigner_internal::PropertySheetStringValue(value.toString())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
726 |
else if (value.type() == QVariant::KeySequence) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
727 |
const QKeySequence keySequence = qVariantValue<QKeySequence>(value); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
728 |
v = qVariantFromValue(qdesigner_internal::PropertySheetKeySequenceValue(keySequence)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
729 |
} |
0 | 730 |
|
731 |
if (d->m_addIndex.contains(propName)) { |
|
732 |
const int idx = d->m_addIndex.value(propName); |
|
733 |
// have to be invisible, this was checked in canAddDynamicProperty() method |
|
734 |
setVisible(idx, true); |
|
735 |
d->m_addProperties.insert(idx, v); |
|
736 |
setChanged(idx, false); |
|
737 |
const int index = d->m_meta->indexOfProperty(propName); |
|
738 |
Info &info = d->ensureInfo(index); |
|
739 |
info.defaultValue = value; |
|
740 |
info.kind = QDesignerPropertySheetPrivate::DynamicProperty; |
|
741 |
if (value.type() == QVariant::Icon || value.type() == QVariant::Pixmap) |
|
742 |
d->addResourceProperty(idx, value.type()); |
|
743 |
else if (value.type() == QVariant::String) |
|
744 |
d->addStringProperty(idx); |
|
745 |
else if (value.type() == QVariant::KeySequence) |
|
746 |
d->addKeySequenceProperty(idx); |
|
747 |
return idx; |
|
748 |
} |
|
749 |
||
750 |
const int index = count(); |
|
751 |
d->m_addIndex.insert(propName, index); |
|
752 |
d->m_addProperties.insert(index, v); |
|
753 |
Info &info = d->ensureInfo(index); |
|
754 |
info.visible = true; |
|
755 |
info.changed = false; |
|
756 |
info.defaultValue = value; |
|
757 |
info.kind = QDesignerPropertySheetPrivate::DynamicProperty; |
|
758 |
setPropertyGroup(index, tr("Dynamic Properties")); |
|
759 |
if (value.type() == QVariant::Icon || value.type() == QVariant::Pixmap) |
|
760 |
d->addResourceProperty(index, value.type()); |
|
761 |
else if (value.type() == QVariant::String) |
|
762 |
d->addStringProperty(index); |
|
763 |
else if (value.type() == QVariant::KeySequence) |
|
764 |
d->addKeySequenceProperty(index); |
|
765 |
return index; |
|
766 |
} |
|
767 |
||
768 |
bool QDesignerPropertySheet::removeDynamicProperty(int index) |
|
769 |
{ |
|
770 |
if (!d->m_addIndex.contains(propertyName(index))) |
|
771 |
return false; |
|
772 |
||
773 |
setVisible(index, false); |
|
774 |
return true; |
|
775 |
} |
|
776 |
||
777 |
bool QDesignerPropertySheet::isDynamic(int index) const |
|
778 |
{ |
|
779 |
if (!d->m_addProperties.contains(index)) |
|
780 |
return false; |
|
781 |
||
782 |
switch (propertyType(index)) { |
|
783 |
case PropertyBuddy: |
|
784 |
if (d->m_objectType == ObjectLabel) |
|
785 |
return false; |
|
786 |
break; |
|
787 |
case PropertyLayoutLeftMargin: |
|
788 |
case PropertyLayoutTopMargin: |
|
789 |
case PropertyLayoutRightMargin: |
|
790 |
case PropertyLayoutBottomMargin: |
|
791 |
case PropertyLayoutSpacing: |
|
792 |
case PropertyLayoutHorizontalSpacing: |
|
793 |
case PropertyLayoutVerticalSpacing: |
|
794 |
case PropertyLayoutObjectName: |
|
795 |
case PropertyLayoutSizeConstraint: |
|
796 |
case PropertyLayoutFieldGrowthPolicy: |
|
797 |
case PropertyLayoutRowWrapPolicy: |
|
798 |
case PropertyLayoutLabelAlignment: |
|
799 |
case PropertyLayoutFormAlignment: |
|
800 |
case PropertyLayoutBoxStretch: |
|
801 |
case PropertyLayoutGridRowStretch: |
|
802 |
case PropertyLayoutGridColumnStretch: |
|
803 |
case PropertyLayoutGridRowMinimumHeight: |
|
804 |
case PropertyLayoutGridColumnMinimumWidth: |
|
805 |
if (d->m_object->isWidgetType() && d->m_canHaveLayoutAttributes) |
|
806 |
return false; |
|
807 |
default: |
|
808 |
break; |
|
809 |
} |
|
810 |
return true; |
|
811 |
} |
|
812 |
||
813 |
bool QDesignerPropertySheet::isDynamicProperty(int index) const |
|
814 |
{ |
|
815 |
// Do not complain here, as an invalid index might be encountered |
|
816 |
// if someone implements a property sheet only, omitting the dynamic sheet. |
|
817 |
if (index < 0 || index >= count()) |
|
818 |
return false; |
|
819 |
return d->m_info.value(index).kind == QDesignerPropertySheetPrivate::DynamicProperty; |
|
820 |
} |
|
821 |
||
822 |
bool QDesignerPropertySheet::isDefaultDynamicProperty(int index) const |
|
823 |
{ |
|
824 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
825 |
return false; |
|
826 |
return d->m_info.value(index).kind == QDesignerPropertySheetPrivate::DefaultDynamicProperty; |
|
827 |
} |
|
828 |
||
829 |
bool QDesignerPropertySheet::isResourceProperty(int index) const |
|
830 |
{ |
|
831 |
return d->isResourceProperty(index); |
|
832 |
} |
|
833 |
||
834 |
QVariant QDesignerPropertySheet::defaultResourceProperty(int index) const |
|
835 |
{ |
|
836 |
return d->defaultResourceProperty(index); |
|
837 |
} |
|
838 |
||
839 |
qdesigner_internal::DesignerPixmapCache *QDesignerPropertySheet::pixmapCache() const |
|
840 |
{ |
|
841 |
return d->m_pixmapCache; |
|
842 |
} |
|
843 |
||
844 |
void QDesignerPropertySheet::setPixmapCache(qdesigner_internal::DesignerPixmapCache *cache) |
|
845 |
{ |
|
846 |
d->m_pixmapCache = cache; |
|
847 |
} |
|
848 |
||
849 |
qdesigner_internal::DesignerIconCache *QDesignerPropertySheet::iconCache() const |
|
850 |
{ |
|
851 |
return d->m_iconCache; |
|
852 |
} |
|
853 |
||
854 |
void QDesignerPropertySheet::setIconCache(qdesigner_internal::DesignerIconCache *cache) |
|
855 |
{ |
|
856 |
d->m_iconCache = cache; |
|
857 |
} |
|
858 |
||
859 |
int QDesignerPropertySheet::createFakeProperty(const QString &propertyName, const QVariant &value) |
|
860 |
{ |
|
861 |
typedef QDesignerPropertySheetPrivate::Info Info; |
|
862 |
// fake properties |
|
863 |
const int index = d->m_meta->indexOfProperty(propertyName); |
|
864 |
if (index != -1) { |
|
865 |
if (!(d->m_meta->property(index)->attributes() & QDesignerMetaPropertyInterface::DesignableAttribute)) |
|
866 |
return -1; |
|
867 |
Info &info = d->ensureInfo(index); |
|
868 |
info.visible = false; |
|
869 |
info.kind = QDesignerPropertySheetPrivate::FakeProperty; |
|
870 |
QVariant v = value.isValid() ? value : metaProperty(index); |
|
871 |
if (v.type() == QVariant::String) |
|
872 |
v = qVariantFromValue(qdesigner_internal::PropertySheetStringValue()); |
|
873 |
if (v.type() == QVariant::KeySequence) |
|
874 |
v = qVariantFromValue(qdesigner_internal::PropertySheetKeySequenceValue()); |
|
875 |
d->m_fakeProperties.insert(index, v); |
|
876 |
return index; |
|
877 |
} |
|
878 |
if (!value.isValid()) |
|
879 |
return -1; |
|
880 |
||
881 |
const int newIndex = count(); |
|
882 |
d->m_addIndex.insert(propertyName, newIndex); |
|
883 |
d->m_addProperties.insert(newIndex, value); |
|
884 |
Info &info = d->ensureInfo(newIndex); |
|
885 |
info.propertyType = propertyTypeFromName(propertyName); |
|
886 |
info.kind = QDesignerPropertySheetPrivate::FakeProperty; |
|
887 |
return newIndex; |
|
888 |
} |
|
889 |
||
890 |
bool QDesignerPropertySheet::isAdditionalProperty(int index) const |
|
891 |
{ |
|
892 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
893 |
return false; |
|
894 |
return d->m_addProperties.contains(index); |
|
895 |
} |
|
896 |
||
897 |
bool QDesignerPropertySheet::isFakeProperty(int index) const |
|
898 |
{ |
|
899 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
900 |
return false; |
|
901 |
// additional properties must be fake |
|
902 |
return (d->m_fakeProperties.contains(index) || isAdditionalProperty(index)); |
|
903 |
} |
|
904 |
||
905 |
int QDesignerPropertySheet::count() const |
|
906 |
{ |
|
907 |
return d->count(); |
|
908 |
} |
|
909 |
||
910 |
int QDesignerPropertySheet::indexOf(const QString &name) const |
|
911 |
{ |
|
912 |
int index = d->m_meta->indexOfProperty(name); |
|
913 |
||
914 |
if (index == -1) |
|
915 |
index = d->m_addIndex.value(name, -1); |
|
916 |
||
917 |
return index; |
|
918 |
} |
|
919 |
||
920 |
QDesignerPropertySheet::PropertyType QDesignerPropertySheet::propertyType(int index) const |
|
921 |
{ |
|
922 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
923 |
return PropertyNone; |
|
924 |
return d->propertyType(index); |
|
925 |
} |
|
926 |
||
927 |
QDesignerPropertySheet::ObjectType QDesignerPropertySheet::objectType() const |
|
928 |
{ |
|
929 |
return d->m_objectType; |
|
930 |
} |
|
931 |
||
932 |
QString QDesignerPropertySheet::propertyName(int index) const |
|
933 |
{ |
|
934 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
935 |
return QString(); |
|
936 |
if (isAdditionalProperty(index)) |
|
937 |
return d->m_addIndex.key(index); |
|
938 |
||
939 |
return d->m_meta->property(index)->name(); |
|
940 |
} |
|
941 |
||
942 |
QString QDesignerPropertySheet::propertyGroup(int index) const |
|
943 |
{ |
|
944 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
945 |
return QString(); |
|
946 |
const QString g = d->m_info.value(index).group; |
|
947 |
||
948 |
if (!g.isEmpty()) |
|
949 |
return g; |
|
950 |
||
951 |
if (propertyType(index) == PropertyAccessibility) |
|
952 |
return QString::fromUtf8("Accessibility"); |
|
953 |
||
954 |
if (isAdditionalProperty(index)) |
|
955 |
return d->m_meta->className(); |
|
956 |
||
957 |
return g; |
|
958 |
} |
|
959 |
||
960 |
void QDesignerPropertySheet::setPropertyGroup(int index, const QString &group) |
|
961 |
{ |
|
962 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
963 |
return; |
|
964 |
d->ensureInfo(index).group = group; |
|
965 |
} |
|
966 |
||
967 |
QVariant QDesignerPropertySheet::property(int index) const |
|
968 |
{ |
|
969 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
970 |
return QVariant(); |
|
971 |
if (isAdditionalProperty(index)) { |
|
972 |
if (isFakeLayoutProperty(index)) { |
|
973 |
QDesignerPropertySheetExtension *layoutPropertySheet; |
|
974 |
if (d->layout(&layoutPropertySheet) && layoutPropertySheet) { |
|
975 |
const QString newPropName = d->transformLayoutPropertyName(index); |
|
976 |
if (!newPropName.isEmpty()) { |
|
977 |
const int newIndex = layoutPropertySheet->indexOf(newPropName); |
|
978 |
if (newIndex != -1) |
|
979 |
return layoutPropertySheet->property(newIndex); |
|
980 |
return QVariant(); |
|
981 |
} |
|
982 |
} |
|
983 |
} |
|
984 |
return d->m_addProperties.value(index); |
|
985 |
} |
|
986 |
||
987 |
if (isFakeProperty(index)) { |
|
988 |
return d->m_fakeProperties.value(index); |
|
989 |
} |
|
990 |
||
991 |
if (d->isResourceProperty(index)) |
|
992 |
return d->resourceProperty(index); |
|
993 |
||
994 |
if (d->isStringProperty(index)) { |
|
995 |
QString strValue = metaProperty(index).toString(); |
|
996 |
qdesigner_internal::PropertySheetStringValue value = d->stringProperty(index); |
|
997 |
if (strValue != value.value()) { |
|
998 |
value.setValue(strValue); |
|
999 |
d->setStringProperty(index, value); // cache it |
|
1000 |
} |
|
1001 |
return qVariantFromValue(value); |
|
1002 |
} |
|
1003 |
||
1004 |
if (d->isKeySequenceProperty(index)) { |
|
1005 |
QKeySequence keyValue = qVariantValue<QKeySequence>(metaProperty(index)); |
|
1006 |
qdesigner_internal::PropertySheetKeySequenceValue value = d->keySequenceProperty(index); |
|
1007 |
if (keyValue != value.value()) { |
|
1008 |
value.setValue(keyValue); |
|
1009 |
d->setKeySequenceProperty(index, value); // cache it |
|
1010 |
} |
|
1011 |
return qVariantFromValue(value); |
|
1012 |
} |
|
1013 |
||
1014 |
return metaProperty(index); |
|
1015 |
} |
|
1016 |
||
1017 |
QVariant QDesignerPropertySheet::metaProperty(int index) const |
|
1018 |
{ |
|
1019 |
Q_ASSERT(!isFakeProperty(index)); |
|
1020 |
||
1021 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
1022 |
QVariant v = p->read(d->m_object); |
|
1023 |
switch (p->kind()) { |
|
1024 |
case QDesignerMetaPropertyInterface::FlagKind: { |
|
1025 |
qdesigner_internal::PropertySheetFlagValue psflags = qdesigner_internal::PropertySheetFlagValue(v.toInt(), designerMetaFlagsFor(p->enumerator())); |
|
1026 |
qVariantSetValue(v, psflags); |
|
1027 |
} |
|
1028 |
break; |
|
1029 |
case QDesignerMetaPropertyInterface::EnumKind: { |
|
1030 |
qdesigner_internal::PropertySheetEnumValue pse = qdesigner_internal::PropertySheetEnumValue(v.toInt(), designerMetaEnumFor(p->enumerator())); |
|
1031 |
qVariantSetValue(v, pse); |
|
1032 |
} |
|
1033 |
break; |
|
1034 |
case QDesignerMetaPropertyInterface::OtherKind: |
|
1035 |
break; |
|
1036 |
} |
|
1037 |
return v; |
|
1038 |
} |
|
1039 |
||
1040 |
QVariant QDesignerPropertySheet::resolvePropertyValue(int index, const QVariant &value) const |
|
1041 |
{ |
|
1042 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetEnumValue>(value)) |
|
1043 |
return qvariant_cast<qdesigner_internal::PropertySheetEnumValue>(value).value; |
|
1044 |
||
1045 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetFlagValue>(value)) |
|
1046 |
return qvariant_cast<qdesigner_internal::PropertySheetFlagValue>(value).value; |
|
1047 |
||
1048 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetStringValue>(value)) |
|
1049 |
return qVariantValue<qdesigner_internal::PropertySheetStringValue>(value).value(); |
|
1050 |
||
1051 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetKeySequenceValue>(value)) |
|
1052 |
return qVariantValue<qdesigner_internal::PropertySheetKeySequenceValue>(value).value(); |
|
1053 |
||
1054 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetPixmapValue>(value)) { |
|
1055 |
const QString path = qVariantValue<qdesigner_internal::PropertySheetPixmapValue>(value).path(); |
|
1056 |
if (path.isEmpty()) |
|
1057 |
return defaultResourceProperty(index); |
|
1058 |
if (d->m_pixmapCache) { |
|
1059 |
return d->m_pixmapCache->pixmap(qvariant_cast<qdesigner_internal::PropertySheetPixmapValue>(value)); |
|
1060 |
} |
|
1061 |
} |
|
1062 |
||
1063 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetIconValue>(value)) { |
|
1064 |
const int pathCount = qVariantValue<qdesigner_internal::PropertySheetIconValue>(value).paths().count(); |
|
1065 |
if (pathCount == 0) |
|
1066 |
return defaultResourceProperty(index); |
|
1067 |
if (d->m_iconCache) |
|
1068 |
return d->m_iconCache->icon(qvariant_cast<qdesigner_internal::PropertySheetIconValue>(value)); |
|
1069 |
} |
|
1070 |
||
1071 |
return value; |
|
1072 |
} |
|
1073 |
||
1074 |
void QDesignerPropertySheet::setFakeProperty(int index, const QVariant &value) |
|
1075 |
{ |
|
1076 |
Q_ASSERT(isFakeProperty(index)); |
|
1077 |
||
1078 |
QVariant &v = d->m_fakeProperties[index]; |
|
1079 |
||
1080 |
// set resource properties also (if we are going to have fake resource properties) |
|
1081 |
if (qVariantCanConvert<qdesigner_internal::PropertySheetFlagValue>(value) || qVariantCanConvert<qdesigner_internal::PropertySheetEnumValue>(value)) { |
|
1082 |
v = value; |
|
1083 |
} else if (qVariantCanConvert<qdesigner_internal::PropertySheetFlagValue>(v)) { |
|
1084 |
qdesigner_internal::PropertySheetFlagValue f = qvariant_cast<qdesigner_internal::PropertySheetFlagValue>(v); |
|
1085 |
f.value = value.toInt(); |
|
1086 |
qVariantSetValue(v, f); |
|
1087 |
Q_ASSERT(value.type() == QVariant::Int); |
|
1088 |
} else if (qVariantCanConvert<qdesigner_internal::PropertySheetEnumValue>(v)) { |
|
1089 |
qdesigner_internal::PropertySheetEnumValue e = qvariant_cast<qdesigner_internal::PropertySheetEnumValue>(v); |
|
1090 |
e.value = value.toInt(); |
|
1091 |
qVariantSetValue(v, e); |
|
1092 |
Q_ASSERT(value.type() == QVariant::Int); |
|
1093 |
} else { |
|
1094 |
v = value; |
|
1095 |
} |
|
1096 |
} |
|
1097 |
||
1098 |
void QDesignerPropertySheet::clearFakeProperties() |
|
1099 |
{ |
|
1100 |
d->m_fakeProperties.clear(); |
|
1101 |
} |
|
1102 |
||
1103 |
// Buddy needs to be byte array, else uic won't work |
|
1104 |
static QVariant toByteArray(const QVariant &value) { |
|
1105 |
if (value.type() == QVariant::ByteArray) |
|
1106 |
return value; |
|
1107 |
const QByteArray ba = value.toString().toUtf8(); |
|
1108 |
return QVariant(ba); |
|
1109 |
} |
|
1110 |
||
1111 |
void QDesignerPropertySheet::setProperty(int index, const QVariant &value) |
|
1112 |
{ |
|
1113 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1114 |
return; |
|
1115 |
if (isAdditionalProperty(index)) { |
|
1116 |
if (d->m_objectType == ObjectLabel && propertyType(index) == PropertyBuddy) { |
|
1117 |
QFormBuilderExtra::applyBuddy(value.toString(), QFormBuilderExtra::BuddyApplyVisibleOnly, qobject_cast<QLabel *>(d->m_object)); |
|
1118 |
d->m_addProperties[index] = toByteArray(value); |
|
1119 |
return; |
|
1120 |
} |
|
1121 |
||
1122 |
if (isFakeLayoutProperty(index)) { |
|
1123 |
QDesignerPropertySheetExtension *layoutPropertySheet; |
|
1124 |
if (d->layout(&layoutPropertySheet) && layoutPropertySheet) { |
|
1125 |
const QString newPropName = d->transformLayoutPropertyName(index); |
|
1126 |
if (!newPropName.isEmpty()) { |
|
1127 |
const int newIndex = layoutPropertySheet->indexOf(newPropName); |
|
1128 |
if (newIndex != -1) |
|
1129 |
layoutPropertySheet->setProperty(newIndex, value); |
|
1130 |
} |
|
1131 |
} |
|
1132 |
} |
|
1133 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1134 |
if (isDynamicProperty(index) || isDefaultDynamicProperty(index)) { |
0 | 1135 |
if (d->isResourceProperty(index)) |
1136 |
d->setResourceProperty(index, value); |
|
1137 |
if (d->isStringProperty(index)) |
|
1138 |
d->setStringProperty(index, qVariantValue<qdesigner_internal::PropertySheetStringValue>(value)); |
|
1139 |
if (d->isKeySequenceProperty(index)) |
|
1140 |
d->setKeySequenceProperty(index, qVariantValue<qdesigner_internal::PropertySheetKeySequenceValue>(value)); |
|
1141 |
d->m_object->setProperty(propertyName(index).toUtf8(), resolvePropertyValue(index, value)); |
|
1142 |
if (d->m_object->isWidgetType()) { |
|
1143 |
QWidget *w = qobject_cast<QWidget *>(d->m_object); |
|
1144 |
w->setStyleSheet(w->styleSheet()); |
|
1145 |
} |
|
1146 |
} |
|
1147 |
d->m_addProperties[index] = value; |
|
1148 |
} else if (isFakeProperty(index)) { |
|
1149 |
setFakeProperty(index, value); |
|
1150 |
} else { |
|
1151 |
if (d->isResourceProperty(index)) |
|
1152 |
d->setResourceProperty(index, value); |
|
1153 |
if (d->isStringProperty(index)) |
|
1154 |
d->setStringProperty(index, qVariantValue<qdesigner_internal::PropertySheetStringValue>(value)); |
|
1155 |
if (d->isKeySequenceProperty(index)) |
|
1156 |
d->setKeySequenceProperty(index, qVariantValue<qdesigner_internal::PropertySheetKeySequenceValue>(value)); |
|
1157 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
1158 |
p->write(d->m_object, resolvePropertyValue(index, value)); |
|
1159 |
if (qobject_cast<QGroupBox *>(d->m_object) && propertyType(index) == PropertyCheckable) { |
|
1160 |
const int idx = indexOf(QLatin1String("focusPolicy")); |
|
1161 |
if (!isChanged(idx)) { |
|
1162 |
qdesigner_internal::PropertySheetEnumValue e = qVariantValue<qdesigner_internal::PropertySheetEnumValue>(property(idx)); |
|
1163 |
if (value.toBool()) { |
|
1164 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(idx); |
|
1165 |
p->write(d->m_object, Qt::NoFocus); |
|
1166 |
e.value = Qt::StrongFocus; |
|
1167 |
QVariant v; |
|
1168 |
qVariantSetValue(v, e); |
|
1169 |
setFakeProperty(idx, v); |
|
1170 |
} else { |
|
1171 |
e.value = Qt::NoFocus; |
|
1172 |
QVariant v; |
|
1173 |
qVariantSetValue(v, e); |
|
1174 |
setFakeProperty(idx, v); |
|
1175 |
} |
|
1176 |
} |
|
1177 |
} |
|
1178 |
} |
|
1179 |
} |
|
1180 |
||
1181 |
bool QDesignerPropertySheet::hasReset(int index) const |
|
1182 |
{ |
|
1183 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1184 |
return false; |
|
1185 |
if (isAdditionalProperty(index)) |
|
1186 |
return d->m_info.value(index).reset; |
|
1187 |
return true; |
|
1188 |
} |
|
1189 |
||
1190 |
bool QDesignerPropertySheet::reset(int index) |
|
1191 |
{ |
|
1192 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1193 |
return false; |
|
1194 |
if (d->isStringProperty(index)) |
|
1195 |
setProperty(index, qVariantFromValue(qdesigner_internal::PropertySheetStringValue())); |
|
1196 |
if (d->isKeySequenceProperty(index)) |
|
1197 |
setProperty(index, qVariantFromValue(qdesigner_internal::PropertySheetKeySequenceValue())); |
|
1198 |
if (d->isResourceProperty(index)) { |
|
1199 |
setProperty(index, d->emptyResourceProperty(index)); |
|
1200 |
return true; |
|
1201 |
} else if (isDynamic(index)) { |
|
1202 |
const QString propName = propertyName(index); |
|
1203 |
const QVariant oldValue = d->m_addProperties.value(index); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1204 |
const QVariant defaultValue = d->m_info.value(index).defaultValue; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1205 |
QVariant newValue = defaultValue; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1206 |
if (d->isStringProperty(index)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1207 |
newValue = qVariantFromValue(qdesigner_internal::PropertySheetStringValue(newValue.toString())); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1208 |
} else if (d->isKeySequenceProperty(index)) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1209 |
const QKeySequence keySequence = qVariantValue<QKeySequence>(newValue); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1210 |
newValue = qVariantFromValue(qdesigner_internal::PropertySheetKeySequenceValue(keySequence)); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1211 |
} |
0 | 1212 |
if (oldValue == newValue) |
1213 |
return true; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1214 |
d->m_object->setProperty(propName.toUtf8(), defaultValue); |
0 | 1215 |
d->m_addProperties[index] = newValue; |
1216 |
return true; |
|
1217 |
} else if (!d->m_info.value(index).defaultValue.isNull()) { |
|
1218 |
setProperty(index, d->m_info.value(index).defaultValue); |
|
1219 |
return true; |
|
1220 |
} |
|
1221 |
if (isAdditionalProperty(index)) { |
|
1222 |
const PropertyType pType = propertyType(index); |
|
1223 |
if (d->m_objectType == ObjectLabel && pType == PropertyBuddy) { |
|
1224 |
setProperty(index, QVariant(QByteArray())); |
|
1225 |
return true; |
|
1226 |
} |
|
1227 |
if (isFakeLayoutProperty(index)) { |
|
1228 |
// special properties |
|
1229 |
switch (pType) { |
|
1230 |
case PropertyLayoutObjectName: |
|
1231 |
setProperty(index, QString()); |
|
1232 |
return true; |
|
1233 |
case PropertyLayoutSizeConstraint: |
|
1234 |
setProperty(index, QVariant(QLayout::SetDefaultConstraint)); |
|
1235 |
return true; |
|
1236 |
case PropertyLayoutBoxStretch: |
|
1237 |
case PropertyLayoutGridRowStretch: |
|
1238 |
case PropertyLayoutGridColumnStretch: |
|
1239 |
case PropertyLayoutGridRowMinimumHeight: |
|
1240 |
case PropertyLayoutGridColumnMinimumWidth: |
|
1241 |
case PropertyLayoutFieldGrowthPolicy: |
|
1242 |
case PropertyLayoutRowWrapPolicy: |
|
1243 |
case PropertyLayoutLabelAlignment: |
|
1244 |
case PropertyLayoutFormAlignment: { |
|
1245 |
QDesignerPropertySheetExtension *layoutPropertySheet; |
|
1246 |
if (d->layout(&layoutPropertySheet) && layoutPropertySheet) |
|
1247 |
return layoutPropertySheet->reset(layoutPropertySheet->indexOf(d->transformLayoutPropertyName(index))); |
|
1248 |
} |
|
1249 |
break; |
|
1250 |
default: |
|
1251 |
break; |
|
1252 |
} |
|
1253 |
// special margins |
|
1254 |
int value = -1; |
|
1255 |
switch (d->m_objectType) { |
|
1256 |
case ObjectQ3GroupBox: { |
|
1257 |
const QWidget *w = qobject_cast<const QWidget *>(d->m_object); |
|
1258 |
switch (pType) { |
|
1259 |
case PropertyLayoutLeftMargin: |
|
1260 |
value = w->style()->pixelMetric(QStyle::PM_LayoutLeftMargin); |
|
1261 |
break; |
|
1262 |
case PropertyLayoutTopMargin: |
|
1263 |
value = w->style()->pixelMetric(QStyle::PM_LayoutTopMargin); |
|
1264 |
break; |
|
1265 |
case PropertyLayoutRightMargin: |
|
1266 |
value = w->style()->pixelMetric(QStyle::PM_LayoutRightMargin); |
|
1267 |
break; |
|
1268 |
case PropertyLayoutBottomMargin: |
|
1269 |
value = w->style()->pixelMetric(QStyle::PM_LayoutBottomMargin); |
|
1270 |
break; |
|
1271 |
case PropertyLayoutSpacing: |
|
1272 |
case PropertyLayoutHorizontalSpacing: |
|
1273 |
case PropertyLayoutVerticalSpacing: |
|
1274 |
value = -1; |
|
1275 |
break; |
|
1276 |
default: |
|
1277 |
break; |
|
1278 |
} |
|
1279 |
} |
|
1280 |
break; |
|
1281 |
case ObjectLayoutWidget: |
|
1282 |
if (pType == PropertyLayoutLeftMargin || |
|
1283 |
pType == PropertyLayoutTopMargin || |
|
1284 |
pType == PropertyLayoutRightMargin || |
|
1285 |
pType == PropertyLayoutBottomMargin) |
|
1286 |
value = 0; |
|
1287 |
break; |
|
1288 |
default: |
|
1289 |
break; |
|
1290 |
} |
|
1291 |
setProperty(index, value); |
|
1292 |
return true; |
|
1293 |
} |
|
1294 |
return false; |
|
1295 |
} else if (isFakeProperty(index)) { |
|
1296 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
1297 |
const bool result = p->reset(d->m_object); |
|
1298 |
d->m_fakeProperties[index] = p->read(d->m_object); |
|
1299 |
return result; |
|
1300 |
} else if (propertyType(index) == PropertyGeometry && d->m_object->isWidgetType()) { |
|
1301 |
if (QWidget *w = qobject_cast<QWidget*>(d->m_object)) { |
|
1302 |
QWidget *widget = w; |
|
1303 |
if (qdesigner_internal::Utils::isCentralWidget(d->m_fwb, widget) && d->m_fwb->parentWidget()) |
|
1304 |
widget = d->m_fwb->parentWidget(); |
|
1305 |
||
1306 |
if (widget != w && widget->parentWidget()) { |
|
1307 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
|
1308 |
widget->parentWidget()->adjustSize(); |
|
1309 |
} |
|
1310 |
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents); |
|
1311 |
widget->adjustSize(); |
|
1312 |
return true; |
|
1313 |
} |
|
1314 |
} |
|
1315 |
// ### TODO: reset for fake properties. |
|
1316 |
||
1317 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
1318 |
return p->reset(d->m_object); |
|
1319 |
} |
|
1320 |
||
1321 |
bool QDesignerPropertySheet::isChanged(int index) const |
|
1322 |
{ |
|
1323 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1324 |
return false; |
|
1325 |
if (isAdditionalProperty(index)) { |
|
1326 |
if (isFakeLayoutProperty(index)) { |
|
1327 |
QDesignerPropertySheetExtension *layoutPropertySheet; |
|
1328 |
if (d->layout(&layoutPropertySheet) && layoutPropertySheet) { |
|
1329 |
const QString newPropName = d->transformLayoutPropertyName(index); |
|
1330 |
if (!newPropName.isEmpty()) { |
|
1331 |
const int newIndex = layoutPropertySheet->indexOf(newPropName); |
|
1332 |
if (newIndex != -1) |
|
1333 |
return layoutPropertySheet->isChanged(newIndex); |
|
1334 |
return false; |
|
1335 |
} |
|
1336 |
} |
|
1337 |
} |
|
1338 |
} |
|
1339 |
return d->m_info.value(index).changed; |
|
1340 |
} |
|
1341 |
||
1342 |
void QDesignerPropertySheet::setChanged(int index, bool changed) |
|
1343 |
{ |
|
1344 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1345 |
return; |
|
1346 |
if (isAdditionalProperty(index)) { |
|
1347 |
if (isFakeLayoutProperty(index)) { |
|
1348 |
QDesignerPropertySheetExtension *layoutPropertySheet; |
|
1349 |
if (d->layout(&layoutPropertySheet) && layoutPropertySheet) { |
|
1350 |
const QString newPropName = d->transformLayoutPropertyName(index); |
|
1351 |
if (!newPropName.isEmpty()) { |
|
1352 |
const int newIndex = layoutPropertySheet->indexOf(newPropName); |
|
1353 |
if (newIndex != -1) |
|
1354 |
layoutPropertySheet->setChanged(newIndex, changed); |
|
1355 |
} |
|
1356 |
} |
|
1357 |
} |
|
1358 |
} |
|
1359 |
if (d->isReloadableProperty(index)) { |
|
1360 |
if (d->m_fwb) { |
|
1361 |
if (changed) |
|
1362 |
d->m_fwb->addReloadableProperty(this, index); |
|
1363 |
else |
|
1364 |
d->m_fwb->removeReloadableProperty(this, index); |
|
1365 |
} |
|
1366 |
} |
|
1367 |
d->ensureInfo(index).changed = changed; |
|
1368 |
} |
|
1369 |
||
1370 |
bool QDesignerPropertySheet::isFakeLayoutProperty(int index) const |
|
1371 |
{ |
|
1372 |
if (!isAdditionalProperty(index)) |
|
1373 |
return false; |
|
1374 |
||
1375 |
switch (propertyType(index)) { |
|
1376 |
case PropertyLayoutObjectName: |
|
1377 |
case PropertyLayoutSizeConstraint: |
|
1378 |
return true; |
|
1379 |
case PropertyLayoutLeftMargin: |
|
1380 |
case PropertyLayoutTopMargin: |
|
1381 |
case PropertyLayoutRightMargin: |
|
1382 |
case PropertyLayoutBottomMargin: |
|
1383 |
case PropertyLayoutSpacing: |
|
1384 |
case PropertyLayoutHorizontalSpacing: |
|
1385 |
case PropertyLayoutVerticalSpacing: |
|
1386 |
case PropertyLayoutFieldGrowthPolicy: |
|
1387 |
case PropertyLayoutRowWrapPolicy: |
|
1388 |
case PropertyLayoutLabelAlignment: |
|
1389 |
case PropertyLayoutFormAlignment: |
|
1390 |
case PropertyLayoutBoxStretch: |
|
1391 |
case PropertyLayoutGridRowStretch: |
|
1392 |
case PropertyLayoutGridColumnStretch: |
|
1393 |
case PropertyLayoutGridRowMinimumHeight: |
|
1394 |
case PropertyLayoutGridColumnMinimumWidth: |
|
1395 |
return d->m_canHaveLayoutAttributes; |
|
1396 |
default: |
|
1397 |
break; |
|
1398 |
} |
|
1399 |
return false; |
|
1400 |
} |
|
1401 |
||
1402 |
// Determine the "designable" state of a property. Properties, which have |
|
1403 |
// a per-object boolean test function that returns false are shown in |
|
1404 |
// disabled state ("checked" depending on "checkable", etc.) |
|
1405 |
// Properties, which are generally not designable independent |
|
1406 |
// of the object are not shown at all. |
|
1407 |
enum DesignableState { PropertyIsDesignable, |
|
1408 |
// Object has a Designable test function that returns false. |
|
1409 |
PropertyOfObjectNotDesignable, |
|
1410 |
PropertyNotDesignable }; |
|
1411 |
||
1412 |
static inline DesignableState designableState(const QDesignerMetaPropertyInterface *p, const QObject *object) |
|
1413 |
{ |
|
1414 |
if (p->attributes(object) & QDesignerMetaPropertyInterface::DesignableAttribute) |
|
1415 |
return PropertyIsDesignable; |
|
1416 |
return (p->attributes() & QDesignerMetaPropertyInterface::DesignableAttribute) ? |
|
1417 |
PropertyOfObjectNotDesignable : PropertyNotDesignable; |
|
1418 |
} |
|
1419 |
||
1420 |
bool QDesignerPropertySheet::isVisible(int index) const |
|
1421 |
{ |
|
1422 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1423 |
return false; |
|
1424 |
||
1425 |
const PropertyType type = propertyType(index); |
|
1426 |
if (isAdditionalProperty(index)) { |
|
1427 |
if (isFakeLayoutProperty(index) && d->m_object->isWidgetType()) { |
|
1428 |
const QLayout *currentLayout = d->layout(); |
|
1429 |
if (!currentLayout) |
|
1430 |
return false; |
|
1431 |
const int visibleMask = qdesigner_internal::LayoutProperties::visibleProperties(currentLayout); |
|
1432 |
switch (type) { |
|
1433 |
case PropertyLayoutSpacing: |
|
1434 |
return visibleMask & qdesigner_internal::LayoutProperties::SpacingProperty; |
|
1435 |
case PropertyLayoutHorizontalSpacing: |
|
1436 |
case PropertyLayoutVerticalSpacing: |
|
1437 |
return visibleMask & qdesigner_internal::LayoutProperties::HorizSpacingProperty; |
|
1438 |
case PropertyLayoutFieldGrowthPolicy: |
|
1439 |
return visibleMask & qdesigner_internal::LayoutProperties::FieldGrowthPolicyProperty; |
|
1440 |
case PropertyLayoutRowWrapPolicy: |
|
1441 |
return visibleMask & qdesigner_internal::LayoutProperties::RowWrapPolicyProperty; |
|
1442 |
case PropertyLayoutLabelAlignment: |
|
1443 |
return visibleMask & qdesigner_internal::LayoutProperties::LabelAlignmentProperty; |
|
1444 |
case PropertyLayoutFormAlignment: |
|
1445 |
return visibleMask & qdesigner_internal::LayoutProperties::FormAlignmentProperty; |
|
1446 |
case PropertyLayoutBoxStretch: |
|
1447 |
return visibleMask & qdesigner_internal::LayoutProperties::BoxStretchProperty; |
|
1448 |
case PropertyLayoutGridRowStretch: |
|
1449 |
return visibleMask & qdesigner_internal::LayoutProperties::GridRowStretchProperty; |
|
1450 |
case PropertyLayoutGridColumnStretch: |
|
1451 |
return visibleMask & qdesigner_internal::LayoutProperties::GridColumnStretchProperty; |
|
1452 |
case PropertyLayoutGridRowMinimumHeight: |
|
1453 |
return visibleMask & qdesigner_internal::LayoutProperties::GridRowMinimumHeightProperty; |
|
1454 |
case PropertyLayoutGridColumnMinimumWidth: |
|
1455 |
return visibleMask & qdesigner_internal::LayoutProperties::GridColumnMinimumWidthProperty; |
|
1456 |
default: |
|
1457 |
break; |
|
1458 |
} |
|
1459 |
return true; |
|
1460 |
} |
|
1461 |
return d->m_info.value(index).visible; |
|
1462 |
} |
|
1463 |
||
1464 |
if (isFakeProperty(index)) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1465 |
switch (type) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1466 |
case PropertyWindowModality: // Hidden for child widgets |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1467 |
case PropertyWindowOpacity: |
0 | 1468 |
return d->m_info.value(index).visible; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1469 |
default: |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1470 |
break; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1471 |
} |
0 | 1472 |
return true; |
1473 |
} |
|
1474 |
||
1475 |
const bool visible = d->m_info.value(index).visible; |
|
1476 |
switch (type) { |
|
1477 |
case PropertyWindowTitle: |
|
1478 |
case PropertyWindowIcon: |
|
1479 |
case PropertyWindowFilePath: |
|
1480 |
case PropertyWindowOpacity: |
|
1481 |
case PropertyWindowIconText: |
|
1482 |
case PropertyWindowModified: |
|
1483 |
return visible; |
|
1484 |
default: |
|
1485 |
if (visible) |
|
1486 |
return true; |
|
1487 |
break; |
|
1488 |
} |
|
1489 |
||
1490 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
1491 |
if (!(p->accessFlags() & QDesignerMetaPropertyInterface::WriteAccess)) |
|
1492 |
return false; |
|
1493 |
||
1494 |
// Enabled handling: Hide only statically not designable properties |
|
1495 |
return designableState(p, d->m_object) != PropertyNotDesignable; |
|
1496 |
} |
|
1497 |
||
1498 |
void QDesignerPropertySheet::setVisible(int index, bool visible) |
|
1499 |
{ |
|
1500 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1501 |
return; |
|
1502 |
d->ensureInfo(index).visible = visible; |
|
1503 |
} |
|
1504 |
||
1505 |
bool QDesignerPropertySheet::isEnabled(int index) const |
|
1506 |
{ |
|
1507 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1508 |
return false; |
|
1509 |
if (isAdditionalProperty(index)) |
|
1510 |
return true; |
|
1511 |
||
1512 |
if (isFakeProperty(index)) |
|
1513 |
return true; |
|
1514 |
||
1515 |
// Grey out geometry of laid-out widgets (including splitter) |
|
1516 |
if (propertyType(index) == PropertyGeometry && d->m_object->isWidgetType()) { |
|
1517 |
bool isManaged; |
|
1518 |
const qdesigner_internal::LayoutInfo::Type lt = qdesigner_internal::LayoutInfo::laidoutWidgetType(d->m_core, qobject_cast<QWidget *>(d->m_object), &isManaged); |
|
1519 |
return !isManaged || lt == qdesigner_internal::LayoutInfo::NoLayout; |
|
1520 |
} |
|
1521 |
||
1522 |
if (d->m_info.value(index).visible == true) // Sun CC 5.5 oddity, wants true |
|
1523 |
return true; |
|
1524 |
||
1525 |
// Enable setting of properties for statically non-designable properties |
|
1526 |
// as this might be done via TaskMenu/Cursor::setProperty. Note that those |
|
1527 |
// properties are not visible. |
|
1528 |
const QDesignerMetaPropertyInterface *p = d->m_meta->property(index); |
|
1529 |
return (p->accessFlags() & QDesignerMetaPropertyInterface::WriteAccess) && |
|
1530 |
designableState(p, d->m_object) != PropertyOfObjectNotDesignable; |
|
1531 |
} |
|
1532 |
||
1533 |
bool QDesignerPropertySheet::isAttribute(int index) const |
|
1534 |
{ |
|
1535 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1536 |
return false; |
|
1537 |
if (isAdditionalProperty(index)) |
|
1538 |
return d->m_info.value(index).attribute; |
|
1539 |
||
1540 |
if (isFakeProperty(index)) |
|
1541 |
return false; |
|
1542 |
||
1543 |
return d->m_info.value(index).attribute; |
|
1544 |
} |
|
1545 |
||
1546 |
void QDesignerPropertySheet::setAttribute(int index, bool attribute) |
|
1547 |
{ |
|
1548 |
if (d->invalidIndex(Q_FUNC_INFO, index)) |
|
1549 |
return; |
|
1550 |
d->ensureInfo(index).attribute = attribute; |
|
1551 |
} |
|
1552 |
||
1553 |
QDesignerFormEditorInterface *QDesignerPropertySheet::core() const |
|
1554 |
{ |
|
1555 |
return d->m_core; |
|
1556 |
} |
|
1557 |
||
1558 |
bool QDesignerPropertySheet::internalDynamicPropertiesEnabled() |
|
1559 |
{ |
|
1560 |
return QDesignerPropertySheetPrivate::m_internalDynamicPropertiesEnabled; |
|
1561 |
} |
|
1562 |
||
1563 |
void QDesignerPropertySheet::setInternalDynamicPropertiesEnabled(bool v) |
|
1564 |
{ |
|
1565 |
QDesignerPropertySheetPrivate::m_internalDynamicPropertiesEnabled = v; |
|
1566 |
} |
|
1567 |
||
1568 |
// ---------- QDesignerAbstractPropertySheetFactory |
|
1569 |
||
1570 |
struct QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate { |
|
1571 |
PropertySheetFactoryPrivate(); |
|
1572 |
const QString m_propertySheetId; |
|
1573 |
const QString m_dynamicPropertySheetId; |
|
1574 |
||
1575 |
typedef QMap<QObject*, QObject*> ExtensionMap; |
|
1576 |
ExtensionMap m_extensions; |
|
1577 |
typedef QHash<QObject*, bool> ExtendedSet; |
|
1578 |
ExtendedSet m_extended; |
|
1579 |
}; |
|
1580 |
||
1581 |
QDesignerAbstractPropertySheetFactory::PropertySheetFactoryPrivate::PropertySheetFactoryPrivate() : |
|
1582 |
m_propertySheetId(Q_TYPEID(QDesignerPropertySheetExtension)), |
|
1583 |
m_dynamicPropertySheetId(Q_TYPEID(QDesignerDynamicPropertySheetExtension)) |
|
1584 |
{ |
|
1585 |
} |
|
1586 |
||
1587 |
// ---------- QDesignerAbstractPropertySheetFactory |
|
1588 |
||
1589 |
||
1590 |
QDesignerAbstractPropertySheetFactory::QDesignerAbstractPropertySheetFactory(QExtensionManager *parent) : |
|
1591 |
QExtensionFactory(parent), |
|
1592 |
m_impl(new PropertySheetFactoryPrivate) |
|
1593 |
{ |
|
1594 |
} |
|
1595 |
||
1596 |
QDesignerAbstractPropertySheetFactory::~QDesignerAbstractPropertySheetFactory() |
|
1597 |
{ |
|
1598 |
delete m_impl; |
|
1599 |
} |
|
1600 |
||
1601 |
QObject *QDesignerAbstractPropertySheetFactory::extension(QObject *object, const QString &iid) const |
|
1602 |
{ |
|
1603 |
typedef PropertySheetFactoryPrivate::ExtensionMap ExtensionMap; |
|
1604 |
if (!object) |
|
1605 |
return 0; |
|
1606 |
||
1607 |
if (iid != m_impl->m_propertySheetId && iid != m_impl->m_dynamicPropertySheetId) |
|
1608 |
return 0; |
|
1609 |
||
1610 |
ExtensionMap::iterator it = m_impl->m_extensions.find(object); |
|
1611 |
if (it == m_impl->m_extensions.end()) { |
|
1612 |
if (QObject *ext = createPropertySheet(object, const_cast<QDesignerAbstractPropertySheetFactory*>(this))) { |
|
1613 |
connect(ext, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*))); |
|
1614 |
it = m_impl->m_extensions.insert(object, ext); |
|
1615 |
} |
|
1616 |
} |
|
1617 |
||
1618 |
if (!m_impl->m_extended.contains(object)) { |
|
1619 |
connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(objectDestroyed(QObject*))); |
|
1620 |
m_impl->m_extended.insert(object, true); |
|
1621 |
} |
|
1622 |
||
1623 |
if (it == m_impl->m_extensions.end()) |
|
1624 |
return 0; |
|
1625 |
||
1626 |
return it.value(); |
|
1627 |
} |
|
1628 |
||
1629 |
void QDesignerAbstractPropertySheetFactory::objectDestroyed(QObject *object) |
|
1630 |
{ |
|
1631 |
QMutableMapIterator<QObject*, QObject*> it(m_impl->m_extensions); |
|
1632 |
while (it.hasNext()) { |
|
1633 |
it.next(); |
|
1634 |
||
1635 |
QObject *o = it.key(); |
|
1636 |
if (o == object || object == it.value()) { |
|
1637 |
it.remove(); |
|
1638 |
} |
|
1639 |
} |
|
1640 |
||
1641 |
m_impl->m_extended.remove(object); |
|
1642 |
} |
|
1643 |
||
1644 |
QT_END_NAMESPACE |