2012-11-06 15:35:19 +01:00
|
|
|
/****************************************************************************
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2016-01-15 14:59:14 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2012-11-06 15:35:19 +01:00
|
|
|
** This file is part of Qt Creator.
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2012-11-06 15:35:19 +01:00
|
|
|
** 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
|
2016-01-15 14:59:14 +01:00
|
|
|
** 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.
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2015-09-18 11:34:48 +02:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
2016-01-15 14:59:14 +01:00
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** 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-3.0.html.
|
2012-09-19 15:57:22 +02:00
|
|
|
**
|
2012-11-06 15:35:19 +01:00
|
|
|
****************************************************************************/
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
#include "objectnodeinstance.h"
|
|
|
|
|
2013-12-16 12:50:32 +01:00
|
|
|
#include <enumeration.h>
|
2015-05-19 13:11:39 +02:00
|
|
|
#include <qmlprivategate.h>
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2017-07-06 09:31:41 +02:00
|
|
|
#include <QDebug>
|
2012-09-19 15:57:22 +02:00
|
|
|
#include <QEvent>
|
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQmlError>
|
|
|
|
#include <QQmlEngine>
|
|
|
|
#include <QQmlProperty>
|
|
|
|
#include <QQmlComponent>
|
|
|
|
#include <QSharedPointer>
|
|
|
|
#include <QFileInfo>
|
|
|
|
#include <QFileSystemWatcher>
|
|
|
|
#include <QPixmapCache>
|
2012-09-26 14:00:27 +02:00
|
|
|
#include <QQuickItem>
|
2015-05-19 14:02:35 +02:00
|
|
|
#include <QQmlExpression>
|
2013-04-23 18:45:26 +02:00
|
|
|
#include <QQmlParserStatus>
|
2012-09-19 15:57:22 +02:00
|
|
|
#include <QTextDocument>
|
|
|
|
#include <QLibraryInfo>
|
|
|
|
|
2014-08-08 11:44:06 +02:00
|
|
|
static bool isSimpleExpression(const QString &expression)
|
|
|
|
{
|
|
|
|
if (expression.startsWith(QStringLiteral("{")))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
namespace QmlDesigner {
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
ObjectNodeInstance::ObjectNodeInstance(QObject *object)
|
2013-02-19 11:40:16 +01:00
|
|
|
: m_object(object),
|
|
|
|
m_instanceId(-1),
|
|
|
|
m_deleteHeldInstance(true),
|
2013-04-23 11:13:25 +02:00
|
|
|
m_isInLayoutable(false)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-02-23 11:28:23 +01:00
|
|
|
if (object)
|
|
|
|
QObject::connect(m_object.data(), &QObject::destroyed, [=] {
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2015-02-23 11:28:23 +01:00
|
|
|
/*This lambda is save because m_nodeInstanceServer
|
|
|
|
is a smartpointer and object is a dangling pointer anyway.*/
|
|
|
|
|
|
|
|
if (m_nodeInstanceServer)
|
|
|
|
m_nodeInstanceServer->removeInstanceRelationsipForDeletedObject(object);
|
|
|
|
});
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectNodeInstance::~ObjectNodeInstance()
|
|
|
|
{
|
|
|
|
destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::destroy()
|
|
|
|
{
|
|
|
|
if (deleteHeldInstance()) {
|
|
|
|
// Remove from old property
|
|
|
|
if (object()) {
|
|
|
|
setId(QString());
|
|
|
|
if (m_instanceId >= 0) {
|
2013-03-05 12:19:19 +01:00
|
|
|
reparent(parentInstance(), m_parentProperty, ObjectNodeInstance::Pointer(), PropertyName());
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object()) {
|
|
|
|
QObject *obj = object();
|
|
|
|
m_object.clear();
|
|
|
|
delete obj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_instanceId = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::setInstanceId(qint32 id)
|
|
|
|
{
|
|
|
|
m_instanceId = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
qint32 ObjectNodeInstance::instanceId() const
|
|
|
|
{
|
|
|
|
return m_instanceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
NodeInstanceServer *ObjectNodeInstance::nodeInstanceServer() const
|
|
|
|
{
|
|
|
|
return m_nodeInstanceServer.data();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::setNodeInstanceServer(NodeInstanceServer *server)
|
|
|
|
{
|
|
|
|
Q_ASSERT(!m_nodeInstanceServer.data());
|
|
|
|
|
|
|
|
m_nodeInstanceServer = server;
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:35:58 +02:00
|
|
|
void ObjectNodeInstance::initializePropertyWatcher(const ObjectNodeInstance::Pointer &objectNodeInstance)
|
|
|
|
{
|
|
|
|
m_signalSpy.setObjectNodeInstance(objectNodeInstance);
|
|
|
|
}
|
|
|
|
|
2018-03-02 15:29:26 +01:00
|
|
|
void ObjectNodeInstance::initialize(const ObjectNodeInstance::Pointer &objectNodeInstance,
|
|
|
|
InstanceContainer::NodeFlags /*flags*/)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-20 16:35:58 +02:00
|
|
|
initializePropertyWatcher(objectNodeInstance);
|
2015-05-20 20:45:48 +02:00
|
|
|
QmlPrivateGate::registerNodeInstanceMetaObject(objectNodeInstance->object(), objectNodeInstance->nodeInstanceServer()->engine());
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::setId(const QString &id)
|
|
|
|
{
|
|
|
|
if (!m_id.isEmpty() && context()) {
|
|
|
|
context()->engine()->rootContext()->setContextProperty(m_id, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!id.isEmpty() && context()) {
|
|
|
|
context()->engine()->rootContext()->setContextProperty(id, object()); // will also force refresh of all bindings
|
|
|
|
}
|
|
|
|
|
|
|
|
m_id = id;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString ObjectNodeInstance::id() const
|
|
|
|
{
|
|
|
|
return m_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isTransition() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isPositioner() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-25 17:05:00 +02:00
|
|
|
bool ObjectNodeInstance::isQuickItem() const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:22:15 +02:00
|
|
|
bool ObjectNodeInstance::isQuickWindow() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:42:58 +02:00
|
|
|
bool ObjectNodeInstance::isLayoutable() const
|
|
|
|
{
|
2013-09-23 19:05:11 +02:00
|
|
|
return false;
|
2013-04-18 18:42:58 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
bool ObjectNodeInstance::equalGraphicsItem(QGraphicsItem * /*item*/) const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QTransform ObjectNodeInstance::transform() const
|
|
|
|
{
|
|
|
|
return QTransform();
|
|
|
|
}
|
|
|
|
|
2013-05-22 13:07:32 +02:00
|
|
|
QTransform ObjectNodeInstance::contentTransform() const
|
|
|
|
{
|
|
|
|
return QTransform();
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QTransform ObjectNodeInstance::customTransform() const
|
|
|
|
{
|
|
|
|
return QTransform();
|
|
|
|
}
|
|
|
|
|
2013-05-28 14:14:07 +02:00
|
|
|
QTransform ObjectNodeInstance::contentItemTransform() const
|
|
|
|
{
|
|
|
|
return QTransform();
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QTransform ObjectNodeInstance::sceneTransform() const
|
|
|
|
{
|
|
|
|
return QTransform();
|
|
|
|
}
|
|
|
|
|
|
|
|
double ObjectNodeInstance::rotation() const
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ObjectNodeInstance::scale() const
|
|
|
|
{
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QList<QGraphicsTransform *> ObjectNodeInstance::transformations() const
|
|
|
|
{
|
|
|
|
QList<QGraphicsTransform *> transformationsList;
|
|
|
|
|
|
|
|
return transformationsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
QPointF ObjectNodeInstance::transformOriginPoint() const
|
|
|
|
{
|
|
|
|
return QPoint();
|
|
|
|
}
|
|
|
|
|
|
|
|
double ObjectNodeInstance::zValue() const
|
|
|
|
{
|
|
|
|
return 0.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
double ObjectNodeInstance::opacity() const
|
|
|
|
{
|
|
|
|
return 1.0;
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
bool ObjectNodeInstance::hasAnchor(const PropertyName &/*name*/) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isAnchoredBySibling() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isAnchoredByChildren() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
QPair<PropertyName, ServerNodeInstance> ObjectNodeInstance::anchor(const PropertyName &/*name*/) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2017-04-26 13:17:14 +02:00
|
|
|
return {PropertyName(), ServerNodeInstance()};
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool isList(const QQmlProperty &property)
|
|
|
|
{
|
|
|
|
return property.propertyTypeCategory() == QQmlProperty::List;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isObject(const QQmlProperty &property)
|
|
|
|
{
|
|
|
|
return (property.propertyTypeCategory() == QQmlProperty::Object) ||
|
|
|
|
//QVariant can also store QObjects. Lets trust our model.
|
|
|
|
(QLatin1String(property.propertyTypeName()) == QLatin1String("QVariant"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static QVariant objectToVariant(QObject *object)
|
|
|
|
{
|
|
|
|
return QVariant::fromValue(object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void removeObjectFromList(const QQmlProperty &property, QObject *objectToBeRemoved, QQmlEngine * engine)
|
|
|
|
{
|
2013-03-05 12:19:19 +01:00
|
|
|
QQmlListReference listReference(property.object(), property.name().toUtf8(), engine);
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2015-05-19 16:06:19 +02:00
|
|
|
if (!QmlPrivateGate::hasFullImplementedListInterface(listReference)) {
|
2012-09-19 15:57:22 +02:00
|
|
|
qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int count = listReference.count();
|
|
|
|
|
|
|
|
QObjectList objectList;
|
|
|
|
|
|
|
|
for (int i = 0; i < count; i ++) {
|
|
|
|
QObject *listItem = listReference.at(i);
|
|
|
|
if (listItem && listItem != objectToBeRemoved)
|
|
|
|
objectList.append(listItem);
|
|
|
|
}
|
|
|
|
|
|
|
|
listReference.clear();
|
|
|
|
|
|
|
|
foreach (QObject *object, objectList)
|
|
|
|
listReference.append(object);
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::removeFromOldProperty(QObject *object, QObject *oldParent, const PropertyName &oldParentProperty)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2016-03-18 10:19:09 +01:00
|
|
|
QQmlProperty property(oldParent, QString::fromUtf8(oldParentProperty), context());
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
if (!property.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (isList(property)) {
|
|
|
|
removeObjectFromList(property, object, nodeInstanceServer()->engine());
|
|
|
|
} else if (isObject(property)) {
|
|
|
|
if (nodeInstanceServer()->hasInstanceForObject(oldParent)) {
|
|
|
|
nodeInstanceServer()->instanceForObject(oldParent).resetProperty(oldParentProperty);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (object && object->parent())
|
|
|
|
object->setParent(0);
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::addToNewProperty(QObject *object, QObject *newParent, const PropertyName &newParentProperty)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2016-03-18 10:19:09 +01:00
|
|
|
QQmlProperty property(newParent, QString::fromUtf8(newParentProperty), context());
|
2012-09-19 15:57:22 +02:00
|
|
|
|
2013-04-30 12:40:01 +02:00
|
|
|
if (object)
|
|
|
|
object->setParent(newParent);
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
if (isList(property)) {
|
|
|
|
QQmlListReference list = qvariant_cast<QQmlListReference>(property.read());
|
|
|
|
|
2015-05-19 16:06:19 +02:00
|
|
|
if (!QmlPrivateGate::hasFullImplementedListInterface(list)) {
|
2012-09-19 15:57:22 +02:00
|
|
|
qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
list.append(object);
|
|
|
|
} else if (isObject(property)) {
|
|
|
|
property.write(objectToVariant(object));
|
2016-10-13 11:59:09 +02:00
|
|
|
|
|
|
|
if (QQuickItem *item = qobject_cast<QQuickItem *>(object))
|
|
|
|
if (QQuickItem *newParentItem = qobject_cast<QQuickItem *>(newParent))
|
|
|
|
item->setParentItem(newParentItem);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Q_ASSERT(objectToVariant(object).isValid());
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::reparent(const ObjectNodeInstance::Pointer &oldParentInstance, const PropertyName &oldParentProperty, const ObjectNodeInstance::Pointer &newParentInstance, const PropertyName &newParentProperty)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2014-04-17 17:41:18 +02:00
|
|
|
if (oldParentInstance && !oldParentInstance->ignoredProperties().contains(oldParentProperty)) {
|
2012-09-19 15:57:22 +02:00
|
|
|
removeFromOldProperty(object(), oldParentInstance->object(), oldParentProperty);
|
|
|
|
m_parentProperty.clear();
|
|
|
|
}
|
|
|
|
|
2014-04-17 17:41:18 +02:00
|
|
|
if (newParentInstance && !newParentInstance->ignoredProperties().contains(newParentProperty)) {
|
2012-09-19 15:57:22 +02:00
|
|
|
m_parentProperty = newParentProperty;
|
|
|
|
addToNewProperty(object(), newParentInstance->object(), newParentProperty);
|
|
|
|
}
|
|
|
|
}
|
2014-04-17 17:41:18 +02:00
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QVariant ObjectNodeInstance::convertSpecialCharacter(const QVariant& value) const
|
|
|
|
{
|
|
|
|
QVariant specialCharacterConvertedValue = value;
|
|
|
|
if (value.type() == QVariant::String) {
|
|
|
|
QString string = value.toString();
|
|
|
|
string.replace(QLatin1String("\\n"), QLatin1String("\n"));
|
|
|
|
string.replace(QLatin1String("\\t"), QLatin1String("\t"));
|
|
|
|
specialCharacterConvertedValue = string;
|
|
|
|
}
|
|
|
|
|
|
|
|
return specialCharacterConvertedValue;
|
|
|
|
}
|
|
|
|
|
2013-06-18 14:57:34 +02:00
|
|
|
void ObjectNodeInstance::updateAllDirtyNodesRecursive()
|
2013-04-15 13:28:48 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-04-17 17:41:18 +02:00
|
|
|
PropertyNameList ObjectNodeInstance::ignoredProperties() const
|
|
|
|
{
|
|
|
|
return PropertyNameList();
|
|
|
|
}
|
|
|
|
|
2014-08-21 13:34:22 +02:00
|
|
|
QVariant ObjectNodeInstance::convertEnumToValue(const QVariant &value, const PropertyName &name)
|
|
|
|
{
|
2014-09-09 13:38:40 +02:00
|
|
|
Q_ASSERT(value.canConvert<Enumeration>());
|
|
|
|
int propertyIndex = object()->metaObject()->indexOfProperty(name);
|
|
|
|
QMetaProperty metaProperty = object()->metaObject()->property(propertyIndex);
|
|
|
|
|
|
|
|
QVariant adjustedValue;
|
|
|
|
Enumeration enumeration = value.value<Enumeration>();
|
|
|
|
if (metaProperty.isValid() && metaProperty.isEnumType()) {
|
|
|
|
adjustedValue = metaProperty.enumerator().keyToValue(enumeration.name());
|
|
|
|
} else {
|
|
|
|
QQmlExpression expression(context(), object(), enumeration.toString());
|
|
|
|
adjustedValue = expression.evaluate();
|
|
|
|
if (expression.hasError())
|
2018-10-22 16:34:31 +02:00
|
|
|
qDebug() << "Enumeration cannot be evaluated:" << object() << name << enumeration;
|
2014-08-21 13:34:22 +02:00
|
|
|
}
|
2014-09-09 13:38:40 +02:00
|
|
|
return adjustedValue;
|
2014-08-21 13:34:22 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::setPropertyVariant(const PropertyName &name, const QVariant &value)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2014-04-17 17:41:18 +02:00
|
|
|
if (ignoredProperties().contains(name))
|
|
|
|
return;
|
|
|
|
|
2016-03-18 10:19:09 +01:00
|
|
|
QQmlProperty property(object(), QString::fromUtf8(name), context());
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
if (!property.isValid())
|
|
|
|
return;
|
|
|
|
|
2014-09-09 13:38:40 +02:00
|
|
|
QVariant adjustedValue;
|
|
|
|
if (value.canConvert<Enumeration>())
|
|
|
|
adjustedValue = convertEnumToValue(value, name);
|
|
|
|
else
|
2015-05-19 10:54:16 +02:00
|
|
|
adjustedValue = QmlPrivateGate::fixResourcePaths(value);
|
2014-09-09 13:38:40 +02:00
|
|
|
|
2013-12-16 12:50:32 +01:00
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QVariant oldValue = property.read();
|
|
|
|
if (oldValue.type() == QVariant::Url) {
|
|
|
|
QUrl url = oldValue.toUrl();
|
|
|
|
QString path = url.toLocalFile();
|
2017-04-13 16:26:38 +02:00
|
|
|
if (QFileInfo::exists(path) && nodeInstanceServer() && !path.isEmpty())
|
2012-09-19 15:57:22 +02:00
|
|
|
nodeInstanceServer()->removeFilePropertyFromFileSystemWatcher(object(), name, path);
|
|
|
|
}
|
|
|
|
|
2015-05-19 16:48:47 +02:00
|
|
|
if (hasValidResetBinding(name)) {
|
|
|
|
QmlPrivateGate::keepBindingFromGettingDeleted(object(), context(), name);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2014-09-09 13:38:40 +02:00
|
|
|
bool isWritten = property.write(convertSpecialCharacter(adjustedValue));
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
if (!isWritten)
|
2014-09-09 13:38:40 +02:00
|
|
|
qDebug() << "ObjectNodeInstance.setPropertyVariant: Cannot be written: " << object() << name << adjustedValue;
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
QVariant newValue = property.read();
|
|
|
|
if (newValue.type() == QVariant::Url) {
|
|
|
|
QUrl url = newValue.toUrl();
|
|
|
|
QString path = url.toLocalFile();
|
2017-04-13 16:26:38 +02:00
|
|
|
if (QFileInfo::exists(path) && nodeInstanceServer() && !path.isEmpty())
|
2012-09-19 15:57:22 +02:00
|
|
|
nodeInstanceServer()->addFilePropertyToFileSystemWatcher(object(), name, path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::setPropertyBinding(const PropertyName &name, const QString &expression)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2014-04-17 17:41:18 +02:00
|
|
|
if (ignoredProperties().contains(name))
|
|
|
|
return;
|
|
|
|
|
2014-08-08 11:44:06 +02:00
|
|
|
if (!isSimpleExpression(expression))
|
|
|
|
return;
|
|
|
|
|
2015-05-19 16:37:55 +02:00
|
|
|
QmlPrivateGate::setPropertyBinding(object(), context(), name, expression);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::deleteObjectsInList(const QQmlProperty &property)
|
|
|
|
{
|
|
|
|
QObjectList objectList;
|
|
|
|
QQmlListReference list = qvariant_cast<QQmlListReference>(property.read());
|
|
|
|
|
2015-05-19 16:06:19 +02:00
|
|
|
if (!QmlPrivateGate::hasFullImplementedListInterface(list)) {
|
2012-09-19 15:57:22 +02:00
|
|
|
qWarning() << "Property list interface not fully implemented for Class " << property.property().typeName() << " in property " << property.name() << "!";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < list.count(); i++) {
|
|
|
|
objectList += list.at(i);
|
|
|
|
}
|
|
|
|
|
|
|
|
list.clear();
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::resetProperty(const PropertyName &name)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2014-04-17 17:41:18 +02:00
|
|
|
if (ignoredProperties().contains(name))
|
|
|
|
return;
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
doResetProperty(name);
|
|
|
|
|
|
|
|
if (name == "font.pixelSize")
|
|
|
|
doResetProperty("font.pointSize");
|
|
|
|
|
|
|
|
if (name == "font.pointSize")
|
|
|
|
doResetProperty("font.pixelSize");
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::refreshProperty(const PropertyName &name)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2016-03-18 10:19:09 +01:00
|
|
|
QQmlProperty property(object(), QString::fromUtf8(name), context());
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
if (!property.isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
QVariant oldValue(property.read());
|
|
|
|
|
|
|
|
if (property.isResettable())
|
|
|
|
property.reset();
|
|
|
|
else
|
|
|
|
property.write(resetValue(name));
|
|
|
|
|
|
|
|
if (oldValue.type() == QVariant::Url) {
|
|
|
|
QByteArray key = oldValue.toUrl().toEncoded(QUrl::UrlFormattingOption(0x100));
|
2013-03-05 12:19:19 +01:00
|
|
|
QString pixmapKey = QString::fromUtf8(key.constData(), key.count());
|
2012-09-19 15:57:22 +02:00
|
|
|
QPixmapCache::remove(pixmapKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
property.write(oldValue);
|
|
|
|
}
|
|
|
|
|
2015-05-19 16:11:35 +02:00
|
|
|
bool ObjectNodeInstance::hasBindingForProperty(const PropertyName &propertyName, bool *hasChanged) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-19 16:37:55 +02:00
|
|
|
return QmlPrivateGate::hasBindingForProperty(object(), context(), propertyName, hasChanged);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
void ObjectNodeInstance::doResetProperty(const PropertyName &propertyName)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-19 16:37:55 +02:00
|
|
|
QmlPrivateGate::doResetProperty(object(), context(), propertyName);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
QVariant ObjectNodeInstance::property(const PropertyName &name) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2014-04-17 17:41:18 +02:00
|
|
|
if (ignoredProperties().contains(name))
|
|
|
|
return QVariant();
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
// TODO: handle model nodes
|
|
|
|
|
2015-05-18 19:09:33 +02:00
|
|
|
if (QmlPrivateGate::isPropertyBlackListed(name))
|
2013-04-10 15:34:50 +02:00
|
|
|
return QVariant();
|
|
|
|
|
2016-03-18 10:19:09 +01:00
|
|
|
QQmlProperty property(object(), QString::fromUtf8(name), context());
|
2012-09-19 15:57:22 +02:00
|
|
|
if (property.property().isEnumType()) {
|
|
|
|
QVariant value = property.read();
|
|
|
|
return property.property().enumerator().valueToKey(value.toInt());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (property.propertyType() == QVariant::Url) {
|
|
|
|
QUrl url = property.read().toUrl();
|
|
|
|
if (url.isEmpty())
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
if (url.scheme() == "file") {
|
|
|
|
int basePathLength = nodeInstanceServer()->fileUrl().toLocalFile().lastIndexOf('/');
|
|
|
|
return QUrl(url.toLocalFile().mid(basePathLength + 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return property.read();
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
PropertyNameList ObjectNodeInstance::propertyNames() const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
if (isValid())
|
2015-05-19 10:04:50 +02:00
|
|
|
return QmlPrivateGate::allPropertyNames(object());
|
2013-03-05 12:19:19 +01:00
|
|
|
return PropertyNameList();
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
QString ObjectNodeInstance::instanceType(const PropertyName &name) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-18 19:09:33 +02:00
|
|
|
if (QmlPrivateGate::isPropertyBlackListed(name))
|
2013-04-10 15:34:50 +02:00
|
|
|
return QLatin1String("undefined");
|
|
|
|
|
2016-03-18 10:19:09 +01:00
|
|
|
QQmlProperty property(object(), QString::fromUtf8(name), context());
|
2012-09-19 15:57:22 +02:00
|
|
|
if (!property.isValid())
|
|
|
|
return QLatin1String("undefined");
|
2016-03-18 10:19:09 +01:00
|
|
|
return QString::fromUtf8(property.propertyTypeName());
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QList<ServerNodeInstance> ObjectNodeInstance::childItems() const
|
|
|
|
{
|
|
|
|
return QList<ServerNodeInstance>();
|
|
|
|
}
|
|
|
|
|
2014-04-16 12:33:50 +02:00
|
|
|
QList<QQuickItem *> ObjectNodeInstance::allItemsRecursive() const
|
|
|
|
{
|
|
|
|
return QList<QQuickItem *>();
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QList<ServerNodeInstance> ObjectNodeInstance::stateInstances() const
|
|
|
|
{
|
|
|
|
return QList<ServerNodeInstance>();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::setNodeSource(const QString & /*source*/)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::setDeleteHeldInstance(bool deleteInstance)
|
|
|
|
{
|
|
|
|
m_deleteHeldInstance = deleteInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::deleteHeldInstance() const
|
|
|
|
{
|
|
|
|
return m_deleteHeldInstance;
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectNodeInstance::Pointer ObjectNodeInstance::create(QObject *object)
|
|
|
|
{
|
|
|
|
Pointer instance(new ObjectNodeInstance(object));
|
|
|
|
|
|
|
|
instance->populateResetHashes();
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2015-05-18 19:09:33 +02:00
|
|
|
QObject *ObjectNodeInstance::createPrimitive(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2017-02-21 15:00:26 +01:00
|
|
|
QString polishTypeName = typeName;
|
|
|
|
if (typeName == "QtQuick.Controls/Popup"
|
|
|
|
|| typeName == "QtQuick.Controls/Drawer"
|
|
|
|
|| typeName == "QtQuick.Controls/Dialog"
|
|
|
|
|| typeName == "QtQuick.Controls/Menu"
|
|
|
|
|| typeName == "QtQuick.Controls/ToolTip")
|
|
|
|
polishTypeName = "QtQuick/Item";
|
|
|
|
|
2017-05-03 17:59:38 +02:00
|
|
|
const QHash<QString, QString> mockHash = {{"QtQuick.Controls/SwipeView","qrc:/qtquickplugin/mockfiles/SwipeView.qml"}};
|
|
|
|
|
|
|
|
QObject *object = nullptr;
|
|
|
|
|
|
|
|
if (mockHash.contains(typeName))
|
|
|
|
object = QmlPrivateGate::createComponent(mockHash.value(typeName), context);
|
|
|
|
else
|
|
|
|
object = QmlPrivateGate::createPrimitive(polishTypeName, majorNumber, minorNumber, context);
|
2016-10-31 14:34:32 +01:00
|
|
|
|
|
|
|
/* Let's try to create the primitive from source, since with incomplete meta info this might be a pure
|
|
|
|
* QML type. This is the case for example if a C++ type is mocked up with a QML file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (!object)
|
2017-02-21 15:00:26 +01:00
|
|
|
object = createPrimitiveFromSource(polishTypeName, majorNumber, minorNumber, context);
|
2016-10-31 14:34:32 +01:00
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject *ObjectNodeInstance::createPrimitiveFromSource(const QString &typeName, int majorNumber, int minorNumber, QQmlContext *context)
|
|
|
|
{
|
|
|
|
if (typeName.isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
QStringList parts = typeName.split("/");
|
|
|
|
const QString unqualifiedTypeName = parts.last();
|
|
|
|
parts.removeLast();
|
|
|
|
|
|
|
|
if (parts.isEmpty())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
const QString importString = parts.join(".") + " " + QString::number(majorNumber) + "." + QString::number(minorNumber);
|
|
|
|
QString source = "import " + importString + "\n" + unqualifiedTypeName + " {\n" + "}\n";
|
|
|
|
return createCustomParserObject(source, "", context);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2014-09-25 12:57:57 +02:00
|
|
|
QObject *ObjectNodeInstance::createComponentWrap(const QString &nodeSource, const QByteArray &importCode, QQmlContext *context)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-19 10:15:40 +02:00
|
|
|
QmlPrivateGate::ComponentCompleteDisabler disableComponentComplete;
|
2013-04-22 17:52:57 +02:00
|
|
|
Q_UNUSED(disableComponentComplete)
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QQmlComponent *component = new QQmlComponent(context->engine());
|
|
|
|
|
|
|
|
QByteArray data(nodeSource.toUtf8());
|
2014-09-25 12:57:57 +02:00
|
|
|
data.prepend(importCode);
|
2012-09-19 15:57:22 +02:00
|
|
|
component->setData(data, context->baseUrl().resolved(QUrl("createComponent.qml")));
|
|
|
|
QObject *object = component;
|
2015-05-18 19:09:33 +02:00
|
|
|
QmlPrivateGate::tweakObjects(object);
|
2014-05-05 17:20:49 +03:00
|
|
|
QQmlEngine::setContextForObject(object, context);
|
2012-09-19 15:57:22 +02:00
|
|
|
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
|
|
|
|
|
2014-10-09 13:35:12 +02:00
|
|
|
if (component->isError()) {
|
|
|
|
qWarning() << "Error in:" << Q_FUNC_INFO << component->url().toString();
|
|
|
|
foreach (const QQmlError &error, component->errors())
|
|
|
|
qWarning() << error;
|
|
|
|
qWarning() << "file data:\n" << data;
|
|
|
|
}
|
2012-09-19 15:57:22 +02:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
//The component might also be shipped with Creator.
|
|
|
|
//To avoid trouble with import "." we use the component shipped with Creator.
|
|
|
|
static inline QString fixComponentPathForIncompatibleQt(const QString &componentPath)
|
|
|
|
{
|
|
|
|
QString result = componentPath;
|
|
|
|
const QLatin1String importString("/imports/");
|
|
|
|
|
|
|
|
if (componentPath.contains(importString)) {
|
|
|
|
int index = componentPath.indexOf(importString) + 8;
|
|
|
|
const QString relativeImportPath = componentPath.right(componentPath.length() - index);
|
2018-10-09 12:34:23 +02:00
|
|
|
QString fixedComponentPath = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath) + relativeImportPath;
|
2012-09-19 15:57:22 +02:00
|
|
|
fixedComponentPath.replace(QLatin1Char('\\'), QLatin1Char('/'));
|
2017-04-13 16:26:38 +02:00
|
|
|
if (QFileInfo::exists(fixedComponentPath))
|
2012-09-19 15:57:22 +02:00
|
|
|
return fixedComponentPath;
|
|
|
|
QString fixedPath = QFileInfo(fixedComponentPath).path();
|
|
|
|
if (fixedPath.endsWith(QLatin1String(".1.0"))) {
|
|
|
|
//plugin directories might contain the version number
|
|
|
|
fixedPath.chop(4);
|
|
|
|
fixedPath += QLatin1Char('/') + QFileInfo(componentPath).fileName();
|
2017-10-19 08:34:06 +02:00
|
|
|
if (QFileInfo::exists(fixedPath))
|
2012-09-19 15:57:22 +02:00
|
|
|
return fixedPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject *ObjectNodeInstance::createComponent(const QString &componentPath, QQmlContext *context)
|
|
|
|
{
|
2015-05-19 10:15:40 +02:00
|
|
|
QmlPrivateGate::ComponentCompleteDisabler disableComponentComplete;
|
2013-04-22 17:52:57 +02:00
|
|
|
|
|
|
|
Q_UNUSED(disableComponentComplete)
|
|
|
|
|
2012-10-10 15:59:45 +02:00
|
|
|
QQmlComponent component(context->engine(), fixComponentPathForIncompatibleQt(componentPath));
|
2012-09-19 15:57:22 +02:00
|
|
|
QObject *object = component.beginCreate(context);
|
|
|
|
|
2015-05-18 19:09:33 +02:00
|
|
|
QmlPrivateGate::tweakObjects(object);
|
2012-09-19 15:57:22 +02:00
|
|
|
component.completeCreate();
|
|
|
|
|
|
|
|
if (component.isError()) {
|
|
|
|
qDebug() << componentPath;
|
|
|
|
foreach (const QQmlError &error, component.errors())
|
2014-10-09 13:35:12 +02:00
|
|
|
qWarning() << error;
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
|
|
|
|
|
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
2013-10-29 14:28:43 +01:00
|
|
|
QObject *ObjectNodeInstance::createComponent(const QUrl &componentUrl, QQmlContext *context)
|
|
|
|
{
|
2015-05-19 10:12:52 +02:00
|
|
|
return QmlPrivateGate::createComponent(componentUrl, context);
|
2013-10-29 14:28:43 +01:00
|
|
|
}
|
|
|
|
|
2014-09-25 12:57:57 +02:00
|
|
|
QObject *ObjectNodeInstance::createCustomParserObject(const QString &nodeSource, const QByteArray &importCode, QQmlContext *context)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-19 10:15:40 +02:00
|
|
|
QmlPrivateGate::ComponentCompleteDisabler disableComponentComplete;
|
2013-04-22 17:52:57 +02:00
|
|
|
Q_UNUSED(disableComponentComplete)
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
QQmlComponent component(context->engine());
|
|
|
|
|
|
|
|
QByteArray data(nodeSource.toUtf8());
|
2014-09-25 12:57:57 +02:00
|
|
|
data.prepend(importCode);
|
2012-09-19 15:57:22 +02:00
|
|
|
component.setData(data, context->baseUrl().resolved(QUrl("createCustomParserObject.qml")));
|
|
|
|
QObject *object = component.beginCreate(context);
|
2015-05-18 19:09:33 +02:00
|
|
|
QmlPrivateGate::tweakObjects(object);
|
2012-09-19 15:57:22 +02:00
|
|
|
component.completeCreate();
|
|
|
|
QQmlEngine::setObjectOwnership(object, QQmlEngine::CppOwnership);
|
|
|
|
|
2014-10-09 13:35:12 +02:00
|
|
|
if (component.isError()) {
|
|
|
|
qWarning() << "Error in:" << Q_FUNC_INFO << component.url().toString();
|
|
|
|
foreach (const QQmlError &error, component.errors())
|
|
|
|
qWarning() << error;
|
|
|
|
qWarning() << "file data:\n" << data;
|
|
|
|
}
|
2012-09-19 15:57:22 +02:00
|
|
|
return object;
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject *ObjectNodeInstance::object() const
|
|
|
|
{
|
2015-05-19 16:54:38 +02:00
|
|
|
if (!m_object.isNull() && !QmlPrivateGate::objectWasDeleted(m_object.data()))
|
2012-09-19 15:57:22 +02:00
|
|
|
return m_object.data();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-05-28 14:14:07 +02:00
|
|
|
QQuickItem *ObjectNodeInstance::contentItem() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-09-19 15:57:22 +02:00
|
|
|
bool ObjectNodeInstance::hasContent() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isResizable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isMovable() const
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-04-18 18:42:58 +02:00
|
|
|
bool ObjectNodeInstance::isInLayoutable() const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2013-04-18 18:42:58 +02:00
|
|
|
return m_isInLayoutable;
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-04-18 18:42:58 +02:00
|
|
|
void ObjectNodeInstance::setInLayoutable(bool isInLayoutable)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2013-04-18 18:42:58 +02:00
|
|
|
m_isInLayoutable = isInLayoutable;
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-04-18 18:42:58 +02:00
|
|
|
void ObjectNodeInstance::refreshLayoutable()
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::updateAnchors()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlContext *ObjectNodeInstance::context() const
|
|
|
|
{
|
|
|
|
if (nodeInstanceServer())
|
|
|
|
return nodeInstanceServer()->context();
|
|
|
|
|
|
|
|
qWarning() << "Error: No NodeInstanceServer";
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
QQmlEngine *ObjectNodeInstance::engine() const
|
|
|
|
{
|
|
|
|
return nodeInstanceServer()->engine();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::paintUpdate()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::activateState()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::deactivateState()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::populateResetHashes()
|
|
|
|
{
|
2015-05-19 16:37:55 +02:00
|
|
|
QmlPrivateGate::registerCustomData(object());
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
bool ObjectNodeInstance::hasValidResetBinding(const PropertyName &propertyName) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-19 16:11:35 +02:00
|
|
|
return QmlPrivateGate::hasValidResetBinding(object(), propertyName);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
QVariant ObjectNodeInstance::resetValue(const PropertyName &propertyName) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2015-05-19 16:11:35 +02:00
|
|
|
return QmlPrivateGate::getResetValue(object(), propertyName);
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QImage ObjectNodeInstance::renderImage() const
|
|
|
|
{
|
|
|
|
return QImage();
|
|
|
|
}
|
|
|
|
|
2013-04-15 13:28:48 +02:00
|
|
|
QImage ObjectNodeInstance::renderPreviewImage(const QSize & /*previewImageSize*/) const
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
return QImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
QObject *ObjectNodeInstance::parent() const
|
|
|
|
{
|
|
|
|
if (!object())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return object()->parent();
|
|
|
|
}
|
|
|
|
|
2013-05-21 16:49:28 +02:00
|
|
|
QObject *ObjectNodeInstance::parentObject(QObject *object)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
2012-09-26 14:00:27 +02:00
|
|
|
QQuickItem *quickItem = qobject_cast<QQuickItem*>(object);
|
2016-03-22 11:52:51 +01:00
|
|
|
if (quickItem && quickItem->parentItem())
|
2012-09-26 14:00:27 +02:00
|
|
|
return quickItem->parentItem();
|
2012-09-19 15:57:22 +02:00
|
|
|
|
|
|
|
return object->parent();
|
|
|
|
}
|
|
|
|
|
|
|
|
ObjectNodeInstance::Pointer ObjectNodeInstance::parentInstance() const
|
|
|
|
{
|
|
|
|
QObject *parentHolder = parent();
|
|
|
|
if (!nodeInstanceServer())
|
|
|
|
return Pointer();
|
|
|
|
|
|
|
|
while (parentHolder) {
|
|
|
|
if (nodeInstanceServer()->hasInstanceForObject(parentHolder))
|
|
|
|
return nodeInstanceServer()->instanceForObject(parentHolder).internalInstance();
|
|
|
|
|
|
|
|
parentHolder = parentObject(parentHolder);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Pointer();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF ObjectNodeInstance::boundingRect() const
|
|
|
|
{
|
2013-05-28 14:14:07 +02:00
|
|
|
return QRectF();
|
|
|
|
}
|
|
|
|
|
|
|
|
QRectF ObjectNodeInstance::contentItemBoundingBox() const
|
|
|
|
{
|
|
|
|
return QRectF();
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QPointF ObjectNodeInstance::position() const
|
|
|
|
{
|
|
|
|
return QPointF();
|
|
|
|
}
|
|
|
|
|
|
|
|
QSizeF ObjectNodeInstance::size() const
|
|
|
|
{
|
|
|
|
return QSizeF();
|
|
|
|
}
|
|
|
|
|
|
|
|
int ObjectNodeInstance::penWidth() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
bool ObjectNodeInstance::updateStateVariant(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QVariant &/*value*/)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
bool ObjectNodeInstance::updateStateBinding(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QString &/*expression*/)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-05 12:19:19 +01:00
|
|
|
bool ObjectNodeInstance::resetStateProperty(const ObjectNodeInstance::Pointer &/*target*/, const PropertyName &/*propertyName*/, const QVariant &/*resetValue*/)
|
2012-09-19 15:57:22 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectNodeInstance::doComponentComplete()
|
|
|
|
{
|
2015-05-20 15:01:55 +02:00
|
|
|
QmlPrivateGate::doComponentCompleteRecursive(object(), nodeInstanceServer());
|
2012-09-19 15:57:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isRootNodeInstance() const
|
|
|
|
{
|
|
|
|
return nodeInstanceServer()->rootNodeInstance().isWrappingThisObject(object());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectNodeInstance::isValid() const
|
|
|
|
{
|
|
|
|
return instanceId() >= 0 && object();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|