1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-03-01 18:29:16 +01:00

OP-952 Adds settings per scope-plot if to draw the plot anti-aliased. Default setting is true. Adds a fix to not render the plots when they are not visible. Saves CPU.

This commit is contained in:
Fredrik Arvidsson 2013-05-13 21:24:19 +02:00
parent b9601c3ad6
commit c4adede7ac
8 changed files with 764 additions and 743 deletions

View File

@ -36,35 +36,30 @@ ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *pa
IUAVGadget(classId, parent), IUAVGadget(classId, parent),
m_widget(widget), m_widget(widget),
configLoaded(false) configLoaded(false)
{ {}
}
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config) void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
{ {
ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration *>(config); ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration *>(config);
ScopeGadgetWidget *widget = qobject_cast<ScopeGadgetWidget *>(m_widget); ScopeGadgetWidget *widget = qobject_cast<ScopeGadgetWidget *>(m_widget);
widget->setXWindowSize(sgConfig->dataSize()); widget->setXWindowSize(sgConfig->dataSize());
widget->setRefreshInterval(sgConfig->refreshInterval()); widget->setRefreshInterval(sgConfig->refreshInterval());
if(sgConfig->plotType() == SequentialPlot ) if (sgConfig->plotType() == SequentialPlot) {
widget->setupSequentialPlot(); widget->setupSequentialPlot();
else if(sgConfig->plotType() == ChronoPlot) } else if (sgConfig->plotType() == ChronoPlot) {
widget->setupChronoPlot(); widget->setupChronoPlot();
// else if(sgConfig->plotType() == UAVObjectPlot) }
// widget->setupUAVObjectPlot();
foreach(PlotCurveConfiguration * plotCurveConfig, sgConfig->plotCurveConfigs()) { foreach(PlotCurveConfiguration * plotCurveConfig, sgConfig->plotCurveConfigs()) {
QString uavObject = plotCurveConfig->uavObject; QString uavObject = plotCurveConfig->uavObject;
QString uavField = plotCurveConfig->uavField; QString uavField = plotCurveConfig->uavField;
int scale = plotCurveConfig->yScalePower; int scale = plotCurveConfig->yScalePower;
int mean = plotCurveConfig->yMeanSamples; int mean = plotCurveConfig->yMeanSamples;
QString mathFunction = plotCurveConfig->mathFunction; QString mathFunction = plotCurveConfig->mathFunction;
QRgb color = plotCurveConfig->color; QRgb color = plotCurveConfig->color;
bool antialiased = plotCurveConfig->drawAntialiased;
widget->addCurvePlot( widget->addCurvePlot(
uavObject, uavObject,
uavField, uavField,
@ -72,11 +67,11 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config)
mean, mean,
mathFunction, mathFunction,
QPen(QBrush(QColor(color), Qt::SolidPattern), QPen(QBrush(QColor(color), Qt::SolidPattern),
// (qreal)2,
(qreal)1, (qreal)1,
Qt::SolidLine, Qt::SolidLine,
Qt::SquareCap, Qt::SquareCap,
Qt::BevelJoin) Qt::BevelJoin),
antialiased
); );
} }
@ -87,7 +82,6 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config)
widget->csvLoggingStop(); widget->csvLoggingStop();
widget->csvLoggingSetName(sgConfig->name()); widget->csvLoggingSetName(sgConfig->name());
widget->csvLoggingStart(); widget->csvLoggingStart();
} }
/** /**

View File

@ -38,64 +38,52 @@ ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* q
int plotCurveCount = 0; int plotCurveCount = 0;
//if a saved configuration exists load it // If a saved configuration exists load it
if (qSettings != 0) { if (qSettings != 0) {
currentStreamVersion = qSettings->value("configurationStreamVersion").toUInt(); currentStreamVersion = qSettings->value("configurationStreamVersion").toUInt();
if(currentStreamVersion != m_configurationStreamVersion) if (currentStreamVersion != m_configurationStreamVersion) {
return; return;
}
m_plotType = qSettings->value("plotType").toInt(); m_plotType = qSettings->value("plotType").toInt();
m_dataSize = qSettings->value("dataSize").toInt(); m_dataSize = qSettings->value("dataSize").toInt();
m_refreshInterval = qSettings->value("refreshInterval").toInt(); m_refreshInterval = qSettings->value("refreshInterval").toInt();
plotCurveCount = qSettings->value("plotCurveCount").toInt(); plotCurveCount = qSettings->value("plotCurveCount").toInt();
for(int plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) for (int plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
{
QString uavObject;
QString uavField;
QRgb color;
qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex)); qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
PlotCurveConfiguration *plotCurveConf = new PlotCurveConfiguration(); PlotCurveConfiguration *plotCurveConf = new PlotCurveConfiguration();
uavObject = qSettings->value("uavObject").toString(); plotCurveConf->uavObject = qSettings->value("uavObject").toString();
plotCurveConf->uavObject = uavObject; plotCurveConf->uavField = qSettings->value("uavField").toString();
uavField = qSettings->value("uavField").toString(); plotCurveConf->color = qSettings->value("color").value<QRgb>();
plotCurveConf->uavField = uavField;
color = qSettings->value("color").value<QRgb>();
plotCurveConf->color = color;
plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt(); plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt();
plotCurveConf->mathFunction = qSettings->value("mathFunction").toString(); plotCurveConf->mathFunction = qSettings->value("mathFunction").toString();
plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples").toInt(); plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples", 1).toInt();
plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples", 1).toInt();
if (!plotCurveConf->yMeanSamples) plotCurveConf->yMeanSamples = 1; // fallback for backward compatibility with earlier versions //IS THIS STILL NECESSARY? plotCurveConf->drawAntialiased = qSettings->value("drawAntialiased", true).toBool();
plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble(); plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble();
plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble(); plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble();
m_plotCurveConfigs.append(plotCurveConf);
m_PlotCurveConfigs.append(plotCurveConf);
qSettings->endGroup(); qSettings->endGroup();
} }
m_LoggingEnabled = qSettings->value("LoggingEnabled").toBool(); m_loggingEnabled = qSettings->value("LoggingEnabled").toBool();
m_LoggingNewFileOnConnect = qSettings->value("LoggingNewFileOnConnect").toBool(); m_loggingNewFileOnConnect = qSettings->value("LoggingNewFileOnConnect").toBool();
m_LoggingPath = qSettings->value("LoggingPath").toString(); m_loggingPath = qSettings->value("LoggingPath").toString();
} }
} }
void ScopeGadgetConfiguration::clearPlotData() void ScopeGadgetConfiguration::clearPlotData()
{ {
PlotCurveConfiguration* poltCurveConfig; PlotCurveConfiguration *plotCurveConfig;
while(m_PlotCurveConfigs.size() > 0) while (m_plotCurveConfigs.size() > 0) {
{ plotCurveConfig = m_plotCurveConfigs.first();
poltCurveConfig = m_PlotCurveConfigs.first(); m_plotCurveConfigs.pop_front();
m_PlotCurveConfigs.pop_front(); delete plotCurveConfig;
delete poltCurveConfig;
} }
} }
@ -109,16 +97,16 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
int plotDatasLoadIndex = 0; int plotDatasLoadIndex = 0;
ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId()); ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId());
m->setPlotType(m_plotType); m->setPlotType(m_plotType);
m->setDataSize(m_dataSize); m->setDataSize(m_dataSize);
m->setMathFunctionType(m_mathFunctionType); m->setMathFunctionType(m_mathFunctionType);
m->setRefreashInterval(m_refreshInterval); m->setRefreashInterval(m_refreshInterval);
plotCurveCount = m_PlotCurveConfigs.size(); plotCurveCount = m_plotCurveConfigs.size();
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) for (plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
{ PlotCurveConfiguration *currentPlotCurveConf = m_plotCurveConfigs.at(plotDatasLoadIndex);
PlotCurveConfiguration* currentPlotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex);
PlotCurveConfiguration *newPlotCurveConf = new PlotCurveConfiguration(); PlotCurveConfiguration *newPlotCurveConf = new PlotCurveConfiguration();
newPlotCurveConf->uavObject = currentPlotCurveConf->uavObject; newPlotCurveConf->uavObject = currentPlotCurveConf->uavObject;
@ -127,18 +115,16 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower; newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower;
newPlotCurveConf->yMeanSamples = currentPlotCurveConf->yMeanSamples; newPlotCurveConf->yMeanSamples = currentPlotCurveConf->yMeanSamples;
newPlotCurveConf->mathFunction = currentPlotCurveConf->mathFunction; newPlotCurveConf->mathFunction = currentPlotCurveConf->mathFunction;
newPlotCurveConf->drawAntialiased = currentPlotCurveConf->drawAntialiased;
newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum; newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum;
newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum; newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum;
m->addPlotCurveConfig(newPlotCurveConf); m->addPlotCurveConfig(newPlotCurveConf);
} }
m->setLoggingEnabled(m_LoggingEnabled); m->setLoggingEnabled(m_loggingEnabled);
m->setLoggingNewFileOnConnect(m_LoggingNewFileOnConnect); m->setLoggingNewFileOnConnect(m_loggingNewFileOnConnect);
m->setLoggingPath(m_LoggingPath); m->setLoggingPath(m_loggingPath);
return m; return m;
} }
@ -148,9 +134,9 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
* Saves a configuration. //REDEFINES saveConfig CHILD BEHAVIOR? * Saves a configuration. //REDEFINES saveConfig CHILD BEHAVIOR?
* *
*/ */
void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const { void ScopeGadgetConfiguration::saveConfig(QSettings *qSettings) const
{
int plotCurveCount = m_PlotCurveConfigs.size(); int plotCurveCount = m_plotCurveConfigs.size();
int plotDatasLoadIndex = 0; int plotDatasLoadIndex = 0;
qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion); qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion);
@ -159,11 +145,10 @@ void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const {
qSettings->setValue("refreshInterval", m_refreshInterval); qSettings->setValue("refreshInterval", m_refreshInterval);
qSettings->setValue("plotCurveCount", plotCurveCount); qSettings->setValue("plotCurveCount", plotCurveCount);
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) for (plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
{
qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex)); qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
PlotCurveConfiguration* plotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex); PlotCurveConfiguration *plotCurveConf = m_plotCurveConfigs.at(plotDatasLoadIndex);
qSettings->setValue("uavObject", plotCurveConf->uavObject); qSettings->setValue("uavObject", plotCurveConf->uavObject);
qSettings->setValue("uavField", plotCurveConf->uavField); qSettings->setValue("uavField", plotCurveConf->uavField);
qSettings->setValue("color", plotCurveConf->color); qSettings->setValue("color", plotCurveConf->color);
@ -172,22 +157,21 @@ void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const {
qSettings->setValue("yMeanSamples", plotCurveConf->yMeanSamples); qSettings->setValue("yMeanSamples", plotCurveConf->yMeanSamples);
qSettings->setValue("yMinimum", plotCurveConf->yMinimum); qSettings->setValue("yMinimum", plotCurveConf->yMinimum);
qSettings->setValue("yMaximum", plotCurveConf->yMaximum); qSettings->setValue("yMaximum", plotCurveConf->yMaximum);
qSettings->setValue("drawAntialiased", plotCurveConf->drawAntialiased);
qSettings->endGroup(); qSettings->endGroup();
} }
qSettings->setValue("LoggingEnabled", m_LoggingEnabled); qSettings->setValue("LoggingEnabled", m_loggingEnabled);
qSettings->setValue("LoggingNewFileOnConnect", m_LoggingNewFileOnConnect); qSettings->setValue("LoggingNewFileOnConnect", m_loggingNewFileOnConnect);
qSettings->setValue("LoggingPath", m_LoggingPath); qSettings->setValue("LoggingPath", m_loggingPath);
} }
void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration *> newPlotCurveConfigs) void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration *> newPlotCurveConfigs)
{ {
clearPlotData(); clearPlotData();
m_PlotCurveConfigs.append(newPlotCurveConfigs); m_plotCurveConfigs.append(newPlotCurveConfigs);
} }
ScopeGadgetConfiguration::~ScopeGadgetConfiguration() ScopeGadgetConfiguration::~ScopeGadgetConfiguration()

