File indexing completed on 2024-12-08 07:33:46

0001 // SPDX-FileCopyrightText: 2022 Snehit Sah <hi@snehit.dev>
0002 // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
0003 
0004 #pragma once
0005 
0006 #include <QQmlEngine>
0007 #include <QSortFilterProxyModel>
0008 
0009 /**
0010  * @class SortFilterSpaceListModel
0011  *
0012  * This model sorts and filters the space list.
0013  *
0014  * The spaces are sorted by their matrix ID. The filter only shows space rooms,
0015  * but filters out upgraded spaces.
0016  */
0017 class SortFilterSpaceListModel : public QSortFilterProxyModel
0018 {
0019     Q_OBJECT
0020     QML_ELEMENT
0021 
0022     /**
0023      * @brief The number of spaces in the model.
0024      */
0025     Q_PROPERTY(int count READ rowCount NOTIFY countChanged)
0026 
0027 public:
0028     explicit SortFilterSpaceListModel(QObject *parent = nullptr);
0029 
0030 Q_SIGNALS:
0031     void countChanged();
0032 
0033 protected:
0034     /**
0035      * @brief Returns true if the value of source_left is less than source_right.
0036      *
0037      * @sa QSortFilterProxyModel::lessThan
0038      */
0039     [[nodiscard]] bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
0040 
0041     /**
0042      * @brief Whether a row should be shown out or not.
0043      *
0044      * @sa QSortFilterProxyModel::filterAcceptsRow
0045      */
0046     [[nodiscard]] bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0047 };