File indexing completed on 2025-03-02 04:17:41

0001 /*
0002  * Copyright (C) 2016 Dan Leinir Turthra Jensen <admin@leinir.dk>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Lesser General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2.1 of the License, or (at your option) version 3, or any
0008  * later version accepted by the membership of KDE e.V. (or its
0009  * successor approved by the membership of KDE e.V.), which shall
0010  * act as a proxy defined in Section 6 of version 3 of the license.
0011  *
0012  * This library is distributed in the hope that it will be useful,
0013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015  * Lesser General Public License for more details.
0016  *
0017  * You should have received a copy of the GNU Lesser General Public
0018  * License along with this library.  If not, see <http://www.gnu.org/licenses/>.
0019  *
0020  */
0021 
0022 #ifndef FILTERPROXY_H
0023 #define FILTERPROXY_H
0024 
0025 #include <QSortFilterProxyModel>
0026 
0027 #include <memory>
0028 /**
0029  * \brief a Filter proxy for handling search with.
0030  * 
0031  * Extends QSortFilterProxyModel, is caseInsensitive.
0032  */
0033 class FilterProxy : public QSortFilterProxyModel
0034 {
0035     Q_OBJECT
0036     Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
0037     Q_PROPERTY(bool filterBoolean READ filterBoolean WRITE setFilterBoolean NOTIFY filterBooleanChanged)
0038     Q_PROPERTY(int filterInt READ filterInt WRITE setFilterInt NOTIFY filterIntChanged)
0039     /**
0040      * If you for some reason need to toggle the filter off, you can turn the integer filtering off
0041      * by toggling this to false. Setting the filterInt property will set this to true.
0042      */
0043     Q_PROPERTY(bool filterIntEnabled READ filterIntEnabled WRITE setFilterIntEnabled NOTIFY filterIntEnabledChanged)
0044     Q_PROPERTY(int count READ count NOTIFY countChanged)
0045 public:
0046     explicit FilterProxy(QObject* parent = nullptr);
0047     ~FilterProxy() override;
0048 
0049     void setFilterString(const QString &string);
0050     QString filterString() const;
0051     Q_SIGNAL void filterStringChanged();
0052 
0053     void setFilterBoolean(const bool &value);
0054     bool filterBoolean() const;
0055     Q_SIGNAL void filterBooleanChanged();
0056 
0057     void setFilterInt(const int &value);
0058     int filterInt() const;
0059     Q_SIGNAL void filterIntChanged();
0060 
0061     void setFilterIntEnabled(const bool &value);
0062     bool filterIntEnabled() const;
0063     Q_SIGNAL void filterIntEnabledChanged();
0064 
0065     int count() const;
0066     Q_SIGNAL void countChanged();
0067 
0068     Q_INVOKABLE int sourceIndex(const int &filterIndex);
0069 protected:
0070     bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
0071 
0072 private:
0073     class Private;
0074     std::unique_ptr<Private> d;
0075 };
0076 
0077 #endif//FILTERPROXY_H