1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtQuick module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qquickdesignersupportproperties_p.h"
41
42#include "qqmldesignermetaobject_p.h"
43#include "qquickdesignercustomobjectdata_p.h"
44
45QT_BEGIN_NAMESPACE
46
47static void addToPropertyNameListIfNotBlackListed(QQuickDesignerSupport::PropertyNameList *propertyNameList,
48 const QQuickDesignerSupport::PropertyName &propertyName)
49{
50 if (!QQuickDesignerSupportProperties::isPropertyBlackListed(propertyName))
51 propertyNameList->append(t: propertyName);
52}
53
54void QQuickDesignerSupportProperties::createNewDynamicProperty(QObject *object, QQmlEngine *engine, const QString &name)
55{
56 QQmlDesignerMetaObject::getNodeInstanceMetaObject(object, engine)->createNewDynamicProperty(name);
57}
58
59void QQuickDesignerSupportProperties::registerNodeInstanceMetaObject(QObject *object, QQmlEngine *engine)
60{
61 // we just create one and the ownership goes automatically to the object in nodeinstance see init method
62 QQmlDesignerMetaObject::getNodeInstanceMetaObject(object, engine);
63}
64
65bool QQuickDesignerSupportProperties::hasFullImplementedListInterface(const QQmlListReference &list)
66{
67 return list.isValid() && list.canCount() && list.canAt() && list.canAppend() && list.canClear();
68}
69
70void QQuickDesignerSupportProperties::registerCustomData(QObject *object)
71{
72 QQuickDesignerCustomObjectData::registerData(object);
73}
74
75QVariant QQuickDesignerSupportProperties::getResetValue(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName)
76{
77 return QQuickDesignerCustomObjectData::getResetValue(object, propertyName);
78}
79
80void QQuickDesignerSupportProperties::doResetProperty(QObject *object, QQmlContext *context, const QQuickDesignerSupport::PropertyName &propertyName)
81{
82 QQuickDesignerCustomObjectData::doResetProperty(object, context, propertyName);
83}
84
85bool QQuickDesignerSupportProperties::hasValidResetBinding(QObject *object, const QQuickDesignerSupport::PropertyName &propertyName)
86{
87 return QQuickDesignerCustomObjectData::hasValidResetBinding(object, propertyName);
88}
89
90bool QQuickDesignerSupportProperties::hasBindingForProperty(QObject *object,
91 QQmlContext *context,
92 const QQuickDesignerSupport::PropertyName &propertyName,
93 bool *hasChanged)
94{
95 return QQuickDesignerCustomObjectData::hasBindingForProperty(object, context, propertyName, hasChanged);
96}
97
98void QQuickDesignerSupportProperties::setPropertyBinding(QObject *object,
99 QQmlContext *context,
100 const QQuickDesignerSupport::PropertyName &propertyName,
101 const QString &expression)
102{
103 QQuickDesignerCustomObjectData::setPropertyBinding(object, context, propertyName, expression);
104}
105
106void QQuickDesignerSupportProperties::keepBindingFromGettingDeleted(QObject *object,
107 QQmlContext *context,
108 const QQuickDesignerSupport::PropertyName &propertyName)
109{
110 QQuickDesignerCustomObjectData::keepBindingFromGettingDeleted(object, context, propertyName);
111}
112
113bool QQuickDesignerSupportProperties::isPropertyQObject(const QMetaProperty &metaProperty)
114{
115 return QQmlMetaType::isQObject(metaProperty.userType());
116}
117
118
119QObject *QQuickDesignerSupportProperties::readQObjectProperty(const QMetaProperty &metaProperty, QObject *object)
120{
121 return QQmlMetaType::toQObject(metaProperty.read(obj: object));
122}
123
124void QQuickDesignerSupportProperties::getPropertyCache(QObject *object, QQmlEngine *engine)
125{
126 QQmlEnginePrivate::get(e: engine)->cache(metaObject: object->metaObject());
127}
128
129static QQuickDesignerSupport::PropertyNameList propertyNameListForWritableProperties(QObject *object,
130 const QQuickDesignerSupport::PropertyName &baseName,
131 QObjectList *inspectedObjects,
132 int depth = 0)
133{
134 QQuickDesignerSupport::PropertyNameList propertyNameList;
135
136 if (depth > 2)
137 return propertyNameList;
138
139 if (!inspectedObjects->contains(t: object))
140 inspectedObjects->append(t: object);
141
142 const QMetaObject *metaObject = object->metaObject();
143 for (int index = 0; index < metaObject->propertyCount(); ++index) {
144 QMetaProperty metaProperty = metaObject->property(index);
145 QQmlProperty declarativeProperty(object, QString::fromUtf8(str: metaProperty.name()));
146 if (declarativeProperty.isValid() && !declarativeProperty.isWritable() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) {
147 if (declarativeProperty.name() != QLatin1String("parent")) {
148 QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read());
149 if (childObject)
150 propertyNameList.append(t: propertyNameListForWritableProperties(object: childObject,
151 baseName: baseName + QQuickDesignerSupport::PropertyName(metaProperty.name())
152 + '.', inspectedObjects,
153 depth: depth + 1));
154 }
155 } else if (QQmlGadgetPtrWrapper *valueType
156 = QQmlGadgetPtrWrapper::instance(engine: qmlEngine(object), index: metaProperty.userType())) {
157 valueType->setValue(metaProperty.read(obj: object));
158 propertyNameList.append(t: propertyNameListForWritableProperties(object: valueType,
159 baseName: baseName + QQuickDesignerSupport::PropertyName(metaProperty.name())
160 + '.', inspectedObjects,
161 depth: depth + 1));
162 }
163
164 if (metaProperty.isReadable() && metaProperty.isWritable()) {
165 addToPropertyNameListIfNotBlackListed(propertyNameList: &propertyNameList,
166 propertyName: baseName + QQuickDesignerSupport::PropertyName(metaProperty.name()));
167 }
168 }
169
170 return propertyNameList;
171}
172
173QQuickDesignerSupport::PropertyNameList QQuickDesignerSupportProperties::propertyNameListForWritableProperties(QObject *object)
174{
175 QObjectList localObjectList;
176 return ::propertyNameListForWritableProperties(object, baseName: {}, inspectedObjects: &localObjectList);
177}
178
179bool QQuickDesignerSupportProperties::isPropertyBlackListed(const QQuickDesignerSupport::PropertyName &propertyName)
180{
181 if (propertyName.contains(c: ".") && propertyName.contains(c: "__"))
182 return true;
183
184 if (propertyName.count(a: ".") > 1)
185 return true;
186
187 return false;
188}
189
190QQuickDesignerSupport::PropertyNameList QQuickDesignerSupportProperties::allPropertyNames(QObject *object,
191 const QQuickDesignerSupport::PropertyName &baseName,
192 QObjectList *inspectedObjects,
193 int depth)
194{
195 QQuickDesignerSupport::PropertyNameList propertyNameList;
196
197 QObjectList localObjectList;
198
199 if (inspectedObjects == nullptr)
200 inspectedObjects = &localObjectList;
201
202 if (depth > 2)
203 return propertyNameList;
204
205 if (!inspectedObjects->contains(t: object))
206 inspectedObjects->append(t: object);
207
208 const QMetaObject *metaObject = object->metaObject();
209
210 QStringList deferredPropertyNames;
211 const int namesIndex = metaObject->indexOfClassInfo(name: "DeferredPropertyNames");
212 if (namesIndex != -1) {
213 QMetaClassInfo classInfo = metaObject->classInfo(index: namesIndex);
214 deferredPropertyNames = QString::fromUtf8(str: classInfo.value()).split(sep: QLatin1Char(','));
215 }
216
217 for (int index = 0; index < metaObject->propertyCount(); ++index) {
218 QMetaProperty metaProperty = metaObject->property(index);
219 QQmlProperty declarativeProperty(object, QString::fromUtf8(str: metaProperty.name()));
220 if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) {
221 if (declarativeProperty.name() != QLatin1String("parent")
222 && !deferredPropertyNames.contains(str: declarativeProperty.name())) {
223 QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read());
224 if (childObject)
225 propertyNameList.append(t: allPropertyNames(object: childObject,
226 baseName: baseName
227 + QQuickDesignerSupport::PropertyName(metaProperty.name())
228 + '.', inspectedObjects,
229 depth: depth + 1));
230 }
231 } else if (QQmlGadgetPtrWrapper *valueType
232 = QQmlGadgetPtrWrapper::instance(engine: qmlEngine(object), index: metaProperty.userType())) {
233 valueType->setValue(metaProperty.read(obj: object));
234 propertyNameList.append(t: baseName + QQuickDesignerSupport::PropertyName(metaProperty.name()));
235 propertyNameList.append(t: allPropertyNames(object: valueType,
236 baseName: baseName
237 + QQuickDesignerSupport::PropertyName(metaProperty.name())
238 + '.', inspectedObjects,
239 depth: depth + 1));
240 } else {
241 addToPropertyNameListIfNotBlackListed(propertyNameList: &propertyNameList,
242 propertyName: baseName + QQuickDesignerSupport::PropertyName(metaProperty.name()));
243 }
244 }
245
246 return propertyNameList;
247}
248
249
250QT_END_NAMESPACE
251
252
253
254
255

source code of qtdeclarative/src/quick/designer/qquickdesignersupportproperties.cpp