From ad868daebe9d2e81b6a5b8ce25997d1b6d8729f0 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Mon, 13 Feb 2023 18:08:15 +0100 Subject: [PATCH] remove custom property to set a source model in a sort proxy model custom property for source model is not needed remove code that is not needed Signed-off-by: Matthieu Gallien --- src/gui/filedetails/ShareView.qml | 2 +- src/gui/filedetails/sortedsharemodel.cpp | 35 +----------------------- src/gui/filedetails/sortedsharemodel.h | 11 -------- test/testsortedsharemodel.cpp | 8 +++--- 4 files changed, 6 insertions(+), 50 deletions(-) diff --git a/src/gui/filedetails/ShareView.qml b/src/gui/filedetails/ShareView.qml index a1c80bb0f..528936645 100644 --- a/src/gui/filedetails/ShareView.qml +++ b/src/gui/filedetails/ShareView.qml @@ -195,7 +195,7 @@ ColumnLayout { enabled: !root.loading model: SortedShareModel { - shareModel: root.shareModel + sourceModel: root.shareModel } delegate: ShareDelegate { diff --git a/src/gui/filedetails/sortedsharemodel.cpp b/src/gui/filedetails/sortedsharemodel.cpp index 4658060e1..9b9ef99a6 100644 --- a/src/gui/filedetails/sortedsharemodel.cpp +++ b/src/gui/filedetails/sortedsharemodel.cpp @@ -21,40 +21,7 @@ Q_LOGGING_CATEGORY(lcSortedShareModel, "com.nextcloud.sortedsharemodel") SortedShareModel::SortedShareModel(QObject *parent) : QSortFilterProxyModel(parent) { -} - -void SortedShareModel::sortModel() -{ - sort(0); -} - -ShareModel *SortedShareModel::shareModel() const -{ - return qobject_cast(sourceModel()); -} - -void SortedShareModel::setShareModel(ShareModel *shareModel) -{ - const auto currentSetModel = sourceModel(); - - if(currentSetModel) { - disconnect(currentSetModel, &ShareModel::rowsInserted, this, &SortedShareModel::sortModel); - disconnect(currentSetModel, &ShareModel::rowsMoved, this, &SortedShareModel::sortModel); - disconnect(currentSetModel, &ShareModel::rowsRemoved, this, &SortedShareModel::sortModel); - disconnect(currentSetModel, &ShareModel::dataChanged, this, &SortedShareModel::sortModel); - disconnect(currentSetModel, &ShareModel::modelReset, this, &SortedShareModel::sortModel); - } - - // Re-sort model when any changes take place - connect(shareModel, &ShareModel::rowsInserted, this, &SortedShareModel::sortModel); - connect(shareModel, &ShareModel::rowsMoved, this, &SortedShareModel::sortModel); - connect(shareModel, &ShareModel::rowsRemoved, this, &SortedShareModel::sortModel); - connect(shareModel, &ShareModel::dataChanged, this, &SortedShareModel::sortModel); - connect(shareModel, &ShareModel::modelReset, this, &SortedShareModel::sortModel); - - setSourceModel(shareModel); - sortModel(); - Q_EMIT shareModelChanged(); + sort(0, Qt::AscendingOrder); } bool SortedShareModel::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const diff --git a/src/gui/filedetails/sortedsharemodel.h b/src/gui/filedetails/sortedsharemodel.h index 9e9db90f5..413bb0e76 100644 --- a/src/gui/filedetails/sortedsharemodel.h +++ b/src/gui/filedetails/sortedsharemodel.h @@ -22,24 +22,13 @@ namespace OCC { class SortedShareModel : public QSortFilterProxyModel { Q_OBJECT - Q_PROPERTY(ShareModel* shareModel READ shareModel WRITE setShareModel NOTIFY shareModelChanged) public: explicit SortedShareModel(QObject *parent = nullptr); - [[nodiscard]] ShareModel *shareModel() const; - -signals: - void shareModelChanged(); - -public slots: - void setShareModel(OCC::ShareModel *shareModel); - protected: [[nodiscard]] bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override; -private slots: - void sortModel(); }; } // namespace OCC diff --git a/test/testsortedsharemodel.cpp b/test/testsortedsharemodel.cpp index 0f3a0dfe1..f35ab3922 100644 --- a/test/testsortedsharemodel.cpp +++ b/test/testsortedsharemodel.cpp @@ -151,13 +151,13 @@ private slots: SortedShareModel sortedModel; QAbstractItemModelTester sortedModelTester(&sortedModel); QSignalSpy sortedModelReset(&sortedModel, &SortedShareModel::modelReset); - QSignalSpy shareModelChanged(&sortedModel, &SortedShareModel::shareModelChanged); + QSignalSpy shareModelChanged(&sortedModel, &SortedShareModel::sourceModelChanged); - sortedModel.setShareModel(&model); + sortedModel.setSourceModel(&model); QCOMPARE(shareModelChanged.count(), 1); QCOMPARE(sortedModelReset.count(), 1); QCOMPARE(sortedModel.rowCount(), model.rowCount()); - QCOMPARE(sortedModel.shareModel(), &model); + QCOMPARE(sortedModel.sourceModel(), &model); } void testCorrectSort() @@ -177,7 +177,7 @@ private slots: QAbstractItemModelTester sortedModelTester(&sortedModel); QSignalSpy sortedModelReset(&sortedModel, &SortedShareModel::modelReset); - sortedModel.setShareModel(&model); + sortedModel.setSourceModel(&model); QCOMPARE(sortedModelReset.count(), 1); QCOMPARE(sortedModel.rowCount(), model.rowCount());