From bad166cda85ee9e055f7e9c098a811b58114d984 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Thu, 20 Oct 2022 22:44:59 +0300 Subject: [PATCH] QmlDesigner: Maintain bundle categories expand state Prevent categories auto-expanding when adding an bundle material instance. Also some relevant tweaks. Fixes: QDS-8043 Change-Id: Id87886c6d6e065f2c9c1253279348e076bc4d97f Reviewed-by: Miikka Heikkinen --- .../MaterialBrowser.qml | 7 +++-- .../bundlematerialcategory.cpp | 5 ++++ .../materialbrowser/bundlematerialcategory.h | 11 ++++++-- .../materialbrowserbundlemodel.cpp | 28 +++++++++++++------ .../materialbrowserbundlemodel.h | 1 + 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml index 1e8cdfda5d1..7ee927f250a 100644 --- a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml +++ b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml @@ -263,10 +263,13 @@ Item { delegate: Section { width: root.width - caption: bundleCategory + caption: bundleCategoryName addTopPadding: false sectionBackgroundColor: "transparent" visible: bundleCategoryVisible + expanded: bundleCategoryExpanded + expandOnClick: false + onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded Grid { width: scrollView.width @@ -276,7 +279,7 @@ Item { columns: root.width / root.cellWidth Repeater { - model: bundleMaterialsModel + model: bundleCategoryMaterials delegate: BundleMaterialItem { width: root.cellWidth diff --git a/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.cpp b/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.cpp index 716fb57dbf5..60910abb046 100644 --- a/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.cpp +++ b/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.cpp @@ -72,6 +72,11 @@ bool BundleMaterialCategory::visible() const return m_visible; } +bool BundleMaterialCategory::expanded() const +{ + return m_expanded; +} + QList BundleMaterialCategory::categoryMaterials() const { return m_categoryMaterials; diff --git a/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.h b/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.h index 2336a03d010..14f7ddf654e 100644 --- a/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.h +++ b/src/plugins/qmldesigner/components/materialbrowser/bundlematerialcategory.h @@ -35,8 +35,11 @@ class BundleMaterialCategory : public QObject { Q_OBJECT - Q_PROPERTY(QString categoryName MEMBER m_name CONSTANT) - Q_PROPERTY(bool categoryVisible MEMBER m_visible NOTIFY categoryVisibleChanged) + Q_PROPERTY(QString bundleCategoryName MEMBER m_name CONSTANT) + Q_PROPERTY(bool bundleCategoryVisible MEMBER m_visible NOTIFY categoryVisibleChanged) + Q_PROPERTY(bool bundleCategoryExpanded MEMBER m_expanded NOTIFY categoryExpandChanged) + Q_PROPERTY(QList bundleCategoryMaterials MEMBER m_categoryMaterials + NOTIFY bundleMaterialsModelChanged) public: BundleMaterialCategory(QObject *parent, const QString &name); @@ -47,14 +50,18 @@ public: QString name() const; bool visible() const; + bool expanded() const; QList categoryMaterials() const; signals: void categoryVisibleChanged(); + void categoryExpandChanged(); + void bundleMaterialsModelChanged(); private: QString m_name; bool m_visible = true; + bool m_expanded = true; QList m_categoryMaterials; }; diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.cpp b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.cpp index a43a23a1d1d..441cdc7a693 100644 --- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.cpp +++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.cpp @@ -54,17 +54,26 @@ QVariant MaterialBrowserBundleModel::data(const QModelIndex &index, int role) co QTC_ASSERT(index.isValid() && index.row() < m_bundleCategories.count(), return {}); QTC_ASSERT(roleNames().contains(role), return {}); + return m_bundleCategories.at(index.row())->property(roleNames().value(role)); +} + +bool MaterialBrowserBundleModel::setData(const QModelIndex &index, const QVariant &value, int role) +{ + if (!index.isValid() || !roleNames().contains(role)) + return false; + QByteArray roleName = roleNames().value(role); - if (roleName == "bundleCategory") - return m_bundleCategories.at(index.row())->name(); + BundleMaterialCategory *bundleCategory = m_bundleCategories.at(index.row()); + QVariant currValue = bundleCategory->property(roleName); - if (roleName == "bundleCategoryVisible") - return m_bundleCategories.at(index.row())->visible(); + if (currValue != value) { + bundleCategory->setProperty(roleName, value); - if (roleName == "bundleMaterialsModel") - return QVariant::fromValue(m_bundleCategories.at(index.row())->categoryMaterials()); + emit dataChanged(index, index, {role}); + return true; + } - return {}; + return false; } bool MaterialBrowserBundleModel::isValidIndex(int idx) const @@ -75,9 +84,10 @@ bool MaterialBrowserBundleModel::isValidIndex(int idx) const QHash MaterialBrowserBundleModel::roleNames() const { static const QHash roles { - {Qt::UserRole + 1, "bundleCategory"}, + {Qt::UserRole + 1, "bundleCategoryName"}, {Qt::UserRole + 2, "bundleCategoryVisible"}, - {Qt::UserRole + 3, "bundleMaterialsModel"} + {Qt::UserRole + 3, "bundleCategoryExpanded"}, + {Qt::UserRole + 4, "bundleCategoryMaterials"} }; return roles; } diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.h b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.h index 8197ebd78b0..459d7c423af 100644 --- a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.h +++ b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.h @@ -57,6 +57,7 @@ public: int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; + bool setData(const QModelIndex &index, const QVariant &value, int role) override; QHash roleNames() const override; void setSearchText(const QString &searchText);