1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-20 10:54:14 +01:00

OP-1554 Cleanup and rename.

This commit is contained in:
m_thread 2014-10-29 00:05:53 +01:00
parent 0af45277f3
commit abe33bbea2
4 changed files with 21 additions and 74 deletions

View File

@ -37,23 +37,23 @@ PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
m_mathFunction(mathFunction), m_plotDataSize(plotDataSize),
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);
}
// 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()) {
m_curveName.append(QString(".%1").arg(m_elementName));
m_plotName.append(QString(".%1").arg(m_elementName));
}
if (m_scalePower == 0) {
m_curveName.append(QString(" (%1)").arg(m_field->getUnits()));
m_plotName.append(QString(" (%1)").arg(m_field->getUnits()));
} 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) {
m_plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
@ -65,15 +65,6 @@ PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
m_meanSum = 0.0f;
m_correctionSum = 0.0f;
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()
@ -82,7 +73,7 @@ PlotData::~PlotData()
delete m_plotCurve;
}
void PlotData::updatePlotCurveData()
void PlotData::updatePlotData()
{
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
}
@ -128,7 +119,7 @@ void PlotData::calcMathFunction(double currentValue)
bool SequentialPlotData::append(UAVObject *obj)
{
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
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
@ -154,7 +145,7 @@ bool ChronoPlotData::append(UAVObject *obj)
if (m_object == obj && m_field) {
// Get the field of interest
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
if (m_mathFunction == "Boxcar average" || m_mathFunction == "Standard deviation") {
@ -181,8 +172,3 @@ void ChronoPlotData::removeStaleData()
m_xDataEntries.pop_front();
}
}
void ChronoPlotData::removeStaleDataTimeout()
{
removeStaleData();
}

View File

@ -57,7 +57,7 @@ public:
QString mathFunction, double plotDataSize, QPen pen, bool antialiased);
~PlotData();
QString name() { return m_curveName; }
QString plotName() const { return m_plotName; }
UAVObject *object() const { return m_object; }
UAVObjectField *field() const { return m_field; }
@ -65,25 +65,22 @@ public:
QString elementName() const { return m_elementName; }
bool isVisible() const { return m_plotCurve->isVisible(); }
double yMin() const { return m_yMin;}
double yMax() const { return m_yMax;}
void setVisible(bool visible) { return m_plotCurve->setVisible(visible); }
virtual bool append(UAVObject *obj) = 0;
virtual PlotType plotType() const = 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(); }
void attach(QwtPlot *plot);
protected:
double valueAsDouble(UAVObject *obj, UAVObjectField *field);
int m_scalePower; // This is the power to which each value must be raised
// This is the power to which each value must be raised
int m_scalePower;
int m_meanSamples;
double m_meanSum;
QString m_mathFunction;
@ -103,10 +100,8 @@ protected:
virtual void calcMathFunction(double currentValue);
private:
double m_yMin;
double m_yMax;
QwtPlotCurve *m_plotCurve;
QString m_curveName;
QString m_plotName;
};
/*!
@ -123,22 +118,8 @@ public:
mathFunction, plotDataSize, pen, antialiased) {}
~SequentialPlotData() {}
/*!
\brief Append new data to the plot
*/
bool append(UAVObject *obj);
/*!
\brief The type of plot
*/
PlotType plotType() const
{
return SequentialPlot;
}
/*!
\brief Removes the old data from the buffer
*/
PlotType plotType() const { return SequentialPlot; }
void removeStaleData() {}
};
@ -158,16 +139,8 @@ public:
~ChronoPlotData() {}
bool append(UAVObject *obj);
PlotType plotType() const
{
return ChronoPlot;
}
PlotType plotType() const { return ChronoPlot; }
void removeStaleData();
private slots:
void removeStaleDataTimeout();
};
#endif // PLOTDATA_H

View File

@ -77,7 +77,6 @@ public:
}
void replacePlotCurveConfig(QList<PlotCurveConfiguration *> m_plotCurveConfigs);
// Configurations getter functions
int plotType()
{

View File

@ -371,15 +371,10 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
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);
// 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
if (!m_connectedUAVObjects.contains(object->getName())) {
@ -411,7 +406,7 @@ void ScopeGadgetWidget::replotNewData()
QMutexLocker locker(&mutex);
foreach(PlotData * plotData, m_curvesData.values()) {
plotData->removeStaleData();
plotData->updatePlotCurveData();
plotData->updatePlotData();
}
QDateTime NOW = QDateTime::currentDateTime();
@ -437,7 +432,6 @@ void ScopeGadgetWidget::clearCurvePlots()
void ScopeGadgetWidget::saveState(QSettings *qSettings)
{
/*
// plot state
int i = 1;
@ -451,19 +445,15 @@ void ScopeGadgetWidget::saveState(QSettings *qSettings)
}
// legend state
qSettings->setValue("legendVisible", legend() != NULL);
*/
}
void ScopeGadgetWidget::restoreState(QSettings *qSettings)
{
/*
// plot state
int i = 1;
foreach(PlotData * plotData, m_curvesData.values()) {
bool visible = qSettings->value(QString("plot%1").arg(i), true).toBool();
showCurve(plotData->m_plotCurve, !visible);
plotData->setVisible(qSettings->value(QString("plot%1").arg(i), true).toBool());
i++;
}
// legend state
@ -473,7 +463,6 @@ void ScopeGadgetWidget::restoreState(QSettings *qSettings)
} else {
deleteLegend();
}
*/
}
/*