File indexing completed on 2024-04-14 04:53:18

0001 /*
0002     SPDX-FileCopyrightText: 2009 John Tapsell <tapsell@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef KSORTFILTERPROXYMODEL_H
0008 #define KSORTFILTERPROXYMODEL_H
0009 
0010 #include <QSortFilterProxyModel>
0011 
0012 /**
0013  * @class KSortFilterProxyModel
0014  *
0015  * This class extends QSortFilterProxyModel to allow filtering for a matching child
0016  * in a tree.
0017  * It can also show all the children of a matching parent, if setShowAllChildren is set.
0018  *
0019  * @author John Tapsell <tapsell@kde.org>
0020  * @since 4.4
0021  */
0022 class KSortFilterProxyModelPrivate;
0023 
0024 class KSortFilterProxyModel
0025     : public QSortFilterProxyModel
0026 {
0027     Q_OBJECT
0028 public:
0029     /*! Constructs a sorting filter model with the given parent. */
0030     KSortFilterProxyModel(QObject *parent = nullptr);
0031     /*! Destroys this sorting filter model. */
0032     ~KSortFilterProxyModel() override;
0033 
0034     /*! Whether to show the children of a matching parent.
0035      *  This is false by default. */
0036     bool showAllChildren() const;
0037     /*! Set whether to show the children of a matching parent.
0038      *  This is false by default. */
0039     void setShowAllChildren(bool showAllChildren);
0040 
0041 protected:
0042     /*! \reimp */
0043     bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
0044     KSortFilterProxyModelPrivate *const d_ptr;
0045 
0046     Q_DISABLE_COPY(KSortFilterProxyModel)
0047 };
0048 #endif