Merge pull request #1583 from xiaoyifang/opt/clang-tidy-issues

opt: clean clang tidy issues
This commit is contained in:
xiaoyifang 2024-06-14 22:53:26 +08:00 committed by GitHub
commit ac8c459e01
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1721,7 +1721,6 @@ void MainWindow::fillWindowsMenu()
} }
} }
} }
return;
} }
void MainWindow::switchToWindow( QAction * act ) void MainWindow::switchToWindow( QAction * act )
@ -1818,7 +1817,7 @@ void MainWindow::tabCloseRequested( int x )
// and only then remove the old one. // and only then remove the old one.
//activate a tab in accordance with MRU //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 ) ); ui.tabWidget->setCurrentWidget( mruList.at( 0 ) );
} }
else if ( ui.tabWidget->count() > 1 ) { else if ( ui.tabWidget->count() > 1 ) {
@ -2225,7 +2224,7 @@ void MainWindow::editPreferences()
// Loop through all tabs and reload pages due to ArticleMaker's change. // Loop through all tabs and reload pages due to ArticleMaker's change.
for ( int x = 0; x < ui.tabWidget->count(); ++x ) { 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.setSelectionBySingleClick( p.selectWordBySingleClick );
view.syncBackgroundColorWithCfgDarkReader(); view.syncBackgroundColorWithCfgDarkReader();
@ -2247,9 +2246,9 @@ void MainWindow::editPreferences()
history.setMaxSize( cfg.preferences.maxStringsInHistory ); history.setMaxSize( cfg.preferences.maxStringsInHistory );
ui.historyPaneWidget->updateHistoryCounts(); ui.historyPaneWidget->updateHistoryCounts();
for ( unsigned x = 0; x < dictionaries.size(); x++ ) { for ( const auto & dictionarie : dictionaries ) {
dictionaries[ x ]->setFTSParameters( cfg.preferences.fts ); dictionarie->setFTSParameters( cfg.preferences.fts );
dictionaries[ x ]->setSynonymSearchEnabled( cfg.preferences.synonymSearchEnabled ); dictionarie->setSynonymSearchEnabled( cfg.preferences.synonymSearchEnabled );
} }
ui.fullTextSearchAction->setEnabled( cfg.preferences.fts.enabled ); ui.fullTextSearchAction->setEnabled( cfg.preferences.fts.enabled );
@ -2463,7 +2462,7 @@ bool MainWindow::handleBackForwardMouseButtons( QMouseEvent * event )
bool MainWindow::eventFilter( QObject * obj, QEvent * ev ) bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
{ {
if ( ev->type() == QEvent::ShortcutOverride || ev->type() == QEvent::KeyPress ) { 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 // Handle F3/Shift+F3 shortcuts
int const key = ke->key(); int const key = ke->key();
if ( key == Qt::Key_F3 ) { if ( key == Qt::Key_F3 ) {
@ -2498,7 +2497,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
} }
if ( ev->type() == QEvent::MouseButtonPress ) { if ( ev->type() == QEvent::MouseButtonPress ) {
auto event = static_cast< QMouseEvent * >( ev ); auto event = dynamic_cast< QMouseEvent * >( ev );
return handleBackForwardMouseButtons( event ); return handleBackForwardMouseButtons( event );
} }
@ -2530,7 +2529,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
if ( obj == translateLine ) { if ( obj == translateLine ) {
if ( ev->type() == QEvent::KeyPress ) { if ( ev->type() == QEvent::KeyPress ) {
QKeyEvent * keyEvent = static_cast< QKeyEvent * >( ev ); QKeyEvent * keyEvent = dynamic_cast< QKeyEvent * >( ev );
if ( cfg.preferences.searchInDock ) { if ( cfg.preferences.searchInDock ) {
if ( keyEvent->matches( QKeySequence::MoveToNextLine ) && ui.wordList->count() ) { if ( keyEvent->matches( QKeySequence::MoveToNextLine ) && ui.wordList->count() ) {
@ -2552,7 +2551,7 @@ bool MainWindow::eventFilter( QObject * obj, QEvent * ev )
} }
else if ( obj == ui.wordList ) { else if ( obj == ui.wordList ) {
if ( ev->type() == QEvent::KeyPress ) { 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() ) { if ( keyEvent->matches( QKeySequence::MoveToPreviousLine ) && !ui.wordList->currentRow() ) {
ui.wordList->setCurrentRow( 0, QItemSelectionModel::Clear ); ui.wordList->setCurrentRow( 0, QItemSelectionModel::Clear );
@ -2606,7 +2605,7 @@ void MainWindow::wordListSelectionChanged()
{ {
QList< QListWidgetItem * > selected = ui.wordList->selectedItems(); QList< QListWidgetItem * > selected = ui.wordList->selectedItems();
if ( selected.size() ) { if ( !selected.empty() ) {
wordListSelChanged = true; wordListSelChanged = true;
showTranslationFor( selected.front()->text() ); showTranslationFor( selected.front()->text() );
} }
@ -3063,10 +3062,10 @@ void MainWindow::on_newTab_triggered()
void MainWindow::setAutostart( bool autostart ) void MainWindow::setAutostart( bool autostart )
{ {
#if defined Q_OS_WIN32 #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 ) { if ( autostart ) {
QString app_fname = QString( "\"%1\"" ).arg( QCoreApplication::applicationFilePath() ); QString app_fname = QString( R"("%1")" ).arg( QCoreApplication::applicationFilePath() );
app_fname.replace( "/", "\\" ); app_fname.replace( "/", R"(\)" );
reg.setValue( ApplicationSettingName, app_fname ); reg.setValue( ApplicationSettingName, app_fname );
} }
else { else {
@ -3105,8 +3104,8 @@ void MainWindow::on_pageSetup_triggered()
void MainWindow::on_printPreview_triggered() void MainWindow::on_printPreview_triggered()
{ {
QPrinter printer; QPrinter _printer;
QPrintPreviewDialog dialog( &printer, this ); QPrintPreviewDialog dialog( &_printer, this );
auto combox = dialog.findChild< QComboBox * >(); auto combox = dialog.findChild< QComboBox * >();
int index = combox->findText( "100%" ); int index = combox->findText( "100%" );
combox->setCurrentIndex( index ); combox->setCurrentIndex( index );
@ -3162,7 +3161,7 @@ static void filterAndCollectResources( QString & html,
if ( resourceIncluded.insert( hash.result() ).second ) { if ( resourceIncluded.insert( hash.result() ).second ) {
// Gather resource information (url, filename) to be download later // 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 // Modify original url, set to the native one
@ -3225,7 +3224,7 @@ void MainWindow::on_saveArticle_triggered()
// Convert internal links // Convert internal links
QRegExp rx3( "href=\"(bword:|gdlookup://localhost/)([^\"]+)\"" ); QRegExp rx3( R"lit(href="(bword:|gdlookup://localhost/)([^"]+)")lit" );
int pos = 0; int pos = 0;
QRegularExpression anchorRx( "(g[0-9a-f]{32}_)[0-9a-f]+_" ); QRegularExpression anchorRx( "(g[0-9a-f]{32}_)[0-9a-f]+_" );
while ( ( pos = rx3.indexIn( html, pos ) ) != -1 ) { while ( ( pos = rx3.indexIn( html, pos ) ) != -1 ) {
@ -3239,7 +3238,7 @@ void MainWindow::on_saveArticle_triggered()
anchor.replace( anchorRx, "\\1" ); // MDict anchors anchor.replace( anchorRx, "\\1" ); // MDict anchors
} }
name.replace( rxName, "_" ); 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 ); html.replace( pos, rx3.cap().length(), name );
pos += name.length(); pos += name.length();
} }
@ -3252,7 +3251,7 @@ void MainWindow::on_saveArticle_triggered()
if ( complete ) { if ( complete ) {
QString folder = fi.absoluteDir().absolutePath() + "/" + fi.baseName() + "_files"; 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)://[^']+)'" ); QRegExp rx2( "'((?:bres|gico|gdau|qrcx|qrc|gdvideo)://[^']+)'" );
set< QByteArray > resourceIncluded; set< QByteArray > resourceIncluded;
vector< pair< QUrl, QString > > downloadResources; vector< pair< QUrl, QString > > downloadResources;
@ -3260,7 +3259,7 @@ void MainWindow::on_saveArticle_triggered()
filterAndCollectResources( html, rx1, "\"", folder, resourceIncluded, downloadResources ); filterAndCollectResources( html, rx1, "\"", folder, resourceIncluded, downloadResources );
filterAndCollectResources( html, rx2, "'", 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 // reserve '1' for saving main html file
int maxVal = 1; int maxVal = 1;