mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Use QRegularExpression instead of QRegExp in dictionary headwords dialog under Qt 5.12 and later
This commit is contained in:
parent
5fb4ff183e
commit
b61863b8df
|
@ -11,6 +11,12 @@
|
|||
#include <QTimer>
|
||||
#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
|
||||
|
||||
DictHeadwords::DictHeadwords( QWidget *parent, Config::Class & cfg_,
|
||||
|
@ -212,14 +218,43 @@ void DictHeadwords::filterChanged()
|
|||
QRegExp::PatternSyntax( ui.searchModeCombo->itemData(
|
||||
ui.searchModeCombo->currentIndex()).toInt() );
|
||||
|
||||
Qt::CaseSensitivity caseSensitivity = ui.matchCase->isChecked() ? Qt::CaseSensitive
|
||||
: Qt::CaseInsensitive;
|
||||
#if QT_VERSION >= QT_VERSION_CHECK( 5, 12, 0 )
|
||||
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 );
|
||||
|
||||
QApplication::setOverrideCursor( Qt::WaitCursor );
|
||||
|
||||
proxy->setFilterRegExp( regExp );
|
||||
#endif
|
||||
|
||||
proxy->sort( 0 );
|
||||
|
||||
QApplication::restoreOverrideCursor();
|
||||
|
|
Loading…
Reference in a new issue