class GraphDelegate(QtGui.QItemDelegate):
   def __init__(self, parent=None):
      QtGui.QItemDelegate.__init__(self,parent)

      self.mTimeData = [i for i in xrange(HISTORY)]

      self.mCurve = Curve()
      self.mCurve.setColor(QtCore.Qt.blue)
      self.mCurve.setStyle(Curve.LINES)

      self.mXMap = Scale()
      self.mYMap = Scale()
      self.mXMap.setScaleInterval(0, HISTORY)
      self.mYMap.setScaleInterval(0, 100)

   def paint(self, painter, option, index):
      # If we are painting the first column, use default paint method.
      if index.column() == 0:
         QtGui.QItemDelegate.paint(self, painter, option, index)
      else:
         # Get data out of the model for the curves.
         data = index.model().data(index)
         self.mCurve.setData(self.mTimeData, data)

         # Solid background
         #background_color = QtGui.QColor(QtCore.Qt.black)
         #brush = QtGui.QBrush(background_color)

         # Simple gradiant
         linear_gradient = QtGui.QLinearGradient(0, 0, 0, option.rect.bottom())
         linear_gradient.setColorAt(0.0, QtCore.Qt.white)
         linear_gradient.setColorAt(1.0, QtCore.Qt.gray)
         brush = QtGui.QBrush(linear_gradient)
         painter.fillRect(option.rect, brush)

         # Set the intervals so the curves know how to draw themselves.
         self.mXMap.setScaleInterval(0, len(data))
         self.mXMap.setPaintInterval(option.rect.left(), option.rect.right())
         self.mYMap.setPaintInterval(0.0, option.rect.bottom()-option.rect.top())

         # Paint the curves.
         painter.save()
         painter.setClipRect(option.rect)
         painter.translate(0, option.rect.bottom())
         painter.scale(1.0, -1.0)
         self.mCurve.draw(painter, self.mXMap, self.mYMap)
         painter.restore()


         # Draw a frame around cell if it is selected.
         if (option.showDecorationSelected and (option.state & QtGui.QStyle.State_Selected)):
            QtGui.qDrawPlainRect(painter, option.rect, option.palette.highlight().color(), 1)

         # Draw the percentage as text.
         #text_width = max(option.fontMetrics.width(''), option.fontMetrics.width("100%")) + 6;
         overlay_text = ("%.2f " % data[-1]) + "%"
         style = QtGui.QApplication.style()
         align_flags = QtCore.Qt.AlignHorizontal_Mask | QtCore.Qt.TextSingleLine
         style.drawItemText(painter, option.rect, align_flags, option.palette, True, overlay_text)
Beispiel #2
0
    def __init__(self, parent=None):
        QtGui.QItemDelegate.__init__(self, parent)

        self.mTimeData = [i for i in xrange(HISTORY)]

        self.mCurve = Curve()
        self.mCurve.setColor(QtCore.Qt.blue)
        self.mCurve.setStyle(Curve.LINES)

        self.mXMap = Scale()
        self.mYMap = Scale()
        self.mXMap.setScaleInterval(0, HISTORY)
        self.mYMap.setScaleInterval(0, 100)
   def __init__(self, parent=None):
      QtGui.QItemDelegate.__init__(self,parent)

      self.mTimeData = [i for i in xrange(HISTORY)]

      self.mCurve = Curve()
      self.mCurve.setColor(QtCore.Qt.blue)
      self.mCurve.setStyle(Curve.LINES)

      self.mXMap = Scale()
      self.mYMap = Scale()
      self.mXMap.setScaleInterval(0, HISTORY)
      self.mYMap.setScaleInterval(0, 100)
Beispiel #4
0
class GraphDelegate(QtGui.QItemDelegate):
    def __init__(self, parent=None):
        QtGui.QItemDelegate.__init__(self, parent)

        self.mTimeData = [i for i in xrange(HISTORY)]

        self.mCurve = Curve()
        self.mCurve.setColor(QtCore.Qt.blue)
        self.mCurve.setStyle(Curve.LINES)

        self.mXMap = Scale()
        self.mYMap = Scale()
        self.mXMap.setScaleInterval(0, HISTORY)
        self.mYMap.setScaleInterval(0, 100)

    def paint(self, painter, option, index):
        # If we are painting the first column, use default paint method.
        if index.column() == 0:
            QtGui.QItemDelegate.paint(self, painter, option, index)
        else:
            # Get data out of the model for the curves.
            data = index.model().data(index)
            self.mCurve.setData(self.mTimeData, data)

            # Solid background
            #background_color = QtGui.QColor(QtCore.Qt.black)
            #brush = QtGui.QBrush(background_color)

            # Simple gradiant
            linear_gradient = QtGui.QLinearGradient(0, 0, 0,
                                                    option.rect.bottom())
            linear_gradient.setColorAt(0.0, QtCore.Qt.white)
            linear_gradient.setColorAt(1.0, QtCore.Qt.gray)
            brush = QtGui.QBrush(linear_gradient)
            painter.fillRect(option.rect, brush)

            # Set the intervals so the curves know how to draw themselves.
            self.mXMap.setScaleInterval(0, len(data))
            self.mXMap.setPaintInterval(option.rect.left(),
                                        option.rect.right())
            self.mYMap.setPaintInterval(
                0.0,
                option.rect.bottom() - option.rect.top())

            # Paint the curves.
            painter.save()
            painter.setClipRect(option.rect)
            painter.translate(0, option.rect.bottom())
            painter.scale(1.0, -1.0)
            self.mCurve.draw(painter, self.mXMap, self.mYMap)
            painter.restore()

            # Draw a frame around cell if it is selected.
            if (option.showDecorationSelected
                    and (option.state & QtGui.QStyle.State_Selected)):
                QtGui.qDrawPlainRect(painter, option.rect,
                                     option.palette.highlight().color(), 1)

            # Draw the percentage as text.
            #text_width = max(option.fontMetrics.width(''), option.fontMetrics.width("100%")) + 6;
            overlay_text = ("%.2f " % data[-1]) + "%"
            style = QtGui.QApplication.style()
            align_flags = QtCore.Qt.AlignHorizontal_Mask | QtCore.Qt.TextSingleLine
            style.drawItemText(painter, option.rect, align_flags,
                               option.palette, True, overlay_text)