2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
|
|
|
|
|
** Contact: http://www.qt-project.org/legal
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02: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
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
2011-02-22 12:08:19 +01:00
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
2011-02-22 12:08:19 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2011-02-22 12:08:19 +01:00
|
|
|
|
2010-02-04 14:28:19 +01:00
|
|
|
#include "nodeinstancemetaobject.h"
|
|
|
|
|
|
2010-02-15 17:05:20 +01:00
|
|
|
#include "objectnodeinstance.h"
|
|
|
|
|
#include <QSharedPointer>
|
2010-03-19 14:12:23 +01:00
|
|
|
#include <QMetaProperty>
|
2010-02-15 17:05:20 +01:00
|
|
|
#include <qnumeric.h>
|
2012-08-06 13:42:46 +02:00
|
|
|
#include <QDebug>
|
2010-02-15 17:05:20 +01:00
|
|
|
|
2010-02-04 14:28:19 +01:00
|
|
|
namespace QmlDesigner {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-04-08 13:56:15 +02:00
|
|
|
NodeInstanceMetaObject::NodeInstanceMetaObject(const ObjectNodeInstance::Pointer &nodeInstance, QDeclarativeEngine *engine)
|
2011-02-09 12:56:28 +01:00
|
|
|
: QDeclarativeOpenMetaObject(nodeInstance->object(), new QDeclarativeOpenMetaObjectType(nodeInstance->object()->metaObject(), engine), true),
|
2010-02-15 17:05:20 +01:00
|
|
|
m_nodeInstance(nodeInstance),
|
2010-11-24 14:52:06 +01:00
|
|
|
m_context(nodeInstance->isRootNodeInstance() ? nodeInstance->context() : 0)
|
2010-02-15 17:05:20 +01:00
|
|
|
{
|
2010-04-08 13:56:15 +02:00
|
|
|
setCached(true);
|
2010-02-15 17:05:20 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-08 13:56:15 +02:00
|
|
|
NodeInstanceMetaObject::NodeInstanceMetaObject(const ObjectNodeInstancePointer &nodeInstance, QObject *object, const QString &prefix, QDeclarativeEngine *engine)
|
2011-02-09 12:56:28 +01:00
|
|
|
: QDeclarativeOpenMetaObject(object, new QDeclarativeOpenMetaObjectType(object->metaObject(), engine), true),
|
2010-02-15 17:05:20 +01:00
|
|
|
m_nodeInstance(nodeInstance),
|
|
|
|
|
m_prefix(prefix)
|
2010-02-04 14:28:19 +01:00
|
|
|
{
|
2010-04-08 13:56:15 +02:00
|
|
|
setCached(true);
|
2010-02-04 14:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NodeInstanceMetaObject::createNewProperty(const QString &name)
|
|
|
|
|
{
|
2011-02-09 12:56:28 +01:00
|
|
|
int id = createProperty(name.toLatin1(), 0);
|
2011-03-18 16:56:55 +01:00
|
|
|
setValue(id, QVariant());
|
2011-02-09 12:56:28 +01:00
|
|
|
Q_ASSERT(id >= 0);
|
2011-02-24 17:47:41 +01:00
|
|
|
Q_UNUSED(id)
|
2010-02-04 14:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-15 17:05:20 +01:00
|
|
|
int NodeInstanceMetaObject::metaCall(QMetaObject::Call call, int id, void **a)
|
2010-02-04 14:28:19 +01:00
|
|
|
{
|
2010-02-15 17:05:20 +01:00
|
|
|
int metaCallReturnValue = -1;
|
|
|
|
|
|
|
|
|
|
if (call == QMetaObject::WriteProperty
|
2010-04-26 13:54:36 +02:00
|
|
|
&& property(id).userType() == QMetaType::QVariant
|
2010-02-15 17:05:20 +01:00
|
|
|
&& reinterpret_cast<QVariant *>(a[0])->type() == QVariant::Double
|
|
|
|
|
&& qIsNaN(reinterpret_cast<QVariant *>(a[0])->toDouble())) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-26 13:54:36 +02:00
|
|
|
if (call == QMetaObject::WriteProperty
|
|
|
|
|
&& property(id).userType() == QMetaType::Double
|
|
|
|
|
&& qIsNaN(*reinterpret_cast<double*>(a[0]))) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (call == QMetaObject::WriteProperty
|
|
|
|
|
&& property(id).userType() == QMetaType::Float
|
|
|
|
|
&& qIsNaN(*reinterpret_cast<float*>(a[0]))) {
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 17:05:20 +01:00
|
|
|
QVariant oldValue;
|
|
|
|
|
|
|
|
|
|
if (call == QMetaObject::WriteProperty && !property(id).hasNotifySignal())
|
|
|
|
|
{
|
2011-05-06 13:28:09 +02:00
|
|
|
oldValue = property(id).read(object());
|
2010-02-15 17:05:20 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-08 17:46:15 +01:00
|
|
|
ObjectNodeInstance::Pointer objectNodeInstance = m_nodeInstance.toStrongRef();
|
|
|
|
|
|
|
|
|
|
if (parent() && id < parent()->propertyOffset()) {
|
2010-11-24 14:52:06 +01:00
|
|
|
metaCallReturnValue = parent()->metaCall(call, id, a);
|
2011-02-08 17:46:15 +01:00
|
|
|
} else {
|
2010-11-24 14:52:06 +01:00
|
|
|
metaCallReturnValue = QDeclarativeOpenMetaObject::metaCall(call, id, a);
|
2011-02-08 17:46:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((call == QMetaObject::WriteProperty || call == QMetaObject::ReadProperty) && metaCallReturnValue < 0) {
|
|
|
|
|
if (objectNodeInstance
|
|
|
|
|
&& objectNodeInstance->nodeInstanceServer()
|
|
|
|
|
&& objectNodeInstance->nodeInstanceServer()->dummyContextObject()
|
|
|
|
|
&& !(objectNodeInstance && !objectNodeInstance->isRootNodeInstance() && property(id).name() == QLatin1String("parent"))) {
|
|
|
|
|
|
|
|
|
|
QObject *contextDummyObject = objectNodeInstance->nodeInstanceServer()->dummyContextObject();
|
|
|
|
|
int properyIndex = contextDummyObject->metaObject()->indexOfProperty(property(id).name());
|
|
|
|
|
if (properyIndex >= 0)
|
|
|
|
|
metaCallReturnValue = contextDummyObject->qt_metacall(call, properyIndex, a);
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-02-15 17:05:20 +01:00
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
if (metaCallReturnValue >= 0
|
|
|
|
|
&& call == QMetaObject::WriteProperty
|
2010-02-15 17:05:20 +01:00
|
|
|
&& !property(id).hasNotifySignal()
|
2011-05-06 13:28:09 +02:00
|
|
|
&& oldValue != property(id).read(object()))
|
2010-11-24 14:52:06 +01:00
|
|
|
notifyPropertyChange(id);
|
2010-02-04 14:28:19 +01:00
|
|
|
|
2010-02-15 17:05:20 +01:00
|
|
|
return metaCallReturnValue;
|
2010-02-04 14:28:19 +01:00
|
|
|
}
|
|
|
|
|
|
2010-02-15 17:05:20 +01:00
|
|
|
void NodeInstanceMetaObject::notifyPropertyChange(int id)
|
|
|
|
|
{
|
|
|
|
|
ObjectNodeInstance::Pointer objectNodeInstance = m_nodeInstance.toStrongRef();
|
|
|
|
|
|
2010-11-24 14:52:06 +01:00
|
|
|
if (objectNodeInstance && objectNodeInstance->nodeInstanceServer()) {
|
2010-02-15 17:05:20 +01:00
|
|
|
if (id < type()->propertyOffset()) {
|
2010-11-24 14:52:06 +01:00
|
|
|
objectNodeInstance->nodeInstanceServer()->notifyPropertyChange(objectNodeInstance->instanceId(), m_prefix + property(id).name());
|
2010-02-15 17:05:20 +01:00
|
|
|
} else {
|
2010-11-24 14:52:06 +01:00
|
|
|
objectNodeInstance->nodeInstanceServer()->notifyPropertyChange(objectNodeInstance->instanceId(), m_prefix + name(id - type()->propertyOffset()));
|
2010-02-15 17:05:20 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-04 14:28:19 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace QmlDesigner
|