File indexing completed on 2023-09-24 09:41:13
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 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0032 Q_PROPERTY(QString filterRegExp READ filterRegExp WRITE setFilterRegExp NOTIFY filterRegExpChanged) 0033 #else 0034 Q_PROPERTY(QString filterRegExp READ filterRegularExpression WRITE setFilterRegularExpression NOTIFY filterRegularExpressionChanged) 0035 #endif 0036 0037 public: 0038 /** 0039 * Constructs a MenuProxyModel with the specified parent. 0040 * 0041 * @param parent The QObject to use as a parent. 0042 */ 0043 MenuProxyModel(QObject *parent = nullptr); 0044 0045 QHash<int, QByteArray> roleNames() const override; 0046 0047 /** 0048 * Please see the Qt QSortFilterProxyModel documentation for further information.\n 0049 * Provides information on whether or not the QModelIndex specified by left is below right. 0050 * 0051 * @param left the QModelIndex that is being used for comparing. 0052 * @param right the QModelIndex to compare against. 0053 * @returns true if the left is below the right. 0054 */ 0055 bool lessThan(const QModelIndex &left, const QModelIndex &right) const override; 0056 0057 /** 0058 * Please see the KDE KCategorizedSortFilterProxyModel documentation for further information.\n 0059 * Provides information on whether or not the QModelIndex specified by left is below right. 0060 * 0061 * @param left the QModelIndex that is being used for comparing. 0062 * @param right the QModelIndex to compare against. 0063 * @returns true if the left is below the right. 0064 */ 0065 bool subSortLessThan(const QModelIndex &left, const QModelIndex &right) const override; 0066 0067 /** 0068 * Please see the Qt QSortFilterProxyModel documentation for further information.\n 0069 * Provides additional filtering of the MenuModel to only show categories which contain modules. 0070 * 0071 * @param source_column Please see QSortFilterProxyModel documentation. 0072 * @param source_parent Please see QSortFilterProxyModel documentation. 0073 * @returns true if the row should be displayed, false if it should not. 0074 */ 0075 bool filterAcceptsRow(int source_column, const QModelIndex &source_parent) const override; 0076 0077 /** 0078 * Please see Qt QAbstractItemModel documentation for more details.\n 0079 * Provides the status flags for the QModelIndex specified. 0080 * The item will be selectable and enabled for its status unless invalid or filtered by search terms. 0081 * 0082 * @returns The flags for the QModelIndex provided. 0083 */ 0084 Qt::ItemFlags flags(const QModelIndex &index) const override; 0085 0086 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0087 /** 0088 * Please see Qt QAbstractItemModel documentation for more details.\n 0089 * Reimplemented for internal reasons. 0090 */ 0091 void setFilterRegExp(const QRegExp ®Exp); 0092 0093 /** 0094 * Please see Qt QAbstractItemModel documentation for more details.\n 0095 * Reimplemented for internal reasons. 0096 */ 0097 void setFilterRegExp(const QString &pattern); 0098 0099 QString filterRegExp() const; 0100 #else 0101 /** 0102 * Please see Qt QAbstractItemModel documentation for more details.\n 0103 * Reimplemented for internal reasons. 0104 */ 0105 void setFilterRegularExpression(const QRegularExpression ®Exp); 0106 0107 /** 0108 * Please see Qt QAbstractItemModel documentation for more details.\n 0109 * Reimplemented for internal reasons. 0110 */ 0111 void setFilterRegularExpression(const QString &pattern); 0112 0113 QString filterRegularExpression() const; 0114 #endif 0115 0116 /** 0117 * makes the filter highlight matching entries instead of hiding them 0118 */ 0119 void setFilterHighlightsEntries(bool highlight); 0120 0121 /** 0122 * @returns the filter highlight matching entries instead of hiding them, default true 0123 */ 0124 bool filterHighlightsEntries() const; 0125 0126 Q_SIGNALS: 0127 #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) 0128 void filterRegExpChanged(); 0129 #else 0130 void filterRegularExpressionChanged(); 0131 #endif 0132 0133 private: 0134 bool m_filterHighlightsEntries : 1; 0135 }; 0136 0137 #endif