From 32ee1a962f816b7d6b072fa863b8fc7100e14fbc Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 13 Feb 2023 18:02:14 +0100 Subject: [PATCH] remove custom property and use standard sourceModel for our proxy model a QSortFilterProxyModel will trigger a new sort whenever needed, so custom code is not needed we might have someone that would use the standard property and loose teh side effects of setting the source model via thet non standard property this makes it more complicated to read as one might wonder why a custom property was needed deletes a bunch of code not really needed Signed-off-by: Matthieu Gallien --- src/gui/owncloudgui.cpp | 4 +-- src/gui/tray/ActivityList.qml | 3 +-- src/gui/tray/sortedactivitylistmodel.cpp | 32 +----------------------- src/gui/tray/sortedactivitylistmodel.h | 12 --------- 4 files changed, 4 insertions(+), 47 deletions(-) diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index 45215d53e..713fca59f 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -54,7 +54,7 @@ #include #endif - +#include #include #include #include @@ -127,6 +127,7 @@ ownCloudGui::ownCloudGui(Application *parent) qmlRegisterType("com.nextcloud.desktopclient", 1, 0, "ShareeModel"); qmlRegisterType("com.nextcloud.desktopclient", 1, 0, "SortedShareModel"); qmlRegisterType("com.nextcloud.desktopclient", 1, 0, "SyncConflictsModel"); + qmlRegisterUncreatableType("com.nextcloud.desktopclient", 1, 0, "QAbstractItemModel", "QAbstractItemModel"); qmlRegisterUncreatableType("com.nextcloud.desktopclient", 1, 0, "UnifiedSearchResultsListModel", "UnifiedSearchResultsListModel"); qmlRegisterUncreatableType("com.nextcloud.desktopclient", 1, 0, "UserStatus", "Access to Status enum"); @@ -134,7 +135,6 @@ ownCloudGui::ownCloudGui(Application *parent) qRegisterMetaTypeStreamOperators(); - qRegisterMetaType("ActivityListModel*"); qRegisterMetaType("UnifiedSearchResultsListModel*"); qRegisterMetaType("UserStatus"); qRegisterMetaType("SharePtr"); diff --git a/src/gui/tray/ActivityList.qml b/src/gui/tray/ActivityList.qml index 0f690ca27..168afaaba 100644 --- a/src/gui/tray/ActivityList.qml +++ b/src/gui/tray/ActivityList.qml @@ -6,8 +6,8 @@ import com.nextcloud.desktopclient 1.0 as NC ScrollView { id: controlRoot - property alias model: sortedActivityList.activityListModel + property alias model: sortedActivityList.sourceModel property bool isFileActivityList: false property int iconSize: Style.trayListItemIconSize property int delegateHorizontalPadding: 0 @@ -53,7 +53,6 @@ ScrollView { model: NC.SortedActivityListModel { id: sortedActivityList - activityListModel: controlRoot.model } delegate: ActivityItem { diff --git a/src/gui/tray/sortedactivitylistmodel.cpp b/src/gui/tray/sortedactivitylistmodel.cpp index 4879143f2..3dced0982 100644 --- a/src/gui/tray/sortedactivitylistmodel.cpp +++ b/src/gui/tray/sortedactivitylistmodel.cpp @@ -21,37 +21,7 @@ namespace OCC { SortedActivityListModel::SortedActivityListModel(QObject *parent) : QSortFilterProxyModel(parent) { -} - -void SortedActivityListModel::sortModel() -{ - sort(0); -} - -ActivityListModel* SortedActivityListModel::activityListModel() const -{ - return dynamic_cast(sourceModel()); -} - -void SortedActivityListModel::setActivityListModel(ActivityListModel* activityListModel) -{ - if(const auto currentSetModel = sourceModel()) { - disconnect(currentSetModel, &ActivityListModel::rowsInserted, this, &SortedActivityListModel::sortModel); - disconnect(currentSetModel, &ActivityListModel::rowsMoved, this, &SortedActivityListModel::sortModel); - disconnect(currentSetModel, &ActivityListModel::rowsRemoved, this, &SortedActivityListModel::sortModel); - disconnect(currentSetModel, &ActivityListModel::dataChanged, this, &SortedActivityListModel::sortModel); - disconnect(currentSetModel, &ActivityListModel::modelReset, this, &SortedActivityListModel::sortModel); - } - - // Re-sort model when any changes take place - connect(activityListModel, &ActivityListModel::rowsInserted, this, &SortedActivityListModel::sortModel); - connect(activityListModel, &ActivityListModel::rowsMoved, this, &SortedActivityListModel::sortModel); - connect(activityListModel, &ActivityListModel::rowsRemoved, this, &SortedActivityListModel::sortModel); - connect(activityListModel, &ActivityListModel::dataChanged, this, &SortedActivityListModel::sortModel); - connect(activityListModel, &ActivityListModel::modelReset, this, &SortedActivityListModel::sortModel); - - setSourceModel(activityListModel); - Q_EMIT activityListModelChanged(); + sort(0, Qt::AscendingOrder); } bool SortedActivityListModel::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const diff --git a/src/gui/tray/sortedactivitylistmodel.h b/src/gui/tray/sortedactivitylistmodel.h index d3e8219c1..faf490d43 100644 --- a/src/gui/tray/sortedactivitylistmodel.h +++ b/src/gui/tray/sortedactivitylistmodel.h @@ -23,24 +23,12 @@ class ActivityListModel; class SortedActivityListModel : public QSortFilterProxyModel { Q_OBJECT - Q_PROPERTY(ActivityListModel* activityListModel READ activityListModel WRITE setActivityListModel NOTIFY activityListModelChanged) public: explicit SortedActivityListModel(QObject *parent = nullptr); - [[nodiscard]] ActivityListModel *activityListModel() const; - -signals: - void activityListModelChanged(); - -public slots: - void setActivityListModel(OCC::ActivityListModel *activityListModel); - protected: [[nodiscard]] bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override; - -private slots: - void sortModel(); }; }