From 5f869b589fd07f6140c8f336c3782aba3ff09a25 Mon Sep 17 00:00:00 2001 From: ababi <albert.babi@savoirfairelinux.com> Date: Mon, 21 Sep 2020 18:36:56 +0200 Subject: [PATCH] misc: avoid using magic numbers - register SmartListModel - acces to AccountListModel and SmartListModel registered enumerations Change-Id: Idbc943a3b6a6f2989be7d20f5fe4259402a5adeb --- src/contactadapter.cpp | 4 ++-- src/conversationsadapter.cpp | 2 +- src/mainview/components/AccountComboBox.qml | 24 +++++++++---------- .../components/AccountComboBoxPopup.qml | 3 ++- .../components/ConversationSmartListView.qml | 2 +- src/qmlregister.cpp | 1 + src/smartlistmodel.cpp | 4 ++-- src/smartlistmodel.h | 5 ++-- 8 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/contactadapter.cpp b/src/contactadapter.cpp index fd7252b8a..eff294965 100644 --- a/src/contactadapter.cpp +++ b/src/contactadapter.cpp @@ -35,8 +35,8 @@ ContactAdapter::getContactSelectableModel(int type) * Called from qml every time contact picker refreshes. */ listModeltype_ = static_cast<SmartListModel::Type>(type); - smartListModel_.reset(new SmartListModel(LRCInstance::getCurrAccId(), - this, + smartListModel_.reset(new SmartListModel(this, + LRCInstance::getCurrAccId(), listModeltype_, LRCInstance::getCurrentConvUid())); selectableProxyModel_->setSourceModel(smartListModel_.get()); diff --git a/src/conversationsadapter.cpp b/src/conversationsadapter.cpp index 2dcedda88..3688345e0 100644 --- a/src/conversationsadapter.cpp +++ b/src/conversationsadapter.cpp @@ -35,7 +35,7 @@ ConversationsAdapter::ConversationsAdapter(QObject* parent) void ConversationsAdapter::safeInit() { - conversationSmartListModel_ = new SmartListModel(LRCInstance::getCurrAccId(), this); + conversationSmartListModel_ = new SmartListModel(this, LRCInstance::getCurrAccId()); emit modelChanged(QVariant::fromValue(conversationSmartListModel_)); diff --git a/src/mainview/components/AccountComboBox.qml b/src/mainview/components/AccountComboBox.qml index 54a7dc8ed..090be8ea3 100644 --- a/src/mainview/components/AccountComboBox.qml +++ b/src/mainview/components/AccountComboBox.qml @@ -42,11 +42,13 @@ ComboBox { function onModelReset() { userImageRoot.source = "data:image/png;base64," + accountListModel.data( - accountListModel.index(0, 0), 259) + accountListModel.index(0, 0), AccountListModel.Picture) currentAccountPresenseCycle.accountStatus = - accountListModel.data(accountListModel.index(0, 0), 261) - textMetricsUserAliasRoot.text = accountListModel.data(accountListModel.index(0,0), 257) - textMetricsUsernameRoot.text = accountListModel.data(accountListModel.index(0,0), 258) + accountListModel.data(accountListModel.index(0, 0), AccountListModel.Status) + textMetricsUserAliasRoot.text = accountListModel.data(accountListModel.index(0,0), + AccountListModel.Alias) + textMetricsUsernameRoot.text = accountListModel.data(accountListModel.index(0,0), + AccountListModel.Username) } } @@ -72,7 +74,7 @@ ComboBox { // Base 64 format source: "data:image/png;base64," + accountListModel.data( - accountListModel.index(0, 0), 259) + accountListModel.index(0, 0), AccountListModel.Picture) mipmap: true AccountPresenceCycle { @@ -83,7 +85,8 @@ ComboBox { anchors.bottom: userImageRoot.bottom anchors.bottomMargin: -2 - accountStatus: accountListModel.data(accountListModel.index(0, 0), 261) + accountStatus: accountListModel.data(accountListModel.index(0, 0), + AccountListModel.Status) } } @@ -133,8 +136,7 @@ ComboBox { elideWidth: root.width - userImageRoot.width - settingsButton.width - arrowDropDown.width - qrCodeGenerateButton.width - 55 - // Role::Alias - text: accountListModel.data(accountListModel.index(0,0), 257) + text: accountListModel.data(accountListModel.index(0,0), AccountListModel.Alias) } TextMetrics { @@ -145,10 +147,8 @@ ComboBox { elideWidth: root.width - userImageRoot.width - settingsButton.width - qrCodeGenerateButton.width - 55 - - - // Role::Username - text: accountListModel.data(accountListModel.index(0,0), 258) + text: accountListModel.data(accountListModel.index(0,0), + AccountListModel.Username) } HoverableButton { diff --git a/src/mainview/components/AccountComboBoxPopup.qml b/src/mainview/components/AccountComboBoxPopup.qml index e916e0011..27abb5322 100644 --- a/src/mainview/components/AccountComboBoxPopup.qml +++ b/src/mainview/components/AccountComboBoxPopup.qml @@ -68,7 +68,8 @@ Popup { // Role::Picture source: { - var data = accountListModel.data(accountListModel.index(index, 0), 259) + var data = accountListModel.data(accountListModel.index(index, 0), + AccountListModel.Picture) if (data === undefined) { return "" } diff --git a/src/mainview/components/ConversationSmartListView.qml b/src/mainview/components/ConversationSmartListView.qml index 189ab3176..165d7e47b 100644 --- a/src/mainview/components/ConversationSmartListView.qml +++ b/src/mainview/components/ConversationSmartListView.qml @@ -63,7 +63,7 @@ ListView { updateListView() for (var i = 0; i < count; i++) { if (root.model.data( - root.model.index(i, 0), 261) === uri) { + root.model.index(i, 0), SmartListModel.URI) === uri) { root.currentIndex = i break } diff --git a/src/qmlregister.cpp b/src/qmlregister.cpp index f4e46e175..29ef8019b 100644 --- a/src/qmlregister.cpp +++ b/src/qmlregister.cpp @@ -111,6 +111,7 @@ registerTypes() QML_REGISTERTYPE("net.jami.Models", VideoFormatResolutionModel, 1, 0); QML_REGISTERTYPE("net.jami.Models", VideoFormatFpsModel, 1, 0); QML_REGISTERTYPE("net.jami.Models", PluginListPreferenceModel, 1, 0); + QML_REGISTERTYPE("net.jami.Models", SmartListModel, 1, 0); /* * QQuickItems diff --git a/src/smartlistmodel.cpp b/src/smartlistmodel.cpp index 1e3d5964c..f863556a3 100644 --- a/src/smartlistmodel.cpp +++ b/src/smartlistmodel.cpp @@ -29,8 +29,8 @@ #include <QDateTime> -SmartListModel::SmartListModel(const QString& accId, - QObject* parent, +SmartListModel::SmartListModel(QObject* parent, + const QString& accId, SmartListModel::Type listModelType, const QString& convUid) : QAbstractListModel(parent) diff --git a/src/smartlistmodel.h b/src/smartlistmodel.h index 1c70bd4ff..4f47b44b1 100644 --- a/src/smartlistmodel.h +++ b/src/smartlistmodel.h @@ -60,9 +60,10 @@ public: AccountId, Draft }; + Q_ENUM(Role) - explicit SmartListModel(const QString& accId, - QObject* parent = 0, + explicit SmartListModel(QObject* parent = 0, + const QString& accId = {}, SmartListModel::Type listModelType = Type::CONVERSATION, const QString& convUid = {}); ~SmartListModel(); -- GitLab