Issue with QwtPlot::setAxisScaleDiv();
Hello,
I'm using Qt 4.8.2 with Qwt 6.0.1.
I'm trying to create grid and scale based upon dimensions of xMap and yMap, because creating them static in my environment is ridiculous in terms of speed and memory footprint. Below is a prototype of what i figured from docs and examples.
class GRID : public QwtPlotGrid {
// i smuggle a pointer to QwtPlot to be used while automatically updating the plot with MOVE / PAN / ZOOM / WHATEVER_ELSE
GRID::GRID ( QwtPlot *PLOT_POINTER ) { ... }
virtual void updateScaleDiv ( const QwtScaleDiv &xMap, const QwtScaleDiv &yMap ) {
// i create my custom QwtScaleDiv and then use it like that
PLOT_POINTER->setAxisScaleDiv ( QwtPlot::xBottom, QwtScaleDiv ( xMap.lowerBound(), xMap.upperBound(), MY_CUSTOM_SCALE_MARKS ) );
// and like that
QwtPlotGrid::updateScaleDiv ( QwtScaleDiv ( xMap.lowerBound(), xMap.upperBound(), MY_CUSTOM_SCALE_MARKS ), yMap );
}
}
QwtPlotGrid::updateScaleDiv works just fine.
PLOT_POINTER->setAxisScaleDiv works only once at plot creation time, but when MOVE / PAN / ZOOM / WHATEVER_ELSE is applied it reverts back to default, autogenerated i assume, QwtScaleDiv. I suppose it's expected because it's more of a hack, than a normal way of doing this, but i couldn't come with anything better.
I'll be reading up on this, but in the mean time i ask for suggestion.
Regards,
icosahedron
Re: Issue with QwtPlot::setAxisScaleDiv();
Quote:
Originally Posted by
icosahedron
I'm trying to create grid and scale based upon dimensions of xMap and yMap, ...
It is the job of the scale engine to calculate useful ticks for a given interval: see QwtScaleEngine::divideScale().
The parameters for this method have been set by QwtPlot::setAxisMaxMinor() and friends, but the scale engine itself has a couple of additional options affecting the algorithm.
When the default algorithm doesn't work for your situation you can overload and implement your specific one ( QwtPlot::setAxisScaleEngine() ).
Uwe
PS: When your problem is about misaligned date/time ticks note that you find QwtDateTimeScaleEngine/QwtDateTimeScaleDraw in SVN trunk, that are almost completed - or will be completed the next days.
Re: Issue with QwtPlot::setAxisScaleDiv();
Thank Uwe,
My major grid lines and major scale ticks have irregular intervals to reflect presented data, stock functions like QwtPlot::setAxisMaxMinor() and friends will not work in this case.
Will overloading QwtPlot::setAxisScaleEngine() allow me to reflect irregularity from prepared QwtScaleDiv ? My comfort zone is C and basic C++, so i'll need to invest some learning time into it.
icosahedron
Update :
Also it completely puzzles me why setAxisScaleDiv() works only once at plot creation time ? Maybe i can disable some ScaleEngine algorithms to avoid that and force it to use the supplied ScaleDiv ?
Re: Issue with QwtPlot::setAxisScaleDiv();
Quote:
Originally Posted by
icosahedron
Will overloading QwtPlot::setAxisScaleEngine() allow me to reflect irregularity from prepared QwtScaleDiv ?
Code:
{
public:
virtual QwtScaleDiv divideScale
( double x1,
double x2,
int ,
int ,
double ) const {
const QwtInterval interval = QwtInterval( x1, x2 ).normalized();
// fill the ticks somehow according to interval
// here you can set whatever ticks you want as long as
// they are inside the interval x1/x2
....
if ( x1 > x2 )
scaleDiv.invert();
return scaleDiv;
}
};
and
Code:
plot->setAxisScaleEngine( axis, new YourScaleEngine() );
Quote:
Also it completely puzzles me why setAxisScaleDiv() works only once at plot creation time ?
Because all what modifies a scale ( f.e panning, zooming ) has to do it in the end with setAxisScaleDiv() and your initial assignment gets overwritten.
Uwe