work towards finishing nodeview copy/paste refactor
This commit is contained in:
@@ -53,16 +53,15 @@ void XMLNodeData::PostConnect(uint version, MultiUndoCommand *command) const
|
|||||||
|
|
||||||
if (command) {
|
if (command) {
|
||||||
command->add_child(new NodeEdgeAddCommand(out, con.input));
|
command->add_child(new NodeEdgeAddCommand(out, con.input));
|
||||||
|
|
||||||
if (version < 210907) {
|
|
||||||
/// Deprecated: backwards compatibility only
|
|
||||||
command->add_child(new NodeSetValueHintCommand(con.input, hint));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Node::ConnectEdge(out, con.input);
|
Node::ConnectEdge(out, con.input);
|
||||||
|
}
|
||||||
|
|
||||||
if (version < 210907) {
|
if (version < 210907) {
|
||||||
/// Deprecated: backwards compatibility only
|
/// 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());
|
con.input.node()->SetValueHintForInput(con.input.input(), hint, con.input.element());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -201,7 +201,11 @@ QVector<Node *> NodeCopyPasteService::PasteNodesFromClipboard(NodeGraph *graph,
|
|||||||
|
|
||||||
// Add all nodes to graph
|
// Add all nodes to graph
|
||||||
foreach (Node* n, pasted_nodes) {
|
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
|
// Make connections
|
||||||
@@ -215,7 +219,11 @@ QVector<Node *> NodeCopyPasteService::PasteNodesFromClipboard(NodeGraph *graph,
|
|||||||
for (auto jt=map.cbegin(); jt!=map.cend(); jt++) {
|
for (auto jt=map.cbegin(); jt!=map.cend(); jt++) {
|
||||||
Node *subnode = xml_node_data.node_ptrs.value(jt.key());
|
Node *subnode = xml_node_data.node_ptrs.value(jt.key());
|
||||||
if (subnode) {
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -181,13 +181,10 @@ void NodeView::Select(const QVector<Node *> &nodes, bool center_view_on_item)
|
|||||||
context->Select(nodes);
|
context->Select(nodes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
// Center on something
|
// Center on something
|
||||||
Node *first_item = nodes.isEmpty() ? nullptr : nodes.first();
|
if (center_view_on_item && !nodes.isEmpty()) {
|
||||||
if (center_view_on_item && first_item) {
|
QMetaObject::invokeMethod(this, "CenterOnNode", Qt::QueuedConnection, OLIVE_NS_ARG(Node*, nodes.first()));
|
||||||
centerOn(first_item);
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
ConnectSelectionChangedSignal();
|
ConnectSelectionChangedSignal();
|
||||||
|
|
||||||
@@ -849,6 +846,16 @@ void NodeView::CenterOnItemsBoundingRect()
|
|||||||
centerOn(scene_.itemsBoundingRect().center());
|
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()
|
void NodeView::RepositionMiniMap()
|
||||||
{
|
{
|
||||||
if (minimap_->isVisible()) {
|
if (minimap_->isVisible()) {
|
||||||
@@ -980,34 +987,32 @@ bool NodeView::eventFilter(QObject *object, QEvent *event)
|
|||||||
|
|
||||||
void NodeView::CopyNodesToClipboardInternal(QXmlStreamWriter *writer, const QVector<Node *> &nodes, void *userdata)
|
void NodeView::CopyNodesToClipboardInternal(QXmlStreamWriter *writer, const QVector<Node *> &nodes, void *userdata)
|
||||||
{
|
{
|
||||||
qDebug() << "STUB!";
|
writer->writeStartElement(QStringLiteral("pos"));
|
||||||
/*writer->writeStartElement(QStringLiteral("pos"));
|
|
||||||
|
|
||||||
for (Node *n : nodes) {
|
for (Node *n : nodes) {
|
||||||
NodeViewItem *item = scene_.item_map().value(n);
|
Node::Position pos = GetAssumedPositionForSelectedNode(n);
|
||||||
QPointF pos = item->GetNodePosition();
|
|
||||||
|
|
||||||
writer->writeStartElement(QStringLiteral("node"));
|
writer->writeStartElement(QStringLiteral("node"));
|
||||||
writer->writeAttribute(QStringLiteral("ptr"), QString::number(reinterpret_cast<quintptr>(n)));
|
writer->writeAttribute(QStringLiteral("ptr"), QString::number(reinterpret_cast<quintptr>(n)));
|
||||||
writer->writeTextElement(QStringLiteral("x"), QString::number(pos.x()));
|
writer->writeTextElement(QStringLiteral("x"), QString::number(pos.position.x()));
|
||||||
writer->writeTextElement(QStringLiteral("y"), QString::number(pos.y()));
|
writer->writeTextElement(QStringLiteral("y"), QString::number(pos.position.y()));
|
||||||
|
writer->writeTextElement(QStringLiteral("expanded"), QString::number(pos.expanded));
|
||||||
writer->writeEndElement(); // node
|
writer->writeEndElement(); // node
|
||||||
}
|
}
|
||||||
|
|
||||||
writer->writeEndElement(); // pos*/
|
writer->writeEndElement(); // pos
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNodeData &xml_node_data, void *userdata)
|
void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNodeData &xml_node_data, void *userdata)
|
||||||
{
|
{
|
||||||
qDebug() << "STUB!";
|
Node::PositionMap *map = static_cast<Node::PositionMap *>(userdata);
|
||||||
/*NodeGraph::PositionMap *map = static_cast<NodeGraph::PositionMap *>(userdata);
|
|
||||||
|
|
||||||
while (XMLReadNextStartElement(reader)) {
|
while (XMLReadNextStartElement(reader)) {
|
||||||
if (reader->name() == QStringLiteral("pos")) {
|
if (reader->name() == QStringLiteral("pos")) {
|
||||||
while (XMLReadNextStartElement(reader)) {
|
while (XMLReadNextStartElement(reader)) {
|
||||||
if (reader->name() == QStringLiteral("node")) {
|
if (reader->name() == QStringLiteral("node")) {
|
||||||
Node *n = nullptr;
|
Node *n = nullptr;
|
||||||
QPointF pos;
|
Node::Position pos;
|
||||||
|
|
||||||
XMLAttributeLoop(reader, attr) {
|
XMLAttributeLoop(reader, attr) {
|
||||||
if (attr.name() == QStringLiteral("ptr")) {
|
if (attr.name() == QStringLiteral("ptr")) {
|
||||||
@@ -1018,9 +1023,11 @@ void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNode
|
|||||||
|
|
||||||
while (XMLReadNextStartElement(reader)) {
|
while (XMLReadNextStartElement(reader)) {
|
||||||
if (reader->name() == QStringLiteral("x")) {
|
if (reader->name() == QStringLiteral("x")) {
|
||||||
pos.setX(reader->readElementText().toDouble());
|
pos.position.setX(reader->readElementText().toDouble());
|
||||||
} else if (reader->name() == QStringLiteral("y")) {
|
} 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 {
|
} else {
|
||||||
reader->skipCurrentElement();
|
reader->skipCurrentElement();
|
||||||
}
|
}
|
||||||
@@ -1036,7 +1043,7 @@ void NodeView::PasteNodesFromClipboardInternal(QXmlStreamReader *reader, XMLNode
|
|||||||
} else {
|
} else {
|
||||||
reader->skipCurrentElement();
|
reader->skipCurrentElement();
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeView::changeEvent(QEvent *e)
|
void NodeView::changeEvent(QEvent *e)
|
||||||
@@ -1070,6 +1077,21 @@ QPointF NodeView::GetEstimatedPositionForContext(NodeViewItem *item, Node *conte
|
|||||||
return item->GetNodePosition() - context_offsets_.value(context);
|
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 *NodeView::CreateAddMenu(Menu *parent)
|
||||||
{
|
{
|
||||||
Menu* add_menu = NodeFactory::CreateMenu(parent);
|
Menu* add_menu = NodeFactory::CreateMenu(parent);
|
||||||
@@ -1277,7 +1299,7 @@ void NodeView::ShowNodeProperties()
|
|||||||
Node *first_node = selected_nodes_.first();
|
Node *first_node = selected_nodes_.first();
|
||||||
|
|
||||||
if (NodeGroup *group = dynamic_cast<NodeGroup*>(first_node)) {
|
if (NodeGroup *group = dynamic_cast<NodeGroup*>(first_node)) {
|
||||||
qDebug() << "STUB!";
|
emit NodeGroupOpenRequested(group);
|
||||||
} else {
|
} else {
|
||||||
LabelSelectedNodes();
|
LabelSelectedNodes();
|
||||||
}
|
}
|
||||||
@@ -1290,51 +1312,46 @@ void NodeView::LabelSelectedNodes()
|
|||||||
|
|
||||||
void NodeView::PasteNodesInternal(const QVector<Node *> &duplicate_nodes)
|
void NodeView::PasteNodesInternal(const QVector<Node *> &duplicate_nodes)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
// If no graph, do nothing
|
// If no graph, do nothing
|
||||||
if (contexts_.isEmpty()) {
|
if (contexts_.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
paste_command_ = new MultiUndoCommand();
|
|
||||||
|
|
||||||
// If duplicating nodes, duplicate, otherwise paste
|
// If duplicating nodes, duplicate, otherwise paste
|
||||||
QVector<Node*> new_nodes;
|
QVector<Node*> new_nodes;
|
||||||
NodeGraph::PositionMap map;
|
Node::PositionMap map;
|
||||||
if (duplicate_nodes.isEmpty()) {
|
if (duplicate_nodes.isEmpty()) {
|
||||||
new_nodes = PasteNodesFromClipboard(graph_, paste_command_, &map);
|
new_nodes = PasteNodesFromClipboard(nullptr, nullptr, &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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
new_nodes = Node::CopyDependencyGraph(duplicate_nodes, paste_command_);
|
new_nodes.resize(selected_nodes_.size());
|
||||||
|
|
||||||
for (int i=0; i<duplicate_nodes.size(); i++) {
|
for (int i=0; i<new_nodes.size(); i++) {
|
||||||
Node *src = duplicate_nodes.at(i);
|
Node *og = selected_nodes_.at(i);
|
||||||
Node *copy = new_nodes.at(i);
|
Node *copy = og->copy();
|
||||||
|
Node::CopyInputs(og, copy, false);
|
||||||
for (Node *context : qAsConst(contexts_)) {
|
map.insert(copy, GetAssumedPositionForSelectedNode(og));
|
||||||
QPointF p = scene_.item_map().value(src)->GetNodePosition();
|
new_nodes[i] = copy;
|
||||||
paste_command_->add_child(new NodeSetPositionCommand(copy, context, p, false));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Node::CopyDependencyGraph(selected_nodes_, new_nodes, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no nodes were retrieved, do nothing
|
// If no nodes were retrieved, do nothing
|
||||||
if (new_nodes.isEmpty()) {
|
if (!new_nodes.isEmpty()) {
|
||||||
delete paste_command_;
|
QVector<NodeViewItem*> items(new_nodes.size());
|
||||||
paste_command_ = nullptr;
|
|
||||||
return;
|
for (int i=0; i<new_nodes.size(); i++) {
|
||||||
|
Node *node = new_nodes.at(i);
|
||||||
|
NodeViewItem *new_item = new NodeViewItem(node, nullptr);
|
||||||
|
new_item->SetFlowDirection(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)
|
void NodeView::AddContext(Node *n)
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ public:
|
|||||||
|
|
||||||
void SetContexts(const QVector<Node *> &nodes);
|
void SetContexts(const QVector<Node *> &nodes);
|
||||||
|
|
||||||
|
const QVector<Node*> &GetContexts() const
|
||||||
|
{
|
||||||
|
return contexts_;
|
||||||
|
}
|
||||||
|
|
||||||
void CloseContextsBelongingToProject(Project *project);
|
void CloseContextsBelongingToProject(Project *project);
|
||||||
|
|
||||||
void ClearGraph();
|
void ClearGraph();
|
||||||
@@ -97,11 +102,15 @@ public slots:
|
|||||||
|
|
||||||
void CenterOnItemsBoundingRect();
|
void CenterOnItemsBoundingRect();
|
||||||
|
|
||||||
|
void CenterOnNode(olive::Node *n);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void NodesSelected(const QVector<Node*>& nodes);
|
void NodesSelected(const QVector<Node*>& nodes);
|
||||||
|
|
||||||
void NodesDeselected(const QVector<Node*>& nodes);
|
void NodesDeselected(const QVector<Node*>& nodes);
|
||||||
|
|
||||||
|
void NodeGroupOpenRequested(NodeGroup *group);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void keyPressEvent(QKeyEvent *event) override;
|
virtual void keyPressEvent(QKeyEvent *event) override;
|
||||||
|
|
||||||
@@ -141,6 +150,8 @@ private:
|
|||||||
|
|
||||||
QPointF GetEstimatedPositionForContext(NodeViewItem *item, Node *context) const;
|
QPointF GetEstimatedPositionForContext(NodeViewItem *item, Node *context) const;
|
||||||
|
|
||||||
|
Node::Position GetAssumedPositionForSelectedNode(Node *node);
|
||||||
|
|
||||||
Menu *CreateAddMenu(Menu *parent);
|
Menu *CreateAddMenu(Menu *parent);
|
||||||
|
|
||||||
void PositionNewEdge(const QPoint &pos);
|
void PositionNewEdge(const QPoint &pos);
|
||||||
|
|||||||
@@ -189,6 +189,8 @@ void NodeViewContext::DeleteSelected(NodeViewDeleteCommand *command)
|
|||||||
command->AddNode(node->GetNode(), context_);
|
command->AddNode(node->GetNode(), context_);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NodeViewContext::Select(const QVector<Node *> &nodes)
|
void NodeViewContext::Select(const QVector<Node *> &nodes)
|
||||||
|
|||||||
@@ -79,8 +79,7 @@ NodeViewItem::NodeViewItem(Node *node, const QString &input, int element, Node *
|
|||||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||||
|
|
||||||
if (context_) {
|
if (context_) {
|
||||||
SetNodePosition(context_->GetNodePositionInContext(node_));
|
SetNodePosition(context_->GetNodePositionDataInContext(node_));
|
||||||
SetExpanded(context_->IsNodeExpandedInContext(node_));
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
output_connector_->setVisible(false);
|
output_connector_->setVisible(false);
|
||||||
@@ -110,6 +109,12 @@ void NodeViewItem::SetNodePosition(const QPointF &pos)
|
|||||||
UpdateNodePosition();
|
UpdateNodePosition();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NodeViewItem::SetNodePosition(const Node::Position &pos)
|
||||||
|
{
|
||||||
|
SetNodePosition(pos.position);
|
||||||
|
SetExpanded(pos.expanded);
|
||||||
|
}
|
||||||
|
|
||||||
QVector<NodeViewEdge *> NodeViewItem::GetAllEdgesRecursively() const
|
QVector<NodeViewEdge *> NodeViewItem::GetAllEdgesRecursively() const
|
||||||
{
|
{
|
||||||
QVector<NodeViewEdge *> list = edges_;
|
QVector<NodeViewEdge *> list = edges_;
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ public:
|
|||||||
|
|
||||||
QPointF GetNodePosition() const;
|
QPointF GetNodePosition() const;
|
||||||
void SetNodePosition(const QPointF& pos);
|
void SetNodePosition(const QPointF& pos);
|
||||||
|
void SetNodePosition(const Node::Position& pos);
|
||||||
|
|
||||||
QVector<NodeViewEdge*> GetAllEdgesRecursively() const;
|
QVector<NodeViewEdge*> GetAllEdgesRecursively() const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user