From 348c0515d8d6bead8ab8e574100a7151a8244b66 Mon Sep 17 00:00:00 2001 From: Jared Van Bortel Date: Fri, 4 Oct 2024 18:48:42 -0400 Subject: [PATCH] modellist: emit layoutChanged when sorting, but not otherwise Also, hint to layoutChanged about the specific way in which the model was sorted. Signed-off-by: Jared Van Bortel --- gpt4all-chat/src/modellist.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/gpt4all-chat/src/modellist.cpp b/gpt4all-chat/src/modellist.cpp index 79577361..51af296c 100644 --- a/gpt4all-chat/src/modellist.cpp +++ b/gpt4all-chat/src/modellist.cpp @@ -1008,24 +1008,22 @@ void ModelList::updateDataInternal(const QString &id, const QVectorcheckedEmbeddingModel = true; } - if (shouldSort) { - auto s = m_discoverSort; - auto d = m_discoverSortDirection; - std::stable_sort(m_models.begin(), m_models.end(), [s, d](const ModelInfo* lhs, const ModelInfo* rhs) { - return ModelList::lessThan(lhs, rhs, s, d); - }); - } - lock.unlock(); + + if (shouldSort) + resortModel(); + emit dataChanged(createIndex(index, 0), createIndex(index, 0)); emit selectableModelListChanged(); + if (relock) lock.relock(); } void ModelList::resortModel() { - emit layoutAboutToBeChanged(); + const QList parents { QModelIndex() }; + emit layoutAboutToBeChanged(parents, QAbstractItemModel::VerticalSortHint); { QMutexLocker locker(&m_mutex); auto s = m_discoverSort; @@ -1034,7 +1032,7 @@ void ModelList::resortModel() return ModelList::lessThan(lhs, rhs, s, d); }); } - emit layoutChanged(); + emit layoutChanged(parents, QAbstractItemModel::VerticalSortHint); } void ModelList::updateDataByFilename(const QString &filename, QVector> data) @@ -1938,7 +1936,6 @@ void ModelList::clearDiscoveredModels() } for (auto &info : std::as_const(infos)) removeInternal(info); - emit layoutChanged(); } float ModelList::discoverProgress() const @@ -2187,7 +2184,6 @@ void ModelList::handleDiscoveryItemFinished() emit discoverProgressChanged(); if (discoverProgress() >= 1.0) { - emit layoutChanged(); m_discoverInProgress = false; emit discoverInProgressChanged(); }