QmlProject: Simplify interface a bit

Remove unneeded code and don't repeately fetch a singleton value.

Change-Id: I718a44c28be7ef8718f813f987f45b32cbcd7ad5
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
hjk
2017-03-14 11:18:09 +01:00
parent 5d1e12faad
commit df73d57295
2 changed files with 10 additions and 27 deletions

View File

@@ -145,8 +145,8 @@ void QmlProject::parseProject(RefreshOptions options)
}
if (m_projectItem) {
m_projectItem.data()->setSourceDirectory(projectDir().path());
if (modelManager())
modelManager()->updateSourceFiles(m_projectItem.data()->files(), true);
if (auto modelManager = QmlJS::ModelManagerInterface::instance())
modelManager->updateSourceFiles(m_projectItem.data()->files(), true);
QString mainFilePath = m_projectItem.data()->mainFile();
if (!mainFilePath.isEmpty()) {
@@ -180,37 +180,21 @@ void QmlProject::refresh(RefreshOptions options)
if (options & Files)
generateProjectTree();
if (!modelManager())
auto modelManager = QmlJS::ModelManagerInterface::instance();
if (!modelManager)
return;
QmlJS::ModelManagerInterface::ProjectInfo projectInfo =
modelManager()->defaultProjectInfoForProject(this);
modelManager->defaultProjectInfoForProject(this);
foreach (const QString &searchPath, customImportPaths())
projectInfo.importPaths.maybeInsert(Utils::FileName::fromString(searchPath),
QmlJS::Dialect::Qml);
modelManager()->updateProjectInfo(projectInfo, this);
modelManager->updateProjectInfo(projectInfo, this);
emit parsingFinished();
}
QStringList QmlProject::convertToAbsoluteFiles(const QStringList &paths) const
{
const QDir projectDir(projectDirectory().toString());
QStringList absolutePaths;
foreach (const QString &file, paths) {
QFileInfo fileInfo(projectDir, file);
absolutePaths.append(fileInfo.absoluteFilePath());
}
absolutePaths.removeDuplicates();
return absolutePaths;
}
QmlJS::ModelManagerInterface *QmlProject::modelManager() const
{
return QmlJS::ModelManagerInterface::instance();
}
QStringList QmlProject::files() const
{
QStringList files;
@@ -265,8 +249,10 @@ QmlProject::QmlImport QmlProject::defaultImport() const
void QmlProject::refreshFiles(const QSet<QString> &/*added*/, const QSet<QString> &removed)
{
refresh(Files);
if (!removed.isEmpty() && modelManager())
modelManager()->removeFiles(removed.toList());
if (!removed.isEmpty()) {
if (auto modelManager = QmlJS::ModelManagerInterface::instance())
modelManager->removeFiles(removed.toList());
}
}
QString QmlProject::displayName() const

View File

@@ -33,7 +33,6 @@
#include <QPointer>
namespace ProjectExplorer { class RunConfiguration; }
namespace QmlJS { class ModelManagerInterface; }
namespace QmlProjectManager {
@@ -91,8 +90,6 @@ private:
// plain format
void parseProject(RefreshOptions options);
QStringList convertToAbsoluteFiles(const QStringList &paths) const;
QmlJS::ModelManagerInterface *modelManager() const;
QmlImport m_defaultImport;
ProjectExplorer::Target *m_activeTarget = 0;