App/aggregation: Some modernization

Change-Id: I390e81122453d20a646af4a5bf08edf9de0d9db5
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2020-02-14 08:25:22 +01:00
parent f9e7a0d44a
commit edbdb4436c
3 changed files with 16 additions and 18 deletions

View File

@@ -190,8 +190,7 @@ static inline int askMsgSendFailed()
}
// taken from utils/fileutils.cpp. We cannot use utils here since that depends app_version.h.
static bool copyRecursively(const QString &srcFilePath,
const QString &tgtFilePath)
static bool copyRecursively(const QString &srcFilePath, const QString &tgtFilePath)
{
QFileInfo srcFileInfo(srcFilePath);
if (srcFileInfo.isDir()) {
@@ -200,12 +199,11 @@ static bool copyRecursively(const QString &srcFilePath,
if (!targetDir.mkdir(Utils::FilePath::fromString(tgtFilePath).fileName()))
return false;
QDir sourceDir(srcFilePath);
QStringList fileNames = sourceDir.entryList(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
foreach (const QString &fileName, fileNames) {
const QString newSrcFilePath
= srcFilePath + QLatin1Char('/') + fileName;
const QString newTgtFilePath
= tgtFilePath + QLatin1Char('/') + fileName;
const QStringList fileNames = sourceDir.entryList
(QDir::Files | QDir::Dirs | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System);
for (const QString &fileName : fileNames) {
const QString newSrcFilePath = srcFilePath + '/' + fileName;
const QString newTgtFilePath = tgtFilePath + '/' + fileName;
if (!copyRecursively(newSrcFilePath, newTgtFilePath))
return false;
}
@@ -300,8 +298,8 @@ static inline QSettings *userSettings()
if (srcDir == destDir) // Nothing to copy and no settings yet
return settings;
QStringList entries = srcDir.entryList();
foreach (const QString &file, entries) {
const QStringList entries = srcDir.entryList();
for (const QString &file : entries) {
const QString lowerFile = file.toLower();
if (lowerFile.startsWith(QLatin1String("profiles.xml"))
|| lowerFile.startsWith(QLatin1String("toolchains.xml"))
@@ -349,7 +347,8 @@ void loadFonts()
{
const QDir dir(resourcePath() + "/fonts/");
foreach (const QFileInfo &fileInfo, dir.entryInfoList(QStringList("*.ttf"), QDir::Files))
const QFileInfoList fonts = dir.entryInfoList(QStringList("*.ttf"), QDir::Files);
for (const QFileInfo &fileInfo : fonts)
QFontDatabase::addApplicationFont(fileInfo.absoluteFilePath());
}
@@ -555,13 +554,12 @@ int main(int argc, char **argv)
QTranslator translator;
QTranslator qtTranslator;
QStringList uiLanguages;
uiLanguages = QLocale::system().uiLanguages();
QStringList uiLanguages = QLocale::system().uiLanguages();
QString overrideLanguage = settings->value(QLatin1String("General/OverrideLanguage")).toString();
if (!overrideLanguage.isEmpty())
uiLanguages.prepend(overrideLanguage);
const QString &creatorTrPath = resourcePath() + "/translations";
foreach (QString locale, uiLanguages) {
for (QString locale : qAsConst(uiLanguages)) {
locale = QLocale(locale).name();
if (translator.load("qtcreator_" + locale, creatorTrPath)) {
const QString &qtTrPath = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
@@ -614,7 +612,7 @@ int main(int argc, char **argv)
const PluginSpecSet plugins = PluginManager::plugins();
PluginSpec *coreplugin = nullptr;
foreach (PluginSpec *spec, plugins) {
for (PluginSpec *spec : plugins) {
if (spec->name() == QLatin1String(corePluginNameC)) {
coreplugin = spec;
break;

View File

@@ -207,7 +207,7 @@ Aggregate::~Aggregate()
QList<QObject *> components;
{
QWriteLocker locker(&lock());
foreach (QObject *component, m_components) {
for (QObject *component : qAsConst(m_components)) {
disconnect(component, &QObject::destroyed, this, &Aggregate::deleteSelf);
aggregateMap().remove(component);
}

View File

@@ -48,7 +48,7 @@ public:
template <typename T> T *component() {
QReadLocker locker(&lock());
foreach (QObject *component, m_components) {
for (QObject *component : qAsConst(m_components)) {
if (T *result = qobject_cast<T *>(component))
return result;
}
@@ -58,7 +58,7 @@ public:
template <typename T> QList<T *> components() {
QReadLocker locker(&lock());
QList<T *> results;
foreach (QObject *component, m_components) {
for (QObject *component : qAsConst(m_components)) {
if (T *result = qobject_cast<T *>(component)) {
results << result;
}