QmlDesigner Add Binding Editor support to States

Change-Id: I3ccce5e2bfbbfa0dfba1e438d527fa18348005b5
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Aleksei German
2019-11-12 17:06:06 +01:00
parent d9981135c1
commit 5bb0298f69
5 changed files with 58 additions and 26 deletions

View File

@@ -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()
}

View File

@@ -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,26 +489,39 @@ void BindingEditor::setModelNodeBackend(const QVariant &modelNodeBackend)
if (!modelNodeBackend.isNull() && modelNodeBackend.isValid()) {
m_modelNodeBackend = modelNodeBackend;
emit modelNodeBackendChanged();
}
}
void BindingEditor::prepareBindings()
{
if (m_backendValue.isNull() || m_modelNodeBackend.isNull())
return;
if (!(m_backendValue.isValid() && m_modelNodeBackend.isValid()))
return;
const auto modelNodeBackendObject = m_modelNodeBackend.value<QObject*>();
const auto backendObjectCasted =
qobject_cast<const QmlDesigner::QmlModelNodeProxy *>(modelNodeBackendObject);
if (backendObjectCasted) {
const QmlDesigner::ModelNode a = backendObjectCasted->qmlObjectNode().modelNode();
const QList<QmlDesigner::ModelNode> allNodes = a.view()->allModelNodes();
m_modelNode = backendObjectCasted->qmlObjectNode().modelNode();
}
emit modelNodeBackendChanged();
}
}
void BindingEditor::setStateModelNode(const QVariant &stateModelNode)
{
if (stateModelNode.isValid())
{
m_stateModelNode = stateModelNode;
m_modelNode = m_stateModelNode.value<QmlDesigner::ModelNode>();
if (m_modelNode.isValid())
m_backendValueTypeName = "bool";
emit stateModelNodeChanged();
}
}
void BindingEditor::prepareBindings()
{
if (!m_modelNode.isValid() || m_backendValueTypeName.isEmpty())
return;
const QList<QmlDesigner::ModelNode> allNodes = m_modelNode.view()->allModelNodes();
QList<BindingEditorDialog::BindingOption> bindings;
@@ -526,7 +539,6 @@ void BindingEditor::prepareBindings()
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;
}
}

View File

@@ -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<BindingEditorDialog> m_dialog;
QVariant m_backendValue;
QVariant m_modelNodeBackend;
QVariant m_stateModelNode;
QmlDesigner::ModelNode m_modelNode;
TypeName m_backendValueTypeName;
};

View File

@@ -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

View File

@@ -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();