|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
#include "include/commands.h"
|
|
|
|
|
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
|
@ -17,16 +18,22 @@ const char* CannotPlaceNewNodeException::what() const throw()
|
|
|
|
|
toStdString().c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* CannotDeleteBaseNodeException::what() const throw()
|
|
|
|
|
{
|
|
|
|
|
return QObject::tr("Base node cannot be deleted.").toStdString().c_str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InsertNodeCommand::InsertNodeCommand(GraphLogic *graphLogic)
|
|
|
|
|
: m_graphLogic(graphLogic)
|
|
|
|
|
, m_node(0)
|
|
|
|
|
, m_activeNode(m_graphLogic->m_activeNode)
|
|
|
|
|
, m_edge(0)
|
|
|
|
|
{
|
|
|
|
|
if (!m_activeNode)
|
|
|
|
|
throw NoActiveNodeException();
|
|
|
|
|
|
|
|
|
|
setText(QObject::tr("New node added to ").append(
|
|
|
|
|
setText(QObject::tr("Node added to ").append(
|
|
|
|
|
m_activeNode == m_graphLogic->m_nodeList.first() ?
|
|
|
|
|
QObject::tr("Base node") :
|
|
|
|
|
QString("\"").append(m_activeNode->toPlainText().append("\""))));
|
|
|
|
@ -55,6 +62,11 @@ InsertNodeCommand::InsertNodeCommand(GraphLogic *graphLogic)
|
|
|
|
|
m_node->setColor(m_activeNode->color());
|
|
|
|
|
m_node->setTextColor(m_activeNode->textColor());
|
|
|
|
|
m_node->setHtml(QString(""));
|
|
|
|
|
|
|
|
|
|
m_edge = new Edge(m_activeNode, m_node);
|
|
|
|
|
m_edge->setColor(m_node->color());
|
|
|
|
|
m_edge->setWidth(m_node->scale()*2 + 1);
|
|
|
|
|
m_edge->setSecondary(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InsertNodeCommand::undo()
|
|
|
|
@ -62,7 +74,10 @@ void InsertNodeCommand::undo()
|
|
|
|
|
m_graphLogic->m_nodeList.removeAll(m_node);
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->removeItem(m_node);
|
|
|
|
|
|
|
|
|
|
m_node->removeEdges();
|
|
|
|
|
// m_node->deleteEdges();
|
|
|
|
|
m_edge->sourceNode()->removeEdge(m_edge);
|
|
|
|
|
m_edge->destNode()->removeEdge(m_edge);
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->removeItem(m_edge);
|
|
|
|
|
|
|
|
|
|
m_graphLogic->setActiveNode(m_activeNode);
|
|
|
|
|
|
|
|
|
@ -76,7 +91,10 @@ void InsertNodeCommand::redo()
|
|
|
|
|
|
|
|
|
|
m_node->setPos(m_pos);
|
|
|
|
|
|
|
|
|
|
m_graphLogic->addEdge(m_activeNode, m_node);
|
|
|
|
|
// m_graphLogic->addEdge(m_activeNode, m_node);
|
|
|
|
|
m_edge->sourceNode()->addEdge(m_edge,true);
|
|
|
|
|
m_edge->destNode()->addEdge(m_edge,false);
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->addItem(m_edge);
|
|
|
|
|
|
|
|
|
|
m_graphLogic->setActiveNode(m_node);
|
|
|
|
|
|
|
|
|
@ -89,3 +107,87 @@ void InsertNodeCommand::redo()
|
|
|
|
|
if (m_graphLogic->m_showingNodeNumbers)
|
|
|
|
|
m_graphLogic->showNodeNumbers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RemoveNodeCommand::RemoveNodeCommand(GraphLogic *graphLogic)
|
|
|
|
|
: m_graphLogic(graphLogic)
|
|
|
|
|
, m_activeNode(m_graphLogic->m_activeNode)
|
|
|
|
|
, m_hintNode(m_graphLogic->m_hintNode)
|
|
|
|
|
{
|
|
|
|
|
if (!m_activeNode)
|
|
|
|
|
throw NoActiveNodeException();
|
|
|
|
|
|
|
|
|
|
if (m_activeNode == m_graphLogic->m_nodeList.first())
|
|
|
|
|
throw CannotDeleteBaseNodeException();
|
|
|
|
|
|
|
|
|
|
setText(QObject::tr("Node removed \"").append(
|
|
|
|
|
m_activeNode->toPlainText().append("\"")));
|
|
|
|
|
|
|
|
|
|
// remove just the active Node or it's subtree too?
|
|
|
|
|
if (QApplication::keyboardModifiers() & Qt::ControlModifier &&
|
|
|
|
|
QApplication::keyboardModifiers() & Qt::ShiftModifier)
|
|
|
|
|
{
|
|
|
|
|
m_nodeList = m_activeNode->subtree();
|
|
|
|
|
setText(text().append(QObject::tr(" with subtree")));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_nodeList.push_back(m_activeNode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(Node *node, m_nodeList)
|
|
|
|
|
foreach(Edge *edge, node->edges())
|
|
|
|
|
if (m_edgeList.indexOf(edge) == -1)
|
|
|
|
|
m_edgeList.push_back(edge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoveNodeCommand::undo()
|
|
|
|
|
{
|
|
|
|
|
foreach (Node *node, m_nodeList)
|
|
|
|
|
{
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->addItem(node);
|
|
|
|
|
m_graphLogic->m_nodeList.append(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (Edge *edge, m_edgeList)
|
|
|
|
|
{
|
|
|
|
|
edge->sourceNode()->addEdge(edge,true);
|
|
|
|
|
edge->destNode()->addEdge(edge,false);
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->addItem(edge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
emit m_graphLogic->contentChanged(false);
|
|
|
|
|
m_graphLogic->m_activeNode = m_activeNode;
|
|
|
|
|
m_graphLogic->m_hintNode = m_hintNode;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// it we are in hint mode, the numbers shall be re-calculated
|
|
|
|
|
if (m_graphLogic->m_showingNodeNumbers)
|
|
|
|
|
m_graphLogic->showNodeNumbers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RemoveNodeCommand::redo()
|
|
|
|
|
{
|
|
|
|
|
foreach(Node *node, m_nodeList)
|
|
|
|
|
{
|
|
|
|
|
if (m_graphLogic->m_hintNode==node)
|
|
|
|
|
m_graphLogic->m_hintNode=0;
|
|
|
|
|
|
|
|
|
|
m_graphLogic->m_nodeList.removeAll(node);
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->removeItem(node);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach(Edge *edge, m_edgeList)
|
|
|
|
|
{
|
|
|
|
|
edge->sourceNode()->removeEdge(edge);
|
|
|
|
|
edge->destNode()->removeEdge(edge);
|
|
|
|
|
m_graphLogic->m_graphWidget->scene()->removeItem(edge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_graphLogic->m_activeNode = 0;
|
|
|
|
|
|
|
|
|
|
emit m_graphLogic->contentChanged();
|
|
|
|
|
|
|
|
|
|
// it we are in hint mode, the numbers shall be re-calculated
|
|
|
|
|
if (m_graphLogic->m_showingNodeNumbers)
|
|
|
|
|
m_graphLogic->showNodeNumbers();
|
|
|
|
|
}
|
|
|
|
|