forked from qt-creator/qt-creator
QmlDesigner: Expand collapsed component categories when searching
- Expand collapsed categories in the following 2 cases: - When searching. - When choosing "Expand all" from the context menu. - Update only changed data when expand state changes rather than resetting the whole model. - Update search after adding a new QML import and switching to the components view. Task-number: QDS-3781 Task-number: QDS-3784 Task-number: QDS-3789 Change-Id: I09e6f1f97171cd9172cadf4202dd8d02cbb78513 Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -60,34 +60,28 @@ bool ItemLibraryModel::loadExpandedState(const QString §ionName)
|
||||
|
||||
void ItemLibraryModel::expandAll()
|
||||
{
|
||||
bool changed = false;
|
||||
int i = 0;
|
||||
for (const QPointer<ItemLibraryImport> &import : std::as_const(m_importList)) {
|
||||
if (import->hasCategories() && !import->importExpanded()) {
|
||||
changed = true;
|
||||
if (!import->importExpanded()) {
|
||||
import->setImportExpanded();
|
||||
emit dataChanged(index(i), index(i), {m_roleNames.key("importExpanded")});
|
||||
saveExpandedState(true, import->importUrl());
|
||||
}
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
import->expandCategories(true);
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
void ItemLibraryModel::collapseAll()
|
||||
{
|
||||
bool changed = false;
|
||||
int i = 0;
|
||||
for (const QPointer<ItemLibraryImport> &import : std::as_const(m_importList)) {
|
||||
if (import->hasCategories() && import->importExpanded()) {
|
||||
changed = true;
|
||||
import->setImportExpanded(false);
|
||||
emit dataChanged(index(i), index(i), {m_roleNames.key("importExpanded")});
|
||||
saveExpandedState(false, import->importUrl());
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,9 +318,18 @@ void ItemLibraryModel::updateVisibility(bool *changed)
|
||||
{
|
||||
for (ItemLibraryImport *import : std::as_const(m_importList)) {
|
||||
bool categoryChanged = false;
|
||||
import->updateCategoryVisibility(m_searchText, &categoryChanged);
|
||||
bool hasVisibleItems = import->updateCategoryVisibility(m_searchText, &categoryChanged);
|
||||
|
||||
*changed |= categoryChanged;
|
||||
|
||||
// expand import if it has an item matching search criteria
|
||||
if (hasVisibleItems && !import->importExpanded())
|
||||
import->setImportExpanded();
|
||||
}
|
||||
|
||||
if (changed) {
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user