Skip to content

Commit

Permalink
Handled deprecated QWidget.getContentsMargins
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Oct 10, 2023
1 parent eb630b5 commit a380e06
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# PythonQwt Releases

## Version 0.10.6

- Handled all occurences of deprecated ``QWidget.getContentsMargins`` method.

## Version 0.10.5

- [Issue #81](https://github.com/PlotPyStack/PythonQwt/issues/81) - Signal disconnection issue with PySide 6.5.3
Expand Down
2 changes: 1 addition & 1 deletion qwt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
.. _GitHub: https://github.com/PlotPyStack/PythonQwt
"""

__version__ = "0.10.5"
__version__ = "0.10.6"
QWT_VERSION_STR = "6.1.5"

import warnings
Expand Down
8 changes: 5 additions & 3 deletions qwt/dyngrid_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,11 @@ def stretchGrid(self, rect, numColumns, rowHeight, colWidth):
return
expandH = self.expandingDirections() & Qt.Horizontal
expandV = self.expandingDirections() & Qt.Vertical
mleft, mtop, mright, mbottom = self.getContentsMargins()
margins = self.contentsMargins()
wmargins = margins.left() + margins.right()
hmargins = margins.top() + margins.bottom()
if expandH:
xDelta = rect.width() - (mleft + mright) - (numColumns - 1) * self.spacing()
xDelta = rect.width() - wmargins - (numColumns - 1) * self.spacing()
for col in range(numColumns):
xDelta -= colWidth[col]
if xDelta > 0:
Expand All @@ -313,7 +315,7 @@ def stretchGrid(self, rect, numColumns, rowHeight, colWidth):
numRows = self.itemCount() / numColumns
if self.itemCount() % numColumns:
numRows += 1
yDelta = rect.height() - (mtop + mbottom) - (numRows - 1) * self.spacing()
yDelta = rect.height() - hmargins - (numRows - 1) * self.spacing()
for row in range(numRows):
yDelta -= rowHeight[row]
if yDelta > 0:
Expand Down
16 changes: 9 additions & 7 deletions qwt/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,8 @@ def setSpacing(self, spacing):
spacing = max([spacing, 0])
if spacing != self.__data.spacing:
self.__data.spacing = spacing
margin = max(self.getContentsMargins())
mgn = self.contentsMargins()
margin = max([mgn.left(), mgn.top(), mgn.right(), mgn.bottom()])
indent = margin + self.__data.spacing
if self.__data.icon.width() > 0:
indent += self.__data.icon.width() + self.__data.spacing
Expand Down Expand Up @@ -912,12 +913,12 @@ def renderLegend(self, painter, rect, fillBackground):
legendLayout = self.__data.view.contentsWidget.layout()
if legendLayout is None:
return
left, right, top, bottom = self.layout().getContentsMargins()
margins = self.layout().contentsMargins()
layoutRect = QRect()
layoutRect.setLeft(math.ceil(rect.left()) + left)
layoutRect.setTop(math.ceil(rect.top()) + top)
layoutRect.setRight(math.ceil(rect.right()) - right)
layoutRect.setBottom(math.ceil(rect.bottom()) - bottom)
layoutRect.setLeft(math.ceil(rect.left()) + margins.left())
layoutRect.setTop(math.ceil(rect.top()) + margins.top())
layoutRect.setRight(math.ceil(rect.right()) - margins.right())
layoutRect.setBottom(math.ceil(rect.bottom()) - margins.bottom())
numCols = legendLayout.columnsForWidth(layoutRect.width())
itemRects = legendLayout.layoutItems(layoutRect, numCols)
index = 0
Expand Down Expand Up @@ -949,7 +950,8 @@ def renderItem(self, painter, widget, rect, fillBackground):
if label is not None:
icon = label.data().icon()
sz = icon.defaultSize()
margin = max(label.getContentsMargins())
mgn = label.contentsMargins()
margin = max([mgn.left(), mgn.top(), mgn.right(), mgn.bottom()])
iconRect = QRectF(
rect.x() + margin,
rect.center().y() - 0.5 * sz.height(),
Expand Down
10 changes: 8 additions & 2 deletions qwt/plot_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,10 @@ def init(self, plot, rect):
self.scale[axis].dimWithoutTitle = 0
layout = plot.canvas().layout()
if layout is not None:
self.canvas.contentsMargins = layout.getContentsMargins()
mgn = layout.contentsMargins()
self.canvas.contentsMargins = [
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
]


class QwtPlotLayout_PrivateData(object):
Expand Down Expand Up @@ -571,7 +574,10 @@ def __init__(self):
if layout is None:
left, top, right, bottom = 0, 0, 0, 0
else:
left, top, right, bottom = layout.getContentsMargins()
mgn = layout.contentsMargins()
left, top, right, bottom = (
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
)
for axis in QwtPlot.AXES:
if plot.axisEnabled(axis):
scl = plot.axisWidget(axis)
Expand Down
14 changes: 10 additions & 4 deletions qwt/plot_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,8 @@ def render(self, plot, painter, plotRect):
invtrans, _ok = transform.inverted()
layoutRect = invtrans.mapRect(plotRect)
if not (self.__data.discardFlags & self.DiscardBackground):
left, top, right, bottom = plot.getContentsMargins()
layoutRect.adjust(left, top, -right, -bottom)
mg = plot.contentsMargins()
layoutRect.adjust(mg.left(), mg.top(), -mg.right(), -mg.bottom())

layout = plot.plotLayout()
baseLineDists = canvasMargins = [None] * len(QwtPlot.AXES)
Expand All @@ -367,7 +367,10 @@ def render(self, plot, painter, plotRect):
if self.__data.layoutFlags & self.FrameWithScales:
scaleWidget = plot.axisWidget(axisId)
if scaleWidget:
baseLineDists[axisId] = max(scaleWidget.getContentsMargins())
mgn = scaleWidget.contentsMargins()
baseLineDists[axisId] = max([
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
])
scaleWidget.setMargin(0)
if not plot.axisEnabled(axisId):
# When we have a scale the frame is painted on
Expand Down Expand Up @@ -430,7 +433,10 @@ def render(self, plot, painter, plotRect):
for axisId in QwtPlot.AXES:
scaleWidget = plot.axisWidget(axisId)
if scaleWidget:
baseDist = max(scaleWidget.getContentsMargins())
mgn = scaleWidget.contentsMargins()
baseDist = max([
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
])
startDist, endDist = scaleWidget.getBorderDistHint()
self.renderScale(
plot,
Expand Down
5 changes: 4 additions & 1 deletion qwt/scale_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,10 @@ def minimumSizeHint(self):
if self.layout() is None:
left, top, right, bottom = 0, 0, 0, 0
else:
left, top, right, bottom = self.layout().getContentsMargins()
mgn = self.layout().contentsMargins()
left, top, right, bottom = (
mgn.left(), mgn.top(), mgn.right(), mgn.bottom()
)
return size + QSize(left + right, top + bottom)

def titleHeightForWidth(self, width):
Expand Down

0 comments on commit a380e06

Please sign in to comment.