mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-03-15 07:29:15 +01:00
OP-1554 Re-factoring
Moved initialization of QwtPlot curve in to PlotData class.
This commit is contained in:
parent
959f197502
commit
0af45277f3
@ -31,18 +31,37 @@
|
||||
#include <QDebug>
|
||||
|
||||
PlotData::PlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleOrderFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize) :
|
||||
int scaleOrderFactor, int meanSamples, QString mathFunction,
|
||||
double plotDataSize, QPen pen, bool antialiased) :
|
||||
m_scalePower(scaleOrderFactor), m_meanSamples(meanSamples),
|
||||
m_mathFunction(mathFunction), m_plotDataSize(plotDataSize),
|
||||
m_object(object), m_field(field),
|
||||
m_element(element), m_plotCurve(plotCurve)
|
||||
m_object(object), m_field(field), m_element(element)
|
||||
{
|
||||
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()));
|
||||
if (!m_elementName.isEmpty()) {
|
||||
m_curveName.append(QString(".%1").arg(m_elementName));
|
||||
}
|
||||
|
||||
if (m_scalePower == 0) {
|
||||
m_curveName.append(QString(" (%1)").arg(m_field->getUnits()));
|
||||
} else {
|
||||
m_curveName.append(QString(" (x10^%1 %2)").arg(m_scalePower).arg(m_field->getUnits()));
|
||||
}
|
||||
|
||||
m_plotCurve = new QwtPlotCurve(m_curveName);
|
||||
|
||||
if (antialiased) {
|
||||
m_plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
|
||||
}
|
||||
|
||||
m_plotCurve->setPen(pen);
|
||||
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
|
||||
|
||||
if (!field->getElementNames().isEmpty()) {
|
||||
m_elementName = field->getElementNames().at(element);
|
||||
}
|
||||
m_meanSum = 0.0f;
|
||||
m_correctionSum = 0.0f;
|
||||
m_correctionCount = 0;
|
||||
@ -68,6 +87,11 @@ void PlotData::updatePlotCurveData()
|
||||
m_plotCurve->setSamples(m_xDataEntries, m_yDataEntries);
|
||||
}
|
||||
|
||||
void PlotData::attach(QwtPlot *plot)
|
||||
{
|
||||
m_plotCurve->attach(plot);
|
||||
}
|
||||
|
||||
void PlotData::calcMathFunction(double currentValue)
|
||||
{
|
||||
// Put the new value at the back
|
||||
|
@ -53,11 +53,12 @@ class PlotData : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
PlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleOrderFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize);
|
||||
PlotData(UAVObject *object, UAVObjectField *field, int element, int scaleOrderFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize, QPen pen, bool antialiased);
|
||||
~PlotData();
|
||||
|
||||
QString name() { return m_curveName; }
|
||||
|
||||
UAVObject *object() const { return m_object; }
|
||||
UAVObjectField *field() const { return m_field; }
|
||||
int element() const { return m_element; }
|
||||
@ -77,6 +78,8 @@ public:
|
||||
bool hasData() { return !m_xDataEntries.isEmpty(); }
|
||||
double lastData() { return m_yDataEntries.last(); }
|
||||
|
||||
void attach(QwtPlot *plot);
|
||||
|
||||
protected:
|
||||
double valueAsDouble(UAVObject *obj, UAVObjectField *field);
|
||||
|
||||
@ -103,6 +106,7 @@ private:
|
||||
double m_yMin;
|
||||
double m_yMax;
|
||||
QwtPlotCurve *m_plotCurve;
|
||||
QString m_curveName;
|
||||
};
|
||||
|
||||
/*!
|
||||
@ -113,9 +117,10 @@ class SequentialPlotData : public PlotData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
SequentialPlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize)
|
||||
: PlotData(object, field, element, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize) {}
|
||||
int scaleFactor, int meanSamples, QString mathFunction,
|
||||
double plotDataSize, QPen pen, bool antialiased)
|
||||
: PlotData(object, field, element, scaleFactor, meanSamples,
|
||||
mathFunction, plotDataSize, pen, antialiased) {}
|
||||
~SequentialPlotData() {}
|
||||
|
||||
/*!
|
||||
@ -144,9 +149,10 @@ class ChronoPlotData : public PlotData {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ChronoPlotData(UAVObject *object, UAVObjectField *field, int element,
|
||||
QwtPlotCurve *plotCurve, int scaleFactor, int meanSamples,
|
||||
QString mathFunction, double plotDataSize)
|
||||
: PlotData(object, field, element, plotCurve, scaleFactor, meanSamples, mathFunction, plotDataSize)
|
||||
int scaleFactor, int meanSamples, QString mathFunction,
|
||||
double plotDataSize, QPen pen, bool antialiased)
|
||||
: PlotData(object, field, element, scaleFactor, meanSamples,
|
||||
mathFunction, plotDataSize, pen, antialiased)
|
||||
{
|
||||
}
|
||||
~ChronoPlotData() {}
|
||||
|
@ -334,12 +334,6 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
elementName = fieldSubfield.at(1);
|
||||
}
|
||||
|
||||
// Create the curve
|
||||
QString curveName = objectName + "." + fieldName;
|
||||
if (!elementName.isEmpty()) {
|
||||
curveName.append("." + elementName);
|
||||
}
|
||||
|
||||
// Get the uav object
|
||||
ExtensionSystem::PluginManager *pm = ExtensionSystem::PluginManager::instance();
|
||||
UAVObjectManager *objManager = pm->getObject<UAVObjectManager>();
|
||||
@ -365,36 +359,16 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
}
|
||||
}
|
||||
|
||||
QString units = field->getUnits();
|
||||
|
||||
if (units == 0) {
|
||||
units = QString();
|
||||
}
|
||||
|
||||
QString curveNameScaled;
|
||||
if (scaleFactor == 0) {
|
||||
curveNameScaled = curveName + " (" + units + ")";
|
||||
} else {
|
||||
curveNameScaled = curveName + " (x10^" + QString::number(scaleFactor) + " " + units + ")";
|
||||
}
|
||||
|
||||
QwtPlotCurve *plotCurve = new QwtPlotCurve(curveNameScaled);
|
||||
|
||||
if (antialiased) {
|
||||
plotCurve->setRenderHint(QwtPlotCurve::RenderAntialiased);
|
||||
}
|
||||
|
||||
plotCurve->setPen(pen);
|
||||
plotCurve->attach(this);
|
||||
|
||||
PlotData *plotData;
|
||||
|
||||
if (m_plotType == SequentialPlot) {
|
||||
plotData = new SequentialPlotData(object, field, element, plotCurve, scaleFactor,
|
||||
meanSamples, mathFunction, m_plotDataSize);
|
||||
plotData = new SequentialPlotData(object, field, element, scaleFactor,
|
||||
meanSamples, mathFunction, m_plotDataSize,
|
||||
pen, antialiased);
|
||||
} else if (m_plotType == ChronoPlot) {
|
||||
plotData = new ChronoPlotData(object, field, element, plotCurve, scaleFactor,
|
||||
meanSamples, mathFunction, m_plotDataSize);
|
||||
plotData = new ChronoPlotData(object, field, element, scaleFactor,
|
||||
meanSamples, mathFunction, m_plotDataSize,
|
||||
pen, antialiased);
|
||||
}
|
||||
|
||||
// If the y-bounds are supplied, set them
|
||||
@ -402,8 +376,10 @@ void ScopeGadgetWidget::addCurvePlot(QString objectName, QString fieldPlusSubFie
|
||||
setAxisScale(QwtPlot::yLeft, plotData->yMin(), plotData->yMax());
|
||||
}
|
||||
|
||||
plotData->attach(this);
|
||||
|
||||
// Keep the curve details for later
|
||||
m_curvesData.insert(curveNameScaled, plotData);
|
||||
m_curvesData.insert(plotData->name(), plotData);
|
||||
|
||||
// Link to the new signal data only if this UAVObject has not been connected yet
|
||||
if (!m_connectedUAVObjects.contains(object->getName())) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user