Example #1
0
def qwtDrawSvgSymbols(painter, points, numPoints, renderer, symbol):
    if renderer is None or not renderer.isValid():
        return
    viewBox = QRectF(renderer.viewBoxF())
    if viewBox.isEmpty():
        return
    sz = QSizeF(symbol.size())
    if not sz.isValid():
        sz = viewBox.size()
    sx = sz.width()/viewBox.width()
    sy = sz.height()/viewBox.height()
    pinPoint = QPointF(viewBox.center())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    dx = sx*(pinPoint.x()-viewBox.left())
    dy = sy*(pinPoint.y()-viewBox.top())
    for pos in points:
        x = pos.x()-dx
        y = pos.y()-dy
        renderer.render(painter, QRectF(x, y, sz.width(), sz.height()))
Example #2
0
def qwtDrawSvgSymbols(painter, points, numPoints, renderer, symbol):
    if renderer is None or not renderer.isValid():
        return
    viewBox = QRectF(renderer.viewBoxF())
    if viewBox.isEmpty():
        return
    sz = QSizeF(symbol.size())
    if not sz.isValid():
        sz = viewBox.size()
    sx = sz.width() / viewBox.width()
    sy = sz.height() / viewBox.height()
    pinPoint = QPointF(viewBox.center())
    if symbol.isPinPointEnabled():
        pinPoint = symbol.pinPoint()
    dx = sx * (pinPoint.x() - viewBox.left())
    dy = sy * (pinPoint.y() - viewBox.top())
    for pos in points:
        x = pos.x() - dx
        y = pos.y() - dy
        renderer.render(painter, QRectF(x, y, sz.width(), sz.height()))
Example #3
0
 def drawLabel(self, painter, canvasRect, pos):
     if self.__data.label.isEmpty():
         return
     align = Qt.Alignment(self.__data.labelAlignment)
     alignPos = QPointF(pos)
     symbolOff = QSizeF(0, 0)
     if self.__data.style == QwtPlotMarker.VLine:
         if bool(self.__data.labelAlignment & Qt.AlignTop):
             alignPos.setY(canvasRect.top())
             align &= ~Qt.AlignTop
             align |= Qt.AlignBottom
         elif bool(self.__data.labelAlignment & Qt.AlignBottom):
             alignPos.setY(canvasRect.bottom() - 1)
             align &= ~Qt.AlignBottom
             align |= Qt.AlignTop
         else:
             alignPos.setY(canvasRect.center().y())
     elif self.__data.style == QwtPlotMarker.HLine:
         if bool(self.__data.labelAlignment & Qt.AlignLeft):
             alignPos.setX(canvasRect.left())
             align &= ~Qt.AlignLeft
             align |= Qt.AlignRight
         elif bool(self.__data.labelAlignment & Qt.AlignRight):
             alignPos.setX(canvasRect.right() - 1)
             align &= ~Qt.AlignRight
             align |= Qt.AlignLeft
         else:
             alignPos.setX(canvasRect.center().x())
     else:
         if self.__data.symbol and\
            self.__data.symbol.style() != QwtSymbol.NoSymbol:
             symbolOff = self.__data.symbol.size() + QSizeF(1, 1)
             symbolOff /= 2
     pw2 = self.__data.pen.widthF() / 2.
     if pw2 == 0.:
         pw2 = .5
     spacing = self.__data.spacing
     xOff = max([pw2, symbolOff.width()])
     yOff = max([pw2, symbolOff.height()])
     textSize = self.__data.label.textSize(painter.font())
     if align & Qt.AlignLeft:
         alignPos.setX(alignPos.x() - (xOff + spacing))
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x() - textSize.height())
         else:
             alignPos.setX(alignPos.x() - textSize.width())
     elif align & Qt.AlignRight:
         alignPos.setX(alignPos.x() + xOff + spacing)
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x() - textSize.height() / 2)
         else:
             alignPos.setX(alignPos.x() - textSize.width() / 2)
     if align & Qt.AlignTop:
         alignPos.setY(alignPos.y() - (yOff + spacing))
         if self.__data.labelOrientation != Qt.Vertical:
             alignPos.setY(alignPos.y() - textSize.height())
     elif align & Qt.AlignBottom:
         alignPos.setY(alignPos.y() + yOff + spacing)
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y() + textSize.width())
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y() + textSize.width() / 2)
         else:
             alignPos.setY(alignPos.y() - textSize.height() / 2)
     painter.translate(alignPos.x(), alignPos.y())
     if self.__data.labelOrientation == Qt.Vertical:
         painter.rotate(-90.)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)
