MatchFilterCompleterModel.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
28  Qt::MatchFlags filterMatchFlags, const QString& filterKey) :
29  QSortFilterProxyModel(parent),
30  filterMatchFlags_(filterMatchFlags),
31  filterKey_(filterKey) {
32 }
33 
35 }
36 
37 /*****************************************************************************/
38 /* Accessors */
39 /*****************************************************************************/
40 
42  if (flags != filterMatchFlags_) {
43  filterMatchFlags_ = flags;
44 
45  filterChanged();
46  }
47 }
48 
50  return filterMatchFlags_;
51 }
52 
53 void MatchFilterCompleterModel::setFilterKey(const QString& key) {
54  if (key != filterKey_) {
55  filterKey_ = key;
56 
57  filterChanged();
58  }
59 }
60 
62  return filterKey_;
63 }
64 
65 /*****************************************************************************/
66 /* Methods */
67 /*****************************************************************************/
68 
70  QModelIndex& sourceParent) const {
71  if (filterMatchFlags_ & Qt::MatchRegExp)
72  return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
73 
74  if (filterKeyColumn() == -1)
75  return true;
76 
77  QModelIndex sourceIndex = sourceModel()->index(sourceRow, filterKeyColumn(),
78  sourceParent);
79 
80  if (!sourceIndex.isValid())
81  return true;
82 
83  QString key = sourceModel()->data(sourceIndex, filterRole()).toString();
84 
85  if (filterMatchFlags_ & Qt::MatchContains)
86  return key.contains(filterKey_, filterCaseSensitivity());
87  else if (filterMatchFlags_ & Qt::MatchStartsWith)
88  return key.startsWith(filterKey_, filterCaseSensitivity());
89  else if (filterMatchFlags_ & Qt::MatchEndsWith)
90  return key.endsWith(filterKey_, filterCaseSensitivity());
91  else
92  return true;
93 }
94 
95 }
MatchFilterCompleterModel(QObject *parent=0, Qt::MatchFlags filterMatchFlags=Qt::MatchStartsWith, const QString &filterKey=QString())
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44