From ca6d4a88779ce571c97cdd2f0425ff1506d797d2 Mon Sep 17 00:00:00 2001 From: Thomas Hartmann Date: Mon, 12 Feb 2018 16:54:52 +0100 Subject: [PATCH] QmlDesigner: Add static helper functions Change-Id: If89619a7fe75b09afa53e2b33464364deccfcaee Reviewed-by: Tim Jenssen --- src/plugins/qmldesigner/documentmanager.cpp | 33 +++++++++++++++++++++ src/plugins/qmldesigner/documentmanager.h | 2 ++ 2 files changed, 35 insertions(+) diff --git a/src/plugins/qmldesigner/documentmanager.cpp b/src/plugins/qmldesigner/documentmanager.cpp index e5ec89524a2..1e3a3b6d7b6 100644 --- a/src/plugins/qmldesigner/documentmanager.cpp +++ b/src/plugins/qmldesigner/documentmanager.cpp @@ -81,6 +81,7 @@ static inline QHash getProperties(const ModelNode &node) propertyHash.remove("opacity"); } } + return propertyHash; } @@ -326,6 +327,21 @@ Utils::FileName DocumentManager::currentFilePath() return QmlDesignerPlugin::instance()->documentManager().currentDesignDocument()->fileName(); } +Utils::FileName DocumentManager::currentProjectDirPath() +{ + QTC_ASSERT(QmlDesignerPlugin::instance(), return {}); + + if (!QmlDesignerPlugin::instance()->currentDesignDocument()) + return {}; + + Utils::FileName qmlFileName = QmlDesignerPlugin::instance()->currentDesignDocument()->fileName(); + ProjectExplorer::Project *project = ProjectExplorer::SessionManager::projectForFile(qmlFileName); + if (!project) + return {}; + + return project->projectDirectory(); +} + QStringList DocumentManager::isoIconsQmakeVariableValue(const QString &proPath) { ProjectExplorer::Node *node = ProjectExplorer::ProjectTree::nodeForFile(Utils::FileName::fromString(proPath)); @@ -463,5 +479,22 @@ bool DocumentManager::addResourceFileToIsoProject(const QString &resourceFilePro return true; } +bool DocumentManager::belongsToQmakeProject() +{ + QTC_ASSERT(QmlDesignerPlugin::instance(), return false); + + if (!QmlDesignerPlugin::instance()->currentDesignDocument()) + return false; + + Utils::FileName qmlFileName = QmlDesignerPlugin::instance()->currentDesignDocument()->fileName(); + ProjectExplorer::Project *project = ProjectExplorer::SessionManager::projectForFile(qmlFileName); + if (!project) + return false; + + ProjectExplorer::Node *rootNode = project->rootProjectNode(); + QmakeProjectManager::QmakeProFileNode *proNode = dynamic_cast(rootNode); + return proNode; +} + } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/documentmanager.h b/src/plugins/qmldesigner/documentmanager.h index 7e4da751879..d62ee85348a 100644 --- a/src/plugins/qmldesigner/documentmanager.h +++ b/src/plugins/qmldesigner/documentmanager.h @@ -56,6 +56,7 @@ public: static bool createFile(const QString &filePath, const QString &contents); static void addFileToVersionControl(const QString &directoryPath, const QString &newFilePath); static Utils::FileName currentFilePath(); + static Utils::FileName currentProjectDirPath(); static QStringList isoIconsQmakeVariableValue(const QString &proPath); static bool setIsoIconsQmakeVariableValue(const QString &proPath, const QStringList &value); @@ -63,6 +64,7 @@ public: QString *resourceFileProPath, const QString &isoIconsQrcFile); static bool isoProFileSupportsAddingExistingFiles(const QString &resourceFileProPath); static bool addResourceFileToIsoProject(const QString &resourceFileProPath, const QString &resourceFilePath); + static bool belongsToQmakeProject(); private: QHash > m_designDocumentHash;