QmlDesigner: only reset model if it is necessary

- it was 3 times for one update call

Change-Id: Ieed98fc42a2e28487164602549eb11b87f6f2b18
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@theqtcompany.com>
This commit is contained in:
Tim Jenssen
2016-06-07 19:58:38 +02:00
parent eb948c0214
commit cfed8095be
2 changed files with 13 additions and 25 deletions

View File

@@ -118,7 +118,10 @@ void ItemLibraryModel::setSearchText(const QString &searchText)
m_searchText = lowerSearchText; m_searchText = lowerSearchText;
emit searchTextChanged(); 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) if (!model)
return; return;
QMap<QString, int> sections; beginResetModel();
clearSections(); clearSections();
QStringList imports; QStringList imports;
@@ -156,22 +158,22 @@ void ItemLibraryModel::update(ItemLibraryInfo *itemLibraryInfo, Model *model)
|| model->hasImport(entryToImport(entry), true, true))) { || model->hasImport(entryToImport(entry), true, true))) {
QString itemSectionName = entry.category(); QString itemSectionName = entry.category();
ItemLibrarySection *sectionModel = sectionByName(itemSectionName); ItemLibrarySection *sectionModel = sectionByName(itemSectionName);
ItemLibraryItem *item;
if (sectionModel == 0) { if (sectionModel == 0) {
sectionModel = new ItemLibrarySection(itemSectionName, this); sectionModel = new ItemLibrarySection(itemSectionName, this);
m_sections.append(sectionModel); m_sections.append(sectionModel);
} }
item = new ItemLibraryItem(sectionModel); ItemLibraryItem *item = new ItemLibraryItem(sectionModel);
item->setItemLibraryEntry(entry); item->setItemLibraryEntry(entry);
sectionModel->addSectionEntry(item); sectionModel->addSectionEntry(item);
} }
} }
sortSections(); sortSections();
resetModel(); bool changed = false;
updateVisibility(); updateVisibility(&changed);
endResetModel();
} }
QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntry) QMimeData *ItemLibraryModel::getMimeData(const ItemLibraryEntry &itemLibraryEntry)
@@ -195,10 +197,8 @@ QList<ItemLibrarySection *> ItemLibraryModel::sections() const
void ItemLibraryModel::clearSections() void ItemLibraryModel::clearSections()
{ {
beginResetModel();
qDeleteAll(m_sections); qDeleteAll(m_sections);
m_sections.clear(); m_sections.clear();
endResetModel();
} }
void ItemLibraryModel::registerQmlTypes() void ItemLibraryModel::registerQmlTypes()
@@ -217,22 +217,17 @@ ItemLibrarySection *ItemLibraryModel::sectionByName(const QString &sectionName)
return 0; return 0;
} }
void ItemLibraryModel::updateVisibility() void ItemLibraryModel::updateVisibility(bool *changed)
{ {
bool changed = false;
foreach (ItemLibrarySection *itemLibrarySection, m_sections) { foreach (ItemLibrarySection *itemLibrarySection, m_sections) {
QString sectionSearchText = m_searchText; QString sectionSearchText = m_searchText;
bool sectionChanged = false; bool sectionChanged = false;
bool sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText, bool sectionVisibility = itemLibrarySection->updateSectionVisibility(sectionSearchText,
&sectionChanged); &sectionChanged);
changed |= sectionChanged; *changed |= sectionChanged;
changed |= itemLibrarySection->setVisible(sectionVisibility); *changed |= itemLibrarySection->setVisible(sectionVisibility);
} }
if (changed)
resetModel();
} }
void ItemLibraryModel::addRoleNames() void ItemLibraryModel::addRoleNames()
@@ -245,12 +240,6 @@ void ItemLibraryModel::addRoleNames()
} }
} }
void ItemLibraryModel::resetModel()
{
beginResetModel();
endResetModel();
}
void ItemLibraryModel::sortSections() void ItemLibraryModel::sortSections()
{ {
auto sectionSort = [](ItemLibrarySection *first, ItemLibrarySection *second) { auto sectionSort = [](ItemLibrarySection *first, ItemLibrarySection *second) {

View File

@@ -79,9 +79,8 @@ signals:
void searchTextChanged(); void searchTextChanged();
private: // functions private: // functions
void updateVisibility(); void updateVisibility(bool *changed);
void addRoleNames(); void addRoleNames();
void resetModel();
void sortSections(); void sortSections();