Results 1 to 2 of 2

Thread: Virtual Grouping support for Legend in QwtPlot?

  1. #1
    Join Date
    Jan 2010
    Location
    Ankara - TURKEY
    Posts
    30
    Thanks
    13
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Virtual Grouping support for Legend in QwtPlot?

    Hi Uwe;

    I know there is no grouping support for default qwtLegend but I have developed myself as a virtual grouping support which is based on dummy curves in legend. I have created dummy curves (which hasn't ant CurveData) and set as a group curve after then when I am creating new curve I send related group index which is index of QwtPlotItemList. Then I create my curve like below;

    Qt Code:
    1. /*!
    2. \brief Adds new curve by given properties.
    3.  
    4. \param curveGroupIndex curve will be child of curve group index
    5. \param curveName curve name
    6. \param curvePen curve pen
    7. \param curveVisibility curve visibility state
    8. \param curveStyle curve style
    9.  
    10. \return new curve index
    11. \retval -1 curve creation fails
    12. \retval >= 0 curve created and returns curve index
    13.  
    14. \author Umit Uzun
    15. \date 04/04/2010
    16.  
    17. \sa QwtPlotCurve::CurveStyle QwtPlot::Axis
    18. */
    19. short CurveManager::setCurveAddCurve(const ushort &curveGroupIndex,
    20. const QString &curveName,
    21. const QPen &curvePen,
    22. const bool curveVisibility,
    23. const QwtPlot::Axis curveAxis,
    24. const QwtPlotCurve::CurveStyle curveStyle)
    25. {
    26. short curveIndex = -1;
    27.  
    28. QwtText name;
    29. name.setText(curveName);
    30. name.setColor(curvePen.color());
    31.  
    32. QwtPlotCurve *curve = new QwtPlotCurve(name);
    33. if ( curve != NULL )
    34. {
    35. curve->setPen(curvePen);
    36. curve->setVisible(curveVisibility);
    37. curve->setAxis(QwtPlot::xBottom, curveAxis);
    38. curve->setStyle(curveStyle);
    39. curve->setData(new CurveData());
    40. curve->setPaintAttribute(QwtPlotCurve::ClipPolygons);
    41. curve->setRenderHint(QwtPlotItem::RenderAntialiased);
    42. curve->setLegendAttribute(QwtPlotCurve::LegendShowSymbol, !curveVisibility);
    43. curve->attach(privateData.qGraph);
    44.  
    45. QwtLegendItem *legendItem = (QwtLegendItem *)privateData.qGraph->legend()->find(curve);
    46. if ( legendItem != NULL )
    47. {
    48. legendItem->setChecked(curveVisibility);
    49. legendItem->setMargin(-1);
    50. legendItem->setSpacing(10);
    51. }
    52.  
    53. QwtPlotItemList plotItemList = privateData.qGraph->itemList(QwtPlotItem::Rtti_PlotCurve);
    54. if ( plotItemList.size() > 0 )
    55. {
    56. curveIndex = plotItemList.indexOf((QwtPlotItem *)curve);
    57. privateData.curveTree.insert(plotItemList.at(curveGroupIndex), plotItemList.at(curveIndex));
    58. }
    59. }
    60.  
    61. return curveIndex;
    62. }
    To copy to clipboard, switch view to plain text mode 

    I can give my curves space, margin and indent properties but any of them not change curve identifier position in legend. My real target is indenting curve name and identifier together but I can only set indention for curve text in legend as you can see from attached screenshot.

    How can I indent curve identifier with text in my legend?

    Another question; do you think add groping support for formatted curve managing on the legend in the future?

    Regards.
    Attached Images Attached Images

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

    Default Re: Virtual Grouping support for Legend in QwtPlot?

    You can overload QwtPlotCurve::updateLegend and QwtPlotCurve::legendItem to play together with any other widget that you want to play as legend. Then you can align your legend to the plot with a simple QBoxLayout.

    If you need to print your legend together with the plot you have to write code, that renders it into a rectangle and some layout code, that calculates the rectangles for plot and legend.

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    umituzun84 (9th April 2010)

Similar Threads

  1. Replies: 2
    Last Post: 27th October 2009, 13:40
  2. Custom file browser - grouping files
    By chezifresh in forum Qt Programming
    Replies: 3
    Last Post: 21st September 2009, 03:05
  3. Replies: 6
    Last Post: 14th May 2009, 12:02
  4. Replies: 2
    Last Post: 5th December 2008, 20:11
  5. Grouping Widgets Together
    By joshuajcarson in forum Qt Programming
    Replies: 1
    Last Post: 21st October 2008, 20:17

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.