Exemplo n.º 1
0
    def drawSymbol(self, painter, point_or_rect):
        """
        Draw the symbol into a rectangle

        The symbol is painted centered and scaled into the target rectangle.
        It is always painted uncached and the pin point is ignored.

        This method is primarily intended for drawing a symbol to the legend.

        :param QPainter painter: Painter
        :param point_or_rect: Position or target rectangle of the symbol in screen coordinates
        :type point_or_rect: QPointF or QPoint or QRectF
        """
        if isinstance(point_or_rect, (QPointF, QPoint)):
            # drawSymbol( QPainter *, const QPointF & )
            self.drawSymbols(painter, [point_or_rect])
            return
        # drawSymbol( QPainter *, const QRectF & )
        rect = point_or_rect
        assert isinstance(rect, QRectF)
        if self.__data.style == QwtSymbol.NoSymbol:
            return
        if self.__data.style == QwtSymbol.Graphic:
            self.__data.graphic.graphic.render(painter, rect,
                                               Qt.KeepAspectRatio)
        elif self.__data.style == QwtSymbol.Path:
            if self.__data.path.graphic.isNull():
                self.__data.path.graphic = qwtPathGraphic(
                    self.__data.path.path, self.__data.pen, self.__data.brush)
            self.__data.path.graphic.render(painter, rect, Qt.KeepAspectRatio)
            return
        elif self.__data.style == QwtSymbol.SvgDocument:
            if self.__data.svg.renderer is not None:
                scaledRect = QRectF()
                sz = QSizeF(self.__data.svg.renderer.viewBoxF().size())
                if not sz.isEmpty():
                    sz.scale(rect.size(), Qt.KeepAspectRatio)
                    scaledRect.setSize(sz)
                    scaledRect.moveCenter(rect.center())
                else:
                    scaledRect = rect
                self.__data.svg.renderer.render(painter, scaledRect)
        else:
            br = QRect(self.boundingRect())
            ratio = min(
                [rect.width() / br.width(),
                 rect.height() / br.height()])
            painter.save()
            painter.translate(rect.center())
            painter.scale(ratio, ratio)
            isPinPointEnabled = self.__data.isPinPointEnabled
            self.__data.isPinPointEnabled = False
            pos = QPointF()
            self.renderSymbols(painter, pos, 1)
            self.__data.isPinPointEnabled = isPinPointEnabled
            painter.restore()
Exemplo n.º 2
0
    def drawSymbol(self, painter, point_or_rect):
        """
        Draw the symbol into a rectangle

        The symbol is painted centered and scaled into the target rectangle.
        It is always painted uncached and the pin point is ignored.

        This method is primarily intended for drawing a symbol to the legend.

        :param QPainter painter: Painter
        :param point_or_rect: Position or target rectangle of the symbol in screen coordinates
        :type point_or_rect: QPointF or QPoint or QRectF
        """
        if isinstance(point_or_rect, (QPointF, QPoint)):
            # drawSymbol( QPainter *, const QPointF & )
            self.drawSymbols(painter, [point_or_rect])
            return
        # drawSymbol( QPainter *, const QRectF & )
        rect = point_or_rect
        assert isinstance(rect, QRectF)
        if self.__data.style == QwtSymbol.NoSymbol:
            return
        if self.__data.style == QwtSymbol.Graphic:
            self.__data.graphic.graphic.render(painter, rect,
                                               Qt.KeepAspectRatio)
        elif self.__data.style == QwtSymbol.Path:
            if self.__data.path.graphic.isNull():
                self.__data.path.graphic = qwtPathGraphic(
                    self.__data.path.path, self.__data.pen, self.__data.brush)
            self.__data.path.graphic.render(painter, rect, Qt.KeepAspectRatio)
            return
        elif self.__data.style == QwtSymbol.SvgDocument:
            if self.__data.svg.renderer is not None:
                scaledRect = QRectF()
                sz = QSizeF(self.__data.svg.renderer.viewBoxF().size())
                if not sz.isEmpty():
                    sz.scale(rect.size(), Qt.KeepAspectRatio)
                    scaledRect.setSize(sz)
                    scaledRect.moveCenter(rect.center())
                else:
                    scaledRect = rect
                self.__data.svg.renderer.render(painter, scaledRect)
        else:
            br = QRect(self.boundingRect())
            ratio = min([rect.width()/br.width(), rect.height()/br.height()])
            painter.save()
            painter.translate(rect.center())
            painter.scale(ratio, ratio)
            isPinPointEnabled = self.__data.isPinPointEnabled
            self.__data.isPinPointEnabled = False
            pos = QPointF()
            self.renderSymbols(painter, pos, 1)
            self.__data.isPinPointEnabled = isPinPointEnabled
            painter.restore()
