From fb0023abfce189cd70ddc9782074f575029461b3 Mon Sep 17 00:00:00 2001 From: YiFang Xiao Date: Fri, 14 Jun 2024 22:05:14 +0800 Subject: [PATCH] opt: clean clang tidy issues --- src/ui/mainwindow.cc | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/ui/mainwindow.cc b/src/ui/mainwindow.cc index 6ba6b8b0..ed8781b1 100644 --- a/src/ui/mainwindow.cc +++ b/src/ui/mainwindow.cc @@ -1727,7 +1727,6 @@ void MainWindow::fillWindowsMenu() } } } - return; } void MainWindow::switchToWindow( QAction * act ) @@ -1824,7 +1823,7 @@ void MainWindow::tabCloseRequested( int x ) // and only then remove the old one. //activate a tab in accordance with MRU - if ( cfg.preferences.mruTabOrder && mruList.size() > 0 ) { + if ( cfg.preferences.mruTabOrder && !mruList.empty() ) { ui.tabWidget->setCurrentWidget( mruList.at( 0 ) ); } else if ( ui.tabWidget->count() > 1 ) { @@ -2231,7 +2230,7 @@ void MainWindow::editPreferences() // Loop through all tabs and reload pages due to ArticleMaker's change. for ( int x = 0; x < ui.tabWidget->count(); ++x ) { - ArticleView & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) ); + auto & view = dynamic_cast< ArticleView & >( *( ui.tabWidget->widget( x ) ) ); view.setSelectionBySingleClick( p.selectWordBySingleClick ); view.syncBackgroundColorWithCfgDarkReader(); @@ -2253,9 +2252,9 @@ void MainWindow::editPreferences() history.setMaxSize( cfg.preferences.maxStringsInHistory ); ui.historyPaneWidget->updateHistoryCounts(); - for ( unsigned x = 0; x < dictionaries.size(); x++ ) { - dictionaries[ x ]->setFTSParameters( cfg.preferences.fts ); - dictionaries[ x ]->setSynonymSearchEnabled( cfg.preferences.synonymSearchEnabled ); + for ( const auto & dictionarie : dictionaries ) { + dictionarie->setFTSParameters( cfg.preferences.fts ); + dictionarie->setSynonymSearchEnabled( cfg.preferences.synonymSearchEnabled ); } ui.fullTextSearchAction->setEnabled( cfg.preferences.fts.enabled ); @@ -2469,7 +2468,7 @@ bool MainWindow::handleBackForwardMouseButtons( QMouseEvent * event ) bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) { if ( ev->type() == QEvent::ShortcutOverride || ev->type() == QEvent::KeyPress ) { - QKeyEvent * ke = dynamic_cast< QKeyEvent * >( ev ); + auto * ke = dynamic_cast< QKeyEvent * >( ev ); // Handle F3/Shift+F3 shortcuts int const key = ke->key(); if ( key == Qt::Key_F3 ) { @@ -2504,7 +2503,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) } if ( ev->type() == QEvent::MouseButtonPress ) { - auto event = static_cast< QMouseEvent * >( ev ); + auto event = dynamic_cast< QMouseEvent * >( ev ); return handleBackForwardMouseButtons( event ); } @@ -2536,7 +2535,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) if ( obj == translateLine ) { if ( ev->type() == QEvent::KeyPress ) { - QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); + QKeyEvent * keyEvent = dynamic_cast< QKeyEvent * >( ev ); if ( cfg.preferences.searchInDock ) { if ( keyEvent->matches( QKeySequence::MoveToNextLine ) && ui.wordList->count() ) { @@ -2558,7 +2557,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) } else if ( obj == ui.wordList ) { if ( ev->type() == QEvent::KeyPress ) { - QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); + QKeyEvent * keyEvent = dynamic_cast< QKeyEvent * >( ev ); if ( keyEvent->matches( QKeySequence::MoveToPreviousLine ) && !ui.wordList->currentRow() ) { ui.wordList->setCurrentRow( 0, QItemSelectionModel::Clear ); @@ -2612,7 +2611,7 @@ void MainWindow::wordListSelectionChanged() { QList< QListWidgetItem * > selected = ui.wordList->selectedItems(); - if ( selected.size() ) { + if ( !selected.empty() ) { wordListSelChanged = true; showTranslationFor( selected.front()->text() ); } @@ -3069,10 +3068,10 @@ void MainWindow::on_newTab_triggered() void MainWindow::setAutostart( bool autostart ) { #if defined Q_OS_WIN32 - QSettings reg( "HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat ); + QSettings reg( R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat ); if ( autostart ) { - QString app_fname = QString( "\"%1\"" ).arg( QCoreApplication::applicationFilePath() ); - app_fname.replace( "/", "\\" ); + QString app_fname = QString( R"("%1")" ).arg( QCoreApplication::applicationFilePath() ); + app_fname.replace( "/", R"(\)" ); reg.setValue( ApplicationSettingName, app_fname ); } else { @@ -3111,8 +3110,8 @@ void MainWindow::on_pageSetup_triggered() void MainWindow::on_printPreview_triggered() { - QPrinter printer; - QPrintPreviewDialog dialog( &printer, this ); + QPrinter _printer; + QPrintPreviewDialog dialog( &_printer, this ); auto combox = dialog.findChild< QComboBox * >(); int index = combox->findText( "100%" ); combox->setCurrentIndex( index ); @@ -3168,7 +3167,7 @@ static void filterAndCollectResources( QString & html, if ( resourceIncluded.insert( hash.result() ).second ) { // Gather resource information (url, filename) to be download later - downloadResources.push_back( pair< QUrl, QString >( url, folder + host + resourcePath ) ); + downloadResources.emplace_back( url, folder + host + resourcePath ); } // Modify original url, set to the native one @@ -3231,7 +3230,7 @@ void MainWindow::on_saveArticle_triggered() // Convert internal links - QRegExp rx3( "href=\"(bword:|gdlookup://localhost/)([^\"]+)\"" ); + QRegExp rx3( R"lit(href="(bword:|gdlookup://localhost/)([^"]+)")lit" ); int pos = 0; QRegularExpression anchorRx( "(g[0-9a-f]{32}_)[0-9a-f]+_" ); while ( ( pos = rx3.indexIn( html, pos ) ) != -1 ) { @@ -3245,7 +3244,7 @@ void MainWindow::on_saveArticle_triggered() anchor.replace( anchorRx, "\\1" ); // MDict anchors } name.replace( rxName, "_" ); - name = QString( "href=\"" ) + QUrl::toPercentEncoding( name ) + ".html" + anchor + "\""; + name = QString( R"(href=")" ) + QUrl::toPercentEncoding( name ) + ".html" + anchor + "\""; html.replace( pos, rx3.cap().length(), name ); pos += name.length(); } @@ -3258,7 +3257,7 @@ void MainWindow::on_saveArticle_triggered() if ( complete ) { QString folder = fi.absoluteDir().absolutePath() + "/" + fi.baseName() + "_files"; - QRegExp rx1( "\"((?:bres|gico|gdau|qrcx|qrc|gdvideo)://[^\"]+)\"" ); + QRegExp rx1( R"lit("((?:bres|gico|gdau|qrcx|qrc|gdvideo)://[^"]+)")lit" ); QRegExp rx2( "'((?:bres|gico|gdau|qrcx|qrc|gdvideo)://[^']+)'" ); set< QByteArray > resourceIncluded; vector< pair< QUrl, QString > > downloadResources; @@ -3266,7 +3265,7 @@ void MainWindow::on_saveArticle_triggered() filterAndCollectResources( html, rx1, "\"", folder, resourceIncluded, downloadResources ); filterAndCollectResources( html, rx2, "'", folder, resourceIncluded, downloadResources ); - ArticleSaveProgressDialog * progressDialog = new ArticleSaveProgressDialog( this ); + auto * progressDialog = new ArticleSaveProgressDialog( this ); // reserve '1' for saving main html file int maxVal = 1;