mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2024-11-30 08:24:11 +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:
parent
b9601c3ad6
commit
c4adede7ac
@ -33,52 +33,47 @@
|
||||
#include <QtGui/qcolor.h>
|
||||
|
||||
ScopeGadget::ScopeGadget(QString classId, ScopeGadgetWidget *widget, QWidget *parent) :
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget),
|
||||
configLoaded(false)
|
||||
IUAVGadget(classId, parent),
|
||||
m_widget(widget),
|
||||
configLoaded(false)
|
||||
{}
|
||||
|
||||
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration *config)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
{
|
||||
|
||||
ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration*>(config);
|
||||
ScopeGadgetWidget* widget = qobject_cast<ScopeGadgetWidget*>(m_widget);
|
||||
ScopeGadgetConfiguration *sgConfig = qobject_cast<ScopeGadgetConfiguration *>(config);
|
||||
ScopeGadgetWidget *widget = qobject_cast<ScopeGadgetWidget *>(m_widget);
|
||||
|
||||
widget->setXWindowSize(sgConfig->dataSize());
|
||||
widget->setRefreshInterval(sgConfig->refreshInterval());
|
||||
|
||||
if(sgConfig->plotType() == SequentialPlot )
|
||||
if (sgConfig->plotType() == SequentialPlot) {
|
||||
widget->setupSequentialPlot();
|
||||
else if(sgConfig->plotType() == ChronoPlot)
|
||||
} else if (sgConfig->plotType() == ChronoPlot) {
|
||||
widget->setupChronoPlot();
|
||||
// else if(sgConfig->plotType() == UAVObjectPlot)
|
||||
// widget->setupUAVObjectPlot();
|
||||
}
|
||||
|
||||
foreach (PlotCurveConfiguration* plotCurveConfig, sgConfig->plotCurveConfigs()) {
|
||||
|
||||
QString uavObject = plotCurveConfig->uavObject;
|
||||
QString uavField = plotCurveConfig->uavField;
|
||||
foreach(PlotCurveConfiguration * plotCurveConfig, sgConfig->plotCurveConfigs()) {
|
||||
QString uavObject = plotCurveConfig->uavObject;
|
||||
QString uavField = plotCurveConfig->uavField;
|
||||
int scale = plotCurveConfig->yScalePower;
|
||||
int mean = plotCurveConfig->yMeanSamples;
|
||||
QString mathFunction = plotCurveConfig->mathFunction;
|
||||
QRgb color = plotCurveConfig->color;
|
||||
|
||||
bool antialiased = plotCurveConfig->drawAntialiased;
|
||||
widget->addCurvePlot(
|
||||
uavObject,
|
||||
uavField,
|
||||
scale,
|
||||
mean,
|
||||
mathFunction,
|
||||
QPen( QBrush(QColor(color),Qt::SolidPattern),
|
||||
// (qreal)2,
|
||||
(qreal)1,
|
||||
Qt::SolidLine,
|
||||
Qt::SquareCap,
|
||||
Qt::BevelJoin)
|
||||
);
|
||||
}
|
||||
uavObject,
|
||||
uavField,
|
||||
scale,
|
||||
mean,
|
||||
mathFunction,
|
||||
QPen(QBrush(QColor(color), Qt::SolidPattern),
|
||||
(qreal)1,
|
||||
Qt::SolidLine,
|
||||
Qt::SquareCap,
|
||||
Qt::BevelJoin),
|
||||
antialiased
|
||||
);
|
||||
}
|
||||
|
||||
widget->setLoggingEnabled(sgConfig->getLoggingEnabled());
|
||||
widget->setLoggingNewFileOnConnect(sgConfig->getLoggingNewFileOnConnect());
|
||||
@ -87,14 +82,13 @@ void ScopeGadget::loadConfiguration(IUAVGadgetConfiguration* config)
|
||||
widget->csvLoggingStop();
|
||||
widget->csvLoggingSetName(sgConfig->name());
|
||||
widget->csvLoggingStart();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
Scope gadget destructor: should delete the associated
|
||||
scope gadget widget too!
|
||||
*/
|
||||
Scope gadget destructor: should delete the associated
|
||||
scope gadget widget too!
|
||||
*/
|
||||
ScopeGadget::~ScopeGadget()
|
||||
{
|
||||
delete m_widget;
|
||||
delete m_widget;
|
||||
}
|
||||
|
@ -27,75 +27,63 @@
|
||||
|
||||
#include "scopegadgetconfiguration.h"
|
||||
|
||||
ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings* qSettings, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_plotType((int)ChronoPlot),
|
||||
m_dataSize(60),
|
||||
m_refreshInterval(1000),
|
||||
m_mathFunctionType(0)
|
||||
ScopeGadgetConfiguration::ScopeGadgetConfiguration(QString classId, QSettings *qSettings, QObject *parent) :
|
||||
IUAVGadgetConfiguration(classId, parent),
|
||||
m_plotType((int)ChronoPlot),
|
||||
m_dataSize(60),
|
||||
m_refreshInterval(1000),
|
||||
m_mathFunctionType(0)
|
||||
{
|
||||
uint currentStreamVersion = 0;
|
||||
int plotCurveCount = 0;
|
||||
|
||||
|
||||
//if a saved configuration exists load it
|
||||
if(qSettings != 0) {
|
||||
// If a saved configuration exists load it
|
||||
if (qSettings != 0) {
|
||||
currentStreamVersion = qSettings->value("configurationStreamVersion").toUInt();
|
||||
|
||||
if(currentStreamVersion != m_configurationStreamVersion)
|
||||
if (currentStreamVersion != m_configurationStreamVersion) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_plotType = qSettings->value("plotType").toInt();
|
||||
m_dataSize = qSettings->value("dataSize").toInt();
|
||||
m_plotType = qSettings->value("plotType").toInt();
|
||||
m_dataSize = qSettings->value("dataSize").toInt();
|
||||
m_refreshInterval = qSettings->value("refreshInterval").toInt();
|
||||
plotCurveCount = qSettings->value("plotCurveCount").toInt();
|
||||
|
||||
for(int plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++)
|
||||
{
|
||||
QString uavObject;
|
||||
QString uavField;
|
||||
QRgb color;
|
||||
plotCurveCount = qSettings->value("plotCurveCount").toInt();
|
||||
|
||||
for (int plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
|
||||
qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
|
||||
|
||||
PlotCurveConfiguration* plotCurveConf = new PlotCurveConfiguration();
|
||||
uavObject = qSettings->value("uavObject").toString();
|
||||
plotCurveConf->uavObject = uavObject;
|
||||
uavField = qSettings->value("uavField").toString();
|
||||
plotCurveConf->uavField = uavField;
|
||||
color = qSettings->value("color").value<QRgb>();
|
||||
plotCurveConf->color = color;
|
||||
plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt();
|
||||
PlotCurveConfiguration *plotCurveConf = new PlotCurveConfiguration();
|
||||
plotCurveConf->uavObject = qSettings->value("uavObject").toString();
|
||||
plotCurveConf->uavField = qSettings->value("uavField").toString();
|
||||
plotCurveConf->color = qSettings->value("color").value<QRgb>();
|
||||
plotCurveConf->yScalePower = qSettings->value("yScalePower").toInt();
|
||||
plotCurveConf->mathFunction = qSettings->value("mathFunction").toString();
|
||||
plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples").toInt();
|
||||
|
||||
if (!plotCurveConf->yMeanSamples) plotCurveConf->yMeanSamples = 1; // fallback for backward compatibility with earlier versions //IS THIS STILL NECESSARY?
|
||||
|
||||
plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples", 1).toInt();
|
||||
plotCurveConf->yMeanSamples = qSettings->value("yMeanSamples", 1).toInt();
|
||||
plotCurveConf->drawAntialiased = qSettings->value("drawAntialiased", true).toBool();
|
||||
plotCurveConf->yMinimum = qSettings->value("yMinimum").toDouble();
|
||||
plotCurveConf->yMaximum = qSettings->value("yMaximum").toDouble();
|
||||
|
||||
m_PlotCurveConfigs.append(plotCurveConf);
|
||||
m_plotCurveConfigs.append(plotCurveConf);
|
||||
|
||||
qSettings->endGroup();
|
||||
}
|
||||
|
||||
m_LoggingEnabled = qSettings->value("LoggingEnabled").toBool();
|
||||
m_LoggingNewFileOnConnect = qSettings->value("LoggingNewFileOnConnect").toBool();
|
||||
m_LoggingPath = qSettings->value("LoggingPath").toString();
|
||||
|
||||
m_loggingEnabled = qSettings->value("LoggingEnabled").toBool();
|
||||
m_loggingNewFileOnConnect = qSettings->value("LoggingNewFileOnConnect").toBool();
|
||||
m_loggingPath = qSettings->value("LoggingPath").toString();
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetConfiguration::clearPlotData()
|
||||
{
|
||||
PlotCurveConfiguration* poltCurveConfig;
|
||||
PlotCurveConfiguration *plotCurveConfig;
|
||||
|
||||
while(m_PlotCurveConfigs.size() > 0)
|
||||
{
|
||||
poltCurveConfig = m_PlotCurveConfigs.first();
|
||||
m_PlotCurveConfigs.pop_front();
|
||||
|
||||
delete poltCurveConfig;
|
||||
while (m_plotCurveConfigs.size() > 0) {
|
||||
plotCurveConfig = m_plotCurveConfigs.first();
|
||||
m_plotCurveConfigs.pop_front();
|
||||
delete plotCurveConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,40 +93,38 @@ void ScopeGadgetConfiguration::clearPlotData()
|
||||
*/
|
||||
IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
|
||||
{
|
||||
int plotCurveCount = 0;
|
||||
int plotCurveCount = 0;
|
||||
int plotDatasLoadIndex = 0;
|
||||
|
||||
ScopeGadgetConfiguration *m = new ScopeGadgetConfiguration(this->classId());
|
||||
m->setPlotType( m_plotType);
|
||||
m->setDataSize( m_dataSize);
|
||||
m->setMathFunctionType( m_mathFunctionType);
|
||||
m->setRefreashInterval( m_refreshInterval);
|
||||
|
||||
plotCurveCount = m_PlotCurveConfigs.size();
|
||||
m->setPlotType(m_plotType);
|
||||
m->setDataSize(m_dataSize);
|
||||
m->setMathFunctionType(m_mathFunctionType);
|
||||
m->setRefreashInterval(m_refreshInterval);
|
||||
|
||||
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++)
|
||||
{
|
||||
PlotCurveConfiguration* currentPlotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex);
|
||||
plotCurveCount = m_plotCurveConfigs.size();
|
||||
|
||||
PlotCurveConfiguration* newPlotCurveConf = new PlotCurveConfiguration();
|
||||
newPlotCurveConf->uavObject = currentPlotCurveConf->uavObject;
|
||||
newPlotCurveConf->uavField = currentPlotCurveConf->uavField;
|
||||
newPlotCurveConf->color = currentPlotCurveConf->color;
|
||||
newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower;
|
||||
for (plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
|
||||
PlotCurveConfiguration *currentPlotCurveConf = m_plotCurveConfigs.at(plotDatasLoadIndex);
|
||||
|
||||
PlotCurveConfiguration *newPlotCurveConf = new PlotCurveConfiguration();
|
||||
newPlotCurveConf->uavObject = currentPlotCurveConf->uavObject;
|
||||
newPlotCurveConf->uavField = currentPlotCurveConf->uavField;
|
||||
newPlotCurveConf->color = currentPlotCurveConf->color;
|
||||
newPlotCurveConf->yScalePower = currentPlotCurveConf->yScalePower;
|
||||
newPlotCurveConf->yMeanSamples = currentPlotCurveConf->yMeanSamples;
|
||||
newPlotCurveConf->mathFunction = currentPlotCurveConf->mathFunction;
|
||||
|
||||
newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum;
|
||||
newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum;
|
||||
newPlotCurveConf->drawAntialiased = currentPlotCurveConf->drawAntialiased;
|
||||
newPlotCurveConf->yMinimum = currentPlotCurveConf->yMinimum;
|
||||
newPlotCurveConf->yMaximum = currentPlotCurveConf->yMaximum;
|
||||
|
||||
m->addPlotCurveConfig(newPlotCurveConf);
|
||||
}
|
||||
|
||||
m->setLoggingEnabled(m_LoggingEnabled);
|
||||
m->setLoggingNewFileOnConnect(m_LoggingNewFileOnConnect);
|
||||
m->setLoggingPath(m_LoggingPath);
|
||||
|
||||
|
||||
m->setLoggingEnabled(m_loggingEnabled);
|
||||
m->setLoggingNewFileOnConnect(m_loggingNewFileOnConnect);
|
||||
m->setLoggingPath(m_loggingPath);
|
||||
|
||||
return m;
|
||||
}
|
||||
@ -148,9 +134,9 @@ IUAVGadgetConfiguration *ScopeGadgetConfiguration::clone()
|
||||
* Saves a configuration. //REDEFINES saveConfig CHILD BEHAVIOR?
|
||||
*
|
||||
*/
|
||||
void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const {
|
||||
|
||||
int plotCurveCount = m_PlotCurveConfigs.size();
|
||||
void ScopeGadgetConfiguration::saveConfig(QSettings *qSettings) const
|
||||
{
|
||||
int plotCurveCount = m_plotCurveConfigs.size();
|
||||
int plotDatasLoadIndex = 0;
|
||||
|
||||
qSettings->setValue("configurationStreamVersion", m_configurationStreamVersion);
|
||||
@ -159,35 +145,33 @@ void ScopeGadgetConfiguration::saveConfig(QSettings* qSettings) const {
|
||||
qSettings->setValue("refreshInterval", m_refreshInterval);
|
||||
qSettings->setValue("plotCurveCount", plotCurveCount);
|
||||
|
||||
for(plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++)
|
||||
{
|
||||
for (plotDatasLoadIndex = 0; plotDatasLoadIndex < plotCurveCount; plotDatasLoadIndex++) {
|
||||
qSettings->beginGroup(QString("plotCurve") + QString().number(plotDatasLoadIndex));
|
||||
|
||||
PlotCurveConfiguration* plotCurveConf = m_PlotCurveConfigs.at(plotDatasLoadIndex);
|
||||
qSettings->setValue("uavObject", plotCurveConf->uavObject);
|
||||
qSettings->setValue("uavField", plotCurveConf->uavField);
|
||||
qSettings->setValue("color", plotCurveConf->color);
|
||||
qSettings->setValue("mathFunction", plotCurveConf->mathFunction);
|
||||
qSettings->setValue("yScalePower", plotCurveConf->yScalePower);
|
||||
qSettings->setValue("yMeanSamples", plotCurveConf->yMeanSamples);
|
||||
qSettings->setValue("yMinimum", plotCurveConf->yMinimum);
|
||||
qSettings->setValue("yMaximum", plotCurveConf->yMaximum);
|
||||
PlotCurveConfiguration *plotCurveConf = m_plotCurveConfigs.at(plotDatasLoadIndex);
|
||||
qSettings->setValue("uavObject", plotCurveConf->uavObject);
|
||||
qSettings->setValue("uavField", plotCurveConf->uavField);
|
||||
qSettings->setValue("color", plotCurveConf->color);
|
||||
qSettings->setValue("mathFunction", plotCurveConf->mathFunction);
|
||||
qSettings->setValue("yScalePower", plotCurveConf->yScalePower);
|
||||
qSettings->setValue("yMeanSamples", plotCurveConf->yMeanSamples);
|
||||
qSettings->setValue("yMinimum", plotCurveConf->yMinimum);
|
||||
qSettings->setValue("yMaximum", plotCurveConf->yMaximum);
|
||||
qSettings->setValue("drawAntialiased", plotCurveConf->drawAntialiased);
|
||||
|
||||
qSettings->endGroup();
|
||||
}
|
||||
|
||||
qSettings->setValue("LoggingEnabled", m_LoggingEnabled);
|
||||
qSettings->setValue("LoggingNewFileOnConnect", m_LoggingNewFileOnConnect);
|
||||
qSettings->setValue("LoggingPath", m_LoggingPath);
|
||||
|
||||
|
||||
qSettings->setValue("LoggingEnabled", m_loggingEnabled);
|
||||
qSettings->setValue("LoggingNewFileOnConnect", m_loggingNewFileOnConnect);
|
||||
qSettings->setValue("LoggingPath", m_loggingPath);
|
||||
}
|
||||
|
||||
void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration*> newPlotCurveConfigs)
|
||||
void ScopeGadgetConfiguration::replacePlotCurveConfig(QList<PlotCurveConfiguration *> newPlotCurveConfigs)
|
||||
{
|
||||
clearPlotData();
|
||||
|
||||
m_PlotCurveConfigs.append(newPlotCurveConfigs);
|
||||
m_plotCurveConfigs.append(newPlotCurveConfigs);
|
||||
}
|
||||
|
||||
ScopeGadgetConfiguration::~ScopeGadgetConfiguration()
|
||||
|
@ -35,66 +35,117 @@
|
||||
|
||||
using namespace Core;
|
||||
|
||||
struct PlotCurveConfiguration
|
||||
{
|
||||
struct PlotCurveConfiguration {
|
||||
QString uavObject;
|
||||
QString uavField;
|
||||
int yScalePower; //This is the power to which each value must be raised
|
||||
QRgb color;
|
||||
int yMeanSamples;
|
||||
int yScalePower; // This is the power to which each value must be raised
|
||||
QRgb color;
|
||||
int yMeanSamples;
|
||||
QString mathFunction;
|
||||
double yMinimum;
|
||||
double yMaximum;
|
||||
double yMinimum;
|
||||
double yMaximum;
|
||||
bool drawAntialiased;
|
||||
};
|
||||
|
||||
class ScopeGadgetConfiguration : public IUAVGadgetConfiguration
|
||||
{
|
||||
class ScopeGadgetConfiguration : public IUAVGadgetConfiguration {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScopeGadgetConfiguration(QString classId, QSettings* qSettings = 0, QObject *parent = 0);
|
||||
explicit ScopeGadgetConfiguration(QString classId, QSettings *qSettings = 0, QObject *parent = 0);
|
||||
|
||||
~ScopeGadgetConfiguration();
|
||||
|
||||
//configuration setter functions
|
||||
void setPlotType(int value){m_plotType = value;}
|
||||
void setMathFunctionType(int value){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);
|
||||
// configuration setter functions
|
||||
void setPlotType(int value)
|
||||
{
|
||||
m_plotType = value;
|
||||
}
|
||||
void setMathFunctionType(int value)
|
||||
{
|
||||
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
|
||||
int plotType(){return m_plotType;}
|
||||
int mathFunctionType(){return m_mathFunctionType;}
|
||||
int dataSize(){return m_dataSize;}
|
||||
int refreshInterval(){return m_refreshInterval;}
|
||||
QList<PlotCurveConfiguration*> plotCurveConfigs(){return m_PlotCurveConfigs;}
|
||||
// Configurations getter functions
|
||||
int plotType()
|
||||
{
|
||||
return m_plotType;
|
||||
}
|
||||
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();
|
||||
|
||||
bool getLoggingEnabled(){return m_LoggingEnabled;};
|
||||
bool getLoggingNewFileOnConnect(){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;};
|
||||
bool getLoggingEnabled()
|
||||
{
|
||||
return m_loggingEnabled;
|
||||
}
|
||||
bool getLoggingNewFileOnConnect()
|
||||
{
|
||||
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:
|
||||
|
||||
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.
|
||||
int m_plotType; //The type of the plot
|
||||
int m_dataSize; //The size of the data buffer to render in the curve plot
|
||||
int m_refreshInterval; //The interval to replot the curve widget. The data buffer is refresh as the data comes in.
|
||||
int m_mathFunctionType; //The type of math function to be used in the scope analysis
|
||||
QList<PlotCurveConfiguration*> m_PlotCurveConfigs;
|
||||
// Increment this if the stream format is not compatible with previous versions. This would cause existing configs to be discarded.
|
||||
static const uint m_configurationStreamVersion = 1000;
|
||||
// The type of the plot
|
||||
int m_plotType;
|
||||
// The size of the data buffer to render in the curve plot
|
||||
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();
|
||||
bool m_LoggingEnabled;
|
||||
bool m_LoggingNewFileOnConnect;
|
||||
QString m_LoggingPath;
|
||||
|
||||
bool m_loggingEnabled;
|
||||
bool m_loggingNewFileOnConnect;
|
||||
QString m_loggingPath;
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETCONFIGURATION_H
|
||||
|
@ -36,96 +36,98 @@
|
||||
|
||||
|
||||
ScopeGadgetOptionsPage::ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent) :
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
IOptionsPage(parent),
|
||||
m_config(config)
|
||||
{
|
||||
//nothing to do here...
|
||||
// nothing to do here...
|
||||
}
|
||||
|
||||
//creates options page widget (uses the UI file)
|
||||
QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
|
||||
// creates options page widget (uses the UI file)
|
||||
QWidget *ScopeGadgetOptionsPage::createPage(QWidget *parent)
|
||||
{
|
||||
Q_UNUSED(parent);
|
||||
|
||||
options_page = new Ui::ScopeGadgetOptionsPage();
|
||||
//main widget
|
||||
// main widget
|
||||
QWidget *optionsPageWidget = new QWidget;
|
||||
//main layout
|
||||
// main layout
|
||||
options_page->setupUi(optionsPageWidget);
|
||||
|
||||
options_page->cmbPlotType->addItem("Sequential Plot","");
|
||||
options_page->cmbPlotType->addItem("Chronological Plot","");
|
||||
options_page->cmbPlotType->addItem("Sequential Plot", "");
|
||||
options_page->cmbPlotType->addItem("Chronological Plot", "");
|
||||
|
||||
// Fills the combo boxes for the UAVObjects
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
QList< QList<UAVDataObject*> > objList = objManager->getDataObjects();
|
||||
foreach (QList<UAVDataObject*> list, objList) {
|
||||
foreach (UAVDataObject* obj, list) {
|
||||
QList< QList<UAVDataObject *> > objList = objManager->getDataObjects();
|
||||
foreach(QList<UAVDataObject *> list, objList) {
|
||||
foreach(UAVDataObject * obj, list) {
|
||||
options_page->cmbUAVObjects->addItem(obj->getName());
|
||||
}
|
||||
}
|
||||
|
||||
//Connect signals to slots cmbUAVObjects.currentIndexChanged
|
||||
// Connect signals to slots cmbUAVObjects.currentIndexChanged
|
||||
connect(options_page->cmbUAVObjects, SIGNAL(currentIndexChanged(QString)), this, SLOT(on_cmbUAVObjects_currentIndexChanged(QString)));
|
||||
|
||||
options_page->mathFunctionComboBox->addItem("None");
|
||||
options_page->mathFunctionComboBox->addItem("Boxcar average");
|
||||
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());
|
||||
}
|
||||
|
||||
options_page->cmbScale->addItem("10^-9", -9);
|
||||
options_page->cmbScale->addItem("10^-6", -6);
|
||||
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);
|
||||
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);
|
||||
options_page->cmbScale->setCurrentIndex(7);
|
||||
|
||||
//Set widget values from settings
|
||||
// Set widget values from settings
|
||||
options_page->cmbPlotType->setCurrentIndex(m_config->plotType());
|
||||
options_page->mathFunctionComboBox->setCurrentIndex(m_config->mathFunctionType());
|
||||
options_page->spnDataSize->setValue(m_config->dataSize());
|
||||
options_page->spnRefreshInterval->setValue(m_config->refreshInterval());
|
||||
|
||||
//add the configured curves
|
||||
foreach (PlotCurveConfiguration* plotData, m_config->plotCurveConfigs()) {
|
||||
|
||||
// add the configured curves
|
||||
foreach(PlotCurveConfiguration * plotData, m_config->plotCurveConfigs()) {
|
||||
QString uavObject = plotData->uavObject;
|
||||
QString uavField = plotData->uavField;
|
||||
int scale = plotData->yScalePower;
|
||||
int mean = plotData->yMeanSamples;
|
||||
QString mathFunction = plotData->mathFunction;
|
||||
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);
|
||||
}
|
||||
|
||||
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()));
|
||||
connect(options_page->mathFunctionComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(on_mathFunctionComboBox_currentIndexChanged(int)));
|
||||
connect(options_page->spnRefreshInterval, SIGNAL(valueChanged(int )), this, SLOT(on_spnRefreshInterval_valueChanged(int)));
|
||||
connect(options_page->spnRefreshInterval, SIGNAL(valueChanged(int)), this, SLOT(on_spnRefreshInterval_valueChanged(int)));
|
||||
|
||||
setYAxisWidgetFromPlotCurve();
|
||||
|
||||
//logging path setup
|
||||
// logging path setup
|
||||
options_page->LoggingPath->setExpectedKind(Utils::PathChooser::Directory);
|
||||
options_page->LoggingPath->setPromptDialogTitle(tr("Choose Logging Directory"));
|
||||
options_page->LoggingPath->setPath(m_config->getLoggingPath());
|
||||
@ -134,89 +136,91 @@ QWidget* ScopeGadgetOptionsPage::createPage(QWidget *parent)
|
||||
connect(options_page->LoggingEnable, SIGNAL(clicked()), this, SLOT(on_loggingEnable_clicked()));
|
||||
on_loggingEnable_clicked();
|
||||
|
||||
//Disable mouse wheel events
|
||||
foreach( QSpinBox * sp, findChildren<QSpinBox*>() ) {
|
||||
sp->installEventFilter( this );
|
||||
// Disable mouse wheel events
|
||||
foreach(QSpinBox * sp, findChildren<QSpinBox *>()) {
|
||||
sp->installEventFilter(this);
|
||||
}
|
||||
foreach( QDoubleSpinBox * sp, findChildren<QDoubleSpinBox*>() ) {
|
||||
sp->installEventFilter( this );
|
||||
foreach(QDoubleSpinBox * sp, findChildren<QDoubleSpinBox *>()) {
|
||||
sp->installEventFilter(this);
|
||||
}
|
||||
foreach( QSlider * sp, findChildren<QSlider*>() ) {
|
||||
sp->installEventFilter( this );
|
||||
foreach(QSlider * sp, findChildren<QSlider *>()) {
|
||||
sp->installEventFilter(this);
|
||||
}
|
||||
foreach( QComboBox * sp, findChildren<QComboBox*>() ) {
|
||||
sp->installEventFilter( this );
|
||||
foreach(QComboBox * sp, findChildren<QComboBox *>()) {
|
||||
sp->installEventFilter(this);
|
||||
}
|
||||
|
||||
|
||||
return optionsPageWidget;
|
||||
}
|
||||
|
||||
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 ) ))
|
||||
{
|
||||
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))) {
|
||||
evt->ignore();
|
||||
return true;
|
||||
}
|
||||
return ScopeGadgetOptionsPage::eventFilter( obj, evt );
|
||||
return ScopeGadgetOptionsPage::eventFilter(obj, evt);
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged(int currentIndex){
|
||||
if (currentIndex > 0){
|
||||
void ScopeGadgetOptionsPage::on_mathFunctionComboBox_currentIndexChanged(int currentIndex)
|
||||
{
|
||||
if (currentIndex > 0) {
|
||||
options_page->spnMeanSamples->setEnabled(true);
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
options_page->spnMeanSamples->setEnabled(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::on_btnColor_clicked()
|
||||
{
|
||||
QColor color = QColorDialog::getColor( QColor(options_page->btnColor->text()));
|
||||
if (color.isValid()) {
|
||||
setButtonColor(color);
|
||||
}
|
||||
}
|
||||
{
|
||||
QColor color = QColorDialog::getColor(QColor(options_page->btnColor->text()));
|
||||
|
||||
if (color.isValid()) {
|
||||
setButtonColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Populate the widgets that containts the configs for the Y-Axis from
|
||||
the selected plot curve
|
||||
*/
|
||||
\brief Populate the widgets that containts the configs for the Y-Axis from
|
||||
the selected plot curve
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::setYAxisWidgetFromPlotCurve()
|
||||
{
|
||||
bool parseOK = false;
|
||||
QListWidgetItem* listItem = options_page->lstCurves->currentItem();
|
||||
QListWidgetItem *listItem = options_page->lstCurves->currentItem();
|
||||
|
||||
if(listItem == 0)
|
||||
if (listItem == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
//WHAT IS UserRole DOING?
|
||||
int currentIndex = options_page->cmbUAVObjects->findText( listItem->data(Qt::UserRole + 0).toString());
|
||||
// WHAT IS UserRole DOING?
|
||||
int currentIndex = options_page->cmbUAVObjects->findText(listItem->data(Qt::UserRole + 0).toString());
|
||||
options_page->cmbUAVObjects->setCurrentIndex(currentIndex);
|
||||
|
||||
currentIndex = options_page->cmbUAVField->findText( listItem->data(Qt::UserRole + 1).toString());
|
||||
currentIndex = options_page->cmbUAVField->findText(listItem->data(Qt::UserRole + 1).toString());
|
||||
options_page->cmbUAVField->setCurrentIndex(currentIndex);
|
||||
|
||||
currentIndex = options_page->cmbScale->findData( listItem->data(Qt::UserRole + 2), Qt::UserRole, Qt::MatchExactly);
|
||||
currentIndex = options_page->cmbScale->findData(listItem->data(Qt::UserRole + 2), Qt::UserRole, Qt::MatchExactly);
|
||||
options_page->cmbScale->setCurrentIndex(currentIndex);
|
||||
|
||||
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
||||
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
||||
int rgb = varColor.toInt(&parseOK);
|
||||
|
||||
setButtonColor(QColor((QRgb)rgb));
|
||||
|
||||
int mean = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
|
||||
if(!parseOK) mean = 1;
|
||||
if (!parseOK) {
|
||||
mean = 1;
|
||||
}
|
||||
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->drawAntialiasedCheckBox->setChecked(listItem->data(Qt::UserRole + 6).toBool());
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::setButtonColor(const QColor &color)
|
||||
@ -227,33 +231,32 @@ void ScopeGadgetOptionsPage::setButtonColor(const QColor &color)
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief When a new UAVObject is selected, populate the UAVObject field combo box with the correct values.
|
||||
*/
|
||||
\brief When a new UAVObject is selected, populate the UAVObject field combo box with the correct values.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_cmbUAVObjects_currentIndexChanged(QString val)
|
||||
{
|
||||
options_page->cmbUAVField->clear();
|
||||
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
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.
|
||||
|
||||
QList<UAVObjectField*> fieldList = obj->getFields();
|
||||
foreach (UAVObjectField* field, fieldList) {
|
||||
if(field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM )
|
||||
}
|
||||
QList<UAVObjectField *> fieldList = obj->getFields();
|
||||
foreach(UAVObjectField * field, fieldList) {
|
||||
if (field->getType() == UAVObjectField::STRING || field->getType() == UAVObjectField::ENUM) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(field->getElementNames().count() > 1)
|
||||
{
|
||||
foreach(QString elemName , field->getElementNames())
|
||||
{
|
||||
if (field->getElementNames().count() > 1) {
|
||||
foreach(QString elemName, field->getElementNames()) {
|
||||
options_page->cmbUAVField->addItem(field->getName() + "-" + elemName);
|
||||
}
|
||||
}
|
||||
else
|
||||
} else {
|
||||
options_page->cmbUAVField->addItem(field->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -267,130 +270,131 @@ void ScopeGadgetOptionsPage::apply()
|
||||
{
|
||||
bool parseOK = false;
|
||||
|
||||
//Apply configuration changes
|
||||
// Apply configuration changes
|
||||
m_config->setPlotType(options_page->cmbPlotType->currentIndex());
|
||||
m_config->setMathFunctionType(options_page->mathFunctionComboBox->currentIndex());
|
||||
m_config->setDataSize(options_page->spnDataSize->value());
|
||||
m_config->setRefreashInterval(options_page->spnRefreshInterval->value());
|
||||
|
||||
QList<PlotCurveConfiguration*> plotCurveConfigs;
|
||||
for(int iIndex = 0; iIndex < options_page->lstCurves->count();iIndex++) {
|
||||
QListWidgetItem* listItem = options_page->lstCurves->item(iIndex);
|
||||
QList<PlotCurveConfiguration *> plotCurveConfigs;
|
||||
for (int iIndex = 0; iIndex < options_page->lstCurves->count(); iIndex++) {
|
||||
QListWidgetItem *listItem = options_page->lstCurves->item(iIndex);
|
||||
|
||||
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)
|
||||
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) {
|
||||
newPlotCurveConfigs->yScalePower = 0;
|
||||
}
|
||||
|
||||
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
||||
QVariant varColor = listItem->data(Qt::UserRole + 3);
|
||||
int rgb = varColor.toInt(&parseOK);
|
||||
if(!parseOK)
|
||||
if (!parseOK) {
|
||||
newPlotCurveConfigs->color = QColor(Qt::black).rgb();
|
||||
else
|
||||
} else {
|
||||
newPlotCurveConfigs->color = (QRgb)rgb;
|
||||
}
|
||||
|
||||
newPlotCurveConfigs->yMeanSamples = listItem->data(Qt::UserRole + 4).toInt(&parseOK);
|
||||
if(!parseOK)
|
||||
if (!parseOK) {
|
||||
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);
|
||||
}
|
||||
|
||||
m_config->replacePlotCurveConfig(plotCurveConfigs);
|
||||
|
||||
//save the logging config
|
||||
// save the logging config
|
||||
m_config->setLoggingPath(options_page->LoggingPath->path());
|
||||
m_config->setLoggingNewFileOnConnect(options_page->LoggingConnect->isChecked());
|
||||
m_config->setLoggingEnabled(options_page->LoggingEnable->isChecked());
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
\brief Add a new curve to the plot.
|
||||
*/
|
||||
\brief Add a new curve to the plot.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_btnAddCurve_clicked()
|
||||
{
|
||||
bool parseOK = false;
|
||||
bool parseOK = false;
|
||||
QString uavObject = options_page->cmbUAVObjects->currentText();
|
||||
QString uavField = options_page->cmbUAVField->currentText();
|
||||
QString uavField = options_page->cmbUAVField->currentText();
|
||||
int scale = options_page->cmbScale->itemData(options_page->cmbScale->currentIndex()).toInt(&parseOK);
|
||||
|
||||
if(!parseOK)
|
||||
scale = 0;
|
||||
if (!parseOK) {
|
||||
scale = 0;
|
||||
}
|
||||
|
||||
int mean = options_page->spnMeanSamples->value();
|
||||
QString mathFunction = options_page->mathFunctionComboBox->currentText();
|
||||
|
||||
|
||||
QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
|
||||
QVariant varColor = (int)QColor(options_page->btnColor->text()).rgb();
|
||||
|
||||
//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)
|
||||
{
|
||||
bool antialiased = options_page->drawAntialiasedCheckBox->isChecked();
|
||||
// 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) {
|
||||
QListWidgetItem *listWidgetItem = options_page->lstCurves->currentItem();
|
||||
setCurvePlotProperties(listWidgetItem,uavObject,uavField,scale,mean,mathFunction,varColor);
|
||||
}else
|
||||
{
|
||||
addPlotCurveConfig(uavObject,uavField,scale,mean,mathFunction,varColor);
|
||||
setCurvePlotProperties(listWidgetItem, uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
|
||||
} else {
|
||||
addPlotCurveConfig(uavObject, uavField, scale, mean, mathFunction, varColor, antialiased);
|
||||
|
||||
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
|
||||
QString listItemDisplayText = uavObject + "." + uavField;
|
||||
// Add a new curve config to the list
|
||||
QString listItemDisplayText = uavObject + "." + uavField;
|
||||
|
||||
options_page->lstCurves->addItem(listItemDisplayText);
|
||||
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;
|
||||
|
||||
//Set the properties of the newly added list item
|
||||
QString listItemDisplayText = uavObject + "." + uavField;
|
||||
// Set the properties of the newly added list item
|
||||
QRgb rgbColor = (QRgb)varColor.toInt(&parseOK);
|
||||
QColor color = QColor( rgbColor );
|
||||
//listWidgetItem->setText(listItemDisplayText);
|
||||
listWidgetItem->setTextColor( color );
|
||||
QColor color = QColor(rgbColor);
|
||||
|
||||
//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->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));
|
||||
}
|
||||
|
||||
/*!
|
||||
Remove a curve config from the plot.
|
||||
*/
|
||||
Remove a curve config from the plot.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_btnRemoveCurve_clicked()
|
||||
{
|
||||
options_page->lstCurves->takeItem(options_page->lstCurves->currentIndex().row());
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
void ScopeGadgetOptionsPage::on_lstCurves_currentRowChanged(int currentRow)
|
||||
{
|
||||
Q_UNUSED(currentRow);
|
||||
@ -398,15 +402,15 @@ void ScopeGadgetOptionsPage::on_lstCurves_currentRowChanged(int currentRow)
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::on_loggingEnable_clicked()
|
||||
{
|
||||
{
|
||||
bool en = options_page->LoggingEnable->isChecked();
|
||||
|
||||
options_page->LoggingPath->setEnabled(en);
|
||||
options_page->LoggingConnect->setEnabled(en);
|
||||
options_page->LoggingLabel->setEnabled(en);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ScopeGadgetOptionsPage::on_spnRefreshInterval_valueChanged(int )
|
||||
void ScopeGadgetOptionsPage::on_spnRefreshInterval_valueChanged(int)
|
||||
{
|
||||
validateRefreshInterval();
|
||||
}
|
||||
@ -415,19 +419,19 @@ void ScopeGadgetOptionsPage::validateRefreshInterval()
|
||||
{
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
for(int iIndex = 0; iIndex < options_page->lstCurves->count();iIndex++) {
|
||||
QListWidgetItem* listItem = options_page->lstCurves->item(iIndex);
|
||||
|
||||
QString uavObject = listItem->data(Qt::UserRole + 0).toString();
|
||||
for (int iIndex = 0; iIndex < options_page->lstCurves->count(); iIndex++) {
|
||||
QListWidgetItem *listItem = options_page->lstCurves->item(iIndex);
|
||||
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject((uavObject)));
|
||||
if(!obj) {
|
||||
QString uavObject = listItem->data(Qt::UserRole + 0).toString();
|
||||
|
||||
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject((uavObject)));
|
||||
if (!obj) {
|
||||
qDebug() << "Object " << uavObject << " is missing";
|
||||
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.");
|
||||
return;
|
||||
}
|
||||
@ -435,4 +439,3 @@ void ScopeGadgetOptionsPage::validateRefreshInterval()
|
||||
|
||||
options_page->lblWarnings->setText("");
|
||||
}
|
||||
|
||||
|
@ -38,22 +38,19 @@
|
||||
#include <QDebug>
|
||||
#include <QtGui/QColorDialog>
|
||||
|
||||
namespace Core
|
||||
{
|
||||
namespace Core {
|
||||
class IUAVGadgetConfiguration;
|
||||
}
|
||||
|
||||
class ScopeGadgetConfiguration;
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
namespace Ui {
|
||||
class ScopeGadgetOptionsPage;
|
||||
}
|
||||
|
||||
using namespace Core;
|
||||
|
||||
class ScopeGadgetOptionsPage : public IOptionsPage
|
||||
{
|
||||
class ScopeGadgetOptionsPage : public IOptionsPage {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit ScopeGadgetOptionsPage(ScopeGadgetConfiguration *config, QObject *parent = 0);
|
||||
@ -66,23 +63,23 @@ private:
|
||||
Ui::ScopeGadgetOptionsPage *options_page;
|
||||
ScopeGadgetConfiguration *m_config;
|
||||
|
||||
void addPlotCurveConfig(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);
|
||||
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, bool antialias);
|
||||
void setYAxisWidgetFromPlotCurve();
|
||||
void setButtonColor(const QColor &color);
|
||||
void validateRefreshInterval();
|
||||
bool eventFilter( QObject * obj, QEvent * evt );
|
||||
bool eventFilter(QObject *obj, QEvent *evt);
|
||||
|
||||
private slots:
|
||||
void on_spnRefreshInterval_valueChanged(int );
|
||||
void on_spnRefreshInterval_valueChanged(int);
|
||||
void on_lstCurves_currentRowChanged(int currentRow);
|
||||
void on_btnRemoveCurve_clicked();
|
||||
void on_btnAddCurve_clicked();
|
||||
void on_cmbUAVObjects_currentIndexChanged(QString val);
|
||||
void on_cmbUAVObjects_currentIndexChanged(QString val);
|
||||
void on_btnColor_clicked();
|
||||
void on_mathFunctionComboBox_currentIndexChanged(int currentIndex);
|
||||
void on_loggingEnable_clicked();
|
||||
|
||||
};
|
||||
|
||||
#endif // SCOPEGADGETOPTIONSPAGE_H
|
||||
|
@ -176,38 +176,18 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="mathFunctionLabel">
|
||||
<property name="text">
|
||||
<string>Color:</string>
|
||||
<string>Math function:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<widget class="QPushButton" name="btnColor">
|
||||
<item row="7" column="1">
|
||||
<widget class="QComboBox" name="mathFunctionComboBox">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</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="8" column="0">
|
||||
@ -248,18 +228,51 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="0">
|
||||
<widget class="QLabel" name="mathFunctionLabel">
|
||||
<item row="9" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Math function:</string>
|
||||
<string>Color:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1">
|
||||
<widget class="QComboBox" name="mathFunctionComboBox">
|
||||
<item row="9" column="1">
|
||||
<widget class="QPushButton" name="btnColor">
|
||||
<property name="focusPolicy">
|
||||
<enum>Qt::StrongFocus</enum>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
@ -277,7 +290,7 @@
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>100</height>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</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>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Add
|
||||
Update</string>
|
||||
<string>Add / Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -299,8 +311,7 @@ Update</string>
|
||||
<string>Remove the curve from the scope.</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Remove
|
||||
</string>
|
||||
<string>Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
@ -310,12 +321,12 @@ Update</string>
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Fixed</enum>
|
||||
<enum>QSizePolicy::Expanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>15</height>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@ -331,8 +342,8 @@ Update</string>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>200</height>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
@ -347,6 +358,19 @@ Update</string>
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
|
@ -53,16 +53,16 @@
|
||||
#include <QMutexLocker>
|
||||
#include <QWheelEvent>
|
||||
|
||||
//using namespace Core;
|
||||
// using namespace Core;
|
||||
|
||||
// ******************************************************************
|
||||
|
||||
ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
||||
{
|
||||
setMouseTracking(true);
|
||||
// canvas()->setMouseTracking(true);
|
||||
setMouseTracking(true);
|
||||
// canvas()->setMouseTracking(true);
|
||||
|
||||
//Setup the timer that replots data
|
||||
// Setup the timer that replots data
|
||||
replotTimer = new QTimer(this);
|
||||
connect(replotTimer, SIGNAL(timeout()), this, SLOT(replotNewData()));
|
||||
|
||||
@ -71,179 +71,191 @@ ScopeGadgetWidget::ScopeGadgetWidget(QWidget *parent) : QwtPlot(parent)
|
||||
// Also listen to disconnect actions from the user
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(stopPlotting()));
|
||||
connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(startPlotting()));
|
||||
connect(cm, SIGNAL(deviceConnected(QIODevice *)), this, SLOT(startPlotting()));
|
||||
|
||||
m_csvLoggingStarted=0;
|
||||
m_csvLoggingEnabled=0;
|
||||
m_csvLoggingHeaderSaved=0;
|
||||
m_csvLoggingDataSaved=0;
|
||||
m_csvLoggingDataUpdated=0;
|
||||
m_csvLoggingNameSet=0;
|
||||
m_csvLoggingConnected=0;
|
||||
m_csvLoggingNewFileOnConnect=0;
|
||||
m_csvLoggingStarted = 0;
|
||||
m_csvLoggingEnabled = 0;
|
||||
m_csvLoggingHeaderSaved = 0;
|
||||
m_csvLoggingDataSaved = 0;
|
||||
m_csvLoggingDataUpdated = 0;
|
||||
m_csvLoggingNameSet = 0;
|
||||
m_csvLoggingConnected = 0;
|
||||
m_csvLoggingNewFileOnConnect = 0;
|
||||
m_csvLoggingPath = QString("./csvlogging/");
|
||||
m_csvLoggingStartTime = QDateTime::currentDateTime();
|
||||
m_csvLoggingStartTime = QDateTime::currentDateTime();
|
||||
|
||||
//Listen to autopilot connection events
|
||||
// Listen to autopilot connection events
|
||||
connect(cm, SIGNAL(deviceAboutToDisconnect()), this, SLOT(csvLoggingDisconnect()));
|
||||
connect(cm, SIGNAL(deviceConnected(QIODevice*)), this, SLOT(csvLoggingConnect()));
|
||||
connect(cm, SIGNAL(deviceConnected(QIODevice *)), this, SLOT(csvLoggingConnect()));
|
||||
}
|
||||
|
||||
ScopeGadgetWidget::~ScopeGadgetWidget()
|
||||
{
|
||||
if (replotTimer)
|
||||
{
|
||||
replotTimer->stop();
|
||||
if (replotTimer) {
|
||||
replotTimer->stop();
|
||||
|
||||
delete replotTimer;
|
||||
replotTimer = NULL;
|
||||
}
|
||||
delete replotTimer;
|
||||
replotTimer = NULL;
|
||||
}
|
||||
|
||||
// Get the object to de-monitor
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
foreach (QString uavObjName, m_connectedUAVObjects)
|
||||
{
|
||||
UAVDataObject *obj = dynamic_cast<UAVDataObject*>(objManager->getObject(uavObjName));
|
||||
disconnect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*)));
|
||||
}
|
||||
// Get the object to de-monitor
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
foreach(QString uavObjName, m_connectedUAVObjects) {
|
||||
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject(uavObjName));
|
||||
|
||||
clearCurvePlots();
|
||||
disconnect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *)));
|
||||
}
|
||||
|
||||
clearCurvePlots();
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
|
||||
void ScopeGadgetWidget::mousePressEvent(QMouseEvent *e)
|
||||
{
|
||||
QwtPlot::mousePressEvent(e);
|
||||
QwtPlot::mousePressEvent(e);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::mouseReleaseEvent(QMouseEvent *e)
|
||||
{
|
||||
QwtPlot::mouseReleaseEvent(e);
|
||||
QwtPlot::mouseReleaseEvent(e);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::mouseDoubleClickEvent(QMouseEvent *e)
|
||||
{
|
||||
//On double-click, toggle legend
|
||||
// On double-click, toggle legend
|
||||
mutex.lock();
|
||||
if (legend())
|
||||
if (legend()) {
|
||||
deleteLegend();
|
||||
else
|
||||
} else {
|
||||
addLegend();
|
||||
}
|
||||
mutex.unlock();
|
||||
|
||||
//On double-click, reset plot zoom
|
||||
// On double-click, reset plot zoom
|
||||
setAxisAutoScale(QwtPlot::yLeft, true);
|
||||
|
||||
update();
|
||||
|
||||
QwtPlot::mouseDoubleClickEvent(e);
|
||||
QwtPlot::mouseDoubleClickEvent(e);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
{
|
||||
QwtPlot::mouseMoveEvent(e);
|
||||
QwtPlot::mouseMoveEvent(e);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
//Change zoom on scroll wheel event
|
||||
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)
|
||||
{
|
||||
//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
|
||||
//does *not*. Thus, when zooming with a legend, there will always be a small bias error.
|
||||
//In practice, this seems not to be a UI problem.
|
||||
QPoint mouse_pos=e->pos(); //Get the mouse coordinate in the frame
|
||||
double zoomLine=invTransform(QwtPlot::yLeft, mouse_pos.y()); //Transform the y mouse coordinate into a frame value.
|
||||
// Change zoom on scroll wheel event
|
||||
QwtInterval yInterval = axisInterval(QwtPlot::yLeft);
|
||||
|
||||
double zoomScale=1.1; //THIS IS AN ARBITRARY CONSTANT, AND PERHAPS SHOULD BE IN A DEFINE INSTEAD OF BURIED HERE
|
||||
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
|
||||
// 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.
|
||||
// In practice, this seems not to be a UI problem.
|
||||
QPoint mouse_pos = e->pos(); // Get the mouse coordinate in the frame
|
||||
double zoomLine = invTransform(QwtPlot::yLeft, mouse_pos.y()); // Transform the y mouse coordinate into a frame value.
|
||||
|
||||
mutex.lock(); //DOES THIS mutex.lock NEED TO BE HERE? I DON'T KNOW, I JUST COPIED IT FROM THE ABOVE CODE
|
||||
double zoomScale = 1.1; // THIS IS AN ARBITRARY CONSTANT, AND PERHAPS SHOULD BE IN A DEFINE INSTEAD OF BURIED HERE
|
||||
|
||||
mutex.lock(); // DOES THIS mutex.lock NEED TO BE HERE? I DON'T KNOW, I JUST COPIED IT FROM THE ABOVE CODE
|
||||
// Set the scale
|
||||
if (e->delta()<0){
|
||||
if (e->delta() < 0) {
|
||||
setAxisScale(QwtPlot::yLeft,
|
||||
(yInterval.minValue()-zoomLine)*zoomScale+zoomLine,
|
||||
(yInterval.maxValue()-zoomLine)*zoomScale+zoomLine );
|
||||
}
|
||||
else{
|
||||
(yInterval.minValue() - zoomLine) * zoomScale + zoomLine,
|
||||
(yInterval.maxValue() - zoomLine) * zoomScale + zoomLine);
|
||||
} else {
|
||||
setAxisScale(QwtPlot::yLeft,
|
||||
(yInterval.minValue()-zoomLine)/zoomScale+zoomLine,
|
||||
(yInterval.maxValue()-zoomLine)/zoomScale+zoomLine );
|
||||
(yInterval.minValue() - zoomLine) / zoomScale + zoomLine,
|
||||
(yInterval.maxValue() - zoomLine) / zoomScale + zoomLine);
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
QwtPlot::wheelEvent(e);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::showEvent(QShowEvent *e)
|
||||
{
|
||||
replotNewData();
|
||||
QwtPlot::showEvent(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts/stops telemetry
|
||||
*/
|
||||
void ScopeGadgetWidget::startPlotting()
|
||||
{
|
||||
if (!replotTimer)
|
||||
return;
|
||||
if (!replotTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!replotTimer->isActive())
|
||||
if (!replotTimer->isActive()) {
|
||||
replotTimer->start(m_refreshInterval);
|
||||
}
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::stopPlotting()
|
||||
{
|
||||
if (!replotTimer)
|
||||
return;
|
||||
if (!replotTimer) {
|
||||
return;
|
||||
}
|
||||
|
||||
replotTimer->stop();
|
||||
replotTimer->stop();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::deleteLegend()
|
||||
{
|
||||
if (!legend())
|
||||
return;
|
||||
if (!legend()) {
|
||||
return;
|
||||
}
|
||||
|
||||
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
|
||||
disconnect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, 0);
|
||||
|
||||
insertLegend(NULL, QwtPlot::TopLegend);
|
||||
// insertLegend(NULL, QwtPlot::ExternalLegend);
|
||||
insertLegend(NULL, QwtPlot::TopLegend);
|
||||
// insertLegend(NULL, QwtPlot::ExternalLegend);
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::addLegend()
|
||||
{
|
||||
if (legend())
|
||||
return;
|
||||
if (legend()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Show a legend at the top
|
||||
QwtLegend *legend = new QwtLegend();
|
||||
legend->setItemMode(QwtLegend::CheckableItem);
|
||||
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
||||
legend->setToolTip(tr("Click legend to show/hide scope trace"));
|
||||
// Show a legend at the top
|
||||
QwtLegend *legend = new QwtLegend();
|
||||
legend->setItemMode(QwtLegend::CheckableItem);
|
||||
legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
||||
legend->setToolTip(tr("Click legend to show/hide scope trace"));
|
||||
|
||||
QPalette pal = legend->palette();
|
||||
pal.setColor(legend->backgroundRole(), QColor(100, 100, 100)); // background colour
|
||||
// pal.setColor(legend->backgroundRole(), Qt::transparent); // background colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
pal.setColor(QPalette::Text, QColor(0, 0, 0)); // text colour
|
||||
legend->setPalette(pal);
|
||||
QPalette pal = legend->palette();
|
||||
pal.setColor(legend->backgroundRole(), QColor(100, 100, 100)); // background colour
|
||||
// pal.setColor(legend->backgroundRole(), Qt::transparent); // background colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
pal.setColor(QPalette::Text, QColor(0, 0, 0)); // text colour
|
||||
legend->setPalette(pal);
|
||||
|
||||
insertLegend(legend, QwtPlot::TopLegend);
|
||||
// insertLegend(legend, QwtPlot::ExternalLegend);
|
||||
insertLegend(legend, QwtPlot::TopLegend);
|
||||
// insertLegend(legend, QwtPlot::ExternalLegend);
|
||||
|
||||
// // Show a legend at the bottom
|
||||
// QwtLegend *legend = new QwtLegend();
|
||||
// legend->setItemMode(QwtLegend::CheckableItem);
|
||||
// legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
||||
// insertLegend(legend, QwtPlot::BottomLegend);
|
||||
//// Show a legend at the bottom
|
||||
// QwtLegend *legend = new QwtLegend();
|
||||
// legend->setItemMode(QwtLegend::CheckableItem);
|
||||
// legend->setFrameStyle(QFrame::Box | QFrame::Sunken);
|
||||
// insertLegend(legend, QwtPlot::BottomLegend);
|
||||
|
||||
// Update the checked/unchecked state of the legend items
|
||||
// -> this is necessary when hiding a legend where some plots are
|
||||
// not visible, and the un-hiding it.
|
||||
foreach (QwtPlotItem *item, this->itemList()) {
|
||||
bool on = item->isVisible();
|
||||
// not visible, and the un-hiding it.
|
||||
foreach(QwtPlotItem * item, this->itemList()) {
|
||||
bool on = item->isVisible();
|
||||
QWidget *w = legend->find(item);
|
||||
if ( w && w->inherits("QwtLegendItem") )
|
||||
|
||||
if (w && w->inherits("QwtLegendItem")) {
|
||||
((QwtLegendItem *)w)->setChecked(!on);
|
||||
}
|
||||
}
|
||||
|
||||
connect(this, SIGNAL(legendChecked(QwtPlotItem *, bool)), this, SLOT(showCurve(QwtPlotItem *, bool)));
|
||||
@ -258,18 +270,18 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
||||
setMinimumSize(64, 64);
|
||||
setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding);
|
||||
|
||||
// setMargin(1);
|
||||
// setMargin(1);
|
||||
|
||||
// QPalette pal = palette();
|
||||
// QPalette::ColorRole cr = backgroundRole();
|
||||
// pal.setColor(cr, QColor(128, 128, 128)); // background colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
// setPalette(pal);
|
||||
// QPalette pal = palette();
|
||||
// QPalette::ColorRole cr = backgroundRole();
|
||||
// pal.setColor(cr, QColor(128, 128, 128)); // background colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
// setPalette(pal);
|
||||
|
||||
// setCanvasBackground(Utils::StyleHelper::baseColor());
|
||||
// setCanvasBackground(Utils::StyleHelper::baseColor());
|
||||
setCanvasBackground(QColor(64, 64, 64));
|
||||
|
||||
//Add grid lines
|
||||
// Add grid lines
|
||||
QwtPlotGrid *grid = new QwtPlotGrid;
|
||||
grid->setMajPen(QPen(Qt::gray, 0, Qt::DashLine));
|
||||
grid->setMinPen(QPen(Qt::lightGray, 0, Qt::DotLine));
|
||||
@ -281,12 +293,12 @@ void ScopeGadgetWidget::preparePlot(PlotType plotType)
|
||||
|
||||
// Only start the timer if we are already connected
|
||||
Core::ConnectionManager *cm = Core::ICore::instance()->connectionManager();
|
||||
if (cm->getCurrentConnection() && replotTimer)
|
||||
{
|
||||
if (!replotTimer->isActive())
|
||||
if (cm->getCurrentConnection() && replotTimer) {
|
||||
if (!replotTimer->isActive()) {
|
||||
replotTimer->start(m_refreshInterval);
|
||||
else
|
||||
} else {
|
||||
replotTimer->setInterval(m_refreshInterval);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,22 +306,23 @@ void ScopeGadgetWidget::showCurve(QwtPlotItem *item, bool on)
|
||||
{
|
||||
item->setVisible(!on);
|
||||
QWidget *w = legend()->find(item);
|
||||
if ( w && w->inherits("QwtLegendItem") )
|
||||
if (w && w->inherits("QwtLegendItem")) {
|
||||
((QwtLegendItem *)w)->setChecked(on);
|
||||
}
|
||||
|
||||
mutex.lock();
|
||||
replot();
|
||||
mutex.unlock();
|
||||
mutex.lock();
|
||||
replot();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::setupSequentialPlot()
|
||||
{
|
||||
preparePlot(SequentialPlot);
|
||||
|
||||
// QwtText title("Index");
|
||||
// QwtText title("Index");
|
||||
//// title.setFont(QFont("Helvetica", 20));
|
||||
// title.font().setPointSize(title.font().pointSize() / 2);
|
||||
// setAxisTitle(QwtPlot::xBottom, title);
|
||||
// title.font().setPointSize(title.font().pointSize() / 2);
|
||||
// setAxisTitle(QwtPlot::xBottom, title);
|
||||
//// setAxisTitle(QwtPlot::xBottom, "Index");
|
||||
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new QwtScaleDraw());
|
||||
@ -317,175 +330,187 @@ void ScopeGadgetWidget::setupSequentialPlot()
|
||||
setAxisLabelRotation(QwtPlot::xBottom, 0.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
|
||||
// reduce the gap between the scope canvas and the axis scale
|
||||
scaleWidget->setMargin(0);
|
||||
// reduce the gap between the scope canvas and the axis scale
|
||||
scaleWidget->setMargin(0);
|
||||
|
||||
// reduce the axis font size
|
||||
QFont fnt(axisFont(QwtPlot::xBottom));
|
||||
fnt.setPointSize(7);
|
||||
setAxisFont(QwtPlot::xBottom, fnt); // x-axis
|
||||
setAxisFont(QwtPlot::yLeft, fnt); // y-axis
|
||||
// reduce the axis font size
|
||||
QFont fnt(axisFont(QwtPlot::xBottom));
|
||||
fnt.setPointSize(7);
|
||||
setAxisFont(QwtPlot::xBottom, fnt); // x-axis
|
||||
setAxisFont(QwtPlot::yLeft, fnt); // y-axis
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::setupChronoPlot()
|
||||
{
|
||||
preparePlot(ChronoPlot);
|
||||
|
||||
// QwtText title("Time [h:m:s]");
|
||||
// QwtText title("Time [h:m:s]");
|
||||
//// title.setFont(QFont("Helvetica", 20));
|
||||
// title.font().setPointSize(title.font().pointSize() / 2);
|
||||
// setAxisTitle(QwtPlot::xBottom, title);
|
||||
// title.font().setPointSize(title.font().pointSize() / 2);
|
||||
// setAxisTitle(QwtPlot::xBottom, title);
|
||||
//// setAxisTitle(QwtPlot::xBottom, "Time [h:m:s]");
|
||||
|
||||
setAxisScaleDraw(QwtPlot::xBottom, new TimeScaleDraw());
|
||||
uint NOW = QDateTime::currentDateTime().toTime_t();
|
||||
setAxisScale(QwtPlot::xBottom, NOW - m_xWindowSize / 1000, NOW);
|
||||
// setAxisLabelRotation(QwtPlot::xBottom, -15.0);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, 0.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
// setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignCenter | Qt::AlignBottom);
|
||||
// setAxisLabelRotation(QwtPlot::xBottom, -15.0);
|
||||
setAxisLabelRotation(QwtPlot::xBottom, 0.0);
|
||||
setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignLeft | Qt::AlignBottom);
|
||||
// setAxisLabelAlignment(QwtPlot::xBottom, Qt::AlignCenter | Qt::AlignBottom);
|
||||
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
// QwtScaleDraw *scaleDraw = axisScaleDraw();
|
||||
QwtScaleWidget *scaleWidget = axisWidget(QwtPlot::xBottom);
|
||||
// QwtScaleDraw *scaleDraw = axisScaleDraw();
|
||||
|
||||
// reduce the gap between the scope canvas and the axis scale
|
||||
scaleWidget->setMargin(0);
|
||||
// reduce the gap between the scope canvas and the axis scale
|
||||
scaleWidget->setMargin(0);
|
||||
|
||||
// reduce the axis font size
|
||||
QFont fnt(axisFont(QwtPlot::xBottom));
|
||||
fnt.setPointSize(7);
|
||||
setAxisFont(QwtPlot::xBottom, fnt); // x-axis
|
||||
setAxisFont(QwtPlot::yLeft, fnt); // y-axis
|
||||
// reduce the axis font size
|
||||
QFont fnt(axisFont(QwtPlot::xBottom));
|
||||
fnt.setPointSize(7);
|
||||
setAxisFont(QwtPlot::xBottom, fnt); // x-axis
|
||||
setAxisFont(QwtPlot::yLeft, fnt); // y-axis
|
||||
|
||||
// set the axis colours .. can't seem to change the background colour :(
|
||||
// QPalette pal = scaleWidget->palette();
|
||||
// QPalette::ColorRole cr = scaleWidget->backgroundRole();
|
||||
// pal.setColor(cr, QColor(128, 128, 128)); // background colour
|
||||
// cr = scaleWidget->foregroundRole();
|
||||
// pal.setColor(cr, QColor(255, 255, 255)); // tick colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
// scaleWidget->setPalette(pal);
|
||||
// set the axis colours .. can't seem to change the background colour :(
|
||||
// QPalette pal = scaleWidget->palette();
|
||||
// QPalette::ColorRole cr = scaleWidget->backgroundRole();
|
||||
// pal.setColor(cr, QColor(128, 128, 128)); // background colour
|
||||
// cr = scaleWidget->foregroundRole();
|
||||
// pal.setColor(cr, QColor(255, 255, 255)); // tick colour
|
||||
// pal.setColor(QPalette::Text, QColor(255, 255, 255)); // text colour
|
||||
// scaleWidget->setPalette(pal);
|
||||
|
||||
/*
|
||||
In situations, when there is a label at the most right position of the
|
||||
scale, additional space is needed to display the overlapping part
|
||||
of the label would be taken by reducing the width of scale and canvas.
|
||||
To avoid this "jumping canvas" effect, we add a permanent margin.
|
||||
We don't need to do the same for the left border, because there
|
||||
is enough space for the overlapping label below the left scale.
|
||||
In situations, when there is a label at the most right position of the
|
||||
scale, additional space is needed to display the overlapping part
|
||||
of the label would be taken by reducing the width of scale and canvas.
|
||||
To avoid this "jumping canvas" effect, we add a permanent margin.
|
||||
We don't need to do the same for the left border, because there
|
||||
is enough space for the overlapping label below the left scale.
|
||||
*/
|
||||
|
||||
// const int fmh = QFontMetrics(scaleWidget->font()).height();
|
||||
// scaleWidget->setMinBorderDist(0, fmh / 2);
|
||||
// const int fmh = QFontMetrics(scaleWidget->font()).height();
|
||||
// scaleWidget->setMinBorderDist(0, fmh / 2);
|
||||
|
||||
// const int fmw = QFontMetrics(scaleWidget->font()).width(" 00:00:00 ");
|
||||
// const int fmw = QFontMetrics(scaleWidget->font()).width(" ");
|
||||
// scaleWidget->setMinBorderDist(0, fmw);
|
||||
// const int fmw = QFontMetrics(scaleWidget->font()).width(" 00:00:00 ");
|
||||
// const int fmw = QFontMetrics(scaleWidget->font()).width(" ");
|
||||
// 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);
|
||||
else if (m_plotType == ChronoPlot)
|
||||
} else if (m_plotType == ChronoPlot) {
|
||||
plotData = new ChronoPlotData(uavObject, uavFieldSubField);
|
||||
//else if (m_plotType == UAVObjectPlot)
|
||||
// plotData = new UAVObjectPlotData(uavObject, uavField);
|
||||
}
|
||||
// else if (m_plotType == UAVObjectPlot)
|
||||
// plotData = new UAVObjectPlotData(uavObject, uavField);
|
||||
|
||||
plotData->m_xWindowSize = m_xWindowSize;
|
||||
plotData->scalePower = scaleOrderFactor;
|
||||
plotData->meanSamples = meanSamples;
|
||||
plotData->mathFunction = mathFunction;
|
||||
plotData->scalePower = scaleOrderFactor;
|
||||
plotData->meanSamples = meanSamples;
|
||||
plotData->mathFunction = mathFunction;
|
||||
|
||||
//If the y-bounds are supplied, set them
|
||||
if (plotData->yMinimum != plotData->yMaximum)
|
||||
{
|
||||
setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum);
|
||||
}
|
||||
// If the y-bounds are supplied, set them
|
||||
if (plotData->yMinimum != plotData->yMaximum) {
|
||||
setAxisScale(QwtPlot::yLeft, plotData->yMinimum, plotData->yMaximum);
|
||||
}
|
||||
|
||||
//Create the curve
|
||||
// Create the curve
|
||||
QString curveName = (plotData->uavObject) + "." + (plotData->uavField);
|
||||
if(plotData->haveSubField)
|
||||
if (plotData->haveSubField) {
|
||||
curveName = curveName.append("." + plotData->uavSubField);
|
||||
}
|
||||
|
||||
//Get the uav object
|
||||
// Get the uav object
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
UAVDataObject* obj = dynamic_cast<UAVDataObject*>(objManager->getObject((plotData->uavObject)));
|
||||
if(!obj) {
|
||||
UAVDataObject *obj = dynamic_cast<UAVDataObject *>(objManager->getObject((plotData->uavObject)));
|
||||
if (!obj) {
|
||||
qDebug() << "Object " << plotData->uavObject << " is missing";
|
||||
return;
|
||||
}
|
||||
UAVObjectField* field = obj->getField(plotData->uavField);
|
||||
if(!field) {
|
||||
UAVObjectField *field = obj->getField(plotData->uavField);
|
||||
if (!field) {
|
||||
qDebug() << "In scope gadget, in fields loaded from GCS config file, field" << plotData->uavField << " of object " << plotData->uavObject << " is missing";
|
||||
return;
|
||||
}
|
||||
QString units = field->getUnits();
|
||||
|
||||
if(units == 0)
|
||||
if (units == 0) {
|
||||
units = QString();
|
||||
}
|
||||
|
||||
QString curveNameScaled;
|
||||
if(scaleOrderFactor == 0)
|
||||
if (scaleOrderFactor == 0) {
|
||||
curveNameScaled = curveName + " (" + units + ")";
|
||||
else
|
||||
} else {
|
||||
curveNameScaled = curveName + " (x10^" + QString::number(scaleOrderFactor) + " " + units + ")";
|
||||
}
|
||||
|
||||
QwtPlotCurve *plotCurve = new QwtPlotCurve(curveNameScaled);
|
||||
|
||||
if (antialiased) {
|
||||
plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
|
||||
}
|
||||
|
||||
QwtPlotCurve* plotCurve = new QwtPlotCurve(curveNameScaled);
|
||||
plotCurve->setPen(pen);
|
||||
plotCurve->setSamples(*plotData->xData, *plotData->yData);
|
||||
plotCurve->attach(this);
|
||||
plotData->curve = plotCurve;
|
||||
|
||||
//Keep the curve details for later
|
||||
// Keep the curve details for later
|
||||
m_curvesData.insert(curveNameScaled, plotData);
|
||||
|
||||
//Link to the new signal data only if this UAVObject has not been connected yet
|
||||
// Link to the new signal data only if this UAVObject has not been connected yet
|
||||
if (!m_connectedUAVObjects.contains(obj->getName())) {
|
||||
m_connectedUAVObjects.append(obj->getName());
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject*)), this, SLOT(uavObjectReceived(UAVObject*)));
|
||||
connect(obj, SIGNAL(objectUpdated(UAVObject *)), this, SLOT(uavObjectReceived(UAVObject *)));
|
||||
}
|
||||
|
||||
mutex.lock();
|
||||
replot();
|
||||
mutex.unlock();
|
||||
mutex.lock();
|
||||
replot();
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
//void ScopeGadgetWidget::removeCurvePlot(QString uavObject, QString uavField)
|
||||
//{
|
||||
// QString curveName = uavObject + "." + uavField;
|
||||
// void ScopeGadgetWidget::removeCurvePlot(QString uavObject, QString uavField)
|
||||
// {
|
||||
// QString curveName = uavObject + "." + uavField;
|
||||
//
|
||||
// PlotData* plotData = m_curvesData.take(curveName);
|
||||
// m_curvesData.remove(curveName);
|
||||
// plotData->curve->detach();
|
||||
// PlotData* plotData = m_curvesData.take(curveName);
|
||||
// m_curvesData.remove(curveName);
|
||||
// plotData->curve->detach();
|
||||
//
|
||||
// delete plotData->curve;
|
||||
// delete plotData;
|
||||
// delete plotData->curve;
|
||||
// delete plotData;
|
||||
//
|
||||
// mutex.lock();
|
||||
// replot();
|
||||
// mutex.unlock();
|
||||
//}
|
||||
// mutex.lock();
|
||||
// replot();
|
||||
// mutex.unlock();
|
||||
// }
|
||||
|
||||
void ScopeGadgetWidget::uavObjectReceived(UAVObject* obj)
|
||||
void ScopeGadgetWidget::uavObjectReceived(UAVObject *obj)
|
||||
{
|
||||
foreach(PlotData* plotData, m_curvesData.values()) {
|
||||
if (plotData->append(obj)) m_csvLoggingDataUpdated=1;
|
||||
foreach(PlotData * plotData, m_curvesData.values()) {
|
||||
if (plotData->append(obj)) {
|
||||
m_csvLoggingDataUpdated = 1;
|
||||
}
|
||||
}
|
||||
csvLoggingAddData();
|
||||
}
|
||||
|
||||
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->curve->setSamples(*plotData->xData, *plotData->yData);
|
||||
}
|
||||
@ -493,66 +518,20 @@ void ScopeGadgetWidget::replotNewData()
|
||||
QDateTime NOW = QDateTime::currentDateTime();
|
||||
double toTime = NOW.toTime_t();
|
||||
toTime += NOW.time().msec() / 1000.0;
|
||||
if (m_plotType == ChronoPlot)
|
||||
if (m_plotType == ChronoPlot) {
|
||||
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;
|
||||
|
||||
csvLoggingInsertData();
|
||||
|
||||
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()
|
||||
{
|
||||
foreach(PlotData* plotData, m_curvesData.values()) {
|
||||
foreach(PlotData * plotData, m_curvesData.values()) {
|
||||
plotData->curve->detach();
|
||||
|
||||
delete plotData->curve;
|
||||
@ -564,49 +543,42 @@ void ScopeGadgetWidget::clearCurvePlots()
|
||||
|
||||
|
||||
/*
|
||||
int csvLoggingEnable;
|
||||
int csvLoggingHeaderSaved;
|
||||
int csvLoggingDataSaved;
|
||||
QString csvLoggingPath;
|
||||
QFile csvLoggingFile;
|
||||
*/
|
||||
int csvLoggingEnable;
|
||||
int csvLoggingHeaderSaved;
|
||||
int csvLoggingDataSaved;
|
||||
QString csvLoggingPath;
|
||||
QFile csvLoggingFile;
|
||||
*/
|
||||
int ScopeGadgetWidget::csvLoggingStart()
|
||||
{
|
||||
if (!m_csvLoggingStarted)
|
||||
if (m_csvLoggingEnabled)
|
||||
if ((!m_csvLoggingNewFileOnConnect)||(m_csvLoggingNewFileOnConnect && m_csvLoggingConnected))
|
||||
{
|
||||
QDateTime NOW = QDateTime::currentDateTime();
|
||||
m_csvLoggingStartTime = NOW;
|
||||
m_csvLoggingHeaderSaved=0;
|
||||
m_csvLoggingDataSaved=0;
|
||||
m_csvLoggingBuffer.clear();
|
||||
QDir PathCheck(m_csvLoggingPath);
|
||||
if (!PathCheck.exists())
|
||||
{
|
||||
PathCheck.mkpath("./");
|
||||
}
|
||||
if (!m_csvLoggingStarted) {
|
||||
if (m_csvLoggingEnabled) {
|
||||
if ((!m_csvLoggingNewFileOnConnect) || (m_csvLoggingNewFileOnConnect && m_csvLoggingConnected)) {
|
||||
QDateTime NOW = QDateTime::currentDateTime();
|
||||
m_csvLoggingStartTime = NOW;
|
||||
m_csvLoggingHeaderSaved = 0;
|
||||
m_csvLoggingDataSaved = 0;
|
||||
m_csvLoggingBuffer.clear();
|
||||
QDir PathCheck(m_csvLoggingPath);
|
||||
if (!PathCheck.exists()) {
|
||||
PathCheck.mkpath("./");
|
||||
}
|
||||
|
||||
|
||||
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")));
|
||||
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")));
|
||||
} 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")));
|
||||
}
|
||||
QDir FileCheck(m_csvLoggingFile.fileName());
|
||||
if (FileCheck.exists()) {
|
||||
m_csvLoggingFile.setFileName("");
|
||||
} else {
|
||||
m_csvLoggingStarted = 1;
|
||||
csvLoggingInsertHeader();
|
||||
}
|
||||
}
|
||||
}
|
||||
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")));
|
||||
}
|
||||
QDir FileCheck(m_csvLoggingFile.fileName());
|
||||
if (FileCheck.exists())
|
||||
{
|
||||
m_csvLoggingFile.setFileName("");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_csvLoggingStarted=1;
|
||||
csvLoggingInsertHeader();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -614,33 +586,37 @@ int ScopeGadgetWidget::csvLoggingStart()
|
||||
|
||||
int ScopeGadgetWidget::csvLoggingStop()
|
||||
{
|
||||
m_csvLoggingStarted=0;
|
||||
m_csvLoggingStarted = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ScopeGadgetWidget::csvLoggingInsertHeader()
|
||||
{
|
||||
if (!m_csvLoggingStarted) return -1;
|
||||
if (m_csvLoggingHeaderSaved) return -2;
|
||||
if (m_csvLoggingDataSaved) return -3;
|
||||
|
||||
m_csvLoggingHeaderSaved=1;
|
||||
if(m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append)== FALSE)
|
||||
{
|
||||
qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Header";
|
||||
if (!m_csvLoggingStarted) {
|
||||
return -1;
|
||||
}
|
||||
if (m_csvLoggingHeaderSaved) {
|
||||
return -2;
|
||||
}
|
||||
if (m_csvLoggingDataSaved) {
|
||||
return -3;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream ts( &m_csvLoggingFile );
|
||||
ts << "date" << ", " << "Time"<< ", " << "Sec since start"<< ", " << "Connected" << ", " << "Data changed";
|
||||
|
||||
foreach(PlotData* plotData2, m_curvesData.values())
|
||||
{
|
||||
ts << ", ";
|
||||
ts << plotData2->uavObject;
|
||||
ts << "." << plotData2->uavField;
|
||||
if (plotData2->haveSubField) ts << "." << plotData2->uavSubField;
|
||||
m_csvLoggingHeaderSaved = 1;
|
||||
if (m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append) == FALSE) {
|
||||
qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Header";
|
||||
} else {
|
||||
QTextStream ts(&m_csvLoggingFile);
|
||||
ts << "date" << ", " << "Time" << ", " << "Sec since start" << ", " << "Connected" << ", " << "Data changed";
|
||||
|
||||
foreach(PlotData * plotData2, m_curvesData.values()) {
|
||||
ts << ", ";
|
||||
ts << plotData2->uavObject;
|
||||
ts << "." << plotData2->uavField;
|
||||
if (plotData2->haveSubField) {
|
||||
ts << "." << plotData2->uavSubField;
|
||||
}
|
||||
}
|
||||
ts << endl;
|
||||
m_csvLoggingFile.close();
|
||||
@ -650,47 +626,40 @@ int ScopeGadgetWidget::csvLoggingInsertHeader()
|
||||
|
||||
int ScopeGadgetWidget::csvLoggingAddData()
|
||||
{
|
||||
if (!m_csvLoggingStarted) return -1;
|
||||
m_csvLoggingDataValid=0;
|
||||
if (!m_csvLoggingStarted) {
|
||||
return -1;
|
||||
}
|
||||
m_csvLoggingDataValid = 0;
|
||||
QDateTime NOW = QDateTime::currentDateTime();
|
||||
QString tempString;
|
||||
|
||||
QTextStream ss( &tempString );
|
||||
ss << NOW.toString("yyyy-MM-dd") << ", " << NOW.toString("hh:mm:ss.z") << ", " ;
|
||||
QTextStream ss(&tempString);
|
||||
ss << NOW.toString("yyyy-MM-dd") << ", " << NOW.toString("hh:mm:ss.z") << ", ";
|
||||
|
||||
#if QT_VERSION >= 0x040700
|
||||
ss <<(NOW.toMSecsSinceEpoch() - m_csvLoggingStartTime.toMSecsSinceEpoch())/1000.00;
|
||||
ss << (NOW.toMSecsSinceEpoch() - m_csvLoggingStartTime.toMSecsSinceEpoch()) / 1000.00;
|
||||
#else
|
||||
ss <<(NOW.toTime_t() - m_csvLoggingStartTime.toTime_t());
|
||||
ss << (NOW.toTime_t() - m_csvLoggingStartTime.toTime_t());
|
||||
#endif
|
||||
ss << ", " << m_csvLoggingConnected << ", " << m_csvLoggingDataUpdated;
|
||||
m_csvLoggingDataUpdated=0;
|
||||
m_csvLoggingDataUpdated = 0;
|
||||
|
||||
foreach(PlotData* plotData2, m_curvesData.values())
|
||||
{
|
||||
ss << ", ";
|
||||
if (plotData2->xData->isEmpty ())
|
||||
{
|
||||
ss << ", ";
|
||||
if (plotData2->xData->isEmpty ())
|
||||
{
|
||||
foreach(PlotData * plotData2, m_curvesData.values()) {
|
||||
ss << ", ";
|
||||
if (plotData2->xData->isEmpty()) {
|
||||
ss << ", ";
|
||||
if (plotData2->xData->isEmpty()) {} else {
|
||||
ss << QString().sprintf("%3.10g", plotData2->yData->last());
|
||||
m_csvLoggingDataValid = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << QString().sprintf("%3.10g",plotData2->yData->last());
|
||||
m_csvLoggingDataValid=1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << QString().sprintf("%3.10g",plotData2->yData->last());
|
||||
m_csvLoggingDataValid=1;
|
||||
} else {
|
||||
ss << QString().sprintf("%3.10g", plotData2->yData->last());
|
||||
m_csvLoggingDataValid = 1;
|
||||
}
|
||||
}
|
||||
ss << endl;
|
||||
if (m_csvLoggingDataValid)
|
||||
{
|
||||
QTextStream ts( &m_csvLoggingBuffer );
|
||||
if (m_csvLoggingDataValid) {
|
||||
QTextStream ts(&m_csvLoggingBuffer);
|
||||
ts << tempString;
|
||||
}
|
||||
|
||||
@ -699,16 +668,15 @@ int ScopeGadgetWidget::csvLoggingAddData()
|
||||
|
||||
int ScopeGadgetWidget::csvLoggingInsertData()
|
||||
{
|
||||
if (!m_csvLoggingStarted) return -1;
|
||||
m_csvLoggingDataSaved=1;
|
||||
|
||||
if(m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append)== FALSE)
|
||||
{
|
||||
qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Data";
|
||||
if (!m_csvLoggingStarted) {
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
QTextStream ts( &m_csvLoggingFile );
|
||||
m_csvLoggingDataSaved = 1;
|
||||
|
||||
if (m_csvLoggingFile.open(QIODevice::WriteOnly | QIODevice::Append) == FALSE) {
|
||||
qDebug() << "Unable to open " << m_csvLoggingFile.fileName() << " for csv logging Data";
|
||||
} else {
|
||||
QTextStream ts(&m_csvLoggingFile);
|
||||
ts << m_csvLoggingBuffer;
|
||||
m_csvLoggingFile.close();
|
||||
}
|
||||
@ -719,20 +687,22 @@ int ScopeGadgetWidget::csvLoggingInsertData()
|
||||
|
||||
void ScopeGadgetWidget::csvLoggingSetName(QString newName)
|
||||
{
|
||||
m_csvLoggingName = newName;
|
||||
m_csvLoggingNameSet=1;
|
||||
m_csvLoggingName = newName;
|
||||
m_csvLoggingNameSet = 1;
|
||||
}
|
||||
|
||||
void ScopeGadgetWidget::csvLoggingConnect()
|
||||
{
|
||||
m_csvLoggingConnected=1;
|
||||
if (m_csvLoggingNewFileOnConnect)csvLoggingStart();
|
||||
return;
|
||||
m_csvLoggingConnected = 1;
|
||||
if (m_csvLoggingNewFileOnConnect) {
|
||||
csvLoggingStart();
|
||||
}
|
||||
}
|
||||
void ScopeGadgetWidget::csvLoggingDisconnect()
|
||||
{
|
||||
m_csvLoggingHeaderSaved=0;
|
||||
m_csvLoggingConnected=0;
|
||||
if (m_csvLoggingNewFileOnConnect)csvLoggingStop();
|
||||
return;
|
||||
m_csvLoggingHeaderSaved = 0;
|
||||
m_csvLoggingConnected = 0;
|
||||
if (m_csvLoggingNewFileOnConnect) {
|
||||
csvLoggingStop();
|
||||
}
|
||||
}
|
||||
|
@ -49,7 +49,6 @@ class TimeScaleDraw : public QwtScaleDraw
|
||||
{
|
||||
public:
|
||||
TimeScaleDraw() {
|
||||
//baseTime = QDateTime::currentDateTime().toTime_t();
|
||||
}
|
||||
virtual QwtText label(double v) const {
|
||||
uint seconds = (uint)(v);
|
||||
@ -58,8 +57,6 @@ public:
|
||||
upTime.setTime(timePart);
|
||||
return upTime.toLocalTime().toString("hh:mm:ss");
|
||||
}
|
||||
private:
|
||||
// double baseTime;
|
||||
};
|
||||
|
||||
class ScopeGadgetWidget : public QwtPlot
|
||||
@ -81,15 +78,15 @@ public:
|
||||
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 removeCurvePlot(QString uavObject, QString uavField);
|
||||
void addCurvePlot(QString uavObject, QString uavFieldSubField, int scaleOrderFactor = 0, int meanSamples = 1,
|
||||
QString mathFunction= "None", QPen pen = QPen(Qt::black), bool antialiased = true);
|
||||
void clearCurvePlots();
|
||||
int csvLoggingStart();
|
||||
int csvLoggingStop();
|
||||
void csvLoggingSetName(QString);
|
||||
void setLoggingEnabled(bool value){m_csvLoggingEnabled=value;};
|
||||
void setLoggingNewFileOnConnect(bool value){m_csvLoggingNewFileOnConnect=value;};
|
||||
void setLoggingPath(QString value){m_csvLoggingPath=value;};
|
||||
void setLoggingEnabled(bool value){m_csvLoggingEnabled=value;}
|
||||
void setLoggingNewFileOnConnect(bool value){m_csvLoggingNewFileOnConnect=value;}
|
||||
void setLoggingPath(QString value){m_csvLoggingPath=value;}
|
||||
|
||||
protected:
|
||||
void mousePressEvent(QMouseEvent *e);
|
||||
@ -97,6 +94,7 @@ protected:
|
||||
void mouseDoubleClickEvent(QMouseEvent *e);
|
||||
void mouseMoveEvent(QMouseEvent *e);
|
||||
void wheelEvent(QWheelEvent *e);
|
||||
void showEvent(QShowEvent *e);
|
||||
|
||||
private slots:
|
||||
void uavObjectReceived(UAVObject*);
|
||||
|
Loading…
Reference in New Issue
Block a user