File indexing completed on 2024-05-05 05:47:27
0001 /* 0002 This file is part of Massif Visualizer 0003 0004 Copyright 2010 Milian Wolff <mail@milianw.de> 0005 0006 This library is free software; you can redistribute it and/or 0007 modify it under the terms of the GNU Lesser General Public 0008 License as published by the Free Software Foundation; either 0009 version 2.1 of the License, or (at your option) version 3, or any 0010 later version accepted by the membership of KDE e.V. (or its 0011 successor approved by the membership of KDE e.V.), which shall 0012 act as a proxy defined in Section 6 of version 3 of the license. 0013 0014 This library is distributed in the hope that it will be useful, 0015 but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0017 Lesser General Public License for more details. 0018 0019 You should have received a copy of the GNU Lesser General Public 0020 License along with this library. If not, see <http://www.gnu.org/licenses/>. 0021 */ 0022 0023 #ifndef MASSIF_FILTEREDDATATREEMODEL_H 0024 #define MASSIF_FILTEREDDATATREEMODEL_H 0025 0026 #include <QSortFilterProxyModel> 0027 #include <QTimer> 0028 0029 namespace Massif { 0030 0031 class DataTreeModel; 0032 0033 /** 0034 * Filter class for DataTreeModel 0035 */ 0036 class FilteredDataTreeModel : public QSortFilterProxyModel 0037 { 0038 Q_OBJECT 0039 0040 public: 0041 explicit FilteredDataTreeModel(DataTreeModel* parent); 0042 0043 public Q_SLOTS: 0044 void setFilter(const QString& needle); 0045 0046 protected: 0047 /// true for any branch that has an item in it that matches m_needle 0048 bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const override; 0049 /// always true 0050 bool filterAcceptsColumn(int source_column, const QModelIndex& source_parent) const override; 0051 0052 private Q_SLOTS: 0053 void timeout(); 0054 0055 private: 0056 /// we don't want that 0057 void setSourceModel(QAbstractItemModel* sourceModel) override; 0058 0059 /// search string that should be contained in the data (case insensitively) 0060 QString m_needle; 0061 QTimer m_timer; 0062 }; 0063 0064 } 0065 0066 #endif // MASSIF_FILTEREDDATATREEMODEL_H