moved block links to node links

Seems like it might be useful to have this as part of the node architecture as a whole
This commit is contained in:
itsmattkc
2021-01-25 09:17:25 +11:00
parent 2c7e974f78
commit 7795d42347
11 changed files with 222 additions and 227 deletions
+13 -81
View File
@@ -170,24 +170,6 @@ rational Block::MediaToSequenceTime(const rational &media_time) const
return sequence_time;
}
void Block::LoadInternal(QXmlStreamReader *reader, XMLNodeData &xml_node_data)
{
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("link")) {
xml_node_data.block_links.append({this, reader->readElementText().toULongLong()});
} else {
reader->skipCurrentElement();
}
}
}
void Block::SaveInternal(QXmlStreamWriter *writer) const
{
foreach (Block* link, linked_clips_) {
writer->writeTextElement(QStringLiteral("link"), QString::number(reinterpret_cast<quintptr>(link)));
}
}
QVector<NodeInput *> Block::GetInputsToHash() const
{
QVector<NodeInput*> inputs = Node::GetInputsToHash();
@@ -200,74 +182,24 @@ QVector<NodeInput *> Block::GetInputsToHash() const
return inputs;
}
void Block::LinkChangeEvent()
{
block_links_.clear();
foreach (Node* n, links()) {
Block* b = dynamic_cast<Block*>(n);
if (b) {
block_links_.append(b);
}
}
}
void Block::set_length_internal(const rational &length)
{
length_input_->SetStandardValue(QVariant::fromValue(length));
}
bool Block::Link(Block *a, Block *b)
{
if (a == b || !a || !b) {
return false;
}
// Prevent duplicate link entries (assume that we only need to check one clip since this should be the only function
// that adds to the linked array)
if (Block::AreLinked(a, b)) {
return false;
}
a->linked_clips_.append(b);
b->linked_clips_.append(a);
emit a->LinksChanged();
emit b->LinksChanged();
return true;
}
void Block::Link(const QList<Block*>& blocks)
{
foreach (Block* a, blocks) {
foreach (Block* b, blocks) {
Link(a, b);
}
}
}
bool Block::Unlink(Block *a, Block *b)
{
if (a == b || !a || !b) {
return false;
}
if (!Block::AreLinked(a, b)) {
return false;
}
a->linked_clips_.removeOne(b);
b->linked_clips_.removeOne(a);
emit a->LinksChanged();
emit b->LinksChanged();
return true;
}
void Block::Unlink(const QList<Block *> &blocks)
{
foreach (Block* a, blocks) {
foreach (Block* b, blocks) {
Unlink(a, b);
}
}
}
bool Block::AreLinked(Block *a, Block *b)
{
return a->linked_clips_.contains(b);
}
void Block::Retranslate()
{
Node::Retranslate();
+8 -23
View File
@@ -112,22 +112,6 @@ public:
bool is_enabled() const;
void set_enabled(bool e);
static bool Link(Block* a, Block* b);
static void Link(const QList<Block*>& blocks);
static bool Unlink(Block* a, Block* b);
static void Unlink(const QList<Block*>& blocks);
static bool AreLinked(Block* a, Block* b);
const QVector<Block*>& linked_clips() const
{
return linked_clips_;
}
bool HasLinks() const
{
return !linked_clips_.isEmpty();
}
virtual void Retranslate() override;
NodeInput* length_input() const
@@ -175,13 +159,16 @@ public:
index_ = i;
}
const QVector<Block*>& block_links() const
{
return block_links_;
}
virtual void Hash(QCryptographicHash &hash, const rational &time) const override;
public slots:
signals:
void LinksChanged();
void EnabledChanged();
void LengthChanged();
@@ -191,12 +178,10 @@ protected:
rational MediaToSequenceTime(const rational& media_time) const;
virtual void LoadInternal(QXmlStreamReader* reader, XMLNodeData& xml_node_data) override;
virtual void SaveInternal(QXmlStreamWriter* writer) const override;
virtual QVector<NodeInput*> GetInputsToHash() const override;
virtual void LinkChangeEvent() override;
Block* previous_;
Block* next_;
@@ -216,7 +201,7 @@ private:
TransitionBlock* in_transition_;
TransitionBlock* out_transition_;
QVector<Block*> linked_clips_;
QVector<Block*> block_links_;
};
+59
View File
@@ -108,6 +108,14 @@ void Node::Load(QXmlStreamReader *reader, XMLNodeData& xml_node_data, const QAto
SetLabel(reader->readElementText());
} else if (reader->name() == QStringLiteral("color")) {
override_color_ = reader->readElementText().toInt();
} else if (reader->name() == QStringLiteral("links")) {
while (XMLReadNextStartElement(reader)) {
if (reader->name() == QStringLiteral("link")) {
xml_node_data.block_links.append({this, reader->readElementText().toULongLong()});
} else {
reader->skipCurrentElement();
}
}
} else if (reader->name() == QStringLiteral("custom")) {
LoadInternal(reader, xml_node_data);
} else {
@@ -136,6 +144,12 @@ void Node::Save(QXmlStreamWriter *writer) const
writer->writeEndElement(); // input
}
writer->writeStartElement(QStringLiteral("links"));
foreach (Node* link, links_) {
writer->writeTextElement(QStringLiteral("link"), QString::number(reinterpret_cast<quintptr>(link)));
}
writer->writeEndElement(); // links
writer->writeStartElement(QStringLiteral("custom"));
SaveInternal(writer);
writer->writeEndElement(); // custom
@@ -299,6 +313,51 @@ void Node::InvalidateAll(NodeInput* input, int element)
InvalidateCache(TimeRange(RATIONAL_MIN, RATIONAL_MAX), {input, element});
}
bool Node::Link(Node *a, Node *b)
{
if (a == b || !a || !b) {
return false;
}
if (AreLinked(a, b)) {
return false;
}
a->links_.append(b);
b->links_.append(a);
a->LinkChangeEvent();
b->LinkChangeEvent();
emit a->LinksChanged();
emit b->LinksChanged();
return true;
}
bool Node::Unlink(Node *a, Node *b)
{
if (!AreLinked(a, b)) {
return false;
}
a->links_.removeOne(b);
b->links_.removeOne(a);
a->LinkChangeEvent();
b->LinkChangeEvent();
emit a->LinksChanged();
emit b->LinksChanged();
return true;
}
bool Node::AreLinked(Node *a, Node *b)
{
return a->links_.contains(b);
}
void Node::IgnoreInvalidationsFrom(NodeInput *input)
{
ignore_connections_.append(input);
+23
View File
@@ -425,6 +425,20 @@ public:
void InvalidateAll(NodeInput *input, int element);
bool HasLinks() const
{
return !links_.isEmpty();
}
const QVector<Node*>& links() const
{
return links_;
}
static bool Link(Node* a, Node* b);
static bool Unlink(Node* a, Node* b);
static bool AreLinked(Node* a, Node* b);
protected:
void SendInvalidateCache(const TimeRange &range);
@@ -463,6 +477,8 @@ protected:
virtual void childEvent(QChildEvent* event) override;
virtual void LinkChangeEvent(){}
signals:
/**
* @brief Signal emitted whenever the position is set through SetPosition()
@@ -486,6 +502,8 @@ signals:
void OutputDisconnected(NodeInput* destination, int element);
void LinksChanged();
private:
template<class T>
static void FindInputNodeInternal(const Node* n, QVector<T *>& list);
@@ -521,6 +539,11 @@ private:
*/
int override_color_;
/**
* @brief Nodes that are linked with this one
*/
QVector<Node*> links_;
private slots:
void ParameterValueChanged(const olive::TimeRange &range, int element);