Commit 0de18de1 authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Use a dummy context instead of the root context

All type information should be now available.
parent dfa37a8f
......@@ -336,19 +336,21 @@ void NodeInstanceServer::addImports(const QVector<AddImportContainer> &container
}
}
QDeclarativeComponent importComponent(engine(), 0);
delete m_importComponent.data();
delete m_importComponentObject.data();
m_importComponent = new QDeclarativeComponent(engine(), 0);
QString componentString;
foreach(const QString &importStatement, m_importList)
componentString += QString("%1").arg(importStatement);
componentString += QString("Item {}\n");
importComponent.setData(componentString.toUtf8(), fileUrl());
if (!importComponent.errorString().isEmpty())
qDebug() << "QmlDesigner.NodeInstances: import wrong: " << importComponent.errorString();
m_importComponent->setData(componentString.toUtf8(), fileUrl());
m_importComponentObject = m_importComponent->create();
refreshBindings();
if (!m_importComponent->errorString().isEmpty())
qDebug() << "QmlDesigner.NodeInstances: import wrong: " << m_importComponent->errorString();
}
void NodeInstanceServer::addImport(const AddImportCommand &command)
......@@ -415,6 +417,11 @@ QDeclarativeEngine *NodeInstanceServer::engine() const
return 0;
}
QDeclarativeContext *NodeInstanceServer::context() const
{
return QDeclarativeEngine::contextForObject(m_importComponentObject.data());
}
QDeclarativeView *NodeInstanceServer::delcarativeView() const
{
return m_declarativeView.data();
......
......@@ -15,6 +15,7 @@ class QDeclarativeView;
class QDeclarativeEngine;
class QGraphicsObject;
class QFileInfo;
class QDeclarativeComponent;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -63,6 +64,7 @@ public:
bool hasInstanceForObject(QObject *object) const;
QDeclarativeEngine *engine() const;
QDeclarativeContext *context() const;
void removeAllInstanceRelationships();
......@@ -165,6 +167,8 @@ private:
QStringList m_importList;
QList<ServerNodeInstance> m_completedComponentList;
QWeakPointer<QObject> m_dummyContextObject;
QWeakPointer<QDeclarativeComponent> m_importComponent;
QWeakPointer<QObject> m_importComponentObject;
};
}
......
......@@ -823,12 +823,10 @@ void ObjectNodeInstance::updateAnchors()
QDeclarativeContext *ObjectNodeInstance::context() const
{
QDeclarativeContext *context = QDeclarativeEngine::contextForObject(object());
if (context)
return context;
else if (nodeInstanceServer())
return nodeInstanceServer()->engine()->rootContext();
if (nodeInstanceServer())
return nodeInstanceServer()->context();
qWarning() << "Error: No NodeInstanceServer";
return 0;
}
......@@ -885,7 +883,7 @@ void ObjectNodeInstance::populateResetValueHash()
QStringList propertyNameList = propertyNameForWritableProperties(object());
foreach(const QString &propertyName, propertyNameList) {
QDeclarativeProperty property(object(), propertyName, context());
QDeclarativeProperty property(object(), propertyName, QDeclarativeEngine::contextForObject(object()));
if (property.isWritable())
m_resetValueHash.insert(propertyName, property.read());
}
......
......@@ -195,16 +195,16 @@ ServerNodeInstance ServerNodeInstance::create(NodeInstanceServer *nodeInstanceSe
Q_ASSERT(instanceContainer.instanceId() != -1);
Q_ASSERT(nodeInstanceServer);
QDeclarativeContext *context = nodeInstanceServer->engine()->rootContext();
QDeclarativeContext *context = nodeInstanceServer->context();
QObject *object = Internal::ObjectNodeInstance::createObject(instanceContainer.type(), instanceContainer.majorNumber(), instanceContainer.minorNumber(), instanceContainer.componentPath(), context);
ServerNodeInstance instance(createInstance(object));
instance.internalInstance()->setInstanceId(instanceContainer.instanceId());
instance.internalInstance()->setNodeInstanceServer(nodeInstanceServer);
instance.internalInstance()->setInstanceId(instanceContainer.instanceId());
instance.internalInstance()->initializePropertyWatcher(instance.m_nodeInstance);
//QObject::connect(instance.internalObject(), SIGNAL(destroyed(QObject*)), nodeInstanceView, SLOT(removeIdFromContext(QObject*)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment