mirror of https://github.com/nextcloud/desktop
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:
parent
32ee1a962f
commit
ad868daebe
|
@ -195,7 +195,7 @@ ColumnLayout {
|
||||||
|
|
||||||
enabled: !root.loading
|
enabled: !root.loading
|
||||||
model: SortedShareModel {
|
model: SortedShareModel {
|
||||||
shareModel: root.shareModel
|
sourceModel: root.shareModel
|
||||||
}
|
}
|
||||||
|
|
||||||
delegate: ShareDelegate {
|
delegate: ShareDelegate {
|
||||||
|
|
|
@ -21,40 +21,7 @@ Q_LOGGING_CATEGORY(lcSortedShareModel, "com.nextcloud.sortedsharemodel")
|
||||||
SortedShareModel::SortedShareModel(QObject *parent)
|
SortedShareModel::SortedShareModel(QObject *parent)
|
||||||
: QSortFilterProxyModel(parent)
|
: QSortFilterProxyModel(parent)
|
||||||
{
|
{
|
||||||
}
|
sort(0, Qt::AscendingOrder);
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SortedShareModel::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const
|
bool SortedShareModel::lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const
|
||||||
|
|
|
@ -22,24 +22,13 @@ namespace OCC {
|
||||||
class SortedShareModel : public QSortFilterProxyModel
|
class SortedShareModel : public QSortFilterProxyModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(ShareModel* shareModel READ shareModel WRITE setShareModel NOTIFY shareModelChanged)
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SortedShareModel(QObject *parent = nullptr);
|
explicit SortedShareModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
[[nodiscard]] ShareModel *shareModel() const;
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void shareModelChanged();
|
|
||||||
|
|
||||||
public slots:
|
|
||||||
void setShareModel(OCC::ShareModel *shareModel);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
[[nodiscard]] bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
|
[[nodiscard]] bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
|
||||||
|
|
||||||
private slots:
|
|
||||||
void sortModel();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace OCC
|
} // namespace OCC
|
||||||
|
|
|
@ -151,13 +151,13 @@ private slots:
|
||||||
SortedShareModel sortedModel;
|
SortedShareModel sortedModel;
|
||||||
QAbstractItemModelTester sortedModelTester(&sortedModel);
|
QAbstractItemModelTester sortedModelTester(&sortedModel);
|
||||||
QSignalSpy sortedModelReset(&sortedModel, &SortedShareModel::modelReset);
|
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(shareModelChanged.count(), 1);
|
||||||
QCOMPARE(sortedModelReset.count(), 1);
|
QCOMPARE(sortedModelReset.count(), 1);
|
||||||
QCOMPARE(sortedModel.rowCount(), model.rowCount());
|
QCOMPARE(sortedModel.rowCount(), model.rowCount());
|
||||||
QCOMPARE(sortedModel.shareModel(), &model);
|
QCOMPARE(sortedModel.sourceModel(), &model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void testCorrectSort()
|
void testCorrectSort()
|
||||||
|
@ -177,7 +177,7 @@ private slots:
|
||||||
QAbstractItemModelTester sortedModelTester(&sortedModel);
|
QAbstractItemModelTester sortedModelTester(&sortedModel);
|
||||||
QSignalSpy sortedModelReset(&sortedModel, &SortedShareModel::modelReset);
|
QSignalSpy sortedModelReset(&sortedModel, &SortedShareModel::modelReset);
|
||||||
|
|
||||||
sortedModel.setShareModel(&model);
|
sortedModel.setSourceModel(&model);
|
||||||
QCOMPARE(sortedModelReset.count(), 1);
|
QCOMPARE(sortedModelReset.count(), 1);
|
||||||
QCOMPARE(sortedModel.rowCount(), model.rowCount());
|
QCOMPARE(sortedModel.rowCount(), model.rowCount());
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue