From 120d56c116ffb3b0de2946c17616c475ed7708c9 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann <Thomas.Hartmann@digia.com> Date: Wed, 23 Oct 2013 17:44:19 +0200 Subject: [PATCH] QmlDesigner.PropertyEditor: bringing back the templates Template for auto generates pages now work with in Qt Quick 2. Change-Id: Idd0a8fe8d82555bc69b192b21df7641dcdb634b4 Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com> --- .../BooleanEditorTemplate.template | 9 ++ .../ColorEditorTemplate.template | 8 ++ .../IntEditorTemplate.template | 7 ++ .../RealEditorTemplate.template | 7 ++ .../StringEditorTemplate.template | 7 ++ .../PropertyTemplates/TemplateTypes.qml | 29 ++++++ .../UrlEditorTemplate.template | 7 ++ .../QtQuick/ItemPane.qml | 12 ++- .../propertyeditorcontextobject.cpp | 96 ++++++++++++++++++- .../propertyeditorcontextobject.h | 91 +++++------------- .../propertyeditorqmlbackend.cpp | 10 +- 11 files changed, 205 insertions(+), 78 deletions(-) create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/BooleanEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/ColorEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/IntEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/RealEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/StringEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/UrlEditorTemplate.template diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/BooleanEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/BooleanEditorTemplate.template new file mode 100644 index 00000000000..c9a82d0f4a2 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/BooleanEditorTemplate.template @@ -0,0 +1,9 @@ +Label { + text: "%1" + toolTip: "%1" +} + +CheckBox { + text: backendValues.%2.value + backendValue: backendValues.%2 +} \ No newline at end of file diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/ColorEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/ColorEditorTemplate.template new file mode 100644 index 00000000000..0c2c697ecc2 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/ColorEditorTemplate.template @@ -0,0 +1,8 @@ +Item { +} + +ColorEditor { + caption: "%1" + backendColor: backendValues.%2 + supportGradient: false +} \ No newline at end of file diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/IntEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/IntEditorTemplate.template new file mode 100644 index 00000000000..cc8259da8b5 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/IntEditorTemplate.template @@ -0,0 +1,7 @@ +Label { + text: "%1" + toolTip: "%1" +} +SpinBox { + backendValue: backendValues.%2 +} \ No newline at end of file diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/RealEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/RealEditorTemplate.template new file mode 100644 index 00000000000..cc8259da8b5 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/RealEditorTemplate.template @@ -0,0 +1,7 @@ +Label { + text: "%1" + toolTip: "%1" +} +SpinBox { + backendValue: backendValues.%2 +} \ No newline at end of file diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/StringEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/StringEditorTemplate.template new file mode 100644 index 00000000000..3619dd5d4e4 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/StringEditorTemplate.template @@ -0,0 +1,7 @@ +Label { + text: "%1" + toolTip: "%1" +} +LineEdit { + backendValue: backendValues.%2 +} \ No newline at end of file diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml new file mode 100644 index 00000000000..7c140411971 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml @@ -0,0 +1,29 @@ + +AutoTypes { + imports: [ "import HelperWidgets 2.0", "import QtQuick 2.1" ] + + Type { + typeNames: ["int"] + sourceFile: "IntEditorTemplate.template" + } + Type { + typeNames: ["real", "double", "qreal"] + sourceFile: "RealEditorTemplate.template" + } + Type { + typeNames: ["string", "QString"] + sourceFile: "StringEditorTemplate.template" + } + Type { + typeNames: ["QUrl", "url"] + sourceFile: "UrlEditorTemplate.template" + } + Type { + typeNames: ["bool", "boolean"] + sourceFile: "BooleanEditorTemplate.template" + } + Type { + typeNames: ["color", "QColor"] + sourceFile: "ColorEditorTemplate.template" + } +} diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/UrlEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/UrlEditorTemplate.template new file mode 100644 index 00000000000..3619dd5d4e4 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/UrlEditorTemplate.template @@ -0,0 +1,7 @@ +Label { + text: "%1" + toolTip: "%1" +} +LineEdit { + backendValue: backendValues.%2 +} \ No newline at end of file diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml index 7ca3eaa1434..4090bb48146 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/QtQuick/ItemPane.qml @@ -157,11 +157,13 @@ Rectangle { component: Column { anchors.left: parent.left anchors.right: parent.right - // Loader { - // id: specificsTwo; - // baseUrl: globalBaseUrl; - // qmlData: specificQmlData; - // } + Loader { + anchors.left: parent.left + anchors.right: parent.right + + id: specificsTwo; + sourceComponent: specificQmlComponent + } Loader { anchors.left: parent.left diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp index 51d45174765..195a24afb34 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.cpp @@ -29,6 +29,8 @@ #include "propertyeditorcontextobject.h" +#include <QQmlContext> + namespace QmlDesigner { PropertyEditorContextObject::PropertyEditorContextObject(QObject *parent) : @@ -37,7 +39,9 @@ PropertyEditorContextObject::PropertyEditorContextObject(QObject *parent) : m_selectionChanged(false), m_backendValues(0), m_majorVersion(-1), - m_minorVersion(-1) + m_minorVersion(-1), + m_qmlComponent(0), + m_qmlContext(0) { } @@ -73,4 +77,94 @@ void PropertyEditorContextObject::setMinorVersion(int minorVersion) emit minorVersionChanged(); } +void PropertyEditorContextObject::insertInQmlContext(QQmlContext *context) +{ + m_qmlContext = context; + m_qmlContext->setContextObject(this); +} + +QQmlComponent *PropertyEditorContextObject::specificQmlComponent() +{ + if (m_qmlComponent) + return m_qmlComponent; + + m_qmlComponent = new QQmlComponent(m_qmlContext->engine(), this); + + m_qmlComponent->setData(m_specificQmlData.toAscii(), QUrl::fromLocalFile("specfics.qml")); + + return m_qmlComponent; +} + +void PropertyEditorContextObject::setGlobalBaseUrl(const QUrl &newBaseUrl) +{ + if (newBaseUrl == m_globalBaseUrl) + return; + + m_globalBaseUrl = newBaseUrl; + emit globalBaseUrlChanged(); +} + +void PropertyEditorContextObject::setSpecificsUrl(const QUrl &newSpecificsUrl) +{ + if (newSpecificsUrl == m_specificsUrl) + return; + + m_specificsUrl = newSpecificsUrl; + emit specificsUrlChanged(); +} + +void PropertyEditorContextObject::setSpecificQmlData(const QString &newSpecificQmlData) +{ + if (m_specificQmlData == newSpecificQmlData) + return; + + m_specificQmlData = newSpecificQmlData; + emit specificQmlDataChanged(); + + delete m_qmlComponent; + m_qmlComponent = 0; + emit specificQmlComponentChanged(); +} + +void PropertyEditorContextObject::setStateName(const QString &newStateName) +{ + if (newStateName == m_stateName) + return; + + m_stateName = newStateName; + emit stateNameChanged(); +} + +void PropertyEditorContextObject::setIsBaseState(bool newIsBaseState) +{ + if (newIsBaseState == m_isBaseState) + return; + + m_isBaseState = newIsBaseState; + emit isBaseStateChanged(); +} + +void PropertyEditorContextObject::setSelectionChanged(bool newSelectionChanged) +{ + if (newSelectionChanged == m_selectionChanged) + return; + + m_selectionChanged = newSelectionChanged; + emit selectionChangedChanged(); +} + +void PropertyEditorContextObject::setBackendValues(QQmlPropertyMap *newBackendValues) +{ + if (newBackendValues == m_backendValues) + return; + + m_backendValues = newBackendValues; + emit backendValuesChanged(); +} + +void PropertyEditorContextObject::triggerSelectionChanged() +{ + setSelectionChanged(!m_selectionChanged); +} + } //QmlDesigner diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h index 96f43da3cad..6eb7b9bd4b4 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorcontextobject.h @@ -33,6 +33,7 @@ #include <QObject> #include <QUrl> #include <QQmlPropertyMap> +#include <QQmlComponent> #include <QColor> namespace QmlDesigner { @@ -55,6 +56,8 @@ class PropertyEditorContextObject : public QObject Q_PROPERTY(QQmlPropertyMap* backendValues READ backendValues WRITE setBackendValues NOTIFY backendValuesChanged) + Q_PROPERTY(QQmlComponent* specificQmlComponent READ specificQmlComponent NOTIFY specificQmlComponentChanged) + public: PropertyEditorContextObject(QObject *parent = 0); @@ -75,6 +78,9 @@ public: int minorVersion() const; void setMinorVersion(int minorVersion); + void insertInQmlContext(QQmlContext *context); + QQmlComponent *specificQmlComponent(); + signals: void globalBaseUrlChanged(); void specificsUrlChanged(); @@ -85,75 +91,24 @@ signals: void backendValuesChanged(); void majorVersionChanged(); void minorVersionChanged(); + void specificQmlComponentChanged(); public slots: - void setGlobalBaseUrl(const QUrl &newBaseUrl) - { - if (newBaseUrl == m_globalBaseUrl) - return; - - m_globalBaseUrl = newBaseUrl; - emit globalBaseUrlChanged(); - } - - void setSpecificsUrl(const QUrl &newSpecificsUrl) - { - if (newSpecificsUrl == m_specificsUrl) - return; - - m_specificsUrl = newSpecificsUrl; - emit specificsUrlChanged(); - } - - void setSpecificQmlData(const QString &newSpecificQmlData) - { - if (m_specificQmlData == newSpecificQmlData) - return; - - m_specificQmlData = newSpecificQmlData; - emit specificQmlDataChanged(); - } - - void setStateName(const QString &newStateName) - { - if (newStateName == m_stateName) - return; - - m_stateName = newStateName; - emit stateNameChanged(); - } - - void setIsBaseState(bool newIsBaseState) - { - if (newIsBaseState == m_isBaseState) - return; - - m_isBaseState = newIsBaseState; - emit isBaseStateChanged(); - } - - void setSelectionChanged(bool newSelectionChanged) - { - if (newSelectionChanged == m_selectionChanged) - return; - - m_selectionChanged = newSelectionChanged; - emit selectionChangedChanged(); - } - - void setBackendValues(QQmlPropertyMap* newBackendValues) - { - if (newBackendValues == m_backendValues) - return; - - m_backendValues = newBackendValues; - emit backendValuesChanged(); - } - - void triggerSelectionChanged() - { - setSelectionChanged(!m_selectionChanged); - } + void setGlobalBaseUrl(const QUrl &newBaseUrl); + + void setSpecificsUrl(const QUrl &newSpecificsUrl); + + void setSpecificQmlData(const QString &newSpecificQmlData); + + void setStateName(const QString &newStateName); + + void setIsBaseState(bool newIsBaseState); + + void setSelectionChanged(bool newSelectionChanged); + + void setBackendValues(QQmlPropertyMap* newBackendValues); + + void triggerSelectionChanged(); private: QUrl m_globalBaseUrl; @@ -169,6 +124,8 @@ private: int m_majorVersion; int m_minorVersion; + QQmlComponent *m_qmlComponent; + QQmlContext *m_qmlContext; }; } //QmlDesigner { diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index 37fa5bc6df6..05b2511778b 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -129,7 +129,7 @@ PropertyEditorQmlBackend::PropertyEditorQmlBackend(PropertyEditorView *propertyE m_dummyPropertyEditorValue->setValue("#000000"); context()->setContextProperty("dummyBackendValue", m_dummyPropertyEditorValue.data()); m_contextObject->setBackendValues(&m_backendValuesPropertyMap); - context()->setContextObject(m_contextObject.data()); + m_contextObject->insertInQmlContext(context()); QObject::connect(&m_backendValuesPropertyMap, SIGNAL(valueChanged(QString,QVariant)), propertyEditor, SLOT(changeValue(QString))); } @@ -352,9 +352,9 @@ QString PropertyEditorQmlBackend::templateGeneration(NodeMetaInfo type, QStringList imports = variantToStringList(templateConfiguration()->property(QLatin1String("imports"))); QString qmlTemplate = imports.join(QLatin1String("\n")) + QLatin1Char('\n'); - qmlTemplate += QLatin1String("GroupBox {\n"); + qmlTemplate += QLatin1String("Section {\n"); qmlTemplate += QString(QLatin1String("caption: \"%1\"\n")).arg(QString::fromUtf8(objectNode.modelNode().simplifiedTypeName())); - qmlTemplate += QLatin1String("layout: VerticalLayout {\n"); + qmlTemplate += QLatin1String("SectionLayout {\n"); QList<PropertyName> orderedList = type.propertyNames(); qSort(orderedList); @@ -390,8 +390,8 @@ QString PropertyEditorQmlBackend::templateGeneration(NodeMetaInfo type, } } } - qmlTemplate += QLatin1String("}\n"); //VerticalLayout - qmlTemplate += QLatin1String("}\n"); //GroupBox + qmlTemplate += QLatin1String("}\n"); //Section + qmlTemplate += QLatin1String("}\n"); //SectionLayout if (emptyTemplate) return QString(); -- GitLab