Results 1 to 4 of 4

Thread: Issue with QwtPlot::setAxisScaleDiv();

  1. #1
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,308
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issue with QwtPlot::setAxisScaleDiv();

    Quote Originally Posted by icosahedron View Post
    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.

  3. #3
    Join Date
    Dec 2012
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default 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 ?
    Last edited by icosahedron; 28th December 2012 at 20:01.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,308
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Issue with QwtPlot::setAxisScaleDiv();

    Quote Originally Posted by icosahedron View Post
    Will overloading QwtPlot::setAxisScaleEngine() allow me to reflect irregularity from prepared QwtScaleDiv ?
    Qt Code:
    1. class YourScaleEngine: public QwtLinearScaleEngine
    2. {
    3. public:
    4. virtual QwtScaleDiv divideScale( double x1, double x2, int , int , double ) const
    5. {
    6. const QwtInterval interval = QwtInterval( x1, x2 ).normalized();
    7. QList<double> ticks[QwtScaleDiv::NTickTypes];
    8.  
    9. // fill the ticks somehow according to interval
    10. // here you can set whatever ticks you want as long as
    11. // they are inside the interval x1/x2
    12.  
    13. ticks[QwtScaleDiv::MajorTick] += ...;
    14. ....
    15.  
    16. QwtScaleDiv scaleDiv( interval, ticks );
    17. if ( x1 > x2 )
    18. scaleDiv.invert();
    19.  
    20. return scaleDiv;
    21. }
    22. };
    To copy to clipboard, switch view to plain text mode 

    and

    Qt Code:
    1. plot->setAxisScaleEngine( axis, new YourScaleEngine() );
    To copy to clipboard, switch view to plain text mode 

    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

  5. The following user says thank you to Uwe for this useful post:

    icosahedron (28th December 2012)

Similar Threads

  1. Replies: 9
    Last Post: 25th October 2012, 20:55
  2. setAxisScaleDiv - my scale div is invalid
    By frankiefrank in forum Qwt
    Replies: 3
    Last Post: 11th February 2011, 14:43
  3. QwtPlot margins
    By jmsbc in forum Qwt
    Replies: 0
    Last Post: 2nd October 2009, 19:11
  4. Replies: 0
    Last Post: 15th May 2009, 16:12
  5. Replies: 6
    Last Post: 14th May 2009, 13:02

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.