def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the marker on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5*size.height() painter.drawLine(0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5*size.width() painter.drawLine(x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation, rect): colorTable = [] if colorMap.format() == QwtColorMap.Indexed: colorTable = colorMap.colorTable(interval) c = QColor() devRect = rect.toAlignedRect() pixmap = QPixmap(devRect.size()) pixmap.fill(Qt.transparent) pmPainter = QPainter(pixmap) pmPainter.translate(-devRect.x(), -devRect.y()) if orientation == Qt.Horizontal: sMap = scaleMap sMap.setPaintInterval(rect.left(), rect.right()) for x in range(devRect.left(), devRect.right() + 1): value = sMap.invTransform(x) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(x, devRect.top(), devRect.bottom()) else: sMap = scaleMap sMap.setPaintInterval(rect.bottom(), rect.top()) for y in range(devRect.top(), devRect.bottom() + 1): value = sMap.invTransform(y) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(devRect.left(), y, devRect.right(), y) pmPainter.end() self.drawPixmap(painter, rect, pixmap)
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5*size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the marker on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5 * size.height() painter.drawLine(0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5 * size.width() painter.drawLine(x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style( ) == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5 * size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation, rect): colorTable = [] if colorMap.format() == QwtColorMap.Indexed: colorTable = colorMap.colorTable(interval) c = QColor() devRect = rect.toAlignedRect() pixmap = QPixmap(devRect.size()) pixmap.fill(Qt.transparent) pmPainter = QPainter(pixmap) pmPainter.translate(-devRect.x(), -devRect.y()) if orientation == Qt.Horizontal: sMap = scaleMap sMap.setPaintInterval(rect.left(), rect.right()) for x in range(devRect.left(), devRect.right()+1): value = sMap.invTransform(x) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(x, devRect.top(), devRect.bottom()) else: sMap = scaleMap sMap.setPaintInterval(rect.bottom(), rect.top()) for y in range(devRect.top(), devRect.bottom()+1): value = sMap.invTransform(y) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(devRect.left(), y, devRect.right(), y) pmPainter.end() self.drawPixmap(painter, rect, pixmap)
def qwtPathGraphic(path, pen, brush): graphic = QwtGraphic() graphic.setRenderHint(QwtGraphic.RenderPensUnscaled) painter = QPainter(graphic) painter.setPen(pen) painter.setBrush(brush) painter.drawPath(path) painter.end() return graphic
def toImage(self, xMap, yMap, series, from_, to, pen, antialiased, numThreads): if USE_THREADS: if numThreads == 0: numThreads = QThread.idealThreadCount() if numThreads <= 0: numThreads = 1 rect = self.__data.boundingRect.toAlignedRect() image = QImage(rect.size(), QImage.Format_ARGB32) image.fill(Qt.transparent) if pen.width() <= 1 and pen.color().alpha() == 255: command = QwtDotsCommand() command.series = series command.rgb = pen.color().rgba() if USE_THREADS: numPoints = int((to - from_ + 1) / numThreads) futures = [] for i in range(numThreads): pos = rect.topLeft() index0 = from_ + i * numPoints if i == numThreads - 1: command.from_ = index0 command.to = to qwtRenderDots(xMap, yMap, command, pos, image) else: command.from_ = index0 command.to = index0 + numPoints - 1 futures += [ QtConcurrent.run(qwtRenderDots, xMap, yMap, command, pos, image) ] for future in futures: future.waitForFinished() else: command.from_ = from_ command.to = to qwtRenderDots(xMap, yMap, command, rect.topLeft(), image) else: painter = QPainter(image) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, antialiased) chunkSize = 1000 for i in range(chunkSize): indexTo = min([i + chunkSize - 1, to]) points = self.toPoints(xMap, yMap, series, i, indexTo) painter.drawPoints(points) return image
def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the curve on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style( ) == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5 * size.height() painter.drawLine(0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation, rect): """ Draw a color bar into a rectangle :param QPainter painter: Painter :param qwt.color_map.QwtColorMap colorMap: Color map :param qwt.interval.QwtInterval interval: Value range :param qwt.scalemap.QwtScaleMap scaleMap: Scale map :param Qt.Orientation orientation: Orientation :param QRectF rect: Target rectangle """ colorTable = [] if colorMap.format() == QwtColorMap.Indexed: colorTable = colorMap.colorTable(interval) c = QColor() devRect = rect.toAlignedRect() pixmap = QPixmap(devRect.size()) pixmap.fill(Qt.transparent) pmPainter = QPainter(pixmap) pmPainter.translate(-devRect.x(), -devRect.y()) if orientation == Qt.Horizontal: sMap = QwtScaleMap(scaleMap) sMap.setPaintInterval(rect.left(), rect.right()) for x in range(devRect.left(), devRect.right() + 1): value = sMap.invTransform(x) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(x, devRect.top(), x, devRect.bottom()) else: sMap = QwtScaleMap(scaleMap) sMap.setPaintInterval(rect.bottom(), rect.top()) for y in range(devRect.top(), devRect.bottom() + 1): value = sMap.invTransform(y) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(devRect.left(), y, devRect.right(), y) pmPainter.end() self.drawPixmap(painter, rect, pixmap)
def drawColorBar(self, painter, colorMap, interval, scaleMap, orientation, rect): """ Draw a color bar into a rectangle :param QPainter painter: Painter :param qwt.color_map.QwtColorMap colorMap: Color map :param qwt.interval.QwtInterval interval: Value range :param qwt.scalemap.QwtScaleMap scaleMap: Scale map :param Qt.Orientation orientation: Orientation :param QRectF rect: Target rectangle """ colorTable = [] if colorMap.format() == QwtColorMap.Indexed: colorTable = colorMap.colorTable(interval) c = QColor() devRect = rect.toAlignedRect() pixmap = QPixmap(devRect.size()) pixmap.fill(Qt.transparent) pmPainter = QPainter(pixmap) pmPainter.translate(-devRect.x(), -devRect.y()) if orientation == Qt.Horizontal: sMap = QwtScaleMap(scaleMap) sMap.setPaintInterval(rect.left(), rect.right()) for x in range(devRect.left(), devRect.right()+1): value = sMap.invTransform(x) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(x, devRect.top(), x, devRect.bottom()) else: sMap = QwtScaleMap(scaleMap) sMap.setPaintInterval(rect.bottom(), rect.top()) for y in range(devRect.top(), devRect.bottom()+1): value = sMap.invTransform(y) if colorMap.format() == QwtColorMap.RGB: c.setRgba(colorMap.rgb(interval, value)) else: c = colorTable[colorMap.colorIndex(interval, value)] pmPainter.setPen(c) pmPainter.drawLine(devRect.left(), y, devRect.right(), y) pmPainter.end() self.drawPixmap(painter, rect, pixmap)
def qwtDrawBackground(painter, canvas): painter.save() borderClip = canvas.borderPath(canvas.rect()) if not borderClip.isEmpty(): painter.setClipPath(borderClip, Qt.IntersectClip) brush = canvas.palette().brush(canvas.backgroundRole()) if brush.style() == Qt.TexturePattern: pm = QPixmap(canvas.size()) QwtPainter.fillPixmap(canvas, pm) painter.drawPixmap(0, 0, pm) elif brush.gradient(): rects = [] if brush.gradient().coordinateMode() == QGradient.ObjectBoundingMode: rects += [canvas.rect()] else: rects += [painter.clipRegion().rects()] useRaster = False if painter.paintEngine().type() == QPaintEngine.X11: useRaster = True if useRaster: format_ = QImage.Format_RGB32 stops = brush.gradient().stops() for stop in stops: if stop.second.alpha() != 255: format_ = QImage.Format_ARGB32 break image = QImage(canvas.size(), format_) p = QPainter(image) p.setPen(Qt.NoPen) p.setBrush(brush) p.drawRects(_rects_conv_PyQt5(rects)) p.end() painter.drawImage(0, 0, image) else: painter.setPen(Qt.NoPen) painter.setBrush(brush) painter.drawRects(_rects_conv_PyQt5(rects)) else: painter.setPen(Qt.NoPen) painter.setBrush(brush) painter.drawRects(_rects_conv_PyQt5(painter.clipRegion().rects())) painter.restore()
def legendIcon(self, index, size): """ :param int index: Index of the legend entry (ignored as there is only one) :param QSizeF size: Icon size :return: Icon representing the curve on the legend .. seealso:: :py:meth:`qwt.plot.QwtPlotItem.setLegendIconSize()`, :py:meth:`qwt.plot.QwtPlotItem.legendData()` """ if size.isEmpty(): return QwtGraphic() graphic = QwtGraphic() graphic.setDefaultSize(size) graphic.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(graphic) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.legendAttributes == 0 or\ (self.__data.legendAttributes & QwtPlotCurve.LegendShowBrush): brush = self.__data.brush if brush.style() == Qt.NoBrush and self.__data.legendAttributes == 0: if self.style() != QwtPlotCurve.NoCurve: brush = QBrush(self.pen().color()) elif self.__data.symbol and\ self.__data.symbol.style() != QwtSymbol.NoSymbol: brush = QBrush(self.__data.symbol.pen().color()) if brush.style() != Qt.NoBrush: r = QRectF(0, 0, size.width(), size.height()) painter.fillRect(r, brush) if self.__data.legendAttributes & QwtPlotCurve.LegendShowLine: if self.pen() != Qt.NoPen: pn = self.pen() # pn.setCapStyle(Qt.FlatCap) painter.setPen(pn) y = .5*size.height() painter.drawLine(0., y, size.width(), y) if self.__data.legendAttributes & QwtPlotCurve.LegendShowSymbol: if self.__data.symbol: r = QRectF(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return graphic
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint(QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5*size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5*size.width() QwtPainter.drawLine(painter, x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def toImage(self, xMap, yMap, series, from_, to, pen, antialiased): """ Translate a series into a QImage :param qwt.scale_map.QwtScaleMap xMap: x map :param qwt.scale_map.QwtScaleMap yMap: y map :param series: Series of points to be mapped :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted :param QPen pen: Pen used for drawing a point of the image, where a point is mapped to :param bool antialiased: True, when the dots should be displayed antialiased :return: Image displaying the series """ #TODO: rewrite this method to fix performance issue (litteral translation from C++!) rect = self.__data.boundingRect.toAlignedRect() image = QImage(rect.size(), QImage.Format_ARGB32) image.fill(Qt.transparent) if pen.width() <= 1 and pen.color().alpha() == 255: bits = image.bits() w = image.width() h = image.height() x0 = rect.topLeft().x() y0 = rect.topLeft().y() for i in range(from_, to+1): sample = series.sample(i) x = int(xMap.transform(sample.x())+0.5)-x0 y = int(yMap.transform(sample.y())+0.5)-y0 if x >= 0 and x < w and y >= 0 and y < h: bits[y*w+x] = pen.color().rgba() else: painter = QPainter(image) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, antialiased) chunkSize = 1000 for i in range(chunkSize): indexTo = min([i+chunkSize-1, to]) points = self.toPoints(xMap, yMap, series, i, indexTo) painter.drawPoints(points) return image
def legendIcon(self, index, size): if size.isEmpty(): return QwtGraphic() icon = QwtGraphic() icon.setDefaultSize(size) icon.setRenderHint(QwtGraphic.RenderPensUnscaled, True) painter = QPainter(icon) painter.setRenderHint( QPainter.Antialiasing, self.testRenderHint(QwtPlotItem.RenderAntialiased)) if self.__data.style != QwtPlotMarker.NoLine: painter.setPen(self.__data.pen) if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross): y = .5 * size.height() QwtPainter.drawLine(painter, 0., y, size.width(), y) if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross): x = .5 * size.width() QwtPainter.drawLine(painter, x, 0., x, size.height()) if self.__data.symbol: r = QRect(0, 0, size.width(), size.height()) self.__data.symbol.drawSymbol(painter, r) return icon
def toImage(self, xMap, yMap, series, from_, to, pen, antialiased): """ Translate a series into a QImage :param qwt.scale_map.QwtScaleMap xMap: x map :param qwt.scale_map.QwtScaleMap yMap: y map :param series: Series of points to be mapped :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted :param QPen pen: Pen used for drawing a point of the image, where a point is mapped to :param bool antialiased: True, when the dots should be displayed antialiased :return: Image displaying the series """ #TODO: rewrite this method to fix performance issue (litteral translation from C++!) rect = self.__data.boundingRect.toAlignedRect() image = QImage(rect.size(), QImage.Format_ARGB32) image.fill(Qt.transparent) if pen.width() <= 1 and pen.color().alpha() == 255: bits = image.bits() w = image.width() h = image.height() x0 = rect.topLeft().x() y0 = rect.topLeft().y() for i in range(from_, to + 1): sample = series.sample(i) x = int(xMap.transform(sample.x()) + 0.5) - x0 y = int(yMap.transform(sample.y()) + 0.5) - y0 if x >= 0 and x < w and y >= 0 and y < h: bits[y * w + x] = pen.color().rgba() else: painter = QPainter(image) painter.setPen(pen) painter.setRenderHint(QPainter.Antialiasing, antialiased) chunkSize = 1000 for i in range(chunkSize): indexTo = min([i + chunkSize - 1, to]) points = self.toPoints(xMap, yMap, series, i, indexTo) painter.drawPoints(points) return image