@@ -199,352 +199,362 @@ void PlotManager::onChannelInfoChanged(c
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]->setVisible(true);
void PlotManager::setMulti(bool enabled)
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);
// add new widgets and attach
int i = 0;
auto plot = addPlotWidget();
plot->setVisible(curve->isVisible());
plot->setDispChannels(QVector<const StreamChannel*>(1, _stream->channel(i)));
curve->attach(plot);
i++;
else
// add a single widget
if (_stream != nullptr)
plot->setDispChannels(_stream->allChannels());
// attach all curves
// will skip if no plot widgets exist (can happen during constructor)
if (plotWidgets.length())
checkNoVisChannels();
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);
// 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(_menu->darkBackgroundAction.isChecked());
plot->showGrid(_menu->showGridAction.isChecked());
plot->showMinorGrid(_menu->showMinorGridAction.isChecked());
plot->showLegend(_menu->showLegendAction.isChecked());
plot->setSymbols(_menu->showSymbols());
plot->showDemoIndicator(isDemoShown);
plot->setYAxis(_autoScaled, _yMin, _yMax);
plot->setNumOfSamples(_numOfSamples);
plot->setPlotWidth(_plotWidth);
if (_xAxisAsIndex)
plot->setXAxis(0, _numOfSamples);
plot->setXAxis(_xMin, _xMax);
return plot;
void PlotManager::addCurve(QString title, const XFrameBuffer* xBuf, const FrameBuffer* yBuf)
auto curve = new QwtPlotCurve(title);
auto series = new FrameBufferSeries(xBuf, yBuf);
curve->setSamples(series);
_addCurve(curve);
void PlotManager::_addCurve(QwtPlotCurve* curve)
// store and init the curve
curves.append(curve);
unsigned index = curves.size()-1;
auto color = infoModel->color(index);
curve->setPen(color);
// create the plot for the curve if we are on multi display
Plot* plot;
// create a new plot widget
plot = addPlotWidget();
plot = plotWidgets[0];
if (_stream != nullptr) // not displaying snapshot
QVector<const StreamChannel*> dispChannels;
dispChannels = QVector<const StreamChannel*>(1, _stream->channel(index));
dispChannels = _stream->allChannels();
plot->setDispChannels(dispChannels);
// show the curve
plot->replot();
void PlotManager::removeCurves(unsigned number)
if (! isMulti)
plotWidgets[0]->setDispChannels(dispChannels);
for (unsigned i = 0; i < number; i++)
if (!curves.isEmpty())
delete curves.takeLast();
if (isMulti) // delete corresponding widget as well
unsigned PlotManager::numOfCurves()
return curves.size();
Plot* PlotManager::plotWidget(unsigned curveIndex)
return plotWidgets[curveIndex];
return plotWidgets[0];
void PlotManager::replot()
for (auto plot : plotWidgets)
void PlotManager::showGrid(bool show)
plot->showGrid(show);
void PlotManager::showMinorGrid(bool show)
plot->showMinorGrid(show);
void PlotManager::showLegend(bool show)
plot->showLegend(show);
void PlotManager::showDemoIndicator(bool show)
isDemoShown = show;
plot->showDemoIndicator(show);
void PlotManager::unzoom()
plot->unzoom();
void PlotManager::darkBackground(bool enabled)
plot->darkBackground(enabled);
void PlotManager::setSymbols(Plot::ShowSymbols shown)
showSymbols = shown;
plot->setSymbols(shown);
void PlotManager::setYAxis(bool autoScaled, double yAxisMin, double yAxisMax)
_autoScaled = autoScaled;
_yMin = yAxisMin;
_yMax = yAxisMax;
plot->setYAxis(autoScaled, yAxisMin, yAxisMax);
void PlotManager::setXAxis(bool asIndex, double xMin, double xMax)
_xAxisAsIndex = asIndex;
_xMin = xMin;
_xMax = xMax;
int ci = 0;
FrameBufferSeries* series = static_cast<FrameBufferSeries*>(curve->data());
series->setX(_stream->channel(ci)->xData());
ci++;
if (asIndex)
plot->setXAxis(xMin, xMax);
void PlotManager::flashSnapshotOverlay()
plot->flashSnapshotOverlay(_menu->darkBackgroundAction.isChecked());
void PlotManager::setNumOfSamples(unsigned value)
_numOfSamples = value;
plot->setNumOfSamples(value);
if (_xAxisAsIndex) plot->setXAxis(0, value);
void PlotManager::setPlotWidth(double width)
_plotWidth = width;
plot->setPlotWidth(width);
Status change: