Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "rqt_multiplot/MatchFilterCompleterModel.h"
00020
00021 namespace rqt_multiplot {
00022
00023
00024
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
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
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 }