def qwtDrawDiamondSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) if QwtPainter.roundingAlignment(painter): for pos in points: x = round(pos.x()) y = round(pos.y()) x1 = x - size.width() // 2 y1 = y - size.height() // 2 x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(x, y1) polygon += QPointF(x1, y) polygon += QPointF(x, y2) polygon += QPointF(x2, y) QwtPainter.drawPolygon(painter, polygon) else: for pos in points: x1 = pos.x() - .5 * size.width() y1 = pos.y() - .5 * size.height() x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(pos.x(), y1) polygon += QPointF(x1, pos.y()) polygon += QPointF(pos.x(), y2) polygon += QPointF(x2, pos.y()) QwtPainter.drawPolygon(painter, polygon)
def fitParametric(self, points): size = points.size() fittedPoints = QPolygonF(self.__data.splineSize) splinePointsX = QPolygonF(size) splinePointsY = QPolygonF(size) # p = points.data() spX = splinePointsX#.data() spY = splinePointsY#.data() param = 0. for i in range(size): x = points[i].x() y = points[i].y() if i > 0: delta = np.sqrt((x-spX[i-1].y())**2+(y-spY[i-1].y())**2) param += max([delta, 1.]) spX[i] = QPointF(param, x) spY[i] = QPointF(param, y) self.__data.spline.setPoints(splinePointsX) if not self.__data.spline.isValid(): return points deltaX = splinePointsX[size-1].x()/(self.__data.splineSize-1) for i in range(self.__data.splineSize): dtmp = i*deltaX fittedPoints[i] = QPointF(self.__data.spline.value(dtmp), fittedPoints[i].y()) self.__data.spline.setPoints(splinePointsY) if not self.__data.spline.isValid(): return points deltaY = splinePointsY[size-1].x()/(self.__data.splineSize-1) for i in range(self.__data.splineSize): dtmp = i*deltaY fittedPoints[i] = QPointF(fittedPoints[i].x(), self.__data.spline.value(dtmp)) return fittedPoints
def qwtDrawPanel(painter, rect, pal, lw): if lw > 0.: if rect.width() == 0.: painter.setPen(pal.window().color()) painter.drawLine(rect.topLeft(), rect.bottomLeft()) return if rect.height() == 0.: painter.setPen(pal.window().color()) painter.drawLine(rect.topLeft(), rect.topRight()) return lw = min([lw, rect.height() / 2. - 1.]) lw = min([lw, rect.width() / 2. - 1.]) outerRect = rect.adjusted(0, 0, 1, 1) innerRect = outerRect.adjusted(lw, lw, -lw, -lw) lines = [QPolygonF(), QPolygonF()] lines[0] += outerRect.bottomLeft() lines[0] += outerRect.topLeft() lines[0] += outerRect.topRight() lines[0] += innerRect.topRight() lines[0] += innerRect.topLeft() lines[0] += innerRect.bottomLeft() lines[1] += outerRect.topRight() lines[1] += outerRect.bottomRight() lines[1] += outerRect.bottomLeft() lines[1] += innerRect.bottomLeft() lines[1] += innerRect.bottomRight() lines[1] += innerRect.topRight() painter.setPen(Qt.NoPen) painter.setBrush(pal.light()) painter.drawPolygon(lines[0]) painter.setBrush(pal.dark()) painter.drawPolygon(lines[1]) painter.fillRect(rect.adjusted(lw, lw, -lw + 1, -lw + 1), pal.window())
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 drawPoints(self, painter, points, pointCount): deviceClipping, clipRect = qwtIsClippingNeeded(painter) if isinstance(points[0], QPointF): if deviceClipping: clippedPolygon = QPolygonF(pointCount) clippedData = clippedPolygon.data() numClippedPoints = 0 for point in points: if clipRect.contains(point): clippedData[numClippedPoints] = point numClippedPoints += 1 painter.drawPoints(clippedData, numClippedPoints) else: painter.drawPoints(points, pointCount) else: if deviceClipping: minX = np.ceil(clipRect.left()) maxX = np.floor(clipRect.right()) minY = np.ceil(clipRect.top()) maxY = np.floor(clipRect.bottom()) r = QRect(minX, minY, maxX - minX, maxY - minY) clippedPolygon = QPolygon(pointCount) clippedData = clippedPolygon.data() numClippedPoints = 0 for point in points: if r.contains(point): clippedData[numClippedPoints] = point numClippedPoints += 1 painter.drawPoints(clippedData, numClippedPoints) else: painter.drawPoints(points, pointCount)
def drawLine(self, *args): if len(args) == 3: painter, p1, p2 = args if isinstance(p1, QPointF): p1 = p1.toPoint() if isinstance(p2, QPointF): p2 = p2.toPoint() deviceClipping, clipRect = qwtIsClippingNeeded(painter) if deviceClipping and not clipRect.contains(p1)\ and not clipRect.contains(p2): polygon = QPolygonF() polygon += p1 polygon += p2 self.drawPolyline(painter, polygon) return painter.drawLine(p1, p2) elif len(args) == 5: painter, x1, y1, x2, y2 = args self.drawLine(painter, QPointF(x1, y1), QPointF(x2, y2)) elif len(args) == 2: painter, line = args self.drawLine(painter, line.p1(), line.p2()) else: raise TypeError("QwtPainter.drawLine() takes 2, 3 or 5 argument"\ "(s) (%s given)" % len(args))
def qwtDrawHexagonSymbols(painter, points, numPoints, symbol): painter.setBrush(symbol.brush()) painter.setPen(symbol.pen()) cos30 = np.cos(30 * np.pi / 180.) dx = .5 * (symbol.size().width() - cos30) dy = .25 * symbol.size().height() for pos in points: x = pos.x() y = pos.y() x1 = x - dx y1 = y - 2 * dy x2 = x1 + 1 * dx x3 = x1 + 2 * dx y2 = y1 + 1 * dy y3 = y1 + 3 * dy y4 = y1 + 4 * dy hexa = [ QPointF(x2, y1), QPointF(x3, y2), QPointF(x3, y3), QPointF(x2, y4), QPointF(x1, y3), QPointF(x1, y2) ] painter.drawPolygon(QPolygonF(hexa))
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) doAlign = QwtPainter.roundingAlignment(painter) sw2 = .5 * size.width() sh2 = .5 * size.height() if doAlign: sw2 = np.floor(sw2) sh2 = np.floor(sh2) for pos in points: x = pos.x() y = pos.y() if doAlign: x = round(x) y = round(y) x1 = x - sw2 x2 = x1 + size.width() y1 = y - sh2 y2 = y1 + size.height() if type == QwtTriangle.Left: triangle = [QPointF(x2, y1), QPointF(x1, y), QPointF(x2, y2)] elif type == QwtTriangle.Right: triangle = [QPointF(x1, y1), QPointF(x2, y), QPointF(x1, y2)] elif type == QwtTriangle.Up: triangle = [QPointF(x1, y2), QPointF(x, y1), QPointF(x2, y2)] elif type == QwtTriangle.Down: triangle = [QPointF(x1, y1), QPointF(x, y2), QPointF(x2, y1)] QwtPainter.drawPolygon(painter, QPolygonF(triangle))
def qwtDrawHexagonSymbols(painter, points, numPoints, symbol): painter.setBrush(symbol.brush()) painter.setPen(symbol.pen()) cos30 = np.cos(30 * np.pi / 180.) dx = .5 * (symbol.size().width() - cos30) dy = .25 * symbol.size().height() doAlign = QwtPainter.roundingAlignment(painter) for pos in points: if doAlign: x = round(pos.x()) y = round(pos.y()) x1 = np.ceil(x - dx) y1 = np.ceil(y - 2 * dy) else: x = pos.x() y = pos.y() x1 = x - dx y1 = y - 2 * dy x2 = x1 + 1 * dx x3 = x1 + 2 * dx y2 = y1 + 1 * dy y3 = y1 + 3 * dy y4 = y1 + 4 * dy hexa = [ QPointF(x2, y1), QPointF(x3, y2), QPointF(x3, y3), QPointF(x2, y4), QPointF(x1, y3), QPointF(x1, y2) ] QwtPainter.drawPolygon(painter, QPolygonF(hexa))
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 fitCurve(self, points): fittedPoints = QPolygonF() if self.__data.chunkSize == 0: fittedPoints = self.simplify(points) else: for i in range(0, points.size(), self.__data.chunkSize): p = points.mid(i, self.__data.chunkSize) fittedPoints += self.simplify(p) return fittedPoints
def series_to_polyline(xMap, yMap, series, from_, to): """ Convert series data to QPolygon(F) polyline """ polyline = QPolygonF(to - from_ + 1) pointer = polyline.data() dtype, tinfo = np.float, np.finfo # integers: = np.int, np.iinfo pointer.setsize(2 * polyline.size() * tinfo(dtype).dtype.itemsize) memory = np.frombuffer(pointer, dtype) memory[:(to - from_) * 2 + 1:2] = xMap.transform(series.xData()[from_:to + 1]) memory[1:(to - from_) * 2 + 2:2] = yMap.transform(series.yData()[from_:to + 1]) return polyline
def qwtCombinePathList(rect, pathList): if not pathList: return QPainterPath() ordered = [None] * 8 for subPath in pathList: index = -1 br = subPath.controlPointRect() if br.center().x() < rect.center().x(): if br.center().y() < rect.center().y(): if abs(br.top() - rect.top()) < abs(br.left() - rect.left()): index = 1 else: index = 0 else: if abs(br.bottom() - rect.bottom) < abs(br.left() - rect.left()): index = 6 else: index = 7 if subPath.currentPosition().y() > br.center().y(): qwtRevertPath(subPath) else: if br.center().y() < rect.center().y(): if abs(br.top() - rect.top()) < abs(br.right() - rect.right()): index = 2 else: index = 3 else: if abs(br.bottom() - rect.bottom()) < abs(br.right() - rect.right()): index = 5 else: index = 4 if subPath.currentPosition().y() < br.center().y(): qwtRevertPath(subPath) ordered[index] = subPath for i in range(4): if ordered[2 * i].isEmpty() != ordered[2 * i + 1].isEmpty(): return QPainterPath() corners = QPolygonF(rect) path = QPainterPath() for i in range(4): if ordered[2 * i].isEmpty(): path.lineTo(corners[i]) else: path.connectPath(ordered[2 * i]) path.connectPath(ordered[2 * i + 1]) path.closeSubpath() return path
def fitSpline(self, points): self.__data.spline.setPoints(points) if not self.__data.spline.isValid(): return points fittedPoints = QPolygonF(self.__data.splineSize) x1 = points[0].x() x2 = points[int(points.size()-1)].x() dx = x2 - x1 delta = dx/(self.__data.splineSize()-1) for i in range(self.__data.splineSize): v = x1 + i*delta sv = self.__data.spline.value(v) fittedPoints[i] = QPointF(v, sv) self.__data.spline.reset() return fittedPoints
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 qwtDrawStar2Symbols(painter, points, numPoints, symbol): pen = QPen(symbol.pen()) if pen.width() > 1: pen.setCapStyle(Qt.FlatCap) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) cos30 = np.cos(30 * np.pi / 180.) dy = .25 * symbol.size().height() dx = .5 * symbol.size().width() * cos30 / 3. doAlign = QwtPainter.roundingAlignment(painter) for pos in points: if doAlign: x = round(pos.x()) y = round(pos.y()) x1 = round(x - 3 * dx) y1 = round(y - 2 * dy) else: x = pos.x() y = pos.y() x1 = x - 3 * dx y1 = y - 2 * dy x2 = x1 + 1 * dx x3 = x1 + 2 * dx x4 = x1 + 3 * dx x5 = x1 + 4 * dx x6 = x1 + 5 * dx x7 = x1 + 6 * dx y2 = y1 + 1 * dy y3 = y1 + 2 * dy y4 = y1 + 3 * dy y5 = y1 + 4 * dy star = [ QPointF(x4, y1), QPointF(x5, y2), QPointF(x7, y2), QPointF(x6, y3), QPointF(x7, y4), QPointF(x5, y4), QPointF(x4, y5), QPointF(x3, y4), QPointF(x1, y4), QPointF(x2, y3), QPointF(x1, y2), QPointF(x3, y2) ] QwtPainter.drawPolygon(painter, QPolygonF(star))
def qwtDrawDiamondSymbols(painter, points, numPoints, symbol): size = symbol.size() pen = QPen(symbol.pen()) pen.setJoinStyle(Qt.MiterJoin) painter.setPen(pen) painter.setBrush(symbol.brush()) for pos in points: x1 = pos.x() - .5 * size.width() y1 = pos.y() - .5 * size.height() x2 = x1 + size.width() y2 = y1 + size.height() polygon = QPolygonF() polygon += QPointF(pos.x(), y1) polygon += QPointF(x1, pos.y()) polygon += QPointF(pos.x(), y2) polygon += QPointF(x2, pos.y()) painter.drawPolygon(polygon)
def drawOutline(self, painter, xMap, yMap, from_, to): doAlign = QwtPainter.roundingAlignment(painter) if self.orientation() == Qt.Horizontal: v0 = xMap.transform(self.baseline()) else: v0 = yMap.transform(self.baseline()) if doAlign: v0 = round(v0) previous = QwtIntervalSample() polygon = QPolygonF() for i in range(from_, to + 1): sample = self.sample(i) if not sample.interval.isValid(): self.flushPolygon(painter, v0, polygon) previous = sample continue if previous.interval.isValid(): if not qwtIsCombinable(previous.interval, sample.interval): self.flushPolygon(painter, v0, polygon) if self.orientation() == Qt.Vertical: x1 = xMap.transform(sample.interval.minValue()) x2 = xMap.transform(sample.interval.maxValue()) y = yMap.transform(sample.value) if doAlign: x1 = round(x1) x2 = round(x2) y = round(y) if polygon.size() == 0: polygon += QPointF(x1, v0) polygon += QPointF(x1, y) polygon += QPointF(x2, y) else: y1 = yMap.transform(sample.interval.minValue()) y2 = yMap.transform(sample.interval.maxValue()) x = xMap.transform(sample.value) if doAlign: y1 = round(y1) y2 = round(y2) x = round(x) if polygon.size() == 0: polygon += QPointF(v0, y1) polygon += QPointF(x, y1) polygon += QPointF(x, y2) previous = sample self.flushPolygon(painter, v0, polygon)
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)
def simplify(self, points): Line = QwtWeedingCurveFitter_Line toleranceSqr = self.__data.tolerance*self.__data.tolerance stack = [] p = points.data() nPoints = points.size() usePoint = [False]*nPoints stack.insert(0, Line(0, nPoints-1)) while stack: r = stack.pop(0) vecX = p[r.to].x()-p[r.from_].x() vecY = p[r.to].y()-p[r.from_].y() vecLength = np.sqrt(vecX**2+vecY**2) unitVecX = vecX/vecLength if vecLength != 0. else 0. unitVecY = vecY/vecLength if vecLength != 0. else 0. maxDistSqr = 0. nVertexIndexMaxDistance = r.from_ + 1 for i in range(r.from_+1, r.to): fromVecX = p[i].x()-p[r.from_].x() fromVecY = p[i].y()-p[r.from_].y() if fromVecX * unitVecX + fromVecY * unitVecY < 0.0: distToSegmentSqr = fromVecX * fromVecX + fromVecY * fromVecY else: toVecX = p[i].x() - p[r.to].x() toVecY = p[i].y() - p[r.to].y() toVecLength = toVecX * toVecX + toVecY * toVecY s = toVecX * ( -unitVecX ) + toVecY * ( -unitVecY ) if s < 0.: distToSegmentSqr = toVecLength else: distToSegmentSqr = abs( toVecLength - s * s ) if maxDistSqr < distToSegmentSqr: maxDistSqr = distToSegmentSqr nVertexIndexMaxDistance = i if maxDistSqr <= toleranceSqr: usePoint[r.from_] = True usePoint[r.to] = True else: stack.insert(0, Line( r.from_, nVertexIndexMaxDistance )) stack.insert(0, Line( nVertexIndexMaxDistance, r.to )) stripped = QPolygonF() for i in range(0, nPoints): if usePoint[i]: stripped += p[i] return stripped
def drawRect(self, *args): if len(args) == 5: painter, x, y, w, h = args self.drawRect(painter, QRectF(x, y, w, h)) elif len(args) == 2: painter, rect = args r = rect deviceClipping, clipRect = qwtIsClippingNeeded(painter) if deviceClipping: if not clipRect.intersects(r): return if not clipRect.contains(r): self.fillRect(painter, r & clipRect, painter.brush()) painter.save() painter.setBrush(Qt.NoBrush) self.drawPolyline(painter, QPolygonF(r)) painter.restore() return painter.drawRect(r) else: raise TypeError("QwtPainter.drawRect() takes 2 or 5 argument(s) "\ "(%s given)" % len(args))
def qwtDrawBox(p, rect, pal, lw): if lw > 0.: if rect.width() == 0.: p.setPen(pal.dark().color()) p.drawLine(rect.topLeft(), rect.bottomLeft()) return if rect.height() == 0.: p.setPen(pal.dark().color()) p.drawLine(rect.topLeft(), rect.topRight()) return lw = min([lw, rect.height() / 2. - 1.]) lw = min([lw, rect.width() / 2. - 1.]) outerRect = rect.adjusted(0, 0, 1, 1) polygon = QPolygonF(outerRect) if outerRect.width() > 2 * lw and outerRect.height() > 2 * lw: innerRect = outerRect.adjusted(lw, lw, -lw, -lw) polygon = polygon.subtracted(innerRect) p.setPen(Qt.NoPen) p.setBrush(pal.dark()) p.drawPolygon(polygon) windowRect = rect.adjusted(lw, lw, -lw + 1, -lw + 1) if windowRect.isValid(): p.fillRect(windowRect, pal.window())
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 __init__(self): self.splineType = QwtSpline.Natural self.a = np.array([]) self.b = np.array([]) self.c = np.array([]) self.points = QPolygonF()