2010-08-10 05:42:39 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
*
|
|
|
|
* @file scopegadgetoptionspage.cpp
|
|
|
|
* @author The OpenPilot Team, http://www.openpilot.org Copyright (C) 2010.
|
|
|
|
* @addtogroup GCSPlugins GCS Plugins
|
|
|
|
* @{
|
|
|
|
* @addtogroup ScopePlugin Scope Gadget Plugin
|
|
|
|
* @{
|
|
|
|
* @brief The scope Gadget, graphically plots the states of UAVObjects
|
|
|
|
*****************************************************************************/
|
|
|
|
/*
|
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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 this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "scopegadgetoptionspage.h"
|
|
|
|
|
|
|
|
#include "extensionsystem/pluginmanager.h"
|
2011-01-22 17:38:22 +00:00
|
|
|
#include "uavobjectmanager.h"
|
|
|
|
#include "uavdataobject.h"
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
|
2013-09-15 23:06:25 +02:00
|
|
|
#include <qpalette.h>
|
2010-08-29 22:45:12 +00:00
|
|
|
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
ScopeGadgetOptionsPage::ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent) :
|
2013-05-13 21:24:19 +02:00
|
|
|
IOptionsPage(parent),
|
|
|
|
m_config(config)
|
2010-08-10 05:42:39 +00:00
|
|
|
{
|
2013-05-13 21:24:19 +02:00
|
|
|
// nothing to do here...
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// creates options page widget (uses the UI file)
|
|
|
|
QWidget *ScopeGadgetOptionsPage::createPage(QWidget *parent)
|
2010-08-10 05:42:39 +00:00
|
|
|
{
|
2010-09-21 19:29:43 +00:00
|
|
|
Q_UNUSED(parent);
|
|
|
|
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page = new Ui::ScopeGadgetOptionsPage();
|
2013-05-13 21:24:19 +02:00
|
|
|
// main widget
|
2010-08-10 05:42:39 +00:00
|
|
|
QWidget *optionsPageWidget = new QWidget;
|
2013-05-13 21:24:19 +02:00
|
|
|
// main layout
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->setupUi(optionsPageWidget);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
options_page->cmbPlotType->addItem("Sequential Plot", "");
|
|
|
|
options_page->cmbPlotType->addItem("Chronological Plot", "");
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
// Fills the combo boxes for the UAVObjects
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
2013-05-13 21:24:19 +02:00
|
|
|
QList< QList<UAVDataObject *> > objList = objManager->getDataObjects();
|
|
|
|
foreach(QList<UAVDataObject *> list, objList) {
|
|
|
|
foreach(UAVDataObject * obj, list) {
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->cmbUAVObjects->addItem(obj->getName());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// Connect signals to slots cmbUAVObjects.currentIndexChanged
|
2010-08-10 05:42:39 +00:00
|
|
|
connect(options_page->cmbUAVObjects, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_cmbUAVObjects_currentIndexChanged(QString)));
|
|
|
|
|
2012-05-22 05:21:11 +03:00
|
|
|
options_page->mathFunctionComboBox->addItem("None");
|
2012-05-22 12:34:01 +03:00
|
|
|
options_page->mathFunctionComboBox->addItem("Boxcar average");
|
2012-05-22 05:21:11 +03:00
|
|
|
options_page->mathFunctionComboBox->addItem("Standard deviation");
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (options_page->cmbUAVObjects->currentIndex() >= 0) {
|
2010-08-10 05:42:39 +00:00
|
|
|
on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText());
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2012-05-22 00:40:01 +03:00
|
|
|
options_page->cmbScale->addItem("10^-9", -9);
|
|
|
|
options_page->cmbScale->addItem("10^-6", -6);
|
2013-05-13 21:24:19 +02:00
|
|
|
options_page->cmbScale->addItem("10^-5", -5);
|
|
|
|
options_page->cmbScale->addItem("10^-4", -4);
|
|
|
|
options_page->cmbScale->addItem("10^-3", -3);
|
|
|
|
options_page->cmbScale->addItem("10^-2", -2);
|
|
|
|
options_page->cmbScale->addItem("10^-1", -1);
|
|
|
|
options_page->cmbScale->addItem("1", 0);
|
|
|
|
options_page->cmbScale->addItem("10^1", 1);
|
|
|
|
options_page->cmbScale->addItem("10^2", 2);
|
|
|
|
options_page->cmbScale->addItem("10^3", 3);
|
|
|
|
options_page->cmbScale->addItem("10^4", 4);
|
|
|
|
options_page->cmbScale->addItem("10^5", 5);
|
|
|
|
options_page->cmbScale->addItem("10^6", 6);
|
|
|
|
options_page->cmbScale->addItem("10^9", 9);
|
|
|
|
options_page->cmbScale->addItem("10^12", 12);
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->cmbScale->setCurrentIndex(7);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// Set widget values from settings
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->cmbPlotType->setCurrentIndex(m_config->plotType());
|
2012-05-22 05:21:11 +03:00
|
|
|
options_page->mathFunctionComboBox->setCurrentIndex(m_config->mathFunctionType());
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->spnDataSize->setValue(m_config->dataSize());
|
|
|
|
options_page->spnRefreshInterval->setValue(m_config->refreshInterval());
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// add the configured curves
|
|
|
|
foreach(PlotCurveConfiguration * plotData, m_config->plotCurveConfigs()) {
|
2013-05-19 17:37:30 +03:00
|
|
|
QString uavObject = plotData->uavObject;
|
|
|
|
QString uavField = plotData->uavField;
|
2010-08-10 05:42:39 +00:00
|
|
|
int scale = plotData->yScalePower;
|
2012-05-22 05:21:11 +03:00
|
|
|
int mean = plotData->yMeanSamples;
|
|
|
|
QString mathFunction = plotData->mathFunction;
|
2013-05-19 17:37:30 +03:00
|
|
|
QVariant varColor = plotData->color;
|
|
|
|
bool antialiased = plotData->drawAntialiased;
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
addPlotCurveConfig(uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (m_config->plotCurveConfigs().count() > 0) {
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->lstCurves->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
connect(options_page->btnAddCurve, SIGNAL(clicked()), this, SLOT(on_btnAddCurve_clicked()));
|
|
|
|
connect(options_page->btnRemoveCurve, SIGNAL(clicked()), this, SLOT(on_btnRemoveCurve_clicked()));
|
|
|
|
connect(options_page->lstCurves, SIGNAL(currentRowChanged(int)), this, SLOT(on_lstCurves_currentRowChanged(int)));
|
|
|
|
connect(options_page->btnColor, SIGNAL(clicked()), this, SLOT(on_btnColor_clicked()));
|
2012-05-22 12:34:01 +03:00
|
|
|
connect(options_page->mathFunctionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_mathFunctionComboBox_currentIndexChanged(int)));
|
2013-05-13 21:24:19 +02:00
|
|
|
connect(options_page->spnRefreshInterval, SIGNAL(valueChanged(int)), this, SLOT(on_spnRefreshInterval_valueChanged(int)));
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
setYAxisWidgetFromPlotCurve();
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// logging path setup
|
2011-01-31 02:09:44 +00:00
|
|
|
options_page->LoggingPath->setExpectedKind(Utils::PathChooser::Directory);
|
|
|
|
options_page->LoggingPath->setPromptDialogTitle(tr("Choose Logging Directory"));
|
|
|
|
options_page->LoggingPath->setPath(m_config->getLoggingPath());
|
|
|
|
options_page->LoggingConnect->setChecked(m_config->getLoggingNewFileOnConnect());
|
|
|
|
options_page->LoggingEnable->setChecked(m_config->getLoggingEnabled());
|
|
|
|
connect(options_page->LoggingEnable, SIGNAL(clicked()), this, SLOT(on_loggingEnable_clicked()));
|
|
|
|
on_loggingEnable_clicked();
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// Disable mouse wheel events
|
|
|
|
foreach(QSpinBox * sp, findChildren<QSpinBox *>()) {
|
|
|
|
sp->installEventFilter(this);
|
2012-05-22 12:34:01 +03:00
|
|
|
}
|
2013-05-13 21:24:19 +02:00
|
|
|
foreach(QDoubleSpinBox * sp, findChildren<QDoubleSpinBox *>()) {
|
|
|
|
sp->installEventFilter(this);
|
2012-05-22 12:34:01 +03:00
|
|
|
}
|
2013-05-13 21:24:19 +02:00
|
|
|
foreach(QSlider * sp, findChildren<QSlider *>()) {
|
|
|
|
sp->installEventFilter(this);
|
2012-05-22 12:34:01 +03:00
|
|
|
}
|
2013-05-13 21:24:19 +02:00
|
|
|
foreach(QComboBox * sp, findChildren<QComboBox *>()) {
|
|
|
|
sp->installEventFilter(this);
|
2012-05-22 12:34:01 +03:00
|
|
|
}
|
2011-01-31 02:09:44 +00:00
|
|
|
|
2010-08-10 05:42:39 +00:00
|
|
|
return optionsPageWidget;
|
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
bool ScopeGadgetOptionsPage::eventFilter(QObject *obj, QEvent *evt)
|
|
|
|
{
|
|
|
|
// Filter all wheel events, and ignore them
|
|
|
|
if (evt->type() == QEvent::Wheel &&
|
|
|
|
(qobject_cast<QAbstractSpinBox *>(obj) ||
|
|
|
|
qobject_cast<QComboBox *>(obj) ||
|
|
|
|
qobject_cast<QAbstractSlider *>(obj))) {
|
2012-05-22 12:34:01 +03:00
|
|
|
evt->ignore();
|
|
|
|
return true;
|
|
|
|
}
|
2013-05-13 21:24:19 +02:00
|
|
|
return ScopeGadgetOptionsPage::eventFilter(obj, evt);
|
2012-05-22 12:34:01 +03:00
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
void ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged(int currentIndex)
|
|
|
|
{
|
|
|
|
if (currentIndex > 0) {
|
2012-05-22 12:34:01 +03:00
|
|
|
options_page->spnMeanSamples->setEnabled(true);
|
2013-05-13 21:24:19 +02:00
|
|
|
} else {
|
2012-05-22 12:34:01 +03:00
|
|
|
options_page->spnMeanSamples->setEnabled(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-10 05:42:39 +00:00
|
|
|
void ScopeGadgetOptionsPage::on_btnColor_clicked()
|
2013-05-13 21:24:19 +02:00
|
|
|
{
|
|
|
|
QColor color = QColorDialog::getColor(QColor(options_page->btnColor->text()));
|
|
|
|
|
|
|
|
if (color.isValid()) {
|
|
|
|
setButtonColor(color);
|
|
|
|
}
|
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
/*!
|
2013-05-13 21:24:19 +02:00
|
|
|
\brief Populate the widgets that containts the configs for the Y-Axis from
|
|
|
|
the selected plot curve
|
|
|
|
*/
|
2010-08-10 05:42:39 +00:00
|
|
|
void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
|
|
|
|
{
|
|
|
|
bool parseOK = false;
|
2013-05-13 21:24:19 +02:00
|
|
|
QListWidgetItem *listItem = options_page->lstCurves->currentItem();
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (listItem == 0) {
|
2010-08-10 05:42:39 +00:00
|
|
|
return;
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// WHAT IS UserRole DOING?
|
|
|
|
int currentIndex = options_page->cmbUAVObjects->findText(listItem->data(Qt::UserRole + 0).toString());
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->cmbUAVObjects->setCurrentIndex(currentIndex);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
currentIndex = options_page->cmbUAVField->findText(listItem->data(Qt::UserRole + 1).toString());
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->cmbUAVField->setCurrentIndex(currentIndex);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
currentIndex = options_page->cmbScale->findData(listItem->data(Qt::UserRole + 2), Qt::UserRole, Qt::MatchExactly);
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->cmbScale->setCurrentIndex(currentIndex);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
2010-08-10 05:42:39 +00:00
|
|
|
int rgb = varColor.toInt(&parseOK);
|
|
|
|
|
|
|
|
setButtonColor(QColor((QRgb)rgb));
|
2011-11-18 18:30:58 +01:00
|
|
|
|
2012-05-22 05:21:11 +03:00
|
|
|
int mean = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
|
2013-05-13 21:24:19 +02:00
|
|
|
if (!parseOK) {
|
|
|
|
mean = 1;
|
|
|
|
}
|
2012-05-22 05:21:11 +03:00
|
|
|
options_page->spnMeanSamples->setValue(mean);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
currentIndex = options_page->mathFunctionComboBox->findText(listItem->data(Qt::UserRole + 5).toString());
|
2012-05-22 05:21:11 +03:00
|
|
|
options_page->mathFunctionComboBox->setCurrentIndex(currentIndex);
|
2013-05-13 21:24:19 +02:00
|
|
|
options_page->drawAntialiasedCheckBox->setChecked(listItem->data(Qt::UserRole + 6).toBool());
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeGadgetOptionsPage::setButtonColor(const QColor &color)
|
|
|
|
{
|
2010-08-29 22:45:12 +00:00
|
|
|
options_page->btnColor->setAutoFillBackground(true);
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->btnColor->setText(color.name());
|
|
|
|
options_page->btnColor->setPalette(QPalette(color));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-05-13 21:24:19 +02:00
|
|
|
\brief When a new UAVObject is selected, populate the UAVObject field combo box with the correct values.
|
|
|
|
*/
|
2010-08-10 05:42:39 +00:00
|
|
|
void ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged(QString val)
|
|
|
|
{
|
|
|
|
options_page->cmbUAVField->clear();
|
|
|
|
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
2013-05-13 21:24:19 +02:00
|
|
|
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(val));
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (obj == NULL) {
|
2011-05-03 10:54:38 +02:00
|
|
|
return; // Rare case: the config contained a UAVObject name which does not exist anymore.
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
|
|
|
QList<UAVObjectField *> fieldList = obj->getFields();
|
|
|
|
foreach(UAVObjectField * field, fieldList) {
|
|
|
|
if (field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM) {
|
2010-08-30 14:17:15 +00:00
|
|
|
continue;
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2010-08-30 14:17:15 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (field->getElementNames().count() > 1) {
|
|
|
|
foreach(QString elemName, field->getElementNames()) {
|
2010-08-30 14:17:15 +00:00
|
|
|
options_page->cmbUAVField->addItem(field->getName() + "-" + elemName);
|
|
|
|
}
|
2013-05-13 21:24:19 +02:00
|
|
|
} else {
|
2010-08-30 14:17:15 +00:00
|
|
|
options_page->cmbUAVField->addItem(field->getName());
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when the user presses apply or OK.
|
|
|
|
*
|
|
|
|
* Saves the current values
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
void ScopeGadgetOptionsPage::apply()
|
|
|
|
{
|
|
|
|
bool parseOK = false;
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// Apply configuration changes
|
2010-08-10 05:42:39 +00:00
|
|
|
m_config->setPlotType(options_page->cmbPlotType->currentIndex());
|
2012-05-22 05:21:11 +03:00
|
|
|
m_config->setMathFunctionType(options_page->mathFunctionComboBox->currentIndex());
|
2010-08-10 05:42:39 +00:00
|
|
|
m_config->setDataSize(options_page->spnDataSize->value());
|
|
|
|
m_config->setRefreashInterval(options_page->spnRefreshInterval->value());
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
QList<PlotCurveConfiguration *> plotCurveConfigs;
|
|
|
|
for (int iIndex = 0; iIndex < options_page->lstCurves->count(); iIndex++) {
|
|
|
|
QListWidgetItem *listItem = options_page->lstCurves->item(iIndex);
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
PlotCurveConfiguration *newPlotCurveConfigs = new PlotCurveConfiguration();
|
|
|
|
newPlotCurveConfigs->uavObject = listItem->data(Qt::UserRole + 0).toString();
|
|
|
|
newPlotCurveConfigs->uavField = listItem->data(Qt::UserRole + 1).toString();
|
|
|
|
newPlotCurveConfigs->yScalePower = listItem->data(Qt::UserRole + 2).toInt(&parseOK);
|
|
|
|
if (!parseOK) {
|
2010-08-10 05:42:39 +00:00
|
|
|
newPlotCurveConfigs->yScalePower = 0;
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
2010-08-10 05:42:39 +00:00
|
|
|
int rgb = varColor.toInt(&parseOK);
|
2013-05-13 21:24:19 +02:00
|
|
|
if (!parseOK) {
|
2010-08-10 05:42:39 +00:00
|
|
|
newPlotCurveConfigs->color = QColor(Qt::black).rgb();
|
2013-05-13 21:24:19 +02:00
|
|
|
} else {
|
2010-08-10 05:42:39 +00:00
|
|
|
newPlotCurveConfigs->color = (QRgb)rgb;
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2012-05-22 05:21:11 +03:00
|
|
|
|
|
|
|
newPlotCurveConfigs->yMeanSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
|
2013-05-13 21:24:19 +02:00
|
|
|
if (!parseOK) {
|
2012-05-22 05:21:11 +03:00
|
|
|
newPlotCurveConfigs->yMeanSamples = 1;
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2012-05-22 05:21:11 +03:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
newPlotCurveConfigs->mathFunction = listItem->data(Qt::UserRole + 5).toString();
|
|
|
|
newPlotCurveConfigs->drawAntialiased = listItem->data(Qt::UserRole + 6).toBool();
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2010-08-30 14:17:15 +00:00
|
|
|
plotCurveConfigs.append(newPlotCurveConfigs);
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
2010-08-30 14:17:15 +00:00
|
|
|
m_config->replacePlotCurveConfig(plotCurveConfigs);
|
2011-01-31 02:09:44 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// save the logging config
|
2011-01-31 02:09:44 +00:00
|
|
|
m_config->setLoggingPath(options_page->LoggingPath->path());
|
|
|
|
m_config->setLoggingNewFileOnConnect(options_page->LoggingConnect->isChecked());
|
|
|
|
m_config->setLoggingEnabled(options_page->LoggingEnable->isChecked());
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-05-13 21:24:19 +02:00
|
|
|
\brief Add a new curve to the plot.
|
|
|
|
*/
|
2010-08-10 05:42:39 +00:00
|
|
|
void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
|
|
|
|
{
|
2013-05-13 21:24:19 +02:00
|
|
|
bool parseOK = false;
|
2010-08-10 05:42:39 +00:00
|
|
|
QString uavObject = options_page->cmbUAVObjects->currentText();
|
2013-05-13 21:24:19 +02:00
|
|
|
QString uavField = options_page->cmbUAVField->currentText();
|
2010-08-10 05:42:39 +00:00
|
|
|
int scale = options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (!parseOK) {
|
|
|
|
scale = 0;
|
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2012-05-22 05:21:11 +03:00
|
|
|
int mean = options_page->spnMeanSamples->value();
|
|
|
|
QString mathFunction = options_page->mathFunctionComboBox->currentText();
|
|
|
|
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2013-05-19 17:37:30 +03:00
|
|
|
bool antialiased = options_page->drawAntialiasedCheckBox->isChecked();
|
2013-05-13 21:24:19 +02:00
|
|
|
// Find an existing plot curve config based on the uavobject and uav field. If it
|
|
|
|
// exists, update it, else add a new one.
|
|
|
|
if (options_page->lstCurves->count() &&
|
|
|
|
options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField) {
|
2010-08-29 22:45:12 +00:00
|
|
|
QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem();
|
2013-05-13 21:24:19 +02:00
|
|
|
setCurvePlotProperties(listWidgetItem, uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
|
|
|
|
} else {
|
|
|
|
addPlotCurveConfig(uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
|
2010-08-10 05:42:39 +00:00
|
|
|
|
2010-08-29 22:45:12 +00:00
|
|
|
options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1);
|
|
|
|
}
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor, bool antialias)
|
2010-08-10 05:42:39 +00:00
|
|
|
{
|
2013-05-13 21:24:19 +02:00
|
|
|
// Add a new curve config to the list
|
|
|
|
QString listItemDisplayText = uavObject + "." + uavField;
|
|
|
|
|
2010-08-10 05:42:39 +00:00
|
|
|
options_page->lstCurves->addItem(listItemDisplayText);
|
|
|
|
QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1);
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
setCurvePlotProperties(listWidgetItem, uavObject, uavField, scale, mean, mathFunction, varColor, antialias);
|
2010-08-29 22:45:12 +00:00
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale,
|
|
|
|
int mean, QString mathFunction, QVariant varColor, bool antialias)
|
2010-08-29 22:45:12 +00:00
|
|
|
{
|
2013-05-19 17:37:30 +03:00
|
|
|
bool parseOK = false;
|
2010-08-29 22:45:12 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
// Set the properties of the newly added list item
|
2010-08-10 05:42:39 +00:00
|
|
|
QRgb rgbColor = (QRgb)varColor.toInt(&parseOK);
|
2013-05-13 21:24:19 +02:00
|
|
|
QColor color = QColor(rgbColor);
|
|
|
|
|
|
|
|
listWidgetItem->setTextColor(color);
|
|
|
|
|
|
|
|
// Store some additional data for the plot curve on the list item
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 0, QVariant(uavObject));
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 1, QVariant(uavField));
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 2, QVariant(scale));
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 3, varColor);
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 4, QVariant(mean));
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 5, QVariant(mathFunction));
|
|
|
|
listWidgetItem->setData(Qt::UserRole + 6, QVariant(antialias));
|
2010-08-10 05:42:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*!
|
2013-05-13 21:24:19 +02:00
|
|
|
Remove a curve config from the plot.
|
|
|
|
*/
|
2010-08-10 05:42:39 +00:00
|
|
|
void ScopeGadgetOptionsPage::on_btnRemoveCurve_clicked()
|
|
|
|
{
|
|
|
|
options_page->lstCurves->takeItem(options_page->lstCurves->currentIndex().row());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ScopeGadgetOptionsPage::finish()
|
2013-05-13 21:24:19 +02:00
|
|
|
{}
|
2010-08-10 05:42:39 +00:00
|
|
|
|
|
|
|
/*!
|
2013-05-13 21:24:19 +02:00
|
|
|
When a different plot curve config is selected, populate its values into the widgets.
|
|
|
|
*/
|
2010-08-10 05:42:39 +00:00
|
|
|
void ScopeGadgetOptionsPage::on_lstCurves_currentRowChanged(int currentRow)
|
|
|
|
{
|
2010-09-21 19:29:43 +00:00
|
|
|
Q_UNUSED(currentRow);
|
2010-08-10 05:42:39 +00:00
|
|
|
setYAxisWidgetFromPlotCurve();
|
|
|
|
}
|
2011-01-31 02:09:44 +00:00
|
|
|
|
|
|
|
void ScopeGadgetOptionsPage::on_loggingEnable_clicked()
|
2013-05-13 21:24:19 +02:00
|
|
|
{
|
2011-01-31 02:09:44 +00:00
|
|
|
bool en = options_page->LoggingEnable->isChecked();
|
2013-05-13 21:24:19 +02:00
|
|
|
|
2011-01-31 02:09:44 +00:00
|
|
|
options_page->LoggingPath->setEnabled(en);
|
|
|
|
options_page->LoggingConnect->setEnabled(en);
|
|
|
|
options_page->LoggingLabel->setEnabled(en);
|
2013-05-13 21:24:19 +02:00
|
|
|
}
|
2011-01-31 02:09:44 +00:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
void ScopeGadgetOptionsPage::on_spnRefreshInterval_valueChanged(int)
|
2012-02-11 15:59:34 +02:00
|
|
|
{
|
2012-02-11 16:17:20 +02:00
|
|
|
validateRefreshInterval();
|
2012-02-11 15:59:34 +02:00
|
|
|
}
|
|
|
|
|
2012-02-11 16:17:20 +02:00
|
|
|
void ScopeGadgetOptionsPage::validateRefreshInterval()
|
2012-02-11 15:59:34 +02:00
|
|
|
{
|
|
|
|
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
|
|
|
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
for (int iIndex = 0; iIndex < options_page->lstCurves->count(); iIndex++) {
|
|
|
|
QListWidgetItem *listItem = options_page->lstCurves->item(iIndex);
|
2012-02-11 15:59:34 +02:00
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
QString uavObject = listItem->data(Qt::UserRole + 0).toString();
|
|
|
|
|
|
|
|
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject((uavObject)));
|
|
|
|
if (!obj) {
|
2012-02-11 15:59:34 +02:00
|
|
|
qDebug() << "Object " << uavObject << " is missing";
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-13 21:24:19 +02:00
|
|
|
if (options_page->spnRefreshInterval->value() < obj->getMetadata().flightTelemetryUpdatePeriod) {
|
2012-02-11 15:59:34 +02:00
|
|
|
options_page->lblWarnings->setText("The refresh interval is faster than some or all telemetry objects.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
options_page->lblWarnings->setText("");
|
|
|
|
}
|