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 <QVector2D>
|
||||
|
||||
using namespace Qt::StringLiterals;
|
||||
|
||||
namespace EffectComposer {
|
||||
|
||||
enum class FileType
|
||||
@@ -1003,6 +1005,7 @@ void EffectComposerModel::saveComposition(const QString &name)
|
||||
QJsonObject json;
|
||||
// File format version
|
||||
json.insert("version", 1);
|
||||
json.insert("tool", "EffectComposer");
|
||||
|
||||
// Add nodes
|
||||
QJsonArray nodesArray;
|
||||
@@ -1012,16 +1015,15 @@ void EffectComposerModel::saveComposition(const QString &name)
|
||||
}
|
||||
|
||||
auto toJsonArray = [](const QString &code) -> QJsonArray {
|
||||
if (code.isEmpty())
|
||||
return {};
|
||||
return QJsonArray::fromStringList(code.split('\n'));
|
||||
};
|
||||
|
||||
if (!nodesArray.isEmpty())
|
||||
json.insert("nodes", nodesArray);
|
||||
|
||||
if (!m_rootVertexShader.isEmpty())
|
||||
json.insert("vertexCode", toJsonArray(m_rootVertexShader));
|
||||
|
||||
if (!m_rootFragmentShader.isEmpty())
|
||||
json.insert("fragmentCode", toJsonArray(m_rootFragmentShader));
|
||||
|
||||
QJsonObject rootJson;
|
||||
@@ -1117,6 +1119,18 @@ void EffectComposerModel::openComposition(const QString &path)
|
||||
|
||||
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;
|
||||
if (json.contains("version"))
|
||||
version = json["version"].toInt(-1);
|
||||
@@ -1142,8 +1156,15 @@ void EffectComposerModel::openComposition(const QString &path)
|
||||
return code;
|
||||
};
|
||||
|
||||
if (json.contains("vertexCode"))
|
||||
setRootVertexShader(toCodeBlock(json["vertexCode"]));
|
||||
else
|
||||
resetRootVertexShader();
|
||||
|
||||
if (json.contains("fragmentCode"))
|
||||
setRootFragmentShader(toCodeBlock(json["fragmentCode"]));
|
||||
else
|
||||
resetRootFragmentShader();
|
||||
|
||||
if (json.contains("nodes") && json["nodes"].isArray()) {
|
||||
beginResetModel();
|
||||
|
Reference in New Issue
Block a user