Commit 075b0aeb authored by Marco Bubke's avatar Marco Bubke

QmlDesigner.NodeInstances: Use dummy data for components too

Reviewed-By: Thomas Hartmann
parent e3c59a58
......@@ -124,6 +124,9 @@ QList<ServerNodeInstance> NodeInstanceServer::createInstances(const QVector<Ins
}
}
foreach (QDeclarativeContext* context, allSubContextsForObject(instance.internalObject()))
setupDummysForContext(context);
}
return instanceList;
......@@ -474,6 +477,43 @@ void NodeInstanceServer::clearChangedPropertyList()
m_changedPropertyList.clear();
}
void NodeInstanceServer::setupDummysForContext(QDeclarativeContext *context)
{
foreach (const DummyPair& dummyPair, m_dummyObjectList) {
if (dummyPair.second) {
context->setContextProperty(dummyPair.first, dummyPair.second.data());
}
}
}
QList<QDeclarativeContext*> NodeInstanceServer::allSubContextsForObject(QObject *object)
{
QList<QDeclarativeContext*> contextList;
if (object) {
foreach (QObject *subObject, allSubObjectsForObject(object)) {
QDeclarativeContext *contextOfObject = QDeclarativeEngine::contextForObject(subObject);
if (contextOfObject) {
if (contextOfObject != context() && !contextList.contains(contextOfObject))
contextList.append(contextOfObject);
}
}
}
return contextList;
}
QList<QObject*> NodeInstanceServer::allSubObjectsForObject(QObject *object)
{
QList<QObject*> subChildren;
if (object) {
subChildren = object->findChildren<QObject*>();
}
return subChildren;
}
void NodeInstanceServer::refreshBindings()
{
static int counter = 0;
......@@ -1003,6 +1043,7 @@ void NodeInstanceServer::loadDummyDataFile(const QFileInfo& qmlFileInfo)
qWarning() << "Loaded dummy data:" << qmlFileInfo.filePath();
m_declarativeView->rootContext()->setContextProperty(qmlFileInfo.completeBaseName(), dummyData);
dummyData->setParent(this);
m_dummyObjectList.append(DummyPair(qmlFileInfo.completeBaseName(), dummyData));
}
if (!oldDummyDataObject.isNull())
......@@ -1010,6 +1051,11 @@ void NodeInstanceServer::loadDummyDataFile(const QFileInfo& qmlFileInfo)
if (!dummydataFileSystemWatcher()->files().contains(qmlFileInfo.filePath()))
dummydataFileSystemWatcher()->addPath(qmlFileInfo.filePath());
if (rootNodeInstance().isValid() && rootNodeInstance().internalObject()) {
foreach (QDeclarativeContext *context, allSubContextsForObject(rootNodeInstance().internalObject()))
setupDummysForContext(context);
}
}
void NodeInstanceServer::loadDummyContextObjectFile(const QFileInfo& qmlFileInfo)
......
......@@ -73,6 +73,8 @@ public:
typedef QPair<QWeakPointer<QObject>, QString> ObjectPropertyPair;
typedef QPair<qint32, QString> IdPropertyPair;
typedef QPair<ServerNodeInstance, QString> InstancePropertyPair;
typedef QPair<QString, QWeakPointer<QObject> > DummyPair;
explicit NodeInstanceServer(NodeInstanceClientInterface *nodeInstanceClient);
~NodeInstanceServer();
......@@ -180,12 +182,18 @@ protected:
void refreshBindings();
void setupDummysForContext(QDeclarativeContext *context);
QList<QDeclarativeContext*> allSubContextsForObject(QObject *object);
static QList<QObject*> allSubObjectsForObject(QObject *object);
private:
ServerNodeInstance m_rootNodeInstance;
ServerNodeInstance m_activeStateInstance;
QHash<qint32, ServerNodeInstance> m_idInstanceHash;
QHash<QObject*, ServerNodeInstance> m_objectInstanceHash;
QMultiHash<QString, ObjectPropertyPair> m_fileSystemWatcherHash;
QList<QPair<QString, QWeakPointer<QObject> > > m_dummyObjectList;
QWeakPointer<QFileSystemWatcher> m_fileSystemWatcher;
QWeakPointer<QFileSystemWatcher> m_dummdataFileSystemWatcher;
QWeakPointer<QDeclarativeView> m_declarativeView;
......
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