Results 1 to 8 of 8

Thread: QwtPolar change scale steps problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Unhappy QwtPolar change scale steps problem

    Hello everyone!
    I ran into a problem with scaling.
    This is my code to change scale:
    Qt Code:
    1. // class Scale : public QDockWidget
    2. // QComboBox::m_cbScale;
    3. // QComboBox::m_cbAzimuth;
    4. // QComboBox::m_cbDistance;
    5. // QwtPolarPlot::m_screen
    6. const double MAX_DISPLAY_FACTOR = 0.99; // for squared displaying
    7.  
    8. void Scale::changedScale()
    9. {
    10. // Azimuth scale
    11. m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
    12. // Distance scale
    13. m_screen->setScale(QwtPolar::Radius, 0, 600.0, m_cbDistance->currentText().toDouble());
    14. m_screen->setScaleMaxMajor(QwtPolar::Radius, 600.0 / m_cbDistance->currentText().toDouble());
    15. // Zoom scale
    16. if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
    17. m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
    18. } else {
    19. m_screen->zoom(QwtPointPolar(0, 0), m_cbScale->currentText().toDouble() / 600.0);
    20. }
    21. m_screen->replot();
    22. }
    To copy to clipboard, switch view to plain text mode 

    How to set major ticks to be fixed - not auto calculated.

    Scale 200 steps 100 - good.
    scale200_step100.jpg
    Scale 150 steps 100 - bad - steps setted to 100, but displaying 50. In here I want to be displayed only 100 without 50 and 150.
    scale150_step100.jpg
    Scale 50 steps 100 - bad - steps setted to 100, but displaying 20. In here I want to be displayed nothing. If I change distance step to 50 - only 50 major tick are displayed. If I change distance step to 10, I want to be displayed 10, 20, 30, 40 and 50.
    scale50_step100.jpg
    Last edited by BulSV; 14th May 2017 at 16:08.

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

    Default Re: QwtPolar change scale steps problem

    If you want to set the ticks manually you can use setScaleDiv.

    Uwe

  3. #3
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Lightbulb Re: QwtPolar change scale steps problem

    setScaleDiv didn't help.
    I found out that this is due to zoom. When I commented out zooming all major ticks are become perfect.
    How to fix it?

    Qt Code:
    1. // class Scale : public QDockWidget
    2. // QComboBox::m_cbScale;
    3. // QComboBox::m_cbAzimuth;
    4. // QComboBox::m_cbDistance;
    5. // QwtPolarPlot::m_screen
    6. const double MAX_DISPLAY_FACTOR = 0.99; // for squared displaying
    7.  
    8. void Scale::changedScale()
    9. {
    10. // Azimuth scale
    11. m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
    12. // Distance scale
    13. m_screen->setScale(QwtPolar::Radius, 0, 600.0, m_cbDistance->currentText().toDouble());
    14. m_screen->setScaleMaxMajor(QwtPolar::Radius, 600.0 / m_cbDistance->currentText().toDouble());
    15. // Zoom scale
    16. // if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
    17. // m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
    18. // } else {
    19. // m_screen->zoom(QwtPointPolar(0, 0), m_cbScale->currentText().toDouble() / 600.0);
    20. // }
    21. m_screen->replot();
    22. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QwtPolar change scale steps problem

    The zoom call does 2 things:

    1) Putting the previous intervals on the zoom stack
    2) calling setScale

    The only reason for calling zoom manually might be 1, so that the user can navigate to the initial scale ranges easily.
    But even then: you can set an initial zoomStack by QwtPlotZoomer::setZoomStack.

    In case you need more control about how ticks are set when zooming you have to overload QwtPlotZoomer::rescale().

    Uwe

  5. #5
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QwtPolar change scale steps problem

    I'm not using QwtPlotZoomer, just only QwtPolarPlot::zoom. How does this class relate to QwtPolarPlot::zoom ?

  6. #6
    Join Date
    Mar 2016
    Posts
    14
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QwtPolar change scale steps problem

    Nothing helped

    Qt Code:
    1. void Scale::changedScale()
    2. {
    3. // Zoom scale
    4. // if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
    5. // m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
    6. // } else {
    7. // m_screen->zoom(m_screen->zoomPos(), m_cbScale->currentText().toDouble() / 600.0);
    8. // }
    9. // Azimuth scale
    10. m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
    11. // Distance scale
    12. m_scaleDiv.setLowerBound(0);
    13. m_scaleDiv.setUpperBound(m_cbScale->currentText().toDouble());
    14. m_scaleDiv.setTicks(QwtScaleDiv::MinorTick, getTicks(m_cbDistance->currentText().toDouble()));
    15. m_scaleDiv.setTicks(QwtScaleDiv::MediumTick, getTicks(m_cbDistance->currentText().toDouble()));
    16. m_scaleDiv.setTicks(QwtScaleDiv::MajorTick, getTicks(m_cbDistance->currentText().toDouble()));
    17. m_screen->setScaleDiv(QwtPolar::Radius, m_scaleDiv);
    18. m_screen->setScale(QwtPolar::Radius, 0, m_cbScale->currentText().toDouble());
    19.  
    20. m_screen->replot();
    21. }
    22.  
    23. QList<double> Scale::getTicks(double step) const
    24. {
    25. QList<double> ticks;
    26. if(qFuzzyCompare(step, 0)) {
    27. return ticks;
    28. }
    29. for(double i = 0; i <= m_cbScale->currentText().toDouble(); i += step) {
    30. ticks.append(i);
    31. }
    32.  
    33. return ticks;
    34. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. void Scale::changedScale()
    2. {
    3. // Azimuth scale
    4. m_screen->setScale(QwtPolar::Azimuth, 360, 0, m_cbAzimuth->currentText().toDouble());
    5. // Distance scale
    6. m_screen->setScale(QwtPolar::Radius, 0, 600.0);
    7. double maxMajor = 600.0 / m_cbDistance->currentText().toDouble();
    8. m_screen->setScaleMaxMajor(QwtPolar::Radius,
    9. qFuzzyCompare(maxMajor, static_cast<int>(maxMajor))
    10. ? maxMajor : maxMajor + 1);
    11. // Zoom scale <-- This spoils everything!!!
    12. if(qFuzzyCompare(m_cbScale->currentText().toDouble(), 600.0)) {
    13. m_screen->zoom(QwtPointPolar(0, 0), MAX_DISPLAY_FACTOR);
    14. } else {
    15. m_screen->zoom(m_screen->zoomPos(), m_cbScale->currentText().toDouble() / 600.0);
    16. }
    17.  
    18. m_screen->replot();
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by BulSV; 17th June 2017 at 22:24.

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

    Default Re: QwtPolar change scale steps problem

    Qt Code:
    1. void Scale::changedScale()
    2. {
    3. ....
    4. m_screen->setScaleDiv(QwtPolar::Radius, m_scaleDiv);
    5. // m_screen->setScale(QwtPolar::Radius, 0, m_cbScale->currentText().toDouble());
    6. }
    To copy to clipboard, switch view to plain text mode 
    setScale calculates a QwtScaleDiv using the algo of the scale engine and then assigns it. So the second call is bad as it invalidates the effect of the first one.

    Uwe

  8. #8
    Join Date
    Jan 2021
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwtPolar change scale steps problem

    Hello,
    I also had similar problems with the QwtPolar::Radius scale steps.
    The solution : disabling the auto-scaling attribute of the QwtPolarGrid :
    ... .setGridAttribute( QwtPolarGrid::AutoScaling, false );

Similar Threads

  1. Replies: 5
    Last Post: 25th January 2021, 17:01
  2. Replies: 2
    Last Post: 13th November 2016, 19:30
  3. Replies: 7
    Last Post: 13th April 2011, 09:42
  4. Replies: 1
    Last Post: 19th May 2009, 12:14
  5. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 09:47

Tags for this Thread

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.