forked from qt-creator/qt-creator
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:
@@ -40,6 +40,7 @@ CreateSceneCommand::CreateSceneCommand(const QVector<InstanceContainer> &instanc
|
||||
const QVector<PropertyBindingContainer> &bindingChangeVector,
|
||||
const QVector<PropertyValueContainer> &auxiliaryChangeVector,
|
||||
const QVector<AddImportContainer> &importVector,
|
||||
const QVector<MockupTypeContainer> &mockupTypeVector,
|
||||
const QUrl &fileUrl)
|
||||
: m_instanceVector(instanceContainer),
|
||||
m_reparentInstanceVector(reparentContainer),
|
||||
@@ -48,6 +49,7 @@ CreateSceneCommand::CreateSceneCommand(const QVector<InstanceContainer> &instanc
|
||||
m_bindingChangeVector(bindingChangeVector),
|
||||
m_auxiliaryChangeVector(auxiliaryChangeVector),
|
||||
m_importVector(importVector),
|
||||
m_mockupTypeVector(mockupTypeVector),
|
||||
m_fileUrl(fileUrl)
|
||||
{
|
||||
}
|
||||
@@ -87,6 +89,11 @@ QVector<AddImportContainer> CreateSceneCommand::imports() const
|
||||
return m_importVector;
|
||||
}
|
||||
|
||||
QVector<MockupTypeContainer> CreateSceneCommand::mockupTypes() const
|
||||
{
|
||||
return m_mockupTypeVector;
|
||||
}
|
||||
|
||||
QUrl CreateSceneCommand::fileUrl() const
|
||||
{
|
||||
return m_fileUrl;
|
||||
@@ -101,6 +108,7 @@ QDataStream &operator<<(QDataStream &out, const CreateSceneCommand &command)
|
||||
out << command.bindingChanges();
|
||||
out << command.auxiliaryChanges();
|
||||
out << command.imports();
|
||||
out << command.mockupTypes();
|
||||
out << command.fileUrl();
|
||||
|
||||
return out;
|
||||
@@ -115,6 +123,7 @@ QDataStream &operator>>(QDataStream &in, CreateSceneCommand &command)
|
||||
in >> command.m_bindingChangeVector;
|
||||
in >> command.m_auxiliaryChangeVector;
|
||||
in >> command.m_importVector;
|
||||
in >> command.m_mockupTypeVector;
|
||||
in >> command.m_fileUrl;
|
||||
|
||||
return in;
|
||||
@@ -130,6 +139,7 @@ QDebug operator <<(QDebug debug, const CreateSceneCommand &command)
|
||||
<< "bindingChanges: " << command.bindingChanges() << ", "
|
||||
<< "auxiliaryChanges: " << command.auxiliaryChanges() << ", "
|
||||
<< "imports: " << command.imports() << ", "
|
||||
<< "mockupTypes: " << command.mockupTypes() << ", "
|
||||
<< "fileUrl: " << command.fileUrl() << ")";
|
||||
}
|
||||
|
||||
|
@@ -32,6 +32,7 @@
|
||||
#include "instancecontainer.h"
|
||||
#include "reparentcontainer.h"
|
||||
#include "idcontainer.h"
|
||||
#include "mockuptypecontainer.h"
|
||||
#include "propertyvaluecontainer.h"
|
||||
#include "propertybindingcontainer.h"
|
||||
#include "addimportcontainer.h"
|
||||
@@ -51,6 +52,7 @@ public:
|
||||
const QVector<PropertyBindingContainer> &bindingChangeVector,
|
||||
const QVector<PropertyValueContainer> &auxiliaryChangeVector,
|
||||
const QVector<AddImportContainer> &importVector,
|
||||
const QVector<MockupTypeContainer> &mockupTypeVector,
|
||||
const QUrl &fileUrl);
|
||||
|
||||
QVector<InstanceContainer> instances() const;
|
||||
@@ -60,6 +62,7 @@ public:
|
||||
QVector<PropertyBindingContainer> bindingChanges() const;
|
||||
QVector<PropertyValueContainer> auxiliaryChanges() const;
|
||||
QVector<AddImportContainer> imports() const;
|
||||
QVector<MockupTypeContainer> mockupTypes() const;
|
||||
QUrl fileUrl() const;
|
||||
|
||||
private:
|
||||
@@ -70,6 +73,7 @@ private:
|
||||
QVector<PropertyBindingContainer> m_bindingChangeVector;
|
||||
QVector<PropertyValueContainer> m_auxiliaryChangeVector;
|
||||
QVector<AddImportContainer> m_importVector;
|
||||
QVector<MockupTypeContainer> m_mockupTypeVector;
|
||||
QUrl m_fileUrl;
|
||||
};
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
INCLUDEPATH += $$PWD/
|
||||
|
||||
HEADERS += $$PWD/addimportcontainer.h
|
||||
HEADERS += $$PWD/mockuptypecontainer.h
|
||||
HEADERS += $$PWD/sharedmemory.h
|
||||
HEADERS += $$PWD/imagecontainer.h
|
||||
HEADERS += $$PWD/idcontainer.h
|
||||
@@ -12,6 +13,7 @@ HEADERS += $$PWD/propertybindingcontainer.h
|
||||
HEADERS += $$PWD/propertyvaluecontainer.h
|
||||
|
||||
SOURCES += $$PWD/addimportcontainer.cpp
|
||||
SOURCES += $$PWD/mockuptypecontainer.cpp
|
||||
unix:SOURCES += $$PWD/sharedmemory_unix.cpp
|
||||
!unix:SOURCES += $$PWD/sharedmemory_qt.cpp
|
||||
SOURCES += $$PWD/imagecontainer.cpp
|
||||
|
@@ -0,0 +1,88 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "mockuptypecontainer.h"
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
QmlDesigner::MockupTypeContainer::MockupTypeContainer()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QmlDesigner::MockupTypeContainer::MockupTypeContainer(const QmlDesigner::TypeName &type,
|
||||
const QString &importUri,
|
||||
int majorVersion,
|
||||
int minorVersion, bool isItem)
|
||||
: m_typeName(type)
|
||||
,m_importUri(importUri)
|
||||
,m_majorVersion(majorVersion)
|
||||
,m_minorVersion(minorVersion)
|
||||
,m_isItem(isItem)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QString MockupTypeContainer::importUri() const
|
||||
{
|
||||
return m_importUri;
|
||||
}
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const MockupTypeContainer &container)
|
||||
{
|
||||
out << container.typeName();
|
||||
out << container.importUri();
|
||||
out << container.majorVersion();
|
||||
out << container.minorVersion();
|
||||
out << container.isItem();
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
QDataStream &operator>>(QDataStream &in, MockupTypeContainer &container)
|
||||
{
|
||||
in >> container.m_typeName;
|
||||
in >> container.m_importUri;
|
||||
in >> container.m_majorVersion;
|
||||
in >> container.m_minorVersion;
|
||||
in >> container.m_isItem;
|
||||
|
||||
return in;
|
||||
}
|
||||
|
||||
QDebug operator <<(QDebug debug, const MockupTypeContainer &container)
|
||||
{
|
||||
return debug.nospace() << "MockupTypeContainer("
|
||||
<< "typeName: " << container.typeName() << ", "
|
||||
<< "importUri: " << container.importUri() << ", "
|
||||
<< "majorVersion: " << container.majorVersion() << ", "
|
||||
<< "minorVersion: " << container.minorVersion() << ", "
|
||||
<< "isItem: " << container.isItem() << ")";
|
||||
}
|
||||
|
||||
|
||||
} // namespace QmlDesigner
|
@@ -0,0 +1,74 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of Qt Creator.
|
||||
**
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <qmetatype.h>
|
||||
#include <QString>
|
||||
#include <QDataStream>
|
||||
|
||||
#include "nodeinstanceglobal.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
class MockupTypeContainer
|
||||
{
|
||||
friend QDataStream &operator>>(QDataStream &in, MockupTypeContainer &container);
|
||||
|
||||
public:
|
||||
MockupTypeContainer();
|
||||
MockupTypeContainer(const TypeName &type, const QString &importUri, int majorVersion, int minorVersion, bool isItem);
|
||||
|
||||
TypeName typeName() const
|
||||
{ return m_typeName; }
|
||||
|
||||
QString importUri() const;
|
||||
|
||||
int majorVersion() const
|
||||
{ return m_majorVersion; }
|
||||
|
||||
int minorVersion() const
|
||||
{ return m_minorVersion; }
|
||||
|
||||
bool isItem() const
|
||||
{ return m_isItem; }
|
||||
|
||||
private:
|
||||
TypeName m_typeName;
|
||||
QString m_importUri;
|
||||
int m_majorVersion = -1;
|
||||
int m_minorVersion = -1;
|
||||
bool m_isItem = false;
|
||||
};
|
||||
|
||||
|
||||
QDataStream &operator<<(QDataStream &out, const MockupTypeContainer &container);
|
||||
QDataStream &operator>>(QDataStream &in, MockupTypeContainer &container);
|
||||
|
||||
QDebug operator <<(QDebug debug, const MockupTypeContainer &container);
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
||||
Q_DECLARE_METATYPE(QmlDesigner::MockupTypeContainer)
|
@@ -0,0 +1,8 @@
|
||||
import QtQuick 2.6
|
||||
|
||||
QtObject {
|
||||
property int x
|
||||
property int y
|
||||
property int width
|
||||
property int height
|
||||
}
|
@@ -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)
|
||||
{
|
||||
|
@@ -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);
|
||||
|
@@ -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());
|
||||
|
@@ -4,5 +4,6 @@
|
||||
<file>html/welcome.html</file>
|
||||
<file>images/webkit.png</file>
|
||||
<file>mockfiles/Window.qml</file>
|
||||
<file>mockfiles/GenericBackend.qml</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
@@ -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());
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user