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)
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<QString, int> 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<ItemLibrarySection *> 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 &sectionName)
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,
&sectionChanged);
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) {
......
......@@ -79,9 +79,8 @@ signals:
void searchTextChanged();
private: // functions
void updateVisibility();
void updateVisibility(bool *changed);
void addRoleNames();
void resetModel();
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