def drawLines(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw lines :param QPainter painter: Painter :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates. :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates. :param QRectF canvasRect: Contents rectangle of the canvas :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point. .. seealso:: :py:meth:`draw()`, :py:meth:`drawDots()`, :py:meth:`drawSteps()`, :py:meth:`drawSticks()` """ if from_ > to: return doAlign = QwtPainter.roundingAlignment(painter) doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 clipRect = QRectF() if self.__data.paintAttributes & self.ClipPolygons: pw = max([1., painter.pen().widthF()]) clipRect = canvasRect.adjusted(-pw, -pw, pw, pw) doIntegers = False if QT_VERSION < 0x040800: if painter.paintEngine().type() == QPaintEngine.Raster: if not doFill: doIntegers = True noDuplicates = self.__data.paintAttributes & self.FilterPoints mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates) mapper.setBoundingRect(canvasRect) if doIntegers: polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to) if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(), polyline, False) QwtPainter.drawPolyline(painter, polyline) else: polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to) if doFill: if painter.pen().style() != Qt.NoPen: filled = QPolygonF(polyline) self.fillCurve(painter, xMap, yMap, canvasRect, filled) filled.clear() if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline) else: self.fillCurve(painter, xMap, yMap, canvasRect, polyline) else: if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline)
def drawPolygon(self, painter, polygon): deviceClipping, clipRect = qwtIsClippingNeeded(painter) cpa = polygon if deviceClipping: if isinstance(polygon, QPolygonF): cpa = QwtClipper().clipPolygonF(clipRect, polygon) else: cpa = QwtClipper().clipPolygon(clipRect, polygon) painter.drawPolygon(cpa)
def drawLines(self, painter, xMap, yMap, canvasRect, from_, to): if from_ > to: return doAlign = QwtPainter.roundingAlignment(painter) doFit = (self.__data.attributes & self.Fitted)\ and self.__data.curveFitter doFill = self.__data.brush.style() != Qt.NoBrush\ and self.__data.brush.color().alpha() > 0 clipRect = QRectF() if self.__data.paintAttributes & self.ClipPolygons: pw = max([1., painter.pen().widthF()]) clipRect = canvasRect.adjusted(-pw, -pw, pw, pw) doIntegers = False if QT_VERSION < 0x040800: if painter.paintEngine().type() == QPaintEngine.Raster: if not doFit and not doFill: doIntegers = True noDuplicates = self.__data.paintAttributes & self.FilterPoints mapper = QwtPointMapper() mapper.setFlag(QwtPointMapper.RoundPoints, doAlign) mapper.setFlag(QwtPointMapper.WeedOutPoints, noDuplicates) mapper.setBoundingRect(canvasRect) if doIntegers: polyline = mapper.toPolygon(xMap, yMap, self.data(), from_, to) if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygon(clipRect.toAlignedRect(), polyline, False) QwtPainter.drawPolyline(painter, polyline) else: polyline = mapper.toPolygonF(xMap, yMap, self.data(), from_, to) if doFit: polyline = self.__data.curveFitter.fitCurve(polyline) if doFill: if painter.pen().style() != Qt.NoPen: filled = QPolygonF(polyline) self.fillCurve(painter, xMap, yMap, canvasRect, filled) filled.clear() if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline) else: self.fillCurve(painter, xMap, yMap, canvasRect, polyline) else: if self.__data.paintAttributes & self.ClipPolygons: polyline = QwtClipper().clipPolygonF( clipRect, polyline, False) QwtPainter.drawPolyline(painter, polyline)
def fillCurve(self, painter, xMap, yMap, canvasRect, polygon): """ Fill the area between the curve and the baseline with the curve brush :param QPainter painter: Painter :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates. :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates. :param QRectF canvasRect: Contents rectangle of the canvas :param QPolygonF polygon: Polygon - will be modified ! .. seealso:: :py:meth:`setBrush()`, :py:meth:`setBaseline()`, :py:meth:`setStyle()` """ if self.__data.brush.style() == Qt.NoBrush: return self.closePolyline(painter, xMap, yMap, polygon) if polygon.count() <= 2: return brush = self.__data.brush if not brush.color().isValid(): brush.setColor(self.__data.pen.color()) if self.__data.paintAttributes & self.ClipPolygons: polygon = QwtClipper().clipPolygonF(canvasRect, polygon, True) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(brush) QwtPainter.drawPolygon(painter, polygon) painter.restore()
def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): doAlign = QwtPainter.roundingAlignment(painter) polygon = QPolygonF(2 * (to - from_) + 1) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 for i in range(from_, to + 1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if doAlign: xi = round(xi) yi = round(yi) if ip > 0: p0 = polygon[ip - 2] if inverted: polygon[ip - 1] = QPointF(p0.x(), yi) else: polygon[ip - 1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 if self.__data.paintAttributes & self.ClipPolygons: clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False) QwtPainter.drawPolyline(painter, clipped) else: QwtPainter.drawPolyline(painter, polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)
def drawPolyline(self, *args): if len(args) == 2: painter, polygon = args deviceClipping, clipRect = qwtIsClippingNeeded(painter) cpa = polygon if deviceClipping: if isinstance(polygon, QPolygonF): cpa = QwtClipper().clipPolygonF(clipRect, polygon) else: cpa = QwtClipper().clipPolygon(clipRect, polygon) qwtDrawPolyline(painter, cpa, cpa.size(), self.__polylineSplitting) elif len(args) == 3: painter, points, pointCount = args deviceClipping, clipRect = qwtIsClippingNeeded(painter) if deviceClipping: if isinstance(points[0], QPointF): polygon = QPolygonF(points) polygon = QwtClipper().clipPolygonF(clipRect, polygon) else: polygon = QPolygon(points) polygon = QwtClipper().clipPolygon(clipRect, polygon) qwtDrawPolyline(painter, polygon, polygon.size(), self.__polylineSplitting) # polygon = QPolygonF(pointCount) # pointer = polygon.data() # pointer.setsize(pointCount*2*np.finfo(float).dtype.itemsize) # memory = np.frombuffer(pointer, float) # memory[0::2] = xdata # memory[1::2] = ydata else: qwtDrawPolyline(painter, points, pointCount, self.__polylineSplitting) else: raise TypeError("QwtPainter.drawPolyline() takes 2 or 3 argument"\ "(s) (%s given)" % len(args))
def fillCurve(self, painter, xMap, yMap, canvasRect, polygon): if self.__data.brush.style() == Qt.NoBrush: return self.closePolyline(painter, xMap, yMap, polygon) if polygon.count() <= 2: return brush = self.__data.brush if not brush.color().isValid(): brush.setColor(self.__data.pen.color()) if self.__data.paintAttributes & self.ClipPolygons: polygon = QwtClipper().clipPolygonF(canvasRect, polygon, True) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(brush) QwtPainter.drawPolygon(painter, polygon) painter.restore()
def drawSteps(self, painter, xMap, yMap, canvasRect, from_, to): """ Draw steps :param QPainter painter: Painter :param qwt.scale_map.QwtScaleMap xMap: Maps x-values into pixel coordinates. :param qwt.scale_map.QwtScaleMap yMap: Maps y-values into pixel coordinates. :param QRectF canvasRect: Contents rectangle of the canvas :param int from_: Index of the first point to be painted :param int to: Index of the last point to be painted. If to < 0 the curve will be painted to its last point. .. seealso:: :py:meth:`draw()`, :py:meth:`drawSticks()`, :py:meth:`drawDots()`, :py:meth:`drawLines()` """ doAlign = QwtPainter.roundingAlignment(painter) polygon = QPolygonF(2 * (to - from_) + 1) inverted = self.orientation() == Qt.Vertical if self.__data.attributes & self.Inverted: inverted = not inverted series = self.data() ip = 0 for i in range(from_, to + 1): sample = series.sample(i) xi = xMap.transform(sample.x()) yi = yMap.transform(sample.y()) if doAlign: xi = round(xi) yi = round(yi) if ip > 0: p0 = polygon[ip - 2] if inverted: polygon[ip - 1] = QPointF(p0.x(), yi) else: polygon[ip - 1] = QPointF(xi, p0.y()) polygon[ip] = QPointF(xi, yi) ip += 2 if self.__data.paintAttributes & self.ClipPolygons: clipped = QwtClipper().clipPolygonF(canvasRect, polygon, False) QwtPainter.drawPolyline(painter, clipped) else: QwtPainter.drawPolyline(painter, polygon) if self.__data.brush.style() != Qt.NoBrush: self.fillCurve(painter, xMap, yMap, canvasRect, polygon)