Exemplo n.º 3
0
    def drawSymbols(self, painter, points, numPoints=None):
        """
        Render an array of symbols

        Painting several symbols is more effective than drawing symbols
        one by one, as a couple of layout calculations and setting of pen/brush
        can be done once for the complete array.

        :param QPainter painter: Painter
        :param QPolygonF points: Positions of the symbols in screen coordinates
        """
        #TODO: remove argument numPoints (not necessary in `PythonQwt`)
        if numPoints is not None and numPoints <= 0:
            return
        useCache = False
        if QwtPainter.roundingAlignment(painter) and\
           not painter.transform().isScaling():
            if self.__data.cache.policy == QwtSymbol.Cache:
                useCache = True
            elif self.__data.cache.policy == QwtSymbol.AutoCache:
                if painter.paintEngine().type() == QPaintEngine.Raster:
                    useCache = True
                else:
                    if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine,
                                             QwtSymbol.VLine, QwtSymbol.Cross):
                        pass
                    elif self.__data.style == QwtSymbol.Pixmap:
                        if not self.__data.size.isEmpty() and\
                           self.__data.size != self.__data.pixmap.pixmap.size():
                            useCache = True
                    else:
                        useCache = True
        if useCache:
            br = QRect(self.boundingRect())
            rect = QRect(0, 0, br.width(), br.height())
            if self.__data.cache.pixmap.isNull():
                self.__data.cache.pixmap = QwtPainter.backingStore(
                    None, br.size())
                self.__data.cache.pixmap.fill(Qt.transparent)
                p = QPainter(self.__data.cache.pixmap)
                p.setRenderHints(painter.renderHints())
                p.translate(-br.topLeft())
                pos = QPointF()
                self.renderSymbols(p, pos, 1)
            dx = br.left()
            dy = br.top()
            for point in points:
                left = round(point.x()) + dx
                top = round(point.y()) + dy
                painter.drawPixmap(left, top, self.__data.cache.pixmap)
        else:
            painter.save()
            self.renderSymbols(painter, points, numPoints)
            painter.restore()
Exemplo n.º 4
0
    def drawSymbols(self, painter, points, numPoints=None):
        """
        Render an array of symbols

        Painting several symbols is more effective than drawing symbols
        one by one, as a couple of layout calculations and setting of pen/brush
        can be done once for the complete array.

        :param QPainter painter: Painter
        :param QPolygonF points: Positions of the symbols in screen coordinates
        """
        #TODO: remove argument numPoints (not necessary in `PythonQwt`)
        if numPoints is not None and numPoints <= 0:
            return
        useCache = False
        if QwtPainter.roundingAlignment(painter) and\
           not painter.transform().isScaling():
            if self.__data.cache.policy == QwtSymbol.Cache:
                useCache = True
            elif self.__data.cache.policy == QwtSymbol.AutoCache:
                if painter.paintEngine().type() == QPaintEngine.Raster:
                    useCache = True
                else:
                    if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine,
                                             QwtSymbol.VLine, QwtSymbol.Cross):
                        pass
                    elif self.__data.style == QwtSymbol.Pixmap:
                        if not self.__data.size.isEmpty() and\
                           self.__data.size != self.__data.pixmap.pixmap.size():
                            useCache = True
                    else:
                        useCache = True
        if useCache:
            br = QRect(self.boundingRect())
            rect = QRect(0, 0, br.width(), br.height())
            if self.__data.cache.pixmap.isNull():
                self.__data.cache.pixmap = QwtPainter.backingStore(None, br.size())
                self.__data.cache.pixmap.fill(Qt.transparent)
                p = QPainter(self.__data.cache.pixmap)
                p.setRenderHints(painter.renderHints())
                p.translate(-br.topLeft())
                pos = QPointF()
                self.renderSymbols(p, pos, 1)
            dx = br.left()
            dy = br.top()
            for point in points:
                left = round(point.x())+dx
                top = round(point.y())+dy
                painter.drawPixmap(left, top, self.__data.cache.pixmap)
        else:
            painter.save()
            self.renderSymbols(painter, points, numPoints)
            painter.restore()
Exemplo n.º 5
0
    def draw(self, painter, xMap, yMap, rect):
        margin = 5
        pieRect = QRect()
        pieRect.setX(rect.x() + margin)
        pieRect.setY(rect.y() + margin)
        pieRect.setHeight(yMap.transform(80.0))
        pieRect.setWidth(pieRect.height())

        angle = 3 * 5760 / 4
        for key in ["User", "System", "Idle"]:
            curve = self.plot().cpuPlotCurve(key)
            if curve.dataSize():
                value = int(5760 * curve.sample(0).y() / 100.0)
                painter.save()
                painter.setBrush(QBrush(curve.pen().color(), Qt.SolidPattern))
                painter.drawPie(pieRect, -angle, -value)
                painter.restore()
                angle += value
