Skip to content

Commit

Permalink
Fix segfaults related to QwtGraphic_PrivateData and QwtLegendLabel_Pr…
Browse files Browse the repository at this point in the history
…ivateData
  • Loading branch information
PierreRaybaut committed Jul 24, 2024
1 parent 9bc5c75 commit d7447b7
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# PythonQwt Releases

## Version 0.12.7

- Fixed other random crashes (segfaults) on Linux related to Qt objects stored in
private data structures (`QwtGraphic_PrivateData`, `QwtLegendLabel_PrivateData`)

## Version 0.12.6

- Fixed random crashes (segfaults) on Linux related to Qt objects stored in cache data
Expand Down
28 changes: 14 additions & 14 deletions qwt/graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ def scaleFactorY(self, pathRect, targetRect, scalePens):

class QwtGraphic_PrivateData(object):
def __init__(self):
self.boundingRect = QRectF(0.0, 0.0, -1.0, -1.0)
self.pointRect = QRectF(0.0, 0.0, -1.0, -1.0)
self.boundingRect = None
self.pointRect = None
self.initialTransform = None
self.defaultSize = QSizeF()
self.defaultSize = None
self.commands = []
self.pathInfos = []
self.renderHints = 0
Expand Down Expand Up @@ -286,17 +286,17 @@ def reset(self):
"""Clear all stored commands"""
self.__data.commands = []
self.__data.pathInfos = []
self.__data.boundingRect = QRectF(0.0, 0.0, -1.0, -1.0)
self.__data.pointRect = QRectF(0.0, 0.0, -1.0, -1.0)
self.__data.defaultSize = QSizeF()
self.__data.boundingRect = None
self.__data.pointRect = None
self.__data.defaultSize = None

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

def isEmpty(self):
"""Return True, when the bounding rectangle is empty"""
return self.__data.boundingRect.isEmpty()
return self.__data.boundingRect is None or self.__data.boundingRect.isEmpty()

def setRenderHint(self, hint, on=True):
"""Toggle an render hint"""
Expand All @@ -321,7 +321,7 @@ def boundingRect(self):
:py:meth:`controlPointRect`, :py:meth:`scaledBoundingRect`
"""
if self.__data.boundingRect.width() < 0:
if self.__data.boundingRect is None:
return QRectF()
return self.__data.boundingRect

Expand All @@ -337,7 +337,7 @@ def controlPointRect(self):
:py:meth:`boundingRect()`, :py:meth:`scaledBoundingRect()`
"""
if self.__data.pointRect.width() < 0:
if self.__data.pointRect is None:
return QRectF()
return self.__data.pointRect

Expand Down Expand Up @@ -407,7 +407,7 @@ def defaultSize(self):
:py:meth:`setDefaultSize()`, :py:meth:`boundingRect()`
"""
if not self.__data.defaultSize.isEmpty():
if self.__data.defaultSize is not None:
return self.__data.defaultSize
return self.boundingRect().size()

Expand Down Expand Up @@ -486,9 +486,9 @@ def render(self, *args):
return
sx = 1.0
sy = 1.0
if self.__data.pointRect.width() > 0.0:
if self.__data.pointRect is not None:
sx = rect.width() / self.__data.pointRect.width()
if self.__data.pointRect.height() > 0.0:
if self.__data.pointRect is not None:
sy = rect.height() / self.__data.pointRect.height()
scalePens = not bool(self.__data.renderHints & self.RenderPensUnscaled)
for info in self.__data.pathInfos:
Expand Down Expand Up @@ -741,13 +741,13 @@ def updateBoundingRect(self, rect):
cr = painter.clipRegion().boundingRect()
cr = painter.transform().mapRect(cr)
br &= cr
if self.__data.boundingRect.width() < 0:
if self.__data.boundingRect is None:
self.__data.boundingRect = br
else:
self.__data.boundingRect |= br

def updateControlPointRect(self, rect):
if self.__data.pointRect.width() < 0.0:
if self.__data.pointRect is None:
self.__data.pointRect = rect
else:
self.__data.pointRect |= rect
Expand Down
8 changes: 4 additions & 4 deletions qwt/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(self):
self.isDown = False
self.spacing = MARGIN
self.legendData = QwtLegendData()
self.icon = QPixmap()
self.icon = None


class QwtLegendLabel(QwtTextLabel):
Expand Down Expand Up @@ -294,7 +294,7 @@ def icon(self):
:py:meth:`setIcon()`
"""
return self.__data.icon
return QPixmap() if self.__data.icon is None else self.__data.icon

def setSpacing(self, spacing):
"""
Expand All @@ -312,7 +312,7 @@ def setSpacing(self, spacing):
mgn = self.contentsMargins()
margin = max([mgn.left(), mgn.top(), mgn.right(), mgn.bottom()])
indent = margin + self.__data.spacing
if self.__data.icon.width() > 0:
if self.__data.icon is not None:
indent += self.__data.icon.width() + self.__data.spacing
self.setIndent(indent)

Expand Down Expand Up @@ -409,7 +409,7 @@ def paintEvent(self, e):
painter.translate(shiftSize.width(), shiftSize.height())
painter.setClipRect(cr)
self.drawContents(painter)
if not self.__data.icon.isNull():
if self.__data.icon is not None:
iconRect = QRect(cr)
iconRect.setX(iconRect.x() + self.margin())
if self.__data.itemMode != QwtLegendData.ReadOnly:
Expand Down

0 comments on commit d7447b7

Please sign in to comment.