added save functions to various classes
Each class is responsible for its own saving and loading from the XML data in order to reduce the complexity of the save code.
This commit is contained in:
@@ -117,6 +117,11 @@ const intType &rational::denominator() const
|
||||
return denom;
|
||||
}
|
||||
|
||||
QString rational::toString() const
|
||||
{
|
||||
return QStringLiteral("%1/%2").arg(QString::number(numer), QString::number(denom));
|
||||
}
|
||||
|
||||
//Assignment Operators
|
||||
|
||||
const rational& rational::operator=(const rational &rhs)
|
||||
|
||||
@@ -108,6 +108,8 @@ public:
|
||||
const intType& numerator() const;
|
||||
const intType& denominator() const;
|
||||
|
||||
QString toString() const;
|
||||
|
||||
private:
|
||||
//numerator and denominator
|
||||
intType numer;
|
||||
|
||||
+2
-2
@@ -72,12 +72,12 @@ void NodeGraph::TakeNode(Node *node, QObject* new_parent)
|
||||
emit NodeRemoved(node);
|
||||
}
|
||||
|
||||
const QList<Node *> &NodeGraph::nodes()
|
||||
const QList<Node *> &NodeGraph::nodes() const
|
||||
{
|
||||
return node_children_;
|
||||
}
|
||||
|
||||
bool NodeGraph::ContainsNode(Node *n)
|
||||
bool NodeGraph::ContainsNode(Node *n) const
|
||||
{
|
||||
return (n->parent() == this);
|
||||
}
|
||||
|
||||
+2
-2
@@ -58,12 +58,12 @@ public:
|
||||
/**
|
||||
* @brief Retrieve a complete list of the nodes belonging to this graph
|
||||
*/
|
||||
const QList<Node*>& nodes();
|
||||
const QList<Node*>& nodes() const;
|
||||
|
||||
/**
|
||||
* @brief Returns whether a certain Node is in the graph or not
|
||||
*/
|
||||
bool ContainsNode(Node* n);
|
||||
bool ContainsNode(Node* n) const;
|
||||
|
||||
signals:
|
||||
/**
|
||||
|
||||
@@ -84,11 +84,63 @@ QString NodeInput::name()
|
||||
return NodeParam::name();
|
||||
}
|
||||
|
||||
void NodeInput::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("input");
|
||||
|
||||
writer->writeAttribute("id", id());
|
||||
|
||||
writer->writeAttribute("ptr", QString::number(reinterpret_cast<quintptr>(this)));
|
||||
|
||||
writer->writeAttribute("keyframing", QString::number(keyframing_));
|
||||
|
||||
// Write standard value
|
||||
writer->writeStartElement("standard");
|
||||
|
||||
foreach (const QVariant& v, standard_value_) {
|
||||
writer->writeTextElement("value", v.toString());
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // standard
|
||||
|
||||
// Write keyframes
|
||||
writer->writeStartElement("keyframes");
|
||||
|
||||
foreach (const KeyframeTrack& track, keyframe_tracks()) {
|
||||
writer->writeStartElement("track");
|
||||
|
||||
foreach (NodeKeyframePtr key, track) {
|
||||
writer->writeStartElement("key");
|
||||
|
||||
writer->writeAttribute("time", key->time().toString());
|
||||
writer->writeAttribute("type", QString::number(key->type()));
|
||||
|
||||
writer->writeCharacters(key->value().toString());
|
||||
|
||||
writer->writeEndElement(); // key
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // track
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // keyframes
|
||||
|
||||
SaveConnections(writer);
|
||||
|
||||
SaveInternal(writer);
|
||||
|
||||
writer->writeEndElement(); // input
|
||||
}
|
||||
|
||||
const NodeParam::DataType &NodeInput::data_type() const
|
||||
{
|
||||
return data_type_;
|
||||
}
|
||||
|
||||
void NodeInput::SaveInternal(QXmlStreamWriter *writer) const
|
||||
{
|
||||
}
|
||||
|
||||
NodeOutput *NodeInput::get_connected_output() const
|
||||
{
|
||||
if (!edges_.isEmpty()) {
|
||||
|
||||
@@ -54,6 +54,8 @@ public:
|
||||
|
||||
virtual QString name() override;
|
||||
|
||||
virtual void Save(QXmlStreamWriter* writer) const override;
|
||||
|
||||
/**
|
||||
* @brief The data type this parameter outputs
|
||||
*
|
||||
@@ -238,6 +240,9 @@ signals:
|
||||
|
||||
void KeyframeRemoved(NodeKeyframePtr key);
|
||||
|
||||
protected:
|
||||
virtual void SaveInternal(QXmlStreamWriter* writer) const;
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Returns whether a data type can be interpolated or not
|
||||
|
||||
@@ -166,3 +166,14 @@ void NodeInputArray::RemoveAt(int index)
|
||||
|
||||
RemoveLast();
|
||||
}
|
||||
|
||||
void NodeInputArray::SaveInternal(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("subparameters");
|
||||
|
||||
foreach (NodeInput* sub, sub_params_) {
|
||||
sub->Save(writer);
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // subparameters
|
||||
}
|
||||
|
||||
@@ -32,6 +32,9 @@ public:
|
||||
signals:
|
||||
void SizeChanged(int size);
|
||||
|
||||
protected:
|
||||
virtual void SaveInternal(QXmlStreamWriter* writer) const override;
|
||||
|
||||
private:
|
||||
QVector<NodeInput*> sub_params_;
|
||||
|
||||
|
||||
@@ -47,6 +47,19 @@ Node::~Node()
|
||||
}
|
||||
}
|
||||
|
||||
void Node::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("node");
|
||||
|
||||
writer->writeAttribute("id", id());
|
||||
|
||||
foreach (NodeParam* param, parameters()) {
|
||||
param->Save(writer);
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // node
|
||||
}
|
||||
|
||||
QString Node::Category() const
|
||||
{
|
||||
// Return an empty category for any nodes that don't use one
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QMutex>
|
||||
#include <QObject>
|
||||
#include <QPointF>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "node/dependency.h"
|
||||
@@ -64,6 +65,11 @@ public:
|
||||
*/
|
||||
virtual Node* copy() const = 0;
|
||||
|
||||
/**
|
||||
* @brief Save this node into a text/XML format
|
||||
*/
|
||||
void Save(QXmlStreamWriter* writer) const;
|
||||
|
||||
/**
|
||||
* @brief Return the name of the node
|
||||
*
|
||||
|
||||
@@ -40,3 +40,16 @@ QString NodeOutput::name()
|
||||
|
||||
return NodeParam::name();
|
||||
}
|
||||
|
||||
void NodeOutput::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("output");
|
||||
|
||||
writer->writeAttribute("id", id());
|
||||
|
||||
writer->writeAttribute("ptr", QString::number(reinterpret_cast<quintptr>(this)));
|
||||
|
||||
SaveConnections(writer);
|
||||
|
||||
writer->writeEndElement(); // output
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@ public:
|
||||
|
||||
virtual QString name() override;
|
||||
|
||||
virtual void Save(QXmlStreamWriter* writer) const override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
@@ -282,3 +282,23 @@ QByteArray NodeParam::ValueToBytesInternal(const QVariant &v)
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void NodeParam::SaveConnections(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("connections");
|
||||
|
||||
foreach (NodeEdgePtr edge, edges_) {
|
||||
NodeParam* other;
|
||||
|
||||
if (edge->input() == this) {
|
||||
other = edge->output();
|
||||
} else {
|
||||
other = edge->input();
|
||||
}
|
||||
|
||||
writer->writeTextElement("connection",
|
||||
QString::number(reinterpret_cast<quintptr>(other)));
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // connections
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
#include <QVector>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "common/rational.h"
|
||||
#include "node/edge.h"
|
||||
@@ -229,6 +230,11 @@ public:
|
||||
|
||||
virtual ~NodeParam() override;
|
||||
|
||||
/**
|
||||
* @brief Save function
|
||||
*/
|
||||
virtual void Save(QXmlStreamWriter* writer) const = 0;
|
||||
|
||||
/**
|
||||
* @brief Return ID of this parameter
|
||||
*/
|
||||
@@ -368,6 +374,8 @@ signals:
|
||||
void EdgeRemoved(NodeEdgePtr edge);
|
||||
|
||||
protected:
|
||||
void SaveConnections(QXmlStreamWriter* writer) const;
|
||||
|
||||
/**
|
||||
* @brief Internal list of edges
|
||||
*/
|
||||
|
||||
@@ -40,3 +40,16 @@ QIcon Folder::icon()
|
||||
{
|
||||
return icon::Folder;
|
||||
}
|
||||
|
||||
void Folder::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("folder");
|
||||
|
||||
writer->writeAttribute("name", name());
|
||||
|
||||
foreach (ItemPtr child, children()) {
|
||||
child->Save(writer);
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // folder
|
||||
}
|
||||
|
||||
@@ -40,6 +40,8 @@ public:
|
||||
|
||||
virtual QIcon icon() override;
|
||||
|
||||
virtual void Save(QXmlStreamWriter* writer) const override;
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
@@ -35,6 +35,21 @@ Footage::~Footage()
|
||||
ClearStreams();
|
||||
}
|
||||
|
||||
void Footage::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("footage");
|
||||
|
||||
writer->writeAttribute("name", name());
|
||||
writer->writeAttribute("filename", filename());
|
||||
writer->writeAttribute("ptr", FootageToString(this));
|
||||
|
||||
foreach (StreamPtr stream, streams_) {
|
||||
stream->Save(writer);
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // footage
|
||||
}
|
||||
|
||||
const Footage::Status& Footage::status() const
|
||||
{
|
||||
return status_;
|
||||
@@ -147,7 +162,6 @@ QIcon Footage::icon()
|
||||
return QIcon();
|
||||
}
|
||||
|
||||
#include <QDebug>
|
||||
QString Footage::duration()
|
||||
{
|
||||
if (streams_.isEmpty()) {
|
||||
@@ -283,3 +297,8 @@ void Footage::UpdateTooltip()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString FootageToString(const Footage *footage)
|
||||
{
|
||||
return QString::number(reinterpret_cast<quintptr>(footage));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,10 @@ public:
|
||||
*/
|
||||
virtual ~Footage() override;
|
||||
|
||||
DISABLE_COPY_MOVE(Footage)
|
||||
/**
|
||||
* @brief Save function
|
||||
*/
|
||||
virtual void Save(QXmlStreamWriter *writer) const override;
|
||||
|
||||
/**
|
||||
* @brief Check the ready state of this Footage object
|
||||
@@ -252,6 +255,8 @@ private:
|
||||
|
||||
};
|
||||
|
||||
QString FootageToString(const Footage* footage);
|
||||
|
||||
using FootagePtr = std::shared_ptr<Footage>;
|
||||
|
||||
#endif // FOOTAGE_H
|
||||
|
||||
@@ -36,6 +36,11 @@ void ImageStream::FootageSetEvent(Footage *f)
|
||||
connect(f->project()->color_manager(), SIGNAL(ConfigChanged()), this, SLOT(ColorConfigChanged()), Qt::DirectConnection);
|
||||
}
|
||||
|
||||
void ImageStream::SaveCustomParameters(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeTextElement("colorspace", colorspace_);
|
||||
}
|
||||
|
||||
QString ImageStream::description()
|
||||
{
|
||||
return QCoreApplication::translate("Stream", "%1: Image - %2x%3").arg(QString::number(index()),
|
||||
|
||||
@@ -52,6 +52,8 @@ signals:
|
||||
protected:
|
||||
virtual void FootageSetEvent(Footage*) override;
|
||||
|
||||
virtual void SaveCustomParameters(QXmlStreamWriter* writer) const override;
|
||||
|
||||
private:
|
||||
int width_;
|
||||
int height_;
|
||||
|
||||
@@ -35,6 +35,17 @@ Stream::~Stream()
|
||||
{
|
||||
}
|
||||
|
||||
void Stream::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("stream");
|
||||
|
||||
writer->writeAttribute("index", QString::number(index_));
|
||||
|
||||
SaveCustomParameters(writer);
|
||||
|
||||
writer->writeEndElement(); // stream
|
||||
}
|
||||
|
||||
QString Stream::description()
|
||||
{
|
||||
return QCoreApplication::translate("Stream", "%1: Unknown").arg(index());
|
||||
@@ -122,6 +133,14 @@ StreamID Stream::ToID() const
|
||||
return StreamID(footage_->filename(), index_);
|
||||
}
|
||||
|
||||
void Stream::FootageSetEvent(Footage *)
|
||||
{
|
||||
}
|
||||
|
||||
void Stream::SaveCustomParameters(QXmlStreamWriter *writer) const
|
||||
{
|
||||
}
|
||||
|
||||
StreamID::StreamID(const QString &filename, const int &stream_index) :
|
||||
filename_(filename),
|
||||
stream_index_(stream_index)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QCoreApplication>
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "common/rational.h"
|
||||
|
||||
@@ -74,6 +75,8 @@ public:
|
||||
*/
|
||||
virtual ~Stream();
|
||||
|
||||
void Save(QXmlStreamWriter *writer) const;
|
||||
|
||||
virtual QString description();
|
||||
|
||||
const Type& type();
|
||||
@@ -101,7 +104,9 @@ public:
|
||||
QMutex index_lock_;
|
||||
|
||||
protected:
|
||||
virtual void FootageSetEvent(Footage*){}
|
||||
virtual void FootageSetEvent(Footage*);
|
||||
|
||||
virtual void SaveCustomParameters(QXmlStreamWriter* writer) const;
|
||||
|
||||
private:
|
||||
Footage* footage_;
|
||||
|
||||
@@ -71,6 +71,11 @@ Item *Item::child(int i) const
|
||||
return children_.at(i).get();
|
||||
}
|
||||
|
||||
const QList<ItemPtr> &Item::children() const
|
||||
{
|
||||
return children_;
|
||||
}
|
||||
|
||||
ItemPtr Item::shared_ptr_from_raw(Item *item)
|
||||
{
|
||||
for (int i=0;i<children_.size();i++) {
|
||||
|
||||
+5
-18
@@ -26,7 +26,9 @@
|
||||
#include <QList>
|
||||
#include <QMutex>
|
||||
#include <QString>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "common/constructors.h"
|
||||
#include "common/threadedobject.h"
|
||||
|
||||
class Project;
|
||||
@@ -59,25 +61,9 @@ public:
|
||||
*/
|
||||
virtual ~Item();
|
||||
|
||||
/**
|
||||
* @brief Deleted copy constructor
|
||||
*/
|
||||
Item(const Item& other) = delete;
|
||||
DISABLE_COPY_MOVE(Item)
|
||||
|
||||
/**
|
||||
* @brief Deleted move constructor
|
||||
*/
|
||||
Item(Item&& other) = delete;
|
||||
|
||||
/**
|
||||
* @brief Deleted copy assignment
|
||||
*/
|
||||
Item& operator=(const Item& other) = delete;
|
||||
|
||||
/**
|
||||
* @brief Deleted move assignment
|
||||
*/
|
||||
Item& operator=(Item&& other) = delete;
|
||||
virtual void Save(QXmlStreamWriter* writer) const = 0;
|
||||
|
||||
virtual Type type() const = 0;
|
||||
|
||||
@@ -85,6 +71,7 @@ public:
|
||||
void remove_child(Item* c);
|
||||
int child_count() const;
|
||||
Item* child(int i) const;
|
||||
const QList<ItemPtr>& children() const;
|
||||
|
||||
ItemPtr shared_ptr_from_raw(Item* item);
|
||||
|
||||
|
||||
@@ -38,6 +38,19 @@ Sequence::Sequence() :
|
||||
{
|
||||
}
|
||||
|
||||
void Sequence::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("sequence");
|
||||
|
||||
writer->writeAttribute("name", name());
|
||||
|
||||
foreach (Node* node, nodes()) {
|
||||
node->Save(writer);
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // sequence
|
||||
}
|
||||
|
||||
void Sequence::Open(Sequence* sequence)
|
||||
{
|
||||
// FIXME: This is fairly "hardcoded" behavior and doesn't support infinite panels
|
||||
@@ -62,7 +75,6 @@ void Sequence::add_default_nodes()
|
||||
Node* audio_track_output = viewer_output_->track_list(Timeline::kTrackTypeAudio)->AddTrack();
|
||||
NodeParam::ConnectEdge(video_track_output->output(), viewer_output_->texture_input());
|
||||
NodeParam::ConnectEdge(audio_track_output->output(), viewer_output_->samples_input());
|
||||
//timeline_output_->track_list(TrackType::kTrackTypeVideo)->AddTrack();
|
||||
|
||||
// Update the timebase on these nodes
|
||||
set_video_params(video_params_);
|
||||
|
||||
@@ -38,6 +38,11 @@ class Sequence : public Item, public NodeGraph
|
||||
public:
|
||||
Sequence();
|
||||
|
||||
/**
|
||||
* @brief Save function
|
||||
*/
|
||||
virtual void Save(QXmlStreamWriter *writer) const override;
|
||||
|
||||
static void Open(Sequence *sequence);
|
||||
|
||||
void add_default_nodes();
|
||||
|
||||
@@ -27,6 +27,19 @@ Project::Project()
|
||||
root_.set_project(this);
|
||||
}
|
||||
|
||||
void Project::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement("project");
|
||||
|
||||
writer->writeTextElement("url", filename_);
|
||||
|
||||
root_.Save(writer);
|
||||
|
||||
|
||||
|
||||
writer->writeEndElement(); // project
|
||||
}
|
||||
|
||||
Folder *Project::root()
|
||||
{
|
||||
return &root_;
|
||||
|
||||
@@ -44,6 +44,8 @@ class Project : public QObject
|
||||
public:
|
||||
Project();
|
||||
|
||||
void Save(QXmlStreamWriter* writer) const;
|
||||
|
||||
Folder* root();
|
||||
|
||||
QString name() const;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "projectsavemanager.h"
|
||||
|
||||
#include <QFile>
|
||||
|
||||
ProjectSaveManager::ProjectSaveManager(Project *project) :
|
||||
project_(project),
|
||||
cancelled_(false)
|
||||
@@ -9,19 +11,22 @@ ProjectSaveManager::ProjectSaveManager(Project *project) :
|
||||
|
||||
void ProjectSaveManager::Start()
|
||||
{
|
||||
int prog = 0;
|
||||
QFile project_file(project_->filename());
|
||||
|
||||
do {
|
||||
if (cancelled_) {
|
||||
break;
|
||||
}
|
||||
if (project_file.open(QFile::WriteOnly | QFile::Text)) {
|
||||
QXmlStreamWriter writer(&project_file);
|
||||
writer.setAutoFormatting(true);
|
||||
|
||||
prog += 10;
|
||||
writer.writeStartDocument();
|
||||
|
||||
emit ProgressChanged(prog);
|
||||
writer.writeTextElement("version", "0.2.0");
|
||||
|
||||
Sleep(200);
|
||||
} while (prog < 100);
|
||||
project_->Save(&writer);
|
||||
|
||||
writer.writeEndDocument();
|
||||
|
||||
project_file.close();
|
||||
}
|
||||
|
||||
emit Finished();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#define PROJECTSAVEMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "project.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user