MatchFilterCompleterModel.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include "rqt_multiplot/MatchFilterCompleterModel.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 MatchFilterCompleterModel::MatchFilterCompleterModel(QObject* parent,
00028     Qt::MatchFlags filterMatchFlags, const QString& filterKey) :
00029   QSortFilterProxyModel(parent),
00030   filterMatchFlags_(filterMatchFlags),
00031   filterKey_(filterKey) {
00032 }
00033 
00034 MatchFilterCompleterModel::~MatchFilterCompleterModel() {
00035 }
00036 
00037 /*****************************************************************************/
00038 /* Accessors                                                                 */
00039 /*****************************************************************************/
00040 
00041 void MatchFilterCompleterModel::setFilterMatchFlags(Qt::MatchFlags flags) {
00042   if (flags != filterMatchFlags_) {
00043     filterMatchFlags_ = flags;
00044     
00045     filterChanged();
00046   }
00047 }
00048 
00049 Qt::MatchFlags MatchFilterCompleterModel::getFilterMatchFlags() const {
00050   return filterMatchFlags_;
00051 }
00052 
00053 void MatchFilterCompleterModel::setFilterKey(const QString& key) {
00054   if (key != filterKey_) {
00055     filterKey_ = key;
00056     
00057     filterChanged();
00058   }
00059 }
00060 
00061 const QString& MatchFilterCompleterModel::getFilterKey() const {
00062   return filterKey_;
00063 }
00064 
00065 /*****************************************************************************/
00066 /* Methods                                                                   */
00067 /*****************************************************************************/
00068 
00069 bool MatchFilterCompleterModel::filterAcceptsRow(int sourceRow, const
00070     QModelIndex& sourceParent) const {
00071   if (filterMatchFlags_ & Qt::MatchRegExp)
00072     return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
00073       
00074   if (filterKeyColumn() == -1)
00075     return true;
00076   
00077   QModelIndex sourceIndex = sourceModel()->index(sourceRow, filterKeyColumn(),
00078     sourceParent);
00079   
00080   if (!sourceIndex.isValid())
00081     return true;
00082   
00083   QString key = sourceModel()->data(sourceIndex, filterRole()).toString();  
00084   
00085   if (filterMatchFlags_ & Qt::MatchContains)
00086     return key.contains(filterKey_, filterCaseSensitivity());
00087   else if (filterMatchFlags_ & Qt::MatchStartsWith)
00088     return key.startsWith(filterKey_, filterCaseSensitivity());
00089   else if (filterMatchFlags_ & Qt::MatchEndsWith)
00090     return key.endsWith(filterKey_, filterCaseSensitivity());
00091   else
00092     return true;
00093 }
00094 
00095 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:11