diff --git a/include/commands.h b/include/commands.h index c7ec4ba..04f66de 100644 --- a/include/commands.h +++ b/include/commands.h @@ -49,6 +49,12 @@ struct UndoContext }; +/// @todo need a base class... +enum MergeableCommandId +{ + MoveCommandId = 0 +}; + class InsertNodeCommand : public QUndoCommand { @@ -141,6 +147,9 @@ public: void undo(); void redo(); + bool mergeWith(const QUndoCommand *command); + int id() const { return MoveCommandId; } + private: bool m_done; diff --git a/src/commands.cpp b/src/commands.cpp index 1cc770b..3e65ccd 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -241,7 +241,8 @@ MoveCommand::MoveCommand(UndoContext context) setText(QObject::tr("Node \"").append( m_context.m_activeNode == m_context.m_nodeList->first() ? QObject::tr("Base node") : - m_context.m_activeNode->toPlainText()).append("\" moved")); + m_context.m_activeNode->toPlainText()). + append("\" moved (%1, %2)").arg(m_context.m_x).arg(m_context.m_y)); // move just the active Node or it's subtree too? if (QApplication::keyboardModifiers() & Qt::ControlModifier && @@ -267,3 +268,31 @@ void MoveCommand::redo() foreach(Node *node, m_nodeList) node->moveBy(m_context.m_x, m_context.m_y); } + +bool MoveCommand::mergeWith(const QUndoCommand *command) +{ + if (command->id() != id()) + return false; + + const MoveCommand *moveCommand = static_cast(command); + + if (m_context.m_activeNode != moveCommand->m_context.m_activeNode) + return false; + + m_context.m_x += moveCommand->m_context.m_x; + m_context.m_y += moveCommand->m_context.m_y; + + setText(QObject::tr("Node \"").append( + m_context.m_activeNode == m_context.m_nodeList->first() ? + QObject::tr("Base node") : + m_context.m_activeNode->toPlainText()). + append("\" moved (%1, %2)").arg(m_context.m_x).arg(m_context.m_y)); + + if (QApplication::keyboardModifiers() & Qt::ControlModifier && + QApplication::keyboardModifiers() & Qt::ShiftModifier) + { + setText(text().append(QObject::tr(" with subtree"))); + } + + return true; +}