QmlDesigner: Allow qml2puppet to mockup C++ types

This allows Qt Quick Designer to register a component that can serve
as a mockup for known C++ components registered in e.g. main.cpp.

In many cases those components are the interface to the C++ backend.
While the C++ components itself are not relevant for the gui designer,
the user has to be able to instantiate gui components that use such C++
components.

We use the CreateSceneCommand to forward a list of C++ types to
qml2puppet.
Those types are then registered so that the imports and object institation
works.

Change-Id: I1543912f233f9a783998f3c6a1b48981b342ee80
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Thomas Hartmann
2016-09-29 15:30:29 +02:00
parent 5a3aa3fc3e
commit d3b4acfae2
11 changed files with 254 additions and 0 deletions

View File

@@ -34,6 +34,7 @@
#include <model.h>
#include <modelnode.h>
#include <metainfo.h>
#include <rewriterview.h>
#include "abstractproperty.h"
#include "variantproperty.h"
@@ -840,6 +841,44 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
foreach (const Import &import, model()->imports())
importVector.append(AddImportContainer(import.url(), import.file(), import.version(), import.alias(), import.importPaths()));
QVector<MockupTypeContainer> mockupTypesVector;
for (const CppTypeData &cppTypeData : model()->rewriterView()->getCppTypes()) {
const QString versionString = cppTypeData.versionString;
int majorVersion = -1;
int minorVersion = -1;
if (versionString.contains(QStringLiteral("."))) {
const QStringList splittedString = versionString.split(QStringLiteral("."));
majorVersion = splittedString.first().toInt();
minorVersion = splittedString.last().toInt();
}
bool isItem = false;
if (!cppTypeData.isSingleton) { /* Singletons only appear on the right hand sides of bindings and create just warnings. */
const TypeName typeName = cppTypeData.typeName.toUtf8();
const QString uri = cppTypeData.importUrl;
NodeMetaInfo metaInfo = model()->metaInfo(uri.toUtf8() + "." + typeName);
if (metaInfo.isValid())
isItem = metaInfo.isGraphicalItem();
MockupTypeContainer mockupType(typeName, uri, majorVersion, minorVersion, isItem);
mockupTypesVector.append(mockupType);
} else { /* We need a type for the signleton import */
const TypeName typeName = cppTypeData.typeName.toUtf8() + "Mockup";
const QString uri = cppTypeData.importUrl;
MockupTypeContainer mockupType(typeName, uri, majorVersion, minorVersion, isItem);
mockupTypesVector.append(mockupType);
}
}
return CreateSceneCommand(instanceContainerList,
reparentContainerList,
idContainerList,
@@ -847,6 +886,7 @@ CreateSceneCommand NodeInstanceView::createCreateSceneCommand()
bindingContainerList,
auxiliaryContainerVector,
importVector,
mockupTypesVector,
model()->fileUrl());
}