From 21bab622636966bfee520c251afd6129ae42e7f4 Mon Sep 17 00:00:00 2001 From: xiaoyifang <105986+xiaoyifang@users.noreply.github.com> Date: Sat, 22 Apr 2023 13:32:10 +0800 Subject: [PATCH] fix : code smell --- src/headwordsmodel.cc | 4 ++-- src/ui/dictheadwords.cc | 5 ++--- src/ui/dictheadwords.hh | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/headwordsmodel.cc b/src/headwordsmodel.cc index c7a999f3..5add84a8 100644 --- a/src/headwordsmodel.cc +++ b/src/headwordsmodel.cc @@ -2,7 +2,7 @@ #include "wstring_qt.hh" HeadwordListModel::HeadwordListModel( QObject * parent ) : - QAbstractListModel( parent ), filtering( false ), totalSize(0), index( 0 ),ptr( 0 ) + QAbstractListModel( parent ), filtering( false ), totalSize(0), index( 0 ),ptr( nullptr ) { } @@ -49,7 +49,7 @@ void HeadwordListModel::setFilter( QRegularExpression reg ) void HeadwordListModel::addMatches( QStringList matches) { QStringList filtered; - for ( auto & w : matches ) { + for ( auto const & w : matches ) { if ( !words.contains( w ) ) { filtered << w; } diff --git a/src/ui/dictheadwords.cc b/src/ui/dictheadwords.cc index 931cbd50..b112586e 100644 --- a/src/ui/dictheadwords.cc +++ b/src/ui/dictheadwords.cc @@ -201,7 +201,7 @@ void DictHeadwords::filterChangedInternal() QTimer::singleShot( 100, this, &DictHeadwords::filterChanged ); } -QRegularExpression DictHeadwords::getFilterRegex( ) +QRegularExpression DictHeadwords::getFilterRegex( ) const { const QRegExp::PatternSyntax syntax = static_cast< QRegExp::PatternSyntax >(ui.searchModeCombo->itemData( @@ -368,8 +368,7 @@ void DictHeadwords::saveHeadersToFile() QStringList filtered; - const QRegularExpression regExp = getFilterRegex(); - if(regExp.isValid() && !regExp.pattern().isEmpty()){ + if ( const QRegularExpression regExp = getFilterRegex(); regExp.isValid() && !regExp.pattern().isEmpty() ) { filtered = sortedWords.filter( regExp ); } else{ diff --git a/src/ui/dictheadwords.hh b/src/ui/dictheadwords.hh index 5bc1a26e..53022314 100644 --- a/src/ui/dictheadwords.hh +++ b/src/ui/dictheadwords.hh @@ -48,7 +48,7 @@ private: private slots: void savePos(); void filterChangedInternal(); - QRegularExpression getFilterRegex(); + QRegularExpression getFilterRegex() const; void filterChanged(); void exportButtonClicked(); void okButtonClicked();