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.
This commit is contained in:
Adriaan de Groot 2024-12-02 12:48:43 +01:00
parent ba96a39ca0
commit 196f85fa2c
15 changed files with 26 additions and 26 deletions

View File

@ -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 );

View File

@ -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 )
{

View File

@ -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" ) );

View File

@ -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=" ) )
{

View File

@ -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 );
}

View File

@ -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 ) )
{

View File

@ -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 ) )

View File

@ -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 )

View File

@ -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 );

View File

@ -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 );
}

View File

@ -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 )

View File

@ -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 )
{

View File

@ -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.

View File

@ -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() )

View File

@ -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();