Results 1 to 3 of 3

Thread: Refreshtest example. How to introduce new data in the circularbuffer.

  1. #1
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Post Refreshtest example. How to introduce new data in the circularbuffer.

    Hello,

    These days I have been trying to use the refreshtest example to plot different data (i.e. not a circular buffer) when the plot is being updated, changing the last value that is being plotted (the one which appears on the right part of the plot) by another value, for example the one I have in a QDoubleSpinBox implemented in the panel. I was able to change the last value in the buffer, but that last value is moving to the left in this way:

    (Values of the buffer and refreshplot example)

    Qt Code:
    1. At the beginning when I start the programm ([0] and [last value] are index of the buffer)
    2.  
    3. [0].................................................................................[last value]
    4.  
    5. When some timerEvent has ocurred:
    6.  
    7. .........................[last value] [0].......................................................
    8.  
    9. For example, imagine I have all 0's and one [last value] to 0.1, after some timerEvents:
    10. _
    11. _ _
    12. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ __ _ _ _ _
    13.  
    14. Now, If change my QDouble Spinbox to 0.2, then, (after again some timerEvents), the same point changes:
    15.  
    16. -
    17. - -
    18. - -
    19. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    20.  
    21. However, what I would like is the following behaviour (the new value enters by the right, with value 0.1, and the 0.2 value continues moving to the left).
    22. -
    23. - - _
    24. - - _
    25. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    To copy to clipboard, switch view to plain text mode 



    This is what I do in the fill function:
    Qt Code:
    1. void CircularBuffer::fill(double interval, size_t numPoints, double ReceivedValue)
    2. {
    3. if ( interval <= 0.0 || numPoints < 2 )
    4. return;
    5.  
    6. d_values.resize(numPoints);
    7. d_values.fill(0.0);
    8.  
    9. d_step = interval / (numPoints - 2);
    10.  
    11. //MODIFY LAST POINT
    12. d_values[numPoints-1] = ReceivedValue;
    13.  
    14. d_interval = interval;
    15. }
    To copy to clipboard, switch view to plain text mode 

    It is clear that I have to modify the d_values index in another way, and I think it has something to do with the setReferenceTime of the CircularBuffer implementation. Do you have any suggestion of how to do that?

    Regards,

    -E

    PS: I thought about using the oscilloscope example as a base of my implementation, but I prefer the refreshtext example to always have the last receibed value in the right part of the plot.
    Last edited by Ethan; 25th October 2011 at 12:51. Reason: clarification

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

    Default Re: Refreshtest example. How to introduce new data in the circularbuffer.

    Quote Originally Posted by Ethan View Post
    These days I have been trying to use the refreshtest example to plot different data (i.e. not a circular buffer)
    Then write a class for your type of buffer instead of trying to modify a class, that is written for a different use case ( example code ).
    In the end all what your class has to offer is the API how to iterate over the points,

    Uwe

  3. #3
    Join Date
    Jun 2011
    Posts
    26
    Thanks
    3
    Thanked 3 Times in 3 Posts

    Default Re: Refreshtest example. How to introduce new data in the circularbuffer.

    Yes, and that is actually what I am trying to do. Can someone explain me what this line of code does?:
    Qt Code:
    1. CircularBuffer *buffer = (CircularBuffer *)d_curve->data();
    To copy to clipboard, switch view to plain text mode 

    I know this is a casting, d_curve is a QwtPlotCurve pointer, and data() backs a QwtSeriesData< QPointF > pointer. On the other hand, CircularBuffer inherits from QwtSeriesData<QPointF>. It seems to me that, somehow, with this casting I can use the CircularBuffer methods with the data pointed by a QwtSeriesData<QPointF> pointer. Is that the main reason of this line of code, if not, which is?

    Regards,

    -E
    Last edited by Ethan; 25th October 2011 at 18:43.

Similar Threads

  1. DockWidgetArea change and layout direction change
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 21st February 2012, 22:24
  2. QTableView with QSqlTableModel - change widget for edit data
    By elektrrrus in forum Qt Programming
    Replies: 3
    Last Post: 24th February 2011, 16:51
  3. Replies: 8
    Last Post: 25th April 2010, 22:19
  4. Replies: 1
    Last Post: 25th January 2010, 11:12
  5. Change database data in the QTabelView
    By sophister in forum Qt Programming
    Replies: 3
    Last Post: 9th April 2009, 17:40

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.