Skip to content

Commit 973f276

Browse files
committed
Fixed QwtPlotCanvas backingStore feature
1 parent 6a36ce7 commit 973f276

File tree

7 files changed

+54
-26
lines changed

7 files changed

+54
-26
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- Dropped support for Python 3.7 and earlier
66
- Dropped support for PyQt4 and PySide2
77
- Removed unnecessary argument `numPoints` in `QwtSymbol.drawSymbols` and `QwtSymbol.renderSymbols` methods
8+
- `QwtPlotCanvas`: fixed `BackingStore` feature (`paintAttribute`)
89

910
## Version 0.10.6
1011

qwt/painter.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
:members:
1414
"""
1515

16-
from qtpy import QtCore as QC
17-
from qtpy.QtCore import QLineF, QPoint, QRect, QRectF, Qt
16+
from qtpy.QtCore import QLineF, QPoint, QRect, Qt
1817
from qtpy.QtGui import (
1918
QBrush,
2019
QColor,
@@ -27,7 +26,13 @@
2726
QPixmap,
2827
QRegion,
2928
)
30-
from qtpy.QtWidgets import QFrame, QStyle, QStyleOption, QStyleOptionFocusRect
29+
from qtpy.QtWidgets import (
30+
QApplication,
31+
QFrame,
32+
QStyle,
33+
QStyleOption,
34+
QStyleOptionFocusRect,
35+
)
3136

3237
from qwt.color_map import QwtColorMap
3338
from qwt.scale_map import QwtScaleMap
@@ -445,13 +450,8 @@ def backingStore(self, widget, size):
445450
if widget and widget.windowHandle():
446451
pixelRatio = widget.windowHandle().devicePixelRatio()
447452
else:
448-
from qtpy.QtGui import qApp
449-
450-
if qApp is not None:
451-
try:
452-
pixelRatio = qApp.devicePixelRatio()
453-
except RuntimeError:
454-
pass
453+
qapp = QApplication.instance()
454+
pixelRatio = qapp.devicePixelRatio()
455455
pm = QPixmap(size * pixelRatio)
456456
pm.setDevicePixelRatio(pixelRatio)
457457
return pm

qwt/plot_canvas.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
import os
1717

18-
from qtpy.QtCore import QEvent, QPointF, QRect, QRectF, QSizeF, Qt
18+
from qtpy.QtCore import QEvent, QPoint, QPointF, QRect, QRectF, QSize, Qt
1919
from qtpy.QtGui import (
2020
QBrush,
2121
QGradient,
@@ -280,12 +280,12 @@ def qwtFillBackground(*args):
280280
r = canvas.rect()
281281
radius = canvas.borderRadius()
282282
if radius > 0.0:
283-
sz = QSizeF(radius, radius)
283+
sz = QSize(radius, radius)
284284
rects += [
285-
QRectF(r.topLeft(), sz),
286-
QRectF(r.topRight() - QPointF(radius, 0), sz),
287-
QRectF(r.bottomRight() - QPointF(radius, radius), sz),
288-
QRectF(r.bottomLeft() - QPointF(0, radius), sz),
285+
QRect(r.topLeft(), sz),
286+
QRect(r.topRight() - QPoint(radius, 0), sz),
287+
QRect(r.bottomRight() - QPoint(radius, radius), sz),
288+
QRect(r.bottomLeft() - QPoint(0, radius), sz),
289289
]
290290

291291
qwtFillBackground(painter, canvas, rects)
@@ -586,6 +586,7 @@ def paintEvent(self, event):
586586
if (
587587
self.testPaintAttribute(self.BackingStore)
588588
and self.__data.backingStore is not None
589+
and not self.__data.backingStore.isNull()
589590
):
590591
bs = self.__data.backingStore
591592
pixelRatio = bs.devicePixelRatio()

qwt/plot_directpainter.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ def qwtRenderItem(painter, canvasRect, seriesItem, from_, to):
3333

3434
def qwtHasBackingStore(canvas):
3535
return (
36-
canvas.testPaintAttribute(QwtPlotCanvas.BackingStore) and canvas.backingStore()
36+
canvas.testPaintAttribute(QwtPlotCanvas.BackingStore)
37+
and canvas.backingStore() is not None
38+
and not canvas.backingStore().isNull()
3739
)
3840

3941

@@ -207,17 +209,14 @@ def drawSeries(self, seriesItem, from_, to):
207209
return
208210
canvas = seriesItem.plot().canvas()
209211
canvasRect = canvas.contentsRect()
210-
plotCanvas = canvas # XXX: cast to QwtPlotCanvas
211-
if plotCanvas and qwtHasBackingStore(plotCanvas):
212-
painter = QPainter(
213-
plotCanvas.backingStore()
214-
) # XXX: cast plotCanvas.backingStore() to QPixmap
212+
if canvas and qwtHasBackingStore(canvas):
213+
painter = QPainter(canvas.backingStore())
215214
if self.__data.hasClipping:
216215
painter.setClipRegion(self.__data.clipRegion)
217216
qwtRenderItem(painter, canvasRect, seriesItem, from_, to)
218217
painter.end()
219218
if self.testAttribute(self.FullRepaint):
220-
plotCanvas.repaint()
219+
canvas.repaint()
221220
return
222221
if canvas.testAttribute(Qt.WA_WState_InPaintEvent):
223222
if not self.__data.painter.isActive():

qwt/symbol.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def qwtDrawSvgSymbols(painter, points, renderer, symbol):
103103
renderer.render(painter, QRectF(x, y, sz.width(), sz.height()))
104104

105105

106-
def qwtDrawGraphicSymbols(painter, points, numPoint, graphic, symbol):
106+
def qwtDrawGraphicSymbols(painter, points, graphic, symbol):
107107
pointRect = QRectF(graphic.controlPointRect())
108108
if pointRect.isEmpty():
109109
return
@@ -179,7 +179,7 @@ def qwtDrawDiamondSymbols(painter, points, symbol):
179179
painter.drawPolygon(polygon)
180180

181181

182-
def qwtDrawTriangleSymbols(painter, type, points, numPoint, symbol):
182+
def qwtDrawTriangleSymbols(painter, type, points, symbol):
183183
size = symbol.size()
184184
pen = QPen(symbol.pen())
185185
pen.setJoinStyle(Qt.MiterJoin)

qwt/tests/test_backingstore.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# -*- coding: utf-8 -*-
2+
3+
SHOW = False # Do not show test in GUI-based test launcher
4+
5+
from qwt.tests import utils
6+
from qwt.tests.test_simple import SimplePlot
7+
8+
9+
class BackingStorePlot(SimplePlot):
10+
TEST_EXPORT = False
11+
12+
def __init__(self):
13+
SimplePlot.__init__(self)
14+
self.canvas().setPaintAttribute(self.canvas().BackingStore, True)
15+
16+
17+
def test_backingstore():
18+
"""Test for backing store"""
19+
utils.test_widget(BackingStorePlot, size=(600, 400))
20+
21+
22+
if __name__ == "__main__":
23+
test_backingstore()

qwt/tests/test_simple.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121

2222
class SimplePlot(qwt.QwtPlot):
23+
TEST_EXPORT = True
24+
2325
def __init__(self):
2426
qwt.QwtPlot.__init__(self)
2527
self.setTitle("Really simple demo")
@@ -28,6 +30,8 @@ def __init__(self):
2830
self.setAxisTitle(qwt.QwtPlot.yLeft, "Y-axis")
2931
self.enableAxis(self.xBottom)
3032
self.setCanvasBackground(Qt.white)
33+
canvas = self.canvas()
34+
canvas.setBorderRadius(50)
3135

3236
qwt.QwtPlotGrid.make(self, color=Qt.lightGray, width=0, style=Qt.DotLine)
3337

@@ -55,7 +59,7 @@ def __init__(self):
5559
plot=self,
5660
)
5761

58-
if utils.TestEnvironment().unattended:
62+
if self.TEST_EXPORT and utils.TestEnvironment().unattended:
5963
QTimer.singleShot(0, self.export_to_different_formats)
6064

6165
def export_to_different_formats(self):

0 commit comments

Comments
 (0)