forked from qt-creator/qt-creator
QmlDesigner: Load effect maker nodes from path
...instead of from Qt SDK Change-Id: I10d3104477b7cd7c729121175c66a7402ea49651 Reviewed-by: Amr Elsayed <amr.elsayed@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
This commit is contained in:
@@ -3,13 +3,9 @@
|
||||
|
||||
#include "effectmakernodesmodel.h"
|
||||
|
||||
#include <projectexplorer/kit.h>
|
||||
#include <projectexplorer/projecttree.h>
|
||||
#include <projectexplorer/target.h>
|
||||
#include <utils/hostosinfo.h>
|
||||
|
||||
#include <qtsupport/qtkitinformation.h>
|
||||
|
||||
#include <utils/filepath.h>
|
||||
#include <QCoreApplication>
|
||||
|
||||
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<EffectNode *> 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();
|
||||
|
@@ -3,13 +3,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
#include "effectnodescategory.h"
|
||||
|
||||
namespace Utils {
|
||||
class FilePath;
|
||||
}
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QStandardItemModel>
|
||||
|
||||
namespace QmlDesigner {
|
||||
|
||||
@@ -35,9 +33,11 @@ public:
|
||||
QList<EffectNodesCategory *> categories() const { return m_categories; }
|
||||
|
||||
private:
|
||||
static Utils::FilePath getQmlEffectNodesPath();
|
||||
void findNodesPath();
|
||||
|
||||
QList<EffectNodesCategory *> m_categories;
|
||||
Utils::FilePath m_nodesPath;
|
||||
bool m_probeNodesDir = false;
|
||||
};
|
||||
|
||||
} // namespace QmlDesigner
|
||||
|
Reference in New Issue
Block a user