Skip to content

Commit

Permalink
Add Undo Function
Browse files Browse the repository at this point in the history
  • Loading branch information
skeenp committed Oct 25, 2017
1 parent f25acf4 commit 22711a0
Show file tree
Hide file tree
Showing 4 changed files with 491 additions and 5 deletions.
40 changes: 35 additions & 5 deletions src/roam/maptools/maptools.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,23 @@ def __init__(self, icon, name, tool, parent=None):
self.isdefault = False
self.ismaptool = False

class UndoAction(BaseAction):
def __init__(self, tool, parent=None):
super(UndoAction, self).__init__(QIcon(":/icons/back"),
"Undo",
tool,
parent)
self.setObjectName("UndoAction")
self.setText(self.tr("Undo"))


class EndCaptureAction(BaseAction):
def __init__(self, tool, parent=None):
super(EndCaptureAction, self).__init__(QIcon(":/icons/stop-capture"),
"End Capture",
tool,
parent)
self.setObjectName("EnaCaptureAction")
self.setObjectName("EndCaptureAction")
self.setText(self.tr("End Capture"))


Expand Down Expand Up @@ -142,7 +151,6 @@ def set_text(self, tracking):
else:
self.setText(self.tr("Track"))


class GPSCaptureAction(BaseAction):
def __init__(self, tool, geomtype, parent=None):
super(GPSCaptureAction, self).__init__(QIcon(":/icons/gpsadd-{}".format(geomtype)),
Expand Down Expand Up @@ -222,6 +230,10 @@ def __init__(self, canvas):
self.trackingaction = GPSTrackingAction(self)
self.endcaptureaction = EndCaptureAction(self)

self.undoaction = UndoAction(self)
self.undoaction.setEnabled(False)
self.undoaction.triggered.connect(self.undo)

self.trackingaction.setEnabled(False)

self.trackingaction.toggled.connect(self.set_tracking)
Expand Down Expand Up @@ -259,6 +271,7 @@ def selection_updated(self, *args):
def update_end_capture_state(self, *args):
if self.trackingaction.isChecked() and self.captureaction.isChecked():
self.endcaptureaction.setEnabled(self.capturing)
self.undoaction.setEnabled(self.capturing)

def update_tracking_button_disconnect(self):
self.trackingaction.setEnabled(False)
Expand Down Expand Up @@ -329,14 +342,18 @@ def track_gps_location_changed(self, point, info):

@property
def actions(self):
return [self.captureaction, self.trackingaction, self.gpscapture, self.endcaptureaction]
return [self.captureaction, self.trackingaction, self.gpscapture, self.endcaptureaction, self.undoaction]

def add_vertex(self):
location = GPS.postion
self.add_point(location)
# Add an extra point for the move band
self.band.addPoint(location)

def remove_last_vertex(self):
self.remove_last_point()
self.band.removeLastPoint(doUpdate=True)

def canvasPressEvent(self, event):
point = self.canvas.getCoordinateTransform().toMapCoordinates(event.pos())
geom = self.band.asGeometry()
Expand Down Expand Up @@ -435,6 +452,13 @@ def add_point(self, point):
self.pointband.addPoint(point)
self.capturing = True
self.endcaptureaction.setEnabled(True)
self.undoaction.setEnabled(True)

def remove_last_point(self):
if len(self.points) > 1:
del self.points[-1]
self.band.removeLastPoint(doUpdate=True)
self.pointband.removeLastPoint(doUpdate=True)

def endinvalidcapture(self, errors):
geometry = self.band.asGeometry()
Expand All @@ -447,9 +471,13 @@ def endinvalidcapture(self, errors):
self.capturing = False
self.set_tracking(False)
self.captureaction.setChecked(True)
self.undoaction.setEnabled(False)
self.endcaptureaction.setEnabled(False)
self.reset()

def undo(self):
self.remove_last_point()

def endcapture(self):
errors = self.has_errors()
if errors:
Expand All @@ -462,6 +490,7 @@ def endcapture(self):
self.capturing = False
self.set_tracking(False)
self.captureaction.setChecked(True)
self.undoaction.setEnabled(False)
self.endcaptureaction.setEnabled(False)
if not self.editmode:
self.band.removeLastPoint()
Expand Down Expand Up @@ -531,6 +560,7 @@ def setEditMode(self, enabled, geom):
self.pointband.setColor(self.startcolour)

self.endcaptureaction.setEnabled(self.editmode)
self.undoaction.setEnabled(self.editmode)
self.captureaction.setEditMode(enabled)


Expand Down Expand Up @@ -633,9 +663,9 @@ def addatgps(self):

def activate(self):
"""
Set the tool as the active tool in the canvas.
Set the tool as the active tool in the canvas.
@note: Should be moved out into qmap.py
@note: Should be moved out into qmap.py
and just expose a cursor to be used
"""
self.canvas.setCursor(self.cursor)
Expand Down
1 change: 1 addition & 0 deletions src/roam/resources.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<file alias="download">resources/images/download.svg</file>
<file alias="record">resources/images/record.svg</file>
<file alias="pause">resources/images/pause.svg</file>
<file alias="back">resources/images/back.svg</file>
</qresource>
<qresource prefix="branding">
<file alias="config">resources/branding/config.ico</file>
Expand Down
Binary file added src/roam/resources/back.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 22711a0

Please sign in to comment.