From 8f261d06db2ca91fd6094be08ad32b8a52bc57b1 Mon Sep 17 00:00:00 2001 From: Adam Treat Date: Fri, 12 Jul 2024 16:15:40 -0400 Subject: [PATCH] Respond to translation events by invalidating the model. Signed-off-by: Adam Treat --- gpt4all-chat/chatlistmodel.cpp | 12 +++++++++++- gpt4all-chat/chatlistmodel.h | 3 +++ gpt4all-chat/modellist.cpp | 11 +++++++++++ gpt4all-chat/modellist.h | 3 +++ 4 files changed, 28 insertions(+), 1 deletion(-) diff --git a/gpt4all-chat/chatlistmodel.cpp b/gpt4all-chat/chatlistmodel.cpp index d5b7070a..87400c05 100644 --- a/gpt4all-chat/chatlistmodel.cpp +++ b/gpt4all-chat/chatlistmodel.cpp @@ -29,7 +29,17 @@ ChatListModel *ChatListModel::globalInstance() } ChatListModel::ChatListModel() - : QAbstractListModel(nullptr) {} + : QAbstractListModel(nullptr) { + + QCoreApplication::instance()->installEventFilter(this); +} + +bool ChatListModel::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == QCoreApplication::instance() && ev->type() == QEvent::LanguageChange) + emit dataChanged(index(0, 0), index(m_chats.size() - 1, 0)); + return false; +} void ChatListModel::loadChats() { diff --git a/gpt4all-chat/chatlistmodel.h b/gpt4all-chat/chatlistmodel.h index 43ccbb41..95f8e6f2 100644 --- a/gpt4all-chat/chatlistmodel.h +++ b/gpt4all-chat/chatlistmodel.h @@ -242,6 +242,9 @@ Q_SIGNALS: void requestSaveChats(const QVector &); void saveChatsFinished(); +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; + private Q_SLOTS: void newChatCountChanged() { diff --git a/gpt4all-chat/modellist.cpp b/gpt4all-chat/modellist.cpp index c79335fa..f6f215d2 100644 --- a/gpt4all-chat/modellist.cpp +++ b/gpt4all-chat/modellist.cpp @@ -483,6 +483,8 @@ ModelList::ModelList() , m_discoverResultsCompleted(0) , m_discoverInProgress(false) { + QCoreApplication::instance()->installEventFilter(this); + m_installedModels->setSourceModel(this); m_selectableModels->setSourceModel(this); m_downloadableModels->setSourceModel(this); @@ -508,6 +510,15 @@ ModelList::ModelList() updateModelsFromJson(); updateModelsFromSettings(); updateModelsFromDirectory(); + + QCoreApplication::instance()->installEventFilter(this); +} + +bool ModelList::eventFilter(QObject *obj, QEvent *ev) +{ + if (obj == QCoreApplication::instance() && ev->type() == QEvent::LanguageChange) + emit dataChanged(index(0, 0), index(m_models.size() - 1, 0)); + return false; } QString ModelList::incompleteDownloadPath(const QString &modelFile) diff --git a/gpt4all-chat/modellist.h b/gpt4all-chat/modellist.h index 29b26323..c60a7067 100644 --- a/gpt4all-chat/modellist.h +++ b/gpt4all-chat/modellist.h @@ -460,6 +460,9 @@ Q_SIGNALS: void discoverProgressChanged(); void discoverInProgressChanged(); +protected: + bool eventFilter(QObject *obj, QEvent *ev) override; + private Q_SLOTS: void resortModel(); void updateModelsFromJson();