EffectComposer: Use default shaders if they don't exist in QEP file

* If a shader does not exist in QEP file, default shader will be used
* If a user clears the shader code, an empty array would be inserted
into the QEP file as the shader. This prevents using default shaders
when the user clears the code deliberately.
* QQEM effect files are not supported
* `tool` property is added to the root of QEP

Fixes: QDS-13857
Change-Id: I85bf6cdd9fe318afbc4c2e943b2d4faaccedbdeb
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Mahmoud Badri <mahmoud.badri@qt.io>
This commit is contained in:
Ali Kianian
2024-10-17 17:54:53 +03:00
parent eea998da9a
commit 5285ff2bc9

View File

@@ -26,6 +26,8 @@
#include <QTemporaryDir> #include <QTemporaryDir>
#include <QVector2D> #include <QVector2D>
using namespace Qt::StringLiterals;
namespace EffectComposer { namespace EffectComposer {
enum class FileType enum class FileType
@@ -1003,6 +1005,7 @@ void EffectComposerModel::saveComposition(const QString &name)
QJsonObject json; QJsonObject json;
// File format version // File format version
json.insert("version", 1); json.insert("version", 1);
json.insert("tool", "EffectComposer");
// Add nodes // Add nodes
QJsonArray nodesArray; QJsonArray nodesArray;
@@ -1012,16 +1015,15 @@ void EffectComposerModel::saveComposition(const QString &name)
} }
auto toJsonArray = [](const QString &code) -> QJsonArray { auto toJsonArray = [](const QString &code) -> QJsonArray {
if (code.isEmpty())
return {};
return QJsonArray::fromStringList(code.split('\n')); return QJsonArray::fromStringList(code.split('\n'));
}; };
if (!nodesArray.isEmpty()) if (!nodesArray.isEmpty())
json.insert("nodes", nodesArray); json.insert("nodes", nodesArray);
if (!m_rootVertexShader.isEmpty())
json.insert("vertexCode", toJsonArray(m_rootVertexShader)); json.insert("vertexCode", toJsonArray(m_rootVertexShader));
if (!m_rootFragmentShader.isEmpty())
json.insert("fragmentCode", toJsonArray(m_rootFragmentShader)); json.insert("fragmentCode", toJsonArray(m_rootFragmentShader));
QJsonObject rootJson; QJsonObject rootJson;
@@ -1117,6 +1119,18 @@ void EffectComposerModel::openComposition(const QString &path)
QJsonObject json = rootJson["QEP"].toObject(); QJsonObject json = rootJson["QEP"].toObject();
const QString toolName = json.contains("tool") ? json["tool"].toString()
: json.contains("QQEM") ? "QQEM"_L1
: ""_L1;
if (!toolName.isEmpty() && toolName != "EffectComposer") {
const QString error
= tr("Error: '%1' effects are not compatible with 'Effect Composer'").arg(toolName);
qWarning() << error;
setEffectError(error);
return;
}
int version = -1; int version = -1;
if (json.contains("version")) if (json.contains("version"))
version = json["version"].toInt(-1); version = json["version"].toInt(-1);
@@ -1142,8 +1156,15 @@ void EffectComposerModel::openComposition(const QString &path)
return code; return code;
}; };
if (json.contains("vertexCode"))
setRootVertexShader(toCodeBlock(json["vertexCode"])); setRootVertexShader(toCodeBlock(json["vertexCode"]));
else
resetRootVertexShader();
if (json.contains("fragmentCode"))
setRootFragmentShader(toCodeBlock(json["fragmentCode"])); setRootFragmentShader(toCodeBlock(json["fragmentCode"]));
else
resetRootFragmentShader();
if (json.contains("nodes") && json["nodes"].isArray()) { if (json.contains("nodes") && json["nodes"].isArray()) {
beginResetModel(); beginResetModel();