From 196f85fa2cddc0f2020d2bdf63ccfcc459c9c2ca Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Mon, 2 Dec 2024 12:48:43 +0100 Subject: [PATCH] C++: prefer std::as_const over Qt solution In Qt 6.6, qAsConst is deprecated; since Calamares is C++17 we have had a standard solution always. --- src/calamares/testmain.cpp | 2 +- src/libcalamares/Settings.cpp | 2 +- src/libcalamares/packages/Tests.cpp | 8 ++++---- src/modules/keyboard/SetKeyboardLayoutJob.cpp | 2 +- src/modules/netinstall/PackageModel.cpp | 2 +- src/modules/packagechooser/PackageModel.cpp | 4 ++-- src/modules/partition/PartitionViewStep.cpp | 4 ++-- src/modules/partition/core/PartitionCoreModule.cpp | 2 +- src/modules/partition/core/PartitionLayout.cpp | 8 ++++---- src/modules/partition/jobs/ClearMountsJob.cpp | 4 ++-- src/modules/partition/jobs/ClearTempMountsJob.cpp | 2 +- src/modules/preservefiles/PreserveFiles.cpp | 2 +- src/modules/umount/UmountJob.cpp | 2 +- src/modules/welcome/checker/GeneralRequirements.cpp | 2 +- src/modules/zfs/ZfsJob.cpp | 6 +++--- 15 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/calamares/testmain.cpp b/src/calamares/testmain.cpp index c25bc519c..f40cf3629 100644 --- a/src/calamares/testmain.cpp +++ b/src/calamares/testmain.cpp @@ -309,7 +309,7 @@ load_module( const ModuleConfig& moduleConfig ) QVariantMap descriptor; QStringList moduleDirectories { "./", "src/modules/", "modules/", CMAKE_INSTALL_FULL_LIBDIR "/calamares/modules/" }; - for ( const QString& prefix : qAsConst( moduleDirectories ) ) + for ( const QString& prefix : std::as_const( moduleDirectories ) ) { // Could be a complete path, eg. src/modules/dummycpp/module.desc fi = QFileInfo( prefix + moduleName ); diff --git a/src/libcalamares/Settings.cpp b/src/libcalamares/Settings.cpp index 7f3cec8ed..32a6e10b6 100644 --- a/src/libcalamares/Settings.cpp +++ b/src/libcalamares/Settings.cpp @@ -275,7 +275,7 @@ bool Settings::isModuleEnabled( const QString& module ) const { // Iterate over the list of modules searching for a match - for ( const auto& moduleInstance : qAsConst( m_moduleInstances ) ) + for ( const auto& moduleInstance : std::as_const( m_moduleInstances ) ) { if ( moduleInstance.key().module() == module ) { diff --git a/src/libcalamares/packages/Tests.cpp b/src/libcalamares/packages/Tests.cpp index 00d70da33..d4b8696c5 100644 --- a/src/libcalamares/packages/Tests.cpp +++ b/src/libcalamares/packages/Tests.cpp @@ -96,7 +96,7 @@ PackagesTests::testAdd() QVERIFY( action.contains( "install" ) ); auto op = action[ "install" ].toList(); QCOMPARE( op.length(), packages.length() ); - for ( const auto& s : qAsConst( packages ) ) + for ( const auto& s : std::as_const( packages ) ) { QVERIFY( op.contains( s ) ); } @@ -121,7 +121,7 @@ PackagesTests::testAdd() QVERIFY( gs.contains( topKey ) ); auto actionList = gs.value( topKey ).toList(); QCOMPARE( actionList.length(), 2 ); // One for each instance key! - for ( const auto& actionVariant : qAsConst( actionList ) ) + for ( const auto& actionVariant : std::as_const( actionList ) ) { auto action = actionVariant.toMap(); QVERIFY( action.contains( "install" ) ); @@ -130,7 +130,7 @@ PackagesTests::testAdd() { auto op = action[ "install" ].toList(); QCOMPARE( op.length(), packages.length() ); // changed from original length, though - for ( const auto& s : qAsConst( packages ) ) + for ( const auto& s : std::as_const( packages ) ) { QVERIFY( op.contains( s ) ); } @@ -212,7 +212,7 @@ PackagesTests::testAddMixed() auto actionList = gs.value( topKey ).toList(); QCOMPARE( actionList.length(), 2 ); - for ( const auto& actionVariant : qAsConst( actionList ) ) + for ( const auto& actionVariant : std::as_const( actionList ) ) { auto action = actionVariant.toMap(); QVERIFY( action.contains( "install" ) ); diff --git a/src/modules/keyboard/SetKeyboardLayoutJob.cpp b/src/modules/keyboard/SetKeyboardLayoutJob.cpp index beb5780a2..81eba130b 100644 --- a/src/modules/keyboard/SetKeyboardLayoutJob.cpp +++ b/src/modules/keyboard/SetKeyboardLayoutJob.cpp @@ -233,7 +233,7 @@ SetKeyboardLayoutJob::writeVConsoleData( const QString& vconsoleConfPath, const } QTextStream stream( &file ); bool found = false; - for ( const QString& existingLine : qAsConst( existingLines ) ) + for ( const QString& existingLine : std::as_const( existingLines ) ) { if ( existingLine.trimmed().startsWith( "KEYMAP=" ) ) { diff --git a/src/modules/netinstall/PackageModel.cpp b/src/modules/netinstall/PackageModel.cpp index 01a0205e7..98eb446eb 100644 --- a/src/modules/netinstall/PackageModel.cpp +++ b/src/modules/netinstall/PackageModel.cpp @@ -378,7 +378,7 @@ PackageModel::appendModelData( const QVariantList& groupList ) removeList.insert( 0, i ); } } - for ( const int& item : qAsConst( removeList ) ) + for ( const int& item : std::as_const( removeList ) ) { m_rootItem->removeChild( item ); } diff --git a/src/modules/packagechooser/PackageModel.cpp b/src/modules/packagechooser/PackageModel.cpp index d183680b0..f2a0b434d 100644 --- a/src/modules/packagechooser/PackageModel.cpp +++ b/src/modules/packagechooser/PackageModel.cpp @@ -112,7 +112,7 @@ PackageListModel::addPackage( PackageItem&& p ) QStringList PackageListModel::getInstallPackagesForName( const QString& id ) const { - for ( const auto& p : qAsConst( m_packages ) ) + for ( const auto& p : std::as_const( m_packages ) ) { if ( p.id == id ) { @@ -126,7 +126,7 @@ QStringList PackageListModel::getInstallPackagesForNames( const QStringList& ids ) const { QStringList l; - for ( const auto& p : qAsConst( m_packages ) ) + for ( const auto& p : std::as_const( m_packages ) ) { if ( ids.contains( p.id ) ) { diff --git a/src/modules/partition/PartitionViewStep.cpp b/src/modules/partition/PartitionViewStep.cpp index a5de6d5ea..e4fe1ad2c 100644 --- a/src/modules/partition/PartitionViewStep.cpp +++ b/src/modules/partition/PartitionViewStep.cpp @@ -117,7 +117,7 @@ static QStringList jobDescriptions( const Calamares::JobList& jobs ) { QStringList jobsLines; - for ( const Calamares::job_ptr& job : qAsConst( jobs ) ) + for ( const Calamares::job_ptr& job : std::as_const( jobs ) ) { const auto description = job->prettyDescription(); if ( !description.isEmpty() ) @@ -478,7 +478,7 @@ shouldWarnForGPTOnBIOS( const PartitionCoreModule* core ) if ( table && table->type() == PartitionTable::TableType::gpt ) { // So this is a BIOS system, and the bootloader will be installed on a GPT system - for ( const auto& partition : qAsConst( table->children() ) ) + for ( const auto& partition : std::as_const( table->children() ) ) { using Calamares::Units::operator""_MiB; if ( ( partition->activeFlags() & KPM_PARTITION_FLAG( BiosGrub ) ) diff --git a/src/modules/partition/core/PartitionCoreModule.cpp b/src/modules/partition/core/PartitionCoreModule.cpp index 51e99f2d2..c2fd61db9 100644 --- a/src/modules/partition/core/PartitionCoreModule.cpp +++ b/src/modules/partition/core/PartitionCoreModule.cpp @@ -619,7 +619,7 @@ findEssentialLVs( const QList< PartitionCoreModule::DeviceInfo* >& infos ) continue; } - for ( const auto& j : qAsConst( info->jobs() ) ) + for ( const auto& j : std::as_const( info->jobs() ) ) { FormatPartitionJob* format = dynamic_cast< FormatPartitionJob* >( j.data() ); if ( format ) diff --git a/src/modules/partition/core/PartitionLayout.cpp b/src/modules/partition/core/PartitionLayout.cpp index b476a3181..ff049784a 100644 --- a/src/modules/partition/core/PartitionLayout.cpp +++ b/src/modules/partition/core/PartitionLayout.cpp @@ -221,7 +221,7 @@ PartitionLayout::createPartitions( Device* dev, // Let's check if we have enough space for each partitions, using the size // propery or the min-size property if unit is in percentage. - for ( const auto& entry : qAsConst( m_partLayout ) ) + for ( const auto& entry : std::as_const( m_partLayout ) ) { if ( !entry.partSize.isValid() ) { @@ -250,7 +250,7 @@ PartitionLayout::createPartitions( Device* dev, if ( availableSectors < 0 ) { availableSectors = totalSectors; - for ( const auto& entry : qAsConst( m_partLayout ) ) + for ( const auto& entry : std::as_const( m_partLayout ) ) { qint64 sectors = partSectorsMap.value( &entry ); if ( entry.partMinSize.isValid() ) @@ -263,7 +263,7 @@ PartitionLayout::createPartitions( Device* dev, } // Assign sectors for percentage-defined partitions. - for ( const auto& entry : qAsConst( m_partLayout ) ) + for ( const auto& entry : std::as_const( m_partLayout ) ) { if ( entry.partSize.unit() == Calamares::Partition::SizeUnit::Percent ) { @@ -286,7 +286,7 @@ PartitionLayout::createPartitions( Device* dev, // Create the partitions. currentSector = firstSector; availableSectors = totalSectors; - for ( const auto& entry : qAsConst( m_partLayout ) ) + for ( const auto& entry : std::as_const( m_partLayout ) ) { // Adjust partition size based on available space. qint64 sectors = partSectorsMap.value( &entry ); diff --git a/src/modules/partition/jobs/ClearMountsJob.cpp b/src/modules/partition/jobs/ClearMountsJob.cpp index ce1355b2b..2865d9538 100644 --- a/src/modules/partition/jobs/ClearMountsJob.cpp +++ b/src/modules/partition/jobs/ClearMountsJob.cpp @@ -333,7 +333,7 @@ template < typename F > void apply( const QStringList& paths, F f, QList< MessageAndPath >& news ) { - for ( const QString& p : qAsConst( paths ) ) + for ( const QString& p : std::as_const( paths ) ) { auto n = f( p ); if ( !n.isEmpty() ) @@ -347,7 +347,7 @@ STATICTEST QStringList stringify( const QList< MessageAndPath >& news ) { QStringList l; - for ( const auto& m : qAsConst( news ) ) + for ( const auto& m : std::as_const( news ) ) { l << QString( m ); } diff --git a/src/modules/partition/jobs/ClearTempMountsJob.cpp b/src/modules/partition/jobs/ClearTempMountsJob.cpp index cb0fb572e..f231983de 100644 --- a/src/modules/partition/jobs/ClearTempMountsJob.cpp +++ b/src/modules/partition/jobs/ClearTempMountsJob.cpp @@ -56,7 +56,7 @@ ClearTempMountsJob::exec() std::sort( targetMounts.begin(), targetMounts.end(), MtabInfo::mountPointOrder ); QStringList goodNews; - for ( const auto& m : qAsConst( targetMounts ) ) + for ( const auto& m : std::as_const( targetMounts ) ) { cDebug() << o << "Will try to umount path" << m.mountPoint; if ( Calamares::Partition::unmount( m.mountPoint, { "-lv" } ) == 0 ) diff --git a/src/modules/preservefiles/PreserveFiles.cpp b/src/modules/preservefiles/PreserveFiles.cpp index 743b51fc4..8419d4c94 100644 --- a/src/modules/preservefiles/PreserveFiles.cpp +++ b/src/modules/preservefiles/PreserveFiles.cpp @@ -65,7 +65,7 @@ PreserveFiles::exec() } int count = 0; - for ( const auto& it : qAsConst( m_items ) ) + for ( const auto& it : std::as_const( m_items ) ) { if ( !it ) { diff --git a/src/modules/umount/UmountJob.cpp b/src/modules/umount/UmountJob.cpp index 1e207d9ea..f899d8e27 100644 --- a/src/modules/umount/UmountJob.cpp +++ b/src/modules/umount/UmountJob.cpp @@ -63,7 +63,7 @@ unmountTargetMounts( const QString& rootMountPoint ) std::sort( targetMounts.begin(), targetMounts.end(), MtabInfo::mountPointOrder ); cDebug() << "Read" << targetMounts.count() << "entries from" << targetMountPath; - for ( const auto& m : qAsConst( targetMounts ) ) + for ( const auto& m : std::as_const( targetMounts ) ) { // Returns the program's exit code, so 0 is success and non-0 // (truthy) is a failure. diff --git a/src/modules/welcome/checker/GeneralRequirements.cpp b/src/modules/welcome/checker/GeneralRequirements.cpp index a58f3df83..693f81248 100644 --- a/src/modules/welcome/checker/GeneralRequirements.cpp +++ b/src/modules/welcome/checker/GeneralRequirements.cpp @@ -288,7 +288,7 @@ getCheckInternetUrls( const QVariantMap& configurationMap ) if ( !checkInternetSetting.isEmpty() ) { QVector< QUrl > urls; - for ( const auto& urlString : qAsConst( checkInternetSetting ) ) + for ( const auto& urlString : std::as_const( checkInternetSetting ) ) { QUrl url( urlString.trimmed() ); if ( url.isValid() ) diff --git a/src/modules/zfs/ZfsJob.cpp b/src/modules/zfs/ZfsJob.cpp index 7181656e6..22487a838 100644 --- a/src/modules/zfs/ZfsJob.cpp +++ b/src/modules/zfs/ZfsJob.cpp @@ -193,7 +193,7 @@ ZfsJob::exec() } QVariantList zfsInfoList = gs->value( "zfsInfo" ).toList(); - for ( auto& partition : qAsConst( partitions ) ) + for ( auto& partition : std::as_const( partitions ) ) { QVariantMap pMap; if ( partition.canConvert< QVariantMap >() ) @@ -231,7 +231,7 @@ ZfsJob::exec() // Look in the zfs info list to see if this partition should be encrypted bool encrypt = false; QString passphrase; - for ( const QVariant& zfsInfo : qAsConst( zfsInfoList ) ) + for ( const QVariant& zfsInfo : std::as_const( zfsInfoList ) ) { if ( zfsInfo.canConvert< QVariantMap >() && zfsInfo.toMap().value( "encrypted" ).toBool() && mountpoint == zfsInfo.toMap().value( "mountpoint" ) ) @@ -276,7 +276,7 @@ ZfsJob::exec() { collectMountpoints( partitions ); QVariantList datasetList; - for ( const auto& dataset : qAsConst( m_datasets ) ) + for ( const auto& dataset : std::as_const( m_datasets ) ) { QVariantMap datasetMap = dataset.toMap();