Fixing issues with deleting random rows
[ejpi] / src / qhistory.py
index e39fb71..af164b8 100644 (file)
@@ -40,7 +40,7 @@ class QCalcHistory(history.AbstractHistory):
                self._historyView.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
                self._historyView.setSelectionMode(QtGui.QAbstractItemView.SingleSelection)
                self._historyView.setHeaderHidden(True)
-               self._historyView.activated.connect(self._on_delete_row)
+               self._historyView.activated.connect(self._on_row_activated)
 
                viewHeader = self._historyView.header()
                viewHeader.setSortIndicatorShown(True)
@@ -73,6 +73,7 @@ class QCalcHistory(history.AbstractHistory):
                equation.setCheckable(False)
                result = QtGui.QStandardItem(operation.render_operation(self._prettyRenderer, simpleNode))
                result.setData(simpleNode)
+               result.setEditable(False)
                result.setCheckable(False)
 
                row = (icon, equation, result)
@@ -105,9 +106,12 @@ class QCalcHistory(history.AbstractHistory):
                self._rowCount = 0
 
        @misc_utils.log_exception(_moduleLogger)
-       def _on_delete_row(self, index):
+       def _on_row_activated(self, index):
                if index.column() == self._CLOSE_COLUMN:
                        self._historyStore.removeRow(index.row(), index.parent())
+                       self._rowCount -= 1
+               elif index.column() == self._RESULT_COLUMN:
+                       self._duplicate_row(index)
                else:
                        raise NotImplementedError("Unsupported column to activate %s" % index.column())
 
@@ -127,6 +131,10 @@ class QCalcHistory(history.AbstractHistory):
                finally:
                        self._programmaticUpdate = False
 
+       def _duplicate_row(self, index):
+               item = self._historyStore.item(index.row(), self._EQ_COLUMN)
+               self.push(item.data().toPyObject())
+
        def _parse_value(self, value):
                raise NotImplementedError("What?")
 
@@ -155,4 +163,7 @@ class QCalcHistory(history.AbstractHistory):
 
        def __iter__(self):
                for i in xrange(self._rowCount):
-                       yield self._historyStore.item(i, 1).data().toPyObject()
+                       item = self._historyStore.item(i, self._EQ_COLUMN)
+                       if item is None:
+                               continue
+                       yield item.data().toPyObject()