From a2c8972ce128ce81769f1ed6a2d1e81f47f9943b Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Fri, 9 Sep 2022 17:05:14 +0300 Subject: [PATCH] QmlDesigner: Expose dynamic texture and vector properties in components Provide editor templates for Texture, TextureInput, and vectorXd type dynamic properties exposed by components. Change-Id: Ie7ae62aeffc5e151a1300b3aefdfc68584ccda6a Reviewed-by: Thomas Hartmann Reviewed-by: --- ...DItemFilterComboBoxEditorTemplate.template | 17 ++++ .../PropertyTemplates/TemplateTypes.qml | 21 +++++ .../Vector2dEditorTemplate.template | 42 ++++++++++ .../Vector3dEditorTemplate.template | 61 +++++++++++++++ .../Vector4dEditorTemplate.template | 78 +++++++++++++++++++ .../propertyeditorqmlbackend.cpp | 18 ++++- 6 files changed, 233 insertions(+), 4 deletions(-) create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/3DItemFilterComboBoxEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector2dEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector3dEditorTemplate.template create mode 100644 share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector4dEditorTemplate.template diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/3DItemFilterComboBoxEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/3DItemFilterComboBoxEditorTemplate.template new file mode 100644 index 00000000000..6870a3e74ce --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/3DItemFilterComboBoxEditorTemplate.template @@ -0,0 +1,17 @@ +PropertyLabel { + text: "%1" + tooltip: "%1" +} + +SecondColumnLayout { + ItemFilterComboBox { + typeFilter: "QtQuick3D.%3" + validator: RegExpValidator { regExp: /(^$|^[a-z_]\w*)/ } + backendValue: backendValues.%2 + implicitWidth: StudioTheme.Values.singleControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + width: implicitWidth + } + + ExpandingSpacer {} +} diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml index 9b0a9a44873..5d408ce0183 100644 --- a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/TemplateTypes.qml @@ -78,4 +78,25 @@ AutoTypes { sourceFile: "ImageEditorTemplate.template" separateSection: true } + + Type { + typeNames: ["TextureInput", "Texture"] + sourceFile: "3DItemFilterComboBoxEditorTemplate.template" + needsTypeArg: true + } + + Type { + typeNames: ["vector2d"] + sourceFile: "Vector2dEditorTemplate.template" + } + + Type { + typeNames: ["vector3d"] + sourceFile: "Vector3dEditorTemplate.template" + } + + Type { + typeNames: ["vector4d"] + sourceFile: "Vector4dEditorTemplate.template" + } } diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector2dEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector2dEditorTemplate.template new file mode 100644 index 00000000000..b339c254bac --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector2dEditorTemplate.template @@ -0,0 +1,42 @@ +PropertyLabel { + text: "%1" + tooltip: "%1" +} + +ColumnLayout { + SecondColumnLayout { + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_x + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "X" + } + + Spacer { implicitWidth: StudioTheme.Values.controlGap } + + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_y + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "Y" + } + + ExpandingSpacer {} + } +} diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector3dEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector3dEditorTemplate.template new file mode 100644 index 00000000000..5caff585d73 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector3dEditorTemplate.template @@ -0,0 +1,61 @@ +PropertyLabel { + text: "%1" + tooltip: "%1" +} + +ColumnLayout { + SecondColumnLayout { + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_x + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "X" + } + + Spacer { implicitWidth: StudioTheme.Values.controlGap } + + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_y + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "Y" + } + + ExpandingSpacer {} + } + + SecondColumnLayout { + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_z + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "Z" + } + + ExpandingSpacer {} + } +} diff --git a/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector4dEditorTemplate.template b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector4dEditorTemplate.template new file mode 100644 index 00000000000..619f51cebe3 --- /dev/null +++ b/share/qtcreator/qmldesigner/propertyEditorQmlSources/PropertyTemplates/Vector4dEditorTemplate.template @@ -0,0 +1,78 @@ +PropertyLabel { + text: "%1" + tooltip: "%1" +} + +ColumnLayout { + SecondColumnLayout { + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_x + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "X" + } + + Spacer { implicitWidth: StudioTheme.Values.controlGap } + + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_y + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "Y" + } + + ExpandingSpacer {} + } + + SecondColumnLayout { + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_z + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "Z" + } + + Spacer { implicitWidth: StudioTheme.Values.controlGap } + + SpinBox { + minimumValue: -9999999 + maximumValue: 9999999 + decimals: 2 + backendValue: backendValues.%2_w + implicitWidth: StudioTheme.Values.twoControlColumnWidth + + StudioTheme.Values.actionIndicatorWidth + } + + Spacer { implicitWidth: StudioTheme.Values.controlLabelGap } + + ControlLabel { + text: "W" + } + + ExpandingSpacer {} + } +} diff --git a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp index c3e201bf1d9..f66e7fb72c5 100644 --- a/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp +++ b/src/plugins/qmldesigner/components/propertyeditor/propertyeditorqmlbackend.cpp @@ -586,7 +586,7 @@ inline bool dotPropertyHeuristic(const QmlObjectNode &node, const NodeMetaInfo & NodeMetaInfo rectangleInfo = node.view()->model()->metaInfo("QtQuick.Rectangle"); NodeMetaInfo imageInfo = node.view()->model()->metaInfo("QtQuick.Image"); - if (typeName == "font" + if (typeName == "font" || typeName == "Texture" || typeName == "vector4d" || itemInfo.hasProperty(itemProperty) || textInfo.isSubclassOf(typeName) || rectangleInfo.isSubclassOf(typeName) @@ -607,10 +607,13 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type, QStringList allTypes; // all template types QStringList separateSectionTypes; // separate section types only + QStringList needsTypeArgTypes; // types that need type as third parameter for (const QmlJS::SimpleReaderNode::Ptr &node : nodes) { if (node->propertyNames().contains("separateSection")) separateSectionTypes.append(variantToStringList(node->property("typeNames").value)); + if (node->propertyNames().contains("needsTypeArg")) + needsTypeArgTypes.append(variantToStringList(node->property("typeNames").value)); allTypes.append(variantToStringList(node->property("typeNames").value)); } @@ -668,8 +671,8 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type, Utils::sort(basicProperties); - auto findAndFillTemplate = [&nodes, &node, &type](const PropertyName &label, - const PropertyName &property) { + auto findAndFillTemplate = [&nodes, &node, &type, &needsTypeArgTypes]( + const PropertyName &label, const PropertyName &property) { PropertyName underscoreProperty = property; underscoreProperty.replace('.', '_'); @@ -687,7 +690,14 @@ QString PropertyEditorQmlBackend::templateGeneration(const NodeMetaInfo &type, if (file.open(QIODevice::ReadOnly)) { QString source = QString::fromUtf8(file.readAll()); file.close(); - filledTemplate = source.arg(QString::fromUtf8(label)).arg(QString::fromUtf8(underscoreProperty)); + if (needsTypeArgTypes.contains(QString::fromUtf8(typeName))) { + filledTemplate = source.arg(QString::fromUtf8(label), + QString::fromUtf8(underscoreProperty), + QString::fromUtf8(typeName)); + } else { + filledTemplate = source.arg(QString::fromUtf8(label), + QString::fromUtf8(underscoreProperty)); + } } else { qWarning().nospace() << "template definition source file not found:" << fileName; }