hand drawn map editor: allow "undo" after "clear"
authorsheepluva
Sun, 11 Sep 2011 18:19:05 +0200
changeset 5858 1f4a8cf9efcb
parent 5857 63276513b7b3
child 5859 285b3fd862e7
hand drawn map editor: allow "undo" after "clear"
QTfrontend/drawmapscene.cpp
QTfrontend/drawmapscene.h
--- a/QTfrontend/drawmapscene.cpp	Sun Sep 11 11:09:28 2011 -0400
+++ b/QTfrontend/drawmapscene.cpp	Sun Sep 11 18:19:05 2011 +0200
@@ -108,11 +108,32 @@
 
         emit pathChanged();
     }
+    else if(oldItems.size())
+    {
+        while(oldItems.size())
+            addItem(oldItems.takeFirst());
+        paths = oldPaths;
+
+        emit pathChanged();
+    }
 }
 
 void DrawMapScene::clearMap()
 {
-    clear();
+    // don't clear if already cleared
+    if(!items().size())
+        return;
+
+    oldItems.clear();
+
+    // do this since clear() would _destroy_ all items
+    while(items().size()) {
+        oldItems.push_front(items().first());
+        removeItem(items().first());
+    }
+
+    oldPaths = paths;
+
     paths.clear();
 
     emit pathChanged();
@@ -146,6 +167,8 @@
 
 void DrawMapScene::decode(QByteArray data)
 {
+    oldItems.clear();
+    oldPaths.clear();
     clear();
     paths.clear();
 
--- a/QTfrontend/drawmapscene.h	Sun Sep 11 11:09:28 2011 -0400
+++ b/QTfrontend/drawmapscene.h	Sun Sep 11 18:19:05 2011 +0200
@@ -48,6 +48,8 @@
     QBrush m_brush;
     QGraphicsPathItem  * m_currPath;
     Paths paths;
+    Paths oldPaths;
+    QList<QGraphicsItem *> oldItems;
 
     virtual void mouseMoveEvent(QGraphicsSceneMouseEvent * mouseEvent);
     virtual void mousePressEvent(QGraphicsSceneMouseEvent * mouseEvent);