Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opt: properly use Qt containers in range for loops with std::as_const #2145

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/dict/dictserver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ QString const & DictServerDictionary::getDescription()
if ( dictionaryDescription.isEmpty() ) {
dictionaryDescription = QCoreApplication::translate( "DictServer", "Url: " ) + url + "<br>";
dictionaryDescription += QCoreApplication::translate( "DictServer", "Databases: " ) + "<br>";
for ( const auto & serverDatabase : databases ) {
for ( const auto & serverDatabase : std::as_const( databases ) ) {
dictionaryDescription += serverDatabase + "<br>";
}
dictionaryDescription +=
Expand All @@ -374,7 +374,7 @@ QString const & DictServerDictionary::getDescription()
dictionaryDescription += "<br><br>";
dictionaryDescription += QCoreApplication::translate( "DictServer", "Server databases" ) + " ("
+ QString::number( serverDatabases.size() ) + "):" + "<br>";
for ( const auto & serverDatabase : serverDatabases ) {
for ( const auto & serverDatabase : std::as_const( serverDatabases ) ) {
dictionaryDescription += serverDatabase + "<br>";
}
}
Expand Down Expand Up @@ -607,7 +607,7 @@ class DictServerArticleRequest: public Dictionary::DataRequest
static QRegularExpression leadingRespCode( "^\\d{3} " );
uint32_t leadingSpaceCount = 0;
uint32_t firstLeadingSpaceCount = 0;
for ( const QString & line : lines ) {
for ( const QString & line : std::as_const( lines ) ) {
//ignore 15X lines
if ( leadingRespCode.match( line ).hasMatch() ) {
continue;
Expand Down
4 changes: 2 additions & 2 deletions src/dict/hunspell.cc
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void HunspellHeadwordsRequest::run()
if ( !suggestions.empty() ) {
QMutexLocker _( &dataMutex );

for ( const auto & suggestion : suggestions ) {
for ( const auto & suggestion : std::as_const( suggestions ) ) {
matches.push_back( suggestion );
}
}
Expand Down Expand Up @@ -570,7 +570,7 @@ void getSuggestionsForExpression( std::u32string const & expression,
}
}

for ( const auto & result : results ) {
for ( const auto & result : std::as_const( results ) ) {
if ( result != trimmedWord ) {
suggestions.push_back( result );
}
Expand Down
2 changes: 1 addition & 1 deletion src/dict/programs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ void ProgramWordSearchRequest::instanceFinished( QByteArray output, QString erro
output.replace( "\r\n", "\n" );
QStringList result = QString::fromUtf8( output ).split( "\n", Qt::SkipEmptyParts );

for ( const auto & x : result ) {
for ( const auto & x : std::as_const( result ) ) {
matches.push_back( Dictionary::WordMatch( x.toStdU32String() ) );
}

Expand Down
2 changes: 1 addition & 1 deletion src/dict/stardict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class PowerWordDataProcessor
QStringList sl;
walkNode( doc.firstChild(), sl );

for ( auto s : sl ) {
for ( auto s : std::as_const( sl ) ) {
translatePW( s );
ss += s;
ss += "<br>";
Expand Down
2 changes: 1 addition & 1 deletion src/dict/xdxf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ QString readXhtmlData( QXmlStreamReader & stream )

QXmlStreamAttributes attrs = stream.attributes();

for ( const auto & attr : attrs ) {
for ( const auto & attr : std::as_const( attrs ) ) {
result += Utils::escape( attr.name().toString() );
result += "=\"" + Utils::escape( attr.value().toString() ) + "\"";
}
Expand Down
2 changes: 1 addition & 1 deletion src/ftshelpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void FTSResultsRequest::run()
QMutexLocker _( &dataMutex );
QString id = QString::fromUtf8( dict.getId().c_str() );
dict.getHeadwordsFromOffsets( offsetsForHeadwords, headwords, &isCancelled );
for ( const auto & headword : headwords ) {
for ( const auto & headword : std::as_const( headwords ) ) {
foundHeadwords->append( FTS::FtsHeadword( headword, id, QStringList(), matchCase ) );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/headwordsmodel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ QSet< QString > HeadwordListModel::getRemainRows( int & nodeIndex )
_dict->findHeadWordsWithLenth( nodeIndex, &headword, 10000 );

QSet< QString > filtered;
for ( const auto & word : headword ) {
for ( const auto & word : std::as_const( headword ) ) {
if ( !containWord( word ) ) {
filtered.insert( word );
}
Expand Down
2 changes: 1 addition & 1 deletion src/history.cc
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ bool History::save()
}

QTextStream out( &file );
for ( const auto & i : items ) {
for ( const auto & i : std::as_const( items ) ) {
// "0 " is to keep compatibility with the original GD (an unused number)
out << "0 " << i.word.trimmed() << '\n';
}
Expand Down
6 changes: 3 additions & 3 deletions src/langcoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ quint32 LangCoder::findIdForLanguage( std::u32string const & lang )
{
const auto langFolded = QByteArrayView( Text::toUtf8( lang ) );

for ( auto const & lc : LANG_CODE_MAP ) {
for ( auto const & lc : std::as_const( LANG_CODE_MAP ) ) {
if ( langFolded.compare( lc.lang, Qt::CaseInsensitive ) == 0 ) {
return code2toInt( lc.code2.toStdString().c_str() );
}
Expand All @@ -241,7 +241,7 @@ quint32 LangCoder::findIdForLanguage( std::u32string const & lang )

quint32 LangCoder::findIdForLanguageCode3( std::string const & code )
{
for ( auto const & lc : LANG_CODE_MAP ) {
for ( auto const & lc : std::as_const( LANG_CODE_MAP ) ) {
if ( code == lc.code3 ) {
return code2toInt( lc.code2 );
}
Expand All @@ -261,7 +261,7 @@ quint32 LangCoder::guessId( const QString & lang )

// check if it could be the whole language name
if ( lstr.size() >= 3 ) {
for ( auto const & lc : LANG_CODE_MAP ) {
for ( auto const & lc : std::as_const( LANG_CODE_MAP ) ) {
if ( lstr == ( lstr.size() == 3 ? QString::fromStdString( lc.code3 ) : QString::fromStdString( lc.lang ) ) ) {
return code2toInt( lc.code2 );
}
Expand Down
2 changes: 1 addition & 1 deletion src/speechclient.hh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public:
#endif
sp->setLocale( e.locale );
auto voices = sp->availableVoices();
for ( const auto & voice : voices ) {
for ( const auto & voice : std::as_const( voices ) ) {
if ( voice.name() == e.voice_name ) {
sp->setVoice( voice );

Expand Down
2 changes: 1 addition & 1 deletion src/texttospeechsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ TextToSpeechSource::TextToSpeechSource( QWidget * parent, Config::VoiceEngines v
occupiedEngines.insert( ve.name );
}

for ( const auto & engine : engines ) {
for ( const auto & engine : std::as_const( engines ) ) {
QMap< QString, QVariant > map;
map[ "engine_name" ] = engine.engine_name;
map[ "locale" ] = engine.locale;
Expand Down
2 changes: 1 addition & 1 deletion src/ui/dictheadwords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ void DictHeadwords::exportAllWords( QProgressDialog & progress, QTextStream & ou
break;
}

for ( const auto & item : headwords ) {
for ( const auto & item : std::as_const( headwords ) ) {
progress.setValue( totalCount++ );

writeWordToFile( out, item );
Expand Down
12 changes: 6 additions & 6 deletions src/ui/dictionarybar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void DictionaryBar::showContextMenu( QContextMenuEvent * event, bool extended )

unsigned refsAdded = 0;

for ( const auto & dictAction : dictActions ) {
for ( const auto & dictAction : std::as_const( dictActions ) ) {

// Enough! Or the menu would become too large.
if ( refsAdded++ >= maxDictionaryRefsInContextMenu && !extended ) {
Expand Down Expand Up @@ -220,7 +220,7 @@ void DictionaryBar::mutedDictionariesChanged()

setUpdatesEnabled( false );

for ( const auto & dictAction : dictActions ) {
for ( const auto & dictAction : std::as_const( dictActions ) ) {
bool const isUnmuted = !mutedDictionaries->contains( dictAction->data().toString() );

if ( isUnmuted != dictAction->isChecked() ) {
Expand Down Expand Up @@ -253,7 +253,7 @@ void DictionaryBar::actionWasTriggered( QAction * action )
// For solo, all dictionaries must be unchecked, since we're handling
// the result of the dictionary being (un)checked, and in case we were
// in solo, now we would end up with no dictionaries being checked at all.
for ( const auto & dictAction : dictActions ) {
for ( const auto & dictAction : std::as_const( dictActions ) ) {
if ( dictAction->isChecked() ) {
isSolo = false;
break;
Expand All @@ -275,13 +275,13 @@ void DictionaryBar::actionWasTriggered( QAction * action )
}

if ( isSolo ) {
for ( const auto & dictAction : dictActions ) {
for ( const auto & dictAction : std::as_const( dictActions ) ) {
mutedDictionaries->remove( dictAction->data().toString() );
}
}
else {
// Make dictionary solo
for ( const auto & dictAction : dictActions ) {
for ( const auto & dictAction : std::as_const( dictActions ) ) {
QString const dictId = dictAction->data().toString();

if ( dictId == id ) {
Expand Down Expand Up @@ -325,7 +325,7 @@ void DictionaryBar::dictsPaneClicked( const QString & id )
return;
}

for ( const auto & dictAction : dictActions ) {
for ( const auto & dictAction : std::as_const( dictActions ) ) {
QString const dictId = dictAction->data().toString();
if ( dictId == id ) {
dictAction->activate( QAction::Trigger );
Expand Down
2 changes: 1 addition & 1 deletion src/ui/favoritespanewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ bool FavoritesModel::setDataFromTxt( QString const & dataStr )
rootItem = new TreeItem( QVariant(), 0, TreeItem::Root );
}

for ( auto const & word : words ) {
for ( auto const & word : std::as_const( words ) ) {
rootItem->appendChild( new TreeItem( word, rootItem, TreeItem::Word ) );
}
endResetModel();
Expand Down
6 changes: 3 additions & 3 deletions src/ui/historypanewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void HistoryPaneWidget::copySelectedItems()
}

QStringList selectedStrings;
for ( const auto & id : selectedIdxs ) {
for ( const auto & id : std::as_const( selectedIdxs ) ) {
selectedStrings << m_historyList->model()->data( id ).toString();
}

Expand All @@ -122,15 +122,15 @@ void HistoryPaneWidget::deleteSelectedItems()

QList< int > idxsToDelete;

for ( const auto & id : selectedIdxs ) {
for ( const auto & id : std::as_const( selectedIdxs ) ) {
idxsToDelete << id.row();
}

// Need to sort indexes in the decreasing order so that
// the first deletions won't affect the indexes for subsequent deletions.
std::sort( idxsToDelete.begin(), idxsToDelete.end(), std::greater< int >() );

for ( const auto & id : idxsToDelete ) {
for ( const auto & id : std::as_const( idxsToDelete ) ) {
m_history->removeItem( id );
}

Expand Down
2 changes: 1 addition & 1 deletion src/ui/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
// We need to sort by language name -- otherwise list looks really weird
QMultiMap< QString, QString > sortedLocs;
sortedLocs.insert( Language::languageForLocale( "en_US" ), "en_US" );
for ( const auto & availLoc : availLocs ) {
for ( const auto & availLoc : std::as_const( availLocs ) ) {
// Here we assume the xx_YY naming, where xx is language and YY is region.
//remove .qm suffix.
QString locale = availLoc.left( availLoc.size() - 3 );
Expand Down