various: use simpler/smarter XML reading functions
Should address any XML parsing issues and allows for simpler, more maintainable code. Should also address a crash that could occur when pasting nodes that had inputs that weren't copied.
This commit is contained in:
+21
-2
@@ -31,7 +31,26 @@ Node* XMLLoadNode(QXmlStreamReader* reader) {
|
||||
void XMLConnectNodes(const QHash<quintptr, NodeOutput*>& output_ptrs, const QList<NodeParam::SerializedConnection>& desired_connections)
|
||||
{
|
||||
foreach (const NodeParam::SerializedConnection& con, desired_connections) {
|
||||
NodeParam::ConnectEdge(output_ptrs.value(con.output),
|
||||
con.input);
|
||||
NodeOutput* out = output_ptrs.value(con.output);
|
||||
|
||||
if (out) {
|
||||
NodeParam::ConnectEdge(out, con.input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool XMLReadNextStartElement(QXmlStreamReader *reader)
|
||||
{
|
||||
QXmlStreamReader::TokenType token;
|
||||
|
||||
while ((token = reader->readNext()) != QXmlStreamReader::Invalid
|
||||
&& token != QXmlStreamReader::EndDocument) {
|
||||
if (reader->isEndElement()) {
|
||||
return false;
|
||||
} else if (reader->isStartElement()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -5,9 +5,6 @@
|
||||
|
||||
#include "node/node.h"
|
||||
|
||||
#define XMLReadLoop(reader, section) \
|
||||
while (!reader->atEnd() && !(reader->name() == section && reader->isEndElement()) && reader->readNext())
|
||||
|
||||
#define XMLAttributeLoop(reader, item) \
|
||||
QXmlStreamAttributes __attributes = reader->attributes(); \
|
||||
foreach (const QXmlStreamAttribute& item, __attributes)
|
||||
@@ -16,4 +13,6 @@ Node *XMLLoadNode(QXmlStreamReader* reader);
|
||||
|
||||
void XMLConnectNodes(const QHash<quintptr, NodeOutput *> &output_ptrs, const QList<NodeParam::SerializedConnection> &desired_connections);
|
||||
|
||||
bool XMLReadNextStartElement(QXmlStreamReader* reader);
|
||||
|
||||
#endif // XMLREADLOOP_H
|
||||
|
||||
+33
-34
@@ -29,6 +29,7 @@
|
||||
|
||||
#include "common/autoscroll.h"
|
||||
#include "common/filefunctions.h"
|
||||
#include "common/xmlutils.h"
|
||||
#include "core.h"
|
||||
#include "window/mainwindow/mainwindow.h"
|
||||
|
||||
@@ -120,52 +121,50 @@ void Config::Load()
|
||||
|
||||
QString config_version;
|
||||
|
||||
while (!reader.atEnd()) {
|
||||
reader.readNext();
|
||||
while (XMLReadNextStartElement(&reader)) {
|
||||
if (reader.name() == QStringLiteral("Configuration")) {
|
||||
while (XMLReadNextStartElement(&reader)) {
|
||||
QString key = reader.name().toString();
|
||||
QString value = reader.readElementText();
|
||||
|
||||
if (!reader.isStartElement()) {
|
||||
continue;
|
||||
}
|
||||
if (key == QStringLiteral("Version")) {
|
||||
config_version = value;
|
||||
|
||||
QString key = reader.name().toString();
|
||||
if (!value.contains(".")) {
|
||||
qDebug() << "CONFIG: This is a 0.1.x config file, upconvert";
|
||||
}
|
||||
} else if (key == QStringLiteral("DefaultSequenceFrameRate") && !config_version.contains('.')) {
|
||||
// 0.1.x stored this value as a float while we now use rationals, we'll use a heuristic to find the closest
|
||||
// supported rational
|
||||
qDebug() << " CONFIG: Finding closest match to" << value;
|
||||
|
||||
reader.readNext();
|
||||
QString value = reader.text().toString();
|
||||
double config_fr = value.toDouble();
|
||||
|
||||
if (key == "Configuration") {
|
||||
// First element, ignore
|
||||
} else if (key == "Version") {
|
||||
config_version = value;
|
||||
QList<rational> supported_frame_rates = Core::SupportedFrameRates();
|
||||
|
||||
if (!value.contains(".")) {
|
||||
qDebug() << "CONFIG: This is a 0.1.x config file, upconvert";
|
||||
}
|
||||
} else if (key == "DefaultSequenceFrameRate" && !config_version.contains(".")) {
|
||||
// 0.1.x stored this value as a float while we now use rationals, we'll use a heuristic to find the closest
|
||||
// supported rational
|
||||
qDebug() << " CONFIG: Finding closest match to" << value;
|
||||
rational match = supported_frame_rates.first();
|
||||
double match_diff = qAbs(match.toDouble() - config_fr);
|
||||
|
||||
double config_fr = value.toDouble();
|
||||
for (int i=1;i<supported_frame_rates.size();i++) {
|
||||
double diff = qAbs(supported_frame_rates.at(i).toDouble() - config_fr);
|
||||
|
||||
QList<rational> supported_frame_rates = Core::SupportedFrameRates();
|
||||
if (diff < match_diff) {
|
||||
match = supported_frame_rates.at(i);
|
||||
match_diff = diff;
|
||||
}
|
||||
}
|
||||
|
||||
rational match = supported_frame_rates.first();
|
||||
double match_diff = qAbs(match.toDouble() - config_fr);
|
||||
qDebug() << " CONFIG: Closest match was" << match.toDouble();
|
||||
|
||||
for (int i=1;i<supported_frame_rates.size();i++) {
|
||||
double diff = qAbs(supported_frame_rates.at(i).toDouble() - config_fr);
|
||||
|
||||
if (diff < match_diff) {
|
||||
match = supported_frame_rates.at(i);
|
||||
match_diff = diff;
|
||||
current_config_[key] = QVariant::fromValue(match.flipped());
|
||||
} else {
|
||||
current_config_[key] = value;
|
||||
}
|
||||
}
|
||||
|
||||
qDebug() << " CONFIG: Closest match was" << match.toDouble();
|
||||
|
||||
current_config_[key] = QVariant::fromValue(match.flipped());
|
||||
//reader.skipCurrentElement();
|
||||
} else {
|
||||
current_config_[key] = value;
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,7 +172,7 @@ void Config::Load()
|
||||
QMessageBox::critical(Core::instance()->main_window(),
|
||||
QCoreApplication::translate("Config", "Error loading settings"),
|
||||
QCoreApplication::translate("Config", "Failed to load application settings. This session will "
|
||||
"use defaults."),
|
||||
"use defaults.\n\n%1").arg(reader.errorString()),
|
||||
QMessageBox::Ok);
|
||||
current_config_.SetDefaults();
|
||||
}
|
||||
|
||||
+85
-84
@@ -91,111 +91,111 @@ void NodeInput::Load(QXmlStreamReader *reader, QHash<quintptr, NodeOutput*>& par
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr.name() == "keyframing") {
|
||||
set_is_keyframing(attr.value() == "1");
|
||||
if (attr.name() == QStringLiteral("keyframing")) {
|
||||
set_is_keyframing(attr.value() == QStringLiteral("1"));
|
||||
}
|
||||
}
|
||||
|
||||
XMLReadLoop(reader, "input") {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "standard") {
|
||||
// Load standard value
|
||||
int val_index = 0;
|
||||
if (reader->name() == QStringLiteral("standard")) {
|
||||
// Load standard value
|
||||
int val_index = 0;
|
||||
|
||||
XMLReadLoop(reader, "standard") {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->name() == QStringLiteral("value")) {
|
||||
QString value_text = reader->readElementText();
|
||||
|
||||
if (value_text.isEmpty()) {
|
||||
standard_value_.replace(val_index, QVariant());
|
||||
} else {
|
||||
standard_value_.replace(val_index, StringToValue(value_text, footage_connections));
|
||||
}
|
||||
|
||||
if (reader->isStartElement() && reader->name() == "value") {
|
||||
reader->readNext();
|
||||
val_index++;
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
} else if (reader->name() == QStringLiteral("keyframes")) {
|
||||
int track = 0;
|
||||
|
||||
QString value_text = reader->text().toString();
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value_text.isEmpty()) {
|
||||
standard_value_.replace(val_index, QVariant());
|
||||
} else {
|
||||
standard_value_.replace(val_index, StringToValue(value_text, footage_connections));
|
||||
if (reader->name() == QStringLiteral("track")) {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
val_index++;
|
||||
}
|
||||
}
|
||||
} else if (reader->name() == "keyframes") {
|
||||
int track = 0;
|
||||
if (reader->name() == QStringLiteral("key")) {
|
||||
rational key_time;
|
||||
NodeKeyframe::Type key_type;
|
||||
QVariant key_value;
|
||||
QPointF key_in_handle;
|
||||
QPointF key_out_handle;
|
||||
|
||||
XMLReadLoop(reader, "keyframes") {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement() && reader->name() == "track") {
|
||||
XMLReadLoop(reader, "track") {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->name() == "key") {
|
||||
rational key_time;
|
||||
NodeKeyframe::Type key_type;
|
||||
QVariant key_value;
|
||||
QPointF key_in_handle;
|
||||
QPointF key_out_handle;
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr.name() == "time") {
|
||||
key_time = rational::fromString(attr.value().toString());
|
||||
} else if (attr.name() == "type") {
|
||||
key_type = static_cast<NodeKeyframe::Type>(attr.value().toInt());
|
||||
} else if (attr.name() == "inhandlex") {
|
||||
key_in_handle.setX(attr.value().toDouble());
|
||||
} else if (attr.name() == "inhandley") {
|
||||
key_in_handle.setY(attr.value().toDouble());
|
||||
} else if (attr.name() == "outhandlex") {
|
||||
key_out_handle.setX(attr.value().toDouble());
|
||||
} else if (attr.name() == "outhandley") {
|
||||
key_out_handle.setY(attr.value().toDouble());
|
||||
}
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
reader->readNext();
|
||||
|
||||
key_value = StringToValue(reader->text().toString(), footage_connections);
|
||||
|
||||
NodeKeyframePtr key = NodeKeyframe::Create(key_time, key_value, key_type, track);
|
||||
key->set_bezier_control_in(key_in_handle);
|
||||
key->set_bezier_control_out(key_out_handle);
|
||||
key->set_parent(this);
|
||||
keyframe_tracks_[track].append(key);
|
||||
if (attr.name() == QStringLiteral("time")) {
|
||||
key_time = rational::fromString(attr.value().toString());
|
||||
} else if (attr.name() == QStringLiteral("type")) {
|
||||
key_type = static_cast<NodeKeyframe::Type>(attr.value().toInt());
|
||||
} else if (attr.name() == QStringLiteral("inhandlex")) {
|
||||
key_in_handle.setX(attr.value().toDouble());
|
||||
} else if (attr.name() == QStringLiteral("inhandley")) {
|
||||
key_in_handle.setY(attr.value().toDouble());
|
||||
} else if (attr.name() == QStringLiteral("outhandlex")) {
|
||||
key_out_handle.setX(attr.value().toDouble());
|
||||
} else if (attr.name() == QStringLiteral("outhandley")) {
|
||||
key_out_handle.setY(attr.value().toDouble());
|
||||
}
|
||||
}
|
||||
|
||||
key_value = StringToValue(reader->readElementText(), footage_connections);
|
||||
|
||||
NodeKeyframePtr key = NodeKeyframe::Create(key_time, key_value, key_type, track);
|
||||
key->set_bezier_control_in(key_in_handle);
|
||||
key->set_bezier_control_out(key_out_handle);
|
||||
key->set_parent(this);
|
||||
keyframe_tracks_[track].append(key);
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
track++;
|
||||
}
|
||||
|
||||
track++;
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
} else if (reader->name() == "connections") {
|
||||
XMLReadLoop(reader, "connections") {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement() && reader->name() == "connection") {
|
||||
reader->readNext();
|
||||
|
||||
input_connections.append({this, reader->text().toULongLong()});
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LoadInternal(reader, param_ptrs, input_connections, footage_connections, cancelled);
|
||||
}
|
||||
} else if (reader->name() == QStringLiteral("connections")) {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->name() == QStringLiteral("connection")) {
|
||||
input_connections.append({this, reader->readElementText().toULongLong()});
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
LoadInternal(reader, param_ptrs, input_connections, footage_connections, cancelled);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -268,8 +268,9 @@ const NodeParam::DataType &NodeInput::data_type() const
|
||||
return data_type_;
|
||||
}
|
||||
|
||||
void NodeInput::LoadInternal(QXmlStreamReader*, QHash<quintptr, NodeOutput *>&, QList<SerializedConnection>&, QList<FootageConnection>&, const QAtomicInt*)
|
||||
void NodeInput::LoadInternal(QXmlStreamReader* reader, QHash<quintptr, NodeOutput *>&, QList<SerializedConnection>&, QList<FootageConnection>&, const QAtomicInt*)
|
||||
{
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
void NodeInput::SaveInternal(QXmlStreamWriter*) const
|
||||
|
||||
@@ -166,13 +166,17 @@ void NodeInputArray::RemoveAt(int index)
|
||||
|
||||
void NodeInputArray::LoadInternal(QXmlStreamReader *reader, QHash<quintptr, NodeOutput*>& param_ptrs, QList<SerializedConnection> &input_connections, QList<FootageConnection>& footage_connections, const QAtomicInt* cancelled)
|
||||
{
|
||||
if (reader->name() == "subparameters") {
|
||||
XMLReadLoop(reader, "subparameters") {
|
||||
if (reader->name() == "input") {
|
||||
if (reader->name() == QStringLiteral("subparameters")) {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("input")) {
|
||||
Append();
|
||||
At(GetSize() - 1)->Load(reader, param_ptrs, input_connections, footage_connections, cancelled);
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
NodeInput::Load(reader, param_ptrs, input_connections, footage_connections, cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+24
-24
@@ -50,39 +50,39 @@ Node::~Node()
|
||||
}
|
||||
}
|
||||
|
||||
void Node::Load(QXmlStreamReader *reader, QHash<quintptr, NodeOutput *> &output_ptrs, QList<NodeInput::SerializedConnection>& input_connections, QList<NodeParam::FootageConnection>& footage_connections, const QAtomicInt* cancelled, const QString& element)
|
||||
void Node::Load(QXmlStreamReader *reader, QHash<quintptr, NodeOutput *> &output_ptrs, QList<NodeInput::SerializedConnection>& input_connections, QList<NodeParam::FootageConnection>& footage_connections, const QAtomicInt* cancelled)
|
||||
{
|
||||
XMLReadLoop(reader, (element.isEmpty() ? "node" : element)) {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "input" || reader->name() == "output") {
|
||||
QString param_id;
|
||||
if (reader->name() == QStringLiteral("input") || reader->name() == QStringLiteral("output")) {
|
||||
QString param_id;
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == "id") {
|
||||
param_id = attr.value().toString();
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == QStringLiteral("id")) {
|
||||
param_id = attr.value().toString();
|
||||
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (param_id.isEmpty()) {
|
||||
qDebug() << "Found parameter with no ID";
|
||||
continue;
|
||||
}
|
||||
|
||||
NodeParam* param = GetParameterWithID(param_id);
|
||||
|
||||
if (!param) {
|
||||
qDebug() << "No parameter in" << id() << "with parameter" << param_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
param->Load(reader, output_ptrs, input_connections, footage_connections, cancelled);
|
||||
}
|
||||
|
||||
if (param_id.isEmpty()) {
|
||||
qDebug() << "Found parameter with no ID";
|
||||
continue;
|
||||
}
|
||||
|
||||
NodeParam* param = GetParameterWithID(param_id);
|
||||
|
||||
if (!param) {
|
||||
qDebug() << "No parameter in" << id() << "with parameter" << param_id;
|
||||
continue;
|
||||
}
|
||||
|
||||
param->Load(reader, output_ptrs, input_connections, footage_connections, cancelled);
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -67,7 +67,7 @@ public:
|
||||
/**
|
||||
* @brief Clear current node variables and replace them with
|
||||
*/
|
||||
void Load(QXmlStreamReader* reader, QHash<quintptr, NodeOutput*>& param_ptrs, QList<NodeInput::SerializedConnection> &input_connections, QList<NodeParam::FootageConnection>& footage_connections, const QAtomicInt *cancelled, const QString &element = QString());
|
||||
void Load(QXmlStreamReader* reader, QHash<quintptr, NodeOutput*>& param_ptrs, QList<NodeInput::SerializedConnection> &input_connections, QList<NodeParam::FootageConnection>& footage_connections, const QAtomicInt *cancelled);
|
||||
|
||||
/**
|
||||
* @brief Save this node into a text/XML format
|
||||
|
||||
@@ -55,6 +55,8 @@ void NodeOutput::Load(QXmlStreamReader* reader, QHash<quintptr, NodeOutput*>& pa
|
||||
param_ptrs.insert(saved_ptr, this);
|
||||
}
|
||||
}
|
||||
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
void NodeOutput::Save(QXmlStreamWriter *writer) const
|
||||
|
||||
@@ -46,37 +46,38 @@ QIcon Folder::icon()
|
||||
|
||||
void Folder::Load(QXmlStreamReader *reader, QHash<quintptr, StreamPtr> &footage_ptrs, QList<NodeParam::FootageConnection>& footage_connections, const QAtomicInt *cancelled)
|
||||
{
|
||||
qDebug() << "Hello?";
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr.name() == "name") {
|
||||
if (attr.name() == QStringLiteral("name")) {
|
||||
set_name(attr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
XMLReadLoop(reader, "folder") {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement()) {
|
||||
ItemPtr child;
|
||||
ItemPtr child;
|
||||
|
||||
if (reader->name() == "folder") {
|
||||
child = std::make_shared<Folder>();
|
||||
} else if (reader->name() == "footage") {
|
||||
child = std::make_shared<Footage>();
|
||||
} else if (reader->name() == "sequence") {
|
||||
child = std::make_shared<Sequence>();
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
add_child(child);
|
||||
child->Load(reader, footage_ptrs, footage_connections, cancelled);
|
||||
if (reader->name() == QStringLiteral("folder")) {
|
||||
child = std::make_shared<Folder>();
|
||||
} else if (reader->name() == QStringLiteral("footage")) {
|
||||
child = std::make_shared<Footage>();
|
||||
} else if (reader->name() == QStringLiteral("sequence")) {
|
||||
child = std::make_shared<Sequence>();
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
continue;
|
||||
}
|
||||
|
||||
add_child(child);
|
||||
child->Load(reader, footage_ptrs, footage_connections, cancelled);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -40,48 +40,50 @@ Footage::~Footage()
|
||||
|
||||
void Footage::Load(QXmlStreamReader *reader, QHash<quintptr, StreamPtr>& footage_ptrs, QList<NodeParam::FootageConnection>&, const QAtomicInt* cancelled)
|
||||
{
|
||||
qDebug() << "Hello?";
|
||||
|
||||
QXmlStreamAttributes attributes = reader->attributes();
|
||||
|
||||
foreach (const QXmlStreamAttribute& attr, attributes) {
|
||||
if (attr.name() == "name") {
|
||||
if (attr.name() == QStringLiteral("name")) {
|
||||
set_name(attr.value().toString());
|
||||
} else if (attr.name() == "filename") {
|
||||
} else if (attr.name() == QStringLiteral("filename")) {
|
||||
set_filename(attr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
Decoder::ProbeMedia(this, cancelled);
|
||||
|
||||
XMLReadLoop(reader, "footage") {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "stream") {
|
||||
int stream_index = -1;
|
||||
quintptr stream_ptr = 0;
|
||||
if (reader->name() == QStringLiteral("stream")) {
|
||||
int stream_index = -1;
|
||||
quintptr stream_ptr = 0;
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (attr.name() == "index") {
|
||||
stream_index = attr.value().toInt();
|
||||
} else if (attr.name() == "ptr") {
|
||||
stream_ptr = attr.value().toULongLong();
|
||||
}
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (stream_index > -1 && stream_ptr > 0) {
|
||||
footage_ptrs.insert(stream_ptr, stream(stream_index));
|
||||
|
||||
stream(stream_index)->Load(reader);
|
||||
} else {
|
||||
qWarning() << "Invalid stream found in project file";
|
||||
if (attr.name() == QStringLiteral("index")) {
|
||||
stream_index = attr.value().toInt();
|
||||
} else if (attr.name() == QStringLiteral("ptr")) {
|
||||
stream_ptr = attr.value().toULongLong();
|
||||
}
|
||||
}
|
||||
|
||||
if (stream_index > -1 && stream_ptr > 0) {
|
||||
footage_ptrs.insert(stream_ptr, stream(stream_index));
|
||||
|
||||
stream(stream_index)->Load(reader);
|
||||
} else {
|
||||
qWarning() << "Invalid stream found in project file";
|
||||
}
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,10 +43,11 @@ void ImageStream::FootageSetEvent(Footage *f)
|
||||
|
||||
void ImageStream::LoadCustomParameters(QXmlStreamReader *reader)
|
||||
{
|
||||
XMLReadLoop(reader, "stream") {
|
||||
if (reader->isStartElement() && reader->name() == "colorspace") {
|
||||
reader->readNext();
|
||||
set_colorspace(reader->text().toString());
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("colorspace")) {
|
||||
set_colorspace(reader->readElementText());
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,8 +151,9 @@ void Stream::FootageSetEvent(Footage*)
|
||||
{
|
||||
}
|
||||
|
||||
void Stream::LoadCustomParameters(QXmlStreamReader*)
|
||||
void Stream::LoadCustomParameters(QXmlStreamReader* reader)
|
||||
{
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
void Stream::SaveCustomParameters(QXmlStreamWriter*) const
|
||||
|
||||
@@ -59,68 +59,63 @@ void Sequence::Load(QXmlStreamReader *reader, QHash<quintptr, StreamPtr> &, QLis
|
||||
QHash<quintptr, NodeOutput*> output_ptrs;
|
||||
QList<NodeParam::SerializedConnection> desired_connections;
|
||||
|
||||
XMLReadLoop(reader, "sequence") {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "video") {
|
||||
int video_width, video_height;
|
||||
rational video_timebase;
|
||||
if (reader->name() == QStringLiteral("video")) {
|
||||
int video_width, video_height;
|
||||
rational video_timebase;
|
||||
|
||||
XMLReadLoop(reader, "video") {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "width") {
|
||||
reader->readNext();
|
||||
video_width = reader->text().toInt();
|
||||
} else if (reader->name() == "height") {
|
||||
reader->readNext();
|
||||
video_height = reader->text().toInt();
|
||||
} else if (reader->name() == "timebase") {
|
||||
reader->readNext();
|
||||
video_timebase = rational::fromString(reader->text().toString());
|
||||
}
|
||||
}
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (cancelled && *cancelled) {
|
||||
return;
|
||||
}
|
||||
|
||||
set_video_params(VideoParams(video_width, video_height, video_timebase));
|
||||
} else if (reader->name() == "audio") {
|
||||
int rate;
|
||||
uint64_t layout;
|
||||
|
||||
XMLReadLoop(reader, "audio") {
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "rate") {
|
||||
reader->readNext();
|
||||
rate = reader->text().toInt();
|
||||
} else if (reader->name() == "layout") {
|
||||
reader->readNext();
|
||||
layout = reader->text().toULongLong();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
set_audio_params(AudioParams(rate, layout));
|
||||
} else if (reader->name() == "node" || reader->name() == "viewer") {
|
||||
Node* node;
|
||||
|
||||
if (reader->name() == "node") {
|
||||
node = XMLLoadNode(reader);
|
||||
if (reader->name() == QStringLiteral("width")) {
|
||||
video_width = reader->readElementText().toInt();
|
||||
} else if (reader->name() == QStringLiteral("height")) {
|
||||
video_height = reader->readElementText().toInt();
|
||||
} else if (reader->name() == QStringLiteral("timebase")) {
|
||||
video_timebase = rational::fromString(reader->readElementText());
|
||||
} else {
|
||||
node = viewer_output_;
|
||||
}
|
||||
|
||||
if (node) {
|
||||
node->Load(reader, output_ptrs, desired_connections, footage_connections, cancelled, reader->name().toString());
|
||||
|
||||
AddNode(node);
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
set_video_params(VideoParams(video_width, video_height, video_timebase));
|
||||
} else if (reader->name() == QStringLiteral("audio")) {
|
||||
int rate;
|
||||
uint64_t layout;
|
||||
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("rate")) {
|
||||
rate = reader->readElementText().toInt();
|
||||
} else if (reader->name() == QStringLiteral("layout")) {
|
||||
layout = reader->readElementText().toULongLong();
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
set_audio_params(AudioParams(rate, layout));
|
||||
} else if (reader->name() == QStringLiteral("node") || reader->name() == QStringLiteral("viewer")) {
|
||||
Node* node;
|
||||
|
||||
if (reader->name() == QStringLiteral("node")) {
|
||||
node = XMLLoadNode(reader);
|
||||
} else {
|
||||
node = viewer_output_;
|
||||
}
|
||||
|
||||
if (node) {
|
||||
node->Load(reader, output_ptrs, desired_connections, footage_connections, cancelled);
|
||||
|
||||
AddNode(node);
|
||||
}
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+19
-16
@@ -35,29 +35,32 @@ Project::Project()
|
||||
|
||||
void Project::Load(QXmlStreamReader *reader, const QAtomicInt* cancelled)
|
||||
{
|
||||
qDebug() << "Hello?";
|
||||
|
||||
QHash<quintptr, StreamPtr> footage_ptrs;
|
||||
QList<NodeInput::FootageConnection> footage_connections;
|
||||
|
||||
XMLReadLoop(reader, "project") {
|
||||
if (reader->isStartElement()) {
|
||||
if (reader->name() == "folder") {
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("folder")) {
|
||||
|
||||
// Assume this folder is our root
|
||||
root_.Load(reader, footage_ptrs, footage_connections, cancelled);
|
||||
// Assume this folder is our root
|
||||
root_.Load(reader, footage_ptrs, footage_connections, cancelled);
|
||||
|
||||
} else if (reader->name() == "colormanagement") {
|
||||
} else if (reader->name() == QStringLiteral("colormanagement")) {
|
||||
|
||||
// Read color management info
|
||||
XMLReadLoop(reader, "colormanagement") {
|
||||
if (reader->name() == "config") {
|
||||
reader->readNext();
|
||||
set_ocio_config(reader->text().toString());
|
||||
} else if (reader->name() == "default") {
|
||||
reader->readNext();
|
||||
set_default_input_colorspace(reader->text().toString());
|
||||
}
|
||||
// Read color management info
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("config")) {
|
||||
set_ocio_config(reader->readElementText());
|
||||
} else if (reader->name() == QStringLiteral("default")) {
|
||||
set_default_input_colorspace(reader->readElementText());
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +100,7 @@ QString Project::name() const
|
||||
if (filename_.isEmpty()) {
|
||||
return tr("(untitled)");
|
||||
} else {
|
||||
return QFileInfo(filename_).baseName();
|
||||
return QFileInfo(filename_).completeBaseName();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "common/xmlutils.h"
|
||||
|
||||
ProjectLoadManager::ProjectLoadManager(const QString &filename) :
|
||||
filename_(filename)
|
||||
{
|
||||
@@ -17,28 +19,32 @@ void ProjectLoadManager::Action()
|
||||
if (project_file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
QXmlStreamReader reader(&project_file);
|
||||
|
||||
while (!reader.atEnd()) {
|
||||
reader.readNext();
|
||||
qDebug() << "Hello?";
|
||||
|
||||
if (reader.isStartElement()) {
|
||||
if (reader.name() == "version") {
|
||||
reader.readNext();
|
||||
while (XMLReadNextStartElement(&reader)) {
|
||||
if (reader.name() == QStringLiteral("olive")) {
|
||||
while(XMLReadNextStartElement(&reader)) {
|
||||
if (reader.name() == QStringLiteral("version")) {
|
||||
qDebug() << "Project version:" << reader.readElementText();
|
||||
} else if (reader.name() == QStringLiteral("project")) {
|
||||
ProjectPtr project = std::make_shared<Project>();
|
||||
|
||||
qDebug() << "Project version:" << reader.text();
|
||||
} else if (reader.name() == "project") {
|
||||
ProjectPtr project = std::make_shared<Project>();
|
||||
project->set_filename(filename_);
|
||||
|
||||
project->set_filename(filename_);
|
||||
project->Load(&reader, &IsCancelled());
|
||||
|
||||
project->Load(&reader, &IsCancelled());
|
||||
// Ensure project is in main thread
|
||||
moveToThread(qApp->thread());
|
||||
|
||||
// Ensure project is in main thread
|
||||
moveToThread(qApp->thread());
|
||||
|
||||
if (!IsCancelled()) {
|
||||
emit ProjectLoaded(project);
|
||||
if (!IsCancelled()) {
|
||||
emit ProjectLoaded(project);
|
||||
}
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -186,17 +186,25 @@ void NodeView::Paste()
|
||||
QList<NodeParam::SerializedConnection> desired_connections;
|
||||
QList<NodeInput::FootageConnection> footage_connections;
|
||||
|
||||
XMLReadLoop((&reader), QStringLiteral("olive")) {
|
||||
if (reader.name() == QStringLiteral("node")) {
|
||||
Node* node = XMLLoadNode(&reader);
|
||||
while (XMLReadNextStartElement(&reader)) {
|
||||
if (reader.name() == QStringLiteral("olive")) {
|
||||
while (XMLReadNextStartElement(&reader)) {
|
||||
if (reader.name() == QStringLiteral("node")) {
|
||||
Node* node = XMLLoadNode(&reader);
|
||||
|
||||
if (node) {
|
||||
node->Load(&reader, output_ptrs, desired_connections, footage_connections, nullptr, reader.name().toString());
|
||||
if (node) {
|
||||
node->Load(&reader, output_ptrs, desired_connections, footage_connections, nullptr);
|
||||
|
||||
graph_->AddNode(node);
|
||||
graph_->AddNode(node);
|
||||
|
||||
pasted_nodes.append(node);
|
||||
pasted_nodes.append(node);
|
||||
}
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
reader.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user