Skip to content

Commit

Permalink
_PrivateData classes: prevent random segfaults by deriving from QObject
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Jul 26, 2024
1 parent 4c40eb4 commit f23b52f
Show file tree
Hide file tree
Showing 17 changed files with 102 additions and 39 deletions.
10 changes: 7 additions & 3 deletions qwt/color_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
:members:
"""

from qtpy.QtCore import Qt, qIsNaN
from qtpy.QtCore import QObject, Qt, qIsNaN
from qtpy.QtGui import QColor, qAlpha, qBlue, qGreen, qRed, qRgb, qRgba


Expand Down Expand Up @@ -211,8 +211,10 @@ def colorIndex(self, interval, value):
return 0


class QwtLinearColorMap_PrivateData(object):
class QwtLinearColorMap_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.colorStops = ColorStops()
self.mode = None

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


class QwtAlphaColorMap_PrivateData(object):
class QwtAlphaColorMap_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.color = QColor()
self.rgb = QColor().rgb()
self.rgbMax = QColor().rgb()
Expand Down
6 changes: 4 additions & 2 deletions qwt/column_symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Copyright (c) 2015 Pierre Raybaut, for the Python translation/optimization
# (see LICENSE file for more details)

from qtpy.QtCore import QLineF, QRectF, Qt
from qtpy.QtCore import QLineF, QObject, QRectF, Qt
from qtpy.QtGui import QPalette, QPolygonF

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


class QwtColumnSymbol_PrivateData(object):
class QwtColumnSymbol_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.style = QwtColumnSymbol.Box
self.frameStyle = QwtColumnSymbol.Raised
self.lineWidth = 2
Expand Down
6 changes: 4 additions & 2 deletions qwt/dyngrid_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
:members:
"""

from qtpy.QtCore import QRect, QSize, Qt
from qtpy.QtCore import QObject, QRect, QSize, Qt
from qtpy.QtWidgets import QLayout


class QwtDynGridLayout_PrivateData(object):
class QwtDynGridLayout_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.isDirty = True
self.maxColumns = 0
self.numRows = 0
Expand Down
5 changes: 3 additions & 2 deletions qwt/graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import math

