Skip to content

Commit 8f3d107

Browse files
authored
modellist: fix incorrect signal use and remove invalidate calls (#3042)
Signed-off-by: Jared Van Bortel <[email protected]>
1 parent 8618a19 commit 8f3d107

File tree

3 files changed

+8
-24
lines changed

3 files changed

+8
-24
lines changed

gpt4all-chat/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
2424
- Fix "regenerate" always forgetting the most recent message ([#3011](https://github.com/nomic-ai/gpt4all/pull/3011))
2525
- Fix loaded chats forgetting context when there is a system prompt ([#3015](https://github.com/nomic-ai/gpt4all/pull/3015))
2626
- Make it possible to downgrade and keep some chats, and avoid crash for some model types ([#3030](https://github.com/nomic-ai/gpt4all/pull/3030))
27+
- Fix scroll positition being reset in model view, and attempt a better fix for the clone issue ([#3042](https://github.com/nomic-ai/gpt4all/pull/3042))
2728

2829
## [3.3.1] - 2024-09-27 ([v3.3.y](https://github.com/nomic-ai/gpt4all/tree/v3.3.y))
2930

gpt4all-chat/src/localdocsmodel.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ LocalDocsCollectionsModel::LocalDocsCollectionsModel(QObject *parent)
2020
connect(this, &LocalDocsCollectionsModel::rowsInserted, this, &LocalDocsCollectionsModel::countChanged);
2121
connect(this, &LocalDocsCollectionsModel::rowsRemoved, this, &LocalDocsCollectionsModel::countChanged);
2222
connect(this, &LocalDocsCollectionsModel::modelReset, this, &LocalDocsCollectionsModel::countChanged);
23-
connect(this, &LocalDocsCollectionsModel::layoutChanged, this, &LocalDocsCollectionsModel::countChanged);
2423
}
2524

2625
bool LocalDocsCollectionsModel::filterAcceptsRow(int sourceRow,
@@ -67,7 +66,6 @@ LocalDocsModel::LocalDocsModel(QObject *parent)
6766
connect(this, &LocalDocsModel::rowsInserted, this, &LocalDocsModel::countChanged);
6867
connect(this, &LocalDocsModel::rowsRemoved, this, &LocalDocsModel::countChanged);
6968
connect(this, &LocalDocsModel::modelReset, this, &LocalDocsModel::countChanged);
70-
connect(this, &LocalDocsModel::layoutChanged, this, &LocalDocsModel::countChanged);
7169
}
7270

7371
int LocalDocsModel::rowCount(const QModelIndex &parent) const

gpt4all-chat/src/modellist.cpp

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,6 @@ InstalledModels::InstalledModels(QObject *parent, bool selectable)
398398
connect(this, &InstalledModels::rowsInserted, this, &InstalledModels::countChanged);
399399
connect(this, &InstalledModels::rowsRemoved, this, &InstalledModels::countChanged);
400400
connect(this, &InstalledModels::modelReset, this, &InstalledModels::countChanged);
401-
connect(this, &InstalledModels::layoutChanged, this, &InstalledModels::countChanged);
402401
}
403402

404403
bool InstalledModels::filterAcceptsRow(int sourceRow,
@@ -423,7 +422,6 @@ DownloadableModels::DownloadableModels(QObject *parent)
423422
connect(this, &DownloadableModels::rowsInserted, this, &DownloadableModels::countChanged);
424423
connect(this, &DownloadableModels::rowsRemoved, this, &DownloadableModels::countChanged);
425424
connect(this, &DownloadableModels::modelReset, this, &DownloadableModels::countChanged);
426-
connect(this, &DownloadableModels::layoutChanged, this, &DownloadableModels::countChanged);
427425
}
428426

429427
bool DownloadableModels::filterAcceptsRow(int sourceRow,
@@ -821,7 +819,11 @@ QVariant ModelList::data(const QModelIndex &index, int role) const
821819

822820
void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>> &data)
823821
{
822+
// We only sort when one of the fields used by the sorting algorithm actually changes that
823+
// is implicated or used by the sorting algorithm
824+
bool shouldSort = false;
824825
int index;
826+
825827
{
826828
QMutexLocker locker(&m_mutex);
827829
if (!m_modelMap.contains(id)) {
@@ -836,10 +838,6 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
836838
return;
837839
}
838840

839-
// We only sort when one of the fields used by the sorting algorithm actually changes that
840-
// is implicated or used by the sorting algorithm
841-
bool shouldSort = false;
842-
843841
for (const auto &d : data) {
844842
const int role = d.first;
845843
const QVariant value = d.second;
@@ -1000,21 +998,12 @@ void ModelList::updateData(const QString &id, const QVector<QPair<int, QVariant>
1000998
info->isEmbeddingModel = LLModel::Implementation::isEmbeddingModel(modelPath.toStdString());
1001999
info->checkedEmbeddingModel = true;
10021000
}
1003-
1004-
if (shouldSort) {
1005-
auto s = m_discoverSort;
1006-
auto d = m_discoverSortDirection;
1007-
std::stable_sort(m_models.begin(), m_models.end(), [s, d](const ModelInfo* lhs, const ModelInfo* rhs) {
1008-
return ModelList::lessThan(lhs, rhs, s, d);
1009-
});
1010-
}
10111001
}
1002+
10121003
emit dataChanged(createIndex(index, 0), createIndex(index, 0));
10131004

1014-
// FIXME(jared): for some reason these don't update correctly when the source model changes, so we explicitly invalidate them
1015-
m_selectableModels->invalidate();
1016-
m_installedModels->invalidate();
1017-
m_downloadableModels->invalidate();
1005+
if (shouldSort)
1006+
resortModel();
10181007

10191008
emit selectableModelListChanged();
10201009
}
@@ -1122,7 +1111,6 @@ void ModelList::removeClone(const ModelInfo &model)
11221111
return;
11231112

11241113
removeInternal(model);
1125-
emit layoutChanged();
11261114
}
11271115

11281116
void ModelList::removeInstalled(const ModelInfo &model)
@@ -1131,7 +1119,6 @@ void ModelList::removeInstalled(const ModelInfo &model)
11311119
Q_ASSERT(!model.isClone());
11321120
Q_ASSERT(model.isDiscovered() || model.isCompatibleApi || model.description() == "" /*indicates sideloaded*/);
11331121
removeInternal(model);
1134-
emit layoutChanged();
11351122
}
11361123

11371124
void ModelList::removeInternal(const ModelInfo &model)
@@ -1928,7 +1915,6 @@ void ModelList::clearDiscoveredModels()
19281915
}
19291916
for (ModelInfo &info : infos)
19301917
removeInternal(info);
1931-
emit layoutChanged();
19321918
}
19331919

19341920
float ModelList::discoverProgress() const
@@ -2176,7 +2162,6 @@ void ModelList::handleDiscoveryItemFinished()
21762162
emit discoverProgressChanged();
21772163

21782164
if (discoverProgress() >= 1.0) {
2179-
emit layoutChanged();
21802165
m_discoverInProgress = false;
21812166
emit discoverInProgressChanged();;
21822167
}

0 commit comments

Comments
 (0)