Results 1 to 5 of 5

Thread: A suggestion about QwtPlotLegendItem

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2013
    Posts
    56
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default A suggestion about QwtPlotLegendItem

    Hi Uwe,
    I am using QWT6.1 - Downloaded at 20130630.
    In my application, it's required to refresh the legend item when the data is changed and I found that :

    In the updateLegend() of QwtPlotLegendItem, the layoutItems does not be cleared at each time.
    So the list length will be longer and longer, and not be equal to the count of actual items.
    eg.
    updateLegend( plotItem, dataOfSize1 );
    updateLegend( plotItem, dataOfSize2 );
    updateLegend( plotItem, dataOfSize1 );
    then at the third call of updateLegend(), it will crash.

    The codes are like below.

    Hope this information is useful.
    Nicho

    Qt Code:
    1. void QwtPlotLegendItem::updateLegend( const QwtPlotItem *plotItem,
    2. const QList<QwtLegendData> &data )
    3. {
    4. if ( plotItem == NULL )
    5. return;
    6.  
    7. QList<QwtLegendLayoutItem *> layoutItems;
    8.  
    9. QMap<const QwtPlotItem *, QList<QwtLegendLayoutItem *> >::iterator it =
    10. d_data->map.find( plotItem );
    11. if ( it != d_data->map.end() )
    12. layoutItems = it.value();
    13.  
    14. bool changed = false;
    15.  
    16. if ( data.size() != layoutItems.size() )
    17. {
    18. changed = true;
    19.  
    20. for ( int i = 0; i < layoutItems.size(); i++ )
    21. {
    22. d_data->layout->removeItem( layoutItems[i] );
    23. delete layoutItems[i];//app may crash here.
    24. }
    25. layoutItems.clear();//suggestion
    26. if ( it != d_data->map.end() )
    27. d_data->map.remove( plotItem );
    28.  
    29. if ( !data.isEmpty() )
    30. {
    31. for ( int i = 0; i < data.size(); i++ )
    32. {
    33. QwtLegendLayoutItem *layoutItem =
    34. new QwtLegendLayoutItem( this, plotItem );
    35. d_data->layout->addItem( layoutItem );
    36. layoutItems += layoutItem;
    37. }
    38.  
    39. d_data->map.insert( plotItem, layoutItems );
    40. }
    41. }
    42.  
    43. for ( int i = 0; i < data.size(); i++ )
    44. {
    45. if ( layoutItems[i]->data().values() != data[i].values() )
    46. {
    47. layoutItems[i]->setData( data[i] );
    48. changed = true;
    49. }
    50. }
    51.  
    52. if ( changed )
    53. {
    54. d_data->layout->invalidate();
    55. itemChanged();
    56. }
    57. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Nicho; 16th August 2013 at 12:12.

Similar Threads

  1. QwtPlotLegendItem and QwtLegendItem
    By jesse_mark in forum Qwt
    Replies: 3
    Last Post: 14th November 2012, 07:10
  2. Newbie to QT, any suggestion?
    By xhsoldier in forum Qt Programming
    Replies: 2
    Last Post: 4th June 2009, 13:09
  3. Multicasting--Not able to Do it, suggestion pls
    By swamyonline in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2009, 00:45
  4. SVG suggestion
    By Gopala Krishna in forum Qt Programming
    Replies: 5
    Last Post: 20th October 2007, 14:35

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.