Hello!
For some reason, autoscaling is not working for a specific QwtPlot I'm using. I checked the code again and again and certified that in no place the auto scaling is withdraw, either by a call to QwtPlot::setAutoScale(...,false) or by QwtPlot::setAxisScale().
Guessing about what may be causing the problem, I noticed that auto scalling works by calculating the boundary rectangle of the QwtPlotCurve's data. Here two points need to be noticed: I'm not using QwtPlotCurve directly, but a subclass with the only difference that it has drawLines reimplemented; and I'm using setRawData(...) to set the curve's data instead of setSamples(...) and the like (I need fast plotting).
Could one of this two changes be the one creating the problem? If so, how may I solve it? And if not, what else could be doing this?
It's also interesting to notice that the auto scaling actually works only once, when the graph is shown for the first time, and it correctly scales to the current data related to the visible curves (the reason why I think the use of setRawData has nothing to do with it). After that, tough, if the curve changes its range, no matter how many times replot() is called, the scales are never updated (even when updateAxis() is called directly). Here are the methods that are called when the plot is make visible:
void ScopeGraphArea::slotSetItemVisible(const ButtonId id, const bool visible)
{
multiGraph->enableCurve(id,visible);
multiGraph->updateAxisVisibility();
}
void enableCurve(const int curve, const bool enable)
{
if (curve < 0)
return;
if (enable)
{
curveList[curve]->attach(this);
curveList[curve]->show();
}
else
{
curveList[curve]->detach();
curveList[curve]->hide();
}
if (curveList
[curve
]->yAxis
() == QwtPlot::yLeft) yLeftEnabled = enable;
else //if (curveList[curve]->yAxis() == QwtPlot::yRight)
yRightEnabled = enable;
refreshGraphVisibility(enable);
replot();
}
void refreshGraphVisibility(const bool lastCurveEnabled = false)
{
if (lastCurveEnabled) //Provided for efficiency
{
show();
return;
}
bool isOneVisible = false;
for (int aaa = 0; aaa < curveList.size(); aaa++)
{
if (curveList.at(aaa)->isVisible())
{
isOneVisible = true;
break;
}
}
setVisible(isOneVisible);
}
virtual void updateAxisVisibility()
{
bool yLeftvisible = false, yRightVisible = false;
foreach(QwtPlotCurveSpecial* poCurve, curveList)
{
if (poCurve
->isVisible
() && poCurve
->yAxis
() == QwtPlot::yLeft) yLeftvisible = true;
else if (poCurve
->isVisible
() && poCurve
->yAxis
() == QwtPlot::yRight) yRightVisible = true;
}
enableAxis
(QwtPlot::yLeft,yLeftvisible
);
enableAxis
(QwtPlot::yRight,yRightVisible
);
}
void ScopeGraphArea::slotSetItemVisible(const ButtonId id, const bool visible)
{
multiGraph->enableCurve(id,visible);
multiGraph->updateAxisVisibility();
}
void enableCurve(const int curve, const bool enable)
{
if (curve < 0)
return;
if (enable)
{
curveList[curve]->attach(this);
curveList[curve]->show();
}
else
{
curveList[curve]->detach();
curveList[curve]->hide();
}
if (curveList[curve]->yAxis() == QwtPlot::yLeft)
yLeftEnabled = enable;
else //if (curveList[curve]->yAxis() == QwtPlot::yRight)
yRightEnabled = enable;
refreshGraphVisibility(enable);
replot();
}
void refreshGraphVisibility(const bool lastCurveEnabled = false)
{
if (lastCurveEnabled) //Provided for efficiency
{
show();
return;
}
bool isOneVisible = false;
for (int aaa = 0; aaa < curveList.size(); aaa++)
{
if (curveList.at(aaa)->isVisible())
{
isOneVisible = true;
break;
}
}
setVisible(isOneVisible);
}
virtual void updateAxisVisibility()
{
bool yLeftvisible = false, yRightVisible = false;
foreach(QwtPlotCurveSpecial* poCurve, curveList)
{
if (poCurve->isVisible() && poCurve->yAxis() == QwtPlot::yLeft)
yLeftvisible = true;
else if (poCurve->isVisible() && poCurve->yAxis() == QwtPlot::yRight)
yRightVisible = true;
}
enableAxis(QwtPlot::yLeft,yLeftvisible);
enableAxis(QwtPlot::yRight,yRightVisible);
}
To copy to clipboard, switch view to plain text mode
I'm glad for any help
Thanks,
Momergil
Bookmarks