move commands can be merged

master
Denes Matetelki 14 years ago
parent 3f3968a0e4
commit d5ed92497b

@ -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;

@ -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<const MoveCommand *>(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;
}

Loading…
Cancel
Save