Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 95c78c36 authored by Matthieu Gallien's avatar Matthieu Gallien

add a sort proxy model to keep view selector entries in alphabetic order

parent 0728a7ea
......@@ -33,6 +33,7 @@ set(elisaLib_SOURCES
models/editabletrackmetadatamodel.cpp
models/trackcontextmetadatamodel.cpp
models/viewsmodel.cpp
models/viewsproxymodel.cpp
viewslistdata.cpp
viewconfigurationdata.cpp
localFileConfiguration/elisaconfigurationdialog.cpp
......
......@@ -48,6 +48,7 @@
#include "models/trackcontextmetadatamodel.h"
#include "models/editabletrackmetadatamodel.h"
#include "models/viewsmodel.h"
#include "models/viewsproxymodel.h"
#include "models/gridviewproxymodel.h"
#include "localFileConfiguration/elisaconfigurationdialog.h"
......@@ -128,6 +129,7 @@ void ElisaQmlTestPlugin::registerTypes(const char *uri)
qmlRegisterType<TrackContextMetaDataModel>(uri, 1, 0, "TrackContextMetaDataModel");
qmlRegisterType<EditableTrackMetadataModel>(uri, 1, 0, "EditableTrackMetadataModel");
qmlRegisterType<ViewsModel>(uri, 1, 0, "ViewsModel");
qmlRegisterType<ViewsProxyModel>(uri, 1, 0, "ViewsProxyModel");
qmlRegisterType<ViewsListData>(uri, 1, 0, "ViewsListData");
qmlRegisterType<GridViewProxyModel>(uri, 1, 0, "GridViewProxyModel");
......
/*
SPDX-FileCopyrightText: 2020 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
SPDX-License-Identifier: LGPL-3.0-or-later
*/
#include "viewsproxymodel.h"
#include "viewsmodel.h"
ViewsProxyModel::ViewsProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
sort(0, Qt::AscendingOrder);
}
bool ViewsProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
{
if (source_right.data(ViewsModel::EntryCategoryRole).toString() == QStringLiteral("default")) {
switch (sortOrder())
{
case Qt::AscendingOrder:
return false;
case Qt::DescendingOrder:
return true;
}
}
if (source_left.data(ViewsModel::EntryCategoryRole).toString() == QStringLiteral("default")) {
switch (sortOrder())
{
case Qt::AscendingOrder:
return true;
case Qt::DescendingOrder:
return false;
}
}
return QSortFilterProxyModel::lessThan(source_left, source_right);
}
#include "moc_viewsproxymodel.cpp"
/*
SPDX-FileCopyrightText: 2020 (c) Matthieu Gallien <matthieu_gallien@yahoo.fr>
SPDX-License-Identifier: LGPL-3.0-or-later
*/
#ifndef VIEWSPROXYMODEL_H
#define VIEWSPROXYMODEL_H
#include "elisaLib_export.h"
#include <QSortFilterProxyModel>
class ELISALIB_EXPORT ViewsProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
ViewsProxyModel(QObject *parent = nullptr);
protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
};
#endif // VIEWSPROXYMODEL_H
......@@ -144,6 +144,12 @@ RowLayout {
viewsData: viewsData
}
ViewsProxyModel {
id: pageProxyModel
sourceModel: pageModel
}
ViewsListData {
id: viewsData
......@@ -155,7 +161,7 @@ RowLayout {
ViewSelector {
id: listViews
model: pageModel
model: pageProxyModel
Layout.fillHeight: true
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment