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

QmlDesigner.NodeInstances: Add dummydata support in the visual editor

dummydata directories are searched recursive too.
parent 0434083b
......@@ -848,10 +848,51 @@ QImage NodeInstanceServer::renderPreviewImage()
return image;
}
void NodeInstanceServer::loadDummyDataFiles(const QString& directory)
{
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;
}
}
if (dummyData) {
qWarning() << "Loaded dummy data:" << qmlFileInfo.path();
m_declarativeView->rootContext()->setContextProperty(qmlFileInfo.completeBaseName(), dummyData);
dummyData->setParent(this);
}
}
}
QStringList dummyDataDirectories(const QString& directoryPath)
{
QStringList dummyDataDirectoryList;
QDir directory(directoryPath);
while(true) {
if (directory.isRoot() || !directory.exists())
return dummyDataDirectoryList;
if (directory.exists("dummydata"))
dummyDataDirectoryList.prepend(directory.absoluteFilePath("dummydata"));
directory.cdUp();
}
}
QList<ServerNodeInstance> NodeInstanceServer::setupScene(const CreateSceneCommand &command)
{
if (!command.fileUrl().isEmpty())
if (!command.fileUrl().isEmpty()) {
engine()->setBaseUrl(command.fileUrl());
QStringList dummyDataDirectoryList = dummyDataDirectories(QFileInfo(command.fileUrl().toLocalFile()).path());
foreach(const QString &dummyDataDirectory, dummyDataDirectoryList)
loadDummyDataFiles(dummyDataDirectory);
}
addImports(command.imports());
......
......@@ -127,6 +127,7 @@ protected:
void initializeDeclarativeView();
QList<ServerNodeInstance> setupScene(const CreateSceneCommand &command);
void loadDummyDataFiles(const QString& directory);
QImage renderPreviewImage();
......
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