From 20e6d1d66cacff2995cf78c8b9af44ea910481a4 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 2 Dec 2024 22:57:00 +0100 Subject: [PATCH] [libcalamares] Deal with deprecations in QComboBox --- src/libcalamares/compat/CheckBox.h | 30 ++++++++++++++++++++++++ src/modules/finished/FinishedPage.cpp | 12 ++++------ src/modules/partition/gui/ChoicePage.cpp | 10 ++++---- src/modules/tracking/TrackingPage.cpp | 7 +++--- src/modules/users/UsersPage.cpp | 10 ++++---- 5 files changed, 50 insertions(+), 19 deletions(-) create mode 100644 src/libcalamares/compat/CheckBox.h diff --git a/src/libcalamares/compat/CheckBox.h b/src/libcalamares/compat/CheckBox.h new file mode 100644 index 000000000..261ed465a --- /dev/null +++ b/src/libcalamares/compat/CheckBox.h @@ -0,0 +1,30 @@ +/* === This file is part of Calamares - === + * + * SPDX-FileCopyrightText: 2024 Adriaan de Groot + * SPDX-License-Identifier: GPL-3.0-or-later + * + * Calamares is Free Software: see the License-Identifier above. + * + * + */ +#ifndef CALAMARES_COMPAT_XML_H +#define CALAMARES_COMPAT_XML_H + +#include + +namespace Calamares +{ + +#if QT_VERSION < QT_VERSION_CHECK( 6, 7, 0 ) +using checkBoxStateType = int; +const auto checkBoxStateChangedSignal = &QCheckBox::stateChanged; +constexpr checkBoxStateType checkBoxUncheckedValue = 0; +#else +using checkBoxStateType = Qt::CheckState; +const auto checkBoxStateChangedSignal = &QCheckBox::checkStateChanged; +constexpr checkBoxStateType checkBoxUncheckedValue = Qt::Unchecked; +#endif + +} // namespace Calamares + +#endif diff --git a/src/modules/finished/FinishedPage.cpp b/src/modules/finished/FinishedPage.cpp index cc75ca4d5..a31595f91 100644 --- a/src/modules/finished/FinishedPage.cpp +++ b/src/modules/finished/FinishedPage.cpp @@ -16,6 +16,7 @@ #include "Branding.h" #include "Settings.h" +#include "compat/CheckBox.h" #include "utils/Retranslator.h" #include @@ -41,15 +42,10 @@ FinishedPage::FinishedPage( Config* config, QWidget* parent ) ui->restartCheckBox->setEnabled( mode != Mode::Always ); } ); connect( config, &Config::restartNowWantedChanged, ui->restartCheckBox, &QCheckBox::setChecked ); -#if QT_VERSION < QT_VERSION_CHECK( 6, 7, 0 ) connect( ui->restartCheckBox, - &QCheckBox::stateChanged, - [ config ]( int state ) { config->setRestartNowWanted( state != 0 ); } ); -#else - connect( ui->restartCheckBox, - &QCheckBox::checkStateChanged, - [ config ]( Qt::CheckState state ) { config->setRestartNowWanted( state != Qt::Unchecked ); } ); -#endif + Calamares::checkBoxStateChangedSignal, + [ config ]( Calamares::checkBoxStateType state ) + { config->setRestartNowWanted( state != Calamares::checkBoxUncheckedValue ); } ); CALAMARES_RETRANSLATE_SLOT( &FinishedPage::retranslate ); } diff --git a/src/modules/partition/gui/ChoicePage.cpp b/src/modules/partition/gui/ChoicePage.cpp index 96e7793c9..17c6af3b3 100644 --- a/src/modules/partition/gui/ChoicePage.cpp +++ b/src/modules/partition/gui/ChoicePage.cpp @@ -34,6 +34,7 @@ #include "Branding.h" #include "GlobalStorage.h" #include "JobQueue.h" +#include "compat/CheckBox.h" #include "partition/PartitionIterator.h" #include "partition/PartitionQuery.h" #include "utils/Gui.h" @@ -187,7 +188,7 @@ ChoicePage::init( PartitionCoreModule* core ) connect( m_drivesCombo, qOverload< int >( &QComboBox::currentIndexChanged ), this, &ChoicePage::applyDeviceChoice ); connect( m_encryptWidget, &EncryptWidget::stateChanged, this, &ChoicePage::onEncryptWidgetStateChanged ); - connect( m_reuseHomeCheckBox, &QCheckBox::stateChanged, this, &ChoicePage::onHomeCheckBoxStateChanged ); + connect( m_reuseHomeCheckBox, Calamares::checkBoxStateChangedSignal, this, &ChoicePage::onHomeCheckBoxStateChanged ); ChoicePage::applyDeviceChoice(); } @@ -361,7 +362,8 @@ ChoicePage::setupChoices() Device* ChoicePage::selectedDevice() { - Device* const currentDevice = m_core->deviceModel()->deviceForIndex( m_core->deviceModel()->index( m_drivesCombo->currentIndex() ) ); + Device* const currentDevice + = m_core->deviceModel()->deviceForIndex( m_core->deviceModel()->index( m_drivesCombo->currentIndex() ) ); return currentDevice; } @@ -1031,7 +1033,7 @@ ChoicePage::updateActionChoicePreview( InstallChoice choice ) if ( m_enableEncryptionWidget ) { m_encryptWidget->show(); - if ( m_config->preCheckEncryption() && ! m_preCheckActivated ) + if ( m_config->preCheckEncryption() && !m_preCheckActivated ) { m_encryptWidget->setEncryptionCheckbox( true ); m_preCheckActivated = true; @@ -1091,7 +1093,7 @@ ChoicePage::updateActionChoicePreview( InstallChoice choice ) if ( shouldShowEncryptWidget( choice ) ) { m_encryptWidget->show(); - if ( m_config->preCheckEncryption() && ! m_preCheckActivated ) + if ( m_config->preCheckEncryption() && !m_preCheckActivated ) { m_encryptWidget->setEncryptionCheckbox( true ); m_preCheckActivated = true; diff --git a/src/modules/tracking/TrackingPage.cpp b/src/modules/tracking/TrackingPage.cpp index df4b52385..859abdfd9 100644 --- a/src/modules/tracking/TrackingPage.cpp +++ b/src/modules/tracking/TrackingPage.cpp @@ -16,6 +16,7 @@ #include "GlobalStorage.h" #include "JobQueue.h" #include "ViewManager.h" +#include "compat/CheckBox.h" #include "utils/Gui.h" #include "utils/Logger.h" #include "utils/Retranslator.h" @@ -32,7 +33,7 @@ TrackingPage::TrackingPage( Config* config, QWidget* parent ) ui->noneCheckBox->setChecked( true ); ui->noneCheckBox->setEnabled( false ); - connect( ui->noneCheckBox, &QCheckBox::stateChanged, this, &TrackingPage::buttonNoneChecked ); + connect( ui->noneCheckBox, Calamares::checkBoxStateChangedSignal, this, &TrackingPage::buttonNoneChecked ); // Each "panel" of configuration has the same kind of setup, // where the xButton and xCheckBox is connected to the xTracking @@ -40,9 +41,9 @@ TrackingPage::TrackingPage( Config* config, QWidget* parent ) #define trackingSetup( x ) \ do \ { \ - connect( ui->x##CheckBox, &QCheckBox::stateChanged, this, &TrackingPage::buttonChecked ); \ + connect( ui->x##CheckBox, Calamares::checkBoxStateChangedSignal, this, &TrackingPage::buttonChecked ); \ connect( ui->x##CheckBox, \ - &QCheckBox::stateChanged, \ + Calamares::checkBoxStateChangedSignal, \ config->x##Tracking(), \ QOverload< bool >::of( &TrackingStyleConfig::setTracking ) ); \ connect( config->x##Tracking(), \ diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 1ecc0ebef..da235326c 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -22,6 +22,7 @@ #include "GlobalStorage.h" #include "JobQueue.h" #include "Settings.h" +#include "compat/CheckBox.h" #include "utils/Gui.h" #include "utils/Logger.h" #include "utils/Retranslator.h" @@ -137,9 +138,10 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) ui->checkBoxDoAutoLogin->setChecked( m_config->doAutoLogin() ); connect( ui->checkBoxDoAutoLogin, - &QCheckBox::stateChanged, + Calamares::checkBoxStateChangedSignal, this, - [ this ]( int checked ) { m_config->setAutoLogin( checked != Qt::Unchecked ); } ); + [ this ]( Calamares::checkBoxStateType checked ) + { m_config->setAutoLogin( checked != Calamares::checkBoxUncheckedValue ); } ); connect( config, &Config::autoLoginChanged, ui->checkBoxDoAutoLogin, &QCheckBox::setChecked ); ui->checkBoxReusePassword->setVisible( m_config->writeRootPassword() ); @@ -147,7 +149,7 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) if ( m_config->writeRootPassword() ) { connect( config, &Config::reuseUserPasswordForRootChanged, ui->checkBoxReusePassword, &QCheckBox::setChecked ); - connect( ui->checkBoxReusePassword, &QCheckBox::stateChanged, this, &UsersPage::onReuseUserPasswordChanged ); + connect( ui->checkBoxReusePassword, Calamares::checkBoxStateChangedSignal, this, &UsersPage::onReuseUserPasswordChanged ); } ui->checkBoxRequireStrongPassword->setVisible( m_config->permitWeakPasswords() ); @@ -155,7 +157,7 @@ UsersPage::UsersPage( Config* config, QWidget* parent ) if ( m_config->permitWeakPasswords() ) { connect( ui->checkBoxRequireStrongPassword, - &QCheckBox::stateChanged, + Calamares::checkBoxStateChangedSignal, this, [ this ]( int checked ) { m_config->setRequireStrongPasswords( checked != Qt::Unchecked ); } ); connect(