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>
This commit is contained in:
Mahmoud Badri
2022-10-20 22:44:59 +03:00
parent 2ccc4a03ed
commit bad166cda8
5 changed files with 39 additions and 13 deletions

View File

@@ -263,10 +263,13 @@ Item {
delegate: Section { delegate: Section {
width: root.width width: root.width
caption: bundleCategory caption: bundleCategoryName
addTopPadding: false addTopPadding: false
sectionBackgroundColor: "transparent" sectionBackgroundColor: "transparent"
visible: bundleCategoryVisible visible: bundleCategoryVisible
expanded: bundleCategoryExpanded
expandOnClick: false
onToggleExpand: bundleCategoryExpanded = !bundleCategoryExpanded
Grid { Grid {
width: scrollView.width width: scrollView.width
@@ -276,7 +279,7 @@ Item {
columns: root.width / root.cellWidth columns: root.width / root.cellWidth
Repeater { Repeater {
model: bundleMaterialsModel model: bundleCategoryMaterials
delegate: BundleMaterialItem { delegate: BundleMaterialItem {
width: root.cellWidth width: root.cellWidth

View File

@@ -72,6 +72,11 @@ bool BundleMaterialCategory::visible() const
return m_visible; return m_visible;
} }
bool BundleMaterialCategory::expanded() const
{
return m_expanded;
}
QList<BundleMaterial *> BundleMaterialCategory::categoryMaterials() const QList<BundleMaterial *> BundleMaterialCategory::categoryMaterials() const
{ {
return m_categoryMaterials; return m_categoryMaterials;

View File

@@ -35,8 +35,11 @@ class BundleMaterialCategory : public QObject
{ {
Q_OBJECT Q_OBJECT
Q_PROPERTY(QString categoryName MEMBER m_name CONSTANT) Q_PROPERTY(QString bundleCategoryName MEMBER m_name CONSTANT)
Q_PROPERTY(bool categoryVisible MEMBER m_visible NOTIFY categoryVisibleChanged) 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: public:
BundleMaterialCategory(QObject *parent, const QString &name); BundleMaterialCategory(QObject *parent, const QString &name);
@@ -47,14 +50,18 @@ public:
QString name() const; QString name() const;
bool visible() const; bool visible() const;
bool expanded() const;
QList<BundleMaterial *> categoryMaterials() const; QList<BundleMaterial *> categoryMaterials() const;
signals: signals:
void categoryVisibleChanged(); void categoryVisibleChanged();
void categoryExpandChanged();
void bundleMaterialsModelChanged();
private: private:
QString m_name; QString m_name;
bool m_visible = true; bool m_visible = true;
bool m_expanded = true;
QList<BundleMaterial *> m_categoryMaterials; QList<BundleMaterial *> m_categoryMaterials;
}; };

View File

@@ -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(index.isValid() && index.row() < m_bundleCategories.count(), return {});
QTC_ASSERT(roleNames().contains(role), 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); QByteArray roleName = roleNames().value(role);
if (roleName == "bundleCategory") BundleMaterialCategory *bundleCategory = m_bundleCategories.at(index.row());
return m_bundleCategories.at(index.row())->name(); QVariant currValue = bundleCategory->property(roleName);
if (roleName == "bundleCategoryVisible") if (currValue != value) {
return m_bundleCategories.at(index.row())->visible(); bundleCategory->setProperty(roleName, value);
if (roleName == "bundleMaterialsModel") emit dataChanged(index, index, {role});
return QVariant::fromValue(m_bundleCategories.at(index.row())->categoryMaterials()); return true;
}
return {}; return false;
} }
bool MaterialBrowserBundleModel::isValidIndex(int idx) const bool MaterialBrowserBundleModel::isValidIndex(int idx) const
@@ -75,9 +84,10 @@ bool MaterialBrowserBundleModel::isValidIndex(int idx) const
QHash<int, QByteArray> MaterialBrowserBundleModel::roleNames() const QHash<int, QByteArray> MaterialBrowserBundleModel::roleNames() const
{ {
static const QHash<int, QByteArray> roles { static const QHash<int, QByteArray> roles {
{Qt::UserRole + 1, "bundleCategory"}, {Qt::UserRole + 1, "bundleCategoryName"},
{Qt::UserRole + 2, "bundleCategoryVisible"}, {Qt::UserRole + 2, "bundleCategoryVisible"},
{Qt::UserRole + 3, "bundleMaterialsModel"} {Qt::UserRole + 3, "bundleCategoryExpanded"},
{Qt::UserRole + 4, "bundleCategoryMaterials"}
}; };
return roles; return roles;
} }

View File

@@ -57,6 +57,7 @@ public:
int rowCount(const QModelIndex &parent = QModelIndex()) const override; int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) 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; QHash<int, QByteArray> roleNames() const override;
void setSearchText(const QString &searchText); void setSearchText(const QString &searchText);