aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp')
-rw-r--r--src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp110
1 files changed, 102 insertions, 8 deletions
diff --git a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp
index fe3871c6c1..d2bdd3cbb8 100644
--- a/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp
+++ b/src/plugins/qmldesigner/components/bindingeditor/bindingeditor.cpp
@@ -35,6 +35,9 @@
#include <nodelistproperty.h>
#include <propertyeditorvalue.h>
+#include <bindingproperty.h>
+#include <variantproperty.h>
+
namespace QmlDesigner {
static BindingEditor *s_lastBindingEditor = nullptr;
@@ -53,7 +56,7 @@ void BindingEditor::registerDeclarativeType()
qmlRegisterType<BindingEditor>("HelperWidgets", 2, 0, "BindingEditor");
}
-void BindingEditor::showWidget(int x, int y)
+void BindingEditor::prepareDialog()
{
if (s_lastBindingEditor)
s_lastBindingEditor->hideWidget();
@@ -68,6 +71,17 @@ void BindingEditor::showWidget(int x, int y)
this, &BindingEditor::rejected);
m_dialog->setAttribute(Qt::WA_DeleteOnClose);
+}
+
+void BindingEditor::showWidget()
+{
+ prepareDialog();
+ m_dialog->showWidget();
+}
+
+void BindingEditor::showWidget(int x, int y)
+{
+ prepareDialog();
m_dialog->showWidget(x, y);
}
@@ -149,6 +163,19 @@ void BindingEditor::setStateModelNode(const QVariant &stateModelNode)
}
}
+void BindingEditor::setModelNode(const ModelNode &modelNode)
+{
+ if (modelNode.isValid())
+ m_modelNode = modelNode;
+}
+
+void BindingEditor::setBackendValueTypeName(const TypeName &backendValueTypeName)
+{
+ m_backendValueTypeName = backendValueTypeName;
+
+ emit backendValueChanged();
+}
+
void BindingEditor::prepareBindings()
{
if (!m_modelNode.isValid() || m_backendValueTypeName.isEmpty())
@@ -158,18 +185,55 @@ void BindingEditor::prepareBindings()
QList<BindingEditorDialog::BindingOption> bindings;
- for (auto objnode : allNodes) {
+ const QList<TypeName> variantTypes = {"alias", "unknown", "variant", "var"};
+ const QList<TypeName> numericTypes = {"double", "real", "int"};
+ const QList<TypeName> colorTypes = {"QColor", "color"};
+ auto isNumeric = [&numericTypes](TypeName compareType) { return numericTypes.contains(compareType); };
+ auto isColor = [&colorTypes](TypeName compareType) { return colorTypes.contains(compareType); };
+
+ const bool skipTypeFiltering = variantTypes.contains(m_backendValueTypeName);
+ const bool targetTypeIsNumeric = isNumeric(m_backendValueTypeName);
+
+ for (const auto &objnode : allNodes) {
BindingEditorDialog::BindingOption binding;
- for (auto propertyName : objnode.metaInfo().propertyNames())
+ for (const auto &propertyName : objnode.metaInfo().propertyNames())
{
TypeName propertyTypeName = objnode.metaInfo().propertyTypeName(propertyName);
- if ((propertyTypeName == "alias" || propertyTypeName == "unknown"))
- if (QmlObjectNode::isValidQmlObjectNode(objnode))
- propertyTypeName = QmlObjectNode(objnode).instanceType(propertyName);
-
- if (m_backendValueTypeName == propertyTypeName)
+ if (skipTypeFiltering
+ || (m_backendValueTypeName == propertyTypeName)
+ || variantTypes.contains(propertyTypeName)
+ || (targetTypeIsNumeric && isNumeric(propertyTypeName))) {
binding.properties.append(QString::fromUtf8(propertyName));
+ }
+ }
+
+ //dynamic properties:
+ for (const BindingProperty &bindingProperty : objnode.bindingProperties()) {
+ if (bindingProperty.isValid()) {
+ if (bindingProperty.isDynamic()) {
+ const TypeName dynamicTypeName = bindingProperty.dynamicTypeName();
+ if (skipTypeFiltering
+ || (dynamicTypeName == m_backendValueTypeName)
+ || variantTypes.contains(dynamicTypeName)
+ || (targetTypeIsNumeric && isNumeric(dynamicTypeName))) {
+ binding.properties.append(QString::fromUtf8(bindingProperty.name()));
+ }
+ }
+ }
+ }
+ for (const VariantProperty &variantProperty : objnode.variantProperties()) {
+ if (variantProperty.isValid()) {
+ if (variantProperty.isDynamic()) {
+ const TypeName dynamicTypeName = variantProperty.dynamicTypeName();
+ if (skipTypeFiltering
+ || (dynamicTypeName == m_backendValueTypeName)
+ || variantTypes.contains(dynamicTypeName)
+ || (targetTypeIsNumeric && isNumeric(dynamicTypeName))) {
+ binding.properties.append(QString::fromUtf8(variantProperty.name()));
+ }
+ }
+ }
}
if (!binding.properties.isEmpty() && objnode.hasId()) {
@@ -178,6 +242,36 @@ void BindingEditor::prepareBindings()
}
}
+ //singletons:
+ if (RewriterView* rv = m_modelNode.view()->rewriterView()) {
+ for (const QmlTypeData &data : rv->getQMLTypes()) {
+ if (!data.typeName.isEmpty()) {
+ NodeMetaInfo metaInfo = m_modelNode.view()->model()->metaInfo(data.typeName.toUtf8());
+
+ if (metaInfo.isValid()) {
+ BindingEditorDialog::BindingOption binding;
+
+ for (const PropertyName &propertyName : metaInfo.propertyNames()) {
+ TypeName propertyTypeName = metaInfo.propertyTypeName(propertyName);
+
+ if (skipTypeFiltering
+ || (m_backendValueTypeName == propertyTypeName)
+ || (variantTypes.contains(propertyTypeName))
+ || (targetTypeIsNumeric && isNumeric(propertyTypeName))
+ || (isColor(m_backendValueTypeName) && isColor(propertyTypeName))) {
+ binding.properties.append(QString::fromUtf8(propertyName));
+ }
+ }
+
+ if (!binding.properties.isEmpty()) {
+ binding.item = data.typeName;
+ bindings.append(binding);
+ }
+ }
+ }
+ }
+ }
+
if (!bindings.isEmpty() && !m_dialog.isNull())
m_dialog->setAllBindings(bindings);