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 <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2023-02-13 18:08:15 +01:00
parent 32ee1a962f
commit ad868daebe
No known key found for this signature in database
GPG Key ID: 7D0F74F05C22F553
4 changed files with 6 additions and 50 deletions

View File

@ -195,7 +195,7 @@ ColumnLayout {
enabled: !root.loading
model: SortedShareModel {
shareModel: root.shareModel
sourceModel: root.shareModel
}
delegate: ShareDelegate {

View File

@ -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<ShareModel*>(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

View File

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

View File

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