Skip to content

Commit d7447b7

Browse files
committed
Fix segfaults related to QwtGraphic_PrivateData and QwtLegendLabel_PrivateData
1 parent 9bc5c75 commit d7447b7

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# PythonQwt Releases
22

3+
## Version 0.12.7
4+
5+
- Fixed other random crashes (segfaults) on Linux related to Qt objects stored in
6+
private data structures (`QwtGraphic_PrivateData`, `QwtLegendLabel_PrivateData`)
7+
38
## Version 0.12.6
49

510
- Fixed random crashes (segfaults) on Linux related to Qt objects stored in cache data

qwt/graphic.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,10 @@ def scaleFactorY(self, pathRect, targetRect, scalePens):
187187

188188
class QwtGraphic_PrivateData(object):
189189
def __init__(self):
190-
self.boundingRect = QRectF(0.0, 0.0, -1.0, -1.0)
191-
self.pointRect = QRectF(0.0, 0.0, -1.0, -1.0)
190+
self.boundingRect = None
191+
self.pointRect = None
192192
self.initialTransform = None
193-
self.defaultSize = QSizeF()
193+
self.defaultSize = None
194194
self.commands = []
195195
self.pathInfos = []
196196
self.renderHints = 0
@@ -286,17 +286,17 @@ def reset(self):
286286
"""Clear all stored commands"""
287287
self.__data.commands = []
288288
self.__data.pathInfos = []
289-
self.__data.boundingRect = QRectF(0.0, 0.0, -1.0, -1.0)
290-
self.__data.pointRect = QRectF(0.0, 0.0, -1.0, -1.0)
291-
self.__data.defaultSize = QSizeF()
289+
self.__data.boundingRect = None
290+
self.__data.pointRect = None
291+
self.__data.defaultSize = None
292292

293293
def isNull(self):
294294
"""Return True, when no painter commands have been stored"""
295295
return len(self.__data.commands) == 0
296296

297297
def isEmpty(self):
298298
"""Return True, when the bounding rectangle is empty"""
299-
return self.__data.boundingRect.isEmpty()
299+
return self.__data.boundingRect is None or self.__data.boundingRect.isEmpty()
300300

301301
def setRenderHint(self, hint, on=True):
302302
"""Toggle an render hint"""
@@ -321,7 +321,7 @@ def boundingRect(self):
321321
322322
:py:meth:`controlPointRect`, :py:meth:`scaledBoundingRect`
323323
"""
324-
if self.__data.boundingRect.width() < 0:
324+
if self.__data.boundingRect is None:
325325
return QRectF()
326326
return self.__data.boundingRect
327327

@@ -337,7 +337,7 @@ def controlPointRect(self):
337337
338338
:py:meth:`boundingRect()`, :py:meth:`scaledBoundingRect()`
339339
"""
340-
if self.__data.pointRect.width() < 0:
340+
if self.__data.pointRect is None:
341341
return QRectF()
342342
return self.__data.pointRect
343343

@@ -407,7 +407,7 @@ def defaultSize(self):
407407
408408
:py:meth:`setDefaultSize()`, :py:meth:`boundingRect()`
409409
"""
410-
if not self.__data.defaultSize.isEmpty():
410+
if self.__data.defaultSize is not None:
411411
return self.__data.defaultSize
412412
return self.boundingRect().size()
413413

@@ -486,9 +486,9 @@ def render(self, *args):
486486
return
487487
sx = 1.0
488488
sy = 1.0
489-
if self.__data.pointRect.width() > 0.0:
489+
if self.__data.pointRect is not None:
490490
sx = rect.width() / self.__data.pointRect.width()
491-
if self.__data.pointRect.height() > 0.0:
491+
if self.__data.pointRect is not None:
492492
sy = rect.height() / self.__data.pointRect.height()
493493
scalePens = not bool(self.__data.renderHints & self.RenderPensUnscaled)
494494
for info in self.__data.pathInfos:
@@ -741,13 +741,13 @@ def updateBoundingRect(self, rect):
741741
cr = painter.clipRegion().boundingRect()
742742
cr = painter.transform().mapRect(cr)
743743
br &= cr
744-
if self.__data.boundingRect.width() < 0:
744+
if self.__data.boundingRect is None:
745745
self.__data.boundingRect = br
746746
else:
747747
self.__data.boundingRect |= br
748748

749749
def updateControlPointRect(self, rect):
750-
if self.__data.pointRect.width() < 0.0:
750+
if self.__data.pointRect is None:
751751
self.__data.pointRect = rect
752752
else:
753753
self.__data.pointRect |= rect

qwt/legend.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self):
176176
self.isDown = False
177177
self.spacing = MARGIN
178178
self.legendData = QwtLegendData()
179-
self.icon = QPixmap()
179+
self.icon = None
180180

181181

182182
class QwtLegendLabel(QwtTextLabel):
@@ -294,7 +294,7 @@ def icon(self):
294294
295295
:py:meth:`setIcon()`
296296
"""
297-
return self.__data.icon
297+
return QPixmap() if self.__data.icon is None else self.__data.icon
298298

299299
def setSpacing(self, spacing):
300300
"""
@@ -312,7 +312,7 @@ def setSpacing(self, spacing):
312312
mgn = self.contentsMargins()
313313
margin = max([mgn.left(), mgn.top(), mgn.right(), mgn.bottom()])
314314
indent = margin + self.__data.spacing
315-
if self.__data.icon.width() > 0:
315+
if self.__data.icon is not None:
316316
indent += self.__data.icon.width() + self.__data.spacing
317317
self.setIndent(indent)
318318

@@ -409,7 +409,7 @@ def paintEvent(self, e):
409409
painter.translate(shiftSize.width(), shiftSize.height())
410410
painter.setClipRect(cr)
411411
self.drawContents(painter)
412-
if not self.__data.icon.isNull():
412+
if self.__data.icon is not None:
413413
iconRect = QRect(cr)
414414
iconRect.setX(iconRect.x() + self.margin())
415415
if self.__data.itemMode != QwtLegendData.ReadOnly:

0 commit comments

Comments
 (0)