def renderLegend(self, painter, rect, fillBackground): """ Render the legend into a given rectangle. :param QPainter painter: Painter :param QRectF rect: Bounding rectangle :param bool fillBackground: When true, fill rect with the widget background """ if self.__data.itemMap.isEmpty(): return if fillBackground: if self.autoFillBackground() or self.testAttribute( Qt.WA_StyledBackground): QwtPainter.drawBackground(painter, rect, self) legendLayout = self.__data.view.contentsWidget.layout() if legendLayout is None: return left, right, top, bottom = self.getContentsMargins() layoutRect = QRect() layoutRect.setLeft(math.ceil(rect.left()) + left) layoutRect.setTop(math.ceil(rect.top()) + top) layoutRect.setRight(math.ceil(rect.right()) - right) layoutRect.setBottom(math.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()
def draw(self, painter, xMap, yMap, rect): c = QColor(Qt.white) r = QRect(rect) for i in range(100, 0, -10): r.setBottom(int(yMap.transform(i - 10))) r.setTop(int(yMap.transform(i))) painter.fillRect(r, c) c = c.darker(110)
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.0 if self.__data.pen.style() != Qt.NoPen: pw = max([self.__data.pen.widthF(), 1.0]) rect.setSize(self.__data.size + QSizeF(pw, pw)) rect.moveCenter(QPointF(0.0, 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.0 if self.__data.pen.style() != Qt.NoPen: pw = max([self.__data.pen.widthF(), 1.0]) rect.setSize(QSizeF(self.__data.size) + QSizeF(2 * pw, 2 * pw)) rect.moveCenter(QPointF(0.0, 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, 0.0)) if pinPointTranslation: pinPoint = QPointF(0.0, 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