diff --git a/share/qtcreator/qmldesigner/statesEditorQmlSources/StatesDelegate.qml b/share/qtcreator/qmldesigner/statesEditorQmlSources/StatesDelegate.qml index 5f044b73f44..9f525f2fc5a 100644 --- a/share/qtcreator/qmldesigner/statesEditorQmlSources/StatesDelegate.qml +++ b/share/qtcreator/qmldesigner/statesEditorQmlSources/StatesDelegate.qml @@ -114,6 +114,7 @@ Rectangle { var y = root.mapToGlobal(0,0).y - 32 bindingEditor.showWidget(x, y) bindingEditor.text = delegateWhenConditionString + bindingEditor.prepareBindings() } } @@ -205,6 +206,8 @@ Rectangle { id: bindingEditor + stateModelNodeProperty: statesEditorModel.stateModelNode() + onRejected: { hideWidget() } diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp index c98789587f3..e56822b2a3b 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp @@ -134,7 +134,7 @@ bool BindingEditorWidget::event(QEvent *event) TextEditor::AssistInterface *BindingEditorWidget::createAssistInterface( TextEditor::AssistKind assistKind, TextEditor::AssistReason assistReason) const { - Q_UNUSED(assistKind); + Q_UNUSED(assistKind) return new QmlJSEditor::QmlJSCompletionAssistInterface( document(), position(), QString(), assistReason, qmljsdocument->semanticInfo()); @@ -489,44 +489,56 @@ void BindingEditor::setModelNodeBackend(const QVariant &modelNodeBackend) if (!modelNodeBackend.isNull() && modelNodeBackend.isValid()) { m_modelNodeBackend = modelNodeBackend; + const auto modelNodeBackendObject = m_modelNodeBackend.value(); + + const auto backendObjectCasted = + qobject_cast(modelNodeBackendObject); + + if (backendObjectCasted) { + m_modelNode = backendObjectCasted->qmlObjectNode().modelNode(); + } + emit modelNodeBackendChanged(); } } +void BindingEditor::setStateModelNode(const QVariant &stateModelNode) +{ + if (stateModelNode.isValid()) + { + m_stateModelNode = stateModelNode; + m_modelNode = m_stateModelNode.value(); + + if (m_modelNode.isValid()) + m_backendValueTypeName = "bool"; + + emit stateModelNodeChanged(); + } +} + void BindingEditor::prepareBindings() { - if (m_backendValue.isNull() || m_modelNodeBackend.isNull()) + if (!m_modelNode.isValid() || m_backendValueTypeName.isEmpty()) return; - if (!(m_backendValue.isValid() && m_modelNodeBackend.isValid())) - return; + const QList allNodes = m_modelNode.view()->allModelNodes(); - const auto modelNodeBackendObject = m_modelNodeBackend.value(); + QList bindings; - const auto backendObjectCasted = - qobject_cast(modelNodeBackendObject); + for (auto objnode : allNodes) { + BindingEditorDialog::BindingOption binding; + for (auto propertyName : objnode.metaInfo().propertyNames()) + if (m_backendValueTypeName == objnode.metaInfo().propertyTypeName(propertyName)) + binding.properties.append(QString::fromUtf8(propertyName)); - if (backendObjectCasted) { - const QmlDesigner::ModelNode a = backendObjectCasted->qmlObjectNode().modelNode(); - const QList allNodes = a.view()->allModelNodes(); - - QList bindings; - - for (auto objnode : allNodes) { - BindingEditorDialog::BindingOption binding; - for (auto propertyName : objnode.metaInfo().propertyNames()) - if (m_backendValueTypeName == objnode.metaInfo().propertyTypeName(propertyName)) - binding.properties.append(QString::fromUtf8(propertyName)); - - if (!binding.properties.isEmpty() && objnode.hasId()) { - binding.item = objnode.displayName(); - bindings.append(binding); - } + if (!binding.properties.isEmpty() && objnode.hasId()) { + binding.item = objnode.displayName(); + bindings.append(binding); } - - if (!bindings.isEmpty() && !m_dialog.isNull()) - m_dialog->setAllBindings(bindings); } + + if (!bindings.isEmpty() && !m_dialog.isNull()) + m_dialog->setAllBindings(bindings); } QVariant BindingEditor::backendValue() const @@ -539,5 +551,10 @@ QVariant BindingEditor::modelNodeBackend() const return m_modelNodeBackend; } +QVariant BindingEditor::stateModelNode() const +{ + return m_stateModelNode; +} + } diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h index 78614004770..a1deb741080 100644 --- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h +++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.h @@ -144,6 +144,7 @@ class BindingEditor : public QObject Q_PROPERTY(QString text READ bindingValue WRITE setBindingValue) Q_PROPERTY(QVariant backendValueProperty READ backendValue WRITE setBackendValue NOTIFY backendValueChanged) Q_PROPERTY(QVariant modelNodeBackendProperty READ modelNodeBackend WRITE setModelNodeBackend NOTIFY modelNodeBackendChanged) + Q_PROPERTY(QVariant stateModelNodeProperty READ stateModelNode WRITE setStateModelNode NOTIFY stateModelNodeChanged) public: BindingEditor(QObject *parent = nullptr); @@ -159,6 +160,7 @@ public: void setBackendValue(const QVariant &backendValue); void setModelNodeBackend(const QVariant &modelNodeBackend); + void setStateModelNode(const QVariant &stateModelNode); Q_INVOKABLE void prepareBindings(); @@ -167,15 +169,19 @@ signals: void rejected(); void backendValueChanged(); void modelNodeBackendChanged(); + void stateModelNodeChanged(); private: QVariant backendValue() const; QVariant modelNodeBackend() const; + QVariant stateModelNode() const; private: QPointer m_dialog; QVariant m_backendValue; QVariant m_modelNodeBackend; + QVariant m_stateModelNode; + QmlDesigner::ModelNode m_modelNode; TypeName m_backendValueTypeName; }; diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp index 5676cc2ca40..d5e21ebe945 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.cpp @@ -216,4 +216,9 @@ QStringList StatesEditorModel::autoComplete(const QString &text, int pos, bool e return QStringList(); } +QVariant StatesEditorModel::stateModelNode() +{ + return QVariant::fromValue(m_statesEditorView->currentStateNode()); +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h index 2ea806c9bad..40cad6efefc 100644 --- a/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h +++ b/src/plugins/qmldesigner/components/stateseditor/stateseditormodel.h @@ -61,6 +61,7 @@ public: Q_INVOKABLE void setWhenCondition(int internalNodeId, const QString &condition); Q_INVOKABLE void resetWhenCondition(int internalNodeId); Q_INVOKABLE QStringList autoComplete(const QString &text, int pos, bool explicitComplete); + Q_INVOKABLE QVariant stateModelNode(); void reset();