Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qquickdesignersupportitems.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <private/qabstractanimation_p.h>
8#include <private/qobject_p.h>
9#include <private/qquickbehavior_p.h>
10#include <private/qquicktext_p.h>
11#include <private/qquicktextinput_p.h>
12#include <private/qquicktextedit_p.h>
13#include <private/qquicktransition_p.h>
14#include <private/qquickloader_p.h>
15
16#include <private/qquickanimation_p.h>
17#include <private/qqmlmetatype_p.h>
18#include <private/qqmltimer_p.h>
19
21
23
24static void stopAnimation(QObject *object)
25{
26 if (object == nullptr)
27 return;
28
29 QQuickTransition *transition = qobject_cast<QQuickTransition*>(object);
30 QQuickAbstractAnimation *animation = qobject_cast<QQuickAbstractAnimation*>(object);
31 QQmlTimer *timer = qobject_cast<QQmlTimer*>(object);
32 if (transition) {
33 transition->setFromState(QString());
34 transition->setToState(QString());
35 } else if (animation) {
36// QQuickScriptAction *scriptAimation = qobject_cast<QQuickScriptAction*>(animation);
37// if (scriptAimation) FIXME
38// scriptAimation->setScript(QQmlScriptString());
39 animation->complete();
40 animation->setDisableUserControl();
41 } else if (timer) {
42 timer->blockSignals(true);
43 }
44}
45
46static void makeLoaderSynchronous(QObject *object)
47{
48 if (QQuickLoader *loader = qobject_cast<QQuickLoader*>(object))
49 loader->setAsynchronous(false);
50}
51
52static void allSubObjects(QObject *object, QObjectList &objectList)
53{
54 // don't add null pointer and stop if the object is already in the list
55 if (!object || objectList.contains(object))
56 return;
57
58 objectList.append(object);
59
60 const QMetaObject *mo = object->metaObject();
61
62 QByteArrayList deferredPropertyNames;
63 const int namesIndex = mo->indexOfClassInfo("DeferredPropertyNames");
64 if (namesIndex != -1) {
65 QMetaClassInfo classInfo = mo->classInfo(namesIndex);
66 deferredPropertyNames = QByteArray(classInfo.value()).split(',');
67 }
68
69 for (int index = QObject::staticMetaObject.propertyOffset();
70 index < object->metaObject()->propertyCount();
71 index++) {
72
73 QMetaProperty metaProperty = object->metaObject()->property(index);
74
75 if (deferredPropertyNames.contains(metaProperty.name()))
76 continue;
77
78 // search recursive in property objects
79 if (metaProperty.isReadable()
80 && metaProperty.isWritable()
81 && metaProperty.metaType().flags().testFlag(QMetaType::PointerToQObject)) {
82 if (qstrcmp(metaProperty.name(), "parent")) {
83 QObject *propertyObject = QQmlMetaType::toQObject(metaProperty.read(object));
84 allSubObjects(propertyObject, objectList);
85 }
86
87 }
88
89 // search recursive in property object lists
90 if (metaProperty.isReadable()
91 && QQmlMetaType::isList(metaProperty.metaType())) {
92 QQmlListReference list(object, metaProperty.name());
93 if (list.canCount() && list.canAt()) {
94 for (qsizetype i = 0; i < list.count(); i++) {
95 QObject *propertyObject = list.at(i);
96 allSubObjects(propertyObject, objectList);
97
98 }
99 }
100 }
101 }
102
103 // search recursive in object children list
104 for (QObject *childObject : object->children()) {
105 allSubObjects(childObject, objectList);
106 }
107
108 // search recursive in quick item childItems list
109 QQuickItem *quickItem = qobject_cast<QQuickItem*>(object);
110 if (quickItem) {
111 const auto childItems = quickItem->childItems();
112 for (QQuickItem *childItem : childItems)
113 allSubObjects(childItem, objectList);
114 }
115}
116
118{
119 QObjectList objectList;
120 allSubObjects(object, objectList);
121 for (QObject* childObject : std::as_const(objectList)) {
122 stopAnimation(childObject);
123 makeLoaderSynchronous(childObject);
126 }
127}
128
130{
131 QQmlComponent component(engine, QUrl(QStringLiteral("qrc:/qtquickplugin/mockfiles/Window.qml")));
132 return component.create();
133}
134
136{
137 if (metaObject) {
138 if (metaObject->className() == QByteArrayLiteral("QWindow"))
139 return true;
140
141 return isWindowMetaObject(metaObject->superClass());
142 }
143
144 return false;
145}
146
147static bool isWindow(QObject *object) {
148 if (object)
149 return isWindowMetaObject(object->metaObject());
150
151 return false;
152}
153
154static bool isCrashingType(const QQmlType &type)
155{
156 QString name = type.qmlTypeName();
157
158 if (name == QLatin1String("QtMultimedia/MediaPlayer"))
159 return true;
160
161 if (name == QLatin1String("QtMultimedia/Audio"))
162 return true;
163
164 if (name == QLatin1String("QtQuick.Controls/MenuItem"))
165 return true;
166
167 if (name == QLatin1String("QtQuick.Controls/Menu"))
168 return true;
169
170 if (name == QLatin1String("QtQuick/Timer"))
171 return true;
172
173 return false;
174}
175
177{
178 ComponentCompleteDisabler disableComponentComplete;
179
180 Q_UNUSED(disableComponentComplete);
181
182 QObject *object = nullptr;
184
185 if (isCrashingType(type)) {
186 object = new QObject;
187 } else if (type.isValid()) {
188 if ( type.isComposite()) {
189 object = createComponent(type.sourceUrl(), context);
190 } else
191 {
192 if (type.typeName() == "QQmlComponent") {
193 object = new QQmlComponent(context->engine(), nullptr);
194 } else {
195 object = type.create();
196 }
197 }
198
199 if (isWindow(object)) {
200 delete object;
201 object = createDummyWindow(context->engine());
202 }
203
204 }
205
206 if (!object) {
207 qWarning() << "QuickDesigner: Cannot create an object of type"
208 << QString::fromLatin1("%1 %2,%3").arg(typeName)
209 .arg(version.majorVersion()).arg(version.minorVersion())
210 << "- type isn't known to declarative meta type system";
211 }
212
213 tweakObjects(object);
214
215 if (object && QQmlEngine::contextForObject(object) == nullptr)
217
219
220 return object;
221}
222
224{
225 ComponentCompleteDisabler disableComponentComplete;
226 Q_UNUSED(disableComponentComplete);
227
228 QQmlComponent component(context->engine(), componentUrl);
229
230 QObject *object = component.beginCreate(context);
231 tweakObjects(object);
232 component.completeCreate();
234
235 if (component.isError()) {
236 qWarning() << "Error in:" << Q_FUNC_INFO << componentUrl;
237 const auto errors = component.errors();
238 for (const QQmlError &error : errors)
239 qWarning() << error;
240 }
241 return object;
242}
243
245{
246 return QObjectPrivate::get(object)->wasDeleted;
247}
248
250{
251 QQuickText *text = qobject_cast<QQuickText*>(item);
252 if (text)
253 text->setRenderType(QQuickText::QtRendering);
254
255 QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(item);
256 if (textInput)
258
259 QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit*>(item);
260 if (textEdit)
262}
263
265{
266 const auto childItems = item->childItems();
267 for (QQuickItem *childItem : childItems)
268 disableTextCursor(childItem);
269
270 QQuickTextInput *textInput = qobject_cast<QQuickTextInput*>(item);
271 if (textInput)
272 textInput->setCursorVisible(false);
273
274 QQuickTextEdit *textEdit = qobject_cast<QQuickTextEdit*>(item);
275 if (textEdit)
276 textEdit->setCursorVisible(false);
277}
278
280{
281 QQuickTransition *transition = qobject_cast<QQuickTransition*>(object);
282 Q_ASSERT(transition);
283 const QString invalidState = QLatin1String("invalidState");
284 transition->setToState(invalidState);
285 transition->setFromState(invalidState);
286}
287
289{
290 QQuickBehavior* behavior = qobject_cast<QQuickBehavior*>(object);
291 Q_ASSERT(behavior);
292 behavior->setEnabled(false);
293}
294
296{
297 QUnifiedTimer::instance()->setSlowdownFactor(0.00001);
298 QUnifiedTimer::instance()->setSlowModeEnabled(true);
299}
300
305
307
308
\inmodule QtCore
QList< QGraphicsItem * > childItems() const
static void setObjectOwnership(QObject *, ObjectOwnership)
Sets the ownership of object.
const_reference at(qsizetype i) const noexcept
Definition qlist.h:446
qsizetype count() const noexcept
Definition qlist.h:398
\inmodule QtCore
\inmodule QtCore
QMetaType metaType() const
QVariant read(const QObject *obj) const
Reads the property's value from the given object.
bool isWritable() const
Returns true if this property is writable; otherwise returns false.
const char * name() const
Returns this property's name.
bool isReadable() const
Returns true if this property is readable; otherwise returns false.
constexpr TypeFlags flags() const
Definition qmetatype.h:2658
@ PointerToQObject
Definition qmetatype.h:406
static QObjectPrivate * get(QObject *o)
Definition qobject_p.h:150
\inmodule QtCore
Definition qobject.h:103
bool blockSignals(bool b) noexcept
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition qobject.cpp:1585
The QQmlComponent class encapsulates a QML component definition.
The QQmlContext class defines a context within a QML engine.
Definition qqmlcontext.h:25
The QQmlEngine class provides an environment for instantiating QML components.
Definition qqmlengine.h:57
static QQmlContext * contextForObject(const QObject *)
Returns the QQmlContext for the object, or nullptr if no context has been set.
static void setContextForObject(QObject *, QQmlContext *)
Sets the QQmlContext for the object to context.
The QQmlError class encapsulates a QML error.
Definition qqmlerror.h:18
The QQmlListReference class allows the manipulation of QQmlListProperty properties.
Definition qqmllist.h:183
static bool isList(QMetaType type)
static QObject * toQObject(const QVariant &, bool *ok=nullptr)
static QQmlType qmlType(const QString &qualifiedName, QTypeRevision version)
Returns the type (if any) of URI-qualified named qualifiedName and version specified by version_major...
static void registerFixResourcePathsForObjectCallBack(void(*callback)(QObject *))
static void tweakObjects(QObject *object)
static QObject * createComponent(const QUrl &componentUrl, QQmlContext *context)
static void disableBehaivour(QObject *object)
static void disableTextCursor(QQuickItem *item)
static void disableNativeTextRendering(QQuickItem *item)
static void disableTransition(QObject *object)
static QObject * createPrimitive(const QString &typeName, QTypeRevision version, QQmlContext *context)
static bool objectWasDeleted(QObject *object)
The QQuickItem class provides the most basic of all visual items in \l {Qt Quick}.
Definition qquickitem.h:63
void setRenderType(RenderType renderType)
void setCursorVisible(bool on)
void setFromState(const QString &)
void setToState(const QString &)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
\inmodule QtCore
constexpr quint8 minorVersion() const
Returns the minor version encoded in the revision.
constexpr quint8 majorVersion() const
Returns the major version encoded in the revision.
static QUnifiedTimer * instance()
\inmodule QtCore
Definition qurl.h:94
QString text
auto mo
[7]
Combined button and popup list for selecting options.
static void * context
#define QByteArrayLiteral(str)
Definition qbytearray.h:52
Q_CORE_EXPORT int qstrcmp(const char *str1, const char *str2)
#define Q_FUNC_INFO
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
DBusConnection const char DBusError * error
typedef QByteArray(EGLAPIENTRYP PFNQGSGETDISPLAYSPROC)()
static Window createDummyWindow(Display *dpy, XVisualInfo *visualInfo, int screenNumber, Window rootWin)
#define qWarning
Definition qlogging.h:166
const char * typeName
GLuint index
[2]
GLuint object
[3]
GLenum type
GLuint name
static qreal component(const QPointF &point, unsigned int i)
static bool isCrashingType(const QQmlType &type)
static void makeLoaderSynchronous(QObject *object)
static void stopAnimation(QObject *object)
static void allSubObjects(QObject *object, QObjectList &objectList)
static bool isWindow(QObject *object)
static QT_BEGIN_NAMESPACE void(* fixResourcePathsForObjectCallBack)(QObject *)
static QObject * createDummyWindow(QQmlEngine *engine)
static bool isWindowMetaObject(const QMetaObject *metaObject)
QQuickItem * qobject_cast< QQuickItem * >(QObject *o)
Definition qquickitem.h:492
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
#define QStringLiteral(str)
#define Q_UNUSED(x)
ptrdiff_t qsizetype
Definition qtypes.h:165
QList< int > list
[14]
obj metaObject() -> className()
QTimer * timer
[3]
QPropertyAnimation animation
[0]
QGraphicsWidget * textEdit
QGraphicsItem * item
QJSEngine engine
[0]
\inmodule QtCore