summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukáš Lalinský <lalinsky@gmail.com>2008-12-07 13:28:58 +0100
committerLukáš Lalinský <lalinsky@gmail.com>2008-12-07 13:28:58 +0100
commit0e7dca6418d9ac41f2008a302f43bd42ed22afc8 (patch)
tree9488ca6327c779007edf6fb58a8744763881330c
parent67aa58e87c32fad4948abd859db30a4e7f9551c7 (diff)
downloaddbmodel-0e7dca6418d9ac41f2008a302f43bd42ed22afc8.tar.gz
dbmodel-0e7dca6418d9ac41f2008a302f43bd42ed22afc8.tar.bz2
Make item removes undo-able (ignores relationships for now)
-rw-r--r--src/commands.cpp26
-rw-r--r--src/commands.h12
-rw-r--r--src/diagramdocument.cpp3
3 files changed, 40 insertions, 1 deletions
diff --git a/src/commands.cpp b/src/commands.cpp
index c6eb692..b9960ef 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -170,3 +170,29 @@ AddItemCommand::undo()
m_document->removeItem(m_item);
m_owner = true;
}
+
+
+RemoveItemCommand::RemoveItemCommand(DiagramDocument *document, DiagramItem *item, QUndoCommand *parent)
+ : QUndoCommand(parent), m_document(document), m_item(item), m_owner(false)
+{
+}
+
+RemoveItemCommand::~RemoveItemCommand()
+{
+ if (m_owner)
+ delete m_item;
+}
+
+void
+RemoveItemCommand::redo()
+{
+ m_document->removeItem(m_item);
+ m_owner = true;
+}
+
+void
+RemoveItemCommand::undo()
+{
+ m_document->addItem(m_item);
+ m_owner = false;
+}
diff --git a/src/commands.h b/src/commands.h
index 617193c..7769dfa 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -105,7 +105,19 @@ public:
~AddItemCommand();
void undo();
void redo();
+private:
+ DiagramDocument *m_document;
+ DiagramItem *m_item;
+ bool m_owner;
+};
+class RemoveItemCommand : public QUndoCommand
+{
+public:
+ RemoveItemCommand(DiagramDocument *document, DiagramItem *item, QUndoCommand *parent = 0);
+ ~RemoveItemCommand();
+ void undo();
+ void redo();
private:
DiagramDocument *m_document;
DiagramItem *m_item;
diff --git a/src/diagramdocument.cpp b/src/diagramdocument.cpp
index d0a8b4c..30e751d 100644
--- a/src/diagramdocument.cpp
+++ b/src/diagramdocument.cpp
@@ -165,10 +165,11 @@ DiagramDocument::deleteSelectedItems()
foreach (QGraphicsItem *item, selectedItems()) {
DatabaseTable *table = qgraphicsitem_cast<DatabaseTable *>(item);
if (table) {
+ // FIXME
foreach (DatabaseRelationship *relation, findTableRelations(table)) {
removeItem(relation);
}
- removeItem(table);
+ undoStack()->push(new RemoveItemCommand(this, table));
}
}
}