View File

@ -35,8 +35,7 @@
using namespace Core; using namespace Core;
struct PlotCurveConfiguration struct PlotCurveConfiguration {
{
QString uavObject; QString uavObject;
QString uavField; QString uavField;
int yScalePower; // This is the power to which each value must be raised int yScalePower; // This is the power to which each value must be raised
@ -45,10 +44,10 @@ struct PlotCurveConfiguration
QString mathFunction; QString mathFunction;
double yMinimum; double yMinimum;
double yMaximum; double yMaximum;
bool drawAntialiased;
}; };
class ScopeGadgetConfiguration : public IUAVGadgetConfiguration class ScopeGadgetConfiguration : public IUAVGadgetConfiguration {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ScopeGadgetConfiguration(QString classId, QSettings *qSettings = 0, QObject *parent = 0); explicit ScopeGadgetConfiguration(QString classId, QSettings *qSettings = 0, QObject *parent = 0);
@ -56,45 +55,97 @@ public:
~ScopeGadgetConfiguration(); ~ScopeGadgetConfiguration();
// configuration setter functions // configuration setter functions
void setPlotType(int value){m_plotType = value;} void setPlotType(int value)
void setMathFunctionType(int value){m_mathFunctionType = value;} {
void setDataSize(int value){m_dataSize = value;} m_plotType = value;
void setRefreashInterval(int value){m_refreshInterval = value;} }
void addPlotCurveConfig(PlotCurveConfiguration* value){m_PlotCurveConfigs.append(value);} void setMathFunctionType(int value)
void replacePlotCurveConfig(QList<PlotCurveConfiguration*> m_PlotCurveConfigs); {
m_mathFunctionType = value;
}
void setDataSize(int value)
{
m_dataSize = value;
}
void setRefreashInterval(int value)
{
m_refreshInterval = value;
}
void addPlotCurveConfig(PlotCurveConfiguration *value)
{
m_plotCurveConfigs.append(value);
}
void replacePlotCurveConfig(QList<PlotCurveConfiguration *> m_plotCurveConfigs);
//configurations getter functions // Configurations getter functions
int plotType(){return m_plotType;} int plotType()
int mathFunctionType(){return m_mathFunctionType;} {
int dataSize(){return m_dataSize;} return m_plotType;
int refreshInterval(){return m_refreshInterval;} }
QList<PlotCurveConfiguration*> plotCurveConfigs(){return m_PlotCurveConfigs;} int mathFunctionType()
{
return m_mathFunctionType;
}
int dataSize()
{
return m_dataSize;
}
int refreshInterval()
{
return m_refreshInterval;
}
QList<PlotCurveConfiguration *> plotCurveConfigs()
{
return m_plotCurveConfigs;
}
void saveConfig(QSettings *settings) const; // THIS SEEMS TO BE UNUSED void saveConfig(QSettings *settings) const; // THIS SEEMS TO BE UNUSED
IUAVGadgetConfiguration *clone(); IUAVGadgetConfiguration *clone();
bool getLoggingEnabled(){return m_LoggingEnabled;}; bool getLoggingEnabled()
bool getLoggingNewFileOnConnect(){return m_LoggingNewFileOnConnect;}; {
QString getLoggingPath(){return m_LoggingPath;}; return m_loggingEnabled;
void setLoggingEnabled(bool value){m_LoggingEnabled=value;}; }
void setLoggingNewFileOnConnect(bool value){m_LoggingNewFileOnConnect=value;}; bool getLoggingNewFileOnConnect()
void setLoggingPath(QString value){m_LoggingPath=value;}; {
return m_loggingNewFileOnConnect;
}
QString getLoggingPath()
{
return m_loggingPath;
}
void setLoggingEnabled(bool value)
{
m_loggingEnabled = value;
}
void setLoggingNewFileOnConnect(bool value)
{
m_loggingNewFileOnConnect = value;
}
void setLoggingPath(QString value)
{
m_loggingPath = value;
}
private: private:
static const uint m_configurationStreamVersion = 1000;//Increment this if the stream format is not compatible with previous versions. This would cause existing configs to be discarded. // Increment this if the stream format is not compatible with previous versions. This would cause existing configs to be discarded.
int m_plotType; //The type of the plot static const uint m_configurationStreamVersion = 1000;
int m_dataSize; //The size of the data buffer to render in the curve plot // The type of the plot
int m_refreshInterval; //The interval to replot the curve widget. The data buffer is refresh as the data comes in. int m_plotType;
int m_mathFunctionType; //The type of math function to be used in the scope analysis // The size of the data buffer to render in the curve plot
QList<PlotCurveConfiguration*> m_PlotCurveConfigs; int m_dataSize;
// The interval to replot the curve widget. The data buffer is refresh as the data comes in.
int m_refreshInterval;
// The type of math function to be used in the scope analysis
int m_mathFunctionType;
QList<PlotCurveConfiguration *> m_plotCurveConfigs;
void clearPlotData(); void clearPlotData();
bool m_LoggingEnabled; bool m_loggingEnabled;
bool m_LoggingNewFileOnConnect; bool m_loggingNewFileOnConnect;
QString m_LoggingPath; QString m_loggingPath;
}; };
#endif // SCOPEGADGETCONFIGURATION_H #endif // SCOPEGADGETCONFIGURATION_H

