LP-56 - Better txpid option namings, fix tabs-spaces, tooltips. headers, variable...
[librepilot.git] / ground / openpilotgcs / src / plugins / scope / scopegadget.cpp
blob5531897d13e66d07459a4b8fa5189682cfd296e3
1 /**
2 ******************************************************************************
4 * @file scopegadget.cpp
5 * @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
6 * @addtogroup GCSPlugins GCS Plugins
7 * @{
8 * @addtogroup ScopePlugin Scope Gadget Plugin
9 * @{
10 * @brief The scope Gadget, graphically plots the states of UAVObjects
11 *****************************************************************************/
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful, but
19 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 * for more details.
23 * You should have received a copy of the GNU General Public License along
24 * with this program; if not, write to the Free Software Foundation, Inc.,
25 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "scopegadget.h"
29 #include "scopegadgetconfiguration.h"
30 #include "scopegadgetwidget.h"
32 #include <QVBoxLayout>
33 #include <qcolor.h>
35 ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
36 IUAVGadget(classId, parent), m_widget(widget)
38 m_wrapper = new QWidget();
39 QVBoxLayout *layout = new QVBoxLayout();
40 layout->setContentsMargins(4, 4, 4, 4);
41 layout->addWidget(m_widget);
42 m_wrapper->setLayout(layout);
45 void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
47 ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration *>(config);
48 ScopeGadgetWidget *widget = qobject_cast<ScopeGadgetWidget *>(m_widget);
50 widget->setObjectName(config->name());
51 widget->setPlotDataSize(sgConfig->dataSize());
52 widget->setRefreshInterval(sgConfig->refreshInterval());
54 if (sgConfig->plotType() == SequentialPlot) {
55 widget->setupSequentialPlot();
56 } else if (sgConfig->plotType() == ChronoPlot) {
57 widget->setupChronoPlot();
60 foreach(PlotCurveConfiguration * plotCurveConfig, sgConfig->plotCurveConfigs()) {
61 QString uavObject = plotCurveConfig->uavObject;
62 QString uavField = plotCurveConfig->uavField;
63 int scale = plotCurveConfig->yScalePower;
64 int mean = plotCurveConfig->yMeanSamples;
65 QString mathFunction = plotCurveConfig->mathFunction;
66 QRgb color = plotCurveConfig->color;
67 bool antialiased = plotCurveConfig->drawAntialiased;
69 widget->addCurvePlot(
70 uavObject,
71 uavField,
72 scale,
73 mean,
74 mathFunction,
75 QPen(QBrush(QColor(color), Qt::SolidPattern),
76 (qreal)1,
77 Qt::SolidLine,
78 Qt::SquareCap,
79 Qt::BevelJoin),
80 antialiased
84 widget->setLoggingEnabled(sgConfig->getLoggingEnabled());
85 widget->setLoggingNewFileOnConnect(sgConfig->getLoggingNewFileOnConnect());
86 widget->setLoggingPath(sgConfig->getLoggingPath());
88 widget->csvLoggingStop();
89 widget->csvLoggingSetName(sgConfig->name());
90 widget->csvLoggingStart();
93 /**
94 Scope gadget destructor: should delete the associated scope gadget widget too!
96 ScopeGadget::~ScopeGadget()
98 delete m_widget;
101 void ScopeGadget::saveState(QSettings *qSettings)
103 m_widget->saveState(qSettings);
106 void ScopeGadget::restoreState(QSettings *qSettings)
108 m_widget->restoreState(qSettings);