from qtpy.QtCore import QPointF, QRect, QRectF, QSize, QSizeF, Qt
from qtpy.QtCore import QObject, QPointF, QRect, QRectF, QSize, QSizeF, Qt
from qtpy.QtGui import (
QImage,
QPaintEngine,
Expand Down Expand Up @@ -185,8 +185,9 @@ def scaleFactorY(self, pathRect, targetRect, scalePens):
return sy


class QwtGraphic_PrivateData(object):
class QwtGraphic_PrivateData(QObject):
def __init__(self):
QObject.__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.initialTransform = None
Expand Down
10 changes: 7 additions & 3 deletions qwt/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import math

from qtpy.QtCore import QEvent, QPoint, QRect, QRectF, QSize, Qt, Signal
from qtpy.QtCore import QEvent, QObject, QPoint, QRect, QRectF, QSize, Qt, Signal

# qDrawWinButton,
from qtpy.QtGui import QPainter, QPalette, QPixmap
Expand Down Expand Up @@ -170,8 +170,10 @@ def buttonShift(w):
return QSize(ph, pv)


class QwtLegendLabel_PrivateData(object):
class QwtLegendLabel_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.itemMode = QwtLegendData.ReadOnly
self.isDown = False
self.spacing = MARGIN
Expand Down Expand Up @@ -588,8 +590,10 @@ def layoutContents(self):
self.contentsWidget.resize(w, h)


class QwtLegend_PrivateData(object):
class QwtLegend_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.itemMode = QwtLegendData.ReadOnly
self.view = QwtDynGridLayout()
self.itemMap = QwtLegendMap()
Expand Down
5 changes: 4 additions & 1 deletion qwt/null_paintdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

import os

from qtpy.QtCore import QObject
from qtpy.QtGui import QPaintDevice, QPaintEngine, QPainterPath

QT_API = os.environ["QT_API"]


class QwtNullPaintDevice_PrivateData(object):
class QwtNullPaintDevice_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.mode = QwtNullPaintDevice.NormalMode


Expand Down
11 changes: 7 additions & 4 deletions qwt/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import math

import numpy as np
from qtpy.QtCore import QEvent, QRectF, QSize, Qt, Signal
from qtpy.QtCore import QEvent, QObject, QRectF, QSize, Qt, Signal
from qtpy.QtGui import QBrush, QColor, QFont, QPainter, QPalette
from qtpy.QtWidgets import QApplication, QFrame, QSizePolicy, QWidget

Expand Down Expand Up @@ -75,9 +75,10 @@ def removeItem(self, obj):
self.sortItems()


class QwtPlot_PrivateData(object):
class QwtPlot_PrivateData(QObject):
def __init__(self):
super(QwtPlot_PrivateData, self).__init__()
QObject.__init__(self)

self.itemList = ItemList()
self.titleLabel = None
self.footerLabel = None
Expand Down Expand Up @@ -1691,8 +1692,10 @@ def exportTo(
renderer.renderDocument(self, filename, size_mm, resolution, format_)


class QwtPlotItem_PrivateData(object):
class QwtPlotItem_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.plot = None
self.isVisible = True
self.attributes = 0
Expand Down
6 changes: 4 additions & 2 deletions qwt/plot_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import os

from qtpy.QtCore import QEvent, QPoint, QPointF, QRect, QRectF, QSize, Qt
from qtpy.QtCore import QEvent, QObject, QPoint, QPointF, QRect, QRectF, QSize, Qt
from qtpy.QtGui import (
QBrush,
QGradient,
Expand Down Expand Up @@ -329,8 +329,10 @@ def __init__(self):
self.background = StyleSheetBackground()


class QwtPlotCanvas_PrivateData(object):
class QwtPlotCanvas_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.focusIndicator = QwtPlotCanvas.NoFocusIndicator
self.borderRadius = 0
self.paintAttributes = 0
Expand Down
4 changes: 3 additions & 1 deletion qwt/plot_directpainter.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def qwtHasBackingStore(canvas):
)


class QwtPlotDirectPainter_PrivateData(object):
class QwtPlotDirectPainter_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.attributes = 0
self.hasClipping = False
self.seriesItem = None # QwtPlotSeriesItem
Expand Down
6 changes: 4 additions & 2 deletions qwt/plot_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:members:
"""

from qtpy.QtCore import QLineF, Qt
from qtpy.QtCore import QLineF, QObject, Qt
from qtpy.QtGui import QPen

from qwt._math import qwtFuzzyGreaterOrEqual, qwtFuzzyLessOrEqual
Expand All @@ -22,8 +22,10 @@
from qwt.scale_div import QwtScaleDiv


class QwtPlotGrid_PrivateData(object):
class QwtPlotGrid_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.xEnabled = True
self.yEnabled = True
self.xMinEnabled = False
Expand Down
6 changes: 4 additions & 2 deletions qwt/plot_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import math

from qtpy.QtCore import QRectF, QSize, Qt
from qtpy.QtCore import QObject, QRectF, QSize, Qt
from qtpy.QtGui import QFont, QRegion

from qwt.plot import QwtPlot
Expand Down Expand Up @@ -143,8 +143,10 @@ def init(self, plot, rect):
]


class QwtPlotLayout_PrivateData(object):
class QwtPlotLayout_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.spacing = 5
self.titleRect = QRectF()
self.footerRect = QRectF()
Expand Down
6 changes: 4 additions & 2 deletions qwt/plot_marker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
:members:
"""

from qtpy.QtCore import QLineF, QPointF, QRect, QRectF, QSizeF, Qt
from qtpy.QtCore import QLineF, QObject, QPointF, QRect, QRectF, QSizeF, Qt
from qtpy.QtGui import QPainter, QPen

from qwt.graphic import QwtGraphic
Expand All @@ -23,8 +23,10 @@
from qwt.text import QwtText


class QwtPlotMarker_PrivateData(object):
class QwtPlotMarker_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.labelAlignment = Qt.AlignCenter
self.labelOrientation = Qt.Horizontal
self.spacing = 2
Expand Down
4 changes: 3 additions & 1 deletion qwt/plot_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@ def qwtCanvasClip(canvas, canvasRect):
return canvas.borderPath(r)


class QwtPlotRenderer_PrivateData(object):
class QwtPlotRenderer_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.discardFlags = QwtPlotRenderer.DiscardNone
self.layoutFlags = QwtPlotRenderer.DefaultLayout

Expand Down
25 changes: 20 additions & 5 deletions qwt/scale_draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,16 @@

import math

from qtpy.QtCore import QLineF, QPoint, QPointF, QRect, QRectF, Qt, qFuzzyCompare
from qtpy.QtCore import (
QLineF,
QObject,
QPoint,
QPointF,
QRect,
QRectF,
Qt,
qFuzzyCompare,
)
from qtpy.QtGui import QFontMetrics, QPalette, QTransform

from qwt._math import qwtRadians
Expand All @@ -30,8 +39,10 @@
from qwt.text import QwtText


class QwtAbstractScaleDraw_PrivateData(object):
class QwtAbstractScaleDraw_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.spacing = 4
self.penWidth = 0
self.minExtent = 0.0
Expand Down Expand Up @@ -233,7 +244,8 @@ def draw(self, painter, palette):
Draw the scale
:param QPainter painter: The painter
:param QPalette palette: Palette, text color is used for the labels, foreground color for ticks and backbone
:param QPalette palette: Palette, text color is used for the labels,
foreground color for ticks and backbone
"""
painter.save()

Expand Down Expand Up @@ -457,8 +469,10 @@ def invalidateCache(self):
self.__data.labelCache.clear()


class QwtScaleDraw_PrivateData(object):
class QwtScaleDraw_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.len = 0
self.alignment = QwtScaleDraw.BottomScale
self.labelAlignment = 0
Expand Down Expand Up @@ -1048,7 +1062,8 @@ def setLabelRotation(self, rotation):
adjust the label flags too. Finding a useful combination is
often the result of try and error.
:param float rotation: Angle in degrees. When changing the label rotation, the label flags often needs to be adjusted too.
:param float rotation: Angle in degrees. When changing the label rotation, the
label flags often needs to be adjusted too.
.. seealso::
Expand Down
6 changes: 4 additions & 2 deletions qwt/scale_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import math

from qtpy.QtCore import QRectF, QSize, Qt, Signal
from qtpy.QtCore import QObject, QRectF, QSize, Qt, Signal
from qtpy.QtGui import QPainter, QPalette
from qtpy.QtWidgets import QSizePolicy, QStyle, QStyleOption, QWidget

Expand All @@ -35,8 +35,10 @@ def __init__(self):
self.colorMap = QwtColorMap()


class QwtScaleWidget_PrivateData(object):
class QwtScaleWidget_PrivateData(QObject):
def __init__(self):
QObject.__init__(self)

self.scaleDraw = None
self.borderDist = [None] * 2
self.minBorderDist = [None] * 2
Expand Down
15 changes: 13 additions & 2 deletions qwt/symbol.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,17 @@

import math

from qtpy.QtCore import QLineF, QPoint, QPointF, QRect, QRectF, QSize, QSizeF, Qt
from qtpy.QtCore import (
QLineF,
QObject,
QPoint,
QPointF,
QRect,
QRectF,
QSize,
QSizeF,
Qt,
)
from qtpy.QtGui import (
QBrush,
QPainter,
Expand Down Expand Up @@ -334,8 +344,9 @@ def qwtDrawHexagonSymbols(painter, points, symbol):
painter.drawPolygon(QPolygonF(hexa))


class QwtSymbol_PrivateData(object):
class QwtSymbol_PrivateData(QObject):
def __init__(self, st, br, pn, sz):
QObject.__init__(self)
self.style = st
self.size = sz
self.brush = br
Expand Down
Loading

0 comments on commit f23b52f

Please sign in to comment.