View File

@ -73,8 +73,9 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
options_page->mathFunctionComboBox->addItem("Boxcar average"); options_page->mathFunctionComboBox->addItem("Boxcar average");
options_page->mathFunctionComboBox->addItem("Standard deviation"); options_page->mathFunctionComboBox->addItem("Standard deviation");
if(options_page->cmbUAVObjects->currentIndex() >= 0) if (options_page->cmbUAVObjects->currentIndex() >= 0) {
on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText()); on_cmbUAVObjects_currentIndexChanged(options_page->cmbUAVObjects->currentText());
}
options_page->cmbScale->addItem("10^-9", -9); options_page->cmbScale->addItem("10^-9", -9);
options_page->cmbScale->addItem("10^-6", -6); options_page->cmbScale->addItem("10^-6", -6);
@ -102,19 +103,20 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
// add the configured curves // add the configured curves
foreach(PlotCurveConfiguration * plotData, m_config->plotCurveConfigs()) { foreach(PlotCurveConfiguration * plotData, m_config->plotCurveConfigs()) {
QString uavObject = plotData->uavObject; QString uavObject = plotData->uavObject;
QString uavField = plotData->uavField; QString uavField = plotData->uavField;
int scale = plotData->yScalePower; int scale = plotData->yScalePower;
int mean = plotData->yMeanSamples; int mean = plotData->yMeanSamples;
QString mathFunction = plotData->mathFunction; QString mathFunction = plotData->mathFunction;
QVariant varColor = plotData->color; QVariant varColor = plotData->color;
bool antialiased = plotData->drawAntialiased;
addPlotCurveConfig(uavObject,uavField,scale,mean,mathFunction,varColor); addPlotCurveConfig(uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
} }
if(m_config->plotCurveConfigs().count() > 0) if (m_config->plotCurveConfigs().count() > 0) {
options_page->lstCurves->setCurrentRow(0, QItemSelectionModel::ClearAndSelect); options_page->lstCurves->setCurrentRow(0, QItemSelectionModel::ClearAndSelect);
}
connect(options_page->btnAddCurve, SIGNAL(clicked()), this, SLOT(on_btnAddCurve_clicked())); 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->btnRemoveCurve, SIGNAL(clicked()), this, SLOT(on_btnRemoveCurve_clicked()));
@ -148,36 +150,35 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
sp->installEventFilter(this); sp->installEventFilter(this);
} }
return optionsPageWidget; return optionsPageWidget;
} }
bool ScopeGadgetOptionsPage::eventFilter( QObject * obj, QEvent * evt ) { bool ScopeGadgetOptionsPage::eventFilter(QObject *obj, QEvent *evt)
{
// Filter all wheel events, and ignore them // Filter all wheel events, and ignore them
if (evt->type() == QEvent::Wheel && if (evt->type() == QEvent::Wheel &&
(qobject_cast<QAbstractSpinBox *>(obj) || (qobject_cast<QAbstractSpinBox *>(obj) ||
qobject_cast<QComboBox *>(obj) || qobject_cast<QComboBox *>(obj) ||
qobject_cast<QAbstractSlider*>( obj ) )) qobject_cast<QAbstractSlider *>(obj))) {
{
evt->ignore(); evt->ignore();
return true; return true;
} }
return ScopeGadgetOptionsPage::eventFilter(obj, evt); return ScopeGadgetOptionsPage::eventFilter(obj, evt);
} }
void ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged(int currentIndex){ void ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged(int currentIndex)
{
if (currentIndex > 0) { if (currentIndex > 0) {
options_page->spnMeanSamples->setEnabled(true); options_page->spnMeanSamples->setEnabled(true);
} } else {
else{
options_page->spnMeanSamples->setEnabled(false); options_page->spnMeanSamples->setEnabled(false);
} }
} }
void ScopeGadgetOptionsPage::on_btnColor_clicked() void ScopeGadgetOptionsPage::on_btnColor_clicked()
{ {
QColor color = QColorDialog::getColor(QColor(options_page->btnColor->text())); QColor color = QColorDialog::getColor(QColor(options_page->btnColor->text()));
if (color.isValid()) { if (color.isValid()) {
setButtonColor(color); setButtonColor(color);
} }
@ -192,8 +193,9 @@ void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
bool parseOK = false; bool parseOK = false;
QListWidgetItem *listItem = options_page->lstCurves->currentItem(); QListWidgetItem *listItem = options_page->lstCurves->currentItem();
if(listItem == 0) if (listItem == 0) {
return; return;
}
// WHAT IS UserRole DOING? // WHAT IS UserRole DOING?
int currentIndex = options_page->cmbUAVObjects->findText(listItem->data(Qt::UserRole + 0).toString()); int currentIndex = options_page->cmbUAVObjects->findText(listItem->data(Qt::UserRole + 0).toString());
@ -211,12 +213,14 @@ void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
setButtonColor(QColor((QRgb)rgb)); setButtonColor(QColor((QRgb)rgb));
int mean = listItem->data(Qt::UserRole + 4).toInt(&parseOK); int mean = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
if(!parseOK) mean = 1; if (!parseOK) {
mean = 1;
}
options_page->spnMeanSamples->setValue(mean); options_page->spnMeanSamples->setValue(mean);
currentIndex = options_page->mathFunctionComboBox->findText(listItem->data(Qt::UserRole + 5).toString()); currentIndex = options_page->mathFunctionComboBox->findText(listItem->data(Qt::UserRole + 5).toString());
options_page->mathFunctionComboBox->setCurrentIndex(currentIndex); options_page->mathFunctionComboBox->setCurrentIndex(currentIndex);
options_page->drawAntialiasedCheckBox->setChecked(listItem->data(Qt::UserRole + 6).toBool());
} }
void ScopeGadgetOptionsPage::setButtonColor(const QColor &color) void ScopeGadgetOptionsPage::setButtonColor(const QColor &color)
@ -237,25 +241,24 @@ void ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged(QString val)
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(val)); UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(val));
if (obj == NULL) if (obj == NULL) {
return; // Rare case: the config contained a UAVObject name which does not exist anymore. return; // Rare case: the config contained a UAVObject name which does not exist anymore.
}
QList<UAVObjectField *> fieldList = obj->getFields(); QList<UAVObjectField *> fieldList = obj->getFields();
foreach(UAVObjectField * field, fieldList) { foreach(UAVObjectField * field, fieldList) {
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM ) if (field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM) {
continue; continue;
}
if(field->getElementNames().count() > 1) if (field->getElementNames().count() > 1) {
{ foreach(QString elemName, field->getElementNames()) {
foreach(QString elemName , field->getElementNames())
{
options_page->cmbUAVField->addItem(field->getName() + "-" + elemName); options_page->cmbUAVField->addItem(field->getName() + "-" + elemName);
} }
} } else {
else
options_page->cmbUAVField->addItem(field->getName()); options_page->cmbUAVField->addItem(field->getName());
} }
} }
}
/** /**
* Called when the user presses apply or OK. * Called when the user presses apply or OK.
@ -281,22 +284,25 @@ void ScopeGadgetOptionsPage::apply()
newPlotCurveConfigs->uavObject = listItem->data(Qt::UserRole + 0).toString(); newPlotCurveConfigs->uavObject = listItem->data(Qt::UserRole + 0).toString();
newPlotCurveConfigs->uavField = listItem->data(Qt::UserRole + 1).toString(); newPlotCurveConfigs->uavField = listItem->data(Qt::UserRole + 1).toString();
newPlotCurveConfigs->yScalePower = listItem->data(Qt::UserRole + 2).toInt(&parseOK); newPlotCurveConfigs->yScalePower = listItem->data(Qt::UserRole + 2).toInt(&parseOK);
if(!parseOK) if (!parseOK) {
newPlotCurveConfigs->yScalePower = 0; newPlotCurveConfigs->yScalePower = 0;
}
QVariant varColor = listItem->data(Qt::UserRole + 3); QVariant varColor = listItem->data(Qt::UserRole + 3);
int rgb = varColor.toInt(&parseOK); int rgb = varColor.toInt(&parseOK);
if(!parseOK) if (!parseOK) {
newPlotCurveConfigs->color = QColor(Qt::black).rgb(); newPlotCurveConfigs->color = QColor(Qt::black).rgb();
else } else {
newPlotCurveConfigs->color = (QRgb)rgb; newPlotCurveConfigs->color = (QRgb)rgb;
}
newPlotCurveConfigs->yMeanSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK); newPlotCurveConfigs->yMeanSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
if(!parseOK) if (!parseOK) {
newPlotCurveConfigs->yMeanSamples = 1; newPlotCurveConfigs->yMeanSamples = 1;
}
newPlotCurveConfigs->mathFunction = listItem->data(Qt::UserRole + 5).toString(); newPlotCurveConfigs->mathFunction = listItem->data(Qt::UserRole + 5).toString();
newPlotCurveConfigs->drawAntialiased = listItem->data(Qt::UserRole + 6).toBool();
plotCurveConfigs.append(newPlotCurveConfigs); plotCurveConfigs.append(newPlotCurveConfigs);
} }
@ -307,7 +313,6 @@ void ScopeGadgetOptionsPage::apply()
m_config->setLoggingPath(options_page->LoggingPath->path()); m_config->setLoggingPath(options_page->LoggingPath->path());
m_config->setLoggingNewFileOnConnect(options_page->LoggingConnect->isChecked()); m_config->setLoggingNewFileOnConnect(options_page->LoggingConnect->isChecked());
m_config->setLoggingEnabled(options_page->LoggingEnable->isChecked()); m_config->setLoggingEnabled(options_page->LoggingEnable->isChecked());
} }
/*! /*!
@ -320,8 +325,9 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
QString uavField = options_page->cmbUAVField->currentText(); QString uavField = options_page->cmbUAVField->currentText();
int scale = options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK); int scale = options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK);
if(!parseOK) if (!parseOK) {
scale = 0; scale = 0;
}
int mean = options_page->spnMeanSamples->value(); int mean = options_page->spnMeanSamples->value();
QString mathFunction = options_page->mathFunctionComboBox->currentText(); QString mathFunction = options_page->mathFunctionComboBox->currentText();
@ -329,41 +335,40 @@ void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb(); QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
bool antialiased = options_page->drawAntialiasedCheckBox->isChecked();
// Find an existing plot curve config based on the uavobject and uav field. If it // Find an existing plot curve config based on the uavobject and uav field. If it
// exists, update it, else add a new one. // exists, update it, else add a new one.
if (options_page->lstCurves->count() && if (options_page->lstCurves->count() &&
options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField) options_page->lstCurves->currentItem()->text() == uavObject + "." + uavField) {
{
QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem(); QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem();
setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,mean,mathFunction,varColor); setCurvePlotProperties(listWidgetItem, uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
}else } else {
{ addPlotCurveConfig(uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
addPlotCurveConfig(uavObject,uavField,scale,mean,mathFunction,varColor);
options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1); options_page->lstCurves->setCurrentRow(options_page->lstCurves->count() - 1);
} }
} }
void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor) void ScopeGadgetOptionsPage::addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor, bool antialias)
{ {
// Add a new curve config to the list // Add a new curve config to the list
QString listItemDisplayText = uavObject + "." + uavField; QString listItemDisplayText = uavObject + "." + uavField;
options_page->lstCurves->addItem(listItemDisplayText); options_page->lstCurves->addItem(listItemDisplayText);
QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1); QListWidgetItem *listWidgetItem = options_page->lstCurves->item(options_page->lstCurves->count() - 1);
setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,mean,mathFunction,varColor); setCurvePlotProperties(listWidgetItem, uavObject, uavField, scale, mean, mathFunction, varColor, antialias);
} }
void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem,QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor) void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale,
int mean, QString mathFunction, QVariant varColor, bool antialias)
{ {
bool parseOK = false; bool parseOK = false;
// Set the properties of the newly added list item // Set the properties of the newly added list item
QString listItemDisplayText = uavObject + "." + uavField;
QRgb rgbColor = (QRgb)varColor.toInt(&parseOK); QRgb rgbColor = (QRgb)varColor.toInt(&parseOK);
QColor color = QColor(rgbColor); QColor color = QColor(rgbColor);
//listWidgetItem->setText(listItemDisplayText);
listWidgetItem->setTextColor(color); listWidgetItem->setTextColor(color);
// Store some additional data for the plot curve on the list item // Store some additional data for the plot curve on the list item
@ -373,6 +378,7 @@ void ScopeGadgetOptionsPage::setCurvePlotProperties(QListWidgetItem *listWidgetI
listWidgetItem->setData(Qt::UserRole + 3, varColor); listWidgetItem->setData(Qt::UserRole + 3, varColor);
listWidgetItem->setData(Qt::UserRole + 4, QVariant(mean)); listWidgetItem->setData(Qt::UserRole + 4, QVariant(mean));
listWidgetItem->setData(Qt::UserRole + 5, QVariant(mathFunction)); listWidgetItem->setData(Qt::UserRole + 5, QVariant(mathFunction));
listWidgetItem->setData(Qt::UserRole + 6, QVariant(antialias));
} }
/*! /*!
@ -384,9 +390,7 @@ void ScopeGadgetOptionsPage::on_btnRemoveCurve_clicked()
} }
void ScopeGadgetOptionsPage::finish() void ScopeGadgetOptionsPage::finish()
{ {}
}
/*! /*!
When a different plot curve config is selected, populate its values into the widgets. When a different plot curve config is selected, populate its values into the widgets.
@ -400,10 +404,10 @@ void ScopeGadgetOptionsPage::on_lstCurves_currentRowChanged(int currentRow)
void ScopeGadgetOptionsPage::on_loggingEnable_clicked() void ScopeGadgetOptionsPage::on_loggingEnable_clicked()
{ {
bool en = options_page->LoggingEnable->isChecked(); bool en = options_page->LoggingEnable->isChecked();
options_page->LoggingPath->setEnabled(en); options_page->LoggingPath->setEnabled(en);
options_page->LoggingConnect->setEnabled(en); options_page->LoggingConnect->setEnabled(en);
options_page->LoggingLabel->setEnabled(en); options_page->LoggingLabel->setEnabled(en);
} }
void ScopeGadgetOptionsPage::on_spnRefreshInterval_valueChanged(int) void ScopeGadgetOptionsPage::on_spnRefreshInterval_valueChanged(int)
@ -415,6 +419,7 @@ void ScopeGadgetOptionsPage::validateRefreshInterval()
{ {
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
for (int iIndex = 0; iIndex < options_page->lstCurves->count(); iIndex++) { for (int iIndex = 0; iIndex < options_page->lstCurves->count(); iIndex++) {
QListWidgetItem *listItem = options_page->lstCurves->item(iIndex); QListWidgetItem *listItem = options_page->lstCurves->item(iIndex);
@ -426,8 +431,7 @@ void ScopeGadgetOptionsPage::validateRefreshInterval()
continue; continue;
} }
if(options_page->spnRefreshInterval->value() < obj->getMetadata().flightTelemetryUpdatePeriod) if (options_page->spnRefreshInterval->value() < obj->getMetadata().flightTelemetryUpdatePeriod) {
{
options_page->lblWarnings->setText("The refresh interval is faster than some or all telemetry objects."); options_page->lblWarnings->setText("The refresh interval is faster than some or all telemetry objects.");
return; return;
} }
@ -435,4 +439,3 @@ void ScopeGadgetOptionsPage::validateRefreshInterval()
options_page->lblWarnings->setText(""); options_page->lblWarnings->setText("");
} }

View File

@ -38,22 +38,19 @@
#include <QDebug> #include <QDebug>
#include <QtGui/QColorDialog> #include <QtGui/QColorDialog>
namespace Core namespace Core {
{
class IUAVGadgetConfiguration; class IUAVGadgetConfiguration;
} }
class ScopeGadgetConfiguration; class ScopeGadgetConfiguration;
namespace Ui namespace Ui {
{
class ScopeGadgetOptionsPage; class ScopeGadgetOptionsPage;
} }
using namespace Core; using namespace Core;
class ScopeGadgetOptionsPage : public IOptionsPage class ScopeGadgetOptionsPage : public IOptionsPage {
{
Q_OBJECT Q_OBJECT
public: public:
explicit ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent = 0); explicit ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent = 0);
@ -66,8 +63,9 @@ private:
Ui::ScopeGadgetOptionsPage *options_page; Ui::ScopeGadgetOptionsPage *options_page;
ScopeGadgetConfiguration *m_config; ScopeGadgetConfiguration *m_config;
void addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor); void addPlotCurveConfig(QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor, bool antialias);
void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, int mean, QString mathFunction, QVariant varColor); void setCurvePlotProperties(QListWidgetItem *listWidgetItem, QString uavObject, QString uavField, int scale, int mean,
QString mathFunction, QVariant varColor, bool antialias);
void setYAxisWidgetFromPlotCurve(); void setYAxisWidgetFromPlotCurve();
void setButtonColor(const QColor &color); void setButtonColor(const QColor &color);
void validateRefreshInterval(); void validateRefreshInterval();
@ -82,7 +80,6 @@ private slots:
void on_btnColor_clicked(); void on_btnColor_clicked();
void on_mathFunctionComboBox_currentIndexChanged(int currentIndex); void on_mathFunctionComboBox_currentIndexChanged(int currentIndex);
void on_loggingEnable_clicked(); void on_loggingEnable_clicked();
}; };
#endif // SCOPEGADGETOPTIONSPAGE_H #endif // SCOPEGADGETOPTIONSPAGE_H

View File

@ -176,38 +176,18 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0"> <item row="7" column="0">
<widget class="QLabel" name="label_3"> <widget class="QLabel" name="mathFunctionLabel">
<property name="text"> <property name="text">
<string>Color:</string> <string>Math function:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="1"> <item row="7" column="1">
<widget class="QPushButton" name="btnColor"> <widget class="QComboBox" name="mathFunctionComboBox">
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </property>
<property name="text">
<string>Choose</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y-axis scale factor:</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QComboBox" name="cmbScale">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item row="8" column="0"> <item row="8" column="0">
@ -248,18 +228,51 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="0"> <item row="9" column="0">
<widget class="QLabel" name="mathFunctionLabel"> <widget class="QLabel" name="label_3">
<property name="text"> <property name="text">
<string>Math function:</string> <string>Color:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="7" column="1"> <item row="9" column="1">
<widget class="QComboBox" name="mathFunctionComboBox"> <widget class="QPushButton" name="btnColor">
<property name="focusPolicy"> <property name="focusPolicy">
<enum>Qt::StrongFocus</enum> <enum>Qt::StrongFocus</enum>
</property> </property>
<property name="text">
<string>Choose</string>
</property>
</widget>
</item>
<item row="10" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Y-axis scale factor:</string>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QComboBox" name="cmbScale">
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item row="11" column="1">
<widget class="QCheckBox" name="drawAntialiasedCheckBox">
<property name="toolTip">
<string>Check this to have the curve drawn antialiased.</string>
</property>
<property name="text">
<string>Draw Antialiased</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -277,7 +290,7 @@
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>100</height> <height>40</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -288,8 +301,7 @@
<string>Add a new curve to the scope, or update it if the UAVObject and UAVField is the same.</string> <string>Add a new curve to the scope, or update it if the UAVObject and UAVField is the same.</string>
</property> </property>
<property name="text"> <property name="text">
<string>Add <string>Add / Update</string>
Update</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -299,8 +311,7 @@ Update</string>
<string>Remove the curve from the scope.</string> <string>Remove the curve from the scope.</string>
</property> </property>
<property name="text"> <property name="text">
<string>Remove <string>Remove</string>
</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -310,12 +321,12 @@ Update</string>
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
</property> </property>
<property name="sizeType"> <property name="sizeType">
<enum>QSizePolicy::Fixed</enum> <enum>QSizePolicy::Expanding</enum>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>20</width> <width>20</width>
<height>15</height> <height>40</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -331,8 +342,8 @@ Update</string>
</property> </property>
<property name="sizeHint" stdset="0"> <property name="sizeHint" stdset="0">
<size> <size>
<width>0</width> <width>20</width>
<height>200</height> <height>40</height>
</size> </size>
</property> </property>
</spacer> </spacer>
@ -347,6 +358,19 @@ Update</string>
</property> </property>
</widget> </widget>
</item> </item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -91,8 +91,7 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
ScopeGadgetWidget::~ScopeGadgetWidget() ScopeGadgetWidget::~ScopeGadgetWidget()
{ {
if (replotTimer) if (replotTimer) {
{
replotTimer->stop(); replotTimer->stop();
delete replotTimer; delete replotTimer;
@ -102,9 +101,9 @@ ScopeGadgetWidget::~ScopeGadgetWidget()
// Get the object to de-monitor // Get the object to de-monitor
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>(); UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
foreach (QString uavObjName, m_connectedUAVObjects) foreach(QString uavObjName, m_connectedUAVObjects) {
{
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(uavObjName)); UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(uavObjName));
disconnect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *))); disconnect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *)));
} }
@ -127,10 +126,11 @@ void ScopeGadgetWidget::mouseDoubleClickEvent(QMouseEvent *e)
{ {
// On double-click, toggle legend // On double-click, toggle legend
mutex.lock(); mutex.lock();
if (legend()) if (legend()) {
deleteLegend(); deleteLegend();
else } else {
addLegend(); addLegend();
}
mutex.unlock(); mutex.unlock();
// On double-click, reset plot zoom // On double-click, reset plot zoom
@ -150,8 +150,8 @@ void ScopeGadgetWidget::wheelEvent(QWheelEvent *e)
{ {
// Change zoom on scroll wheel event // Change zoom on scroll wheel event
QwtInterval yInterval = axisInterval(QwtPlot::yLeft); QwtInterval yInterval = axisInterval(QwtPlot::yLeft);
if (yInterval.minValue() != yInterval.maxValue()) //Make sure that the two values are never the same. Sometimes axisInterval returns (0,0)
{ if (yInterval.minValue() != yInterval.maxValue()) { // Make sure that the two values are never the same. Sometimes axisInterval returns (0,0)
// Determine what y value to zoom about. NOTE, this approach has a bug that the in that // Determine what y value to zoom about. NOTE, this approach has a bug that the in that
// the value returned by Qt includes the legend, whereas the value transformed by Qwt // the value returned by Qt includes the legend, whereas the value transformed by Qwt
// does *not*. Thus, when zooming with a legend, there will always be a small bias error. // does *not*. Thus, when zooming with a legend, there will always be a small bias error.
@ -167,8 +167,7 @@ void ScopeGadgetWidget::wheelEvent(QWheelEvent *e)
setAxisScale(QwtPlot::yLeft, setAxisScale(QwtPlot::yLeft,
(yInterval.minValue() - zoomLine) * zoomScale + zoomLine, (yInterval.minValue() - zoomLine) * zoomScale + zoomLine,
(yInterval.maxValue() - zoomLine) * zoomScale + zoomLine); (yInterval.maxValue() - zoomLine) * zoomScale + zoomLine);
} } else {
else{
setAxisScale(QwtPlot::yLeft, setAxisScale(QwtPlot::yLeft,
(yInterval.minValue() - zoomLine) / zoomScale + zoomLine, (yInterval.minValue() - zoomLine) / zoomScale + zoomLine,
(yInterval.maxValue() - zoomLine) / zoomScale + zoomLine); (yInterval.maxValue() - zoomLine) / zoomScale + zoomLine);
@ -178,30 +177,40 @@ void ScopeGadgetWidget::wheelEvent(QWheelEvent *e)
QwtPlot::wheelEvent(e); QwtPlot::wheelEvent(e);
} }
void ScopeGadgetWidget::showEvent(QShowEvent *e)
{
replotNewData();
QwtPlot::showEvent(e);
}
/** /**
* Starts/stops telemetry * Starts/stops telemetry
*/ */
void ScopeGadgetWidget::startPlotting() void ScopeGadgetWidget::startPlotting()
{ {
if (!replotTimer) if (!replotTimer) {
return; return;
}
if (!replotTimer->isActive()) if (!replotTimer->isActive()) {
replotTimer->start(m_refreshInterval); replotTimer->start(m_refreshInterval);
} }
}
void ScopeGadgetWidget::stopPlotting() void ScopeGadgetWidget::stopPlotting()
{ {
if (!replotTimer) if (!replotTimer) {
return; return;
}
replotTimer->stop(); replotTimer->stop();
} }
void ScopeGadgetWidget::deleteLegend() void ScopeGadgetWidget::deleteLegend()
{ {
if (!legend()) if (!legend()) {
return; return;
}
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0); disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
@ -211,8 +220,9 @@ void ScopeGadgetWidget::deleteLegend()
void ScopeGadgetWidget::addLegend() void ScopeGadgetWidget::addLegend()
{ {
if (legend()) if (legend()) {
return; return;
}
// Show a legend at the top // Show a legend at the top
QwtLegend *legend = new QwtLegend(); QwtLegend *legend = new QwtLegend();
@ -242,9 +252,11 @@ void ScopeGadgetWidget::addLegend()
foreach(QwtPlotItem * item, this->itemList()) { foreach(QwtPlotItem * item, this->itemList()) {
bool on = item->isVisible(); bool on = item->isVisible();
QWidget *w = legend->find(item); QWidget *w = legend->find(item);
if ( w && w->inherits("QwtLegendItem") )
if (w && w->inherits("QwtLegendItem")) {
((QwtLegendItem *)w)->setChecked(!on); ((QwtLegendItem *)w)->setChecked(!on);
} }
}
connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, SLOT(showCurve(QwtPlotItem *, bool))); connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, SLOT(showCurve(QwtPlotItem *, bool)));
} }
@ -281,21 +293,22 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
// Only start the timer if we are already connected // Only start the timer if we are already connected
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager(); Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
if (cm->getCurrentConnection() && replotTimer) if (cm->getCurrentConnection() && replotTimer) {
{ if (!replotTimer->isActive()) {
if (!replotTimer->isActive())
replotTimer->start(m_refreshInterval); replotTimer->start(m_refreshInterval);
else } else {
replotTimer->setInterval(m_refreshInterval); replotTimer->setInterval(m_refreshInterval);
} }
} }
}
void ScopeGadgetWidget::showCurve(QwtPlotItem *item, bool on) void ScopeGadgetWidget::showCurve(QwtPlotItem *item, bool on)
{ {
item->setVisible(!on); item->setVisible(!on);
QWidget *w = legend()->find(item); QWidget *w = legend()->find(item);
if ( w && w->inherits("QwtLegendItem") ) if (w && w->inherits("QwtLegendItem")) {
((QwtLegendItem *)w)->setChecked(on); ((QwtLegendItem *)w)->setChecked(on);
}
mutex.lock(); mutex.lock();
replot(); replot();
@ -385,14 +398,15 @@ void ScopeGadgetWidget::setupChronoPlot()
// scaleWidget->setMinBorderDist(0, fmw); // scaleWidget->setMinBorderDist(0, fmw);
} }
void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor, int meanSamples, QString mathFunction, QPen pen) void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor, int meanSamples, QString mathFunction, QPen pen, bool antialiased)
{ {
PlotData *plotData; PlotData *plotData;
if (m_plotType == SequentialPlot) if (m_plotType == SequentialPlot) {
plotData = new SequentialPlotData(uavObject, uavFieldSubField); plotData = new SequentialPlotData(uavObject, uavFieldSubField);
else if (m_plotType == ChronoPlot) } else if (m_plotType == ChronoPlot) {
plotData = new ChronoPlotData(uavObject, uavFieldSubField); plotData = new ChronoPlotData(uavObject, uavFieldSubField);
}
// else if (m_plotType == UAVObjectPlot) // else if (m_plotType == UAVObjectPlot)
// plotData = new UAVObjectPlotData(uavObject, uavField); // plotData = new UAVObjectPlotData(uavObject, uavField);
@ -402,15 +416,15 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField
plotData->mathFunction = mathFunction; plotData->mathFunction = mathFunction;
// If the y-bounds are supplied, set them // If the y-bounds are supplied, set them
if (plotData->yMinimum != plotData->yMaximum) if (plotData->yMinimum != plotData->yMaximum) {
{
setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum); setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum);
} }
// Create the curve // Create the curve
QString curveName = (plotData->uavObject) + "." + (plotData->uavField); QString curveName = (plotData->uavObject) + "." + (plotData->uavField);
if(plotData->haveSubField) if (plotData->haveSubField) {
curveName = curveName.append("." + plotData->uavSubField); curveName = curveName.append("." + plotData->uavSubField);
}
// Get the uav object // Get the uav object
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance(); ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
@ -427,16 +441,23 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField
} }
QString units = field->getUnits(); QString units = field->getUnits();
if(units == 0) if (units == 0) {
units = QString(); units = QString();
}
QString curveNameScaled; QString curveNameScaled;
if(scaleOrderFactor == 0) if (scaleOrderFactor == 0) {
curveNameScaled = curveName + " (" + units + ")"; curveNameScaled = curveName + " (" + units + ")";
else } else {
curveNameScaled = curveName + " (x10^" + QString::number(scaleOrderFactor) + " " + units + ")"; curveNameScaled = curveName + " (x10^" + QString::number(scaleOrderFactor) + " " + units + ")";
}
QwtPlotCurve *plotCurve = new QwtPlotCurve(curveNameScaled); QwtPlotCurve *plotCurve = new QwtPlotCurve(curveNameScaled);
if (antialiased) {
plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
}
plotCurve->setPen(pen); plotCurve->setPen(pen);
plotCurve->setSamples(*plotData->xData, *plotData->yData); plotCurve->setSamples(*plotData->xData, *plotData->yData);
plotCurve->attach(this); plotCurve->attach(this);
@ -475,17 +496,21 @@ void ScopeGadgetWidget::addCurvePlot(QString uavObject, QString uavFieldSubField
void ScopeGadgetWidget::uavObjectReceived(UAVObject *obj) void ScopeGadgetWidget::uavObjectReceived(UAVObject *obj)
{ {
foreach(PlotData * plotData, m_curvesData.values()) { foreach(PlotData * plotData, m_curvesData.values()) {
if (plotData->append(obj)) m_csvLoggingDataUpdated=1; if (plotData->append(obj)) {
m_csvLoggingDataUpdated = 1;
}
} }
csvLoggingAddData(); csvLoggingAddData();
} }
void ScopeGadgetWidget::replotNewData() void ScopeGadgetWidget::replotNewData()
{ {
QMutexLocker locker(&mutex); if (!isVisible()) {
return;
}
foreach(PlotData* plotData, m_curvesData.values()) QMutexLocker locker(&mutex);
{ foreach(PlotData * plotData, m_curvesData.values()) {
plotData->removeStaleData(); plotData->removeStaleData();
plotData->curve->setSamples(*plotData->xData, *plotData->yData); plotData->curve->setSamples(*plotData->xData, *plotData->yData);
} }
@ -493,8 +518,9 @@ void ScopeGadgetWidget::replotNewData()
QDateTime NOW = QDateTime::currentDateTime(); QDateTime NOW = QDateTime::currentDateTime();
double toTime = NOW.toTime_t(); double toTime = NOW.toTime_t();
toTime += NOW.time().msec() / 1000.0; toTime += NOW.time().msec() / 1000.0;
if (m_plotType == ChronoPlot) if (m_plotType == ChronoPlot) {
setAxisScale(QwtPlot::xBottom, toTime - m_xWindowSize, toTime); setAxisScale(QwtPlot::xBottom, toTime - m_xWindowSize, toTime);
}
// qDebug() << "replotNewData from " << NOW.addSecs(- m_xWindowSize) << " to " << NOW; // qDebug() << "replotNewData from " << NOW.addSecs(- m_xWindowSize) << " to " << NOW;
@ -503,53 +529,6 @@ void ScopeGadgetWidget::replotNewData()
replot(); replot();
} }
/*
void ScopeGadgetWidget::setupExamplePlot()
{
preparePlot(SequentialPlot);
// Show the axes
setAxisTitle(xBottom, "x");
setAxisTitle(yLeft, "y");
// Calculate the data, 500 points each
const int points = 500;
double x[ points ];
double sn[ points ];
double cs[ points ];
double sg[ points ];
for (int i = 0; i < points; i++) {
x[i] = (3.0 * 3.14 / double(points)) * double(i);
sn[i] = 2.0 * sin(x[i]);
cs[i] = 3.0 * cos(x[i]);
sg[i] = (sn[i] > 0) ? 1 : ((sn[i] < 0) ? -1 : 0);
}
// add curves
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
curve1->setPen(QPen(Qt::blue));
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
curve2->setPen(QPen(Qt::red));
QwtPlotCurve *curve3 = new QwtPlotCurve("Curve 3");
curve3->setPen(QPen(Qt::green));
// copy the data into the curves
curve1->setSamples(x, sn, points);
curve2->setSamples(x, cs, points);
curve3->setSamples(x, sg, points);
curve1->attach(this);
curve2->attach(this);
curve3->attach(this);
// finally, refresh the plot
mutex.lock();
replot();
mutex.unlock();
}
*/
void ScopeGadgetWidget::clearCurvePlots() void ScopeGadgetWidget::clearCurvePlots()
{ {
foreach(PlotData * plotData, m_curvesData.values()) { foreach(PlotData * plotData, m_curvesData.values()) {
@ -572,41 +551,34 @@ QFile csvLoggingFile;
*/ */
int ScopeGadgetWidget::csvLoggingStart() int ScopeGadgetWidget::csvLoggingStart()
{ {
if (!m_csvLoggingStarted) if (!m_csvLoggingStarted) {
if (m_csvLoggingEnabled) if (m_csvLoggingEnabled) {
if ((!m_csvLoggingNewFileOnConnect)||(m_csvLoggingNewFileOnConnect && m_csvLoggingConnected)) if ((!m_csvLoggingNewFileOnConnect) || (m_csvLoggingNewFileOnConnect && m_csvLoggingConnected)) {
{
QDateTime NOW = QDateTime::currentDateTime(); QDateTime NOW = QDateTime::currentDateTime();
m_csvLoggingStartTime = NOW; m_csvLoggingStartTime = NOW;
m_csvLoggingHeaderSaved = 0; m_csvLoggingHeaderSaved = 0;
m_csvLoggingDataSaved = 0; m_csvLoggingDataSaved = 0;
m_csvLoggingBuffer.clear(); m_csvLoggingBuffer.clear();
QDir PathCheck(m_csvLoggingPath); QDir PathCheck(m_csvLoggingPath);
if (!PathCheck.exists()) if (!PathCheck.exists()) {
{
PathCheck.mkpath("./"); PathCheck.mkpath("./");
} }
if (m_csvLoggingNameSet) if (m_csvLoggingNameSet) {
{
m_csvLoggingFile.setFileName(QString("%1/%2_%3_%4.csv").arg(m_csvLoggingPath).arg(m_csvLoggingName).arg(NOW.toString("yyyy-MM-dd")).arg(NOW.toString("hh-mm-ss"))); m_csvLoggingFile.setFileName(QString("%1/%2_%3_%4.csv").arg(m_csvLoggingPath).arg(m_csvLoggingName).arg(NOW.toString("yyyy-MM-dd")).arg(NOW.toString("hh-mm-ss")));
} } else {
else
{
m_csvLoggingFile.setFileName(QString("%1/Log_%2_%3.csv").arg(m_csvLoggingPath).arg(NOW.toString("yyyy-MM-dd")).arg(NOW.toString("hh-mm-ss"))); m_csvLoggingFile.setFileName(QString("%1/Log_%2_%3.csv").arg(m_csvLoggingPath).arg(NOW.toString("yyyy-MM-dd")).arg(NOW.toString("hh-mm-ss")));
} }
QDir FileCheck(m_csvLoggingFile.fileName()); QDir FileCheck(m_csvLoggingFile.fileName());
if (FileCheck.exists()) if (FileCheck.exists()) {
{
m_csvLoggingFile.setFileName(""); m_csvLoggingFile.setFileName("");
} } else {
else
{
m_csvLoggingStarted = 1; m_csvLoggingStarted = 1;
csvLoggingInsertHeader(); csvLoggingInsertHeader();
} }
}
}
} }
return 0; return 0;
@ -621,26 +593,30 @@ int ScopeGadgetWidget::csvLoggingStop()
int ScopeGadgetWidget::csvLoggingInsertHeader() int ScopeGadgetWidget::csvLoggingInsertHeader()
{ {
if (!m_csvLoggingStarted) return -1; if (!m_csvLoggingStarted) {
if (m_csvLoggingHeaderSaved) return -2; return -1;
if (m_csvLoggingDataSaved) return -3; }
if (m_csvLoggingHeaderSaved) {
return -2;
}
if (m_csvLoggingDataSaved) {
return -3;
}
m_csvLoggingHeaderSaved = 1; m_csvLoggingHeaderSaved = 1;
if(m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append)== FALSE) if (m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append) == FALSE) {
{
qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Header"; qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Header";
} } else {
else
{
QTextStream ts(&m_csvLoggingFile); QTextStream ts(&m_csvLoggingFile);
ts << "date" << ", " << "Time" << ", " << "Sec since start" << ", " << "Connected" << ", " << "Data changed"; ts << "date" << ", " << "Time" << ", " << "Sec since start" << ", " << "Connected" << ", " << "Data changed";
foreach(PlotData* plotData2, m_curvesData.values()) foreach(PlotData * plotData2, m_curvesData.values()) {
{
ts << ", "; ts << ", ";
ts << plotData2->uavObject; ts << plotData2->uavObject;
ts << "." << plotData2->uavField; ts << "." << plotData2->uavField;
if (plotData2->haveSubField) ts << "." << plotData2->uavSubField; if (plotData2->haveSubField) {
ts << "." << plotData2->uavSubField;
}
} }
ts << endl; ts << endl;
m_csvLoggingFile.close(); m_csvLoggingFile.close();
@ -650,7 +626,9 @@ int ScopeGadgetWidget::csvLoggingInsertHeader()
int ScopeGadgetWidget::csvLoggingAddData() int ScopeGadgetWidget::csvLoggingAddData()
{ {
if (!m_csvLoggingStarted) return -1; if (!m_csvLoggingStarted) {
return -1;
}
m_csvLoggingDataValid = 0; m_csvLoggingDataValid = 0;
QDateTime NOW = QDateTime::currentDateTime(); QDateTime NOW = QDateTime::currentDateTime();
QString tempString; QString tempString;
@ -666,30 +644,21 @@ int ScopeGadgetWidget::csvLoggingAddData()
ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated; ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated;
m_csvLoggingDataUpdated = 0; m_csvLoggingDataUpdated = 0;
foreach(PlotData* plotData2, m_curvesData.values()) foreach(PlotData * plotData2, m_curvesData.values()) {
{
ss << ", "; ss << ", ";
if (plotData2->xData->isEmpty ()) if (plotData2->xData->isEmpty()) {
{
ss << ", "; ss << ", ";
if (plotData2->xData->isEmpty ()) if (plotData2->xData->isEmpty()) {} else {
{
}
else
{
ss << QString().sprintf("%3.10g", plotData2->yData->last()); ss << QString().sprintf("%3.10g", plotData2->yData->last());
m_csvLoggingDataValid = 1; m_csvLoggingDataValid = 1;
} }
} } else {
else
{
ss << QString().sprintf("%3.10g", plotData2->yData->last()); ss << QString().sprintf("%3.10g", plotData2->yData->last());
m_csvLoggingDataValid = 1; m_csvLoggingDataValid = 1;
} }
} }
ss << endl; ss << endl;
if (m_csvLoggingDataValid) if (m_csvLoggingDataValid) {
{
QTextStream ts(&m_csvLoggingBuffer); QTextStream ts(&m_csvLoggingBuffer);
ts << tempString; ts << tempString;
} }
@ -699,15 +668,14 @@ int ScopeGadgetWidget::csvLoggingAddData()
int ScopeGadgetWidget::csvLoggingInsertData() int ScopeGadgetWidget::csvLoggingInsertData()
{ {
if (!m_csvLoggingStarted) return -1; if (!m_csvLoggingStarted) {
return -1;
}
m_csvLoggingDataSaved = 1; m_csvLoggingDataSaved = 1;
if(m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append)== FALSE) if (m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append) == FALSE) {
{
qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Data"; qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Data";
} } else {
else
{
QTextStream ts(&m_csvLoggingFile); QTextStream ts(&m_csvLoggingFile);
ts << m_csvLoggingBuffer; ts << m_csvLoggingBuffer;
m_csvLoggingFile.close(); m_csvLoggingFile.close();
@ -726,13 +694,15 @@ void ScopeGadgetWidget::csvLoggingSetName(QString newName)
void ScopeGadgetWidget::csvLoggingConnect() void ScopeGadgetWidget::csvLoggingConnect()
{ {
m_csvLoggingConnected = 1; m_csvLoggingConnected = 1;
if (m_csvLoggingNewFileOnConnect)csvLoggingStart(); if (m_csvLoggingNewFileOnConnect) {
return; csvLoggingStart();
}
} }
void ScopeGadgetWidget::csvLoggingDisconnect() void ScopeGadgetWidget::csvLoggingDisconnect()
{ {
m_csvLoggingHeaderSaved = 0; m_csvLoggingHeaderSaved = 0;
m_csvLoggingConnected = 0; m_csvLoggingConnected = 0;
if (m_csvLoggingNewFileOnConnect)csvLoggingStop(); if (m_csvLoggingNewFileOnConnect) {
return; csvLoggingStop();
}
} }

View File

@ -49,7 +49,6 @@ class TimeScaleDraw : public QwtScaleDraw
{ {
public: public:
TimeScaleDraw() { TimeScaleDraw() {
//baseTime = QDateTime::currentDateTime().toTime_t();
} }
virtual QwtText label(double v) const { virtual QwtText label(double v) const {
uint seconds = (uint)(v); uint seconds = (uint)(v);
@ -58,8 +57,6 @@ public:
upTime.setTime(timePart); upTime.setTime(timePart);
return upTime.toLocalTime().toString("hh:mm:ss"); return upTime.toLocalTime().toString("hh:mm:ss");
} }
private:
// double baseTime;
}; };
class ScopeGadgetWidget : public QwtPlot class ScopeGadgetWidget : public QwtPlot
@ -81,15 +78,15 @@ public:
int refreshInterval(){return m_refreshInterval;} int refreshInterval(){return m_refreshInterval;}
void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1, QString mathFunction= "None", QPen pen = QPen(Qt::black)); void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1,
//void removeCurvePlot(QString uavObject, QString uavField); QString mathFunction= "None", QPen pen = QPen(Qt::black), bool antialiased = true);
void clearCurvePlots(); void clearCurvePlots();
int csvLoggingStart(); int csvLoggingStart();
int csvLoggingStop(); int csvLoggingStop();
void csvLoggingSetName(QString); void csvLoggingSetName(QString);
void setLoggingEnabled(bool value){m_csvLoggingEnabled=value;}; void setLoggingEnabled(bool value){m_csvLoggingEnabled=value;}
void setLoggingNewFileOnConnect(bool value){m_csvLoggingNewFileOnConnect=value;}; void setLoggingNewFileOnConnect(bool value){m_csvLoggingNewFileOnConnect=value;}
void setLoggingPath(QString value){m_csvLoggingPath=value;}; void setLoggingPath(QString value){m_csvLoggingPath=value;}
protected: protected:
void mousePressEvent(QMouseEvent *e); void mousePressEvent(QMouseEvent *e);
@ -97,6 +94,7 @@ protected:
void mouseDoubleClickEvent(QMouseEvent *e); void mouseDoubleClickEvent(QMouseEvent *e);
void mouseMoveEvent(QMouseEvent *e); void mouseMoveEvent(QMouseEvent *e);
void wheelEvent(QWheelEvent *e); void wheelEvent(QWheelEvent *e);
void showEvent(QShowEvent *e);
private slots: private slots:
void uavObjectReceived(UAVObject*); void uavObjectReceived(UAVObject*);