From f7a38da38365a90bc4dddaf31a63b4e635095c1e Mon Sep 17 00:00:00 2001 From: Mika Fischer Date: Tue, 14 Jun 2011 10:24:16 +0200 Subject: [PATCH] Fix going to next/previous image --- sloth/annotations/model.py | 16 ++++++++++++++++ sloth/core/labeltool.py | 12 ++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/sloth/annotations/model.py b/sloth/annotations/model.py index f120c48..ebce7eb 100644 --- a/sloth/annotations/model.py +++ b/sloth/annotations/model.py @@ -34,6 +34,22 @@ class ModelItem(QObject): assert self.parent_ is None self.parent_ = parent + def getPreviousSibling(self): + if self.parent_ is not None: + c = self.parent().children() + row = c.index(self) + if row > 0: + return c[row-1] + return None + + def getNextSibling(self): + if self.parent_ is not None: + c = self.parent().children() + row = c.index(self) + if row < len(c) - 2: + return c[row+1] + return None + def setIndex(self, index): assert self._pindex is None self._pindex = QPersistentModelIndex(index) diff --git a/sloth/core/labeltool.py b/sloth/core/labeltool.py index 763a854..8c5415c 100755 --- a/sloth/core/labeltool.py +++ b/sloth/core/labeltool.py @@ -139,15 +139,15 @@ class LabelTool(QObject): def gotoNext(self): # TODO move this to the scene - if self._model is not None and self.current_index_ is not None: - next_index = self._model.getNextIndex(self.current_index_) - self.setCurrentIndex(next_index) + if self._model is not None and self._current_image is not None: + next_image = self._current_image.getNextSibling() + self.setCurrentImage(next_image) def gotoPrevious(self): # TODO move this to the scene - if self._model is not None and self.current_index_ is not None: - prev_index = self._model.getPreviousIndex(self.current_index_) - self.setCurrentIndex(prev_index) + if self._model is not None and self._current_image is not None: + prev_image = self._current_image.getPreviousSibling() + self.setCurrentImage(prev_image) def updateModified(self): """update all GUI elements which depend on the state of the model,