Add const to almost all remaining vars and arguments that qualify

This commit is contained in:
thalieht
2019-02-21 23:31:43 +02:00
parent bb041c0eca
commit 70f1537d9f
35 changed files with 261 additions and 261 deletions

View File

@@ -81,14 +81,14 @@ QString Utils::Fs::fromNativePath(const QString &path)
*/
QString Utils::Fs::fileExtension(const QString &filename)
{
QString ext = QString(filename).remove(QB_EXT);
const QString ext = QString(filename).remove(QB_EXT);
const int pointIndex = ext.lastIndexOf('.');
return (pointIndex >= 0) ? ext.mid(pointIndex + 1) : QString();
}
QString Utils::Fs::fileName(const QString &filePath)
{
QString path = fromNativePath(filePath);
const QString path = fromNativePath(filePath);
const int slashIndex = path.lastIndexOf('/');
if (slashIndex == -1)
return path;
@@ -97,7 +97,7 @@ QString Utils::Fs::fileName(const QString &filePath)
QString Utils::Fs::folderName(const QString &filePath)
{
QString path = fromNativePath(filePath);
const QString path = fromNativePath(filePath);
const int slashIndex = path.lastIndexOf('/');
if (slashIndex == -1)
return path;
@@ -140,7 +140,7 @@ bool Utils::Fs::smartRemoveEmptyFolderTree(const QString &path)
}
// remove temp files on linux (file ends with '~'), e.g. `filename~`
QDir dir(p);
const QDir dir(p);
const QStringList tmpFileList = dir.entryList(QDir::Files);
for (const QString &f : tmpFileList) {
if (f.endsWith('~'))
@@ -188,7 +188,7 @@ void Utils::Fs::removeDirRecursive(const QString &path)
qint64 Utils::Fs::computePathSize(const QString &path)
{
// Check if it is a file
QFileInfo fi(path);
const QFileInfo fi(path);
if (!fi.exists()) return -1;
if (fi.isFile()) return fi.size();
@@ -221,7 +221,7 @@ bool Utils::Fs::sameFiles(const QString &path1, const QString &path2)
return true;
}
QString Utils::Fs::toValidFileSystemName(const QString &name, bool allowSeparators, const QString &pad)
QString Utils::Fs::toValidFileSystemName(const QString &name, const bool allowSeparators, const QString &pad)
{
const QRegularExpression regex(allowSeparators ? "[:?\"*<>|]+" : "[\\\\/:?\"*<>|]+");
@@ -232,7 +232,7 @@ QString Utils::Fs::toValidFileSystemName(const QString &name, bool allowSeparato
return validName;
}
bool Utils::Fs::isValidFileSystemName(const QString &name, bool allowSeparators)
bool Utils::Fs::isValidFileSystemName(const QString &name, const bool allowSeparators)
{
if (name.isEmpty()) return false;
@@ -272,7 +272,7 @@ bool Utils::Fs::sameFileNames(const QString &first, const QString &second)
QString Utils::Fs::expandPath(const QString &path)
{
QString ret = path.trimmed();
const QString ret = path.trimmed();
if (ret.isEmpty())
return ret;

View File

@@ -252,10 +252,10 @@ QPoint Utils::Misc::screenCenter(const QWidget *w)
{
// Returns the QPoint which the widget will be placed center on screen (where parent resides)
QWidget *parent = w->parentWidget();
QDesktopWidget *desktop = QApplication::desktop();
int scrn = desktop->screenNumber(parent); // fallback to `primaryScreen` when parent is invalid
QRect r = desktop->availableGeometry(scrn);
const QWidget *parent = w->parentWidget();
const QDesktopWidget *desktop = QApplication::desktop();
const int scrn = desktop->screenNumber(parent); // fallback to `primaryScreen` when parent is invalid
const QRect r = desktop->availableGeometry(scrn);
return {r.x() + (r.width() - w->frameSize().width()) / 2, r.y() + (r.height() - w->frameSize().height()) / 2};
}
#endif
@@ -269,7 +269,7 @@ QString Utils::Misc::unitString(const SizeUnit unit, const bool isSpeed)
return ret;
}
QString Utils::Misc::friendlyUnit(qint64 bytesValue, bool isSpeed)
QString Utils::Misc::friendlyUnit(const qint64 bytesValue, const bool isSpeed)
{
SizeUnit unit;
qreal friendlyVal;
@@ -289,7 +289,7 @@ int Utils::Misc::friendlyUnitPrecision(SizeUnit unit)
return 3;
}
qlonglong Utils::Misc::sizeInBytes(qreal size, Utils::Misc::SizeUnit unit)
qlonglong Utils::Misc::sizeInBytes(qreal size, const Utils::Misc::SizeUnit unit)
{
for (int i = 0; i < static_cast<int>(unit); ++i)
size *= 1024;
@@ -347,7 +347,7 @@ bool Utils::Misc::isPreviewable(const QString &extension)
// Take a number of seconds and return an user-friendly
// time duration like "1d 2h 10m".
QString Utils::Misc::userFriendlyDuration(qlonglong seconds)
QString Utils::Misc::userFriendlyDuration(const qlonglong seconds)
{
if ((seconds < 0) || (seconds >= MAX_ETA))
return QString::fromUtf8(C_INFINITY);
@@ -511,7 +511,7 @@ void Utils::Misc::openFolderSelect(const QString &absolutePath)
QProcess proc;
proc.start("xdg-mime", {"query", "default", "inode/directory"});
proc.waitForFinished();
QString output = proc.readLine().simplified();
const QString output = proc.readLine().simplified();
if ((output == "dolphin.desktop") || (output == "org.kde.dolphin.desktop")) {
proc.startDetached("dolphin", {"--select", Utils::Fs::toNativePath(path)});
}

View File

@@ -151,7 +151,7 @@ int Utils::String::naturalCompare(const QString &left, const QString &right, con
}
// to send numbers instead of strings with suffixes
QString Utils::String::fromDouble(double n, int precision)
QString Utils::String::fromDouble(const double n, const int precision)
{
/* HACK because QString rounds up. Eg QString::number(0.999*100.0, 'f' ,1) == 99.9
** but QString::number(0.9999*100.0, 'f' ,1) == 100.0 The problem manifests when
@@ -159,7 +159,7 @@ QString Utils::String::fromDouble(double n, int precision)
** our 'wanted' is >= 5. In this case our last digit gets rounded up. So for each
** precision we add an extra 0 behind 1 in the below algorithm. */
double prec = std::pow(10.0, precision);
const double prec = std::pow(10.0, precision);
return QLocale::system().toString(std::floor(n * prec) / prec, 'f', precision);
}