File indexing completed on 2024-05-19 09:32:18

0001 /*
0002  * SPDX-FileCopyrightText: 2009 Ben Cooksley <bcooksley@kde.org>
0003  * SPDX-FileCopyrightText: 2007 Will Stephenson <wstephenson@kde.org>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #ifndef MENUPROXYMODEL_H
0009 #define MENUPROXYMODEL_H
0010 
0011 #include <KCategorizedSortFilterProxyModel>
0012 
0013 #include "systemsettingsview_export.h"
0014 
0015 /**
0016  * @brief Provides a filter model for MenuModel
0017  *
0018  * Provides a standardised model to be used with views to filter a MenuModel.\n
0019  * It automatically sorts the items appropriately depending on if it is categorised
0020  * or not.
0021  * Call setFilterRegExp(QString) with the desired text to filter to perform searching.
0022  * Items that do not match the search parameters will be disabled, not hidden.
0023  *
0024  * @author Will Stephenson <wstephenson@kde.org>
0025  * @author Ben Cooksley <bcooksley@kde.org>
0026  */
0027 class SYSTEMSETTINGSVIEW_EXPORT MenuProxyModel : public KCategorizedSortFilterProxyModel
0028 {
0029     Q_OBJECT
0030 
0031     Q_PROPERTY(QString filterRegExp READ filterRegularExpression WRITE setFilterRegularExpression NOTIFY filterRegularExpressionChanged)
0032 
0033 public:
0034     /**
0035      * Constructs a MenuProxyModel with the specified parent.
0036      *
0037      * @param parent The QObject to use as a parent.
0038      */
0039     MenuProxyModel(QObject *parent = nullptr);
0040 
0041     QHash<int, QByteArray> roleNames() const override;
0042 
0043     /**
0044      * Please see the Qt QSortFilterProxyModel documentation for further information.\n
0045      * Provides information on whether or not the QModelIndex specified by left is below right.
0046      *
0047      * @param left the QModelIndex that is being used for comparing.
0048      * @param right the QModelIndex to compare against.
0049      * @returns true if the left is below the right.
0050      */
0051     bool lessThan(const QModelIndex &left, const QModelIndex &right) const override;
0052 
0053     /**
0054      * Please see the KDE KCategorizedSortFilterProxyModel documentation for further information.\n
0055      * Provides information on whether or not the QModelIndex specified by left is below right.
0056      *
0057      * @param left the QModelIndex that is being used for comparing.
0058      * @param right the QModelIndex to compare against.
0059      * @returns true if the left is below the right.
0060      */
0061     bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override;
0062 
0063     /**
0064      * Please see the Qt QSortFilterProxyModel documentation for further information.\n
0065      * Provides additional filtering of the MenuModel to only show categories which contain modules.
0066      *
0067      * @param source_column Please see QSortFilterProxyModel documentation.
0068      * @param source_parent Please see QSortFilterProxyModel documentation.
0069      * @returns true if the row should be displayed, false if it should not.
0070      */
0071     bool filterAcceptsRow(int source_column, const QModelIndex &source_parent) const override;
0072 
0073     /**
0074      * Please see Qt QAbstractItemModel documentation for more details.\n
0075      * Provides the status flags for the QModelIndex specified.
0076      * The item will be selectable and enabled for its status unless invalid or filtered by search terms.
0077      *
0078      * @returns The flags for the QModelIndex provided.
0079      */
0080     Qt::ItemFlags flags(const QModelIndex &index) const override;
0081 
0082     /**
0083      * Please see Qt QAbstractItemModel documentation for more details.\n
0084      * Reimplemented for internal reasons.
0085      */
0086     void setFilterRegularExpression(const QRegularExpression &regExp);
0087 
0088     /**
0089      * Please see Qt QAbstractItemModel documentation for more details.\n
0090      * Reimplemented for internal reasons.
0091      */
0092     void setFilterRegularExpression(const QString &pattern);
0093 
0094     QString filterRegularExpression() const;
0095 
0096     /**
0097      * makes the filter highlight matching entries instead of hiding them
0098      */
0099     void setFilterHighlightsEntries(bool highlight);
0100 
0101     /**
0102      * @returns the filter highlight matching entries instead of hiding them, default true
0103      */
0104     bool filterHighlightsEntries() const;
0105 
0106 Q_SIGNALS:
0107     void filterRegularExpressionChanged();
0108 
0109 private:
0110     bool m_filterHighlightsEntries : 1;
0111 };
0112 
0113 #endif