diff --git a/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml b/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml index f4cdddeaca1..c4ddd616ed0 100644 --- a/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml +++ b/share/qtcreator/qmldesigner/effectMakerQmlSources/EffectMaker.qml @@ -137,16 +137,14 @@ Item { Row { spacing: 5 - Image { + IconImage { id: nodeIcon width: 30 height: 30 - Rectangle { // TODO: placeholder until setting image source - anchors.fill: parent - color: "gray" - } + color: StudioTheme.Values.themeTextColor + source: modelData.nodeIcon } Text { diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp index 5adae133b5c..0d38ea446e8 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.cpp @@ -3,14 +3,6 @@ #include "effectmakermodel.h" -#include -#include -#include - -#include - -#include - namespace QmlDesigner { EffectMakerModel::EffectMakerModel(QObject *parent) @@ -33,69 +25,16 @@ int EffectMakerModel::rowCount(const QModelIndex &parent) const return m_categories.count(); } -QVariant EffectMakerModel::data(const QModelIndex &index, int role) const +QVariant EffectMakerModel::data(const QModelIndex &index, int /*role*/) const { - // TODO: to be updated - if (index.row() < 0 || index.row() >= m_categories.count()) return {}; - const EffectNodesCategory *category = m_categories.at(index.row()); - if (role == CategoryRole) - return category->name(); - - if (role == EffectsRole) { - QStringList effectsNames; - const QList effects = category->nodes(); - for (const EffectNode *effect : effects) - effectsNames << effect->name(); - - return effectsNames; - } + // TODO return {}; } -// static -Utils::FilePath EffectMakerModel::getQmlEffectsPath() -{ - const ProjectExplorer::Target *target = ProjectExplorer::ProjectTree::currentTarget(); - if (!target) { - qWarning() << __FUNCTION__ << "No project open"; - return ""; - } - - const QtSupport::QtVersion *baseQtVersion = QtSupport::QtKitAspect::qtVersion(target->kit()); - return baseQtVersion->qmlPath().pathAppended("QtQuickEffectMaker/defaultnodes"); -} - -void EffectMakerModel::loadModel() -{ - const Utils::FilePath effectsPath = getQmlEffectsPath(); - - if (!effectsPath.exists()) { - qWarning() << __FUNCTION__ << "Effects are not found."; - return; - } - QDirIterator itCategories(effectsPath.toString(), QDir::Dirs | QDir::NoDotAndDotDot); - while (itCategories.hasNext()) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - itCategories.next(); - if (itCategories.fileName() == "images") - continue; - QList effects = {}; - Utils::FilePath categoryPath = effectsPath.resolvePath(itCategories.fileName()); - QDirIterator itEffects(categoryPath.toString(), QDir::Files | QDir::NoDotAndDotDot); - while (itEffects.hasNext()) { - itEffects.next(); - effects.push_back(new EffectNode(QFileInfo(itEffects.fileName()).baseName())); - } - EffectNodesCategory *category = new EffectNodesCategory(itCategories.fileName(), effects); - m_categories.push_back(category); - endInsertRows(); - } -} - void EffectMakerModel::resetModel() { beginResetModel(); diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h index 1278a1c5af6..f56c2ed9b91 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakermodel.h @@ -7,10 +7,6 @@ #include "effectnodescategory.h" -namespace Utils { -class FilePath; -} - namespace QmlDesigner { class EffectMakerModel : public QAbstractListModel @@ -34,7 +30,6 @@ public: bool isEmpty() const { return m_isEmpty; } - void loadModel(); void resetModel(); QList categories() { return m_categories; } @@ -49,7 +44,6 @@ signals: private: bool isValidIndex(int idx) const; - static Utils::FilePath getQmlEffectsPath(); QList m_categories; diff --git a/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp b/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp index 3d201b9e9c4..8b7b5c3deb1 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/effectmakernodesmodel.cpp @@ -80,15 +80,20 @@ void EffectMakerNodesModel::loadModel() if (itCategories.fileName() == "images") continue; + QString catName = itCategories.fileName(); + QList effects = {}; Utils::FilePath categoryPath = m_nodesPath.resolvePath(itCategories.fileName()); QDirIterator itEffects(categoryPath.toString(), {"*.qen"}, QDir::Files); while (itEffects.hasNext()) { itEffects.next(); - effects.push_back(new EffectNode(QFileInfo(itEffects.fileName()).baseName())); + QString fileName = QFileInfo(itEffects.fileName()).baseName(); + QString iconPath = m_nodesPath.path() + '/' + catName + "/icon/" + fileName + ".svg"; + if (!QFileInfo::exists(iconPath)) + iconPath = m_nodesPath.path() + "/placeholder.svg"; + effects.push_back(new EffectNode(fileName, iconPath)); } - QString catName = itCategories.fileName(); catName[0] = catName[0].toUpper(); // capitalize first letter EffectNodesCategory *category = new EffectNodesCategory(catName, effects); m_categories.push_back(category); diff --git a/src/plugins/qmldesigner/components/effectmaker/effectnode.cpp b/src/plugins/qmldesigner/components/effectmaker/effectnode.cpp index 777fe28ec82..5b554bc6364 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectnode.cpp +++ b/src/plugins/qmldesigner/components/effectmaker/effectnode.cpp @@ -5,12 +5,8 @@ namespace QmlDesigner { -EffectNode::EffectNode(const QString &name) - : m_name(name) {} - -QString EffectNode::name() const -{ - return m_name; -} +EffectNode::EffectNode(const QString &name, const QString &iconPath) + : m_name(name) + , m_iconPath(QUrl::fromLocalFile(iconPath)) {} } // namespace QmlDesigner diff --git a/src/plugins/qmldesigner/components/effectmaker/effectnode.h b/src/plugins/qmldesigner/components/effectmaker/effectnode.h index b9a51c7f044..4b1216d3539 100644 --- a/src/plugins/qmldesigner/components/effectmaker/effectnode.h +++ b/src/plugins/qmldesigner/components/effectmaker/effectnode.h @@ -4,6 +4,7 @@ #pragma once #include +#include namespace QmlDesigner { @@ -12,14 +13,14 @@ class EffectNode : public QObject Q_OBJECT Q_PROPERTY(QString nodeName MEMBER m_name CONSTANT) + Q_PROPERTY(QUrl nodeIcon MEMBER m_iconPath CONSTANT) public: - EffectNode(const QString &name); - - QString name() const; + EffectNode(const QString &name, const QString &iconPath); private: QString m_name; + QUrl m_iconPath; }; } // namespace QmlDesigner