Skip to content

Commit f23b52f

Browse files
committed
_PrivateData classes: prevent random segfaults by deriving from QObject
1 parent 4c40eb4 commit f23b52f

17 files changed

+102
-39
lines changed

qwt/color_map.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
:members:
2929
"""
3030

31-
from qtpy.QtCore import Qt, qIsNaN
31+
from qtpy.QtCore import QObject, Qt, qIsNaN
3232
from qtpy.QtGui import QColor, qAlpha, qBlue, qGreen, qRed, qRgb, qRgba
3333

3434

@@ -211,8 +211,10 @@ def colorIndex(self, interval, value):
211211
return 0
212212

213213

214-
class QwtLinearColorMap_PrivateData(object):
214+
class QwtLinearColorMap_PrivateData(QObject):
215215
def __init__(self):
216+
QObject.__init__(self)
217+
216218
self.colorStops = ColorStops()
217219
self.mode = None
218220

@@ -322,8 +324,10 @@ def colorIndex(self, interval, value):
322324
return int(ratio * 255 + 0.5)
323325

324326

325-
class QwtAlphaColorMap_PrivateData(object):
327+
class QwtAlphaColorMap_PrivateData(QObject):
326328
def __init__(self):
329+
QObject.__init__(self)
330+
327331
self.color = QColor()
328332
self.rgb = QColor().rgb()
329333
self.rgbMax = QColor().rgb()

qwt/column_symbol.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
# Copyright (c) 2015 Pierre Raybaut, for the Python translation/optimization
66
# (see LICENSE file for more details)
77

8-
from qtpy.QtCore import QLineF, QRectF, Qt
8+
from qtpy.QtCore import QLineF, QObject, QRectF, Qt
99
from qtpy.QtGui import QPalette, QPolygonF
1010

1111
from qwt.interval import QwtInterval
@@ -71,8 +71,10 @@ def qwtDrawPanel(painter, rect, pal, lw):
7171
painter.fillRect(rect.adjusted(lw, lw, -lw + 1, -lw + 1), pal.window())
7272

7373

74-
class QwtColumnSymbol_PrivateData(object):
74+
class QwtColumnSymbol_PrivateData(QObject):
7575
def __init__(self):
76+
QObject.__init__(self)
77+
7678
self.style = QwtColumnSymbol.Box
7779
self.frameStyle = QwtColumnSymbol.Raised
7880
self.lineWidth = 2

qwt/dyngrid_layout.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
:members:
1616
"""
1717

18-
from qtpy.QtCore import QRect, QSize, Qt
18+
from qtpy.QtCore import QObject, QRect, QSize, Qt
1919
from qtpy.QtWidgets import QLayout
2020

2121

22-
class QwtDynGridLayout_PrivateData(object):
22+
class QwtDynGridLayout_PrivateData(QObject):
2323
def __init__(self):
24+
QObject.__init__(self)
25+
2426
self.isDirty = True
2527
self.maxColumns = 0
2628
self.numRows = 0

qwt/graphic.py

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

1616
import math
1717

