mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-21 11:54:15 +01:00
OP-1554 Cleanup and rename.
This commit is contained in:
parent
0af45277f3
commit
abe33bbea2
@ -37,23 +37,23 @@ PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
|
|||||||
m_mathFunction(mathFunction), m_plotDataSize(plotDataSize),
|
m_mathFunction(mathFunction), m_plotDataSize(plotDataSize),
|
||||||
m_object(object), m_field(field), m_element(element)
|
m_object(object), m_field(field), m_element(element)
|
||||||
{
|
{
|
||||||
if (m_field->getNumElements() > 1) {
|
if (!m_field->getNumElements() > 1) {
|
||||||
m_elementName = m_field->getElementNames().at(m_element);
|
m_elementName = m_field->getElementNames().at(m_element);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the curve
|
// Create the curve
|
||||||
m_curveName.append(QString("%1.%2").arg(m_object->getName()).arg(m_field->getName()));
|
m_plotName.append(QString("%1.%2").arg(m_object->getName()).arg(m_field->getName()));
|
||||||
if (!m_elementName.isEmpty()) {
|
if (!m_elementName.isEmpty()) {
|
||||||
m_curveName.append(QString(".%1").arg(m_elementName));
|
m_plotName.append(QString(".%1").arg(m_elementName));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_scalePower == 0) {
|
if (m_scalePower == 0) {
|
||||||
m_curveName.append(QString(" (%1)").arg(m_field->getUnits()));
|
m_plotName.append(QString(" (%1)").arg(m_field->getUnits()));
|
||||||
} else {
|
} else {
|
||||||
m_curveName.append(QString(" (x10^%1 %2)").arg(m_scalePower).arg(m_field->getUnits()));
|
m_plotName.append(QString(" (x10^%1 %2)").arg(m_scalePower).arg(m_field->getUnits()));
|
||||||
}
|
}
|
||||||
|
|
||||||
m_plotCurve = new QwtPlotCurve(m_curveName);
|
m_plotCurve = new QwtPlotCurve(m_plotName);
|
||||||
|
|
||||||
if (antialiased) {
|
if (antialiased) {
|
||||||
m_plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
|
m_plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
|
||||||
@ -65,15 +65,6 @@ PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
|
|||||||
m_meanSum = 0.0f;
|
m_meanSum = 0.0f;
|
||||||
m_correctionSum = 0.0f;
|
m_correctionSum = 0.0f;
|
||||||
m_correctionCount = 0;
|
m_correctionCount = 0;
|
||||||
m_yMin = 0;
|
|
||||||
m_yMax = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
double PlotData::valueAsDouble(UAVObject *obj, UAVObjectField *field)
|
|
||||||
{
|
|
||||||
Q_UNUSED(obj);
|
|
||||||
QVariant value = field->getValue(m_element);
|
|
||||||
return value.toDouble();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PlotData::~PlotData()
|
PlotData::~PlotData()
|
||||||
@ -82,7 +73,7 @@ PlotData::~PlotData()
|
|||||||
delete m_plotCurve;
|
delete m_plotCurve;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlotData::updatePlotCurveData()
|
void PlotData::updatePlotData()
|
||||||
{
|
{
|
||||||
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
|
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
|
||||||
}
|
}
|
||||||
@ -128,7 +119,7 @@ void PlotData::calcMathFunction(double currentValue)
|
|||||||
bool SequentialPlotData::append(UAVObject *obj)
|
bool SequentialPlotData::append(UAVObject *obj)
|
||||||
{
|
{
|
||||||
if (m_object == obj && m_field) {
|
if (m_object == obj && m_field) {
|
||||||
double currentValue = valueAsDouble(m_object, m_field) * pow(10, m_scalePower);
|
double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower);
|
||||||
|
|
||||||
// Perform scope math, if necessary
|
// Perform scope math, if necessary
|
||||||
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
||||||
@ -154,7 +145,7 @@ bool ChronoPlotData::append(UAVObject *obj)
|
|||||||
if (m_object == obj && m_field) {
|
if (m_object == obj && m_field) {
|
||||||
// Get the field of interest
|
// Get the field of interest
|
||||||
QDateTime NOW = QDateTime::currentDateTime(); // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
|
QDateTime NOW = QDateTime::currentDateTime(); // THINK ABOUT REIMPLEMENTING THIS TO SHOW UAVO TIME, NOT SYSTEM TIME
|
||||||
double currentValue = valueAsDouble(m_object, m_field) * pow(10, m_scalePower);
|
double currentValue = m_field->getValue(m_element).toDouble() * pow(10, m_scalePower);
|
||||||
|
|
||||||
// Perform scope math, if necessary
|
// Perform scope math, if necessary
|
||||||
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
|
||||||
@ -181,8 +172,3 @@ void ChronoPlotData::removeStaleData()
|
|||||||
m_xDataEntries.pop_front();
|
m_xDataEntries.pop_front();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ChronoPlotData::removeStaleDataTimeout()
|
|
||||||
{
|
|
||||||
removeStaleData();
|
|
||||||
}
|
|
||||||
|
@ -57,7 +57,7 @@ public:
|
|||||||
QString mathFunction, double plotDataSize, QPen pen, bool antialiased);
|
QString mathFunction, double plotDataSize, QPen pen, bool antialiased);
|
||||||
~PlotData();
|
~PlotData();
|
||||||
|
|
||||||
QString name() { return m_curveName; }
|
QString plotName() const { return m_plotName; }
|
||||||
|
|
||||||
UAVObject *object() const { return m_object; }
|
UAVObject *object() const { return m_object; }
|
||||||
UAVObjectField *field() const { return m_field; }
|
UAVObjectField *field() const { return m_field; }
|
||||||
@ -65,25 +65,22 @@ public:
|
|||||||
QString elementName() const { return m_elementName; }
|
QString elementName() const { return m_elementName; }
|
||||||
|
|
||||||
bool isVisible() const { return m_plotCurve->isVisible(); }
|
bool isVisible() const { return m_plotCurve->isVisible(); }
|
||||||
|
void setVisible(bool visible) { return m_plotCurve->setVisible(visible); }
|
||||||
double yMin() const { return m_yMin;}
|
|
||||||
double yMax() const { return m_yMax;}
|
|
||||||
|
|
||||||
virtual bool append(UAVObject *obj) = 0;
|
virtual bool append(UAVObject *obj) = 0;
|
||||||
virtual PlotType plotType() const = 0;
|
virtual PlotType plotType() const = 0;
|
||||||
virtual void removeStaleData() = 0;
|
virtual void removeStaleData() = 0;
|
||||||
|
|
||||||
void updatePlotCurveData();
|
void updatePlotData();
|
||||||
|
|
||||||
bool hasData() { return !m_xDataEntries.isEmpty(); }
|
bool hasData() const { return !m_xDataEntries.isEmpty(); }
|
||||||
double lastData() { return m_yDataEntries.last(); }
|
double lastData() { return m_yDataEntries.last(); }
|
||||||
|
|
||||||
void attach(QwtPlot *plot);
|
void attach(QwtPlot *plot);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double valueAsDouble(UAVObject *obj, UAVObjectField *field);
|
// This is the power to which each value must be raised
|
||||||
|
int m_scalePower;
|
||||||
int m_scalePower; // This is the power to which each value must be raised
|
|
||||||
int m_meanSamples;
|
int m_meanSamples;
|
||||||
double m_meanSum;
|
double m_meanSum;
|
||||||
QString m_mathFunction;
|
QString m_mathFunction;
|
||||||
@ -103,10 +100,8 @@ protected:
|
|||||||
virtual void calcMathFunction(double currentValue);
|
virtual void calcMathFunction(double currentValue);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
double m_yMin;
|
|
||||||
double m_yMax;
|
|
||||||
QwtPlotCurve *m_plotCurve;
|
QwtPlotCurve *m_plotCurve;
|
||||||
QString m_curveName;
|
QString m_plotName;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -123,22 +118,8 @@ public:
|
|||||||
mathFunction, plotDataSize, pen, antialiased) {}
|
mathFunction, plotDataSize, pen, antialiased) {}
|
||||||
~SequentialPlotData() {}
|
~SequentialPlotData() {}
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief Append new data to the plot
|
|
||||||
*/
|
|
||||||
bool append(UAVObject *obj);
|
bool append(UAVObject *obj);
|
||||||
|
PlotType plotType() const { return SequentialPlot; }
|
||||||
/*!
|
|
||||||
\brief The type of plot
|
|
||||||
*/
|
|
||||||
PlotType plotType() const
|
|
||||||
{
|
|
||||||
return SequentialPlot;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
|
||||||
\brief Removes the old data from the buffer
|
|
||||||
*/
|
|
||||||
void removeStaleData() {}
|
void removeStaleData() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -158,16 +139,8 @@ public:
|
|||||||
~ChronoPlotData() {}
|
~ChronoPlotData() {}
|
||||||
|
|
||||||
bool append(UAVObject *obj);
|
bool append(UAVObject *obj);
|
||||||
|
PlotType plotType() const { return ChronoPlot; }
|
||||||
PlotType plotType() const
|
|
||||||
{
|
|
||||||
return ChronoPlot;
|
|
||||||
}
|
|
||||||
|
|
||||||
void removeStaleData();
|
void removeStaleData();
|
||||||
|
|
||||||
private slots:
|
|
||||||
void removeStaleDataTimeout();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // PLOTDATA_H
|
#endif // PLOTDATA_H
|
||||||
|
@ -77,7 +77,6 @@ public:
|
|||||||
}
|
}
|
||||||
void replacePlotCurveConfig(QList<PlotCurveConfiguration *> m_plotCurveConfigs);
|
void replacePlotCurveConfig(QList<PlotCurveConfiguration *> m_plotCurveConfigs);
|
||||||
|
|
||||||
|
|
||||||
// Configurations getter functions
|
// Configurations getter functions
|
||||||
int plotType()
|
int plotType()
|
||||||
{
|
{
|
||||||
|
@ -371,15 +371,10 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
|||||||
pen, antialiased);
|
pen, antialiased);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the y-bounds are supplied, set them
|
|
||||||
if (plotData->yMin() != plotData->yMax()) {
|
|
||||||
setAxisScale(QwtPlot::yLeft, plotData->yMin(), plotData->yMax());
|
|
||||||
}
|
|
||||||
|
|
||||||
plotData->attach(this);
|
plotData->attach(this);
|
||||||
|
|
||||||
// Keep the curve details for later
|
// Keep the curve details for later
|
||||||
m_curvesData.insert(plotData->name(), plotData);
|
m_curvesData.insert(plotData->plotName(), 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(object->getName())) {
|
if (!m_connectedUAVObjects.contains(object->getName())) {
|
||||||
@ -411,7 +406,7 @@ void ScopeGadgetWidget::replotNewData()
|
|||||||
QMutexLocker locker(&mutex);
|
QMutexLocker locker(&mutex);
|
||||||
foreach(PlotData * plotData, m_curvesData.values()) {
|
foreach(PlotData * plotData, m_curvesData.values()) {
|
||||||
plotData->removeStaleData();
|
plotData->removeStaleData();
|
||||||
plotData->updatePlotCurveData();
|
plotData->updatePlotData();
|
||||||
}
|
}
|
||||||
|
|
||||||
QDateTime NOW = QDateTime::currentDateTime();
|
QDateTime NOW = QDateTime::currentDateTime();
|
||||||
@ -437,7 +432,6 @@ void ScopeGadgetWidget::clearCurvePlots()
|
|||||||
|
|
||||||
void ScopeGadgetWidget::saveState(QSettings *qSettings)
|
void ScopeGadgetWidget::saveState(QSettings *qSettings)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
// plot state
|
// plot state
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
@ -451,19 +445,15 @@ void ScopeGadgetWidget::saveState(QSettings *qSettings)
|
|||||||
}
|
}
|
||||||
// legend state
|
// legend state
|
||||||
qSettings->setValue("legendVisible", legend() != NULL);
|
qSettings->setValue("legendVisible", legend() != NULL);
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScopeGadgetWidget::restoreState(QSettings *qSettings)
|
void ScopeGadgetWidget::restoreState(QSettings *qSettings)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
// plot state
|
// plot state
|
||||||
int i = 1;
|
int i = 1;
|
||||||
|
|
||||||
foreach(PlotData * plotData, m_curvesData.values()) {
|
foreach(PlotData * plotData, m_curvesData.values()) {
|
||||||
bool visible = qSettings->value(QString("plot%1").arg(i), true).toBool();
|
plotData->setVisible(qSettings->value(QString("plot%1").arg(i), true).toBool());
|
||||||
|
|
||||||
showCurve(plotData->m_plotCurve, !visible);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
// legend state
|
// legend state
|
||||||
@ -473,7 +463,6 @@ void ScopeGadgetWidget::restoreState(QSettings *qSettings)
|
|||||||
} else {
|
} else {
|
||||||
deleteLegend();
|
deleteLegend();
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user