## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
-## along with this program; if not, write to the Free Software
-## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
-import collections
import itertools
import math
import qtcompat
'''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.'''
item = QtGui.QStandardItem()
item.setData(uid, MeasurementDataModel.idRole)
item.setData(desc, MeasurementDataModel.descRole)
- item.setData(collections.defaultdict(Trace), MeasurementDataModel.tracesRole)
+ item.setData({}, MeasurementDataModel.tracesRole)
item.setData(next(self._colorgen), MeasurementDataModel.colorRole)
self.appendRow(item)
self.sort(0)
if not math.isinf(value) and not math.isnan(value):
sample = (timestamp, value)
traces = item.data(MeasurementDataModel.tracesRole)
+
+ # It's not possible to use 'collections.defaultdict' here, because
+ # PySide doesn't return the original type that was passed in.
+ if not (unit in traces):
+ traces[unit] = Trace()
traces[unit].append(sample)
+ 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.'''
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