Results 1 to 6 of 6

Thread: Sync charts with custom scale.

Hybrid View

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

    Default Re: Sync charts with custom scale.

    The space, that is needed for the tick labels, has an effect on the position of the ticks. On the left side it is possible to move parts of the label below the left scale, but as there is none on the right ...
    How to solve it depends on the details of your application: f.e you could choose an alignment like in the cpuplot example, where the part of the tick labels right from the tick is smaller, than the canvas margin.

    Uwe

  2. #2
    Join Date
    Nov 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Sync charts with custom scale.

    I figured out from Qwt sources that grid drawing depends on QwtScaleMap object. So I decided to override "canvasMap" method of QwtPlot class and pass the scale widget of another plot with visible scale.
    Qt Code:
    1. void OneAxisDisabledPlot::setDisabledAxis(int axisId, QwtScaleWidget* baseWidget)
    2. {
    3. enableAxis(axisId, false);
    4. m_disabledAxis = axisId;
    5. m_baseScaleWidget = baseWidget;
    6. }
    7.  
    8. bool OneAxisDisabledPlot::isAxisDisabled(int axisId) const
    9. {
    10. return m_disabledAxis == axisId;
    11. }
    12.  
    13. QwtScaleMap OneAxisDisabledPlot::canvasMap(int axisId) const
    14. {
    15. if(!canvas())
    16. return map;
    17.  
    18. map.setTransformation(axisScaleEngine(axisId)->transformation());
    19.  
    20. const QwtScaleDiv &sd = axisScaleDiv(axisId);
    21. map.setScaleInterval(sd.lowerBound(), sd.upperBound());
    22. const QwtScaleWidget *s = isAxisDisabled(axisId) ? m_baseScaleWidget : axisWidget(axisId);
    23. if(axisEnabled(axisId) || isAxisDisabled(axisId))
    24. {
    25. if(axisId == yLeft || axisId == yRight)
    26. {
    27. double y = s->y() + s->startBorderDist() - canvas()->y();
    28. double h = s->height() - s->startBorderDist() - s->endBorderDist();
    29. map.setPaintInterval(y + h, y);
    30. }
    31. else
    32. {
    33. double x = s->x() + s->startBorderDist() - canvas()->x();
    34. double w = s->width() - s->startBorderDist() - s->endBorderDist();
    35. map.setPaintInterval(x, x + w);
    36. }
    37. }
    38. else
    39. {
    40. const QRect &canvasRect = canvas()->contentsRect();
    41. if(axisId == yLeft || axisId == yRight)
    42. {
    43. int top = 0;
    44. if(!plotLayout()->alignCanvasToScale(xTop))
    45. top = plotLayout()->canvasMargin(xTop);
    46.  
    47. int bottom = 0;
    48. if(!plotLayout()->alignCanvasToScale(xBottom))
    49. bottom = plotLayout()->canvasMargin(xBottom);
    50.  
    51. map.setPaintInterval(canvasRect.bottom() - bottom,
    52. canvasRect.top() + top);
    53. }
    54. else
    55. {
    56. int left = 0;
    57. if(!plotLayout()->alignCanvasToScale(yLeft))
    58. left = plotLayout()->canvasMargin(yLeft);
    59.  
    60. int right = 0;
    61. if(!plotLayout()->alignCanvasToScale(yRight))
    62. right = plotLayout()->canvasMargin(yRight);
    63.  
    64. map.setPaintInterval(canvasRect.left() + left,
    65. canvasRect.right() - right);
    66. }
    67. }
    68.  
    69. return map;
    70. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by giker; 4th January 2016 at 21:26.

Similar Threads

  1. Replies: 1
    Last Post: 9th September 2013, 07:50
  2. Replies: 21
    Last Post: 8th December 2011, 02:18
  3. Custom ProxyModel or Two Sync'd Models ?
    By SSurgnier in forum Qt Programming
    Replies: 2
    Last Post: 2nd August 2011, 18:44
  4. sync plot grid w/ external scale widget
    By Kevin Ching in forum Qwt
    Replies: 6
    Last Post: 30th September 2010, 17:12
  5. To draw a custom scale
    By Indalo in forum Qwt
    Replies: 1
    Last Post: 30th November 2009, 13:24

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
  •  
Qt is a trademark of The Qt Company.