本文整理汇总了Python中qwt.painter.QwtPainter.roundingAlignment方法的典型用法代码示例。如果您正苦于以下问题:Python QwtPainter.roundingAlignment方法的具体用法?Python QwtPainter.roundingAlignment怎么用?Python QwtPainter.roundingAlignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qwt.painter.QwtPainter
的用法示例。
在下文中一共展示了QwtPainter.roundingAlignment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: drawSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to):
"""
Draw symbols
:param QPainter painter: Painter
:param qwt.symbol.QwtSymbol symbol: Curve symbol
: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:`setSymbol()`, :py:meth:`drawSeries()`,
:py:meth:`drawCurve()`
"""
mapper = QwtPointMapper()
mapper.setFlag(QwtPointMapper.RoundPoints,
QwtPainter.roundingAlignment(painter))
mapper.setFlag(QwtPointMapper.WeedOutPoints,
self.testPaintAttribute(QwtPlotCurve.FilterPoints))
mapper.setBoundingRect(canvasRect)
chunkSize = 500
for i in range(from_, to+1, chunkSize):
n = min([chunkSize, to-i+1])
points = mapper.toPointsF(xMap, yMap, self.data(), i, i+n-1)
if points.size() > 0:
symbol.drawSymbols(painter, points)
示例2: qwtDrawDiamondSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
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)
示例3: qwtDrawTriangleSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
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))
示例4: qwtDrawXCrossSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def qwtDrawXCrossSymbols(painter, points, numPoints, symbol):
size =symbol.size()
off = 0
pen = QPen(symbol.pen())
if pen.width() > 1:
pen.setCapStyle(Qt.FlatCap)
off = 1
painter.setPen(pen)
if QwtPainter.roundingAlignment(painter):
sw = np.floor(size.width())
sh = np.floor(size.height())
sw2 = size.width()//2
sh2 = size.height()//2
for pos in points:
x = round(pos.x())
y = round(pos.y())
x1 = x-sw2
x2 = x1+sw+off
y1 = y-sh2
y2 = y1+sh+off
QwtPainter.drawLine(painter, x1, y1, x2, y2)
QwtPainter.drawLine(painter, x2, y1, x1, y2)
else:
sw = size.width()
sh = size.height()
sw2 = .5*size.width()
sh2 = .5*size.height()
for pos in points:
x1 = pos.x()-sw2
x2 = x1+sw
y1 = pos.y()-sh2
y2 = y1+sh
QwtPainter.drawLine(painter, x1, y1, x2, y2)
QwtPainter.drawLine(painter, x2, y1, x1, y2)
示例5: closePolyline
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def closePolyline(self, painter, xMap, yMap, polygon):
"""
Complete a polygon to be a closed polygon including the
area between the original polygon and the baseline.
: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 QPolygonF polygon: Polygon to be completed
"""
if polygon.size() < 2:
return
doAlign = QwtPainter.roundingAlignment(painter)
baseline = self.__data.baseline
if self.orientation() == Qt.Vertical:
if yMap.transformation():
baseline = yMap.transformation().bounded(baseline)
refY = yMap.transform(baseline)
if doAlign:
refY = round(refY)
polygon += QPointF(polygon.last().x(), refY)
polygon += QPointF(polygon.first().x(), refY)
else:
if xMap.transformation():
baseline = xMap.transformation().bounded(baseline)
refX = xMap.transform(baseline)
if doAlign:
refX = round(refX)
polygon += QPointF(refX, polygon.last().y())
polygon += QPointF(refX, polygon.first().y())
示例6: qwtDrawHexagonSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
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))
示例7: qwtDrawStar1Symbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def qwtDrawStar1Symbols(painter, points, numPoints, symbol):
size =symbol.size()
painter.setPen(symbol.pen())
sqrt1_2 = np.sqrt(.5)
if QwtPainter.roundingAlignment(painter):
r = QRect(0, 0, size.width(), size.height())
for pos in points:
r.moveCenter(pos.toPoint())
d1 = r.width()/2.*(1.-sqrt1_2)
QwtPainter.drawLine(painter,
round(r.left()+d1), round(r.top()+d1),
round(r.right()-d1), round(r.bottom()-d1))
QwtPainter.drawLine(painter,
round(r.left()+d1), round(r.bottom()-d1),
round(r.right()-d1), round(r.top()+d1))
c = QPoint(r.center())
QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom())
QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())
else:
r = QRectF(0, 0, size.width(), size.height())
for pos in points:
r.moveCenter(pos.toPoint())
c = QPointF(r.center())
d1 = r.width()/2.*(1.-sqrt1_2)
QwtPainter.drawLine(painter, r.left()+d1, r.top()+d1,
r.right()-d1, r.bottom()-d1)
QwtPainter.drawLine(painter, r.left()+d1, r.bottom()-d1,
r.right()-d1, r.top()+d1)
QwtPainter.drawLine(painter, c.x(), r.top(), c.x(), r.bottom())
QwtPainter.drawLine(painter, r.left(), c.y(), r.right(), c.y())
示例8: drawLines
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def drawLines(self, painter, canvasRect, pos):
"""
Draw the lines marker
:param QPainter painter: Painter
:param QRectF canvasRect: Contents rectangle of the canvas in painter coordinates
:param QPointF pos: Position of the marker, translated into widget coordinates
.. seealso::
:py:meth:`drawLabel()`,
:py:meth:`qwt.symbol.QwtSymbol.drawSymbol()`
"""
if self.__data.style == self.NoLine:
return
doAlign = QwtPainter.roundingAlignment(painter)
painter.setPen(self.__data.pen)
if self.__data.style in (QwtPlotMarker.HLine, QwtPlotMarker.Cross):
y = pos.y()
if doAlign:
y = round(y)
QwtPainter.drawLine(painter, canvasRect.left(),
y, canvasRect.right()-1., y)
if self.__data.style in (QwtPlotMarker.VLine, QwtPlotMarker.Cross):
x = pos.x()
if doAlign:
x = round(x)
QwtPainter.drawLine(painter, x,
canvasRect.top(), x, canvasRect.bottom()-1.)
示例9: drawSteps
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
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)
示例10: drawBackbone
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def drawBackbone(self, painter):
doAlign = QwtPainter.roundingAlignment(painter)
pos = self.__data.pos
len_ = self.__data.len
pw = max([self.penWidth(), 1])
if doAlign:
if self.alignment() in (self.LeftScale, self.TopScale):
off = (pw-1)/2
else:
off = pw/2
else:
off = .5*self.penWidth()
if self.alignment() == self.LeftScale:
x = pos.x() - off
if doAlign:
x = round(x)
QwtPainter.drawLine(painter, x, pos.y(), x, pos.y()+len_)
elif self.alignment() == self.RightScale:
x = pos.x() + off
if doAlign:
x = round(x)
QwtPainter.drawLine(painter, x, pos.y(), x, pos.y()+len_)
elif self.alignment() == self.TopScale:
y = pos.y() - off
if doAlign:
y = round(y)
QwtPainter.drawLine(painter, pos.x(), y, pos.x()+len_, y)
elif self.alignment() == self.BottomScale:
y = pos.y() + off
if doAlign:
y = round(y)
QwtPainter.drawLine(painter, pos.x(), y, pos.x()+len_, y)
示例11: qwtDrawRectSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def qwtDrawRectSymbols(painter, points, numPoints, symbol):
size = symbol.size()
pen = QPen(symbol.pen())
pen.setJoinStyle(Qt.MiterJoin)
painter.setPen(pen)
painter.setBrush(symbol.brush())
painter.setRenderHint(QPainter.Antialiasing, False)
if QwtPainter.roundingAlignment(painter):
sw = size.width()
sh = size.height()
sw2 = size.width()//2
sh2 = size.height()//2
for pos in points:
x = round(pos.x())
y = round(pos.y())
r = QRectF(x-sw2, y-sh2, sw, sh)
QwtPainter.drawRect(painter, r)
else:
sw = size.width()
sh = size.height()
sw2 = .5*size.width()
sh2 = .5*size.height()
for pos in points:
x = pos.x()
y = pos.y()
r = QRectF(x-sw2, y-sh2, sw, sh)
QwtPainter.drawRect(painter, r)
示例12: drawLines
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
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)
示例13: drawTick
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def drawTick(self, painter, value, len_):
"""
Draw a tick
:param QPainter painter: Painter
:param float value: Value of the tick
:param float len: Length of the tick
.. seealso::
:py:meth:`drawBackbone()`, :py:meth:`drawLabel()`
"""
if len_ <= 0:
return
roundingAlignment = QwtPainter.roundingAlignment(painter)
pos = self.__data.pos
tval = self.scaleMap().transform(value)
if roundingAlignment:
tval = round(tval)
pw = self.penWidth()
a = 0
if pw > 1 and roundingAlignment:
a = 1
if self.alignment() == self.LeftScale:
x1 = pos.x() + a
x2 = pos.x() + a - pw - len_
if roundingAlignment:
x1 = round(x1)
x2 = round(x2)
QwtPainter.drawLine(painter, x1, tval, x2, tval)
elif self.alignment() == self.RightScale:
x1 = pos.x()
x2 = pos.x() + pw + len_
if roundingAlignment:
x1 = round(x1)
x2 = round(x2)
QwtPainter.drawLine(painter, x1, tval, x2, tval)
elif self.alignment() == self.BottomScale:
y1 = pos.y()
y2 = pos.y() + pw + len_
if roundingAlignment:
y1 = round(y1)
y2 = round(y2)
QwtPainter.drawLine(painter, tval, y1, tval, y2)
elif self.alignment() == self.TopScale:
y1 = pos.y() + a
y2 = pos.y() - pw - len_ + a
if roundingAlignment:
y1 = round(y1)
y2 = round(y2)
QwtPainter.drawLine(painter, tval, y1, tval, y2)
示例14: drawSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def drawSymbols(self, painter, points, numPoints=None):
"""
Render an array of symbols
Painting several symbols is more effective than drawing symbols
one by one, as a couple of layout calculations and setting of pen/brush
can be done once for the complete array.
:param QPainter painter: Painter
:param QPolygonF points: Positions of the symbols in screen coordinates
"""
#TODO: remove argument numPoints (not necessary in `PythonQwt`)
if numPoints is not None and numPoints <= 0:
return
useCache = False
if QwtPainter.roundingAlignment(painter) and\
not painter.transform().isScaling():
if self.__data.cache.policy == QwtSymbol.Cache:
useCache = True
elif self.__data.cache.policy == QwtSymbol.AutoCache:
if painter.paintEngine().type() == QPaintEngine.Raster:
useCache = True
else:
if self.__data.style in (QwtSymbol.XCross, QwtSymbol.HLine,
QwtSymbol.VLine, QwtSymbol.Cross):
pass
elif self.__data.style == QwtSymbol.Pixmap:
if not self.__data.size.isEmpty() and\
self.__data.size != self.__data.pixmap.pixmap.size():
useCache = True
else:
useCache = True
if useCache:
br = QRect(self.boundingRect())
rect = QRect(0, 0, br.width(), br.height())
if self.__data.cache.pixmap.isNull():
self.__data.cache.pixmap = QwtPainter.backingStore(None, br.size())
self.__data.cache.pixmap.fill(Qt.transparent)
p = QPainter(self.__data.cache.pixmap)
p.setRenderHints(painter.renderHints())
p.translate(-br.topLeft())
pos = QPointF()
self.renderSymbols(p, pos, 1)
dx = br.left()
dy = br.top()
for point in points:
left = round(point.x())+dx
top = round(point.y())+dy
painter.drawPixmap(left, top, self.__data.cache.pixmap)
else:
painter.save()
self.renderSymbols(painter, points, numPoints)
painter.restore()
示例15: drawSymbols
# 需要导入模块: from qwt.painter import QwtPainter [as 别名]
# 或者: from qwt.painter.QwtPainter import roundingAlignment [as 别名]
def drawSymbols(self, painter, symbol, xMap, yMap, canvasRect, from_, to):
mapper = QwtPointMapper()
mapper.setFlag(QwtPointMapper.RoundPoints,
QwtPainter.roundingAlignment(painter))
mapper.setFlag(QwtPointMapper.WeedOutPoints,
self.testPaintAttribute(QwtPlotCurve.FilterPoints))
mapper.setBoundingRect(canvasRect)
chunkSize = 500
for i in range(from_, to+1, chunkSize):
n = min([chunkSize, to-i+1])
points = mapper.toPointsF(xMap, yMap, self.data(), i, i+n-1)
if points.size() > 0:
symbol.drawSymbols(painter, points)