Example #1
0
    def drawSeries(self, seriesItem, from_, to):
        """When observing an measurement while it is running, new points have 
        to be added to an existing seriesItem. drawSeries() can be used to 
        display them avoiding a complete redraw of the canvas.

        Setting plot().canvas().setAttribute(Qt.WA_PaintOutsidePaintEvent, True)
        will result in faster painting, if the paint engine of the canvas widget
        supports this feature."""
        if seriesItem is None or seriesItem.plot() is None:
            return
        canvas = seriesItem.plot().canvas()
        canvasRect = canvas.contentsRect()
        plotCanvas = canvas  #XXX: cast to QwtPlotCanvas
        if plotCanvas and qwtHasBackingStore(plotCanvas):
            painter = QPainter(plotCanvas.backingStore())  #XXX: cast plotCanvas.backingStore() to QPixmap
            if self.__data.hasClipping:
                painter.setClipRegion(self.__data.clipRegion)
            qwtRenderItem(painter, canvasRect, seriesItem, from_, to)
            if self.testAttribute(self.FullRepaint):
                plotCanvas.repaint()
                return
        immediatePaint = True
        if not canvas.testAttribute(Qt.WA_WState_InPaintEvent):
            if QT_VERSION >= 0x050000 or\
               not canvas.testAttribute(Qt.WA_PaintOutsidePaintEvent):
                immediatePaint = False
        if immediatePaint:
            if not self.__data.painter.isActive():
                self.reset()
                self.__data.painter.begin(canvas)
                canvas.installEventFilter(self)
            if self.__data.hasClipping:
                self.__data.painter.setClipRegion(
                        QRegion(canvasRect) & self.__data.clipRegion)
            elif not self.__data.painter.hasClipping():
                self.__data.painter.setClipRect(canvasRect)
            qwtRenderItem(self.__data.painter,
                          canvasRect, seriesItem, from_, to)
            if self.__data.attributes & self.AtomicPainter:
                self.reset()
            elif self.__data.hasClipping:
                self.__data.painter.setClipping(False)
        else:
            self.reset()
            self.__data.seriesItem = seriesItem
            self.__data.from_ = from_
            self.__data.to = to
            clipRegion = QRegion(canvasRect)
            if self.__data.hasClipping:
                clipRegion &= self.__data.clipRegion
            canvas.installEventFilter(self)
            canvas.repaint(clipRegion)
            canvas.removeEventFilter(self)
            self.__data.seriesItem = None
Example #2
0
    def updateLayout(self):
#        state = self.get_layout_state()
#        if self.__layout_state is not None and\
#           state == self.__layout_state:
#            return
#        self.__layout_state = state

        self.__data.layout.activate(self, self.contentsRect())
        
        titleRect = self.__data.layout.titleRect().toRect()
        footerRect = self.__data.layout.footerRect().toRect()
        scaleRect = [None] * self.axisCnt
        for axisId in range(self.axisCnt):
            scaleRect[axisId] = self.__data.layout.scaleRect(axisId).toRect()
        legendRect = self.__data.layout.legendRect().toRect()
        canvasRect = self.__data.layout.canvasRect().toRect()
        
        if self.__data.titleLabel.text():
            self.__data.titleLabel.setGeometry(titleRect)
            if not self.__data.titleLabel.isVisibleTo(self):
                self.__data.titleLabel.show()
        else:
            self.__data.titleLabel.hide()

        if self.__data.footerLabel.text():
            self.__data.footerLabel.setGeometry(footerRect)
            if not self.__data.footerLabel.isVisibleTo(self):
                self.__data.footerLabel.show()
        else:
            self.__data.footerLabel.hide()
        
        for axisId in range(self.axisCnt):
            if self.axisEnabled(axisId):
                self.axisWidget(axisId).setGeometry(scaleRect[axisId])
                
                if axisId in (self.xBottom, self.xTop):
                    r = QRegion(scaleRect[axisId])
                    if self.axisEnabled(self.yLeft):
                        r = r.subtracted(QRegion(scaleRect[self.yLeft]))
                    if self.axisEnabled(self.yRight):
                        r = r.subtracted(QRegion(scaleRect[self.yRight]))
                    r.translate(-scaleRect[axisId].x(), -scaleRect[axisId].y())
                    
                    self.axisWidget(axisId).setMask(r)
                    
                if not self.axisWidget(axisId).isVisibleTo(self):
                    self.axisWidget(axisId).show()
                
            else:
                self.axisWidget(axisId).hide()
            
        if self.__data.legend:
            if self.__data.legend.isEmpty():
                self.__data.legend.hide()
            else:
                self.__data.legend.setGeometry(legendRect)
                self.__data.legend.show()
        
        self.__data.canvas.setGeometry(canvasRect)