Example #4
0
 def drawLabel(self, painter, canvasRect, pos):
     """
     Align and draw the text label of the marker
     
     :param QPainter painter: Painter
     :param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
     :param QPointF pos: Position of the marker, translated into widget coordinates
     
     .. seealso::
     
         :py:meth:`drawLabel()`, 
         :py:meth:`qwt.symbol.QwtSymbol.drawSymbol()`
     """
     if self.__data.label.isEmpty():
         return
     align = Qt.Alignment(self.__data.labelAlignment)
     alignPos = QPointF(pos)
     symbolOff = QSizeF(0, 0)
     if self.__data.style == QwtPlotMarker.VLine:
         #  In VLine-style the y-position is pointless and
         #  the alignment flags are relative to the canvas
         if bool(self.__data.labelAlignment & Qt.AlignTop):
             alignPos.setY(canvasRect.top())
             align &= ~Qt.AlignTop
             align |= Qt.AlignBottom
         elif bool(self.__data.labelAlignment & Qt.AlignBottom):
             #  In HLine-style the x-position is pointless and
             #  the alignment flags are relative to the canvas
             alignPos.setY(canvasRect.bottom()-1)
             align &= ~Qt.AlignBottom
             align |= Qt.AlignTop
         else:
             alignPos.setY(canvasRect.center().y())
     elif self.__data.style == QwtPlotMarker.HLine:
         if bool(self.__data.labelAlignment & Qt.AlignLeft):
             alignPos.setX(canvasRect.left())
             align &= ~Qt.AlignLeft
             align |= Qt.AlignRight
         elif bool(self.__data.labelAlignment & Qt.AlignRight):
             alignPos.setX(canvasRect.right()-1)
             align &= ~Qt.AlignRight
             align |= Qt.AlignLeft
         else:
             alignPos.setX(canvasRect.center().x())
     else:
         if self.__data.symbol and\
            self.__data.symbol.style() != QwtSymbol.NoSymbol:
             symbolOff = self.__data.symbol.size()+QSizeF(1, 1)
             symbolOff /= 2
     pw2 = self.__data.pen.widthF()/2.
     if pw2 == 0.:
         pw2 = .5
     spacing = self.__data.spacing
     xOff = max([pw2, symbolOff.width()])
     yOff = max([pw2, symbolOff.height()])
     textSize = self.__data.label.textSize(painter.font())
     if align & Qt.AlignLeft:
         alignPos.setX(alignPos.x()-(xOff+spacing))
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x()-textSize.height())
         else:
             alignPos.setX(alignPos.x()-textSize.width())
     elif align & Qt.AlignRight:
         alignPos.setX(alignPos.x()+xOff+spacing)
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x()-textSize.height()/2)
         else:
             alignPos.setX(alignPos.x()-textSize.width()/2)
     if align & Qt.AlignTop:
         alignPos.setY(alignPos.y()-(yOff+spacing))
         if self.__data.labelOrientation != Qt.Vertical:
             alignPos.setY(alignPos.y()-textSize.height())
     elif align & Qt.AlignBottom:
         alignPos.setY(alignPos.y()+yOff+spacing)
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y()+textSize.width())
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y()+textSize.width()/2)
         else:
             alignPos.setY(alignPos.y()-textSize.height()/2)
     painter.translate(alignPos.x(), alignPos.y())
     if self.__data.labelOrientation == Qt.Vertical:
         painter.rotate(-90.)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)
