Results 1 to 3 of 3

Thread: Change axis ticks and label to switch between millimeter and inch in QWT Plot

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: Change axis ticks and label to switch between millimeter and inch in QWT Plot

    You have to derive from QwtLinearScaleEngine adding your inch/millimeter modes there.

    I guess all what needs to be done is to overload divideScale/autoScale, where you convert the values into the current mode. Then you can simply call the method of the base class with the converted values. Of course the result of the base class needs to be reconverted to the incoming mode too.

    Uwe

  2. #2
    Join Date
    Sep 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Change axis ticks and label to switch between millimeter and inch in QWT Plot

    Thank you Uwe, I got it. In case others have a similar requirement, this is my code:

    Qt Code:
    1. class QwtUnitScaleDraw : public QwtScaleDraw {
    2. public:
    3. QwtUnitScaleDraw(double ConversionFactor = 1.0) : QwtScaleDraw(), _ConversionFactor(ConversionFactor) {
    4. }
    5. protected:
    6. QwtText label(double value) const {
    7. return QwtScaleDraw::label(value * _ConversionFactor);
    8. }
    9. protected:
    10. double _ConversionFactor;
    11. };
    12.  
    13. class QwtUnitScaleEngine: public QwtLinearScaleEngine {
    14. public:
    15. QwtUnitScaleEngine(double ConversionFactor = 1.0) : QwtLinearScaleEngine(10), _ConversionFactor(ConversionFactor) {
    16. }
    17.  
    18. void autoScale(int maxSteps, double &x1, double &x2, double &stepSize) const {
    19. x1 *= _ConversionFactor;
    20. x2 *= _ConversionFactor;
    21. stepSize *= _ConversionFactor;
    22. QwtLinearScaleEngine::autoScale(maxSteps, x1, x2, stepSize);
    23. x1 /= _ConversionFactor;
    24. x2 /= _ConversionFactor;
    25. stepSize /= _ConversionFactor;
    26.  
    27. }
    28.  
    29. QwtScaleDiv divideScale(double x1, double x2, int numMajorSteps, int numMinorSteps, double stepSize = 0.0) const {
    30. x1 *= _ConversionFactor;
    31. x2 *= _ConversionFactor;
    32. stepSize *= _ConversionFactor;
    33.  
    34. QwtScaleDiv Div = QwtLinearScaleEngine::divideScale(x1, x2, numMajorSteps, numMinorSteps, stepSize);
    35.  
    36. QList<double> Ticks[QwtScaleDiv::NTickTypes];
    37.  
    38. Ticks[QwtScaleDiv::MajorTick] = Div.ticks(QwtScaleDiv::MajorTick);
    39. for (unsigned int i = 0; i < Ticks[QwtScaleDiv::MajorTick].count(); i++) {
    40. Ticks[QwtScaleDiv::MajorTick][i] /= _ConversionFactor;
    41. }
    42. Ticks[QwtScaleDiv::MediumTick] = Div.ticks(QwtScaleDiv::MediumTick);
    43. for (unsigned int i = 0; i < Ticks[QwtScaleDiv::MediumTick].count(); i++) {
    44. Ticks[QwtScaleDiv::MediumTick][i] /= _ConversionFactor;
    45. }
    46. Ticks[QwtScaleDiv::MinorTick] = Div.ticks(QwtScaleDiv::MinorTick);
    47. for (unsigned int i = 0; i < Ticks[QwtScaleDiv::MinorTick].count(); i++) {
    48. Ticks[QwtScaleDiv::MinorTick][i] /= _ConversionFactor;
    49. }
    50.  
    51. return QwtScaleDiv(QwtInterval(x1 / _ConversionFactor, x2 / _ConversionFactor), Ticks);
    52. }
    53. protected:
    54. double _ConversionFactor;
    55. };
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Hiding axis, but not ticks
    By bisasatan in forum Qwt
    Replies: 1
    Last Post: 31st May 2013, 07:55
  2. Replies: 12
    Last Post: 18th May 2011, 20:40
  3. PyQT QwtScaleDiv adds ticks to axis
    By mbernasocchi in forum Qwt
    Replies: 12
    Last Post: 13th April 2011, 11:29
  4. Replies: 1
    Last Post: 30th July 2010, 07:23
  5. Replies: 2
    Last Post: 30th June 2009, 17:08

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