Skip to content

Commit

Permalink
clean: enable QT_ENABLE_STRICT_MODE_UP_TO for Qt6.8.2+ (#2142)
Browse files Browse the repository at this point in the history
  • Loading branch information
shenlebantongying authored Feb 9, 2025
1 parent 9463f70 commit 5d9b930
Show file tree
Hide file tree
Showing 17 changed files with 50 additions and 56 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ target_compile_definitions(${GOLDENDICT} PRIVATE
QT_NO_DEPRECATED_WARNINGS
)

# make life harder https://doc.qt.io/qt-6/qtglobal.html#QT_ENABLE_STRICT_MODE_UP_TO
if (Qt6Widgets_VERSION VERSION_GREATER_EQUAL 6.8.2)
target_compile_definitions(${GOLDENDICT} PRIVATE
QT_ENABLE_STRICT_MODE_UP_TO=0x060800
)
endif ()

target_compile_definitions(${GOLDENDICT} PUBLIC
MAKE_QTMULTIMEDIA_PLAYER
MAKE_CHINESE_CONVERSION_SUPPORT
Expand Down
2 changes: 1 addition & 1 deletion src/dict/lingualibre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void LinguaArticleRequest::addQuery( QNetworkAccessManager & mgr, const std::u32

qDebug() << "lingualibre query " << reqUrl;

auto netRequest = QNetworkRequest( reqUrl );
auto netRequest = QNetworkRequest( QUrl( reqUrl ) );
netRequest.setTransferTimeout( 3000 );

auto netReply = std::shared_ptr< QNetworkReply >( mgr.get( netRequest ) );
Expand Down
4 changes: 1 addition & 3 deletions src/dict/stardict.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,7 @@ class PowerWordDataProcessor
QStringList sl;
walkNode( doc.firstChild(), sl );

QStringListIterator itr( sl );
while ( itr.hasNext() ) {
QString s = itr.next();
for ( auto s : sl ) {
translatePW( s );
ss += s;
ss += "<br>";
Expand Down
2 changes: 1 addition & 1 deletion src/dict/transliteration/custom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void CustomTransTable::parse( const QString & content )
continue;
}

ins( parts[ 0 ].toUtf8(), parts[ 1 ].toUtf8() );
ins( parts[ 0 ].toStdString().c_str(), parts[ 1 ].toStdString().c_str() );
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/fulltextsearch.cc
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ FullTextSearchDialog::FullTextSearchDialog( QWidget * parent,
helpAction.setShortcut( QKeySequence( "F1" ) );
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( &helpAction, &QAction::triggered, []() {
connect( &helpAction, &QAction::triggered, this, []() {
Help::openHelpWebpage( Help::section::ui_fulltextserch );
} );
connect( ui.helpButton, &QAbstractButton::clicked, &helpAction, &QAction::trigger );
Expand Down
2 changes: 1 addition & 1 deletion src/iframeschemehandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void IframeSchemeHandler::requestStarted( QWebEngineUrlRequestJob * requestJob )


if ( const auto match = baseTag.match( articleString ); match.hasMatch() ) {
base = reply->url().resolved( match.captured( 1 ) ).url();
base = reply->url().resolved( QUrl( match.captured( 1 ) ) ).url();
}

QString baseTagHtml = QString( R"(<base href="%1">)" ).arg( base );
Expand Down
11 changes: 4 additions & 7 deletions src/texttospeechsource.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ TextToSpeechSource::TextToSpeechSource( QWidget * parent, Config::VoiceEngines v
ui.selectedVoiceEngines->setItemDelegateForColumn( VoiceEnginesModel::kColumnEngineDName,
new VoiceEngineItemDelegate( engines, this ) );

foreach( Config::VoiceEngine ve, voiceEngines )
{
for ( const auto & ve : voiceEngines ) {
occupiedEngines.insert( ve.name );
}

foreach( SpeechClient::Engine engine, engines )
{
for ( const auto & engine : engines ) {
QMap< QString, QVariant > map;
map[ "engine_name" ] = engine.engine_name;
map[ "locale" ] = engine.locale;
Expand Down Expand Up @@ -356,8 +354,7 @@ void VoiceEnginesModel::setEngineParams( QModelIndex idx, int volume, int rate )
VoiceEngineEditor::VoiceEngineEditor( SpeechClient::Engines const & engines, QWidget * parent ):
QComboBox( parent )
{
foreach( SpeechClient::Engine engine, engines )
{
for ( const auto & engine : engines ) {
addItem( engine.name, engine.engine_name );
}
}
Expand Down Expand Up @@ -433,4 +430,4 @@ void VoiceEngineItemDelegate::setModelData( QWidget * uncastedEditor,
model->setData( engineNameIndex, editor->engineName() );
}

#endif
#endif
13 changes: 7 additions & 6 deletions src/tiff.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@

namespace GdTiff {

void tiff2img( std::vector< char > & data, const char * format )
void tiff2img( std::vector< char > & data )
{
QImage img = QImage::fromData( (unsigned char *)&data.front(), data.size() );

if ( !img.isNull() ) {
QByteArray ba;
QBuffer buffer( &ba );

QBuffer buffer( &ba ); // buffer doesn't own ba
buffer.open( QIODevice::WriteOnly );

QSize screenSize = QApplication::primaryScreen()->availableSize();
QSize imgSize = img.size();
int scaleSize = qMin( imgSize.width(), screenSize.width() );
img.scaledToWidth( scaleSize ).save( &buffer, "webp" );

img.scaledToWidth( scaleSize ).save( &buffer, format );

data.resize( buffer.size() );
memcpy( &data.front(), buffer.data(), data.size() );
memcpy( data.data(), ba.data(), ba.size() );
data.resize( ba.size() );
buffer.close();
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/tiff.hh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@
#include <vector>
namespace GdTiff {

void tiff2img( std::vector< char > & data, const char * format = "webp" );

void tiff2img( std::vector< char > & data );
}
2 changes: 1 addition & 1 deletion src/ui/about.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ About::About( QWidget * parent ):

ui.versionInfo->setText( Version::everything() );

connect( ui.copyInfoBtn, &QPushButton::clicked, [] {
connect( ui.copyInfoBtn, &QPushButton::clicked, this, [] {
QGuiApplication::clipboard()->setText( Version::everything() );
} );
}
2 changes: 1 addition & 1 deletion src/ui/dictheadwords.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ DictHeadwords::DictHeadwords( QWidget * parent, Config::Class & cfg_, Dictionary
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( ui.helpButton, &QAbstractButton::clicked, &helpAction, &QAction::trigger );
connect( &helpAction, &QAction::triggered, []() {
connect( &helpAction, &QAction::triggered, this, []() {
Help::openHelpWebpage( Help::section::ui_headwords );
} );

Expand Down
2 changes: 1 addition & 1 deletion src/ui/edit_dictionaries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ EditDictionaries::EditDictionaries( QWidget * parent,
helpAction.setShortcut( QKeySequence( "F1" ) );
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( &helpAction, &QAction::triggered, [ this ]() {
connect( &helpAction, &QAction::triggered, this, [ this ]() {
if ( ui.tabs->currentWidget() == this->groups ) {
Help::openHelpWebpage( Help::section::manage_groups );
}
Expand Down
6 changes: 3 additions & 3 deletions src/ui/favoritespanewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ void FavoritesPaneWidget::setUp( Config::Class * cfg, QMenu * menu )
// Handle context menu, reusing some of the top-level window's History menu
m_favoritesMenu = new QMenu( this );
m_separator = m_favoritesMenu->addSeparator();
QListIterator< QAction * > actionsIter( menu->actions() );
while ( actionsIter.hasNext() ) {
m_favoritesMenu->addAction( actionsIter.next() );

for ( const auto & a : menu->actions() ) {
m_favoritesMenu->addAction( a );
}

// Make the favorites pane's titlebar
Expand Down
20 changes: 8 additions & 12 deletions src/ui/historypanewidget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ void HistoryPaneWidget::setUp( Config::Class * cfg, History * history, QMenu * m
// Handle context menu, reusing some of the top-level window's History menu
m_historyMenu = new QMenu( this );
m_separator = m_historyMenu->addSeparator();
QListIterator< QAction * > actionsIter( menu->actions() );
while ( actionsIter.hasNext() ) {
m_historyMenu->addAction( actionsIter.next() );
for ( const auto & a : menu->actions() ) {
m_historyMenu->addAction( a );
}

// Make the history pane's titlebar
Expand Down Expand Up @@ -105,9 +104,8 @@ void HistoryPaneWidget::copySelectedItems()
}

QStringList selectedStrings;
QListIterator< QModelIndex > i( selectedIdxs );
while ( i.hasNext() ) {
selectedStrings << m_historyList->model()->data( i.next() ).toString();
for ( const auto & id : selectedIdxs ) {
selectedStrings << m_historyList->model()->data( id ).toString();
}

QApplication::clipboard()->setText( selectedStrings.join( QString::fromLatin1( "\n" ) ) );
Expand All @@ -124,18 +122,16 @@ void HistoryPaneWidget::deleteSelectedItems()

QList< int > idxsToDelete;

QListIterator< QModelIndex > i( selectedIdxs );
while ( i.hasNext() ) {
idxsToDelete << i.next().row();
for ( const auto & id : 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 >() );

QListIterator< int > idxs( idxsToDelete );
while ( idxs.hasNext() ) {
m_history->removeItem( idxs.next() );
for ( const auto & id : idxsToDelete ) {
m_history->removeItem( id );
}

if ( idxsToDelete.size() == 1 ) {
Expand Down
24 changes: 10 additions & 14 deletions src/ui/mainwindow.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
navPronounce->setEnabled( false );
navToolbar->widgetForAction( navPronounce )->setObjectName( "soundButton" );

connect( navPronounce, &QAction::triggered, [ this ]() {
connect( navPronounce, &QAction::triggered, this, [ this ]() {
getCurrentArticleView()->playSound();
} );

Expand Down Expand Up @@ -642,7 +642,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):

connect( &addTab, &QAbstractButton::clicked, this, &MainWindow::addNewTab );

connect( ui.tabWidget, &MainTabWidget::tabBarDoubleClicked, [ this ]( const int index ) {
connect( ui.tabWidget, &MainTabWidget::tabBarDoubleClicked, this, [ this ]( const int index ) {
if ( -1 == index ) { // empty space at tabbar clicked.
this->addNewTab();
}
Expand All @@ -666,7 +666,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
connect( ui.visitForum, &QAction::triggered, this, &MainWindow::visitForum );
connect( ui.openConfigFolder, &QAction::triggered, this, &MainWindow::openConfigFolder );
connect( ui.about, &QAction::triggered, this, &MainWindow::showAbout );
connect( ui.showReference, &QAction::triggered, []() {
connect( ui.showReference, &QAction::triggered, this, []() {
Help::openHelpWebpage();
} );

Expand All @@ -678,10 +678,10 @@ MainWindow::MainWindow( Config::Class & cfg_ ):

connect( translateBox->translateLine(), &QLineEdit::textEdited, this, &MainWindow::translateInputChanged );

connect( ui.translateLine, &QLineEdit::returnPressed, [ this ]() {
connect( ui.translateLine, &QLineEdit::returnPressed, this, [ this ]() {
translateInputFinished( true );
} );
connect( translateBox, &TranslateBox::returnPressed, [ this ]() {
connect( translateBox, &TranslateBox::returnPressed, this, [ this ]() {
translateInputFinished( true );
} );

Expand Down Expand Up @@ -3020,7 +3020,7 @@ void MainWindow::checkNewRelease()

auto * github_reply = dictNetMgr.get( github_release_api ); // will be marked as deleteLater when reply finished.

QObject::connect( github_reply, &QNetworkReply::finished, [ github_reply, this ]() {
QObject::connect( github_reply, &QNetworkReply::finished, github_reply, [ github_reply, this ]() {
if ( github_reply->error() != QNetworkReply::NoError ) {
qWarning() << "Version check failed: " << github_reply->errorString();
}
Expand Down Expand Up @@ -3089,7 +3089,7 @@ void MainWindow::trayIconActivated( QSystemTrayIcon::ActivationReason r )

void MainWindow::visitHomepage()
{
QDesktopServices::openUrl( QApplication::organizationDomain() );
QDesktopServices::openUrl( QUrl( QApplication::organizationDomain() ) );
}

void MainWindow::openConfigFolder()
Expand Down Expand Up @@ -3191,13 +3191,9 @@ void MainWindow::toggleMenuBarTriggered( bool announce )
// depending on the menubar state.

QList< QMenu * > allMenus = menuBar()->findChildren< QMenu * >();
QListIterator< QMenu * > menuIter( allMenus );
while ( menuIter.hasNext() ) {
QMenu * menu = menuIter.next();
for ( const auto & menu : allMenus ) {
QList< QAction * > allMenuActions = menu->actions();
QListIterator< QAction * > actionsIter( allMenuActions );
while ( actionsIter.hasNext() ) {
QAction * action = actionsIter.next();
for ( const auto & action : allMenuActions ) {
if ( !action->shortcut().isEmpty() ) {
if ( cfg.preferences.hideMenubar ) {
// add all menubar actions to the main window,
Expand Down Expand Up @@ -3401,7 +3397,7 @@ void MainWindow::on_saveArticle_triggered()
QWebEnginePage * page = view->page();

// Connect the printFinished signal to handle operations after printing is complete
connect( page, &QWebEnginePage::pdfPrintingFinished, [ = ]( const QString & filePath, bool success ) {
connect( page, &QWebEnginePage::pdfPrintingFinished, page, [ = ]( const QString & filePath, bool success ) {
if ( success ) {
qDebug() << "PDF exported successfully to:" << filePath;
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/preferences.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Preferences::Preferences( QWidget * parent, Config::Class & cfg_ ):
helpAction.setShortcut( QKeySequence( "F1" ) );
helpAction.setShortcutContext( Qt::WidgetWithChildrenShortcut );

connect( &helpAction, &QAction::triggered, [ this ]() {
connect( &helpAction, &QAction::triggered, this, [ this ]() {
const auto * currentTab = ui.tabWidget->currentWidget();
if ( ui.tab_popup == currentTab ) {
Help::openHelpWebpage( Help::section::ui_popup );
Expand Down
2 changes: 1 addition & 1 deletion src/ui/translatebox.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ TranslateBox::TranslateBox( QWidget * parent ):
completer->setMaxVisibleItems( 16 );
completer->popup()->setMinimumHeight( 256 );

connect( translate_line, &QLineEdit::returnPressed, [ this ]() {
connect( translate_line, &QLineEdit::returnPressed, this, [ this ]() {
emit returnPressed();
} );
}
Expand Down

0 comments on commit 5d9b930

Please sign in to comment.