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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user