nodeview: implemented copying/pasting nodes

Re-uses XML-based project saving/loading functions to store nodes, their
parameters, and their connections in a text-based format in the clipboard.
This commit is contained in:
itsmattkc
2020-03-15 20:01:58 +11:00
parent 50061e4e55
commit 34f60e639a
24 changed files with 306 additions and 71 deletions
+1 -1
View File
@@ -20,7 +20,7 @@
#include "folder.h"
#include "common/xmlreadloop.h"
#include "common/xmlutils.h"
#include "project/item/footage/footage.h"
#include "project/item/sequence/sequence.h"
#include "ui/icons/icons.h"
+1 -1
View File
@@ -24,7 +24,7 @@
#include "codec/decoder.h"
#include "common/timecodefunctions.h"
#include "common/xmlreadloop.h"
#include "common/xmlutils.h"
#include "config/config.h"
#include "ui/icons/icons.h"
+1 -1
View File
@@ -20,7 +20,7 @@
#include "imagestream.h"
#include "common/xmlreadloop.h"
#include "common/xmlutils.h"
#include "footage.h"
#include "project/project.h"
#include "render/colormanager.h"
+28 -3
View File
@@ -76,11 +76,19 @@ const QList<ItemPtr> &Item::children() const
return children_;
}
ItemPtr Item::shared_ptr_from_raw(Item *item)
ItemPtr Item::shared_ptr_from_raw(Item *item, bool traverse)
{
for (int i=0;i<children_.size();i++) {
if (children_.at(i).get() == item) {
return children_.at(i);
ItemPtr c = children_.at(i);
if (c.get() == item) {
return c;
} else if (traverse && c->CanHaveChildren()) {
ItemPtr grandchild = shared_ptr_from_raw(item);
if (grandchild) {
return grandchild;
}
}
}
@@ -147,6 +155,23 @@ void Item::set_project(Project *project)
project_ = project;
}
QList<ItemPtr> Item::get_children_of_type(Type type, bool recursive) const
{
QList<ItemPtr> list;
foreach (ItemPtr item, children_) {
if (item->type() == type) {
list.append(item);
}
if (recursive && item->CanHaveChildren()) {
list.append(item->get_children_of_type(type, recursive));
}
}
return list;
}
bool Item::CanHaveChildren() const
{
return false;
+3 -1
View File
@@ -77,7 +77,7 @@ public:
Item* child(int i) const;
const QList<ItemPtr>& children() const;
ItemPtr shared_ptr_from_raw(Item* item);
ItemPtr shared_ptr_from_raw(Item* item, bool traverse = false);
const QString& name() const;
void set_name(const QString& n);
@@ -97,6 +97,8 @@ public:
Project* project() const;
void set_project(Project* project);
QList<ItemPtr> get_children_of_type(Type type, bool recursive) const;
virtual bool CanHaveChildren() const;
bool ChildExistsWithName(const QString& name);
+3 -27
View File
@@ -25,7 +25,7 @@
#include "config/config.h"
#include "common/channellayout.h"
#include "common/timecodefunctions.h"
#include "common/xmlreadloop.h"
#include "common/xmlutils.h"
#include "node/factory.h"
#include "panel/panelmanager.h"
#include "panel/node/node.h"
@@ -110,28 +110,7 @@ void Sequence::Load(QXmlStreamReader *reader, QHash<quintptr, StreamPtr> &, QLis
Node* node;
if (reader->name() == "node") {
QString node_id;
XMLAttributeLoop(reader, attr) {
if (attr.name() == "id") {
node_id = attr.value().toString();
// Currently the only thing we need
break;
}
}
if (node_id.isEmpty()) {
qDebug() << "Found node with no ID";
continue;
}
node = NodeFactory::CreateFromID(node_id);
if (!node) {
qDebug() << "Failed to load" << node_id << "- no node with that ID is installed";
continue;
}
node = XMLLoadNode(reader);
} else {
node = viewer_output_;
}
@@ -146,10 +125,7 @@ void Sequence::Load(QXmlStreamReader *reader, QHash<quintptr, StreamPtr> &, QLis
}
// Make connections
foreach (const NodeParam::SerializedConnection& con, desired_connections) {
NodeParam::ConnectEdge(output_ptrs.value(con.output),
con.input);
}
XMLConnectNodes(output_ptrs, desired_connections);
// Ensure this and all children are in the main thread
// (FIXME: Weird place for this? This should probably be in ProjectLoadManager somehow)
+6 -1
View File
@@ -23,7 +23,7 @@
#include <QDir>
#include <QFileInfo>
#include "common/xmlreadloop.h"
#include "common/xmlutils.h"
#include "core.h"
#include "dialog/progress/progress.h"
#include "window/mainwindow/mainwindow.h"
@@ -137,3 +137,8 @@ ColorManager *Project::color_manager()
{
return &color_manager_;
}
QList<ItemPtr> Project::get_items_of_type(Item::Type type) const
{
return root_.get_children_of_type(type, true);
}
+2
View File
@@ -63,6 +63,8 @@ public:
ColorManager* color_manager();
QList<ItemPtr> get_items_of_type(Item::Type type) const;
signals:
void NameChanged();