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(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(object));
122}
123
124void QQuickDesignerSupportProperties::getPropertyCache(QObject *object, QQmlEngine *engine)
125{
126 QQmlEnginePrivate::get(engine)->cache(object->metaObject());
127}
128
129QQuickDesignerSupport::PropertyNameList QQuickDesignerSupportProperties::propertyNameListForWritableProperties(QObject *object,
130 const QQuickDesignerSupport::PropertyName &baseName,
131 QObjectList *inspectedObjects)
132{
133 QQuickDesignerSupport::PropertyNameList propertyNameList;
134
135 QObjectList localObjectList;
136
137 if (inspectedObjects == nullptr)
138 inspectedObjects = &localObjectList;
139
140
141 if (inspectedObjects->contains(object))
142 return propertyNameList;
143
144 inspectedObjects->append(object);
145
146 const QMetaObject *metaObject = object->metaObject();
147 for (int index = 0; index < metaObject->propertyCount(); ++index) {
148 QMetaProperty metaProperty = metaObject->property(index);
149 QQmlProperty declarativeProperty(object, QString::fromUtf8(metaProperty.name()));
150 if (declarativeProperty.isValid() && !declarativeProperty.isWritable() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) {
151 if (declarativeProperty.name() != QLatin1String("parent")) {
152 QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read());
153 if (childObject)
154 propertyNameList.append(propertyNameListForWritableProperties(childObject,
155 baseName + QQuickDesignerSupport::PropertyName(metaProperty.name())
156 + '.', inspectedObjects));
157 }
158 } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) {
159 QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType());
160 valueType->setValue(metaProperty.read(object));
161 propertyNameList.append(propertyNameListForWritableProperties(valueType,
162 baseName + QQuickDesignerSupport::PropertyName(metaProperty.name())
163 + '.', inspectedObjects));
164 }
165
166 if (metaProperty.isReadable() && metaProperty.isWritable()) {
167 addToPropertyNameListIfNotBlackListed(&propertyNameList,
168 baseName + QQuickDesignerSupport::PropertyName(metaProperty.name()));
169 }
170 }
171
172 return propertyNameList;
173}
174
175bool QQuickDesignerSupportProperties::isPropertyBlackListed(const QQuickDesignerSupport::PropertyName &propertyName)
176{
177 if (propertyName.contains(".") && propertyName.contains("__"))
178 return true;
179
180 if (propertyName.count(".") > 1)
181 return true;
182
183 return false;
184}
185
186QQuickDesignerSupport::PropertyNameList QQuickDesignerSupportProperties::allPropertyNames(QObject *object,
187 const QQuickDesignerSupport::PropertyName &baseName,
188 QObjectList *inspectedObjects)
189{
190 QQuickDesignerSupport::PropertyNameList propertyNameList;
191
192 QObjectList localObjectList;
193
194 if (inspectedObjects == nullptr)
195 inspectedObjects = &localObjectList;
196
197
198 if (inspectedObjects->contains(object))
199 return propertyNameList;
200
201 inspectedObjects->append(object);
202
203
204 const QMetaObject *metaObject = object->metaObject();
205
206 QStringList deferredPropertyNames;
207 const int namesIndex = metaObject->indexOfClassInfo("DeferredPropertyNames");
208 if (namesIndex != -1) {
209 QMetaClassInfo classInfo = metaObject->classInfo(namesIndex);
210 deferredPropertyNames = QString::fromUtf8(classInfo.value()).split(QLatin1Char(','));
211 }
212
213 for (int index = 0; index < metaObject->propertyCount(); ++index) {
214 QMetaProperty metaProperty = metaObject->property(index);
215 QQmlProperty declarativeProperty(object, QString::fromUtf8(metaProperty.name()));
216 if (declarativeProperty.isValid() && declarativeProperty.propertyTypeCategory() == QQmlProperty::Object) {
217 if (declarativeProperty.name() != QLatin1String("parent")
218 && !deferredPropertyNames.contains(declarativeProperty.name())) {
219 QObject *childObject = QQmlMetaType::toQObject(declarativeProperty.read());
220 if (childObject)
221 propertyNameList.append(allPropertyNames(childObject,
222 baseName
223 + QQuickDesignerSupport::PropertyName(metaProperty.name())
224 + '.', inspectedObjects));
225 }
226 } else if (QQmlValueTypeFactory::valueType(metaProperty.userType())) {
227 QQmlValueType *valueType = QQmlValueTypeFactory::valueType(metaProperty.userType());
228 valueType->setValue(metaProperty.read(object));
229 propertyNameList.append(baseName + QQuickDesignerSupport::PropertyName(metaProperty.name()));
230 propertyNameList.append(allPropertyNames(valueType,
231 baseName
232 + QQuickDesignerSupport::PropertyName(metaProperty.name())
233 + '.', inspectedObjects));
234 } else {
235 addToPropertyNameListIfNotBlackListed(&propertyNameList,
236 baseName + QQuickDesignerSupport::PropertyName(metaProperty.name()));
237 }
238 }
239
240 return propertyNameList;
241}
242
243
244QT_END_NAMESPACE
245
246
247
248
249