Use QRegularExpression instead of QRegExp in dictionary headwords dialog under Qt 5.12 and later

This commit is contained in:
Abs62 2019-03-25 18:08:52 +03:00
parent 5fb4ff183e
commit b61863b8df

View file

@ -11,6 +11,12 @@
#include <QTimer> #include <QTimer>
#include <QProgressDialog> #include <QProgressDialog>
#if QT_VERSION >= QT_VERSION_CHECK( 5, 12, 0 )
#include <QRegularExpression>
#include "wildcard.hh"
#include "gddebug.hh"
#endif
#define AUTO_APPLY_LIMIT 150000 #define AUTO_APPLY_LIMIT 150000
DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_, DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_,
@ -212,14 +218,43 @@ void DictHeadwords::filterChanged()
QRegExp::PatternSyntax( ui.searchModeCombo->itemData( QRegExp::PatternSyntax( ui.searchModeCombo->itemData(
ui.searchModeCombo->currentIndex()).toInt() ); ui.searchModeCombo->currentIndex()).toInt() );
Qt::CaseSensitivity caseSensitivity = ui.matchCase->isChecked() ? Qt::CaseSensitive #if QT_VERSION >= QT_VERSION_CHECK( 5, 12, 0 )
: Qt::CaseInsensitive; QRegularExpression::PatternOptions options = QRegularExpression::UseUnicodePropertiesOption;
if( !ui.matchCase->isChecked() )
options |= QRegularExpression::CaseInsensitiveOption;
QString pattern;
switch( syntax )
{
case QRegExp::FixedString: pattern = QRegularExpression::escape( ui.filterLine->text() );
break;
case QRegExp::WildcardUnix: pattern = wildcardsToRegexp( ui.filterLine->text() );
break;
default: pattern = ui.filterLine->text();
break;
}
QRegularExpression regExp( pattern, options );
if( !regExp.isValid() )
{
gdWarning( "Invalid regexp pattern: %s\n", pattern.toUtf8().data() );
regExp.setPattern( QString::fromLatin1( "\1" ) );
}
QApplication::setOverrideCursor( Qt::WaitCursor );
proxy->setFilterRegularExpression( regExp );
#else
Qt::CaseSensitivity caseSensitivity = ui.matchCase->isChecked() ? Qt::CaseSensitive
: Qt::CaseInsensitive;
QRegExp regExp( ui.filterLine->text(), caseSensitivity, syntax ); QRegExp regExp( ui.filterLine->text(), caseSensitivity, syntax );
QApplication::setOverrideCursor( Qt::WaitCursor ); QApplication::setOverrideCursor( Qt::WaitCursor );
proxy->setFilterRegExp( regExp ); proxy->setFilterRegExp( regExp );
#endif
proxy->sort( 0 ); proxy->sort( 0 );
QApplication::restoreOverrideCursor(); QApplication::restoreOverrideCursor();