Example #5
0
    def boundingRect(self):
        """
        Calculate the bounding rectangle for a symbol at position (0,0).

        :return: Bounding rectangle
        """
        rect = QRectF()
        pinPointTranslation = False
        if self.__data.style in (QwtSymbol.Ellipse, QwtSymbol.Rect,
                                 QwtSymbol.Hexagon):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(self.__data.size+QSizeF(pw, pw))
            rect.moveCenter(QPointF(0., 0.))
        elif self.__data.style in (QwtSymbol.XCross, QwtSymbol.Diamond,
                                   QwtSymbol.Triangle, QwtSymbol.UTriangle,
                                   QwtSymbol.DTriangle, QwtSymbol.RTriangle,
                                   QwtSymbol.LTriangle, QwtSymbol.Star1,
                                   QwtSymbol.Star2):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(QSizeF(self.__data.size)+QSizeF(2*pw, 2*pw))
            rect.moveCenter(QPointF(0., 0.))
        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)
            rect = qwtScaleBoundingRect(self.__data.path.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Pixmap:
            if self.__data.size.isEmpty():
                rect.setSize(self.__data.pixmap.pixmap.size())
            else:
                rect.setSize(self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Graphic:
            rect = qwtScaleBoundingRect(self.__data.graphic.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.SvgDocument:
            if self.__data.svg.renderer is not None:
                rect = self.__data.svg.renderer.viewBoxF()
            if self.__data.size.isValid() and not rect.isEmpty():
                sz = QSizeF(rect.size())
                sx = self.__data.size.width()/sz.width()
                sy = self.__data.size.height()/sz.height()
                transform = QTransform()
                transform.scale(sx, sy)
                rect = transform.mapRect(rect)
            pinPointTranslation = True
        else:
            rect.setSize(self.__data.size)
            rect.moveCenter(QPointF(0., 0.))
        if pinPointTranslation:
            pinPoint = QPointF(0., 0.)
            if self.__data.isPinPointEnabled:
                pinPoint = rect.center()-self.__data.pinPoint
            rect.moveCenter(pinPoint)
        r = QRect()
        r.setLeft(np.floor(rect.left()))
        r.setTop(np.floor(rect.top()))
        r.setRight(np.floor(rect.right()))
        r.setBottom(np.floor(rect.bottom()))
        if self.__data.style != QwtSymbol.Pixmap:
            r.adjust(-1, -1, 1, 1)
        return r
Example #6
0
    def boundingRect(self):
        """
        Calculate the bounding rectangle for a symbol at position (0,0).

        :return: Bounding rectangle
        """
        rect = QRectF()
        pinPointTranslation = False
        if self.__data.style in (QwtSymbol.Ellipse, QwtSymbol.Rect,
                                 QwtSymbol.Hexagon):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(self.__data.size + QSizeF(pw, pw))
            rect.moveCenter(QPointF(0., 0.))
        elif self.__data.style in (QwtSymbol.XCross, QwtSymbol.Diamond,
                                   QwtSymbol.Triangle, QwtSymbol.UTriangle,
                                   QwtSymbol.DTriangle, QwtSymbol.RTriangle,
                                   QwtSymbol.LTriangle, QwtSymbol.Star1,
                                   QwtSymbol.Star2):
            pw = 0.
            if self.__data.pen.style() != Qt.NoPen:
                pw = max([self.__data.pen.widthF(), 1.])
            rect.setSize(QSizeF(self.__data.size) + QSizeF(2 * pw, 2 * pw))
            rect.moveCenter(QPointF(0., 0.))
        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)
            rect = qwtScaleBoundingRect(self.__data.path.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Pixmap:
            if self.__data.size.isEmpty():
                rect.setSize(self.__data.pixmap.pixmap.size())
            else:
                rect.setSize(self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.Graphic:
            rect = qwtScaleBoundingRect(self.__data.graphic.graphic,
                                        self.__data.size)
            pinPointTranslation = True
        elif self.__data.style == QwtSymbol.SvgDocument:
            if self.__data.svg.renderer is not None:
                rect = self.__data.svg.renderer.viewBoxF()
            if self.__data.size.isValid() and not rect.isEmpty():
                sz = QSizeF(rect.size())
                sx = self.__data.size.width() / sz.width()
                sy = self.__data.size.height() / sz.height()
                transform = QTransform()
                transform.scale(sx, sy)
                rect = transform.mapRect(rect)
            pinPointTranslation = True
        else:
            rect.setSize(self.__data.size)
            rect.moveCenter(QPointF(0., 0.))
        if pinPointTranslation:
            pinPoint = QPointF(0., 0.)
            if self.__data.isPinPointEnabled:
                pinPoint = rect.center() - self.__data.pinPoint
            rect.moveCenter(pinPoint)
        r = QRect()
        r.setLeft(np.floor(rect.left()))
        r.setTop(np.floor(rect.top()))
        r.setRight(np.floor(rect.right()))
        r.setBottom(np.floor(rect.bottom()))
        if self.__data.style != QwtSymbol.Pixmap:
            r.adjust(-1, -1, 1, 1)
        return r
Example #7
0
 def drawLabel(self, painter, canvasRect, pos):
     if self.__data.label.isEmpty():
         return
     align = Qt.Alignment(self.__data.labelAlignment)
     alignPos = QPointF(pos)
     symbolOff = QSizeF(0, 0)
     if self.__data.style == QwtPlotMarker.VLine:
         if bool(self.__data.labelAlignment & Qt.AlignTop):
             alignPos.setY(canvasRect.top())
             align &= ~Qt.AlignTop
             align |= Qt.AlignBottom
         elif bool(self.__data.labelAlignment & Qt.AlignBottom):
             alignPos.setY(canvasRect.bottom()-1)
             align &= ~Qt.AlignBottom
             align |= Qt.AlignTop
         else:
             alignPos.setY(canvasRect.center().y())
     elif self.__data.style == QwtPlotMarker.HLine:
         if bool(self.__data.labelAlignment & Qt.AlignLeft):
             alignPos.setX(canvasRect.left())
             align &= ~Qt.AlignLeft
             align |= Qt.AlignRight
         elif bool(self.__data.labelAlignment & Qt.AlignRight):
             alignPos.setX(canvasRect.right()-1)
             align &= ~Qt.AlignRight
             align |= Qt.AlignLeft
         else:
             alignPos.setX(canvasRect.center().x())
     else:
         if self.__data.symbol and\
            self.__data.symbol.style() != QwtSymbol.NoSymbol:
             symbolOff = self.__data.symbol.size()+QSizeF(1, 1)
             symbolOff /= 2
     pw2 = self.__data.pen.widthF()/2.
     if pw2 == 0.:
         pw2 = .5
     spacing = self.__data.spacing
     xOff = max([pw2, symbolOff.width()])
     yOff = max([pw2, symbolOff.height()])
     textSize = self.__data.label.textSize(painter.font())
     if align & Qt.AlignLeft:
         alignPos.setX(alignPos.x()-(xOff+spacing))
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x()-textSize.height())
         else:
             alignPos.setX(alignPos.x()-textSize.width())
     elif align & Qt.AlignRight:
         alignPos.setX(alignPos.x()+xOff+spacing)
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x()-textSize.height()/2)
         else:
             alignPos.setX(alignPos.x()-textSize.width()/2)
     if align & Qt.AlignTop:
         alignPos.setY(alignPos.y()-(yOff+spacing))
         if self.__data.labelOrientation != Qt.Vertical:
             alignPos.setY(alignPos.y()-textSize.height())
     elif align & Qt.AlignBottom:
         alignPos.setY(alignPos.y()+yOff+spacing)
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y()+textSize.width())
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y()+textSize.width()/2)
         else:
             alignPos.setY(alignPos.y()-textSize.height()/2)
     painter.translate(alignPos.x(), alignPos.y())
     if self.__data.labelOrientation == Qt.Vertical:
         painter.rotate(-90.)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)
