Commit 120d56c1 authored by Thomas Hartmann's avatar Thomas Hartmann
Browse files

QmlDesigner.PropertyEditor: bringing back the templates



Template for auto generates pages now work with in Qt Quick 2.

Change-Id: Idd0a8fe8d82555bc69b192b21df7641dcdb634b4
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent c0cae37d
Label {
text: "%1"
toolTip: "%1"
}
CheckBox {
text: backendValues.%2.value
backendValue: backendValues.%2
}
\ No newline at end of file
Item {
}
ColorEditor {
caption: "%1"
backendColor: backendValues.%2
supportGradient: false
}
\ No newline at end of file
Label {
text: "%1"
toolTip: "%1"
}
SpinBox {
backendValue: backendValues.%2
}
\ No newline at end of file
Label {
text: "%1"
toolTip: "%1"
}
SpinBox {
backendValue: backendValues.%2
}
\ No newline at end of file
Label {
text: "%1"
toolTip: "%1"
}
LineEdit {
backendValue: backendValues.%2
}
\ No newline at end of file
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"
}
}
Label {
text: "%1"
toolTip: "%1"
}
LineEdit {
backendValue: backendValues.%2
}
\ No newline at end of file
......@@ -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
......
......@@ -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
......@@ -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 {
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment