Convert the example to use QRegularExpression
Change-Id: I7a4259ac43e59a8f50ee1c5072a3da5b977d8bfe Reviewed-by: Alex Blasche <alexander.blasche@qt.io> Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
parent
dba00c4a3b
commit
52d91508fd
@ -74,9 +74,9 @@ Window::Window()
|
|||||||
filterPatternLabel->setBuddy(filterPatternLineEdit);
|
filterPatternLabel->setBuddy(filterPatternLineEdit);
|
||||||
|
|
||||||
filterSyntaxComboBox = new QComboBox;
|
filterSyntaxComboBox = new QComboBox;
|
||||||
filterSyntaxComboBox->addItem(tr("Regular expression"), QRegExp::RegExp);
|
filterSyntaxComboBox->addItem(tr("Regular expression"), RegularExpression);
|
||||||
filterSyntaxComboBox->addItem(tr("Wildcard"), QRegExp::Wildcard);
|
filterSyntaxComboBox->addItem(tr("Wildcard"), Wildcard);
|
||||||
filterSyntaxComboBox->addItem(tr("Fixed string"), QRegExp::FixedString);
|
filterSyntaxComboBox->addItem(tr("Fixed string"), FixedString);
|
||||||
filterSyntaxLabel = new QLabel(tr("Filter &syntax:"));
|
filterSyntaxLabel = new QLabel(tr("Filter &syntax:"));
|
||||||
filterSyntaxLabel->setBuddy(filterSyntaxComboBox);
|
filterSyntaxLabel->setBuddy(filterSyntaxComboBox);
|
||||||
|
|
||||||
@ -88,13 +88,13 @@ Window::Window()
|
|||||||
filterColumnLabel->setBuddy(filterColumnComboBox);
|
filterColumnLabel->setBuddy(filterColumnComboBox);
|
||||||
|
|
||||||
connect(filterPatternLineEdit, &QLineEdit::textChanged,
|
connect(filterPatternLineEdit, &QLineEdit::textChanged,
|
||||||
this, &Window::filterRegExpChanged);
|
this, &Window::filterRegularExpressionChanged);
|
||||||
connect(filterSyntaxComboBox, &QComboBox::currentIndexChanged,
|
connect(filterSyntaxComboBox, &QComboBox::currentIndexChanged,
|
||||||
this, &Window::filterRegExpChanged);
|
this, &Window::filterRegularExpressionChanged);
|
||||||
connect(filterColumnComboBox, &QComboBox::currentIndexChanged,
|
connect(filterColumnComboBox, &QComboBox::currentIndexChanged,
|
||||||
this, &Window::filterColumnChanged);
|
this, &Window::filterColumnChanged);
|
||||||
connect(filterCaseSensitivityCheckBox, &QAbstractButton::toggled,
|
connect(filterCaseSensitivityCheckBox, &QAbstractButton::toggled,
|
||||||
this, &Window::filterRegExpChanged);
|
this, &Window::filterRegularExpressionChanged);
|
||||||
connect(sortCaseSensitivityCheckBox, &QAbstractButton::toggled,
|
connect(sortCaseSensitivityCheckBox, &QAbstractButton::toggled,
|
||||||
this, &Window::sortChanged);
|
this, &Window::sortChanged);
|
||||||
|
|
||||||
@ -141,17 +141,26 @@ void Window::setSourceModel(QAbstractItemModel *model)
|
|||||||
sourceView->setModel(model);
|
sourceView->setModel(model);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::filterRegExpChanged()
|
void Window::filterRegularExpressionChanged()
|
||||||
{
|
{
|
||||||
QRegExp::PatternSyntax syntax =
|
Syntax s = Syntax(filterSyntaxComboBox->itemData(filterSyntaxComboBox->currentIndex()).toInt());
|
||||||
QRegExp::PatternSyntax(filterSyntaxComboBox->itemData(
|
QString pattern = filterPatternLineEdit->text();
|
||||||
filterSyntaxComboBox->currentIndex()).toInt());
|
switch (s) {
|
||||||
Qt::CaseSensitivity caseSensitivity =
|
case Wildcard:
|
||||||
filterCaseSensitivityCheckBox->isChecked() ? Qt::CaseSensitive
|
pattern = QRegularExpression::wildcardToRegularExpression(pattern);
|
||||||
: Qt::CaseInsensitive;
|
break;
|
||||||
|
case FixedString:
|
||||||
|
pattern = QRegularExpression::escape(pattern);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
QRegExp regExp(filterPatternLineEdit->text(), caseSensitivity, syntax);
|
QRegularExpression::PatternOptions options = QRegularExpression::NoPatternOption;
|
||||||
proxyModel->setFilterRegExp(regExp);
|
if (!filterCaseSensitivityCheckBox->isChecked())
|
||||||
|
options |= QRegularExpression::CaseInsensitiveOption;
|
||||||
|
QRegularExpression regularExpression(pattern, options);
|
||||||
|
proxyModel->setFilterRegularExpression(regularExpression);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::filterColumnChanged()
|
void Window::filterColumnChanged()
|
||||||
|
@ -74,7 +74,7 @@ public:
|
|||||||
void setSourceModel(QAbstractItemModel *model);
|
void setSourceModel(QAbstractItemModel *model);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void filterRegExpChanged();
|
void filterRegularExpressionChanged();
|
||||||
void filterColumnChanged();
|
void filterColumnChanged();
|
||||||
void sortChanged();
|
void sortChanged();
|
||||||
|
|
||||||
@ -91,6 +91,12 @@ private:
|
|||||||
QLabel *filterSyntaxLabel;
|
QLabel *filterSyntaxLabel;
|
||||||
QLabel *filterColumnLabel;
|
QLabel *filterColumnLabel;
|
||||||
QLineEdit *filterPatternLineEdit;
|
QLineEdit *filterPatternLineEdit;
|
||||||
|
enum Syntax {
|
||||||
|
RegularExpression,
|
||||||
|
Wildcard,
|
||||||
|
FixedString
|
||||||
|
};
|
||||||
|
|
||||||
QComboBox *filterSyntaxComboBox;
|
QComboBox *filterSyntaxComboBox;
|
||||||
QComboBox *filterColumnComboBox;
|
QComboBox *filterColumnComboBox;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user