aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/designer/qqmldesignermetaobject.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/quick/designer/qqmldesignermetaobject.cpp')
-rw-r--r--src/quick/designer/qqmldesignermetaobject.cpp125
1 files changed, 43 insertions, 82 deletions
diff --git a/src/quick/designer/qqmldesignermetaobject.cpp b/src/quick/designer/qqmldesignermetaobject.cpp
index 0264b751f1..dc8c5885a7 100644
--- a/src/quick/designer/qqmldesignermetaobject.cpp
+++ b/src/quick/designer/qqmldesignermetaobject.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtQuick module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qqmldesignermetaobject_p.h"
@@ -53,7 +17,7 @@ static void (*notifyPropertyChangeCallBack)(QObject*, const QQuickDesignerSuppor
struct MetaPropertyData {
inline QPair<QVariant, bool> &getDataRef(int idx) {
- while (m_data.count() <= idx)
+ while (m_data.size() <= idx)
m_data << QPair<QVariant, bool>(QVariant(), false);
return m_data[idx];
}
@@ -68,23 +32,23 @@ struct MetaPropertyData {
}
inline bool hasData(int idx) const {
- if (idx >= m_data.count())
+ if (idx >= m_data.size())
return false;
return m_data[idx].second;
}
- inline int count() { return m_data.count(); }
+ inline int count() { return m_data.size(); }
QVector<QPair<QVariant, bool> > m_data;
};
-static QQmlPropertyCache *cacheForObject(QObject *object, QQmlEngine *engine)
+static QQmlPropertyCache::ConstPtr cacheForObject(QObject *object)
{
QQmlVMEMetaObject *metaObject = QQmlVMEMetaObject::get(object);
if (metaObject)
- return metaObject->cache.data();
+ return metaObject->cache;
- return QQmlEnginePrivate::get(engine)->cache(object);
+ return QQmlMetaType::propertyCache(object);
}
QQmlDesignerMetaObject* QQmlDesignerMetaObject::getNodeInstanceMetaObject(QObject *object, QQmlEngine *engine)
@@ -107,11 +71,10 @@ QQmlDesignerMetaObject* QQmlDesignerMetaObject::getNodeInstanceMetaObject(QObjec
return mo;
}
-void QQmlDesignerMetaObject::init(QObject *object, QQmlEngine *engine)
+void QQmlDesignerMetaObject::init(QObject *object)
{
//Creating QQmlOpenMetaObjectType
- m_type = new QQmlOpenMetaObjectType(metaObjectParent());
- m_type->addref();
+ m_openMetaObject = std::make_unique<QQmlOpenMetaObject>(object, metaObjectParent());
//Assigning type to this
copyTypeMetaObject();
@@ -119,50 +82,46 @@ void QQmlDesignerMetaObject::init(QObject *object, QQmlEngine *engine)
QObjectPrivate *op = QObjectPrivate::get(object);
op->metaObject = this;
- cache = QQmlEnginePrivate::get(engine)->cache(this);
+ m_cache = QQmlPropertyCache::createStandalone(metaObject.data());
+ cache = m_cache;
nodeInstanceMetaObjectList.insert(this, true);
- hasAssignedMetaObjectData = true;
}
QQmlDesignerMetaObject::QQmlDesignerMetaObject(QObject *object, QQmlEngine *engine)
- : QQmlVMEMetaObject(engine->handle(), object, cacheForObject(object, engine), /*qml compilation unit*/nullptr, /*qmlObjectId*/-1),
+ : QQmlVMEMetaObject(engine->handle(), object, cacheForObject(object), /*qml compilation unit*/nullptr, /*qmlObjectId*/-1),
m_context(engine->contextForObject(object)),
m_data(new MetaPropertyData)
{
- init(object, engine);
+ init(object);
QQmlData *ddata = QQmlData::get(object, false);
//Assign cache to object
if (ddata && ddata->propertyCache) {
- cache->setParent(ddata->propertyCache);
- cache->invalidate(this);
- ddata->propertyCache->release();
- ddata->propertyCache = cache.data();
- ddata->propertyCache->addref();
+ m_cache->setParent(ddata->propertyCache);
+ m_cache->invalidate(metaObject.data());
+ ddata->propertyCache = m_cache;
}
}
QQmlDesignerMetaObject::~QQmlDesignerMetaObject()
{
- m_type->release();
-
+ // m_openMetaObject has this metaobject as its parent.
+ // We need to remove it in order to avoid a dtor recursion
+ m_openMetaObject->unparent();
nodeInstanceMetaObjectList.remove(this);
}
void QQmlDesignerMetaObject::createNewDynamicProperty(const QString &name)
{
- int id = m_type->createProperty(name.toUtf8());
+ int id = type()->createProperty(name.toUtf8());
copyTypeMetaObject();
setValue(id, QVariant());
Q_ASSERT(id >= 0);
- Q_UNUSED(id);
//Updating cache
- QQmlPropertyCache *oldParent = cache->parent();
- QQmlEnginePrivate::get(m_context->engine())->cache(this)->invalidate(this);
- cache->setParent(oldParent);
+ m_cache->invalidate(metaObject.data());
QQmlProperty property(myObject(), name, m_context);
Q_ASSERT(property.isValid());
@@ -173,7 +132,7 @@ void QQmlDesignerMetaObject::setValue(int id, const QVariant &value)
QPair<QVariant, bool> &prop = m_data->getDataRef(id);
prop.first = propertyWriteValue(id, value);
prop.second = true;
- QMetaObject::activate(myObject(), id + m_type->signalOffset(), nullptr);
+ QMetaObject::activate(myObject(), id + type()->signalOffset(), nullptr);
}
QVariant QQmlDesignerMetaObject::propertyWriteValue(int, const QVariant &value)
@@ -181,10 +140,10 @@ QVariant QQmlDesignerMetaObject::propertyWriteValue(int, const QVariant &value)
return value;
}
-const QAbstractDynamicMetaObject *QQmlDesignerMetaObject::dynamicMetaObjectParent() const
+QDynamicMetaObjectData *QQmlDesignerMetaObject::dynamicMetaObjectParent() const
{
if (QQmlVMEMetaObject::parent.isT1())
- return QQmlVMEMetaObject::parent.asT1()->toDynamicMetaObject(QQmlVMEMetaObject::object);
+ return QQmlVMEMetaObject::parent.asT1();
else
return nullptr;
}
@@ -205,8 +164,8 @@ int QQmlDesignerMetaObject::propertyOffset() const
int QQmlDesignerMetaObject::openMetaCall(QObject *o, QMetaObject::Call call, int id, void **a)
{
if ((call == QMetaObject::ReadProperty || call == QMetaObject::WriteProperty)
- && id >= m_type->propertyOffset()) {
- int propId = id - m_type->propertyOffset();
+ && id >= type()->propertyOffset()) {
+ int propId = id - type()->propertyOffset();
if (call == QMetaObject::ReadProperty) {
//propertyRead(propId);
*reinterpret_cast<QVariant *>(a[0]) = m_data->getData(propId);
@@ -217,14 +176,14 @@ int QQmlDesignerMetaObject::openMetaCall(QObject *o, QMetaObject::Call call, int
prop.first = propertyWriteValue(propId, *reinterpret_cast<QVariant *>(a[0]));
prop.second = true;
//propertyWritten(propId);
- activate(myObject(), m_type->signalOffset() + propId, nullptr);
+ activate(myObject(), type()->signalOffset() + propId, nullptr);
}
}
return -1;
} else {
- QAbstractDynamicMetaObject *directParent = parent();
- if (directParent)
- return directParent->metaCall(o, call, id, a);
+ QDynamicMetaObjectData *dynamicParent = dynamicMetaObjectParent();
+ if (dynamicParent)
+ return dynamicParent->metaCall(o, call, id, a);
else
return myObject()->qt_metacall(call, id, a);
}
@@ -236,7 +195,7 @@ int QQmlDesignerMetaObject::metaCall(QObject *o, QMetaObject::Call call, int id,
int metaCallReturnValue = -1;
- const QMetaProperty propertyById = QQmlVMEMetaObject::property(id);
+ const QMetaProperty propertyById = metaObject->property(id);
if (call == QMetaObject::WriteProperty
&& propertyById.userType() == QMetaType::QVariant
@@ -264,12 +223,14 @@ int QQmlDesignerMetaObject::metaCall(QObject *o, QMetaObject::Call call, int id,
oldValue = propertyById.read(myObject());
}
- QAbstractDynamicMetaObject *directParent = parent();
- if (directParent && id < directParent->propertyOffset()) {
- metaCallReturnValue = directParent->metaCall(o, call, id, a);
- } else {
+ QDynamicMetaObjectData *dynamicParent = dynamicMetaObjectParent();
+ const QMetaObject *staticParent = dynamicParent
+ ? dynamicParent->toDynamicMetaObject(QQmlVMEMetaObject::object)
+ : nullptr;
+ if (staticParent && id < staticParent->propertyOffset())
+ metaCallReturnValue = dynamicParent->metaCall(o, call, id, a);
+ else
openMetaCall(o, call, id, a);
- }
if (call == QMetaObject::WriteProperty
@@ -282,7 +243,7 @@ int QQmlDesignerMetaObject::metaCall(QObject *o, QMetaObject::Call call, int id,
void QQmlDesignerMetaObject::notifyPropertyChange(int id)
{
- const QMetaProperty propertyById = property(id);
+ const QMetaProperty propertyById = metaObject->property(id);
if (id < propertyOffset()) {
if (notifyPropertyChangeCallBack)
@@ -295,17 +256,17 @@ void QQmlDesignerMetaObject::notifyPropertyChange(int id)
int QQmlDesignerMetaObject::count() const
{
- return m_type->propertyCount();
+ return type()->propertyCount();
}
QByteArray QQmlDesignerMetaObject::name(int idx) const
{
- return m_type->propertyName(idx);
+ return type()->propertyName(idx);
}
void QQmlDesignerMetaObject::copyTypeMetaObject()
{
- *static_cast<QMetaObject *>(this) = *m_type->metaObject();
+ metaObject = m_openMetaObject.get();
}
void QQmlDesignerMetaObject::registerNotifyPropertyChangeCallBack(void (*callback)(QObject *, const QQuickDesignerSupport::PropertyName &))