Results 1 to 6 of 6

Thread: AutoScaling not working

  1. #1
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default AutoScaling not working

    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:

    Qt Code:
    1. void ScopeGraphArea::slotSetItemVisible(const ButtonId id, const bool visible)
    2. {
    3. multiGraph->enableCurve(id,visible);
    4.  
    5. multiGraph->updateAxisVisibility();
    6. }
    7.  
    8. void enableCurve(const int curve, const bool enable)
    9. {
    10. if (curve < 0)
    11. return;
    12.  
    13. if (enable)
    14. {
    15. curveList[curve]->attach(this);
    16. curveList[curve]->show();
    17. }
    18. else
    19. {
    20. curveList[curve]->detach();
    21. curveList[curve]->hide();
    22. }
    23.  
    24. if (curveList[curve]->yAxis() == QwtPlot::yLeft)
    25. yLeftEnabled = enable;
    26. else //if (curveList[curve]->yAxis() == QwtPlot::yRight)
    27. yRightEnabled = enable;
    28.  
    29. refreshGraphVisibility(enable);
    30. replot();
    31. }
    32.  
    33. void refreshGraphVisibility(const bool lastCurveEnabled = false)
    34. {
    35. if (lastCurveEnabled) //Provided for efficiency
    36. {
    37. show();
    38. return;
    39. }
    40.  
    41. bool isOneVisible = false;
    42.  
    43. for (int aaa = 0; aaa < curveList.size(); aaa++)
    44. {
    45. if (curveList.at(aaa)->isVisible())
    46. {
    47. isOneVisible = true;
    48. break;
    49. }
    50. }
    51.  
    52. setVisible(isOneVisible);
    53. }
    54.  
    55. virtual void updateAxisVisibility()
    56. {
    57. bool yLeftvisible = false, yRightVisible = false;
    58.  
    59. foreach(QwtPlotCurveSpecial* poCurve, curveList)
    60. {
    61. if (poCurve->isVisible() && poCurve->yAxis() == QwtPlot::yLeft)
    62. yLeftvisible = true;
    63. else if (poCurve->isVisible() && poCurve->yAxis() == QwtPlot::yRight)
    64. yRightVisible = true;
    65. }
    66.  
    67. enableAxis(QwtPlot::yLeft,yLeftvisible);
    68. enableAxis(QwtPlot::yRight,yRightVisible);
    69. }
    To copy to clipboard, switch view to plain text mode 


    I'm glad for any help

    Thanks,

    Momergil
    May the Lord be with you. Always.

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

    Default Re: AutoScaling not working

    Quote Originally Posted by Momergil View Post
    I noticed that auto scalling works by calculating the boundary rectangle of the QwtPlotCurve's data.
    Yes and the bounding rectangle is cached. So you can't change your arrays behind the back of the curve.

    In case of incremental data it doesn't make much sense to iterate over all points to recalculate the bound rectangle for each new sample. instead I would overload QwtPlotCurve::boundingRect() and do it in a more efficient way.

    Uwe

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

    Momergil (7th May 2014)

  4. #3
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: AutoScaling not working

    Hello Uwe and thanks for the reply.

    Quote Originally Posted by Uwe View Post
    Yes and the bounding rectangle is cached. So you can't change your arrays behind the back of the curve.
    I'm not sure I understood your explanation, but if that essentially means that I'll not be able to use auto replot for my situation, ok.

    Quote Originally Posted by Uwe View Post
    In case of incremental data it doesn't make much sense to iterate over all points to recalculate the bound rectangle for each new sample. instead I would overload QwtPlotCurve::boundingRect() and do it in a more efficient way.
    I agree; too much processing consumption, specially for a embedded situation. The problem, though, is how exactly should I overload QwtPlotCurve::boundingRect()? I'm not familiar with doing this and all Qwt examples only give an ideia of doing it with the QwtPlotSeriesData or similar, not QwtPlotCurve's boundingRect() method.


    Thanks,

    Momergil
    May the Lord be with you. Always.

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

    Default Re: AutoScaling not working

    Quote Originally Posted by Momergil View Post
    I'm not sure I understood your explanation, but if that essentially means that I'll not be able to use auto replot for my situation, ok.
    No it only means, that the cached rectangle is not recalculated, when the curve is not aware of the fact, that the data has changed. But this is not important, when you reimplement QwtPlotCurve::boundingRect() like proposed.
    Quote Originally Posted by Momergil View Post
    The problem, though, is how exactly should I overload QwtPlotCurve::boundingRect()?
    Well overloading is a very fundamental mechanism of OO languages like C++. You can read about it in the C++ book on your shelf.

    Uwe

  6. #5
    Join Date
    Jun 2011
    Location
    Porto Alegre, Brazil
    Posts
    482
    Thanks
    165
    Thanked 2 Times in 2 Posts
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default Re: AutoScaling not working

    Quote Originally Posted by Uwe View Post
    But this is not important, when you reimplement QwtPlotCurve::boundingRect() like proposed.
    Ok - and thanks for the explanation.

    Quote Originally Posted by Uwe View Post
    when the curve is not aware of the fact, that the data has changed
    Just for curiosity, then, how would I do this? (makes the curve aware of the fact that data has changed)

    Quote Originally Posted by Uwe View Post
    Well overloading is a very fundamental mechanism of OO languages like C++. You can read about it in the C++ book on your shelf.
    Well Uwe, certanly I know what is to overload a method! xD I didn't mean that when I put my question, but instead: what exactly should I put inside the overloaded method? But I confess, reading it now, that my question wasn't clear at this point; sorry!
    Last edited by Momergil; 7th May 2014 at 18:06.
    May the Lord be with you. Always.

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

    Default Re: AutoScaling not working

    Just for curiosity, then, how would I do this? (makes the curve aware of the fact that data has changed)
    setRawSamples/setSamples are simply convenience methods creating a data object calling setData then. Behind the back means that you modify the samples inside of this data object without telling the curve with another call of setData.

    what exactly should I put inside the overloaded method?
    How should I know - it depends on the details of your application.

    f.e. if your x values are ordered in time you know the the x value of the first one is the minimum and the last one the maximum. If you add a new sample to an existing set, where you already know the bounding rectangle, all you need to do is to extend it by the coordinates of the new sample. Using such extra information makes it easy to find an implementation, that is way more efficient than the default implementation, that iterates over all points.

    Uwe

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

    Momergil (8th May 2014)

Similar Threads

  1. Autoscaling widget font on resize
    By SeanM in forum Qt Programming
    Replies: 0
    Last Post: 10th March 2014, 16:27
  2. Replies: 7
    Last Post: 24th September 2012, 07:17
  3. Working with map
    By naptizaN in forum Newbie
    Replies: 4
    Last Post: 28th August 2012, 12:57
  4. Replies: 1
    Last Post: 4th July 2012, 19:09
  5. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02

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.