forked from qt-creator/qt-creator
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:
@@ -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 §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) {
|
||||
|
@@ -79,9 +79,8 @@ signals:
|
||||
void searchTextChanged();
|
||||
|
||||
private: // functions
|
||||
void updateVisibility();
|
||||
void updateVisibility(bool *changed);
|
||||
void addRoleNames();
|
||||
void resetModel();
|
||||
void sortSections();
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user