mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 15:06:08 +03:00
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 <matthieu.gallien@nextcloud.com>
This commit is contained in:
parent
9bbabd3baa
commit
32ee1a962f
4 changed files with 4 additions and 47 deletions
|
@ -54,7 +54,7 @@
|
|||
#include <QtDBus/QDBusInterface>
|
||||
#endif
|
||||
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QQmlEngine>
|
||||
#include <QQmlComponent>
|
||||
#include <QQmlApplicationEngine>
|
||||
|
@ -127,6 +127,7 @@ ownCloudGui::ownCloudGui(Application *parent)
|
|||
qmlRegisterType<ShareeModel>("com.nextcloud.desktopclient", 1, 0, "ShareeModel");
|
||||
qmlRegisterType<SortedShareModel>("com.nextcloud.desktopclient", 1, 0, "SortedShareModel");
|
||||
qmlRegisterType<SyncConflictsModel>("com.nextcloud.desktopclient", 1, 0, "SyncConflictsModel");
|
||||
qmlRegisterUncreatableType<QAbstractItemModel>("com.nextcloud.desktopclient", 1, 0, "QAbstractItemModel", "QAbstractItemModel");
|
||||
|
||||
qmlRegisterUncreatableType<UnifiedSearchResultsListModel>("com.nextcloud.desktopclient", 1, 0, "UnifiedSearchResultsListModel", "UnifiedSearchResultsListModel");
|
||||
qmlRegisterUncreatableType<UserStatus>("com.nextcloud.desktopclient", 1, 0, "UserStatus", "Access to Status enum");
|
||||
|
@ -134,7 +135,6 @@ ownCloudGui::ownCloudGui(Application *parent)
|
|||
|
||||
qRegisterMetaTypeStreamOperators<Emoji>();
|
||||
|
||||
qRegisterMetaType<ActivityListModel *>("ActivityListModel*");
|
||||
qRegisterMetaType<UnifiedSearchResultsListModel *>("UnifiedSearchResultsListModel*");
|
||||
qRegisterMetaType<UserStatus>("UserStatus");
|
||||
qRegisterMetaType<SharePtr>("SharePtr");
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -21,37 +21,7 @@ namespace OCC {
|
|||
SortedActivityListModel::SortedActivityListModel(QObject *parent)
|
||||
: QSortFilterProxyModel(parent)
|
||||
{
|
||||
}
|
||||
|
||||
void SortedActivityListModel::sortModel()
|
||||
{
|
||||
sort(0);
|
||||
}
|
||||
|
||||
ActivityListModel* SortedActivityListModel::activityListModel() const
|
||||
{
|
||||
return dynamic_cast<ActivityListModel*>(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
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue