QmlDesigner: Preserve item library expand state

Section and category visibility updates always expanded section
or category. Now this forced expansion is only done when searching
for items.

Fixes: QDS-3811
Change-Id: I006124a92086c4851d54407c4ffba0e9c94a854d
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Miikka Heikkinen
2021-03-08 17:01:40 +02:00
parent 6fdb34994c
commit d37f6648f3
7 changed files with 12 additions and 11 deletions

View File

@@ -102,6 +102,7 @@ void ItemLibraryCategoriesModel::expandCategories(bool expand)
for (const auto &category : std::as_const(m_categoryList)) {
if (category->categoryExpanded() != expand) {
category->setExpanded(expand);
ItemLibraryModel::saveExpandedState(expand, category->categoryName());
emit dataChanged(index(i), index(i), {m_roleNames.key("categoryExpanded")});
}
++i;

View File

@@ -60,7 +60,7 @@ QObject *ItemLibraryCategory::itemModel()
return &m_itemModel;
}
bool ItemLibraryCategory::updateItemVisibility(const QString &searchText, bool *changed)
bool ItemLibraryCategory::updateItemVisibility(const QString &searchText, bool *changed, bool expand)
{
bool hasVisibleItems = false;
@@ -81,7 +81,7 @@ bool ItemLibraryCategory::updateItemVisibility(const QString &searchText, bool *
}
// expand category if it has an item matching search criteria
if (hasVisibleItems && !categoryExpanded())
if (expand && hasVisibleItems && !categoryExpanded())
setExpanded(true);
return hasVisibleItems;

View File

@@ -50,7 +50,7 @@ public:
void addItem(ItemLibraryItem *item);
QObject *itemModel();
bool updateItemVisibility(const QString &searchText, bool *changed);
bool updateItemVisibility(const QString &searchText, bool *changed, bool expand = false);
bool setVisible(bool isVisible);
bool isVisible() const;

View File

@@ -95,14 +95,14 @@ void ItemLibraryImport::expandCategories(bool expand)
m_categoryModel.expandCategories(expand);
}
bool ItemLibraryImport::updateCategoryVisibility(const QString &searchText, bool *changed)
bool ItemLibraryImport::updateCategoryVisibility(const QString &searchText, bool *changed, bool expand)
{
bool hasVisibleCategories = false;
*changed = false;
for (const auto &category : m_categoryModel.categorySections()) {
bool categoryChanged = false;
bool hasVisibleItems = category->updateItemVisibility(searchText, &categoryChanged);
bool hasVisibleItems = category->updateItemVisibility(searchText, &categoryChanged, expand);
categoryChanged |= category->setVisible(hasVisibleItems);
*changed |= categoryChanged;

View File

@@ -67,7 +67,7 @@ public:
void addCategory(ItemLibraryCategory *category);
QObject *categoryModel();
bool updateCategoryVisibility(const QString &searchText, bool *changed);
bool updateCategoryVisibility(const QString &searchText, bool *changed, bool expand = false);
bool setVisible(bool isVisible);
void setImportUsed(bool importUsed);
void sortCategorySections();

View File

@@ -163,7 +163,7 @@ void ItemLibraryModel::setSearchText(const QString &searchText)
m_searchText = lowerSearchText;
bool changed = false;
updateVisibility(&changed);
updateVisibility(&changed, !m_searchText.isEmpty());
}
}
@@ -374,18 +374,18 @@ void ItemLibraryModel::updateUsedImports(const QList<Import> &usedImports)
}
}
void ItemLibraryModel::updateVisibility(bool *changed)
void ItemLibraryModel::updateVisibility(bool *changed, bool expand)
{
for (ItemLibraryImport *import : std::as_const(m_importList)) {
bool categoryChanged = false;
bool hasVisibleItems = import->updateCategoryVisibility(m_searchText, &categoryChanged);
bool hasVisibleItems = import->updateCategoryVisibility(m_searchText, &categoryChanged, expand);
*changed |= categoryChanged;
if (import->sectionType() == ItemLibraryImport::SectionType::Unimported)
*changed |= import->setVisible(!m_searchText.isEmpty());
// expand import if it has an item matching search criteria
if (hasVisibleItems && !import->importExpanded())
if (expand && hasVisibleItems && !import->importExpanded())
import->setImportExpanded();
}

View File

@@ -72,7 +72,7 @@ public:
Import entryToImport(const ItemLibraryEntry &entry);
private:
void updateVisibility(bool *changed);
void updateVisibility(bool *changed, bool expand = false);
void addRoleNames();
void sortSections();
void clearSections();