From 1c459720a729097473338b83e7db5710a899f83d Mon Sep 17 00:00:00 2001 From: askmeaboutloom Date: Tue, 13 Jun 2023 03:23:06 +0200 Subject: [PATCH] Make avatar preferences work again They were waiting for commit() to be called, which never happened because of the settings redesign getting rid of the OK/Apply/Cancel buttons. Now there's an autoCommit option on the model, which will call it automatically. --- src/desktop/dialogs/logindialog.cpp | 2 +- src/desktop/dialogs/settingsdialog/network.cpp | 2 +- src/libclient/utils/avatarlistmodel.cpp | 11 ++++++++++- src/libclient/utils/avatarlistmodel.h | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/desktop/dialogs/logindialog.cpp b/src/desktop/dialogs/logindialog.cpp index c5b594a05e..638f9e6125 100644 --- a/src/desktop/dialogs/logindialog.cpp +++ b/src/desktop/dialogs/logindialog.cpp @@ -72,7 +72,7 @@ struct LoginDialog::Private { // Identity & authentication page ui->username->setValidator(new UsernameValidator(dlg)); - avatars = new AvatarListModel(dlg); + avatars = new AvatarListModel(false, dlg); avatars->loadAvatars(true); ui->avatarList->setModel(avatars); diff --git a/src/desktop/dialogs/settingsdialog/network.cpp b/src/desktop/dialogs/settingsdialog/network.cpp index 6c5d9c4ef4..d5e7e20f99 100644 --- a/src/desktop/dialogs/settingsdialog/network.cpp +++ b/src/desktop/dialogs/settingsdialog/network.cpp @@ -76,7 +76,7 @@ void Network::initAvatars(utils::SanerFormLayout *form) avatars->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); avatars->setSelectionMode(QAbstractItemView::ExtendedSelection); - auto *avatarsModel = new AvatarListModel(this); + auto *avatarsModel = new AvatarListModel(true, this); avatarsModel->loadAvatars(); avatars->setModel(avatarsModel); avatars->setItemDelegate(new AvatarItemDelegate(this)); diff --git a/src/libclient/utils/avatarlistmodel.cpp b/src/libclient/utils/avatarlistmodel.cpp index 06d6b92077..4949059bf9 100644 --- a/src/libclient/utils/avatarlistmodel.cpp +++ b/src/libclient/utils/avatarlistmodel.cpp @@ -8,8 +8,9 @@ #include #include -AvatarListModel::AvatarListModel(QObject *parent) +AvatarListModel::AvatarListModel(bool autoCommit, QObject *parent) : QAbstractListModel(parent) + , m_autoCommit(autoCommit) { } @@ -65,6 +66,10 @@ bool AvatarListModel::removeRows(int row, int count, const QModelIndex &parent) m_avatars.remove(row); } endRemoveRows(); + + if(m_autoCommit) { + commit(); + } return true; } @@ -86,6 +91,10 @@ void AvatarListModel::addAvatar(const QPixmap &icon) QString() }; endInsertRows(); + + if(m_autoCommit) { + commit(); + } } void AvatarListModel::loadAvatars(bool includeBlank) diff --git a/src/libclient/utils/avatarlistmodel.h b/src/libclient/utils/avatarlistmodel.h index 9e94fc4dd2..5a09f390c1 100644 --- a/src/libclient/utils/avatarlistmodel.h +++ b/src/libclient/utils/avatarlistmodel.h @@ -15,7 +15,7 @@ class AvatarListModel final : public QAbstractListModel FilenameRole = Qt::UserRole + 1, }; - AvatarListModel(QObject *parent=nullptr); + AvatarListModel(bool autoCommit, QObject *parent=nullptr); int rowCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; @@ -45,6 +45,7 @@ public slots: QString filename; }; + bool m_autoCommit; QVector m_avatars; QStringList m_deletions; };