timelinepoints: implemented saving/loading into project files
This commit is contained in:
@@ -48,6 +48,11 @@ bool TimeRange::operator==(const TimeRange &r) const
|
||||
return in() == r.in() && out() == r.out();
|
||||
}
|
||||
|
||||
bool TimeRange::operator!=(const TimeRange &r) const
|
||||
{
|
||||
return in() != r.in() || out() != r.out();
|
||||
}
|
||||
|
||||
bool TimeRange::OverlapsWith(const TimeRange &a, bool in_inclusive, bool out_inclusive) const
|
||||
{
|
||||
bool overlaps_in = (in_inclusive) ? (a.out() < in()) : (a.out() <= in());
|
||||
|
||||
@@ -17,6 +17,7 @@ public:
|
||||
void set_range(const rational& in, const rational& out);
|
||||
|
||||
bool operator==(const TimeRange& r) const;
|
||||
bool operator!=(const TimeRange& r) const;
|
||||
|
||||
bool OverlapsWith(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const;
|
||||
bool Contains(const TimeRange& a, bool in_inclusive = true, bool out_inclusive = true) const;
|
||||
|
||||
@@ -80,6 +80,8 @@ void Footage::Load(QXmlStreamReader *reader, XMLNodeData &xml_node_data, const Q
|
||||
} else {
|
||||
qWarning() << "Invalid stream found in project file";
|
||||
}
|
||||
} else if (reader->name() == QStringLiteral("points")) {
|
||||
TimelinePoints::Load(reader);
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
@@ -93,6 +95,8 @@ void Footage::Save(QXmlStreamWriter *writer) const
|
||||
writer->writeAttribute("name", name());
|
||||
writer->writeAttribute("filename", filename());
|
||||
|
||||
TimelinePoints::Save(writer);
|
||||
|
||||
foreach (StreamPtr stream, streams_) {
|
||||
stream->Save(writer);
|
||||
}
|
||||
|
||||
@@ -97,6 +97,10 @@ void Sequence::Load(QXmlStreamReader *reader, XMLNodeData& xml_node_data, const
|
||||
}
|
||||
|
||||
set_audio_params(AudioParams(rate, layout));
|
||||
} else if (reader->name() == QStringLiteral("points")) {
|
||||
|
||||
TimelinePoints::Load(reader);
|
||||
|
||||
} else if (reader->name() == QStringLiteral("node") || reader->name() == QStringLiteral("viewer")) {
|
||||
Node* node;
|
||||
|
||||
@@ -150,6 +154,9 @@ void Sequence::Save(QXmlStreamWriter *writer) const
|
||||
|
||||
writer->writeEndElement(); // audio
|
||||
|
||||
// Write TimelinePoints
|
||||
TimelinePoints::Save(writer);
|
||||
|
||||
foreach (Node* node, nodes()) {
|
||||
if (node != viewer_output_) {
|
||||
node->Save(writer);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "timelinemarker.h"
|
||||
|
||||
#include "common/xmlutils.h"
|
||||
|
||||
TimelineMarker::TimelineMarker(const TimeRange &time, const QString &name, QObject *parent) :
|
||||
QObject(parent),
|
||||
time_(time),
|
||||
@@ -29,6 +31,24 @@ void TimelineMarker::set_name(const QString &name)
|
||||
emit NameChanged(name_);
|
||||
}
|
||||
|
||||
void TimelineMarkerList::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement(QStringLiteral("markers"));
|
||||
|
||||
foreach (TimelineMarker* marker, markers_) {
|
||||
writer->writeStartElement(QStringLiteral("marker"));
|
||||
|
||||
writer->writeAttribute(QStringLiteral("name"), marker->name());
|
||||
|
||||
writer->writeAttribute(QStringLiteral("in"), marker->time().in().toString());
|
||||
writer->writeAttribute(QStringLiteral("out"), marker->time().out().toString());
|
||||
|
||||
writer->writeEndElement(); // marker
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // markers
|
||||
}
|
||||
|
||||
TimelineMarkerList::~TimelineMarkerList()
|
||||
{
|
||||
qDeleteAll(markers_);
|
||||
@@ -59,3 +79,25 @@ const QList<TimelineMarker*> &TimelineMarkerList::list() const
|
||||
{
|
||||
return markers_;
|
||||
}
|
||||
|
||||
void TimelineMarkerList::Load(QXmlStreamReader *reader)
|
||||
{
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("marker")) {
|
||||
QString name;
|
||||
TimeRange range;
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == QStringLiteral("name")) {
|
||||
name = attr.value().toString();
|
||||
} else if (attr.name() == QStringLiteral("in")) {
|
||||
range.set_in(rational::fromString(attr.value().toString()));
|
||||
} else if (attr.name() == QStringLiteral("out")) {
|
||||
range.set_out(rational::fromString(attr.value().toString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#define TIMELINEMARKER_H
|
||||
|
||||
#include <QString>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "common/timerange.h"
|
||||
|
||||
@@ -43,6 +45,9 @@ public:
|
||||
|
||||
const QList<TimelineMarker *> &list() const;
|
||||
|
||||
void Load(QXmlStreamReader* reader);
|
||||
void Save(QXmlStreamWriter* writer) const;
|
||||
|
||||
signals:
|
||||
void MarkerAdded(TimelineMarker* marker);
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "timelinepoints.h"
|
||||
|
||||
#include "common/xmlutils.h"
|
||||
|
||||
TimelineMarkerList *TimelinePoints::markers()
|
||||
{
|
||||
return &markers_;
|
||||
@@ -15,6 +17,30 @@ const TimelineWorkArea *TimelinePoints::workarea() const
|
||||
return &workarea_;
|
||||
}
|
||||
|
||||
void TimelinePoints::Load(QXmlStreamReader *reader)
|
||||
{
|
||||
while (XMLReadNextStartElement(reader)) {
|
||||
if (reader->name() == QStringLiteral("markers")) {
|
||||
markers_.Load(reader);
|
||||
} else if (reader->name() == QStringLiteral("workarea")) {
|
||||
workarea_.Load(reader);
|
||||
} else {
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TimelinePoints::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement(QStringLiteral("points"));
|
||||
|
||||
workarea_.Save(writer);
|
||||
|
||||
markers_.Save(writer);
|
||||
|
||||
writer->writeEndElement(); // points
|
||||
}
|
||||
|
||||
TimelineWorkArea *TimelinePoints::workarea()
|
||||
{
|
||||
return &workarea_;
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
#ifndef TIMELINEPOINTS_H
|
||||
#define TIMELINEPOINTS_H
|
||||
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "timelinemarker.h"
|
||||
#include "timelineworkarea.h"
|
||||
|
||||
@@ -15,6 +18,9 @@ public:
|
||||
TimelineWorkArea* workarea();
|
||||
const TimelineWorkArea* workarea() const;
|
||||
|
||||
void Load(QXmlStreamReader* reader);
|
||||
void Save(QXmlStreamWriter* writer) const;
|
||||
|
||||
private:
|
||||
TimelineMarkerList markers_;
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "timelineworkarea.h"
|
||||
|
||||
#include "common/xmlutils.h"
|
||||
|
||||
const rational TimelineWorkArea::kResetIn = 0;
|
||||
const rational TimelineWorkArea::kResetOut = RATIONAL_MAX;
|
||||
|
||||
@@ -30,6 +32,41 @@ void TimelineWorkArea::set_range(const TimeRange &range)
|
||||
emit RangeChanged(workarea_range_);
|
||||
}
|
||||
|
||||
void TimelineWorkArea::Load(QXmlStreamReader *reader)
|
||||
{
|
||||
rational range_in = workarea_range_.in();
|
||||
rational range_out = workarea_range_.out();
|
||||
|
||||
XMLAttributeLoop(reader, attr) {
|
||||
if (attr.name() == QStringLiteral("enabled")) {
|
||||
set_enabled(attr.value() != 0);
|
||||
} else if (attr.name() == QStringLiteral("in")) {
|
||||
range_in = rational::fromString(attr.value().toString());
|
||||
} else if (attr.name() == QStringLiteral("out")) {
|
||||
range_out = rational::fromString(attr.value().toString());
|
||||
}
|
||||
}
|
||||
|
||||
TimeRange loaded_workarea(range_in, range_out);
|
||||
|
||||
if (loaded_workarea != workarea_range_) {
|
||||
set_range(loaded_workarea);
|
||||
}
|
||||
|
||||
reader->skipCurrentElement();
|
||||
}
|
||||
|
||||
void TimelineWorkArea::Save(QXmlStreamWriter *writer) const
|
||||
{
|
||||
writer->writeStartElement(QStringLiteral("workarea"));
|
||||
|
||||
writer->writeAttribute(QStringLiteral("enabled"), QString::number(workarea_enabled_));
|
||||
writer->writeAttribute(QStringLiteral("in"), workarea_range_.in().toString());
|
||||
writer->writeAttribute(QStringLiteral("out"), workarea_range_.out().toString());
|
||||
|
||||
writer->writeEndElement(); // workarea
|
||||
}
|
||||
|
||||
const rational &TimelineWorkArea::in() const
|
||||
{
|
||||
return workarea_range_.in();
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
#define TIMELINEWORKAREA_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
|
||||
#include "common/timerange.h"
|
||||
|
||||
@@ -19,6 +21,9 @@ public:
|
||||
const TimeRange& range() const;
|
||||
void set_range(const TimeRange& range);
|
||||
|
||||
void Load(QXmlStreamReader* reader);
|
||||
void Save(QXmlStreamWriter* writer) const;
|
||||
|
||||
static const rational kResetIn;
|
||||
static const rational kResetOut;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user