Commit dc40ea15 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

We depend against C++17 => we can use std::as_const

parent 8f4640a4
......@@ -113,7 +113,7 @@ void BatchExtract::slotStartJob()
return;
}
for (const auto& url : qAsConst(m_inputs)) {
for (const auto& url : std::as_const(m_inputs)) {
addExtraction(url);
}
......
......@@ -41,7 +41,7 @@ void ExtractHereDndPlugin::slotTriggered()
batchJob->setAutoSubfolder(true);
batchJob->setDestinationFolder(m_dest.toDisplayString(QUrl::PreferLocalFile));
batchJob->setPreservePaths(true);
for (const QUrl& url : qAsConst(m_urls)) {
for (const QUrl& url : std::as_const(m_urls)) {
batchJob->addInput(url);
}
......
......@@ -158,7 +158,7 @@ void AddTest::testAdding()
QStringList oldPaths = getEntryPaths(archive);
// Check that the expected paths (after the AddJob) are not in the archive.
for (const auto &expectedPath : qAsConst(expectedNewPaths)) {
for (const auto &expectedPath : std::as_const(expectedNewPaths)) {
QVERIFY(!oldPaths.contains(expectedPath));
}
......@@ -171,7 +171,7 @@ void AddTest::testAdding()
QStringList newPaths = getEntryPaths(archive);
// Check that the expected paths are now in the archive.
for (const auto &path : qAsConst(expectedNewPaths)) {
for (const auto &path : std::as_const(expectedNewPaths)) {
QVERIFY(newPaths.contains(path));
}
......
......@@ -221,7 +221,7 @@ void AddToArchiveTest::testCompressHere()
}
QFETCH(QStringList, inputFiles);
for (const QString &file : qAsConst(inputFiles)) {
for (const QString &file : std::as_const(inputFiles)) {
addToArchiveJob->addInput(QUrl::fromUserInput(file));
}
......
......@@ -267,12 +267,12 @@ void CopyTest::testCopying()
QStringList oldPaths = getEntryPaths(archive);
// Check that the entries to be copied are in the archive.
for (const auto entry : qAsConst(targetEntries)) {
for (const auto entry : std::as_const(targetEntries)) {
QVERIFY(oldPaths.contains(entry->fullPath()));
}
// Check that the expected paths (after the CopyJob) are not in the archive.
for (const auto &expectedPath : qAsConst(expectedNewPaths)) {
for (const auto &expectedPath : std::as_const(expectedNewPaths)) {
QVERIFY(!oldPaths.contains(expectedPath));
}
......@@ -285,12 +285,12 @@ void CopyTest::testCopying()
QStringList newPaths = getEntryPaths(archive);
// Check that the expected paths are now in the archive.
for (const auto &path : qAsConst(expectedNewPaths)) {
for (const auto &path : std::as_const(expectedNewPaths)) {
QVERIFY(newPaths.contains(path));
}
// Check also that the target paths are still in the archive.
for (const auto entry : qAsConst(targetEntries)) {
for (const auto entry : std::as_const(targetEntries)) {
QVERIFY(newPaths.contains(entry->fullPath()));
}
......
......@@ -318,7 +318,7 @@ void JobsTest::testRemoveEntries()
QStringList fullPathsToDelete = iface->entryFullPaths(entriesToDelete);
QVector<Archive::Entry*> expectedRemainingEntries;
for (Archive::Entry *entry : qAsConst(entries)) {
for (Archive::Entry *entry : std::as_const(entries)) {
if (!fullPathsToDelete.contains(entry->fullPath())) {
expectedRemainingEntries.append(entry);
}
......@@ -412,7 +412,7 @@ void JobsTest::testAddEntries()
QFETCH(QVector<Archive::Entry*>, originalEntries);
QStringList originalFullPaths = QStringList();
for (const Archive::Entry *entry : qAsConst(originalEntries)) {
for (const Archive::Entry *entry : std::as_const(originalEntries)) {
originalFullPaths.append(entry->fullPath());
}
auto currentEntries = listEntries(iface);
......@@ -426,7 +426,7 @@ void JobsTest::testAddEntries()
QStringList expectedAddedFullPaths = QStringList();
const QString destinationPath = destinationEntry->fullPath();
int expectedEntriesCount = originalEntries.size();
for (const Archive::Entry *entry : qAsConst(entriesToAdd)) {
for (const Archive::Entry *entry : std::as_const(entriesToAdd)) {
const QString fullPath = destinationPath + entry->fullPath();
if (!originalFullPaths.contains(fullPath)) {
expectedEntriesCount++;
......@@ -438,11 +438,11 @@ void JobsTest::testAddEntries()
QCOMPARE(currentEntries.size(), expectedEntriesCount);
QStringList currentFullPaths = QStringList();
for (const Archive::Entry* entry : qAsConst(currentEntries)) {
for (const Archive::Entry* entry : std::as_const(currentEntries)) {
currentFullPaths << entry->fullPath();
}
for (const QString &fullPath : qAsConst(expectedAddedFullPaths)) {
for (const QString &fullPath : std::as_const(expectedAddedFullPaths)) {
QVERIFY(currentFullPaths.contains(fullPath));
}
......
......@@ -57,7 +57,7 @@ void MetaDataTest::testPluginLoading()
void MetaDataTest::testPluginMetadata()
{
for (const KPluginMetaData& metaData : qAsConst(m_plugins)) {
for (const KPluginMetaData& metaData : std::as_const(m_plugins)) {
QVERIFY(!metaData.mimeTypes().isEmpty());
const QJsonObject json = metaData.rawData();
......
......@@ -230,12 +230,12 @@ void MoveTest::testMoving()
QStringList oldPaths = getEntryPaths(archive);
// Check that the entries to be moved are in the archive.
for (const auto entry : qAsConst(targetEntries)) {
for (const auto entry : std::as_const(targetEntries)) {
QVERIFY(oldPaths.contains(entry->fullPath()));
}
// Check that the expected paths (after the MoveJob) are not in the archive.
for (const auto &expectedPath : qAsConst(expectedNewPaths)) {
for (const auto &expectedPath : std::as_const(expectedNewPaths)) {
QVERIFY(!oldPaths.contains(expectedPath));
}
......@@ -248,12 +248,12 @@ void MoveTest::testMoving()
QStringList newPaths = getEntryPaths(archive);
// Check that the expected paths are now in the archive.
for (const auto &path : qAsConst(expectedNewPaths)) {
for (const auto &path : std::as_const(expectedNewPaths)) {
QVERIFY(newPaths.contains(path));
}
// Check that the target paths are no longer in the archive.
for (const auto entry : qAsConst(targetEntries)) {
for (const auto entry : std::as_const(targetEntries)) {
QVERIFY(!newPaths.contains(entry->fullPath()));
}
......
......@@ -460,7 +460,7 @@ void Cli7zTest::testExtractArgs()
QFETCH(QVector<Archive::Entry*>, files);
QStringList filesList;
for (const Archive::Entry *e : qAsConst(files)) {
for (const Archive::Entry *e : std::as_const(files)) {
filesList << e->fullPath(NoTrailingSlash);
}
......
......@@ -510,7 +510,7 @@ void CliRarTest::testExtractArgs()
QFETCH(QVector<Archive::Entry*>, files);
QStringList filesList;
for (const Archive::Entry *e : qAsConst(files)) {
for (const Archive::Entry *e : std::as_const(files)) {
filesList << e->fullPath(NoTrailingSlash);
}
......
......@@ -403,7 +403,7 @@ void CliUnarchiverTest::testExtractArgs()
QFETCH(QVector<Archive::Entry*>, files);
QStringList filesList;
for (const Archive::Entry *e : qAsConst(files)) {
for (const Archive::Entry *e : std::as_const(files)) {
filesList << e->fullPath(NoTrailingSlash);
}
......
......@@ -231,7 +231,7 @@ void CliZipTest::testExtractArgs()
QFETCH(QVector<Archive::Entry*>, files);
QStringList filesList;
for (const Archive::Entry *e : qAsConst(files)) {
for (const Archive::Entry *e : std::as_const(files)) {
filesList << e->fullPath(NoTrailingSlash);
}
......
......@@ -180,7 +180,7 @@ void AddToArchive::slotStartJob()
const QDir stripDir(m_firstPath);
for (Archive::Entry *entry : qAsConst(m_entries)) {
for (Archive::Entry *entry : std::as_const(m_entries)) {
entry->setFullPath(stripDir.absoluteFilePath(entry->fullPath()));
}
......
......@@ -166,7 +166,7 @@ int Archive::Entry::row() const
Archive::Entry *Archive::Entry::find(QStringView name) const
{
for (Entry *entry : qAsConst(m_entries)) {
for (Entry *entry : std::as_const(m_entries)) {
if (entry && (entry->nameView() == name)) {
return entry;
}
......
......@@ -184,7 +184,7 @@ QVector<Archive::Entry*> ReadOnlyArchiveInterface::entriesWithoutChildren(const
QVector<Archive::Entry*> filteredEntries;
QString lastFolder;
for (Archive::Entry *entry : qAsConst(sortedEntries)) {
for (Archive::Entry *entry : std::as_const(sortedEntries)) {
if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) {
continue;
}
......@@ -205,7 +205,7 @@ QStringList ReadOnlyArchiveInterface::entryPathsFromDestination(QStringList entr
QString newPath;
int nameLength = 0;
for (const QString &entryPath : qAsConst(entries)) {
for (const QString &entryPath : std::as_const(entries)) {
if (lastFolder.count() > 0 && entryPath.startsWith(lastFolder)) {
// Replace last moved or copied folder path with destination path.
int charsCount = entryPath.count() - lastFolder.count();
......
......@@ -323,7 +323,7 @@ void CliInterface::processFinished(int exitCode, QProcess::ExitStatus exitStatus
for (const QString &fullPath : removedFullPaths) {
Q_EMIT entryRemoved(fullPath);
}
for (Archive::Entry *e : qAsConst(m_newMovedFiles)) {
for (Archive::Entry *e : std::as_const(m_newMovedFiles)) {
Q_EMIT entry(e);
}
m_newMovedFiles.clear();
......@@ -649,7 +649,7 @@ void CliInterface::setNewMovedFiles(const QVector<Archive::Entry*> &entries, con
QString newPath;
int nameLength = 0;
for (const Archive::Entry* entry : qAsConst(entryMap)) {
for (const Archive::Entry* entry : std::as_const(entryMap)) {
if (lastFolder.count() > 0 && entry->fullPath().startsWith(lastFolder)) {
// Replace last moved or copied folder path with destination path.
int charsCount = entry->fullPath().count() - lastFolder.count();
......@@ -810,7 +810,7 @@ void CliInterface::readStdout(bool handleAll)
m_stdOutData = lines.takeLast();
}
for (const QByteArray& line : qAsConst(lines)) {
for (const QByteArray& line : std::as_const(lines)) {
if (!line.isEmpty() || (m_listEmptyLines && m_operationMode == List)) {
if (!handleLine(QString::fromLocal8Bit(line))) {
killProcess();
......@@ -823,7 +823,7 @@ void CliInterface::readStdout(bool handleAll)
bool CliInterface::setAddedFiles()
{
QDir::setCurrent(m_tempAddDir->path());
for (const Archive::Entry *file : qAsConst(m_passedFiles)) {
for (const Archive::Entry *file : std::as_const(m_passedFiles)) {
const QString oldPath = m_tempWorkingDir->path() + QLatin1Char('/') + file->fullPath(NoTrailingSlash);
const QString newPath = m_tempAddDir->path() + QLatin1Char('/') + file->name();
if (!QFile::rename(oldPath, newPath)) {
......
......@@ -47,7 +47,7 @@ QStringList CliProperties::addArgs(const QString &archive, const QStringList &fi
}
QStringList args;
for (const QString &s : qAsConst(m_addSwitch)) {
for (const QString &s : std::as_const(m_addSwitch)) {
args << s;
}
if (!password.isEmpty()) {
......@@ -124,7 +124,7 @@ QStringList CliProperties::extractArgs(const QString &archive, const QStringList
QStringList CliProperties::listArgs(const QString &archive, const QString &password)
{
QStringList args;
for (const QString &s : qAsConst(m_listSwitch)) {
for (const QString &s : std::as_const(m_listSwitch)) {
args << s;
}
......@@ -161,7 +161,7 @@ QStringList CliProperties::moveArgs(const QString &archive, const QVector<Archiv
QStringList CliProperties::testArgs(const QString &archive, const QString &password)
{
QStringList args;
for (const QString &s : qAsConst(m_testSwitch)) {
for (const QString &s : std::as_const(m_testSwitch)) {
args << s;
}
if (!password.isEmpty()) {
......@@ -293,7 +293,7 @@ QString CliProperties::substituteMultiVolumeSwitch(ulong volumeSize) const
bool CliProperties::isTestPassedMsg(const QString &line)
{
for (const QString &rx : qAsConst(m_testPassedPatterns)) {
for (const QString &rx : std::as_const(m_testPassedPatterns)) {
if (QRegularExpression(rx).match(line).hasMatch()) {
return true;
}
......
......@@ -77,7 +77,7 @@ CreateDialog::CreateDialog(QWidget *parent,
}
// Populate combobox with mimetypes.
for (const QString &type : qAsConst(m_supportedMimeTypes)) {
for (const QString &type : std::as_const(m_supportedMimeTypes)) {
m_ui->mimeComboBox->addItem(QMimeDatabase().mimeTypeForName(type).comment());
}
......
......@@ -654,7 +654,7 @@ void AddJob::doWork()
uint totalCount = 0;
QElapsedTimer timer;
timer.start();
for (const Archive::Entry* entry : qAsConst(m_entries)) {
for (const Archive::Entry* entry : std::as_const(m_entries)) {
totalCount++;
if (QFileInfo(entry->fullPath()).isDir()) {
QDirIterator it(entry->fullPath(), QDir::AllEntries | QDir::Readable | QDir::Hidden | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
......@@ -676,7 +676,7 @@ void AddJob::doWork()
Q_ASSERT(m_writeInterface);
// The file paths must be relative to GlobalWorkDir.
for (Archive::Entry *entry : qAsConst(m_entries)) {
for (Archive::Entry *entry : std::as_const(m_entries)) {
// #191821: workDir must be used instead of QDir::current()
// so that symlinks aren't resolved automatically
const QString &fullPath = entry->fullPath();
......
......@@ -56,7 +56,7 @@ QVector<Plugin*> PluginManager::installedPlugins() const
QVector<Plugin*> PluginManager::availablePlugins() const
{
QVector<Plugin*> availablePlugins;
for (Plugin *plugin : qAsConst(m_plugins)) {
for (Plugin *plugin : std::as_const(m_plugins)) {
if (plugin->isValid()) {
availablePlugins << plugin;
}
......@@ -81,7 +81,7 @@ QVector<Plugin*> PluginManager::availableWritePlugins() const
QVector<Plugin*> PluginManager::enabledPlugins() const
{
QVector<Plugin*> enabledPlugins;
for (Plugin *plugin : qAsConst(m_plugins)) {
for (Plugin *plugin : std::as_const(m_plugins)) {
if (plugin->isEnabled()) {
enabledPlugins << plugin;
}
......@@ -253,7 +253,7 @@ QStringList PluginManager::sortByComment(const QSet<QString> &mimeTypes)
// Convert to sorted QStringList.
QStringList sortedMimeTypes;
for (const QString &value : qAsConst(map)) {
for (const QString &value : std::as_const(map)) {
sortedMimeTypes << value;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment