nodeview/core: moved node copy/paste functions to core so they can be used elsewhere
This commit is contained in:
+101
@@ -21,6 +21,7 @@
|
|||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QClipboard>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
@@ -30,6 +31,7 @@
|
|||||||
#include <QStyleFactory>
|
#include <QStyleFactory>
|
||||||
|
|
||||||
#include "audio/audiomanager.h"
|
#include "audio/audiomanager.h"
|
||||||
|
#include "common/xmlutils.h"
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "dialog/about/about.h"
|
#include "dialog/about/about.h"
|
||||||
#include "dialog/export/export.h"
|
#include "dialog/export/export.h"
|
||||||
@@ -511,6 +513,105 @@ void Core::SetAutorecoveryInterval(int minutes)
|
|||||||
autorecovery_timer_.setInterval(minutes * 60000);
|
autorecovery_timer_.setInterval(minutes * 60000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Core::CopyNodesToClipboard(const QList<Node *> &nodes)
|
||||||
|
{
|
||||||
|
QString copy_str;
|
||||||
|
|
||||||
|
QXmlStreamWriter writer(©_str);
|
||||||
|
writer.setAutoFormatting(true);
|
||||||
|
|
||||||
|
writer.writeStartDocument();
|
||||||
|
writer.writeStartElement(QStringLiteral("olive"));
|
||||||
|
|
||||||
|
foreach (Node* n, nodes) {
|
||||||
|
n->Save(&writer);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.writeEndElement(); // clipboard
|
||||||
|
writer.writeEndDocument();
|
||||||
|
|
||||||
|
QGuiApplication::clipboard()->setText(copy_str);
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<Node*> Core::PasteNodesFromClipboard(Sequence *graph)
|
||||||
|
{
|
||||||
|
QString clipboard = QGuiApplication::clipboard()->text();
|
||||||
|
|
||||||
|
if (clipboard.isEmpty()) {
|
||||||
|
return QList<Node*>();
|
||||||
|
}
|
||||||
|
|
||||||
|
QXmlStreamReader reader(clipboard);
|
||||||
|
|
||||||
|
QList<Node*> pasted_nodes;
|
||||||
|
QHash<quintptr, NodeOutput*> output_ptrs;
|
||||||
|
QList<NodeParam::SerializedConnection> desired_connections;
|
||||||
|
QList<NodeInput::FootageConnection> footage_connections;
|
||||||
|
|
||||||
|
while (XMLReadNextStartElement(&reader)) {
|
||||||
|
if (reader.name() == QStringLiteral("olive")) {
|
||||||
|
while (XMLReadNextStartElement(&reader)) {
|
||||||
|
if (reader.name() == QStringLiteral("node")) {
|
||||||
|
Node* node = XMLLoadNode(&reader);
|
||||||
|
|
||||||
|
if (node) {
|
||||||
|
node->Load(&reader, output_ptrs, desired_connections, footage_connections, nullptr);
|
||||||
|
|
||||||
|
graph->AddNode(node);
|
||||||
|
|
||||||
|
pasted_nodes.append(node);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reader.skipCurrentElement();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make connections
|
||||||
|
if (!desired_connections.isEmpty()) {
|
||||||
|
XMLConnectNodes(output_ptrs, desired_connections);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Connect footage to existing footage if it exists
|
||||||
|
if (!footage_connections.isEmpty()) {
|
||||||
|
// Get list of all footage from project
|
||||||
|
// FIXME: Assumes sequence
|
||||||
|
QList<ItemPtr> footage = graph->project()->get_items_of_type(Item::kFootage);
|
||||||
|
|
||||||
|
if (!footage.isEmpty()) {
|
||||||
|
foreach (const NodeInput::FootageConnection& con, footage_connections) {
|
||||||
|
if (con.footage) {
|
||||||
|
// Assume this is a pointer to a Stream*
|
||||||
|
Stream* loaded_stream = reinterpret_cast<Stream*>(con.footage);
|
||||||
|
|
||||||
|
bool found = false;
|
||||||
|
|
||||||
|
foreach (ItemPtr item, footage) {
|
||||||
|
const QList<StreamPtr>& streams = std::static_pointer_cast<Footage>(item)->streams();
|
||||||
|
|
||||||
|
foreach (StreamPtr s, streams) {
|
||||||
|
if (s.get() == loaded_stream) {
|
||||||
|
con.input->set_standard_value(QVariant::fromValue(s));
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return pasted_nodes;
|
||||||
|
}
|
||||||
|
|
||||||
bool Core::SaveActiveProject()
|
bool Core::SaveActiveProject()
|
||||||
{
|
{
|
||||||
Project* active_project = GetActiveProject();
|
Project* active_project = GetActiveProject();
|
||||||
|
|||||||
@@ -151,6 +151,10 @@ public:
|
|||||||
*/
|
*/
|
||||||
void SetAutorecoveryInterval(int minutes);
|
void SetAutorecoveryInterval(int minutes);
|
||||||
|
|
||||||
|
void CopyNodesToClipboard(const QList<Node*>& nodes);
|
||||||
|
|
||||||
|
QList<Node*> PasteNodesFromClipboard(Sequence *graph);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Return a list of supported frame rates in rational form
|
* @brief Return a list of supported frame rates in rational form
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -20,14 +20,11 @@
|
|||||||
|
|
||||||
#include "nodeview.h"
|
#include "nodeview.h"
|
||||||
|
|
||||||
#include <QClipboard>
|
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QGuiApplication>
|
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
#include "nodeviewundo.h"
|
#include "nodeviewundo.h"
|
||||||
#include "node/factory.h"
|
#include "node/factory.h"
|
||||||
#include "common/xmlutils.h"
|
|
||||||
|
|
||||||
NodeView::NodeView(QWidget *parent) :
|
NodeView::NodeView(QWidget *parent) :
|
||||||
QGraphicsView(parent),
|
QGraphicsView(parent),
|
||||||
@@ -145,26 +142,11 @@ void NodeView::CopySelected(bool cut)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString copy_str;
|
Core::instance()->CopyNodesToClipboard(selected);
|
||||||
|
|
||||||
QXmlStreamWriter writer(©_str);
|
|
||||||
writer.setAutoFormatting(true);
|
|
||||||
|
|
||||||
writer.writeStartDocument();
|
|
||||||
writer.writeStartElement(QStringLiteral("olive"));
|
|
||||||
|
|
||||||
foreach (Node* n, selected) {
|
|
||||||
n->Save(&writer);
|
|
||||||
}
|
|
||||||
|
|
||||||
writer.writeEndElement(); // clipboard
|
|
||||||
writer.writeEndDocument();
|
|
||||||
|
|
||||||
if (cut) {
|
if (cut) {
|
||||||
DeleteSelected();
|
DeleteSelected();
|
||||||
}
|
}
|
||||||
|
|
||||||
QGuiApplication::clipboard()->setText(copy_str);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeView::Paste()
|
void NodeView::Paste()
|
||||||
@@ -173,79 +155,7 @@ void NodeView::Paste()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString clipboard = QGuiApplication::clipboard()->text();
|
QList<Node*> pasted_nodes = Core::instance()->PasteNodesFromClipboard(static_cast<Sequence*>(graph_));
|
||||||
|
|
||||||
if (clipboard.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
QXmlStreamReader reader(clipboard);
|
|
||||||
|
|
||||||
QList<Node*> pasted_nodes;
|
|
||||||
QHash<quintptr, NodeOutput*> output_ptrs;
|
|
||||||
QList<NodeParam::SerializedConnection> desired_connections;
|
|
||||||
QList<NodeInput::FootageConnection> footage_connections;
|
|
||||||
|
|
||||||
while (XMLReadNextStartElement(&reader)) {
|
|
||||||
if (reader.name() == QStringLiteral("olive")) {
|
|
||||||
while (XMLReadNextStartElement(&reader)) {
|
|
||||||
if (reader.name() == QStringLiteral("node")) {
|
|
||||||
Node* node = XMLLoadNode(&reader);
|
|
||||||
|
|
||||||
if (node) {
|
|
||||||
node->Load(&reader, output_ptrs, desired_connections, footage_connections, nullptr);
|
|
||||||
|
|
||||||
graph_->AddNode(node);
|
|
||||||
|
|
||||||
pasted_nodes.append(node);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reader.skipCurrentElement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reader.skipCurrentElement();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make connections
|
|
||||||
if (!desired_connections.isEmpty()) {
|
|
||||||
XMLConnectNodes(output_ptrs, desired_connections);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Connect footage to existing footage if it exists
|
|
||||||
if (!footage_connections.isEmpty()) {
|
|
||||||
// Get list of all footage from project
|
|
||||||
// FIXME: Assumes sequence
|
|
||||||
QList<ItemPtr> footage = static_cast<Sequence*>(graph_)->project()->get_items_of_type(Item::kFootage);
|
|
||||||
|
|
||||||
if (!footage.isEmpty()) {
|
|
||||||
foreach (const NodeInput::FootageConnection& con, footage_connections) {
|
|
||||||
if (con.footage) {
|
|
||||||
// Assume this is a pointer to a Stream*
|
|
||||||
Stream* loaded_stream = reinterpret_cast<Stream*>(con.footage);
|
|
||||||
|
|
||||||
bool found = false;
|
|
||||||
|
|
||||||
foreach (ItemPtr item, footage) {
|
|
||||||
const QList<StreamPtr>& streams = std::static_pointer_cast<Footage>(item)->streams();
|
|
||||||
|
|
||||||
foreach (StreamPtr s, streams) {
|
|
||||||
if (s.get() == loaded_stream) {
|
|
||||||
con.input->set_standard_value(QVariant::fromValue(s));
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (found) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!pasted_nodes.isEmpty()) {
|
if (!pasted_nodes.isEmpty()) {
|
||||||
// FIXME: Attach to cursor so user can drop in place
|
// FIXME: Attach to cursor so user can drop in place
|
||||||
|
|||||||
Reference in New Issue
Block a user