aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/qmldesignerbase
diff options
context:
space:
mode:
authorThomas Hartmann <thomas.hartmann@qt.io>2023-07-04 19:57:59 +0200
committerThomas Hartmann <thomas.hartmann@qt.io>2023-07-07 09:36:34 +0000
commit9a11fa3ef88e700d0e37ce9f080bf835b5290ca1 (patch)
treea0781d9885fd273f7f7ff1755d9b8c7e2196d946 /src/plugins/qmldesignerbase
parentb85eb8aa04df5f7e6fe7c68f6a0e36b739ed781e (diff)
QmlDesigner: Add QML front-end for ConnectionView
This is still disabled by default until the UI gets polished. Add roles to models. ConnectionModel, BindingModel and DynamicPropertiesModel. In QML roles are used in the ListView to "mimic" columns. The columns are only relevant for the "old" cpp QTableView and can be removed. Making currentIndex part of the model. If rows are removed and added again we have to "reset/keep" the currentIndex as part of the model, because the index is temporarly invalid on the view. Implementing DynamicPropertiesModelBackendDelegate as reference. This is a pure "backend delegate" that exposes all relevant properties for a current row to QML. Adding StudioQuickWidget and exposing the backend. Adding StudioQmlTextBackend and StudioQmlComboBoxBackend to StudioQuickWidget (should be moved into their own files). Those helper classes make is easy to expose a property to a combobox or textfield. The backend has to know nothing about the actual frontend and those classes act as a mini-model for a view in QML. The API is similar to UI controls. Change-Id: I7a2c6ad951306fbca1d586fb8f278acdd91a064b Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io> Reviewed-by: Knud Dollereder <knud.dollereder@qt.io>
Diffstat (limited to 'src/plugins/qmldesignerbase')
-rw-r--r--src/plugins/qmldesignerbase/studio/studioquickwidget.h121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/plugins/qmldesignerbase/studio/studioquickwidget.h b/src/plugins/qmldesignerbase/studio/studioquickwidget.h
index ef64fb6a69d..61c2ff8922f 100644
--- a/src/plugins/qmldesignerbase/studio/studioquickwidget.h
+++ b/src/plugins/qmldesignerbase/studio/studioquickwidget.h
@@ -9,6 +9,127 @@
#include <QQmlPropertyMap>
#include <QtQuickWidgets/QQuickWidget>
+class QMLDESIGNERBASE_EXPORT StudioQmlTextBackend : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged)
+
+public:
+ explicit StudioQmlTextBackend(QObject *parent = nullptr) : QObject(parent) {}
+
+ void setText(const QString &text)
+ {
+ if (m_text == text)
+ return;
+
+ m_text = text;
+ emit textChanged();
+ }
+
+ QString text() const { return m_text; }
+
+ Q_INVOKABLE void activateText(const QString &text)
+ {
+ if (m_text == text)
+ return;
+
+ setText(text);
+ emit activated(text);
+ }
+
+signals:
+ void textChanged();
+ void activated(const QString &text);
+
+private:
+ QString m_text;
+};
+
+class QMLDESIGNERBASE_EXPORT StudioQmlComboBoxBackend : public QObject
+{
+ Q_OBJECT
+
+ Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
+ Q_PROPERTY(QString currentText READ currentText WRITE setCurrentText NOTIFY currentTextChanged)
+ Q_PROPERTY(int count READ count NOTIFY countChanged)
+ Q_PROPERTY(QStringList model READ model NOTIFY modelChanged) //TODO turn into model
+
+public:
+ explicit StudioQmlComboBoxBackend(QObject *parent = nullptr) : QObject(parent) {}
+
+ void setModel(const QStringList &model)
+ {
+ if (m_model == model)
+ return;
+ m_model = model;
+ emit countChanged();
+ emit modelChanged();
+ emit currentTextChanged();
+ emit currentIndexChanged();
+ }
+
+ QStringList model() const { return m_model; }
+
+ int count() const { return m_model.count(); }
+
+ QString currentText() const
+ {
+ if (m_currentIndex < 0)
+ return {};
+
+ if (m_model.isEmpty())
+ return {};
+
+ if (m_currentIndex >= m_model.count())
+ return {};
+
+ return m_model.at(m_currentIndex);
+ }
+
+ int currentIndex() const { return m_currentIndex; }
+
+ void setCurrentIndex(int i)
+ {
+ if (m_currentIndex == i)
+ return;
+
+ m_currentIndex = i;
+ emit currentTextChanged();
+ emit currentIndexChanged();
+ }
+
+ void setCurrentText(const QString &text)
+ {
+ if (currentText() == text)
+ return;
+
+ if (!m_model.contains(text))
+ return;
+
+ setCurrentIndex(m_model.indexOf(text));
+ }
+
+ Q_INVOKABLE void activateIndex(int i)
+ {
+ if (m_currentIndex == i)
+ return;
+ setCurrentIndex(i);
+ emit activated(i);
+ }
+
+signals:
+ void currentIndexChanged();
+ void currentTextChanged();
+ void countChanged();
+ void modelChanged();
+ void activated(int i);
+
+private:
+ int m_currentIndex = -1;
+ QStringList m_model;
+};
+
class QMLDESIGNERBASE_EXPORT StudioPropertyMap : public QQmlPropertyMap
{
public: