Skip to content

Commit 420109c

Browse files
author
Pierre Raybaut
committed
Optimization/QwtPlot: updating layout only when necessary (contentsRect changed,
plot title, footer, axes titles (or axes enable state), legend changed)
1 parent 1e9fa3e commit 420109c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

qwt/qwt_plot.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def __init__(self, *args):
152152
QwtPlotDict.__init__(self)
153153
QFrame.__init__(self, parent)
154154

155+
self.__layout_state = None
156+
155157
self.__data = QwtPlot_PrivateData()
156158
from qwt.qwt_plot_layout import QwtPlotLayout
157159
self.__data.layout = QwtPlotLayout()
@@ -573,8 +575,21 @@ def replot(self):
573575
self.__data.canvas.update(self.__data.canvas.contentsRect())
574576

575577
self.setAutoReplot(doAutoReplot)
578+
579+
def get_layout_state(self):
580+
return (self.contentsRect(),
581+
self.__data.titleLabel.text(), self.__data.footerLabel.text(),
582+
[(self.axisEnabled(axisId), self.axisTitle(axisId).text())
583+
for axisId in range(self.axisCnt)],
584+
self.__data.legend)
576585

577586
def updateLayout(self):
587+
state = self.get_layout_state()
588+
if self.__layout_state is not None and\
589+
state == self.__layout_state:
590+
return
591+
self.__layout_state = state
592+
578593
self.__data.layout.activate(self, self.contentsRect())
579594

580595
titleRect = self.__data.layout.titleRect().toRect()

qwt/qwt_plot_layout.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def __init__(self):
318318
ch = max([scaleData[QwtPlot.yLeft].h,
319319
scaleData[QwtPlot.yRight].h]) + top + 1 + bottom + 1
320320
h += max([ch, minCanvasSize.height()])
321-
labels = [plot.titleLabel(), plot.footerLabel()]
322-
for label in labels:
321+
for label in [plot.titleLabel(), plot.footerLabel()]:
323322
if label and not label.text().isEmpty():
324323
centerOnCanvas = not plot.axisEnabled(QwtPlot.yLeft)\
325324
and plot.axisEnabled(QwtPlot.yRight)

0 commit comments

Comments
 (0)