18-
from qtpy.QtCore import QPointF, QRect, QRectF, QSize, QSizeF, Qt
18+
from qtpy.QtCore import QObject, QPointF, QRect, QRectF, QSize, QSizeF, Qt
1919
from qtpy.QtGui import (
2020
QImage,
2121
QPaintEngine,
@@ -185,8 +185,9 @@ def scaleFactorY(self, pathRect, targetRect, scalePens):
185185
return sy
186186

187187

188-
class QwtGraphic_PrivateData(object):
188+
class QwtGraphic_PrivateData(QObject):
189189
def __init__(self):
190+
QObject.__init__(self)
190191
self.boundingRect = QRectF(0.0, 0.0, -1.0, -1.0)
191192
self.pointRect = QRectF(0.0, 0.0, -1.0, -1.0)
192193
self.initialTransform = None

qwt/legend.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import math
2323

24-
from qtpy.QtCore import QEvent, QPoint, QRect, QRectF, QSize, Qt, Signal
24+
from qtpy.QtCore import QEvent, QObject, QPoint, QRect, QRectF, QSize, Qt, Signal
2525

2626
# qDrawWinButton,
2727
from qtpy.QtGui import QPainter, QPalette, QPixmap
@@ -170,8 +170,10 @@ def buttonShift(w):
170170
return QSize(ph, pv)
171171

172172

173-
class QwtLegendLabel_PrivateData(object):
173+
class QwtLegendLabel_PrivateData(QObject):
174174
def __init__(self):
175+
QObject.__init__(self)
176+
175177
self.itemMode = QwtLegendData.ReadOnly
176178
self.isDown = False
177179
self.spacing = MARGIN
@@ -588,8 +590,10 @@ def layoutContents(self):
588590
self.contentsWidget.resize(w, h)
589591

590592

591-
class QwtLegend_PrivateData(object):
593+
class QwtLegend_PrivateData(QObject):
592594
def __init__(self):
595+
QObject.__init__(self)
596+
593597
self.itemMode = QwtLegendData.ReadOnly
594598
self.view = QwtDynGridLayout()
595599
self.itemMap = QwtLegendMap()

qwt/null_paintdevice.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515

1616
import os
1717

18+
from qtpy.QtCore import QObject
1819
from qtpy.QtGui import QPaintDevice, QPaintEngine, QPainterPath
1920

2021
QT_API = os.environ["QT_API"]
2122

2223

23-
class QwtNullPaintDevice_PrivateData(object):
24+
class QwtNullPaintDevice_PrivateData(QObject):
2425
def __init__(self):
26+
QObject.__init__(self)
27+
2528
self.mode = QwtNullPaintDevice.NormalMode
2629

2730

qwt/plot.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import math
2323

2424
import numpy as np
25-
from qtpy.QtCore import QEvent, QRectF, QSize, Qt, Signal
25+
from qtpy.QtCore import QEvent, QObject, QRectF, QSize, Qt, Signal
2626
from qtpy.QtGui import QBrush, QColor, QFont, QPainter, QPalette
2727
from qtpy.QtWidgets import QApplication, QFrame, QSizePolicy, QWidget
2828

@@ -75,9 +75,10 @@ def removeItem(self, obj):
7575
self.sortItems()
7676

7777

78-
class QwtPlot_PrivateData(object):
78+
class QwtPlot_PrivateData(QObject):
7979
def __init__(self):
80-
super(QwtPlot_PrivateData, self).__init__()
80+
QObject.__init__(self)
81+
8182
self.itemList = ItemList()
8283
self.titleLabel = None
8384
self.footerLabel = None
@@ -1691,8 +1692,10 @@ def exportTo(
16911692
renderer.renderDocument(self, filename, size_mm, resolution, format_)
16921693

16931694

1694-
class QwtPlotItem_PrivateData(object):
1695+
class QwtPlotItem_PrivateData(QObject):
16951696
def __init__(self):
1697+
QObject.__init__(self)
1698+
16961699
self.plot = None
16971700
self.isVisible = True
16981701
self.attributes = 0

qwt/plot_canvas.py

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

1616
import os
1717

18-
from qtpy.QtCore import QEvent, QPoint, QPointF, QRect, QRectF, QSize, Qt
18+
from qtpy.QtCore import QEvent, QObject, QPoint, QPointF, QRect, QRectF, QSize, Qt
1919
from qtpy.QtGui import (
2020
QBrush,
2121
QGradient,
@@ -329,8 +329,10 @@ def __init__(self):
329329
self.background = StyleSheetBackground()
330330

331331

332-
class QwtPlotCanvas_PrivateData(object):
332+
class QwtPlotCanvas_PrivateData(QObject):
333333
def __init__(self):
334+
QObject.__init__(self)
335+
334336
self.focusIndicator = QwtPlotCanvas.NoFocusIndicator
335337
self.borderRadius = 0
336338
self.paintAttributes = 0

qwt/plot_directpainter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def qwtHasBackingStore(canvas):
3939
)
4040

4141

42-
class QwtPlotDirectPainter_PrivateData(object):
42+
class QwtPlotDirectPainter_PrivateData(QObject):
4343
def __init__(self):
44+
QObject.__init__(self)
45+
4446
self.attributes = 0
4547
self.hasClipping = False
4648
self.seriesItem = None # QwtPlotSeriesItem

qwt/plot_grid.py

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

16-
from qtpy.QtCore import QLineF, Qt
16+
from qtpy.QtCore import QLineF, QObject, Qt
1717
from qtpy.QtGui import QPen
1818

1919
from qwt._math import qwtFuzzyGreaterOrEqual, qwtFuzzyLessOrEqual
@@ -22,8 +22,10 @@
2222
from qwt.scale_div import QwtScaleDiv
2323

2424

25-
class QwtPlotGrid_PrivateData(object):
25+
class QwtPlotGrid_PrivateData(QObject):
2626
def __init__(self):
27+
QObject.__init__(self)
28+
2729
self.xEnabled = True
2830
self.yEnabled = True
2931
self.xMinEnabled = False

0 commit comments

Comments
 (0)