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

@@ -41,6 +41,10 @@
#include <qmlprivategate.h>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
#include <private/qquickdesignersupportmetainfo_p.h>
#endif
#include <createinstancescommand.h>
#include <changefileurlcommand.h>
#include <clearscenecommand.h>
@@ -659,6 +663,25 @@ void NodeInstanceServer::setupDummysForContext(QQmlContext *context)
}
}
void NodeInstanceServer::setupMockupTypes(const QVector<MockupTypeContainer> &container)
{
for (const MockupTypeContainer &mockupType : container) {
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
QQuickDesignerSupportMetaInfo::registerMockupObject(mockupType.importUri().toUtf8(),
mockupType.majorVersion(),
mockupType.minorVersion(),
mockupType.typeName());
#else
qmlRegisterType(QUrl("qrc:/qtquickplugin/mockfiles/GenericBackend.qml"),
mockupType.importUri().toUtf8(),
mockupType.majorVersion(),
mockupType.minorVersion(),
mockupType.typeName());
#endif
}
}
QList<QQmlContext*> NodeInstanceServer::allSubContextsForObject(QObject *object)
{

View File

@@ -54,6 +54,7 @@ class ChildrenChangedCommand;
class ReparentContainer;
class ComponentCompletedCommand;
class AddImportContainer;
class MockupTypeContainer;
class IdContainer;
namespace Internal {
@@ -188,6 +189,7 @@ protected:
void setupDummysForContext(QQmlContext *context);
void setupMockupTypes(const QVector<MockupTypeContainer> &container);
void setupFileUrl(const QUrl &fileUrl);
void setupImports(const QVector<AddImportContainer> &container);
void setupDummyData(const QUrl &fileUrl);

View File

@@ -85,6 +85,8 @@ void Qt5NodeInstanceServer::resetAllItems()
void Qt5NodeInstanceServer::setupScene(const CreateSceneCommand &command)
{
setupMockupTypes(command.mockupTypes());
setupFileUrl(command.fileUrl());
setupImports(command.imports());
setupDummyData(command.fileUrl());