serialize rationals correctly and move block name to a node input
Since rationals aren't a known Qt format, the QVariant container can't automatically convert them to and from strings (for XML serialization). We have to hijack these functions and do the conversion manually for those types. Also moved the block name type to a node input, which means it's serialized and copied by default (I'm not sure why it wasn't already like this).
This commit is contained in:
@@ -28,6 +28,11 @@ Block::Block() :
|
||||
previous_(nullptr),
|
||||
next_(nullptr)
|
||||
{
|
||||
name_input_ = new NodeInput("name_in", NodeParam::kString);
|
||||
name_input_->SetConnectable(false);
|
||||
name_input_->set_is_keyframable(false);
|
||||
AddInput(name_input_);
|
||||
|
||||
length_input_ = new NodeInput("length_in", NodeParam::kRational);
|
||||
length_input_->SetConnectable(false);
|
||||
length_input_->set_is_keyframable(false);
|
||||
@@ -160,14 +165,16 @@ bool Block::is_reversed() const
|
||||
return speed() < 0;
|
||||
}
|
||||
|
||||
const QString &Block::block_name() const
|
||||
QString Block::block_name() const
|
||||
{
|
||||
return block_name_;
|
||||
return name_input_->get_standard_value().toString();
|
||||
}
|
||||
|
||||
void Block::set_block_name(const QString &name)
|
||||
{
|
||||
block_name_ = name;
|
||||
name_input_->set_standard_value(name);
|
||||
|
||||
// FIXME: Signal the name has changed to update UI objects
|
||||
}
|
||||
|
||||
rational Block::SequenceToMediaTime(const rational &sequence_time) const
|
||||
@@ -190,11 +197,6 @@ rational Block::MediaToSequenceTime(const rational &media_time) const
|
||||
return (media_time - media_in()) / speed() + in();
|
||||
}
|
||||
|
||||
void Block::CopyParameters(const Block *source, Block *dest)
|
||||
{
|
||||
dest->set_block_name(source->block_name());
|
||||
}
|
||||
|
||||
void Block::LengthInputChanged()
|
||||
{
|
||||
emit LengthChanged(length());
|
||||
|
||||
@@ -73,7 +73,7 @@ public:
|
||||
bool is_still() const;
|
||||
bool is_reversed() const;
|
||||
|
||||
const QString& block_name() const;
|
||||
QString block_name() const;
|
||||
void set_block_name(const QString& name);
|
||||
|
||||
static void Link(Block* a, Block* b);
|
||||
@@ -108,12 +108,11 @@ protected:
|
||||
|
||||
rational MediaToSequenceTime(const rational& media_time) const;
|
||||
|
||||
static void CopyParameters(const Block *source, Block* dest);
|
||||
|
||||
Block* previous_;
|
||||
Block* next_;
|
||||
|
||||
private:
|
||||
NodeInput* name_input_;
|
||||
NodeInput* length_input_;
|
||||
NodeInput* media_in_input_;
|
||||
NodeInput* speed_input_;
|
||||
@@ -121,8 +120,6 @@ private:
|
||||
rational in_point_;
|
||||
rational out_point_;
|
||||
|
||||
QString block_name_;
|
||||
|
||||
QVector<Block*> linked_clips_;
|
||||
|
||||
private slots:
|
||||
|
||||
@@ -29,11 +29,7 @@ ClipBlock::ClipBlock()
|
||||
|
||||
Node *ClipBlock::copy() const
|
||||
{
|
||||
ClipBlock* c = new ClipBlock();
|
||||
|
||||
CopyParameters(this, c);
|
||||
|
||||
return c;
|
||||
return new ClipBlock();
|
||||
}
|
||||
|
||||
Block::Type ClipBlock::type() const
|
||||
|
||||
@@ -26,11 +26,7 @@ GapBlock::GapBlock()
|
||||
|
||||
Node *GapBlock::copy() const
|
||||
{
|
||||
GapBlock* c = new GapBlock();
|
||||
|
||||
CopyParameters(this, c);
|
||||
|
||||
return c;
|
||||
return new GapBlock();
|
||||
}
|
||||
|
||||
Block::Type GapBlock::type() const
|
||||
|
||||
@@ -10,11 +10,7 @@ ExternalTransition::ExternalTransition(const QString &xml_meta_filename) :
|
||||
|
||||
Node *ExternalTransition::copy() const
|
||||
{
|
||||
ExternalTransition* t = new ExternalTransition(meta_.filename());
|
||||
|
||||
CopyParameters(this, t);
|
||||
|
||||
return t;
|
||||
return new ExternalTransition(meta_.filename());
|
||||
}
|
||||
|
||||
QString ExternalTransition::Name() const
|
||||
|
||||
+27
-4
@@ -108,7 +108,7 @@ void NodeInput::Load(QXmlStreamReader *reader, QHash<quintptr, NodeOutput*>& par
|
||||
if (value_text.isEmpty()) {
|
||||
standard_value_.replace(val_index, QVariant());
|
||||
} else {
|
||||
standard_value_.replace(val_index, value_text);
|
||||
standard_value_.replace(val_index, StringToValue(data_type_, value_text));
|
||||
}
|
||||
|
||||
val_index++;
|
||||
@@ -145,7 +145,7 @@ void NodeInput::Load(QXmlStreamReader *reader, QHash<quintptr, NodeOutput*>& par
|
||||
|
||||
reader->readNext();
|
||||
|
||||
key_value = reader->text().toString();
|
||||
key_value = StringToValue(data_type_, reader->text().toString());
|
||||
|
||||
NodeKeyframePtr key = NodeKeyframe::Create(key_time, key_value, key_type, track);
|
||||
key->set_bezier_control_in(key_in_handle);
|
||||
@@ -184,7 +184,7 @@ void NodeInput::Save(QXmlStreamWriter *writer) const
|
||||
writer->writeStartElement("standard");
|
||||
|
||||
foreach (const QVariant& v, standard_value_) {
|
||||
writer->writeTextElement("value", v.toString());
|
||||
writer->writeTextElement("value", ValueToString(data_type_, v));
|
||||
}
|
||||
|
||||
writer->writeEndElement(); // standard
|
||||
@@ -205,7 +205,7 @@ void NodeInput::Save(QXmlStreamWriter *writer) const
|
||||
writer->writeAttribute("outhandlex", QString::number(key->bezier_control_out().x()));
|
||||
writer->writeAttribute("outhandley", QString::number(key->bezier_control_out().y()));
|
||||
|
||||
writer->writeCharacters(key->value().toString());
|
||||
writer->writeCharacters(ValueToString(data_type_, key->value()));
|
||||
|
||||
writer->writeEndElement(); // key
|
||||
}
|
||||
@@ -248,6 +248,29 @@ void NodeInput::SaveInternal(QXmlStreamWriter *writer) const
|
||||
{
|
||||
}
|
||||
|
||||
QString NodeInput::ValueToString(const NodeParam::DataType &type, const QVariant &value)
|
||||
{
|
||||
if (type == kRational) {
|
||||
return value.value<rational>().toString();
|
||||
}
|
||||
|
||||
if (value.canConvert<QString>()) {
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
qWarning() << "Failed to convert type" << type << "to string";
|
||||
return QString();
|
||||
}
|
||||
|
||||
QVariant NodeInput::StringToValue(const NodeParam::DataType &type, const QString &string)
|
||||
{
|
||||
if (type == kRational) {
|
||||
return QVariant::fromValue(rational::fromString(string));
|
||||
}
|
||||
|
||||
return string;
|
||||
}
|
||||
|
||||
NodeOutput *NodeInput::get_connected_output() const
|
||||
{
|
||||
if (!edges_.isEmpty()) {
|
||||
|
||||
@@ -248,6 +248,10 @@ protected:
|
||||
virtual void SaveInternal(QXmlStreamWriter* writer) const;
|
||||
|
||||
private:
|
||||
static QString ValueToString(const DataType& type, const QVariant& value);
|
||||
|
||||
static QVariant StringToValue(const DataType& type, const QString &string);
|
||||
|
||||
void SaveConnections(QXmlStreamWriter* writer) const;
|
||||
|
||||
/**
|
||||
|
||||
@@ -141,7 +141,9 @@ void Sequence::Load(QXmlStreamReader *reader)
|
||||
|
||||
// Ensure this and all children are in the main thread
|
||||
// (FIXME: Weird place for this? This should probably be in ProjectLoadManager somehow)
|
||||
moveToThread(qApp->thread());
|
||||
if (thread() != qApp->thread()) {
|
||||
moveToThread(qApp->thread());
|
||||
}
|
||||
}
|
||||
|
||||
void Sequence::Save(QXmlStreamWriter *writer) const
|
||||
|
||||
@@ -50,7 +50,6 @@ void Project::Load(QXmlStreamReader *reader)
|
||||
set_default_input_colorspace(reader->text().toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "projectloadmanager.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user