Esempio n. 1
0
    def renderLegend(self, painter, rect, fillBackground):
        if self.__data.itemMap.isEmpty():
            return
        if fillBackground:
            if self.autoFillBackground() or\
               self.testAttribute(Qt.WA_StyledBackground):
                QwtPainter.drawBackground(painter, rect, self)
#    const QwtDynGridLayout *legendLayout =
#        qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
#TODO: not the exact same implementation
        legendLayout = self.__data.view.contentsWidget.layout()
        if legendLayout is None:
            return
        left, right, top, bottom = self.getContentsMargins()
        layoutRect = QRect()
        layoutRect.setLeft(np.ceil(rect.left()) + left)
        layoutRect.setTop(np.ceil(rect.top()) + top)
        layoutRect.setRight(np.ceil(rect.right()) - right)
        layoutRect.setBottom(np.ceil(rect.bottom()) - bottom)
        numCols = legendLayout.columnsForWidth(layoutRect.width())
        itemRects = legendLayout.layoutItems(layoutRect, numCols)
        index = 0
        for i in range(legendLayout.count()):
            item = legendLayout.itemAt(i)
            w = item.widget()
            if w is not None:
                painter.save()
                painter.setClipRect(itemRects[index], Qt.IntersectClip)
                self.renderItem(painter, w, itemRects[index], fillBackground)
                index += 1
                painter.restore()
Esempio n. 2
0
    def renderLegend(self, painter, rect, fillBackground):
        if self.__data.itemMap.isEmpty():
            return
        if fillBackground:
            if self.autoFillBackground() or\
               self.testAttribute(Qt.WA_StyledBackground):
                QwtPainter.drawBackground(painter, rect, self)
#    const QwtDynGridLayout *legendLayout = 
#        qobject_cast<QwtDynGridLayout *>( contentsWidget()->layout() );
        #TODO: not the exact same implementation
        legendLayout = self.__data.view.contentsWidget.layout()
        if legendLayout is None:
            return
        left, right, top, bottom = self.getContentsMargins()
        layoutRect = QRect()
        layoutRect.setLeft(np.ceil(rect.left())+left)
        layoutRect.setTop(np.ceil(rect.top())+top)
        layoutRect.setRight(np.ceil(rect.right())-right)
        layoutRect.setBottom(np.ceil(rect.bottom())-bottom)
        numCols = legendLayout.columnsForWidth(layoutRect.width())
        itemRects = legendLayout.layoutItems(layoutRect, numCols)
        index = 0
        for i in range(legendLayout.count()):
            item = legendLayout.itemAt(i)
            w = item.widget()
            if w is not None:
                painter.save()
                painter.setClipRect(itemRects[index], Qt.IntersectClip)
                self.renderItem(painter, w, itemRects[index], fillBackground)
                index += 1
                painter.restore()
Esempio n. 3
0
    def draw(self, painter, xMap, yMap, rect):
        c = QColor(Qt.white)
        r = QRect(rect)

        for i in range(100, 0, -10):
            r.setBottom(yMap.transform(i - 10))
            r.setTop(yMap.transform(i))
            painter.fillRect(r, c)
            c = c.darker(110)
Esempio n. 4
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
Esempio n. 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