PDA

View Full Version : setAxisScaleDiv - my scale div is invalid



frankiefrank
10th February 2011, 13:17
I'm using my own logic to have customized ticks on my scale:



// mTimeScaleDiv is a AxisScaleDiv member
mTimeScaleDiv.invalidate();
mTimeScaleDiv.setInterval(0, 40000);
QList<double> majorTicks;
QList<double> minorTicks;

for (int i = 0; i < (20 + 1); i++)
{
if (i % 5 == 0)
{
majorTicks.append(i * 2000);
}
else
{
minorTicks.append(i * 2000);
}
}

mTimeScaleDiv.setTicks(QwtScaleDiv::MajorTick, majorTicks);
mTimeScaleDiv.setTicks(QwtScaleDiv::MinorTick, minorTicks);

// This returns false - why?
bool isValid = mTimeScaleDiv.isValid();

setAxisScaleDiv(QwtPlot::xBottom, mTimeScaleDiv);


Could anyone help me with an explanation why the scale div I'm creating is set to invalid?

frankiefrank
11th February 2011, 12:33
I resolved this using a different way to initialize, taken from from one of the samples:



QList<double> ticks[QwtScaleDiv::NTickTypes];
QList<double> &majorTicks = ticks[QwtScaleDiv::MajorTick];
QList<double> &minorTicks = ticks[QwtScaleDiv::MinorTick];

for (int i = 0; i < (20 + 1); i++)
{
if (i % 5 == 0)
{
majorTicks.append(i * 2000);
}
else
{
minorTicks.append(i * 2000);
}
}

// mTimeScaleDiv is a AxisScaleDiv member
mTimeScaleDiv = QwtScaleDiv(majorTicks.first(), majorTicks.last(), ticks);
bool isValid = mTimeScaleDiv.isValid(); // For debug reasons

// Sets the updated plot
setAxisScaleDiv(QwtPlot::xBottom, mTimeScaleDiv);

Uwe
11th February 2011, 13:09
QwtScaleDiv::isValid() is used by the auto scaler inside of QwtPlot and has nothing to do with what everyone expects from the term "valid".

Of course this flag should be moved somewhere else with a better name.

Uwe

frankiefrank
11th February 2011, 13:43
Thank you for your reply.

My concern was not the flag itself, it was that I saw that while replotting, because of this invalid state my scale was generated automatically, and the ticks I defined were ignored. This happened with the first example of code I put in, but my resolved version doesn't have this problem.