Results 1 to 4 of 4

Thread: shifting curve up or down

  1. #1
    Join Date
    Nov 2012
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default shifting curve up or down

    Hi,

    I have plotted several curves (qwtPlotCurve) in the same plot (qwtPlot), and as they overlap a lot, I would like to shift some using a qwtCounter to increase an offset value that I would use to shift a selected curve up or down.
    I was wondering what was the best way of doing it - is there any simple or build-in way to add a constant double to all the y values of my curve data ?

    regards

    Oliver

  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: shifting curve up or down

    Assuming that your points are stored in a QPolygonF:

    Qt Code:
    1. class YourData: public QwtPointSeriesData
    2. {
    3. public:
    4. YourData( const QVector<QPointF> &samples ):
    5. QwtPointSeriesData( samples ):
    6. m_offset( 0.0 )
    7. {
    8. }
    9.  
    10. void setOffset( double off )
    11. {
    12. m_offset = offset;
    13. }
    14.  
    15. virtual QPointF sample( size_t index ) const
    16. {
    17. QPointF point = QwtPointSeriesData::sample( index );
    18. return QPointF( point.x(), point.y() + m_offset );
    19. }
    20.  
    21. virtual QRectF boundingRect() const
    22. {
    23. return QwtPointSeriesData::boundingRect().translated( 0.0, m_offset );
    24. }
    25. private:
    26. double m_offset;
    27. };
    To copy to clipboard, switch view to plain text mode 

    and:

    Qt Code:
    1. curve->setData( new YourData( points ) );
    To copy to clipboard, switch view to plain text mode 
    Of course you have to replace QwtPointSeriesData by the type of series data object you were using so far ( QwtPlotCurve::setSamples does nothing else than creating such an data object internally - check the implementation ).

    When you have many points it might be a good idea to use a different implementation for YourData::sample() that directly accesses your point container instead of calling the base class.

    HTH,
    Uwe



    }

  3. #3
    Join Date
    Nov 2012
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: shifting curve up or down

    Hi Uwe,

    Thanks for the detailed answer. I will experiment this approach today and report the results on the forum.

    best regards

    Oliver

  4. #4
    Join Date
    Nov 2012
    Posts
    11
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: shifting curve up or down

    Hello Uwe,

    I pasted your code with almost no changes and it worled perfectly at once !

    Thanks a lot for your support.

    Oliver

Similar Threads

  1. Replies: 14
    Last Post: 9th May 2012, 05:43
  2. Bitwise shifting and ORing HexaDecimal Value
    By nagabathula in forum Qt Programming
    Replies: 14
    Last Post: 19th November 2010, 07:22
  3. Shifting a QImage up by 1 pixel row
    By MSUdom5 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2010, 10:25
  4. Replies: 4
    Last Post: 29th April 2010, 06:11
  5. Byte shifting in C
    By tntcoda in forum General Programming
    Replies: 3
    Last Post: 14th November 2008, 22:40

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.