Add plain string filtering capability to SortFilterModel
Filtering only by regexps is not enough because as soon as filtering by special characters is needed, they can get interpreted as regexp special characters and stuff will break. Change-Id: Ic5cd0309e1e77d790faeecedbe87fdaaeceffc33 REVIEW: 122695
This commit is contained in:
parent
2cf49abb3e
commit
0230949b08
@ -104,6 +104,20 @@ QString SortFilterModel::filterRegExp() const
|
||||
return QSortFilterProxyModel::filterRegExp().pattern();
|
||||
}
|
||||
|
||||
void SortFilterModel::setFilterString(const QString &filterString)
|
||||
{
|
||||
if (filterString == m_filterString) {
|
||||
return;
|
||||
}
|
||||
QSortFilterProxyModel::setFilterFixedString(filterString);
|
||||
filterStringChanged(filterString);
|
||||
}
|
||||
|
||||
QString SortFilterModel::filterString() const
|
||||
{
|
||||
return m_filterString;
|
||||
}
|
||||
|
||||
void SortFilterModel::setFilterRole(const QString &role)
|
||||
{
|
||||
QSortFilterProxyModel::setFilterRole(roleNameToId(role));
|
||||
|
@ -51,6 +51,11 @@ class SortFilterModel : public QSortFilterProxyModel
|
||||
*/
|
||||
Q_PROPERTY(QString filterRegExp READ filterRegExp WRITE setFilterRegExp NOTIFY filterRegExpChanged)
|
||||
|
||||
/**
|
||||
* The string for the filter, only items with their filterRole matching filterString will be displayed
|
||||
*/
|
||||
Q_PROPERTY(QString filterString READ filterString WRITE setFilterString NOTIFY filterStringChanged)
|
||||
|
||||
/**
|
||||
* The role of the sourceModel on which filterRegExp must be applied.
|
||||
*/
|
||||
@ -82,6 +87,9 @@ public:
|
||||
void setFilterRegExp(const QString &exp);
|
||||
QString filterRegExp() const;
|
||||
|
||||
void setFilterString(const QString &filterString);
|
||||
QString filterString() const;
|
||||
|
||||
void setFilterRole(const QString &role);
|
||||
QString filterRole() const;
|
||||
|
||||
@ -112,6 +120,7 @@ Q_SIGNALS:
|
||||
void countChanged();
|
||||
void sourceModelChanged(QObject *);
|
||||
void filterRegExpChanged(const QString &);
|
||||
void filterStringChanged(const QString &);
|
||||
|
||||
protected:
|
||||
int roleNameToId(const QString &name);
|
||||
@ -122,6 +131,7 @@ protected Q_SLOTS:
|
||||
private:
|
||||
QString m_filterRole;
|
||||
QString m_sortRole;
|
||||
QString m_filterString;
|
||||
QHash<QString, int> m_roleIds;
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user