Skip to content

Commit

Permalink
Graph Panel widget: improved the alignment of a graph panel with its …
Browse files Browse the repository at this point in the history
…neighbours.

Indeed, when running the model in issue #1630, the X axis of the first
graph panel was flashing on macOS for a bit before becoming "stable",
due to our call to xScaleWidget->setMinBorderDist(0, 0). So, we had to
find another way of doing things without that call...
  • Loading branch information
agarny committed May 2, 2018
1 parent 0ba67a8 commit 609b4d5
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions src/plugins/widget/GraphPanelWidget/src/graphpanelplotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3252,19 +3252,37 @@ void GraphPanelPlotWidget::alignWithNeighbors(bool pCanReplot,
axisWidget(QwtPlot::xBottom)->getMinBorderDist(oldMinBorderDistStartX, oldMinBorderDistEndX);

foreach (GraphPanelPlotWidget *plot, selfPlusNeighbors) {
#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
plot->setUpdatesEnabled(false);
// Note #1: this is needed on Windows and Linux otherwise to resize our
// graph panels will result in the X axis flashing due to our
// call to xScaleWidget->setMinBorderDist(0, 0) below...
// Note #2: to have this on macOS may result in a graph panel becoming
// black, so we definitely don't want to do it on that
// platform...
#endif
// Determine how much space we should have directly to the left and
// right of the X axis
// Note: normally, we would initialise minBorderDistStartX and
// minBorderDistEndX with a call to
// xScaleWidget->getBorderDistHint(), but for that call to work as
// expected it would have to preceded by a call to
// xScaleWidget->setMinBorderDist(0, 0). Yet, that call may result
// in one or several graph panels to be refreshed, yielding the X
// axis to be temporarily rendered too far to the left. So, to
// avoid this problem, we initialise minBorderDistStartX and
// minBorderDistEndX with a call to
// xScaleWidget->scaleDraw()->getBorderDistHint() and then
// "manually" check the values of minBorderDistStartX and
// minBorderDistEndX against zero...

QwtScaleWidget *xScaleWidget = plot->axisWidget(QwtPlot::xBottom);
int minBorderDistStartX;
int minBorderDistEndX;

xScaleWidget->scaleDraw()->getBorderDistHint(xScaleWidget->font(), minBorderDistStartX, minBorderDistEndX);

if (minBorderDistStartX < 0)
minBorderDistStartX = 0;

if (minBorderDistEndX < 0)
minBorderDistEndX = 0;

newMinBorderDistStartX = qMax(newMinBorderDistStartX, minBorderDistStartX);
newMinBorderDistEndX = qMax(newMinBorderDistEndX, minBorderDistEndX);

xScaleWidget->setMinBorderDist(0, 0);
// Determine how much space we should have to the left of the Y axis

QwtScaleWidget *yScaleWidget = plot->axisWidget(QwtPlot::yLeft);
QwtScaleDraw *yScaleDraw = yScaleWidget->scaleDraw();
Expand All @@ -3275,14 +3293,6 @@ void GraphPanelPlotWidget::alignWithNeighbors(bool pCanReplot,
// Note: this ensures that our major ticks (which are used to compute
// the extent) are up to date...

int minBorderDistStartX;
int minBorderDistEndX;

xScaleWidget->getBorderDistHint(minBorderDistStartX, minBorderDistEndX);

newMinBorderDistStartX = qMax(newMinBorderDistStartX, minBorderDistStartX);
newMinBorderDistEndX = qMax(newMinBorderDistEndX, minBorderDistEndX);

double minExtentY = yScaleDraw->extent(yScaleWidget->font())
+(plot->titleAxisY().isEmpty()?
0:
Expand Down Expand Up @@ -3322,10 +3332,6 @@ void GraphPanelPlotWidget::alignWithNeighbors(bool pCanReplot,
replot();
}
}

#if defined(Q_OS_WIN) || defined(Q_OS_LINUX)
plot->setUpdatesEnabled(true);
#endif
}
}

Expand Down

0 comments on commit 609b4d5

Please sign in to comment.