forked from qt-creator/qt-creator
QmlDesigner: Fix hiding categories with similar names
Fixes: QDS-4144 Change-Id: I045a7457f0d5c949f4e3a445d7679108dd0b8495 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -85,8 +85,9 @@ bool ItemLibraryCategoriesModel::setData(const QModelIndex &index, const QVarian
|
||||
ItemLibraryModel::saveExpandedState(value.toBool(),
|
||||
m_categoryList[index.row()]->categoryName());
|
||||
} else if (m_roleNames.value(role) == "categoryVisible") {
|
||||
ItemLibraryModel::saveCategoryVisibleState(value.toBool(),
|
||||
m_categoryList[index.row()]->categoryName());
|
||||
const ItemLibraryCategory *category = m_categoryList[index.row()];
|
||||
ItemLibraryModel::saveCategoryVisibleState(value.toBool(), category->categoryName(),
|
||||
category->ownerImport()->importName());
|
||||
}
|
||||
emit dataChanged(index, index, {role});
|
||||
return true;
|
||||
@@ -148,7 +149,8 @@ void ItemLibraryCategoriesModel::showAllCategories(bool show)
|
||||
for (const auto &category : std::as_const(m_categoryList)) {
|
||||
if (category->isCategoryVisible() != show) {
|
||||
category->setCategoryVisible(show);
|
||||
ItemLibraryModel::saveCategoryVisibleState(show, category->categoryName());
|
||||
ItemLibraryModel::saveCategoryVisibleState(show, category->categoryName(),
|
||||
category->ownerImport()->importName());
|
||||
}
|
||||
}
|
||||
emit dataChanged(index(0), index(m_categoryList.size() - 1), {m_roleNames.key("categoryVisible")});
|
||||
|
||||
@@ -31,6 +31,7 @@ namespace QmlDesigner {
|
||||
|
||||
ItemLibraryCategory::ItemLibraryCategory(const QString &groupName, QObject *parent)
|
||||
: QObject(parent),
|
||||
m_ownerImport(qobject_cast<ItemLibraryImport *>(parent)),
|
||||
m_name(groupName)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "itemlibraryitemsmodel.h"
|
||||
#include "itemlibraryimport.h"
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -60,6 +61,8 @@ public:
|
||||
|
||||
void setExpanded(bool expanded);
|
||||
|
||||
ItemLibraryImport *ownerImport() const { return m_ownerImport; }
|
||||
|
||||
signals:
|
||||
void itemModelChanged();
|
||||
void visibilityChanged();
|
||||
@@ -68,6 +71,7 @@ signals:
|
||||
|
||||
private:
|
||||
ItemLibraryItemsModel m_itemModel;
|
||||
QPointer<ItemLibraryImport> m_ownerImport = nullptr;
|
||||
QString m_name;
|
||||
bool m_categoryExpanded = true;
|
||||
bool m_isVisible = true;
|
||||
|
||||
@@ -126,7 +126,8 @@ bool ItemLibraryImport::updateCategoryVisibility(const QString &searchText, bool
|
||||
hasVisibleCategories = true;
|
||||
|
||||
if (searchText.isEmpty())
|
||||
category->setCategoryVisible(ItemLibraryModel::loadCategoryVisibleState(category->categoryName()));
|
||||
category->setCategoryVisible(ItemLibraryModel::loadCategoryVisibleState(category->categoryName(),
|
||||
importName()));
|
||||
}
|
||||
|
||||
return hasVisibleCategories;
|
||||
|
||||
@@ -59,14 +59,15 @@ bool ItemLibraryModel::loadExpandedState(const QString §ionName)
|
||||
return expandedStateHash.value(sectionName, true);
|
||||
}
|
||||
|
||||
void ItemLibraryModel::saveCategoryVisibleState(bool isVisible, const QString &categoryName)
|
||||
void ItemLibraryModel::saveCategoryVisibleState(bool isVisible, const QString &categoryName, const
|
||||
QString &importName)
|
||||
{
|
||||
categoryVisibleStateHash.insert(categoryName, isVisible);
|
||||
categoryVisibleStateHash.insert(categoryName + '_' + importName, isVisible);
|
||||
}
|
||||
|
||||
bool ItemLibraryModel::loadCategoryVisibleState(const QString &categoryName)
|
||||
bool ItemLibraryModel::loadCategoryVisibleState(const QString &categoryName, const QString &importName)
|
||||
{
|
||||
return categoryVisibleStateHash.value(categoryName, true);
|
||||
return categoryVisibleStateHash.value(categoryName + '_' + importName, true);
|
||||
}
|
||||
|
||||
void ItemLibraryModel::showHiddenCategories()
|
||||
|
||||
@@ -69,8 +69,9 @@ public:
|
||||
static void registerQmlTypes();
|
||||
static void saveExpandedState(bool expanded, const QString §ionName);
|
||||
static bool loadExpandedState(const QString §ionName);
|
||||
static void saveCategoryVisibleState(bool isVisible, const QString &categoryName);
|
||||
static bool loadCategoryVisibleState(const QString &categoryName);
|
||||
static void saveCategoryVisibleState(bool isVisible, const QString &categoryName, const QString
|
||||
&importName);
|
||||
static bool loadCategoryVisibleState(const QString &categoryName, const QString &importName);
|
||||
|
||||
Q_INVOKABLE void expandAll();
|
||||
Q_INVOKABLE void collapseAll();
|
||||
|
||||
Reference in New Issue
Block a user