From 87746b590639f9d63dc389847c4b795025a277d7 Mon Sep 17 00:00:00 2001 From: Tim Jenssen Date: Fri, 18 Jan 2019 20:28:55 +0100 Subject: [PATCH] QmlJS: improve code - no behavior change Change-Id: I61e515876be768309e5647261ffbe2732de423b9 Reviewed-by: Ulf Hermann Reviewed-by: Orgad Shaneh --- src/libs/qmljs/qmljsmodelmanagerinterface.cpp | 22 +++++++++---------- src/libs/qmljs/qmljsmodelmanagerinterface.h | 12 +++++----- src/libs/qmljs/qmljsqrcparser.cpp | 2 +- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp index 9fa907ccfae..82d4da3f4a6 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.cpp +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.cpp @@ -83,11 +83,11 @@ static QStringList environmentImportPaths() { QStringList paths; - QByteArray envImportPath = qgetenv("QML_IMPORT_PATH"); + const QStringList importPaths = QString::fromLocal8Bit(qgetenv("QML_IMPORT_PATH")).split( + Utils::HostOsInfo::pathListSeparator(), QString::SkipEmptyParts); - foreach (const QString &path, QString::fromLatin1(envImportPath) - .split(Utils::HostOsInfo::pathListSeparator(), QString::SkipEmptyParts)) { - QString canonicalPath = QDir(path).canonicalPath(); + for (const QString &path : importPaths) { + const QString canonicalPath = QDir(path).canonicalPath(); if (!canonicalPath.isEmpty() && !paths.contains(canonicalPath)) paths.append(canonicalPath); } @@ -97,11 +97,10 @@ static QStringList environmentImportPaths() ModelManagerInterface::ModelManagerInterface(QObject *parent) : QObject(parent), - m_shouldScanImports(false), - m_defaultProject(nullptr), + m_defaultImportPaths(environmentImportPaths()), m_pluginDumper(new PluginDumper(this)) { - m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1"; + m_indexerDisabled = qEnvironmentVariableIsSet("QTC_NO_CODE_INDEXER"); m_updateCppQmlTypesTimer = new QTimer(this); m_updateCppQmlTypesTimer->setInterval(1000); @@ -123,7 +122,6 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent) m_defaultProjectInfo.qtQmlPath = QFileInfo( QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath)).canonicalFilePath(); - m_defaultImportPaths << environmentImportPaths(); updateImportPaths(); Q_ASSERT(! g_instance); @@ -298,7 +296,7 @@ Snapshot ModelManagerInterface::newestSnapshot() const void ModelManagerInterface::updateSourceFiles(const QStringList &files, bool emitDocumentOnDiskChanged) { - if (!m_indexerEnabled) + if (m_indexerDisabled) return; refreshSourceFiles(files, emitDocumentOnDiskChanged); } @@ -514,7 +512,7 @@ ModelManagerInterface::ProjectInfo ModelManagerInterface::projectInfo( void ModelManagerInterface::updateProjectInfo(const ProjectInfo &pinfo, ProjectExplorer::Project *p) { - if (! pinfo.isValid() || !p || !m_indexerEnabled) + if (! pinfo.isValid() || !p || m_indexerDisabled) return; Snapshot snapshot; @@ -1063,7 +1061,7 @@ QmlLanguageBundles ModelManagerInterface::extendedBundles() const void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths) { - if (!m_indexerEnabled) + if (m_indexerDisabled) return; PathsAndLanguages pathToScan; { @@ -1086,7 +1084,7 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths) void ModelManagerInterface::updateImportPaths() { - if (!m_indexerEnabled) + if (m_indexerDisabled) return; PathsAndLanguages allImportPaths; QmlLanguageBundles activeBundles; diff --git a/src/libs/qmljs/qmljsmodelmanagerinterface.h b/src/libs/qmljs/qmljsmodelmanagerinterface.h index 4b3e2a1a586..5de25eead36 100644 --- a/src/libs/qmljs/qmljsmodelmanagerinterface.h +++ b/src/libs/qmljs/qmljsmodelmanagerinterface.h @@ -265,11 +265,11 @@ private: QmlJS::QmlLanguageBundles m_activeBundles; QmlJS::QmlLanguageBundles m_extendedBundles; QHash m_defaultVContexts; - bool m_shouldScanImports; + bool m_shouldScanImports = false; QSet m_scannedPaths; - QTimer *m_updateCppQmlTypesTimer; - QTimer *m_asyncResetTimer; + QTimer *m_updateCppQmlTypesTimer = nullptr; + QTimer *m_asyncResetTimer = nullptr; QHash > m_queuedCppDocuments; QFuture m_cppQmlTypesUpdater; QrcCache m_qrcCache; @@ -282,13 +282,13 @@ private: // project integration QMap m_projects; ProjectInfo m_defaultProjectInfo; - ProjectExplorer::Project *m_defaultProject; + ProjectExplorer::Project *m_defaultProject = nullptr; QMultiHash m_fileToProject; - PluginDumper *m_pluginDumper; + PluginDumper *m_pluginDumper = nullptr; QList> m_futures; - bool m_indexerEnabled; + bool m_indexerDisabled = false; }; } // namespace QmlJS diff --git a/src/libs/qmljs/qmljsqrcparser.cpp b/src/libs/qmljs/qmljsqrcparser.cpp index bd5d5b7e034..0a68ebe2fbf 100644 --- a/src/libs/qmljs/qmljsqrcparser.cpp +++ b/src/libs/qmljs/qmljsqrcparser.cpp @@ -418,7 +418,7 @@ void QrcParserPrivate::collectResourceFilesForSourceFile(const QString &sourceFi QStringList *results, const QLocale *locale) const { - // TODO: use FileName from fileutils for file pathes + // TODO: use FileName from fileutils for file paths QStringList langs = allUiLanguages(locale); SMap::const_iterator file = m_files.find(sourceFile);