Example #3
0
 def __init__(self):
     self.attributes = 0
     self.hasClipping = False
     self.seriesItem = None  # QwtPlotSeriesItem
     self.clipRegion = QRegion()
     self.painter = QPainter()
     self.from_ = None
     self.to = None
Example #4
0
 def __init__(self):
     self.pathlist = []
     self.rectList = []
     self.clipRegion = QRegion()
Example #5
0
    def activate(self, plot, plotRect, options=0x00):
        self.invalidate()
        rect = QRectF(plotRect)
        self.__data.layoutData.init(plot, rect)
        if not (options & self.IgnoreLegend) and plot.legend() and\
           not plot.legend().isEmpty():
            self.__data.legendRect = self.layoutLegend(options, rect)
            region = QRegion(rect.toRect())
            rect = region.subtracted(QRegion(
                self.__data.legendRect.toRect())).boundingRect()
            if self.__data.legendPos == QwtPlot.LeftLegend:
                rect.setLeft(rect.left() + self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.RightLegend:
                rect.setRight(rect.right() - self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.TopLegend:
                rect.setTop(rect.top() + self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.BottomLegend:
                rect.setBottom(rect.bottom() - self.__data.spacing)

#     +---+-----------+---+
#     |       Title       |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     | A |           | A |
#     | x |  Canvas   | x |
#     | i |           | i |
#     | s |           | s |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     |      Footer       |
#     +---+-----------+---+

        dimTitle, dimFooter, dimAxes = self.expandLineBreaks(options, rect)
        if dimTitle > 0:
            self.__data.titleRect.setRect(rect.left(), rect.top(),
                                          rect.width(), dimTitle)
            rect.setTop(self.__data.titleRect.bottom() + self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.titleRect.setX(rect.left() +
                                           dimAxes[QwtPlot.yLeft])
                self.__data.titleRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        if dimFooter > 0:
            self.__data.footerRect.setRect(rect.left(),
                                           rect.bottom() - dimFooter,
                                           rect.width(), dimFooter)
            rect.setBottom(self.__data.footerRect.top() - self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.footerRect.setX(rect.left() +
                                            dimAxes[QwtPlot.yLeft])
                self.__data.footerRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        self.__data.canvasRect.setRect(
            rect.x() + dimAxes[QwtPlot.yLeft],
            rect.y() + dimAxes[QwtPlot.xTop],
            rect.width() - dimAxes[QwtPlot.yRight] - dimAxes[QwtPlot.yLeft],
            rect.height() - dimAxes[QwtPlot.xBottom] - dimAxes[QwtPlot.xTop])
        for axis in range(QwtPlot.axisCnt):
            if dimAxes[axis]:
                dim = dimAxes[axis]
                scaleRect = self.__data.scaleRect[axis]
                scaleRect.setRect(*self.__data.canvasRect.getRect())
                if axis == QwtPlot.yLeft:
                    scaleRect.setX(self.__data.canvasRect.left() - dim)
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.yRight:
                    scaleRect.setX(self.__data.canvasRect.right())
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.xBottom:
                    scaleRect.setY(self.__data.canvasRect.bottom())
                    scaleRect.setHeight(dim)
                elif axis == QwtPlot.xTop:
                    scaleRect.setY(self.__data.canvasRect.top() - dim)
                    scaleRect.setHeight(dim)
                scaleRect = scaleRect.normalized()

#       +---+-----------+---+
#       |  <-   Axis   ->   |
#       +-^-+-----------+-^-+
#       | | |           | | |
#       |   |           |   |
#       | A |           | A |
#       | x |  Canvas   | x |
#       | i |           | i |
#       | s |           | s |
#       |   |           |   |
#       | | |           | | |
#       +-V-+-----------+-V-+
#       |   <-  Axis   ->   |
#       +---+-----------+---+

        self.alignScales(options, self.__data.canvasRect,
                         self.__data.scaleRect)
        if not self.__data.legendRect.isEmpty():
            self.__data.legendRect = self.alignLegend(self.__data.canvasRect,
                                                      self.__data.legendRect)
Example #6
0
    def activate(self, plot, plotRect, options=0x00):
        """
        Recalculate the geometry of all components.
        
        :param qwt.plot.QwtPlot plot: Plot to be layout
        :param QRectF plotRect: Rectangle where to place the components
        :param options: Layout options
        """
        self.invalidate()
        rect = QRectF(plotRect)
        self.__data.layoutData.init(plot, rect)
        if not (options & self.IgnoreLegend) and plot.legend() and\
           not plot.legend().isEmpty():
            self.__data.legendRect = self.layoutLegend(options, rect)
            region = QRegion(rect.toRect())
            rect = region.subtracted(QRegion(self.__data.legendRect.toRect())
                                     ).boundingRect()
            if self.__data.legendPos == QwtPlot.LeftLegend:
                rect.setLeft(rect.left()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.RightLegend:
                rect.setRight(rect.right()-self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.TopLegend:
                rect.setTop(rect.top()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.BottomLegend:
                rect.setBottom(rect.bottom()-self.__data.spacing)
        
#     +---+-----------+---+
#     |       Title       |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     | A |           | A |
#     | x |  Canvas   | x |
#     | i |           | i |
#     | s |           | s |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     |      Footer       |
#     +---+-----------+---+

        #  title, footer and axes include text labels. The height of each
        #  label depends on its line breaks, that depend on the width
        #  for the label. A line break in a horizontal text will reduce
        #  the available width for vertical texts and vice versa.
        #  expandLineBreaks finds the height/width for title, footer and axes
        #  including all line breaks.

        dimTitle, dimFooter, dimAxes = self.expandLineBreaks(options, rect)
        if dimTitle > 0:
            self.__data.titleRect.setRect(rect.left(), rect.top(),
                                          rect.width(), dimTitle)
            rect.setTop(self.__data.titleRect.bottom()+self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.titleRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.titleRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        if dimFooter > 0:
            self.__data.footerRect.setRect(rect.left(),
                           rect.bottom()-dimFooter, rect.width(), dimFooter)
            rect.setBottom(self.__data.footerRect.top()-self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.footerRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.footerRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        self.__data.canvasRect.setRect(
                rect.x()+dimAxes[QwtPlot.yLeft],
                rect.y()+dimAxes[QwtPlot.xTop],
                rect.width()-dimAxes[QwtPlot.yRight]-dimAxes[QwtPlot.yLeft],
                rect.height()-dimAxes[QwtPlot.xBottom]-dimAxes[QwtPlot.xTop])
        for axis in QwtPlot.validAxes:
            if dimAxes[axis]:
                dim = dimAxes[axis]
                scaleRect = self.__data.scaleRect[axis]
                scaleRect.setRect(*self.__data.canvasRect.getRect())
                if axis == QwtPlot.yLeft:
                    scaleRect.setX(self.__data.canvasRect.left()-dim)
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.yRight:
                    scaleRect.setX(self.__data.canvasRect.right())
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.xBottom:
                    scaleRect.setY(self.__data.canvasRect.bottom())
                    scaleRect.setHeight(dim)
                elif axis == QwtPlot.xTop:
                    scaleRect.setY(self.__data.canvasRect.top()-dim)
                    scaleRect.setHeight(dim)
                scaleRect = scaleRect.normalized()
                
#       +---+-----------+---+
#       |  <-   Axis   ->   |
#       +-^-+-----------+-^-+
#       | | |           | | |
#       |   |           |   |
#       | A |           | A |
#       | x |  Canvas   | x |
#       | i |           | i |
#       | s |           | s |
#       |   |           |   |
#       | | |           | | |
#       +-V-+-----------+-V-+
#       |   <-  Axis   ->   |
#       +---+-----------+---+

        #  The ticks of the axes - not the labels above - should
        #  be aligned to the canvas. So we try to use the empty
        #  corners to extend the axes, so that the label texts
        #  left/right of the min/max ticks are moved into them.
                
        self.alignScales(options, self.__data.canvasRect,
                         self.__data.scaleRect)
        if not self.__data.legendRect.isEmpty():
            self.__data.legendRect = self.alignLegend(self.__data.canvasRect,
                                                      self.__data.legendRect)
Example #7
0
    def activate(self, plot, plotRect, options=0x00):
        self.invalidate()
        rect = QRectF(plotRect)
        self.__data.layoutData.init(plot, rect)
        if not (options & self.IgnoreLegend) and plot.legend() and\
           not plot.legend().isEmpty():
            self.__data.legendRect = self.layoutLegend(options, rect)
            region = QRegion(rect.toRect())
            rect = region.subtracted(QRegion(self.__data.legendRect.toRect())
                                     ).boundingRect()
            if self.__data.legendPos == QwtPlot.LeftLegend:
                rect.setLeft(rect.left()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.RightLegend:
                rect.setRight(rect.right()-self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.TopLegend:
                rect.setTop(rect.top()+self.__data.spacing)
            elif self.__data.legendPos == QwtPlot.BottomLegend:
                rect.setBottom(rect.bottom()-self.__data.spacing)
        
#     +---+-----------+---+
#     |       Title       |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     | A |           | A |
#     | x |  Canvas   | x |
#     | i |           | i |
#     | s |           | s |
#     +---+-----------+---+
#     |   |   Axis    |   |
#     +---+-----------+---+
#     |      Footer       |
#     +---+-----------+---+

        dimTitle, dimFooter, dimAxes = self.expandLineBreaks(options, rect)
        if dimTitle > 0:
            self.__data.titleRect.setRect(rect.left(), rect.top(),
                                          rect.width(), dimTitle)
            rect.setTop(self.__data.titleRect.bottom()+self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.titleRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.titleRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        if dimFooter > 0:
            self.__data.footerRect.setRect(rect.left(),
                           rect.bottom()-dimFooter, rect.width(), dimFooter)
            rect.setBottom(self.__data.footerRect.top()-self.__data.spacing)
            if self.__data.layoutData.scale[QwtPlot.yLeft].isEnabled !=\
               self.__data.layoutData.scale[QwtPlot.yRight].isEnabled:
                self.__data.footerRect.setX(rect.left()+dimAxes[QwtPlot.yLeft])
                self.__data.footerRect.setWidth(rect.width()\
                            -dimAxes[QwtPlot.yLeft]-dimAxes[QwtPlot.yRight])
        self.__data.canvasRect.setRect(
                rect.x()+dimAxes[QwtPlot.yLeft],
                rect.y()+dimAxes[QwtPlot.xTop],
                rect.width()-dimAxes[QwtPlot.yRight]-dimAxes[QwtPlot.yLeft],
                rect.height()-dimAxes[QwtPlot.xBottom]-dimAxes[QwtPlot.xTop])
        for axis in range(QwtPlot.axisCnt):
            if dimAxes[axis]:
                dim = dimAxes[axis]
                scaleRect = self.__data.scaleRect[axis]
                scaleRect.setRect(*self.__data.canvasRect.getRect())
                if axis == QwtPlot.yLeft:
                    scaleRect.setX(self.__data.canvasRect.left()-dim)
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.yRight:
                    scaleRect.setX(self.__data.canvasRect.right())
                    scaleRect.setWidth(dim)
                elif axis == QwtPlot.xBottom:
                    scaleRect.setY(self.__data.canvasRect.bottom())
                    scaleRect.setHeight(dim)
                elif axis == QwtPlot.xTop:
                    scaleRect.setY(self.__data.canvasRect.top()-dim)
                    scaleRect.setHeight(dim)
                scaleRect = scaleRect.normalized()
                
#       +---+-----------+---+
#       |  <-   Axis   ->   |
#       +-^-+-----------+-^-+
#       | | |           | | |
#       |   |           |   |
#       | A |           | A |
#       | x |  Canvas   | x |
#       | i |           | i |
#       | s |           | s |
#       |   |           |   |
#       | | |           | | |
#       +-V-+-----------+-V-+
#       |   <-  Axis   ->   |
#       +---+-----------+---+
                
        self.alignScales(options, self.__data.canvasRect,
                         self.__data.scaleRect)
        if not self.__data.legendRect.isEmpty():
            self.__data.legendRect = self.alignLegend(self.__data.canvasRect,
                                                      self.__data.legendRect)