diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/BooleanEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/BooleanEditorTemplate.template new file mode 100644 index 0000000000000000000000000000000000000000..c9a82d0f4a2b31816c039014acdb2f5b04a43edb --- /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 0000000000000000000000000000000000000000..0c2c697ecc2bf9755ce282766b6b9df6bab7fddd --- /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 0000000000000000000000000000000000000000..cc8259da8b5a9bb1875f532e12f0d350c9d832d3 --- /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 0000000000000000000000000000000000000000..cc8259da8b5a9bb1875f532e12f0d350c9d832d3 --- /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 0000000000000000000000000000000000000000..3619dd5d4e4352c7581b5d6a1de0ff309872fad9 --- /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 0000000000000000000000000000000000000000..7c14041197153f57e8fb02a91925507ca7fe71d3 --- /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 0000000000000000000000000000000000000000..3619dd5d4e4352c7581b5d6a1de0ff309872fad9 --- /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 7ca3eaa1434173bf48a93e444be193de3758040e..4090bb4814605f1b968a0095127faab9ddd93527 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 51d45174765d5061370a65d41732f1bf51b03065..195a24afb34cc5316d35b54213cd07ad0485db03 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 96f43da3cad1cf539c4e7445408e99d55a154a88..6eb7b9bd4b49064333d954a8b4c79d85e3bd3988 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 37fa5bc6df60e639db7bed1b1af967cef8e65404..05b2511778b71fed3206a28e1b3729c5d3dfe987 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();