Changeset - 85b902fd5722
[Not reviewed]
barplot
0 1 0
Hasan Yavuz Ă–ZDERYA - 8 years ago 2017-10-07 08:32:10
hy@ozderya.net
fix initial background for barplot
1 file changed with 1 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/plotmanager.cpp
Show inline comments
 
@@ -192,192 +192,193 @@ void PlotManager::onChannelInfoChanged(c
 
        curves[ci]->setItemAttribute(QwtPlotItem::Legend, visible);
 

	
 
        // replot only updated widgets
 
        if (isMulti)
 
        {
 
            plotWidgets[ci]->updateSymbols(); // required for color change
 
            plotWidgets[ci]->updateLegend(curves[ci]);
 
            plotWidgets[ci]->setVisible(visible);
 
            if (visible)
 
            {
 
                plotWidgets[ci]->replot();
 
            }
 
        }
 
    }
 

	
 
    checkNoVisChannels();
 

	
 
    // replot single widget
 
    if (!isMulti)
 
    {
 
        plotWidgets[0]->updateSymbols();
 
        plotWidgets[0]->updateLegend();
 
        replot();
 
    }
 
}
 

	
 
void PlotManager::checkNoVisChannels()
 
{
 
    // if all channels are hidden show indicator
 
    bool allhidden = std::none_of(curves.cbegin(), curves.cend(),
 
                                  [](QwtPlotCurve* c) {return c->isVisible();});
 

	
 
    plotWidgets[0]->showNoChannel(allhidden);
 
    if (isMulti)
 
    {
 
        plotWidgets[0]->showNoChannel(allhidden);
 
        plotWidgets[0]->setVisible(true);
 
    }
 
}
 

	
 
void PlotManager::setMulti(bool enabled)
 
{
 
    if (enabled == isMulti) return;
 

	
 
    isMulti = enabled;
 

	
 
    // detach all curves
 
    for (auto curve : curves)
 
    {
 
        curve->detach();
 
    }
 

	
 
    // remove all widgets
 
    while (plotWidgets.size())
 
    {
 
        delete plotWidgets.takeLast();
 
    }
 

	
 
    // setup new layout
 
    setupLayout(isMulti);
 

	
 
    if (isMulti)
 
    {
 
        // add new widgets and attach
 
        for (auto curve : curves)
 
        {
 
            auto plot = addPlotWidget();
 
            plot->setVisible(curve->isVisible());
 
            curve->attach(plot);
 
        }
 
    }
 
    else
 
    {
 
        // add a single widget
 
        auto plot = addPlotWidget();
 

	
 
        // attach all curves
 
        for (auto curve : curves)
 
        {
 
            curve->attach(plot);
 
        }
 
    }
 

	
 
    checkNoVisChannels();
 
}
 

	
 
void PlotManager::showBarPlot(bool show)
 
{
 
    // A secondary plot can only be shown if splitter is provided.
 
    Q_ASSERT(_splitter != NULL);
 

	
 
    if (show)
 
    {
 
        Q_ASSERT(barPlot == NULL);
 

	
 
        barPlot = new BarPlot(_channelMan, _splitter);
 
        barPlot->darkBackground(darkBackgroundAction.isChecked());
 
    }
 
    else
 
    {
 
        Q_ASSERT(barPlot != NULL);
 

	
 
        delete barPlot;
 
        barPlot = NULL;
 
    }
 
}
 

	
 
void PlotManager::setupLayout(bool multiPlot)
 
{
 
    // delete previous layout if it exists
 
    if (_plotArea->layout() != 0)
 
    {
 
        delete _plotArea->layout();
 
    }
 

	
 
    if (multiPlot)
 
    {
 
        // setup a scroll area
 
        scrollArea = new QScrollArea();
 
        auto scrolledPlotArea = new QWidget(scrollArea);
 
        scrollArea->setWidget(scrolledPlotArea);
 
        scrollArea->setWidgetResizable(true);
 

	
 
        _plotArea->setLayout(new QVBoxLayout());
 
        _plotArea->layout()->addWidget(scrollArea);
 
        _plotArea->layout()->setContentsMargins(0,0,0,0);
 

	
 
        layout = new QVBoxLayout(scrolledPlotArea);
 
    }
 
    else
 
    {
 
        // delete scrollArea left from multi layout
 
        if (scrollArea != NULL)
 
        {
 
            delete scrollArea;
 
            scrollArea = NULL;
 
        }
 

	
 
        layout = new QVBoxLayout(_plotArea);
 
    }
 

	
 
    layout->setContentsMargins(2,2,2,2);
 
    layout->setSpacing(1);
 
}
 

	
 
Plot* PlotManager::addPlotWidget()
 
{
 
    auto plot = new Plot();
 
    plotWidgets.append(plot);
 
    layout->addWidget(plot);
 

	
 
    plot->darkBackground(darkBackgroundAction.isChecked());
 
    plot->showGrid(showGridAction.isChecked());
 
    plot->showMinorGrid(showMinorGridAction.isChecked());
 
    plot->showLegend(showLegendAction.isChecked());
 
    plot->showDemoIndicator(isDemoShown);
 
    plot->setYAxis(_autoScaled, _yMin, _yMax);
 
    plot->setNumOfSamples(_numOfSamples);
 
    plot->setSymbols(showSymbols);
 

	
 
    plot->setPlotWidth(_plotWidth);
 
    if (_xAxisAsIndex)
 
    {
 
        plot->setXAxis(0, _numOfSamples);
 
    }
 
    else
 
    {
 
        plot->setXAxis(_xMin, _xMax);
 
    }
 

	
 
    return plot;
 
}
 

	
 
void PlotManager::addCurve(QString title, FrameBuffer* buffer)
 
{
 
    auto curve = new QwtPlotCurve(title);
 
    auto series = new FrameBufferSeries(buffer);
 
    series->setXAxis(_xAxisAsIndex, _xMin, _xMax);
 
    curve->setSamples(series);
 
    _addCurve(curve);
 
}
 

	
 
void PlotManager::addCurve(QString title, QVector<QPointF> data)
 
{
 
    auto curve = new QwtPlotCurve(title);
 
    curve->setSamples(data);
 
    _addCurve(curve);
 
}
 

	
 
void PlotManager::_addCurve(QwtPlotCurve* curve)
 
{
 
    // store and init the curve
 
    curves.append(curve);
0 comments (0 inline, 0 general)