Commit b8881fea authored by Marco Bubke's avatar Marco Bubke
Browse files

QmlDesigner.NodeInstances: FileSystemWatcher for dummy data

parent b2389a16
......@@ -401,6 +401,15 @@ void NodeInstanceServer::removeAllInstanceRelationships()
m_objectInstanceHash.clear();
}
QFileSystemWatcher *NodeInstanceServer::dummydataFileSystemWatcher()
{
if (m_dummdataFileSystemWatcher.isNull()) {
m_dummdataFileSystemWatcher = new QFileSystemWatcher(this);
connect(m_dummdataFileSystemWatcher.data(), SIGNAL(fileChanged(QString)), this, SLOT(refreshDummyData(QString)));
}
return m_dummdataFileSystemWatcher.data();
}
QFileSystemWatcher *NodeInstanceServer::fileSystemWatcher()
{
......@@ -445,6 +454,13 @@ void NodeInstanceServer::refreshLocalFileProperty(const QString &path)
}
}
void NodeInstanceServer::refreshDummyData(const QString &path)
{
engine()->clearComponentCache();
loadDummyDataFile(QFileInfo(path));
startRenderTimer();
}
void NodeInstanceServer::addChangedProperty(const InstancePropertyPair &property)
{
if (!m_changedPropertyList.contains(property))
......@@ -848,26 +864,38 @@ QImage NodeInstanceServer::renderPreviewImage()
return image;
}
void NodeInstanceServer::loadDummyDataFiles(const QString& directory)
void NodeInstanceServer::loadDummyDataFile(const QFileInfo& qmlFileInfo)
{
QDir dir(directory, "*.qml");
QList<QFileInfo> filePathList = dir.entryInfoList();
foreach (const QFileInfo &qmlFileInfo, filePathList) {
QDeclarativeComponent component(engine(), qmlFileInfo.filePath());
QObject *dummyData = component.create();
if(component.isError()) {
QList<QDeclarativeError> errors = component.errors();
foreach (const QDeclarativeError &error, errors) {
qWarning() << error;
}
QDeclarativeComponent component(engine(), qmlFileInfo.filePath());
QObject *dummyData = component.create();
if(component.isError()) {
QList<QDeclarativeError> errors = component.errors();
foreach (const QDeclarativeError &error, errors) {
qWarning() << error;
}
}
if (dummyData) {
qWarning() << "Loaded dummy data:" << qmlFileInfo.path();
m_declarativeView->rootContext()->setContextProperty(qmlFileInfo.completeBaseName(), dummyData);
dummyData->setParent(this);
}
QVariant oldDummyDataObject = m_declarativeView->rootContext()->contextProperty(qmlFileInfo.completeBaseName());
if (dummyData) {
qWarning() << "Loaded dummy data:" << qmlFileInfo.filePath();
m_declarativeView->rootContext()->setContextProperty(qmlFileInfo.completeBaseName(), dummyData);
dummyData->setParent(this);
}
if (!oldDummyDataObject.isNull())
delete oldDummyDataObject.value<QObject*>();
if (!dummydataFileSystemWatcher()->files().contains(qmlFileInfo.filePath()))
dummydataFileSystemWatcher()->addPath(qmlFileInfo.filePath());
}
void NodeInstanceServer::loadDummyDataFiles(const QString& directory)
{
QDir dir(directory, "*.qml");
QList<QFileInfo> filePathList = dir.entryInfoList();
foreach (const QFileInfo &qmlFileInfo, filePathList)
loadDummyDataFile(qmlFileInfo);
}
QStringList dummyDataDirectories(const QString& directoryPath)
......
......@@ -14,6 +14,7 @@ class QFileSystemWatcher;
class QDeclarativeView;
class QDeclarativeEngine;
class QGraphicsObject;
class QFileInfo;
QT_END_NAMESPACE
namespace QmlDesigner {
......@@ -66,6 +67,7 @@ public:
void removeAllInstanceRelationships();
QFileSystemWatcher *fileSystemWatcher();
QFileSystemWatcher *dummydataFileSystemWatcher();
Internal::ChildrenChangeEventFilter *childrenChangeEventFilter() const;
void addFilePropertyToFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path);
void removeFilePropertyFromFileSystemWatcher(QObject *object, const QString &propertyName, const QString &path);
......@@ -84,6 +86,7 @@ public:
public slots:
void refreshLocalFileProperty(const QString &path);
void refreshDummyData(const QString &path);
void emitParentChanged(QObject *child);
protected:
......@@ -128,7 +131,7 @@ protected:
void initializeDeclarativeView();
QList<ServerNodeInstance> setupScene(const CreateSceneCommand &command);
void loadDummyDataFiles(const QString& directory);
void loadDummyDataFile(const QFileInfo& fileInfo);
QImage renderPreviewImage();
void setTimerId(int timerId);
......@@ -141,6 +144,7 @@ private:
QHash<QObject*, ServerNodeInstance> m_objectInstanceHash;
QMultiHash<QString, ObjectPropertyPair> m_fileSystemWatcherHash;
QWeakPointer<QFileSystemWatcher> m_fileSystemWatcher;
QWeakPointer<QFileSystemWatcher> m_dummdataFileSystemWatcher;
QWeakPointer<QDeclarativeView> m_declarativeView;
QWeakPointer<Internal::ChildrenChangeEventFilter> m_childrenChangeEventFilter;
QUrl m_fileUrl;
......
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