File indexing completed on 2024-05-12 04:42:08

0001 /*
0002     SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org>
0003     SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 #ifndef KOSMINDOORMAP_AMENITYSORTFILTERMODEL_H
0007 #define KOSMINDOORMAP_AMENITYSORTFILTERMODEL_H
0008 
0009 #include <QCollator>
0010 #include <QSortFilterProxyModel>
0011 
0012 namespace KOSMIndoorMap {
0013 
0014 /** Filtering/sorting on top of the AmenityModel.
0015  *  - filters on all visible roles
0016  *  - sorts while keeping the grouping intact
0017  */
0018 class AmenitySortFilterProxyModel : public QSortFilterProxyModel
0019 {
0020     Q_OBJECT
0021     Q_PROPERTY(QString filterString MEMBER m_filter NOTIFY filterStringChanged)
0022 
0023 public:
0024     explicit AmenitySortFilterProxyModel(QObject *parent = nullptr);
0025     ~AmenitySortFilterProxyModel();
0026 
0027 Q_SIGNALS:
0028     void filterStringChanged();
0029 
0030 protected:
0031     [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0032     [[nodiscard]] bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
0033 
0034 private:
0035     bool filterMatches(const QString &s) const;
0036 
0037     QCollator m_collator;
0038     QString m_filter;
0039 };
0040 
0041 }
0042 
0043 #endif