forked from qt-creator/qt-creator
QmlDesigner: Load effect maker nodes' icons
Also remove some unused code. Fixes: QDS-10426 Change-Id: I71c4fde339261e2856472c15bde56ee8850ed236 Reviewed-by: Amr Elsayed <amr.elsayed@qt.io> Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io> Reviewed-by: Qt CI Patch Build Bot <ci_patchbuild_bot@qt.io>
This commit is contained in:
@@ -137,16 +137,14 @@ Item {
|
|||||||
Row {
|
Row {
|
||||||
spacing: 5
|
spacing: 5
|
||||||
|
|
||||||
Image {
|
IconImage {
|
||||||
id: nodeIcon
|
id: nodeIcon
|
||||||
|
|
||||||
width: 30
|
width: 30
|
||||||
height: 30
|
height: 30
|
||||||
|
|
||||||
Rectangle { // TODO: placeholder until setting image source
|
color: StudioTheme.Values.themeTextColor
|
||||||
anchors.fill: parent
|
source: modelData.nodeIcon
|
||||||
color: "gray"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Text {
|
Text {
|
||||||
|
|||||||
@@ -3,14 +3,6 @@
|
|||||||
|
|
||||||
#include "effectmakermodel.h"
|
#include "effectmakermodel.h"
|
||||||
|
|
||||||
#include <projectexplorer/kit.h>
|
|
||||||
#include <projectexplorer/projecttree.h>
|
|
||||||
#include <projectexplorer/target.h>
|
|
||||||
|
|
||||||
#include <qtsupport/qtkitinformation.h>
|
|
||||||
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
EffectMakerModel::EffectMakerModel(QObject *parent)
|
EffectMakerModel::EffectMakerModel(QObject *parent)
|
||||||
@@ -33,69 +25,16 @@ int EffectMakerModel::rowCount(const QModelIndex &parent) const
|
|||||||
return m_categories.count();
|
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())
|
if (index.row() < 0 || index.row() >= m_categories.count())
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
const EffectNodesCategory *category = m_categories.at(index.row());
|
// TODO
|
||||||
if (role == CategoryRole)
|
|
||||||
return category->name();
|
|
||||||
|
|
||||||
if (role == EffectsRole) {
|
|
||||||
QStringList effectsNames;
|
|
||||||
const QList<EffectNode *> effects = category->nodes();
|
|
||||||
for (const EffectNode *effect : effects)
|
|
||||||
effectsNames << effect->name();
|
|
||||||
|
|
||||||
return effectsNames;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {};
|
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<EffectNode *> 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()
|
void EffectMakerModel::resetModel()
|
||||||
{
|
{
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
|||||||
@@ -7,10 +7,6 @@
|
|||||||
|
|
||||||
#include "effectnodescategory.h"
|
#include "effectnodescategory.h"
|
||||||
|
|
||||||
namespace Utils {
|
|
||||||
class FilePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class EffectMakerModel : public QAbstractListModel
|
class EffectMakerModel : public QAbstractListModel
|
||||||
@@ -34,7 +30,6 @@ public:
|
|||||||
|
|
||||||
bool isEmpty() const { return m_isEmpty; }
|
bool isEmpty() const { return m_isEmpty; }
|
||||||
|
|
||||||
void loadModel();
|
|
||||||
void resetModel();
|
void resetModel();
|
||||||
|
|
||||||
QList<EffectNodesCategory *> categories() { return m_categories; }
|
QList<EffectNodesCategory *> categories() { return m_categories; }
|
||||||
@@ -49,7 +44,6 @@ signals:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool isValidIndex(int idx) const;
|
bool isValidIndex(int idx) const;
|
||||||
static Utils::FilePath getQmlEffectsPath();
|
|
||||||
|
|
||||||
QList<EffectNodesCategory *> m_categories;
|
QList<EffectNodesCategory *> m_categories;
|
||||||
|
|
||||||
|
|||||||
@@ -80,15 +80,20 @@ void EffectMakerNodesModel::loadModel()
|
|||||||
if (itCategories.fileName() == "images")
|
if (itCategories.fileName() == "images")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
QString catName = itCategories.fileName();
|
||||||
|
|
||||||
QList<EffectNode *> effects = {};
|
QList<EffectNode *> effects = {};
|
||||||
Utils::FilePath categoryPath = m_nodesPath.resolvePath(itCategories.fileName());
|
Utils::FilePath categoryPath = m_nodesPath.resolvePath(itCategories.fileName());
|
||||||
QDirIterator itEffects(categoryPath.toString(), {"*.qen"}, QDir::Files);
|
QDirIterator itEffects(categoryPath.toString(), {"*.qen"}, QDir::Files);
|
||||||
while (itEffects.hasNext()) {
|
while (itEffects.hasNext()) {
|
||||||
itEffects.next();
|
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
|
catName[0] = catName[0].toUpper(); // capitalize first letter
|
||||||
EffectNodesCategory *category = new EffectNodesCategory(catName, effects);
|
EffectNodesCategory *category = new EffectNodesCategory(catName, effects);
|
||||||
m_categories.push_back(category);
|
m_categories.push_back(category);
|
||||||
|
|||||||
@@ -5,12 +5,8 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
EffectNode::EffectNode(const QString &name)
|
EffectNode::EffectNode(const QString &name, const QString &iconPath)
|
||||||
: m_name(name) {}
|
: m_name(name)
|
||||||
|
, m_iconPath(QUrl::fromLocalFile(iconPath)) {}
|
||||||
QString EffectNode::name() const
|
|
||||||
{
|
|
||||||
return m_name;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
#include <QUrl>
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
@@ -12,14 +13,14 @@ class EffectNode : public QObject
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
Q_PROPERTY(QString nodeName MEMBER m_name CONSTANT)
|
Q_PROPERTY(QString nodeName MEMBER m_name CONSTANT)
|
||||||
|
Q_PROPERTY(QUrl nodeIcon MEMBER m_iconPath CONSTANT)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
EffectNode(const QString &name);
|
EffectNode(const QString &name, const QString &iconPath);
|
||||||
|
|
||||||
QString name() const;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString m_name;
|
QString m_name;
|
||||||
|
QUrl m_iconPath;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
Reference in New Issue
Block a user