Example #8
0
 def drawLabel(self, painter, canvasRect, pos):
     """
     Align and draw the text label of the marker
     
     :param QPainter painter: Painter
     :param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
     :param QPointF pos: Position of the marker, translated into widget coordinates
     
     .. seealso::
     
         :py:meth:`drawLabel()`, 
         :py:meth:`qwt.symbol.QwtSymbol.drawSymbol()`
     """
     if self.__data.label.isEmpty():
         return
     align = Qt.Alignment(self.__data.labelAlignment)
     alignPos = QPointF(pos)
     symbolOff = QSizeF(0, 0)
     if self.__data.style == QwtPlotMarker.VLine:
         #  In VLine-style the y-position is pointless and
         #  the alignment flags are relative to the canvas
         if bool(self.__data.labelAlignment & Qt.AlignTop):
             alignPos.setY(canvasRect.top())
             align &= ~Qt.AlignTop
             align |= Qt.AlignBottom
         elif bool(self.__data.labelAlignment & Qt.AlignBottom):
             #  In HLine-style the x-position is pointless and
             #  the alignment flags are relative to the canvas
             alignPos.setY(canvasRect.bottom() - 1)
             align &= ~Qt.AlignBottom
             align |= Qt.AlignTop
         else:
             alignPos.setY(canvasRect.center().y())
     elif self.__data.style == QwtPlotMarker.HLine:
         if bool(self.__data.labelAlignment & Qt.AlignLeft):
             alignPos.setX(canvasRect.left())
             align &= ~Qt.AlignLeft
             align |= Qt.AlignRight
         elif bool(self.__data.labelAlignment & Qt.AlignRight):
             alignPos.setX(canvasRect.right() - 1)
             align &= ~Qt.AlignRight
             align |= Qt.AlignLeft
         else:
             alignPos.setX(canvasRect.center().x())
     else:
         if self.__data.symbol and\
            self.__data.symbol.style() != QwtSymbol.NoSymbol:
             symbolOff = self.__data.symbol.size() + QSizeF(1, 1)
             symbolOff /= 2
     pw2 = self.__data.pen.widthF() / 2.
     if pw2 == 0.:
         pw2 = .5
     spacing = self.__data.spacing
     xOff = max([pw2, symbolOff.width()])
     yOff = max([pw2, symbolOff.height()])
     textSize = self.__data.label.textSize(painter.font())
     if align & Qt.AlignLeft:
         alignPos.setX(alignPos.x() - (xOff + spacing))
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x() - textSize.height())
         else:
             alignPos.setX(alignPos.x() - textSize.width())
     elif align & Qt.AlignRight:
         alignPos.setX(alignPos.x() + xOff + spacing)
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setX(alignPos.x() - textSize.height() / 2)
         else:
             alignPos.setX(alignPos.x() - textSize.width() / 2)
     if align & Qt.AlignTop:
         alignPos.setY(alignPos.y() - (yOff + spacing))
         if self.__data.labelOrientation != Qt.Vertical:
             alignPos.setY(alignPos.y() - textSize.height())
     elif align & Qt.AlignBottom:
         alignPos.setY(alignPos.y() + yOff + spacing)
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y() + textSize.width())
     else:
         if self.__data.labelOrientation == Qt.Vertical:
             alignPos.setY(alignPos.y() + textSize.width() / 2)
         else:
             alignPos.setY(alignPos.y() - textSize.height() / 2)
     painter.translate(alignPos.x(), alignPos.y())
     if self.__data.labelOrientation == Qt.Vertical:
         painter.rotate(-90.)
     textRect = QRectF(0, 0, textSize.width(), textSize.height())
     self.__data.label.draw(painter, textRect)