Commit cfed8095 authored by Tim Jenssen's avatar Tim Jenssen
Browse files

QmlDesigner: only reset model if it is necessary



 - it was 3 times for one update call

Change-Id: Ieed98fc42a2e28487164602549eb11b87f6f2b18
Reviewed-by: default avatarThomas Hartmann <Thomas.Hartmann@theqtcompany.com>
parent eb948c02
...@@ -118,7 +118,10 @@ void ItemLibraryModel::setSearchText(const QString &searchText) ...@@ -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) ...@@ -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) ...@@ -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 ...@@ -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) ...@@ -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() ...@@ -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) {
......
...@@ -79,9 +79,8 @@ signals: ...@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment