forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user