Commit 5b693cda authored by Thomas Hartmann's avatar Thomas Hartmann

QmlDesigner.ItemLibrary: Allow bindings without extra source file

This makes drag and drop faster than merging code.

Task-number: QTCREATORBUG-9361
Change-Id: If9779d7439ea41edfb80c08161b7ef3d0f08cf41
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@digia.com>
parent ed037404
......@@ -11,7 +11,7 @@ MetaInfo {
version: "1.0"
requiredImport: "QtQuick.Controls"
Property { name: "text"; type: "QString"; value: "Button"; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Button\")"; }
}
}
......@@ -39,7 +39,7 @@ MetaInfo {
version: "1.0"
requiredImport: "QtQuick.Controls"
Property { name: "text"; type: "QString"; value: "Check Box"; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Check Box\")"; }
}
}
......@@ -54,7 +54,7 @@ MetaInfo {
version: "1.0"
requiredImport: "QtQuick.Controls"
Property { name: "text"; type: "QString"; value: "Radio Button"; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Radio Button\")"; }
}
}
......@@ -108,7 +108,7 @@ MetaInfo {
version: "1.0"
requiredImport: "QtQuick.Controls"
Property { name: "text"; type: "QString"; value: "Label"; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Label\")"; }
}
}
......@@ -123,7 +123,7 @@ MetaInfo {
version: "1.0"
requiredImport: "QtQuick.Controls"
Property { name: "placeholderText"; type: "QString"; value: "Text Field"; }
Property { name: "placeholderText"; type: "binding"; value: "qsTr(\"Text Field\")"; }
}
}
......
......@@ -32,6 +32,7 @@
#include "qmlchangeset.h"
#include "nodelistproperty.h"
#include "variantproperty.h"
#include "bindingproperty.h"
#include "qmlanchors.h"
#include "invalidmodelnodeexception.h"
#include "itemlibraryinfo.h"
......@@ -134,13 +135,20 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
}
}
typedef QPair<PropertyName, QString> PropertyBindingEntry;
QList<PropertyBindingEntry> propertyBindingList;
if (itemLibraryEntry.qmlSource().isEmpty()) {
QList<QPair<PropertyName, QVariant> > propertyPairList;
propertyPairList.append(qMakePair(PropertyName("x"), QVariant(qRound(position.x()))));
propertyPairList.append(qMakePair(PropertyName("y"), QVariant(qRound(position.y()))));
foreach (const PropertyContainer &property, itemLibraryEntry.properties())
propertyPairList.append(qMakePair(property.name(), property.value()));
foreach (const PropertyContainer &property, itemLibraryEntry.properties()) {
if (property.type() == QLatin1String("binding")) {
propertyBindingList.append(PropertyBindingEntry(property.name(), property.value().toString()));
} else {
propertyPairList.append(qMakePair(property.name(), property.value()));
}
}
newQmlItemNode = QmlItemNode(view->createModelNode(itemLibraryEntry.typeName(), majorVersion, minorVersion, propertyPairList));
} else {
......@@ -160,6 +168,9 @@ QmlItemNode QmlItemNode::createQmlItemNode(AbstractView *view, const ItemLibrary
newQmlItemNode.setVariantProperty("opacity", 1);
}
foreach (const PropertyBindingEntry &propertyBindingEntry, propertyBindingList)
newQmlItemNode.modelNode().bindingProperty(propertyBindingEntry.first).setExpression(propertyBindingEntry.second);
Q_ASSERT(newQmlItemNode.isValid());
}
catch (RewritingException &e) {
......
......@@ -63,7 +63,8 @@ MetaInfo {
libraryIcon: ":/qtquickplugin/images/text-icon.png"
version: "1.0"
QmlSource { source: ":/qtquickplugin/source/text.qml" }
Property { name: "font.pixelSize"; type: "int"; value: 12; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Text\")"; }
}
ItemLibraryEntry {
......@@ -72,7 +73,8 @@ MetaInfo {
libraryIcon: ":/qtquickplugin/images/text-icon.png"
version: "2.0"
QmlSource { source: ":/qtquickplugin/source/textv2.qml" }
Property { name: "font.pixelSize"; type: "int"; value: 12; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Text\")"; }
}
}
......@@ -86,7 +88,11 @@ MetaInfo {
libraryIcon: ":/qtquickplugin/images/text-edit-icon.png"
version: "1.0"
QmlSource { source: ":/qtquickplugin/source/textedit.qml" }
Property { name: "width"; type: "int"; value: 80; }
Property { name: "height"; type: "int"; value: 20; }
Property { name: "font.pixelSize"; type: "int"; value: 12; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Text Edit\")"; }
}
ItemLibraryEntry {
......@@ -95,7 +101,10 @@ MetaInfo {
libraryIcon: ":/qtquickplugin/images/text-edit-icon.png"
version: "2.0"
QmlSource { source: ":/qtquickplugin/source/texteditv2.qml" }
Property { name: "width"; type: "int"; value: 80; }
Property { name: "height"; type: "int"; value: 20; }
Property { name: "font.pixelSize"; type: "int"; value: 12; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Text Edit\")"; }
}
}
......@@ -109,7 +118,10 @@ MetaInfo {
libraryIcon: ":/qtquickplugin/images/text-edit-icon.png"
version: "1.0"
QmlSource { source: ":/qtquickplugin/source/textinput.qml" }
Property { name: "width"; type: "int"; value: 80; }
Property { name: "height"; type: "int"; value: 20; }
Property { name: "font.pixelSize"; type: "int"; value: 12; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Text Input\")"; }
}
ItemLibraryEntry {
......@@ -118,7 +130,10 @@ MetaInfo {
libraryIcon: ":/qtquickplugin/images/text-input-icon.png"
version: "2.0"
QmlSource { source: ":/qtquickplugin/source/textinput.qml" }
Property { name: "width"; type: "int"; value: 80; }
Property { name: "height"; type: "int"; value: 20; }
Property { name: "font.pixelSize"; type: "int"; value: 12; }
Property { name: "text"; type: "binding"; value: "qsTr(\"Text Input\")"; }
}
}
......
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