From e740bc076c3c81179b3027f58459e1f3ffd9f7c2 Mon Sep 17 00:00:00 2001 From: Mahmoud Badri Date: Fri, 17 Nov 2023 18:24:35 +0200 Subject: [PATCH] EffectMaker: Load effect nodes from share folder Change-Id: Ie7b1c95d6eb277c01310d9badc1b755e0517385c Reviewed-by: Qt CI Patch Build Bot Reviewed-by: Miikka Heikkinen --- .../effectmakernew/effectmakernodesmodel.cpp | 41 ++++++------------- .../effectmakernew/effectmakernodesmodel.h | 5 +-- 2 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/plugins/effectmakernew/effectmakernodesmodel.cpp b/src/plugins/effectmakernew/effectmakernodesmodel.cpp index dc028aef8e8..dce99bba26e 100644 --- a/src/plugins/effectmakernew/effectmakernodesmodel.cpp +++ b/src/plugins/effectmakernew/effectmakernodesmodel.cpp @@ -3,6 +3,9 @@ #include "effectmakernodesmodel.h" +#include + +#include #include #include @@ -38,44 +41,27 @@ QVariant EffectMakerNodesModel::data(const QModelIndex &index, int role) const return m_categories.at(index.row())->property(roleNames().value(role)); } -void EffectMakerNodesModel::findNodesPath() +QString EffectMakerNodesModel::nodesSourcesPath() const { - 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; - } - - m_nodesPath = Utils::FilePath::fromString(nodesDir.path()); +#ifdef SHARE_QML_PATH + if (Utils::qtcEnvironmentVariableIsSet("LOAD_QML_FROM_SOURCE")) + return QLatin1String(SHARE_QML_PATH) + "/effectMakerNodes"; +#endif + return Core::ICore::resourcePath("qmldesigner/effectMakerNodes").toString(); } void EffectMakerNodesModel::loadModel() { - findNodesPath(); + auto nodesPath = Utils::FilePath::fromString(nodesSourcesPath()); - if (!m_nodesPath.exists()) { + if (!nodesPath.exists()) { qWarning() << __FUNCTION__ << "Effects not found."; return; } m_categories = {}; - QDirIterator itCategories(m_nodesPath.toString(), QDir::Dirs | QDir::NoDotAndDotDot); + QDirIterator itCategories(nodesPath.toString(), QDir::Dirs | QDir::NoDotAndDotDot); while (itCategories.hasNext()) { itCategories.next(); @@ -85,7 +71,7 @@ void EffectMakerNodesModel::loadModel() QString catName = itCategories.fileName(); QList effects = {}; - Utils::FilePath categoryPath = m_nodesPath.resolvePath(itCategories.fileName()); + Utils::FilePath categoryPath = nodesPath.resolvePath(itCategories.fileName()); QDirIterator itEffects(categoryPath.toString(), {"*.qen"}, QDir::Files); while (itEffects.hasNext()) { itEffects.next(); @@ -112,4 +98,3 @@ void EffectMakerNodesModel::resetModel() } } // namespace EffectMaker - diff --git a/src/plugins/effectmakernew/effectmakernodesmodel.h b/src/plugins/effectmakernew/effectmakernodesmodel.h index 28a4e8484f0..56400982da3 100644 --- a/src/plugins/effectmakernew/effectmakernodesmodel.h +++ b/src/plugins/effectmakernew/effectmakernodesmodel.h @@ -5,8 +5,6 @@ #include "effectnodescategory.h" -#include - #include namespace EffectMaker { @@ -33,10 +31,9 @@ public: QList categories() const { return m_categories; } private: - void findNodesPath(); + QString nodesSourcesPath() const; QList m_categories; - Utils::FilePath m_nodesPath; bool m_probeNodesDir = false; };