/*
Copyright © 2017 Hasan Yavuz Özderya
Copyright © 2018 Hasan Yavuz Özderya
This file is part of serialplot.
serialplot is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
serialplot is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with serialplot. If not, see <http://www.gnu.org/licenses/>.
*/
#include <algorithm>
#include <QMetaEnum>
#include <QtDebug>
#include "qwt_symbol.h"
#include "plot.h"
#include "plotmanager.h"
#include "utils.h"
#include "setting_defines.h"
PlotManager::PlotManager(QWidget* plotArea, PlotMenu* menu,
ChannelInfoModel* infoModel, QObject* parent) :
QObject(parent)
{
_menu = menu;
_plotArea = plotArea;
_autoScaled = true;
_yMin = 0;
_yMax = 1;
_xAxisAsIndex = true;
isDemoShown = false;
_infoModel = infoModel;
_numOfSamples = 1;
_plotWidth = 1;
showSymbols = Plot::ShowSymbolsAuto;
emptyPlot = NULL;
// initalize layout and single widget
isMulti = false;
scrollArea = NULL;
setupLayout(isMulti);
@@ -160,98 +160,102 @@ void PlotManager::checkNoVisChannels()
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
if (isMulti)
// add new widgets and attach
auto plot = addPlotWidget();
plot->setVisible(curve->isVisible());
curve->attach(plot);
else
// add a single widget
// 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;
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());
Status change: