]> sigrok.org Git - sigrok-meter.git/blobdiff - datamodel.py
Minor cosmetics and typo fixes.
[sigrok-meter.git] / datamodel.py
index 2b29fa4b3db328c6d398f63a533c8e7989c7f9b9..83d5ef60df7080c225215eb1cc299e87f311de7a 100644 (file)
@@ -52,7 +52,7 @@ class MeasurementDataModel(QtGui.QStandardItemModel):
     '''Role used to store the device vendor and model.'''
     descRole = QtCore.Qt.UserRole + 2
 
-    '''Role used to store a dictionary with the traces'''
+    '''Role used to store a dictionary with the traces.'''
     tracesRole = QtCore.Qt.UserRole + 3
 
     '''Role used to store the color to draw the graph of the channel.'''
@@ -169,6 +169,13 @@ class MeasurementDataModel(QtGui.QStandardItemModel):
 
             item.setData(traces, MeasurementDataModel.tracesRole)
 
+    def clear_samples(self):
+        '''Removes all old samples from the model.'''
+        for row in range(self.rowCount()):
+            idx = self.index(row, 0)
+            self.setData(idx, {},
+                MeasurementDataModel.tracesRole)
+
 class MultimeterDelegate(QtGui.QStyledItemDelegate):
     '''Delegate to show the data items from a MeasurementDataModel.'''
 
@@ -226,9 +233,11 @@ class MultimeterDelegate(QtGui.QStyledItemDelegate):
                     c = index.data(MeasurementDataModel.colorRole)
                     c = QtGui.QColorDialog.getColor(c, None,
                         'Choose new color for channel')
-
-                    item = model.itemFromIndex(index)
-                    item.setData(c, MeasurementDataModel.colorRole)
+                    if c.isValid():
+                        # False if cancel is pressed (resulting in a black
+                        # color).
+                        item = model.itemFromIndex(index)
+                        item.setData(c, MeasurementDataModel.colorRole)
 
                     return True