forked from qt-creator/qt-creator
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:
@@ -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,17 +1015,16 @@ 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));
|
json.insert("fragmentCode", toJsonArray(m_rootFragmentShader));
|
||||||
|
|
||||||
if (!m_rootFragmentShader.isEmpty())
|
|
||||||
json.insert("fragmentCode", toJsonArray(m_rootFragmentShader));
|
|
||||||
|
|
||||||
QJsonObject rootJson;
|
QJsonObject rootJson;
|
||||||
rootJson.insert("QEP", json);
|
rootJson.insert("QEP", json);
|
||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|
||||||
setRootVertexShader(toCodeBlock(json["vertexCode"]));
|
if (json.contains("vertexCode"))
|
||||||
setRootFragmentShader(toCodeBlock(json["fragmentCode"]));
|
setRootVertexShader(toCodeBlock(json["vertexCode"]));
|
||||||
|
else
|
||||||
|
resetRootVertexShader();
|
||||||
|
|
||||||
|
if (json.contains("fragmentCode"))
|
||||||
|
setRootFragmentShader(toCodeBlock(json["fragmentCode"]));
|
||||||
|
else
|
||||||
|
resetRootFragmentShader();
|
||||||
|
|
||||||
if (json.contains("nodes") && json["nodes"].isArray()) {
|
if (json.contains("nodes") && json["nodes"].isArray()) {
|
||||||
beginResetModel();
|
beginResetModel();
|
||||||
|
Reference in New Issue
Block a user