Merge branch 'master' into typos
This commit is contained in:
@@ -20,11 +20,14 @@
|
||||
|
||||
#include "nodeview.h"
|
||||
|
||||
#include <QClipboard>
|
||||
#include <QMouseEvent>
|
||||
#include <QGuiApplication>
|
||||
|
||||
#include "core.h"
|
||||
#include "nodeviewundo.h"
|
||||
#include "node/factory.h"
|
||||
#include "common/xmlutils.h"
|
||||
|
||||
NodeView::NodeView(QWidget *parent) :
|
||||
QGraphicsView(parent),
|
||||
@@ -90,16 +93,7 @@ void NodeView::DeleteSelected()
|
||||
return;
|
||||
}
|
||||
|
||||
QList<QGraphicsItem*> selected = scene_.selectedItems();
|
||||
QList<Node*> selected_nodes;
|
||||
|
||||
foreach (QGraphicsItem* item, selected) {
|
||||
NodeViewItem* node_item = dynamic_cast<NodeViewItem*>(item);
|
||||
|
||||
if (node_item) {
|
||||
selected_nodes.append(node_item->node());
|
||||
}
|
||||
}
|
||||
QList<Node*> selected_nodes = scene_.GetSelectedNodes();
|
||||
|
||||
if (selected_nodes.isEmpty()) {
|
||||
return;
|
||||
@@ -110,20 +104,12 @@ void NodeView::DeleteSelected()
|
||||
|
||||
void NodeView::SelectAll()
|
||||
{
|
||||
QList<QGraphicsItem *> all_items = this->items();
|
||||
|
||||
foreach (QGraphicsItem* i, all_items) {
|
||||
i->setSelected(true);
|
||||
}
|
||||
scene_.SelectAll();
|
||||
}
|
||||
|
||||
void NodeView::DeselectAll()
|
||||
{
|
||||
QList<QGraphicsItem *> selected_items = scene_.selectedItems();
|
||||
|
||||
foreach (QGraphicsItem* i, selected_items) {
|
||||
i->setSelected(false);
|
||||
}
|
||||
scene_.DeselectAll();
|
||||
}
|
||||
|
||||
void NodeView::Select(const QList<Node *> &nodes)
|
||||
@@ -133,9 +119,6 @@ void NodeView::Select(const QList<Node *> &nodes)
|
||||
foreach (Node* n, nodes) {
|
||||
NodeViewItem* item = scene_.NodeToUIObject(n);
|
||||
|
||||
Q_ASSERT(n);
|
||||
Q_ASSERT(item);
|
||||
|
||||
item->setSelected(true);
|
||||
}
|
||||
}
|
||||
@@ -150,6 +133,125 @@ void NodeView::SelectWithDependencies(QList<Node *> nodes)
|
||||
Select(nodes);
|
||||
}
|
||||
|
||||
void NodeView::CopySelected(bool cut)
|
||||
{
|
||||
if (!graph_) {
|
||||
return;
|
||||
}
|
||||
|
||||
QList<Node*> selected = scene_.GetSelectedNodes();
|
||||
|
||||
if (selected.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString copy_str;
|
||||
|
||||
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) {
|
||||
DeleteSelected();
|
||||
}
|
||||
|
||||
QGuiApplication::clipboard()->setText(copy_str);
|
||||
}
|
||||
|
||||
void NodeView::Paste()
|
||||
{
|
||||
if (!graph_) {
|
||||
return;
|
||||
}
|
||||
|
||||
QString clipboard = QGuiApplication::clipboard()->text();
|
||||
|
||||
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()) {
|
||||
// FIXME: Attach to cursor so user can drop in place
|
||||
}
|
||||
}
|
||||
|
||||
void NodeView::ItemsChanged()
|
||||
{
|
||||
QHash<NodeEdge *, NodeViewEdge *>::const_iterator i;
|
||||
@@ -263,21 +365,7 @@ void NodeView::mouseMoveEvent(QMouseEvent *event)
|
||||
|
||||
void NodeView::SceneSelectionChangedSlot()
|
||||
{
|
||||
// Get the scene's selected items and convert it into a list of selected nodes
|
||||
QList<QGraphicsItem*> selected_items = scene_.selectedItems();
|
||||
|
||||
QList<Node*> selected_nodes;
|
||||
|
||||
for (int i=0;i<selected_items.size();i++) {
|
||||
// Try to dynamically cast to a widget holding a Node
|
||||
NodeViewItem* item = dynamic_cast<NodeViewItem*>(selected_items.at(i));
|
||||
|
||||
if (item != nullptr) {
|
||||
selected_nodes.append(item->node());
|
||||
}
|
||||
}
|
||||
|
||||
emit SelectionChanged(selected_nodes);
|
||||
emit SelectionChanged(scene_.GetSelectedNodes());
|
||||
}
|
||||
|
||||
void NodeView::ShowContextMenu(const QPoint &pos)
|
||||
|
||||
@@ -57,6 +57,9 @@ public:
|
||||
void Select(const QList<Node*>& nodes);
|
||||
void SelectWithDependencies(QList<Node *> nodes);
|
||||
|
||||
void CopySelected(bool cut);
|
||||
void Paste();
|
||||
|
||||
signals:
|
||||
/**
|
||||
* @brief Signal emitted when the selected nodes have changed
|
||||
|
||||
@@ -10,6 +10,15 @@ NodeViewScene::NodeViewScene(QObject *parent) :
|
||||
|
||||
void NodeViewScene::clear()
|
||||
{
|
||||
// Deselect everything (prevents signals that a selection has changed after deleting an object)
|
||||
DeselectAll();
|
||||
|
||||
// HACK: QGraphicsScene contains some sort of internal hashing of the selected items which doesn't update unless
|
||||
// we call a function like this. That means even though we deselect all items above, QGraphicsScene will
|
||||
// continue to incorrectly signal selectionChanged() when items that were selected (but are now not) get
|
||||
// deleted. Calling this function appears to update the internal cache and prevent this.
|
||||
selectedItems();
|
||||
|
||||
{
|
||||
QHash<Node*, NodeViewItem*>::const_iterator i;
|
||||
for (i=item_map_.begin();i!=item_map_.end();i++) {
|
||||
@@ -27,6 +36,24 @@ void NodeViewScene::clear()
|
||||
}
|
||||
}
|
||||
|
||||
void NodeViewScene::SelectAll()
|
||||
{
|
||||
QList<QGraphicsItem *> all_items = this->items();
|
||||
|
||||
foreach (QGraphicsItem* i, all_items) {
|
||||
i->setSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeViewScene::DeselectAll()
|
||||
{
|
||||
QList<QGraphicsItem *> selected_items = this->selectedItems();
|
||||
|
||||
foreach (QGraphicsItem* i, selected_items) {
|
||||
i->setSelected(false);
|
||||
}
|
||||
}
|
||||
|
||||
NodeViewItem *NodeViewScene::NodeToUIObject(Node *n)
|
||||
{
|
||||
return item_map_.value(n);
|
||||
@@ -42,6 +69,34 @@ void NodeViewScene::SetGraph(NodeGraph *graph)
|
||||
graph_ = graph;
|
||||
}
|
||||
|
||||
QList<Node *> NodeViewScene::GetSelectedNodes() const
|
||||
{
|
||||
QHash<Node*, NodeViewItem*>::const_iterator iterator;
|
||||
QList<Node *> selected;
|
||||
|
||||
for (iterator=item_map_.begin();iterator!=item_map_.end();iterator++) {
|
||||
if (iterator.value()->isSelected()) {
|
||||
selected.append(iterator.key());
|
||||
}
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
QList<NodeViewItem *> NodeViewScene::GetSelectedItems() const
|
||||
{
|
||||
QHash<Node*, NodeViewItem*>::const_iterator iterator;
|
||||
QList<NodeViewItem *> selected;
|
||||
|
||||
for (iterator=item_map_.begin();iterator!=item_map_.end();iterator++) {
|
||||
if (iterator.value()->isSelected()) {
|
||||
selected.append(iterator.value());
|
||||
}
|
||||
}
|
||||
|
||||
return selected;
|
||||
}
|
||||
|
||||
const QHash<Node *, NodeViewItem *> &NodeViewScene::item_map() const
|
||||
{
|
||||
return item_map_;
|
||||
|
||||
@@ -16,6 +16,9 @@ public:
|
||||
|
||||
void clear();
|
||||
|
||||
void SelectAll();
|
||||
void DeselectAll();
|
||||
|
||||
/**
|
||||
* @brief Retrieve the graphical widget corresponding to a specific Node
|
||||
*
|
||||
@@ -38,6 +41,9 @@ public:
|
||||
|
||||
void SetGraph(NodeGraph* graph);
|
||||
|
||||
QList<Node*> GetSelectedNodes() const;
|
||||
QList<NodeViewItem*> GetSelectedItems() const;
|
||||
|
||||
const QHash<Node*, NodeViewItem*>& item_map() const;
|
||||
const QHash<NodeEdge*, NodeViewEdge*>& edge_map() const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user