diff options
author | Mahmoud Badri <mahmoud.badri@qt.io> | 2022-10-20 22:44:59 +0300 |
---|---|---|
committer | Mahmoud Badri <mahmoud.badri@qt.io> | 2022-10-21 10:00:01 +0000 |
commit | bad166cda85ee9e055f7e9c098a811b58114d984 (patch) | |
tree | 9e472f2f673febbc33a38153564863560a3791ff | |
parent | 2ccc4a03ed6e52911321fc139dfd9fb3f8f65594 (diff) | |
download | qt-creator-bad166cda85ee9e055f7e9c098a811b58114d984.tar.gz |
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 <miikka.heikkinen@qt.io>
5 files changed, 39 insertions, 13 deletions
diff --git a/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml b/share/qtcreator/qmldesigner/materialBrowserQmlSource/MaterialBrowser.qml index 1e8cdfda5d..7ee927f250 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 716fb57dbf..60910abb04 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<BundleMaterial *> 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 2336a03d01..14f7ddf654 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<BundleMaterial *> 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<BundleMaterial *> categoryMaterials() const; signals: void categoryVisibleChanged(); + void categoryExpandChanged(); + void bundleMaterialsModelChanged(); private: QString m_name; bool m_visible = true; + bool m_expanded = true; QList<BundleMaterial *> m_categoryMaterials; }; diff --git a/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.cpp b/src/plugins/qmldesigner/components/materialbrowser/materialbrowserbundlemodel.cpp index a43a23a1d1..441cdc7a69 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<int, QByteArray> MaterialBrowserBundleModel::roleNames() const { static const QHash<int, QByteArray> 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 8197ebd78b..459d7c423a 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<int, QByteArray> roleNames() const override; void setSearchText(const QString &searchText); |