Skip to content

Commit b27941e

Browse files
author
Pierre Raybaut
committed
Clarified situation regarding the absence of QwtClipper
1 parent b2d5a2a commit b27941e

File tree

5 files changed

+58
-12
lines changed

5 files changed

+58
-12
lines changed

README

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ Licensed under the terms of the MIT License (see qwt/LICENSE)
1818
- QwtPicker
1919
- QwtPlotPicker
2020

21+
QwtClipper is not implemented yet (and it will probably be very difficult
22+
or impossible to implement it in pure Python without performance issues).
23+
As a consequence, when zooming in a plot curve, the entire curve is still
24+
painted (in other words, when working with large amount of data, there is
25+
no performance gain when zooming in).
26+
2127
Dependencies
2228

2329
Requirements

qwt/__init__.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,3 @@ def setMinPen(self, *args):
101101
RuntimeWarning)
102102
return self.setMinorPen(*args)
103103
## ============================================================================
104-
105-
106-
#TODO: implement QwtClipper: needed for SVG export for example

qwt/clipper.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# -*- coding: utf-8 -*-
22

3+
from qwt.qt.QtGui import QPolygon, QPolygonF
4+
from qwt.qt.QtCore import QRect, QRectF
5+
6+
import numpy as np
7+
38

49
class LeftEdge(object):
510
def __init__(self, x1, x2, y1, y2):
@@ -68,8 +73,44 @@ def data(self):
6873

6974
def operator(self, i):
7075
return self.m_buffer[i]
76+
77+
78+
class QwtPolygonClipper(object):
79+
def __init__(self, clipRect):
80+
self.__clipRect = clipRect
7181

82+
def clipPolygon(self, polygon, closePolygon):
83+
if self.__clipRect.contains(polygon.boundingRect()):
84+
return polygon
85+
7286

7387

7488
class QwtClipper(object):
75-
pass
89+
def __init__(self):
90+
pass
91+
92+
def clipPolygon(self, clipRect, polygon, closePolygon):
93+
raise NotImplementedError("Nearly impossible to implement in pure Python")
94+
#XXX: the only viable option would be to use Qt's intersected method
95+
# but unfortunately it's closing systematically the output polygon
96+
# (how to test it: polygon.intersected(QPolygonF(clipRect)))
97+
98+
if isinstance(clipRect, QRectF):
99+
minX = np.ceil(clipRect.left())
100+
maxX = np.floor(clipRect.right())
101+
minY = np.ceil(clipRect.top())
102+
maxY = np.floor(clipRect.bottom())
103+
clipRect = QRect(minX, minY, maxX-minX, maxY-minY)
104+
clipper = QwtPolygonClipper(clipRect)
105+
return clipper.clipPolygon(polygon, closePolygon)
106+
107+
def clipPolygonF(self, clipRect, polygon, closePolygon):
108+
raise NotImplementedError("Nearly impossible to implement in pure Python")
109+
#XXX: the only viable option would be to use Qt's intersected method
110+
# but unfortunately it's closing systematically the output polygon
111+
# (how to test it: polygon.intersected(QPolygonF(clipRect)))
112+
113+
if isinstance(clipRect, QRect):
114+
clipRect = QRectF(clipRect)
115+
clipper = QwtPolygonClipper(clipRect)
116+
return clipper.clipPolygon(polygon, closePolygon)

qwt/painter.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
def qwtIsClippingNeeded(painter):
2020
doClipping = False
2121
clipRect = QRectF()
22+
#TODO: remove next line when QwtClipper will be implemented
23+
return doClipping, clipRect
2224
pe = painter.paintEngine()
2325
if pe and pe.type() == QPaintEngine.SVG:
2426
if painter.hasClipping():
@@ -244,9 +246,9 @@ def drawPolygon(self, painter, polygon):
244246
cpa = polygon
245247
if deviceClipping:
246248
if isinstance(polygon, QPolygonF):
247-
cpa = QwtClipper.clipPolygonF(clipRect, polygon)
249+
cpa = QwtClipper().clipPolygonF(clipRect, polygon)
248250
else:
249-
cpa = QwtClipper.clipPolygon(clipRect, polygon)
251+
cpa = QwtClipper().clipPolygon(clipRect, polygon)
250252
painter.drawPolygon(cpa)
251253

252254
def drawPolyline(self, *args):
@@ -256,9 +258,9 @@ def drawPolyline(self, *args):
256258
cpa = polygon
257259
if deviceClipping:
258260
if isinstance(polygon, QPolygonF):
259-
cpa = QwtClipper.clipPolygonF(clipRect, polygon)
261+
cpa = QwtClipper().clipPolygonF(clipRect, polygon)
260262
else:
261-
cpa = QwtClipper.clipPolygon(clipRect, polygon)
263+
cpa = QwtClipper().clipPolygon(clipRect, polygon)
262264
qwtDrawPolyline(painter, cpa, cpa.size(),
263265
self.__polylineSplitting)
264266
elif len(args) == 3:
@@ -267,10 +269,10 @@ def drawPolyline(self, *args):
267269
if deviceClipping:
268270
if isinstance(points[0], QPointF):
269271
polygon = QPolygonF(points)
270-
polygon = QwtClipper.clipPolygonF(clipRect, polygon)
272+
polygon = QwtClipper().clipPolygonF(clipRect, polygon)
271273
else:
272274
polygon = QPolygon(points)
273-
polygon = QwtClipper.clipPolygon(clipRect, polygon)
275+
polygon = QwtClipper().clipPolygon(clipRect, polygon)
274276
qwtDrawPolyline(painter, polygon,
275277
polygon.size(), self.__polylineSplitting)
276278
# polygon = QPolygonF(pointCount)

qwt/plot_curve.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ def __init__(self):
5151
self.baseline = 0.
5252
self.symbol = None
5353
self.attributes = 0
54-
# self.paintAttributes = QwtPlotCurve.ClipPolygons|QwtPlotCurve.FilterPoints
55-
#TODO: uncomment previous line when QwtClipper will be implemented
5654
self.paintAttributes = QwtPlotCurve.FilterPoints
55+
#TODO: uncomment next line when QwtClipper will be implemented
56+
# self.paintAttributes = QwtPlotCurve.ClipPolygons|QwtPlotCurve.FilterPoints
5757
self.legendAttributes = QwtPlotCurve.LegendShowLine
5858
self.pen = QPen(Qt.black)
5959
self.brush = QBrush()

0 commit comments

Comments
 (0)