diff --git a/app/common/xmlutils.cpp b/app/common/xmlutils.cpp index 97ec92057..1b7820e26 100644 --- a/app/common/xmlutils.cpp +++ b/app/common/xmlutils.cpp @@ -53,16 +53,15 @@ void XMLNodeData::PostConnect(uint version, MultiUndoCommand *command) const if (command) { command->add_child(new NodeEdgeAddCommand(out, con.input)); - - if (version < 210907) { - /// Deprecated: backwards compatibility only - command->add_child(new NodeSetValueHintCommand(con.input, hint)); - } } else { Node::ConnectEdge(out, con.input); + } - if (version < 210907) { - /// Deprecated: backwards compatibility only + if (version < 210907) { + /// Deprecated: backwards compatibility only + if (command) { + command->add_child(new NodeSetValueHintCommand(con.input, hint)); + } else { con.input.node()->SetValueHintForInput(con.input.input(), hint, con.input.element()); } } diff --git a/app/node/nodecopypaste.cpp b/app/node/nodecopypaste.cpp index 2a54212af..7ae4ff17a 100644 --- a/app/node/nodecopypaste.cpp +++ b/app/node/nodecopypaste.cpp @@ -201,7 +201,11 @@ QVector NodeCopyPasteService::PasteNodesFromClipboard(NodeGraph *graph, // Add all nodes to graph foreach (Node* n, pasted_nodes) { - command->add_child(new NodeAddCommand(graph, n)); + if (command) { + command->add_child(new NodeAddCommand(graph, n)); + } else { + n->setParent(graph); + } } // Make connections @@ -215,7 +219,11 @@ QVector NodeCopyPasteService::PasteNodesFromClipboard(NodeGraph *graph, for (auto jt=map.cbegin(); jt!=map.cend(); jt++) { Node *subnode = xml_node_data.node_ptrs.value(jt.key()); if (subnode) { - command->add_child(new NodeSetPositionCommand(subnode, context, jt.value())); + if (command) { + command->add_child(new NodeSetPositionCommand(subnode, context, jt.value())); + } else { + context->SetNodePositionInContext(subnode, jt.value()); + } } } } diff --git a/app/widget/nodeview/nodeview.cpp b/app/widget/nodeview/nodeview.cpp index c87b8ccd5..53621364b 100644 --- a/app/widget/nodeview/nodeview.cpp +++ b/app/widget/nodeview/nodeview.cpp @@ -181,13 +181,10 @@ void NodeView::Select(const QVector &nodes, bool center_view_on_item) context->Select(nodes); } - /* // Center on something - Node *first_item = nodes.isEmpty() ? nullptr : nodes.first(); - if (center_view_on_item && first_item) { - centerOn(first_item); + if (center_view_on_item && !nodes.isEmpty()) { + QMetaObject::invokeMethod(this, "CenterOnNode", Qt::QueuedConnection, OLIVE_NS_ARG(Node*, nodes.first())); } - */ ConnectSelectionChangedSignal(); @@ -849,6 +846,16 @@ void NodeView::CenterOnItemsBoundingRect() centerOn(scene_.itemsBoundingRect().center()); } +void NodeView::CenterOnNode(Node *n) +{ + foreach (NodeViewContext *ctx, scene_.context_map()) { + if (NodeViewItem* item = ctx->GetItemFromMap(n)) { + centerOn(item); + break; + } + } +} + void NodeView::RepositionMiniMap() { if (minimap_->isVisible()) { @@ -980,34 +987,32 @@ bool NodeView::eventFilter(QObject *object, QEvent *event) void NodeView::CopyNodesToClipboardInternal(QXmlStreamWriter *writer, const QVector &nodes, void *userdata) { - qDebug() << "STUB!"; - /*writer->writeStartElement(QStringLiteral("pos")); + writer->writeStartElement(QStringLiteral("pos")); for (Node *n : nodes) { - NodeViewItem *item = scene_.item_map().value(n); - QPointF pos = item->GetNodePosition(); + Node::Position pos = GetAssumedPositionForSelectedNode(n); writer->writeStartElement(QStringLiteral("node")); writer->writeAttribute(QStringLiteral("ptr"), QString::number(reinterpret_cast(n))); - writer->writeTextElement(QStringLiteral("x"), QString::number(pos.x())); - writer->writeTextElement(QStringLiteral("y"), QString::number(pos.y())); + writer->writeTextElement(QStringLiteral("x"), QString::number(pos.position.x())); + writer->writeTextElement(QStringLiteral("y"), QString::number(pos.position.y())); + writer->writeTextElement(QStringLiteral("expanded"), QString::number(pos.expanded)); writer->writeEndElement(); // node } - writer->writeEndElement(); // pos*/ + writer->writeEndElement(); // pos } void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNodeData &xml_node_data, void *userdata) { - qDebug() << "STUB!"; - /*NodeGraph::PositionMap *map = static_cast(userdata); + Node::PositionMap *map = static_cast(userdata); while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("pos")) { while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("node")) { Node *n = nullptr; - QPointF pos; + Node::Position pos; XMLAttributeLoop(reader, attr) { if (attr.name() == QStringLiteral("ptr")) { @@ -1018,9 +1023,11 @@ void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNode while (XMLReadNextStartElement(reader)) { if (reader->name() == QStringLiteral("x")) { - pos.setX(reader->readElementText().toDouble()); + pos.position.setX(reader->readElementText().toDouble()); } else if (reader->name() == QStringLiteral("y")) { - pos.setY(reader->readElementText().toDouble()); + pos.position.setY(reader->readElementText().toDouble()); + } else if (reader->name() == QStringLiteral("expanded")) { + pos.expanded = reader->readElementText().toInt(); } else { reader->skipCurrentElement(); } @@ -1036,7 +1043,7 @@ void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNode } else { reader->skipCurrentElement(); } - }*/ + } } void NodeView::changeEvent(QEvent *e) @@ -1070,6 +1077,21 @@ QPointF NodeView::GetEstimatedPositionForContext(NodeViewItem *item, Node *conte return item->GetNodePosition() - context_offsets_.value(context); } +Node::Position NodeView::GetAssumedPositionForSelectedNode(Node *node) +{ + // Try to find corresponding selected item + foreach (NodeViewContext *ctx, scene_.context_map()) { + NodeViewItem *item = ctx->GetItemFromMap(node); + if (item && item->isSelected()) { + // Good enough + return Node::Position(item->GetNodePosition(), item->IsExpanded()); + } + } + + // Fallback + return Node::Position(); +} + Menu *NodeView::CreateAddMenu(Menu *parent) { Menu* add_menu = NodeFactory::CreateMenu(parent); @@ -1277,7 +1299,7 @@ void NodeView::ShowNodeProperties() Node *first_node = selected_nodes_.first(); if (NodeGroup *group = dynamic_cast(first_node)) { - qDebug() << "STUB!"; + emit NodeGroupOpenRequested(group); } else { LabelSelectedNodes(); } @@ -1290,51 +1312,46 @@ void NodeView::LabelSelectedNodes() void NodeView::PasteNodesInternal(const QVector &duplicate_nodes) { - /* // If no graph, do nothing if (contexts_.isEmpty()) { return; } - paste_command_ = new MultiUndoCommand(); - // If duplicating nodes, duplicate, otherwise paste QVector new_nodes; - NodeGraph::PositionMap map; + Node::PositionMap map; if (duplicate_nodes.isEmpty()) { - new_nodes = PasteNodesFromClipboard(graph_, paste_command_, &map); - - for (auto it=new_nodes.cbegin(); it!=new_nodes.cend(); it++) { - for (Node *context : qAsConst(contexts_)) { - paste_command_->add_child(new NodeSetPositionCommand(*it, context, map.value(*it), false)); - } - } + new_nodes = PasteNodesFromClipboard(nullptr, nullptr, &map); } else { - new_nodes = Node::CopyDependencyGraph(duplicate_nodes, paste_command_); + new_nodes.resize(selected_nodes_.size()); - for (int i=0; iGetNodePosition(); - paste_command_->add_child(new NodeSetPositionCommand(copy, context, p, false)); - } + for (int i=0; icopy(); + Node::CopyInputs(og, copy, false); + map.insert(copy, GetAssumedPositionForSelectedNode(og)); + new_nodes[i] = copy; } + + Node::CopyDependencyGraph(selected_nodes_, new_nodes, nullptr); } // If no nodes were retrieved, do nothing - if (new_nodes.isEmpty()) { - delete paste_command_; - paste_command_ = nullptr; - return; + if (!new_nodes.isEmpty()) { + QVector items(new_nodes.size()); + + for (int i=0; iSetFlowDirection(scene_.GetFlowDirection()); + new_item->SetNodePosition(map.value(node)); + scene_.addItem(new_item); + items[i] = new_item; + } + + // Attach nodes to cursor + AttachItemsToCursor(items); } - - // Attach nodes to cursor - paste_command_->add_child(new NodeViewAttachNodesToCursor(this, new_nodes)); - - paste_command_->redo_now(); - */ } void NodeView::AddContext(Node *n) diff --git a/app/widget/nodeview/nodeview.h b/app/widget/nodeview/nodeview.h index 23e03964a..c3cc73f71 100644 --- a/app/widget/nodeview/nodeview.h +++ b/app/widget/nodeview/nodeview.h @@ -52,6 +52,11 @@ public: void SetContexts(const QVector &nodes); + const QVector &GetContexts() const + { + return contexts_; + } + void CloseContextsBelongingToProject(Project *project); void ClearGraph(); @@ -97,11 +102,15 @@ public slots: void CenterOnItemsBoundingRect(); + void CenterOnNode(olive::Node *n); + signals: void NodesSelected(const QVector& nodes); void NodesDeselected(const QVector& nodes); + void NodeGroupOpenRequested(NodeGroup *group); + protected: virtual void keyPressEvent(QKeyEvent *event) override; @@ -141,6 +150,8 @@ private: QPointF GetEstimatedPositionForContext(NodeViewItem *item, Node *context) const; + Node::Position GetAssumedPositionForSelectedNode(Node *node); + Menu *CreateAddMenu(Menu *parent); void PositionNewEdge(const QPoint &pos); diff --git a/app/widget/nodeview/nodeviewcontext.cpp b/app/widget/nodeview/nodeviewcontext.cpp index 8ded8fdc3..054624a11 100644 --- a/app/widget/nodeview/nodeviewcontext.cpp +++ b/app/widget/nodeview/nodeviewcontext.cpp @@ -189,6 +189,8 @@ void NodeViewContext::DeleteSelected(NodeViewDeleteCommand *command) command->AddNode(node->GetNode(), context_); } } + + UpdateRect(); } void NodeViewContext::Select(const QVector &nodes) diff --git a/app/widget/nodeview/nodeviewitem.cpp b/app/widget/nodeview/nodeviewitem.cpp index 04849fbb2..7389d2cd8 100644 --- a/app/widget/nodeview/nodeviewitem.cpp +++ b/app/widget/nodeview/nodeviewitem.cpp @@ -79,8 +79,7 @@ NodeViewItem::NodeViewItem(Node *node, const QString &input, int element, Node * setFlag(QGraphicsItem::ItemIsSelectable); if (context_) { - SetNodePosition(context_->GetNodePositionInContext(node_)); - SetExpanded(context_->IsNodeExpandedInContext(node_)); + SetNodePosition(context_->GetNodePositionDataInContext(node_)); } } else { output_connector_->setVisible(false); @@ -110,6 +109,12 @@ void NodeViewItem::SetNodePosition(const QPointF &pos) UpdateNodePosition(); } +void NodeViewItem::SetNodePosition(const Node::Position &pos) +{ + SetNodePosition(pos.position); + SetExpanded(pos.expanded); +} + QVector NodeViewItem::GetAllEdgesRecursively() const { QVector list = edges_; diff --git a/app/widget/nodeview/nodeviewitem.h b/app/widget/nodeview/nodeviewitem.h index e236de3ea..6ec3a8ca1 100644 --- a/app/widget/nodeview/nodeviewitem.h +++ b/app/widget/nodeview/nodeviewitem.h @@ -56,6 +56,7 @@ public: QPointF GetNodePosition() const; void SetNodePosition(const QPointF& pos); + void SetNodePosition(const Node::Position& pos); QVector GetAllEdgesRecursively() const;