Results 1 to 3 of 3

Thread: QwtPlot (v5.1.1) looses connection to legend after manual clear() and reload

  1. #1
    Join Date
    Dec 2008
    Location
    California, USA
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QwtPlot (v5.1.1) looses connection to legend after manual clear() and reload

    QwtPlot (v5.1.1) looses connection to legend after I manually clear() and reload legend.
    Can't toggle curves off/on.

    I've provided this function so users can collapse the legend down to only those curves that are visible in QwtPlot area.

    QwtPlot legendChecked(QwtPlotItem*, bool) signal doesn't appear to be "Emitted" after my simplifyLegend() method (see src below) is called. I suspect this because I have a slot that's connected to the legendChecked() signal, and it's never entered if my simplifyLegend function is called prior to the legendChecked event.
    Note: Everything works fine (I can toggle curves off/on) if I don't call my simplifyLegend().

    Any Ideas?

    Here's the function:

    void SingleLogTrack::simplifyLegend(bool on) {

    m_plotItems = itemList();
    m_legend->clear();

    foreach (QwtPlotItem *plt_item, m_plotItems) {
    QwtLegendItem* lgd_item = new QwtLegendItem();
    if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
    QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);
    lgd_item->setText(c->title().text());
    lgd_item->setSymbol(c->symbol());
    lgd_item->setCurvePen(c->pen());
    lgd_item->setItemMode(QwtLegend::CheckableItem);
    if (c->style() == QwtPlotCurve::NoCurve)
    lgd_item->setIdentifierMode(QwtLegendItem::ShowSymbol);
    else
    lgd_item->setIdentifierMode(QwtLegendItem::ShowLine);
    lgd_item->setChecked(c->isVisible());
    }

    if (plt_item->title().text() != "Marker" &&
    plt_item->title().text() != "Grid") {
    if (on) {
    if (plt_item->isVisible()) m_legend->insert(plt_item,lgd_item);
    } else {

    m_legend->insert(plt_item,lgd_item);
    }
    }
    }
    replot();

    }

  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: QwtPlot (v5.1.1) looses connection to legend after manual clear() and reload

    Your code doesn't connect the clicked/checked signals of the legend item with the legendItemClicked/legendItemChecked slots of the plot widget.

    I've provided this function so users can collapse the legend down to only those curves that are visible in QwtPlot area.
    Better use curve->setItemAttribute(QwtPlotItem::Legend, ...) instead. F.e. overload QwtPlotCurve::setVisible() and toggle the flag together with it.

    Uwe

  3. #3
    Join Date
    Dec 2008
    Location
    California, USA
    Posts
    18
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Smile Re: QwtPlot (v5.1.1) looses connection to legend after manual clear() and reload

    Uwe, got it working. Thanks for the reply!

    I was successful implementing curve->setItemAttribute(QwtPlotItem::Legend,...) in my simplifyLegend() function.

    Here's the new version of the function:

    void SingleLogTrack::simplifyLegend(bool on) {
    bool showit = true;
    foreach (QwtPlotItem *plt_item, itemList()) {
    if ( plt_item->rtti() == QwtPlotItem::Rtti_PlotCurve ) {
    QwtPlotCurve *c = (QwtPlotCurve*)(plt_item);
    if (on) showit = c->isVisible();
    c->setItemAttribute(QwtPlotItem::Legend,showit);
    }
    }
    }

    The only issue I can see is that when the legend items are put back into the legend, they appear to be split into two groups: visible curves and hidden curves; consequently, they're not listed in the same order that was originally loaded (and stored in the QwtPlotItemList). Not a big problem however. And I can live with it.

    Thank you again

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.