Skip to content

Commit

Permalink
GraphPanel widget: get GraphPanelPlotWidget::dataRect() and GraphPane…
Browse files Browse the repository at this point in the history
…lPlotWidget::dataLogRect() to tell us whether they are returning something meaningful (#1412).

Indeed, the problem was that when running a simulation with a big simulation delay, then the first time we would call GraphPanelPlotWidget::dataRect() or GraphPanelPlotWidget::dataLogRect(), we would end up with QRectF(minX, minY, maxX-minX, maxY-minY) where minX = maxX and minY = maxY, which when tested using QRectF::isNull() would return true while we didn't want that. Although the values result in 'null', they are actually meaningful to us.
  • Loading branch information
agarny committed Oct 4, 2017
1 parent 5333b33 commit 6e90896
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3014,9 +3014,9 @@ bool SimulationExperimentViewSimulationWidget::updatePlot(GraphPanelWidget::Grap
double minY = GraphPanelWidget::DefaultMinAxis;
double maxY = GraphPanelWidget::DefaultMaxAxis;

QRectF dataRect = pPlot->dataRect();
QRectF dataRect = QRectF();

if (!dataRect.isNull()) {
if (pPlot->dataRect(dataRect)) {
minX = dataRect.left();
maxX = minX+dataRect.width();
minY = dataRect.top();
Expand All @@ -3028,9 +3028,9 @@ bool SimulationExperimentViewSimulationWidget::updatePlot(GraphPanelWidget::Grap
double minLogY = GraphPanelWidget::DefaultMinLogAxis;
double maxLogY = GraphPanelWidget::DefaultMaxAxis;

QRectF dataLogRect = pPlot->dataLogRect();
QRectF dataLogRect = QRectF();

if (!dataLogRect.isNull()) {
if (pPlot->dataLogRect(dataLogRect)) {
minLogX = dataLogRect.left();
maxLogX = minLogX+dataLogRect.width();
minLogY = dataLogRect.top();
Expand Down
32 changes: 21 additions & 11 deletions src/plugins/widget/GraphPanelWidget/src/graphpanelplotwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1116,33 +1116,43 @@ bool GraphPanelPlotWidget::hasData() const

//==============================================================================

QRectF GraphPanelPlotWidget::dataRect() const
bool GraphPanelPlotWidget::dataRect(QRectF &pDataRect) const
{
// Determine and return the rectangle within which all the graphs, which are
// valid, selected and have some data, can fit

QRectF res = QRectF();
bool res = false;

pDataRect = QRectF();

foreach (GraphPanelPlotGraph *graph, mGraphs) {
if (graph->isValid() && graph->isSelected() && graph->dataSize())
res |= graph->boundingRect();
if (graph->isValid() && graph->isSelected() && graph->dataSize()) {
pDataRect |= graph->boundingRect();

res = true;
}
}

return res;
}

//==============================================================================

QRectF GraphPanelPlotWidget::dataLogRect() const
bool GraphPanelPlotWidget::dataLogRect(QRectF &pDataLogRect) const
{
// Determine and return the log rectangle within which all the graphs, which
// are valid, selected and have some data, can fit

QRectF res = QRectF();
bool res = false;

pDataLogRect = QRectF();

foreach (GraphPanelPlotGraph *graph, mGraphs) {
if (graph->isValid() && graph->isSelected() && graph->dataSize())
res |= graph->boundingLogRect();
if (graph->isValid() && graph->isSelected() && graph->dataSize()) {
pDataLogRect |= graph->boundingLogRect();

res = true;
}
}

return res;
Expand All @@ -1155,10 +1165,10 @@ QRectF GraphPanelPlotWidget::realDataRect() const
// Return an optimised version of dataRect() or a default rectangle, if no
// dataRect() exists

QRectF dRect = dataRect();
QRectF dLogRect = dataLogRect();
QRectF dRect = QRectF();
QRectF dLogRect = QRectF();

if (dRect.isNull()) {
if (dataRect(dRect) && dataLogRect(dLogRect)) {
double minX = logAxisX()?mDefaultMinLogX:mDefaultMinX;
double maxX = logAxisX()?mDefaultMaxLogX:mDefaultMaxX;
double minY = logAxisY()?mDefaultMinLogY:mDefaultMinY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ class GRAPHPANELWIDGET_EXPORT GraphPanelPlotWidget : public QwtPlot,

bool hasData() const;

QRectF dataRect() const;
QRectF dataLogRect() const;
bool dataRect(QRectF &pDataRect) const;
bool dataLogRect(QRectF &pDataLogRect) const;

void optimiseAxis(double &pMin, double &pMax) const;

Expand Down

0 comments on commit 6e90896

Please sign in to comment.