forked from qt-creator/qt-creator
QmlDesigner: Set Uniform properties
Setting properties with some support functionality ready for UI binding Change-Id: I9636435c3ddeac74b2dbeec826571abeb4247350 Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
@@ -717,6 +717,7 @@ extend_qtc_plugin(QmlDesigner
|
|||||||
effectnodescategory.cpp effectnodescategory.h
|
effectnodescategory.cpp effectnodescategory.h
|
||||||
compositionnode.cpp compositionnode.h
|
compositionnode.cpp compositionnode.h
|
||||||
uniform.cpp uniform.h
|
uniform.cpp uniform.h
|
||||||
|
effectutils.cpp effectutils.h
|
||||||
)
|
)
|
||||||
|
|
||||||
extend_qtc_plugin(QmlDesigner
|
extend_qtc_plugin(QmlDesigner
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "compositionnode.h"
|
#include "compositionnode.h"
|
||||||
|
|
||||||
|
#include "effectutils.h"
|
||||||
#include "uniform.h"
|
#include "uniform.h"
|
||||||
|
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
@@ -64,10 +65,10 @@ void CompositionNode::parse(const QString &qenPath)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_name = json.value("name").toString(); //TODO: there is a difference between name and type
|
m_name = json.value("name").toString();
|
||||||
m_description = json.value("description").toString();
|
m_description = json.value("description").toString();
|
||||||
m_fragmentCode = codeFromJsonArray(json.value("fragmentCode").toArray());
|
m_fragmentCode = EffectUtils::codeFromJsonArray(json.value("fragmentCode").toArray());
|
||||||
m_vertexCode = codeFromJsonArray(json.value("vertexCode").toArray());
|
m_vertexCode = EffectUtils::codeFromJsonArray(json.value("vertexCode").toArray());
|
||||||
|
|
||||||
// parse properties
|
// parse properties
|
||||||
QJsonArray properties = json.value("properties").toArray();
|
QJsonArray properties = json.value("properties").toArray();
|
||||||
@@ -84,17 +85,4 @@ void CompositionNode::parse(const QString &qenPath)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CompositionNode::codeFromJsonArray(const QJsonArray &codeArray)
|
|
||||||
{
|
|
||||||
if (codeArray.isEmpty())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
QString codeString;
|
|
||||||
for (const auto &element : codeArray)
|
|
||||||
codeString += element.toString() + '\n';
|
|
||||||
|
|
||||||
codeString.chop(1); // Remove last '\n'
|
|
||||||
return codeString;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void parse(const QString &qenPath);
|
void parse(const QString &qenPath);
|
||||||
QString codeFromJsonArray(const QJsonArray &codeArray);
|
|
||||||
|
|
||||||
QString m_name;
|
QString m_name;
|
||||||
QString m_fragmentCode;
|
QString m_fragmentCode;
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#include "effectutils.h"
|
||||||
|
|
||||||
|
#include <QJsonArray>
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
QString EffectUtils::codeFromJsonArray(const QJsonArray &codeArray)
|
||||||
|
{
|
||||||
|
if (codeArray.isEmpty())
|
||||||
|
return {};
|
||||||
|
|
||||||
|
QString codeString;
|
||||||
|
for (const auto &element : codeArray)
|
||||||
|
codeString += element.toString() + '\n';
|
||||||
|
|
||||||
|
codeString.chop(1); // Remove last '\n'
|
||||||
|
return codeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace QmlDesigner
|
||||||
20
src/plugins/qmldesigner/components/effectmaker/effectutils.h
Normal file
20
src/plugins/qmldesigner/components/effectmaker/effectutils.h
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (C) 2023 The Qt Company Ltd.
|
||||||
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QJsonArray)
|
||||||
|
|
||||||
|
namespace QmlDesigner {
|
||||||
|
|
||||||
|
class EffectUtils
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EffectUtils() = delete;
|
||||||
|
|
||||||
|
static QString codeFromJsonArray(const QJsonArray &codeArray);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace QmlDesigner
|
||||||
@@ -7,9 +7,40 @@
|
|||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
Uniform::Uniform(const QJsonObject &props)
|
Uniform::Uniform(const QJsonObject &propObj)
|
||||||
{
|
{
|
||||||
Q_UNUSED(props)
|
//TODO: some cases such as missing values or default values not yet implemented
|
||||||
|
|
||||||
|
QString value, defaultValue;
|
||||||
|
|
||||||
|
m_name = propObj.value("name").toString();
|
||||||
|
m_description = propObj.value("description").toString();
|
||||||
|
m_type = typeFromString(propObj.value("type").toString());
|
||||||
|
defaultValue = propObj.value("defaultValue").toString();
|
||||||
|
|
||||||
|
if (m_type == Type::Sampler) {
|
||||||
|
if (!defaultValue.isEmpty())
|
||||||
|
defaultValue = getResourcePath(defaultValue);
|
||||||
|
if (propObj.contains("enableMipmap"))
|
||||||
|
m_enableMipmap = getBoolValue(propObj.value("enableMipmap"), false);
|
||||||
|
// Update the mipmap property
|
||||||
|
QString mipmapProperty = mipmapPropertyName(m_name);
|
||||||
|
}
|
||||||
|
if (propObj.contains("value")) {
|
||||||
|
value = propObj.value("value").toString();
|
||||||
|
if (m_type == Type::Sampler && !value.isEmpty())
|
||||||
|
value = getResourcePath(value);
|
||||||
|
} else {
|
||||||
|
// QEN files don't store the current value, so with those use default value
|
||||||
|
value = defaultValue;
|
||||||
|
}
|
||||||
|
m_customValue = propObj.value("customValue").toString();
|
||||||
|
m_useCustomValue = getBoolValue(propObj.value("useCustomValue"), false);
|
||||||
|
m_minValue = propObj.value("minValue").toString();
|
||||||
|
m_maxValue = propObj.value("maxValue").toString();
|
||||||
|
//TODO: set uniform value data after validating, for now just set to current value
|
||||||
|
m_defaultValue = defaultValue;
|
||||||
|
m_value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
Uniform::Type Uniform::type() const
|
Uniform::Type Uniform::type() const
|
||||||
@@ -47,11 +78,6 @@ QString Uniform::name() const
|
|||||||
return m_name;
|
return m_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Uniform::setName(const QString &newName)
|
|
||||||
{
|
|
||||||
m_name = newName;
|
|
||||||
}
|
|
||||||
|
|
||||||
QString Uniform::description() const
|
QString Uniform::description() const
|
||||||
{
|
{
|
||||||
return m_description;
|
return m_description;
|
||||||
@@ -87,4 +113,62 @@ bool Uniform::enableMipmap() const
|
|||||||
return m_enableMipmap;
|
return m_enableMipmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns name for image mipmap property.
|
||||||
|
// e.g. "myImage" -> "myImageMipmap".
|
||||||
|
QString Uniform::mipmapPropertyName(const QString &name) const
|
||||||
|
{
|
||||||
|
QString simplifiedName = name.simplified();
|
||||||
|
simplifiedName = simplifiedName.remove(' ');
|
||||||
|
simplifiedName += "Mipmap";
|
||||||
|
return simplifiedName;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uniform::Type Uniform::typeFromString(const QString &typeString) const
|
||||||
|
{
|
||||||
|
if (typeString == "bool")
|
||||||
|
return Type::Bool;
|
||||||
|
if (typeString == "int")
|
||||||
|
return Type::Int;
|
||||||
|
if (typeString == "float")
|
||||||
|
return Type::Float;
|
||||||
|
if (typeString == "vec2")
|
||||||
|
return Type::Vec2;
|
||||||
|
if (typeString == "vec3")
|
||||||
|
return Type::Vec3;
|
||||||
|
if (typeString == "vec4")
|
||||||
|
return Type::Vec4;
|
||||||
|
if (typeString == "color")
|
||||||
|
return Type::Color;
|
||||||
|
if (typeString == "image")
|
||||||
|
return Type::Sampler;
|
||||||
|
if (typeString == "define")
|
||||||
|
return Type::Define;
|
||||||
|
|
||||||
|
qWarning() << QString("Unknown type: %1").arg(typeString).toLatin1();
|
||||||
|
return Type::Float;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the boolean value of QJsonValue. It can be either boolean
|
||||||
|
// (true, false) or string ("true", "false"). Returns the defaultValue
|
||||||
|
// if QJsonValue is undefined, empty, or some other type.
|
||||||
|
bool Uniform::getBoolValue(const QJsonValue &jsonValue, bool defaultValue)
|
||||||
|
{
|
||||||
|
if (jsonValue.isBool())
|
||||||
|
return jsonValue.toBool();
|
||||||
|
|
||||||
|
if (jsonValue.isString())
|
||||||
|
return jsonValue.toString().toLower() == "true";
|
||||||
|
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns the path for a shader resource
|
||||||
|
// Used with sampler types
|
||||||
|
QString Uniform::getResourcePath(const QString &value) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(value)
|
||||||
|
//TODO
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace QmlDesigner
|
} // namespace QmlDesigner
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
|
QT_FORWARD_DECLARE_CLASS(QJsonObject)
|
||||||
|
|
||||||
namespace QmlDesigner {
|
namespace QmlDesigner {
|
||||||
|
|
||||||
class Uniform : public QObject
|
class Uniform : public QObject
|
||||||
@@ -36,17 +38,13 @@ public:
|
|||||||
QVariant defaultValue() const;
|
QVariant defaultValue() const;
|
||||||
|
|
||||||
QVariant minValue() const;
|
QVariant minValue() const;
|
||||||
|
|
||||||
QVariant maxValue() const;
|
QVariant maxValue() const;
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &newName);
|
|
||||||
|
|
||||||
QString description() const;
|
QString description() const;
|
||||||
|
|
||||||
QString customValue() const;
|
QString customValue() const;
|
||||||
void setCustomValue(const QString &newCustomValue);
|
void setCustomValue(const QString &newCustomValue);
|
||||||
|
|
||||||
bool useCustomValue() const;
|
bool useCustomValue() const;
|
||||||
|
|
||||||
bool enabled() const;
|
bool enabled() const;
|
||||||
@@ -55,6 +53,12 @@ public:
|
|||||||
bool enableMipmap() const;
|
bool enableMipmap() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QString mipmapPropertyName(const QString &name) const;
|
||||||
|
|
||||||
|
Uniform::Type typeFromString(const QString &typeString) const;
|
||||||
|
bool getBoolValue(const QJsonValue &jsonValue, bool defaultValue);
|
||||||
|
QString getResourcePath(const QString &value) const;
|
||||||
|
|
||||||
Type m_type;
|
Type m_type;
|
||||||
QVariant m_value;
|
QVariant m_value;
|
||||||
QVariant m_defaultValue;
|
QVariant m_defaultValue;
|
||||||
|
|||||||
Reference in New Issue
Block a user