Remove QRegExp support from QSortFilterProxyModel
Map setFilterWildcard() and setFilterFixedString() to now use QRegularExpression. Change-Id: I2dff2015234decb2badfd306975dcff8553cdd7f Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
This commit is contained in:
parent
48794f5057
commit
eb349930ee
@ -94,8 +94,7 @@ Widget::Widget(QWidget *parent)
|
||||
//! [4]
|
||||
proxyModel->sort(2, Qt::AscendingOrder);
|
||||
//! [4] //! [5]
|
||||
proxyModel->setFilterRegExp(QRegExp(".png", Qt::CaseInsensitive,
|
||||
QRegExp::FixedString));
|
||||
proxyModel->setFilterRegularExpression(QRegularExpression("\.png", QRegularExpression::CaseInsensitiveOption));
|
||||
proxyModel->setFilterKeyColumn(1);
|
||||
//! [5]
|
||||
}
|
||||
|
@ -142,133 +142,6 @@ private:
|
||||
int end;
|
||||
};
|
||||
|
||||
class RegularExpressionData {
|
||||
|
||||
private:
|
||||
enum class ExpressionType {
|
||||
RegExp,
|
||||
#if QT_CONFIG(regularexpression)
|
||||
RegularExpression
|
||||
#endif
|
||||
};
|
||||
|
||||
public:
|
||||
RegularExpressionData() :
|
||||
m_type(ExpressionType::RegExp)
|
||||
{}
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
QRegularExpression regularExpression() const
|
||||
{
|
||||
if (m_type == ExpressionType::RegularExpression)
|
||||
return m_regularExpression;
|
||||
return QRegularExpression();
|
||||
}
|
||||
|
||||
void setRegularExpression(const QRegularExpression &rx)
|
||||
{
|
||||
m_type = ExpressionType::RegularExpression;
|
||||
m_regularExpression = rx;
|
||||
m_regExp = QRegExp();
|
||||
}
|
||||
#endif
|
||||
|
||||
QRegExp regExp() const
|
||||
{
|
||||
if (m_type == ExpressionType::RegExp)
|
||||
return m_regExp;
|
||||
return QRegExp();
|
||||
}
|
||||
|
||||
void setRegExp(const QRegExp &rx)
|
||||
{
|
||||
m_type = ExpressionType::RegExp;
|
||||
m_regExp = rx;
|
||||
#if QT_CONFIG(regularexpression)
|
||||
m_regularExpression = QRegularExpression();
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
{
|
||||
bool result = true;
|
||||
switch (m_type) {
|
||||
case ExpressionType::RegExp:
|
||||
result = m_regExp.isEmpty();
|
||||
break;
|
||||
#if QT_CONFIG(regularexpression)
|
||||
case ExpressionType::RegularExpression:
|
||||
result = m_regularExpression.pattern().isEmpty();
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Qt::CaseSensitivity caseSensitivity() const
|
||||
{
|
||||
Qt::CaseSensitivity sensitivity = Qt::CaseInsensitive;
|
||||
switch (m_type) {
|
||||
case ExpressionType::RegExp:
|
||||
sensitivity = m_regExp.caseSensitivity();
|
||||
break;
|
||||
#if QT_CONFIG(regularexpression)
|
||||
case ExpressionType::RegularExpression:
|
||||
{
|
||||
QRegularExpression::PatternOptions options = m_regularExpression.patternOptions();
|
||||
if (!(options & QRegularExpression::CaseInsensitiveOption))
|
||||
sensitivity = Qt::CaseSensitive;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return sensitivity;
|
||||
}
|
||||
|
||||
void setCaseSensitivity(Qt::CaseSensitivity cs)
|
||||
{
|
||||
switch (m_type) {
|
||||
case ExpressionType::RegExp:
|
||||
m_regExp.setCaseSensitivity(cs);
|
||||
break;
|
||||
#if QT_CONFIG(regularexpression)
|
||||
case ExpressionType::RegularExpression:
|
||||
{
|
||||
QRegularExpression::PatternOptions options = m_regularExpression.patternOptions();
|
||||
options.setFlag(QRegularExpression::CaseInsensitiveOption, cs == Qt::CaseSensitive);
|
||||
m_regularExpression.setPatternOptions(options);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
bool hasMatch(const QString &str) const
|
||||
{
|
||||
bool result = false;
|
||||
switch (m_type) {
|
||||
case ExpressionType::RegExp:
|
||||
result = str.contains(m_regExp);
|
||||
break;
|
||||
#if QT_CONFIG(regularexpression)
|
||||
case ExpressionType::RegularExpression:
|
||||
result = str.contains(m_regularExpression);
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
ExpressionType m_type;
|
||||
QRegExp m_regExp;
|
||||
#if QT_CONFIG(regularexpression)
|
||||
QRegularExpression m_regularExpression;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
class QSortFilterProxyModelPrivate : public QAbstractProxyModelPrivate
|
||||
{
|
||||
Q_DECLARE_PUBLIC(QSortFilterProxyModel)
|
||||
@ -300,7 +173,7 @@ public:
|
||||
|
||||
int filter_column;
|
||||
int filter_role;
|
||||
RegularExpressionData filter_data;
|
||||
QRegularExpression filter_data;
|
||||
QModelIndex last_top_source;
|
||||
|
||||
bool filter_recursive;
|
||||
@ -1271,7 +1144,7 @@ void QSortFilterProxyModelPrivate::update_persistent_indexes(
|
||||
*/
|
||||
void QSortFilterProxyModelPrivate::filter_about_to_be_changed(const QModelIndex &source_parent)
|
||||
{
|
||||
if (!filter_data.isEmpty() &&
|
||||
if (!filter_data.pattern().isEmpty() &&
|
||||
source_index_mapping.constFind(source_parent) == source_index_mapping.constEnd())
|
||||
create_mapping(source_parent);
|
||||
}
|
||||
@ -1934,9 +1807,9 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved(
|
||||
\section1 Filtering
|
||||
|
||||
In addition to sorting, QSortFilterProxyModel can be used to hide items
|
||||
that do not match a certain filter. The filter is specified using a QRegExp
|
||||
that do not match a certain filter. The filter is specified using a QRegularExpression
|
||||
object and is applied to the filterRole() (Qt::DisplayRole by default) of
|
||||
each item, for a given column. The QRegExp object can be used to match a
|
||||
each item, for a given column. The QRegularExpression object can be used to match a
|
||||
regular expression, a wildcard pattern, or a fixed string. For example:
|
||||
|
||||
\snippet qsortfilterproxymodel-details/main.cpp 5
|
||||
@ -1985,21 +1858,6 @@ void QSortFilterProxyModelPrivate::_q_sourceColumnsMoved(
|
||||
\note Some general guidelines for subclassing models are available in the
|
||||
\l{Model Subclassing Reference}.
|
||||
|
||||
\note With Qt 5, regular expression support has been improved through the
|
||||
QRegularExpression class. QSortFilterProxyModel dating back prior to that
|
||||
class creation, it originally supported only QRegExp. Since Qt 5.12,
|
||||
QRegularExpression APIs have been added. Therefore, QRegExp APIs should be
|
||||
considered deprecated and the QRegularExpression version should be used in
|
||||
place.
|
||||
|
||||
\warning Don't mix calls to the getters and setters of different regexp types
|
||||
as this will lead to unexpected results. For maximum compatibility, the original
|
||||
implementation has been kept. Therefore, if, for example, a call to
|
||||
setFilterRegularExpression is made followed by another one to
|
||||
setFilterFixedString, the first call will setup a QRegularExpression object
|
||||
to use as filter while the second will setup a QRegExp in FixedString mode.
|
||||
However, this is an implementation detail that might change in the future.
|
||||
|
||||
\sa QAbstractProxyModel, QAbstractItemModel, {Model/View Programming},
|
||||
{Basic Sort/Filter Model Example}, {Custom Sort/Filter Model Example}, QIdentityProxyModel
|
||||
*/
|
||||
@ -2595,33 +2453,6 @@ Qt::SortOrder QSortFilterProxyModel::sortOrder() const
|
||||
return d->sort_order;
|
||||
}
|
||||
|
||||
/*!
|
||||
\property QSortFilterProxyModel::filterRegExp
|
||||
\brief the QRegExp used to filter the contents of the source model
|
||||
|
||||
Setting this property overwrites the current
|
||||
\l{QSortFilterProxyModel::filterCaseSensitivity}{filterCaseSensitivity}.
|
||||
By default, the QRegExp is an empty string matching all contents.
|
||||
|
||||
If no QRegExp or an empty string is set, everything in the source model
|
||||
will be accepted.
|
||||
|
||||
\sa filterCaseSensitivity, setFilterWildcard(), setFilterFixedString()
|
||||
*/
|
||||
QRegExp QSortFilterProxyModel::filterRegExp() const
|
||||
{
|
||||
Q_D(const QSortFilterProxyModel);
|
||||
return d->filter_data.regExp();
|
||||
}
|
||||
|
||||
void QSortFilterProxyModel::setFilterRegExp(const QRegExp ®Exp)
|
||||
{
|
||||
Q_D(QSortFilterProxyModel);
|
||||
d->filter_about_to_be_changed();
|
||||
d->filter_data.setRegExp(regExp);
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
}
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
/*!
|
||||
\since 5.12
|
||||
@ -2640,14 +2471,14 @@ void QSortFilterProxyModel::setFilterRegExp(const QRegExp ®Exp)
|
||||
QRegularExpression QSortFilterProxyModel::filterRegularExpression() const
|
||||
{
|
||||
Q_D(const QSortFilterProxyModel);
|
||||
return d->filter_data.regularExpression();
|
||||
return d->filter_data;
|
||||
}
|
||||
|
||||
void QSortFilterProxyModel::setFilterRegularExpression(const QRegularExpression ®ularExpression)
|
||||
{
|
||||
Q_D(QSortFilterProxyModel);
|
||||
d->filter_about_to_be_changed();
|
||||
d->filter_data.setRegularExpression(regularExpression);
|
||||
d->filter_data = regularExpression;
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
}
|
||||
#endif
|
||||
@ -2677,12 +2508,12 @@ void QSortFilterProxyModel::setFilterKeyColumn(int column)
|
||||
/*!
|
||||
\property QSortFilterProxyModel::filterCaseSensitivity
|
||||
|
||||
\brief the case sensitivity of the QRegExp pattern used to filter the
|
||||
\brief the case sensitivity of the QRegularExpression pattern used to filter the
|
||||
contents of the source model.
|
||||
|
||||
By default, the filter is case sensitive.
|
||||
|
||||
\sa filterRegExp, sortCaseSensitivity
|
||||
\sa filterRegularExpression, sortCaseSensitivity
|
||||
*/
|
||||
|
||||
/*!
|
||||
@ -2694,16 +2525,20 @@ void QSortFilterProxyModel::setFilterKeyColumn(int column)
|
||||
Qt::CaseSensitivity QSortFilterProxyModel::filterCaseSensitivity() const
|
||||
{
|
||||
Q_D(const QSortFilterProxyModel);
|
||||
return d->filter_data.caseSensitivity();
|
||||
return d->filter_data.patternOptions() & QRegularExpression::CaseInsensitiveOption ?
|
||||
Qt::CaseInsensitive : Qt::CaseSensitive;
|
||||
}
|
||||
|
||||
void QSortFilterProxyModel::setFilterCaseSensitivity(Qt::CaseSensitivity cs)
|
||||
{
|
||||
Q_D(QSortFilterProxyModel);
|
||||
if (cs == d->filter_data.caseSensitivity())
|
||||
QRegularExpression::PatternOptions o = QRegularExpression::NoPatternOption;
|
||||
if (cs == Qt::CaseInsensitive)
|
||||
o = QRegularExpression::CaseInsensitiveOption;
|
||||
if (o == d->filter_data.patternOptions())
|
||||
return;
|
||||
d->filter_about_to_be_changed();
|
||||
d->filter_data.setCaseSensitivity(cs);
|
||||
d->filter_data.setPatternOptions(o);
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
emit filterCaseSensitivityChanged(cs);
|
||||
}
|
||||
@ -2774,24 +2609,6 @@ void QSortFilterProxyModel::setSortLocaleAware(bool on)
|
||||
emit sortLocaleAwareChanged(on);
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
|
||||
Sets the regular expression used to filter the contents
|
||||
of the source model to \a pattern.
|
||||
|
||||
\sa setFilterCaseSensitivity(), setFilterWildcard(), setFilterFixedString(), filterRegExp()
|
||||
*/
|
||||
void QSortFilterProxyModel::setFilterRegExp(const QString &pattern)
|
||||
{
|
||||
Q_D(QSortFilterProxyModel);
|
||||
d->filter_about_to_be_changed();
|
||||
QRegExp rx(pattern);
|
||||
rx.setCaseSensitivity(d->filter_data.caseSensitivity());
|
||||
d->filter_data.setRegExp(rx);
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
}
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
/*!
|
||||
\since 5.12
|
||||
@ -2809,7 +2626,7 @@ void QSortFilterProxyModel::setFilterRegularExpression(const QString &pattern)
|
||||
Q_D(QSortFilterProxyModel);
|
||||
d->filter_about_to_be_changed();
|
||||
QRegularExpression rx(pattern);
|
||||
d->filter_data.setRegularExpression(rx);
|
||||
d->filter_data.setPattern(pattern);
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
}
|
||||
#endif
|
||||
@ -2818,14 +2635,14 @@ void QSortFilterProxyModel::setFilterRegularExpression(const QString &pattern)
|
||||
Sets the wildcard expression used to filter the contents
|
||||
of the source model to the given \a pattern.
|
||||
|
||||
\sa setFilterCaseSensitivity(), setFilterRegExp(), setFilterFixedString(), filterRegExp()
|
||||
\sa setFilterCaseSensitivity(), setFilterRegularExpression(), setFilterFixedString(), filterRegularExpression()
|
||||
*/
|
||||
void QSortFilterProxyModel::setFilterWildcard(const QString &pattern)
|
||||
{
|
||||
Q_D(QSortFilterProxyModel);
|
||||
d->filter_about_to_be_changed();
|
||||
QRegExp rx(pattern, d->filter_data.caseSensitivity(), QRegExp::Wildcard);
|
||||
d->filter_data.setRegExp(rx);
|
||||
QString p = QRegularExpression::wildcardToRegularExpression(pattern, QRegularExpression::UnanchoredWildcardConversion);
|
||||
d->filter_data.setPattern(p);
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
}
|
||||
|
||||
@ -2833,14 +2650,13 @@ void QSortFilterProxyModel::setFilterWildcard(const QString &pattern)
|
||||
Sets the fixed string used to filter the contents
|
||||
of the source model to the given \a pattern.
|
||||
|
||||
\sa setFilterCaseSensitivity(), setFilterRegExp(), setFilterWildcard(), filterRegExp()
|
||||
\sa setFilterCaseSensitivity(), setFilterRegularExpression(), setFilterWildcard(), filterRegularExpression()
|
||||
*/
|
||||
void QSortFilterProxyModel::setFilterFixedString(const QString &pattern)
|
||||
{
|
||||
Q_D(QSortFilterProxyModel);
|
||||
d->filter_about_to_be_changed();
|
||||
QRegExp rx(pattern, d->filter_data.caseSensitivity(), QRegExp::FixedString);
|
||||
d->filter_data.setRegExp(rx);
|
||||
d->filter_data.setPattern(QRegularExpression::escape(pattern));
|
||||
d->filter_changed(QSortFilterProxyModelPrivate::Direction::Rows);
|
||||
}
|
||||
|
||||
@ -3130,20 +2946,20 @@ bool QSortFilterProxyModel::lessThan(const QModelIndex &source_left, const QMode
|
||||
should be accepted or not. This can be changed by setting the
|
||||
\l{QSortFilterProxyModel::filterRole}{filterRole} property.
|
||||
|
||||
\sa filterAcceptsColumn(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard()
|
||||
\sa filterAcceptsColumn(), setFilterFixedString(), setFilterRegularExpression(), setFilterWildcard()
|
||||
*/
|
||||
bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
||||
{
|
||||
Q_D(const QSortFilterProxyModel);
|
||||
|
||||
if (d->filter_data.isEmpty())
|
||||
if (d->filter_data.pattern().isEmpty())
|
||||
return true;
|
||||
if (d->filter_column == -1) {
|
||||
int column_count = d->model->columnCount(source_parent);
|
||||
for (int column = 0; column < column_count; ++column) {
|
||||
QModelIndex source_index = d->model->index(source_row, column, source_parent);
|
||||
QString key = d->model->data(source_index, d->filter_role).toString();
|
||||
if (d->filter_data.hasMatch(key))
|
||||
if (d->filter_data.match(key).hasMatch())
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -3152,7 +2968,7 @@ bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &
|
||||
if (!source_index.isValid()) // the column may not exist
|
||||
return true;
|
||||
QString key = d->model->data(source_index, d->filter_role).toString();
|
||||
return d->filter_data.hasMatch(key);
|
||||
return d->filter_data.match(key).hasMatch();
|
||||
}
|
||||
|
||||
/*!
|
||||
@ -3162,7 +2978,7 @@ bool QSortFilterProxyModel::filterAcceptsRow(int source_row, const QModelIndex &
|
||||
\note The default implementation always returns \c true. You must reimplement this
|
||||
method to get the described behavior.
|
||||
|
||||
\sa filterAcceptsRow(), setFilterFixedString(), setFilterRegExp(), setFilterWildcard()
|
||||
\sa filterAcceptsRow(), setFilterFixedString(), setFilterRegularExpression(), setFilterWildcard()
|
||||
*/
|
||||
bool QSortFilterProxyModel::filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const
|
||||
{
|
||||
|
@ -41,7 +41,6 @@
|
||||
#define QSORTFILTERPROXYMODEL_H
|
||||
|
||||
#include <QtCore/qabstractproxymodel.h>
|
||||
#include <QtCore/qregexp.h>
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
# include <QtCore/qregularexpression.h>
|
||||
@ -62,7 +61,6 @@ class Q_CORE_EXPORT QSortFilterProxyModel : public QAbstractProxyModel
|
||||
friend class QSortFilterProxyModelGreaterThan;
|
||||
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QRegExp filterRegExp READ filterRegExp WRITE setFilterRegExp)
|
||||
#if QT_CONFIG(regularexpression)
|
||||
Q_PROPERTY(QRegularExpression filterRegularExpression READ filterRegularExpression WRITE setFilterRegularExpression)
|
||||
#endif
|
||||
@ -87,8 +85,6 @@ public:
|
||||
QItemSelection mapSelectionToSource(const QItemSelection &proxySelection) const override;
|
||||
QItemSelection mapSelectionFromSource(const QItemSelection &sourceSelection) const override;
|
||||
|
||||
QRegExp filterRegExp() const;
|
||||
|
||||
#if QT_CONFIG(regularexpression)
|
||||
QRegularExpression filterRegularExpression() const;
|
||||
#endif
|
||||
@ -121,8 +117,6 @@ public:
|
||||
void setRecursiveFilteringEnabled(bool recursive);
|
||||
|
||||
public Q_SLOTS:
|
||||
void setFilterRegExp(const QString &pattern);
|
||||
void setFilterRegExp(const QRegExp ®Exp);
|
||||
#if QT_CONFIG(regularexpression)
|
||||
void setFilterRegularExpression(const QString &pattern);
|
||||
void setFilterRegularExpression(const QRegularExpression ®ularExpression);
|
||||
|
@ -11,7 +11,6 @@ if(TARGET Qt::Gui)
|
||||
add_subdirectory(qtransposeproxymodel)
|
||||
endif()
|
||||
if(TARGET Qt::Widgets)
|
||||
add_subdirectory(qsortfilterproxymodel_regexp)
|
||||
add_subdirectory(qsortfilterproxymodel_regularexpression)
|
||||
endif()
|
||||
if(TARGET Qt::Sql AND TARGET Qt::Widgets)
|
||||
|
@ -13,7 +13,6 @@ qtHaveModule(gui): SUBDIRS += \
|
||||
|
||||
qtHaveModule(widgets) {
|
||||
SUBDIRS += \
|
||||
qsortfilterproxymodel_regexp \
|
||||
qsortfilterproxymodel_regularexpression
|
||||
|
||||
qtHaveModule(sql): SUBDIRS += \
|
||||
|
@ -78,15 +78,7 @@ void tst_QSortFilterProxyModel::cleanupTestCase()
|
||||
|
||||
void tst_QSortFilterProxyModel::cleanup()
|
||||
{
|
||||
switch (m_filterType) {
|
||||
case FilterType::RegExp:
|
||||
m_proxy->setFilterRegExp(QRegExp());
|
||||
break;
|
||||
case FilterType::RegularExpression:
|
||||
m_proxy->setFilterRegularExpression(QRegularExpression());
|
||||
break;
|
||||
}
|
||||
|
||||
m_proxy->setFilterRegularExpression(QRegularExpression());
|
||||
m_proxy->sort(-1, Qt::AscendingOrder);
|
||||
m_model->clear();
|
||||
m_model->insertColumns(0, 1);
|
||||
@ -553,7 +545,7 @@ void tst_QSortFilterProxyModel::appendRowFromCombobox()
|
||||
|
||||
QSortFilterProxyModel proxy;
|
||||
proxy.setSourceModel(&model);
|
||||
proxy.setFilterRegExp(pattern);
|
||||
proxy.setFilterRegularExpression(pattern);
|
||||
|
||||
QComboBox comboBox;
|
||||
comboBox.setModel(&proxy);
|
||||
@ -873,29 +865,16 @@ class MyFilteredColumnProxyModel : public QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
MyFilteredColumnProxyModel(FilterType filterType, QObject *parent = nullptr) :
|
||||
QSortFilterProxyModel(parent),
|
||||
m_filterType(filterType)
|
||||
MyFilteredColumnProxyModel(QObject *parent = nullptr) :
|
||||
QSortFilterProxyModel(parent)
|
||||
{ }
|
||||
|
||||
protected:
|
||||
bool filterAcceptsColumn(int sourceColumn, const QModelIndex &) const override
|
||||
{
|
||||
QString key = sourceModel()->headerData(sourceColumn, Qt::Horizontal).toString();
|
||||
bool result = false;
|
||||
switch (m_filterType) {
|
||||
case FilterType::RegExp:
|
||||
result = key.contains(filterRegExp());
|
||||
break;
|
||||
case FilterType::RegularExpression:
|
||||
result = key.contains(filterRegularExpression());
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
return key.contains(filterRegularExpression());
|
||||
}
|
||||
|
||||
private:
|
||||
FilterType m_filterType;
|
||||
};
|
||||
|
||||
void tst_QSortFilterProxyModel::removeColumns_data()
|
||||
@ -1104,7 +1083,7 @@ void tst_QSortFilterProxyModel::removeColumns()
|
||||
QFETCH(QStringList, expectedSource);
|
||||
|
||||
QStandardItemModel model;
|
||||
MyFilteredColumnProxyModel proxy(m_filterType);
|
||||
MyFilteredColumnProxyModel proxy;
|
||||
proxy.setSourceModel(&model);
|
||||
if (!filter.isEmpty())
|
||||
setupFilter(&proxy, filter);
|
||||
@ -1358,14 +1337,7 @@ void tst_QSortFilterProxyModel::checkHierarchy(const QStringList &l, const QAbst
|
||||
|
||||
void tst_QSortFilterProxyModel::setupFilter(QSortFilterProxyModel *model, const QString& pattern)
|
||||
{
|
||||
switch (m_filterType) {
|
||||
case FilterType::RegExp:
|
||||
model->setFilterRegExp(pattern);
|
||||
break;
|
||||
case FilterType::RegularExpression:
|
||||
model->setFilterRegularExpression(pattern);
|
||||
break;
|
||||
}
|
||||
model->setFilterRegularExpression(pattern);
|
||||
}
|
||||
|
||||
class TestModel: public QAbstractTableModel
|
||||
@ -4928,7 +4900,7 @@ void tst_QSortFilterProxyModel::filterAndInsertRow()
|
||||
model.setStringList(initialModelList);
|
||||
proxyModel.setSourceModel(&model);
|
||||
proxyModel.setDynamicSortFilter(true);
|
||||
proxyModel.setFilterRegExp(filterRegExp);
|
||||
proxyModel.setFilterRegularExpression(filterRegExp);
|
||||
|
||||
QVERIFY(proxyModel.insertRow(row));
|
||||
QCOMPARE(model.stringList(), expectedModelList);
|
||||
|
@ -1 +0,0 @@
|
||||
tst_qsortfilterproxymodel_regexp
|
@ -1,18 +0,0 @@
|
||||
# Generated from qsortfilterproxymodel_regexp.pro.
|
||||
|
||||
#####################################################################
|
||||
## tst_qsortfilterproxymodel_regexp Test:
|
||||
#####################################################################
|
||||
|
||||
add_qt_test(tst_qsortfilterproxymodel_regexp
|
||||
SOURCES
|
||||
../../../other/qabstractitemmodelutils/dynamictreemodel.cpp ../../../other/qabstractitemmodelutils/dynamictreemodel.h
|
||||
../qsortfilterproxymodel_common/tst_qsortfilterproxymodel.cpp ../qsortfilterproxymodel_common/tst_qsortfilterproxymodel.h
|
||||
tst_qsortfilterproxymodel_regexp.cpp
|
||||
INCLUDE_DIRECTORIES
|
||||
../../../other/qabstractitemmodelutils
|
||||
../qsortfilterproxymodel_common
|
||||
PUBLIC_LIBRARIES
|
||||
Qt::Gui
|
||||
Qt::Widgets
|
||||
)
|
@ -1,16 +0,0 @@
|
||||
CONFIG += testcase
|
||||
TARGET = tst_qsortfilterproxymodel_regexp
|
||||
|
||||
QT += widgets testlib
|
||||
mtdir = ../../../other/qabstractitemmodelutils
|
||||
qsfpmdir = ../qsortfilterproxymodel_common
|
||||
|
||||
INCLUDEPATH += $$PWD/$${mtdir} $$PWD/$${qsfpmdir}
|
||||
SOURCES += \
|
||||
tst_qsortfilterproxymodel_regexp.cpp \
|
||||
$${qsfpmdir}/tst_qsortfilterproxymodel.cpp \
|
||||
$${mtdir}/dynamictreemodel.cpp
|
||||
|
||||
HEADERS += \
|
||||
$${qsfpmdir}/tst_qsortfilterproxymodel.h \
|
||||
$${mtdir}/dynamictreemodel.h
|
@ -1,69 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2016 The Qt Company Ltd.
|
||||
** Contact: https://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the test suite of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
||||
** Commercial License Usage
|
||||
** Licensees holding valid commercial Qt licenses may use this file in
|
||||
** accordance with the commercial license agreement provided with the
|
||||
** Software or, alternatively, in accordance with the terms contained in
|
||||
** a written agreement between you and The Qt Company. For licensing terms
|
||||
** and conditions see https://www.qt.io/terms-conditions. For further
|
||||
** information use the contact form at https://www.qt.io/contact-us.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU
|
||||
** General Public License version 3 as published by the Free Software
|
||||
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
||||
** included in the packaging of this file. Please review the following
|
||||
** information to ensure the GNU General Public License requirements will
|
||||
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtTest/QtTest>
|
||||
|
||||
#include "tst_qsortfilterproxymodel.h"
|
||||
|
||||
class tst_QSortFilterProxyModelRegExp : public tst_QSortFilterProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
tst_QSortFilterProxyModelRegExp();
|
||||
private slots:
|
||||
void tst_invalid();
|
||||
void tst_caseSensitivity();
|
||||
};
|
||||
|
||||
tst_QSortFilterProxyModelRegExp::tst_QSortFilterProxyModelRegExp() :
|
||||
tst_QSortFilterProxyModel()
|
||||
{
|
||||
m_filterType = FilterType::RegExp;
|
||||
}
|
||||
|
||||
void tst_QSortFilterProxyModelRegExp::tst_invalid()
|
||||
{
|
||||
const QLatin1String pattern("test");
|
||||
QSortFilterProxyModel model;
|
||||
model.setFilterRegExp(pattern);
|
||||
QCOMPARE(model.filterRegExp(), QRegExp(pattern));
|
||||
model.setFilterRegularExpression(pattern);
|
||||
QCOMPARE(model.filterRegExp(), QRegExp());
|
||||
}
|
||||
|
||||
void tst_QSortFilterProxyModelRegExp::tst_caseSensitivity()
|
||||
{
|
||||
const QLatin1String pattern("test");
|
||||
QSortFilterProxyModel model;
|
||||
model.setFilterCaseSensitivity(Qt::CaseInsensitive);
|
||||
model.setFilterRegExp(pattern);
|
||||
QCOMPARE(model.filterCaseSensitivity(), Qt::CaseInsensitive);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QSortFilterProxyModelRegExp)
|
||||
#include "tst_qsortfilterproxymodel_regexp.moc"
|
@ -42,7 +42,6 @@ private slots:
|
||||
tst_QSortFilterProxyModelRegularExpression::tst_QSortFilterProxyModelRegularExpression() :
|
||||
tst_QSortFilterProxyModel()
|
||||
{
|
||||
m_filterType = FilterType::RegularExpression;
|
||||
}
|
||||
|
||||
void tst_QSortFilterProxyModelRegularExpression::tst_invalid()
|
||||
@ -51,8 +50,6 @@ void tst_QSortFilterProxyModelRegularExpression::tst_invalid()
|
||||
QSortFilterProxyModel model;
|
||||
model.setFilterRegularExpression(pattern);
|
||||
QCOMPARE(model.filterRegularExpression(), QRegularExpression(pattern));
|
||||
model.setFilterRegExp(pattern);
|
||||
QCOMPARE(model.filterRegularExpression(), QRegularExpression());
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QSortFilterProxyModelRegularExpression)
|
||||
|
Loading…
x
Reference in New Issue
Block a user