Skip to content

Commit 41bfe1e

Browse files
committed
Fix: Restore QObject on PrivateData to fix segfault while keeping caching optimizations
* [FIX] Restore QObject as base class for all three PrivateData classes: - QwtText_PrivateData - QwtAbstractScaleDraw_PrivateData - QwtScaleDraw_PrivateData → resolves segfault during lifecycle / teardown
1 parent f5f6c44 commit 41bfe1e

2 files changed

Lines changed: 10 additions & 44 deletions

File tree

qwt/scale_draw.py

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
from qtpy.QtCore import (
2626
QLineF,
27+
QObject,
2728
QPoint,
2829
QPointF,
2930
QRect,
@@ -50,22 +51,11 @@
5051
_ALIGN_BOTTOM = int(Qt.AlignBottom)
5152

5253

53-
class QwtAbstractScaleDraw_PrivateData(object):
54-
# See QwtText_PrivateData: ``QObject`` inheritance is unused and the
55-
# base class' ``__init__`` is a measurable cost in tick-heavy renders.
56-
__slots__ = (
57-
"spacing",
58-
"penWidth",
59-
"minExtent",
60-
"components",
61-
"tick_length",
62-
"tick_lighter_factor",
63-
"map",
64-
"scaleDiv",
65-
"labelCache",
66-
)
54+
class QwtAbstractScaleDraw_PrivateData(QObject):
55+
# QObject base class restored for Qt parent/child ownership semantics.
6756

6857
def __init__(self):
58+
QObject.__init__(self)
6959
self.spacing = 4
7060
self.penWidth = 0
7161
self.minExtent = 0.0
@@ -492,20 +482,11 @@ def invalidateCache(self):
492482
self.__data.labelCache.clear()
493483

494484

495-
class QwtScaleDraw_PrivateData(object):
496-
# See QwtText_PrivateData: ``QObject`` inheritance is unused and the
497-
# base class' ``__init__`` is a measurable cost in tick-heavy renders.
498-
__slots__ = (
499-
"len",
500-
"alignment",
501-
"orientation",
502-
"labelAlignment",
503-
"labelRotation",
504-
"labelAutoSize",
505-
"pos",
506-
)
485+
class QwtScaleDraw_PrivateData(QObject):
486+
# QObject base class restored for Qt parent/child ownership semantics.
507487

508488
def __init__(self):
489+
QObject.__init__(self)
509490
self.len = 0
510491
self.alignment = QwtScaleDraw.BottomScale
511492
# Cached orientation - kept in sync by ``QwtScaleDraw.setAlignment``

qwt/text.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -557,26 +557,11 @@ def textMargins(self, font):
557557
return 0, 0, 0, 0
558558

559559

560-
class QwtText_PrivateData(object):
561-
# ``QObject`` was previously used as the base class but no Qt signals
562-
# or events are ever emitted from ``_PrivateData`` containers and the
563-
# ``QObject.__init__`` call dominates ``QwtText.__init__`` (it is the
564-
# single most expensive line for tick-label-heavy renders, see
565-
# https://github.com/PlotPyStack/PythonQwt/issues/93).
566-
__slots__ = (
567-
"renderFlags",
568-
"borderRadius",
569-
"borderPen",
570-
"backgroundBrush",
571-
"paintAttributes",
572-
"layoutAttributes",
573-
"textEngine",
574-
"text",
575-
"font",
576-
"color",
577-
)
560+
class QwtText_PrivateData(QObject):
561+
# QObject base class restored for Qt parent/child ownership semantics.
578562

579563
def __init__(self):
564+
QObject.__init__(self)
580565
self.renderFlags = Qt.AlignCenter
581566
self.borderRadius = 0
582567
self.borderPen = Qt.NoPen

0 commit comments

Comments
 (0)