From cfed8095beabce35cf3d9fa1df0e53b2e3ac2670 Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Tue, 7 Jun 2016 19:58:38 +0200 Subject: [PATCH] QmlDesigner: only reset model if it is necessary - it was 3 times for one update call Change-Id: Ieed98fc42a2e28487164602549eb11b87f6f2b18 Reviewed-by: Thomas Hartmann --- .../itemlibrary/itemlibrarymodel.cpp | 35 +++++++------------ .../components/itemlibrary/itemlibrarymodel.h | 3 +- 2 files changed, 13 insertions(+), 25 deletions(-) diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp index 3080c9befe8..3bfc4550224 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.cpp @@ -118,7 +118,10 @@ void ItemLibraryModel::setSearchText(const QString &searchText) m_searchText = lowerSearchText; emit searchTextChanged(); - updateVisibility(); + bool changed = false; + updateVisibility(&changed); + if (changed) + dataChanged(QModelIndex(), QModelIndex()); } } @@ -137,8 +140,7 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model) if (!model) return; - QMap sections; - + beginResetModel(); clearSections(); QStringList imports; @@ -156,22 +158,22 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model) || model->hasImport(entryToImport(entry), true, true))) { QString itemSectionName = entry.category(); ItemLibrarySection *sectionModel = sectionByName(itemSectionName); - ItemLibraryItem *item; if (sectionModel == 0) { sectionModel = new ItemLibrarySection(itemSectionName, this); m_sections.append(sectionModel); } - item = new ItemLibraryItem(sectionModel); + ItemLibraryItem *item = new ItemLibraryItem(sectionModel); item->setItemLibraryEntry(entry); sectionModel->addSectionEntry(item); } } sortSections(); - resetModel(); - updateVisibility(); + bool changed = false; + updateVisibility(&changed); + endResetModel(); } QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntry) @@ -195,10 +197,8 @@ QList ItemLibraryModel::sections() const void ItemLibraryModel::clearSections() { - beginResetModel(); qDeleteAll(m_sections); m_sections.clear(); - endResetModel(); } void ItemLibraryModel::registerQmlTypes() @@ -217,22 +217,17 @@ ItemLibrarySection *ItemLibraryModel::sectionByName(const QString §ionName) return 0; } -void ItemLibraryModel::updateVisibility() +void ItemLibraryModel::updateVisibility(bool *changed) { - bool changed = false; - foreach (ItemLibrarySection *itemLibrarySection, m_sections) { QString sectionSearchText = m_searchText; bool sectionChanged = false; bool sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText, §ionChanged); - changed |= sectionChanged; - changed |= itemLibrarySection->setVisible(sectionVisibility); + *changed |= sectionChanged; + *changed |= itemLibrarySection->setVisible(sectionVisibility); } - - if (changed) - resetModel(); } void ItemLibraryModel::addRoleNames() @@ -245,12 +240,6 @@ void ItemLibraryModel::addRoleNames() } } -void ItemLibraryModel::resetModel() -{ - beginResetModel(); - endResetModel(); -} - void ItemLibraryModel::sortSections() { auto sectionSort = [](ItemLibrarySection *first, ItemLibrarySection *second) { diff --git a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h index bf1a2112484..b4d5bc1d704 100644 --- a/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h +++ b/src/plugins/qmldesigner/components/itemlibrary/itemlibrarymodel.h @@ -79,9 +79,8 @@ signals: void searchTextChanged(); private: // functions - void updateVisibility(); + void updateVisibility(bool *changed); void addRoleNames(); - void resetModel(); void sortSections();