From dcbab3b5ddb2ed3e603d9a59e210ed60aa8856f1 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Fri, 11 Aug 2023 14:30:16 +0300 Subject: [PATCH] QmlDesigner: Load effect maker nodes from path ...instead of from Qt SDK Change-Id: I10d3104477b7cd7c729121175c66a7402ea49651 Reviewed-by: Amr Elsayed Reviewed-by: Miikka Heikkinen --- .../effectmaker/effectmakernodesmodel.cpp | 45 +++++++++++-------- .../effectmaker/effectmakernodesmodel.h | 12 ++--- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp b/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp index 1c7ff72de1c..e86a7eaf8e6 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp @@ -3,13 +3,9 @@ #include "effectmakernodesmodel.h" -#include -#include -#include +#include -#include - -#include +#include namespace QmlDesigner { @@ -42,29 +38,42 @@ QVariant EffectMakerNodesModel::data(const QModelIndex &index, int role) const return m_categories.at(index.row())->property(roleNames().value(role)); } -// static -Utils::FilePath EffectMakerNodesModel::getQmlEffectNodesPath() +void EffectMakerNodesModel::findNodesPath() { - const ProjectExplorer::Target *target = ProjectExplorer::ProjectTree::currentTarget(); - if (!target) { - qWarning() << __FUNCTION__ << "No project open"; - return ""; + if (m_nodesPath.exists() || m_probeNodesDir) + return; + + QDir nodesDir; + + if (!qEnvironmentVariable("EFFECT_MAKER_NODES_PATH").isEmpty()) + nodesDir.setPath(qEnvironmentVariable("EFFECT_MAKER_NODES_PATH")); + else if (Utils::HostOsInfo::isMacHost()) + nodesDir.setPath(QCoreApplication::applicationDirPath() + "/../Resources/effect_maker_nodes"); + + // search for nodesDir from exec dir and up + if (nodesDir.dirName() == ".") { + m_probeNodesDir = true; // probe only once + nodesDir.setPath(QCoreApplication::applicationDirPath()); + while (!nodesDir.cd("effect_maker_nodes") && nodesDir.cdUp()) + ; // do nothing + + if (nodesDir.dirName() != "effect_maker_nodes") // bundlePathDir not found + return; } - const QtSupport::QtVersion *baseQtVersion = QtSupport::QtKitAspect::qtVersion(target->kit()); - return baseQtVersion->qmlPath().pathAppended("QtQuickEffectMaker/defaultnodes"); + m_nodesPath = Utils::FilePath::fromString(nodesDir.path()); } void EffectMakerNodesModel::loadModel() { - const Utils::FilePath effectsPath = getQmlEffectNodesPath(); + findNodesPath(); - if (!effectsPath.exists()) { + if (!m_nodesPath.exists()) { qWarning() << __FUNCTION__ << "Effects not found."; return; } - QDirIterator itCategories(effectsPath.toString(), QDir::Dirs | QDir::NoDotAndDotDot); + QDirIterator itCategories(m_nodesPath.toString(), QDir::Dirs | QDir::NoDotAndDotDot); while (itCategories.hasNext()) { itCategories.next(); @@ -72,7 +81,7 @@ void EffectMakerNodesModel::loadModel() continue; QList effects = {}; - Utils::FilePath categoryPath = effectsPath.resolvePath(itCategories.fileName()); + Utils::FilePath categoryPath = m_nodesPath.resolvePath(itCategories.fileName()); QDirIterator itEffects(categoryPath.toString(), QDir::Files | QDir::NoDotAndDotDot); while (itEffects.hasNext()) { itEffects.next(); diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.h b/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.h index 022111ea2c0..5ed702f84be 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.h +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.h @@ -3,13 +3,11 @@ #pragma once -#include - #include "effectnodescategory.h" -namespace Utils { -class FilePath; -} +#include + +#include namespace QmlDesigner { @@ -35,9 +33,11 @@ public: QList categories() const { return m_categories; } private: - static Utils::FilePath getQmlEffectNodesPath(); + void findNodesPath(); QList m_categories; + Utils::FilePath m_nodesPath; + bool m_probeNodesDir = false; }; } // namespace QmlDesigner