1 Attachment(s)
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;
Code:
/*!
\brief Adds new curve by given properties.
\param curveGroupIndex curve will be child of curve group index
\param curveName curve name
\param curvePen curve pen
\param curveVisibility curve visibility state
\param curveStyle curve style
\return new curve index
\retval -1 curve creation fails
\retval >= 0 curve created and returns curve index
\author Umit Uzun
\date 04/04/2010
\sa QwtPlotCurve::CurveStyle QwtPlot::Axis
*/
short CurveManager::setCurveAddCurve(const ushort &curveGroupIndex,
const bool curveVisibility,
{
short curveIndex = -1;
name.setText(curveName);
name.setColor(curvePen.color());
if ( curve != NULL )
{
curve->setPen(curvePen);
curve->setVisible(curveVisibility);
curve
->setAxis
(QwtPlot::xBottom, curveAxis
);
curve->setStyle(curveStyle);
curve->setData(new CurveData());
curve
->setLegendAttribute
(QwtPlotCurve::LegendShowSymbol,
!curveVisibility
);
curve->attach(privateData.qGraph);
if ( legendItem != NULL )
{
legendItem->setChecked(curveVisibility);
legendItem->setMargin(-1);
legendItem->setSpacing(10);
}
QwtPlotItemList plotItemList
= privateData.
qGraph->itemList
(QwtPlotItem::Rtti_PlotCurve);
if ( plotItemList.size() > 0 )
{
curveIndex
= plotItemList.
indexOf((QwtPlotItem *)curve
);
privateData.curveTree.insert(plotItemList.at(curveGroupIndex), plotItemList.at(curveIndex));
}
}
return curveIndex;
}
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.
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