Respond to translation events by invalidating the model.

Signed-off-by: Adam Treat <treat.adam@gmail.com>
This commit is contained in:
Adam Treat 2024-07-12 16:15:40 -04:00
parent d515ad3b18
commit 8f261d06db
4 changed files with 28 additions and 1 deletions

View File

@ -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()
{

View File

@ -242,6 +242,9 @@ Q_SIGNALS:
void requestSaveChats(const QVector<Chat*> &);
void saveChatsFinished();
protected:
bool eventFilter(QObject *obj, QEvent *ev) override;
private Q_SLOTS:
void newChatCountChanged()
{

View File

@ -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)

View File

@ -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();