Results 1 to 4 of 4

Thread: Different Units for a Scale?

  1. #1
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Different Units for a Scale?

    Hi,

    actually my measurement values are a pair of time and pressure.
    The pressure value is stored in [mbar].

    What is the best way in Qwt to change the unit eg. [Torr] or [Pa] and other.

    It it necessary to recalculate all values of a curve ( which is not good) or
    is it possible to change the axis only?

    Stefan

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

    Default Re: Different Units for a Scale?

    You could derive from QwtSeriesData<QPointF>. Store the samples as they are and do the translation in QwtSeriesData<QPointF>::sample() and QwtSeriesData<QPointF>::boundingRect().

    Uwe

  3. #3
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Different Units for a Scale?

    Hello Uwe,

    just an idea, but can this be done also using QwtTransform if i add a new one like this (not tried):

    Qt Code:
    1. mbarToTorrTransform::mbarToTorrTransform():
    2. QwtTransform()
    3. {
    4. }
    5. mbarToTorrTransform::~mbarToTorrTransform()
    6. {
    7. }
    8.  
    9. double mbarToTorrTransform::transform( double value ) const
    10. {
    11. return value*0.75006;
    12. }
    13. double mbarToTorrTransform::invTransform( double value ) const
    14. {
    15. return value/0.75006;
    16. }
    To copy to clipboard, switch view to plain text mode 

    Thx
    Stefan
    Last edited by HappyCoder; 28th July 2015 at 09:59.

  4. #4
    Join Date
    Jul 2015
    Posts
    87
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Different Units for a Scale?

    With the grateful help of phenoboy and some modifications i was able to create a subclass of QwtSeriesData.
    But now application crashes on close with this message in Debugger

    can't find linker symbol for virtual table for `QwtSeriesStore<QPointF>' value
    found `construction vtable for QwtSeriesStore<QPointF>-in-PlotCurve' instead


    What is going wrong here? (clean Project, qmake, rebuild all done)

    It looks like the app crahes here:
    Qt Code:
    1. template <typename T>
    2. QwtSeriesStore<T>::~QwtSeriesStore()
    3. {
    4. delete d_series; // CRASH
    5. }
    To copy to clipboard, switch view to plain text mode 

    Thx
    Stefan

    My code:

    plotcurve.h
    Qt Code:
    1. #include "qwt/subclass/seriesdata.h"
    2. ...
    3. SeriesData curveData;
    To copy to clipboard, switch view to plain text mode 

    plotcurve.cpp
    Qt Code:
    1. void PlotCurve::newCurveData()
    2. {
    3. if( isPointerValid() )
    4. {
    5. // with subclass from QwtSeriesData
    6. curveData.setMinYValue( d_data->pmdata.data()->valueMin );
    7. curveData.setMaxYValue( d_data->pmdata.data()->valueMax );
    8. curveData.setSamples(d_data->pmdata.data()->timestamps,
    9. d_data->pmdata.data()->values);
    10. curveData.setFactorY( d_data->unitPressureFactor );
    11.  
    12. setSamples( &curveData );
    13. }
    To copy to clipboard, switch view to plain text mode 


    seriesdata.h
    Qt Code:
    1. #include "qwt_series_data.h"
    2. #include <QObject>
    3.  
    4. class SeriesData : public QwtSeriesData<QPointF>
    5. {
    6. public:
    7. SeriesData();
    8.  
    9. virtual QPointF sample( size_t index ) const;
    10. virtual size_t size() const;
    11. virtual QRectF boundingRect() const;
    12.  
    13. double getFactorY() const;
    14. void setFactorY(const double &value);
    15.  
    16. void setMaxYValue(const double &value);
    17. void setMinYValue(const double &value);
    18.  
    19. void clear();
    20.  
    21. void setSamples( const QVector<double> &xData, const QVector<double> &yData );
    22. QVector<double> &pointsX();
    23. QVector<double> &pointsY();
    24. QRectF _boundingRect;
    25.  
    26. protected:
    27. QVector<double> points_x;
    28. QVector<double> points_y;
    29. double factorY;
    30. double maxYValue;
    31. double minYValue;
    32. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "seriesdata.h"
    2.  
    3. #include "qwt_series_data.h"
    4.  
    5. SeriesData::SeriesData()
    6. {
    7. qDebug() << Q_FUNC_INFO;
    8.  
    9. factorY = 1;
    10. points_x.reserve(1000);
    11. points_y.reserve(1000);
    12. }
    13.  
    14. QPointF SeriesData::sample(size_t index) const
    15. {
    16. QPointF p(points_x.value(index), points_y.value(index));
    17. p.setY(factorY*p.y());
    18. return p;
    19. }
    20.  
    21. size_t SeriesData::size() const
    22. {
    23. return points_x.size();
    24. }
    25.  
    26. QRectF SeriesData::boundingRect() const
    27. {
    28. return _boundingRect;
    29. }
    30.  
    31. QVector<double> &SeriesData::pointsX()
    32. {
    33. return points_x;
    34. }
    35.  
    36. QVector<double> &SeriesData::pointsY()
    37. {
    38. return points_y;
    39. }
    40.  
    41. double SeriesData::getFactorY() const
    42. {
    43. return factorY;
    44. }
    45.  
    46. void SeriesData::setFactorY(const double &value)
    47. {
    48. factorY = value;
    49. }
    50.  
    51. void SeriesData::setMaxYValue(const double &value)
    52. {
    53. maxYValue = value;
    54. }
    55.  
    56. void SeriesData::setMinYValue(const double &value)
    57. {
    58. minYValue = value;
    59. }
    60.  
    61. void SeriesData::clear()
    62. {
    63. points_x.clear();
    64. points_y.clear();
    65. }
    66.  
    67. void SeriesData::setSamples(const QVector<double> &xData, const QVector<double> &yData)
    68. {
    69. points_x = xData;
    70. points_y = yData;
    71.  
    72. _boundingRect.setLeft( (qreal)(xData.first()) );
    73. _boundingRect.setRight( (qreal)(xData.last()) );
    74. _boundingRect.setTop( maxYValue );
    75. _boundingRect.setBottom( minYValue );
    76. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by HappyCoder; 7th October 2015 at 09:52.

Similar Threads

  1. Replies: 1
    Last Post: 9th September 2013, 07:50
  2. Replies: 5
    Last Post: 12th August 2013, 08:59
  3. qwt log scale Y and linear scale X
    By Annihilator in forum Qwt
    Replies: 1
    Last Post: 31st December 2012, 10:01
  4. Small QPushButton possible? (less than 75 units)
    By masterlaws in forum Qt Programming
    Replies: 3
    Last Post: 4th December 2009, 19:09
  5. The application with connected units.
    By kuzulis in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2009, 23:54

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.