Exemplo n.º 6
0
 def drawSymbols(self, painter, points, numPoints=None):
     #TODO: remove argument numPoints (not necessary in Python's qwt)
     if numPoints is not None and numPoints <= 0:
         return
     useCache = False
     if QwtPainter.roundingAlignment(painter) and\
        not painter.transform().isScaling():
         if self.__data.cache.policy == QwtSymbol.Cache:
             useCache = True
         elif self.__data.cache.policy == QwtSymbol.AutoCache:
             if painter.paintEngine().type() == QPaintEngine.Raster:
                 useCache = True
             else:
                 if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine,
                                          QwtSymbol.VLine, QwtSymbol.Cross):
                     pass
                 elif self.__data.style == QwtSymbol.Pixmap:
                     if not self.__data.size.isEmpty() and\
                        self.__data.size != self.__data.pixmap.pixmap.size():
                         useCache = True
                 else:
                     useCache = True
     if useCache:
         br = QRect(self.boundingRect())
         rect = QRect(0, 0, br.width(), br.height())
         if self.__data.cache.pixmap.isNull():
             self.__data.cache.pixmap = QwtPainter.backingStore(None, br.size())
             self.__data.cache.pixmap.fill(Qt.transparent)
             p = QPainter(self.__data.cache.pixmap)
             p.setRenderHints(painter.renderHints())
             p.translate(-br.topLeft())
             pos = QPointF()
             self.renderSymbols(p, pos, 1)
         dx = br.left()
         dy = br.top()
         for point in points:
             left = round(point.x())+dx
             top = round(point.y())+dy
             painter.drawPixmap(left, top, self.__data.cache.pixmap)
     else:
         painter.save()
         self.renderSymbols(painter, points, numPoints)
         painter.restore()
Exemplo n.º 7
0
    def draw(self, painter, xMap, yMap, rect):
        margin = 5
        pieRect = QRect()
        pieRect.setX(rect.x() + margin)
        pieRect.setY(rect.y() + margin)
        pieRect.setHeight(yMap.transform(80.0))
        pieRect.setWidth(pieRect.height())

        angle = 3*5760/4
        for key in ["User", "System", "Idle"]:
            curve = self.plot().cpuPlotCurve(key)
            if curve.dataSize():
                value = int(5760*curve.sample(0).y()/100.0)
                painter.save()
                painter.setBrush(QBrush(curve.pen().color(),
                                              Qt.SolidPattern))
                painter.drawPie(pieRect, -angle, -value)
                painter.restore()
                angle += value
Exemplo n.º 8
0
 def drawSymbol(self, painter, point_or_rect):
     if isinstance(point_or_rect, (QPointF, QPoint)):
         # drawSymbol( QPainter *, const QPointF & )
         self.drawSymbols(painter, [point_or_rect], 1)
         return
     # drawSymbol( QPainter *, const QRectF & )
     rect = point_or_rect
     assert isinstance(rect, QRectF)
     if self.__data.style == QwtSymbol.NoSymbol:
         return
     if self.__data.style == QwtSymbol.Graphic:
         self.__data.graphic.graphic.render(painter, rect,
                                            Qt.KeepAspectRatio)
     elif self.__data.style == QwtSymbol.Path:
         if self.__data.path.graphic.isNull():
             self.__data.path.graphic = qwtPathGraphic(
                 self.__data.path.path, self.__data.pen, self.__data.brush)
         self.__data.path.graphic.render(painter, rect, Qt.KeepAspectRatio)
         return
     elif self.__data.style == QwtSymbol.SvgDocument:
         if self.__data.svg.renderer is not None:
             scaledRect = QRectF()
             sz = QSizeF(self.__data.svg.renderer.viewBoxF().size())
             if not sz.isEmpty():
                 sz.scale(rect.size(), Qt.KeepAspectRatio)
                 scaledRect.setSize(sz)
                 scaledRect.moveCenter(rect.center())
             else:
                 scaledRect = rect
             self.__data.svg.renderer.render(painter, scaledRect)
     else:
         br = QRect(self.boundingRect())
         ratio = min([rect.width()/br.width(), rect.height()/br.height()])
         painter.save()
         painter.translate(rect.center())
         painter.scale(ratio, ratio)
         isPinPointEnabled = self.__data.isPinPointEnabled
         self.__data.isPinPointEnabled = False
         pos = QPointF()
         self.renderSymbols(painter, pos, 1)
         self.__data.isPinPointEnabled = isPinPointEnabled
         painter.restore()