Commit f89cbf71 authored by Bryant's avatar Bryant

Further consolidation of Plot code into ChartPlot. Also removed some unused...

Further consolidation of Plot code into ChartPlot. Also removed some unused variables from LinechartWidget.cc. Also only active curves are recolored in the IncrementalPlot class.
parent ce9fead2
......@@ -26,12 +26,15 @@ const QColor ChartPlot::baseColors[numColors] = {
ChartPlot::ChartPlot(QWidget *parent):
QwtPlot(parent),
nextColorIndex(0)/*,
nextColorIndex(0),
symbolWidth(1.2f),
curveWidth(1.0f),
curveWidth(2.0f),
gridWidth(0.8f),
scaleWidth(1.0f)*/
zoomerWidth(3.0f)
{
// Initialize the list of curves.
curves = QMap<QString, QwtPlotCurve*>();
// Set the grid. The colorscheme was already set in generateColorScheme().
grid = new QwtPlotGrid;
grid->enableXMin(true);
......@@ -80,52 +83,55 @@ void ChartPlot::shuffleColors()
{
foreach (QwtPlotCurve* curve, curves)
{
QPen pen(curve->pen());
pen.setColor(getNextColor());
curve->setPen(pen);
if (curve->isVisible()) {
QPen pen(curve->pen());
pen.setColor(getNextColor());
curve->setPen(pen);
}
}
}
void ChartPlot::applyColorScheme(MainWindow::QGC_MAINWINDOW_STYLE style)
{
// Generate the color list for curves
// Generate a new color list for curves and recolor them.
for (int i = 0; i < numColors; ++i)
{
if (style == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT) {
// colors[i] = baseColors[i].lighter(150);
colors[i] = baseColors[i].lighter(150);
}
else
{
// colors[i] = baseColors[i].darker(150);
colors[i] = baseColors[i].darker(150);
}
}
shuffleColors();
// Configure the rest of the UI colors based on the current theme.
if (style == MainWindow::QGC_MAINWINDOW_STYLE_LIGHT)
{
// Set the coloring of the area selector for zooming.
zoomer->setRubberBandPen(QPen(Qt::darkRed, 3.0f, Qt::DotLine));
zoomer->setRubberBandPen(QPen(Qt::darkRed, zoomerWidth, Qt::DotLine));
zoomer->setTrackerPen(QPen(Qt::darkRed));
// Set canvas background
setCanvasBackground(QColor(0xFF, 0xFF, 0xFF));
// Configure the plot grid.
grid->setMinPen(QPen(QColor(0x55, 0x55, 0x55), 0.8f, Qt::DotLine));
grid->setMajPen(QPen(QColor(0x22, 0x22, 0x22), 0.8f, Qt::DotLine));
grid->setMinPen(QPen(QColor(0x55, 0x55, 0x55), gridWidth, Qt::DotLine));
grid->setMajPen(QPen(QColor(0x22, 0x22, 0x22), gridWidth, Qt::DotLine));
}
else
{
// Set the coloring of the area selector for zooming.
zoomer->setRubberBandPen(QPen(Qt::red, 3.0f, Qt::DotLine));
zoomer->setRubberBandPen(QPen(Qt::red, zoomerWidth, Qt::DotLine));
zoomer->setTrackerPen(QPen(Qt::red));
// Set canvas background
setCanvasBackground(QColor(0, 0, 0));
// Configure the plot grid.
grid->setMinPen(QPen(QColor(0xAA, 0xAA, 0xAA), 0.8f, Qt::DotLine));
grid->setMajPen(QPen(QColor(0xDD, 0xDD, 0xDD), 0.8f, Qt::DotLine));
grid->setMinPen(QPen(QColor(0xAA, 0xAA, 0xAA), gridWidth, Qt::DotLine));
grid->setMajPen(QPen(QColor(0xDD, 0xDD, 0xDD), gridWidth, Qt::DotLine));
}
// And finally refresh the widget to make sure all color changes are redrawn.
......
......@@ -31,6 +31,11 @@ protected:
ScrollZoomer* zoomer; ///< Zoomer class for widget
QwtPlotGrid* grid; ///< Plot grid
float symbolWidth; ///< Width of curve symbols in pixels
float curveWidth; ///< Width of curve lines in pixels
float gridWidth; ///< Width of gridlines in pixels
float zoomerWidth; ///< Width of zoomer selection box
protected slots:
/** @brief Generate coloring for this plot canvas based on current window theme */
......
......@@ -85,10 +85,6 @@ const double* CurveData::y() const
IncrementalPlot::IncrementalPlot(QWidget *parent):
ChartPlot(parent),
symbolWidth(1.2f),
curveWidth(1.0f),
gridWidth(0.8f),
scaleWidth(1.0f),
symmetric(false)
{
setAutoReplot(false);
......@@ -96,10 +92,6 @@ IncrementalPlot::IncrementalPlot(QWidget *parent):
plotLayout()->setAlignCanvasToScales(true);
grid = new QwtPlotGrid;
grid->setMajPen(QPen(Qt::gray, 0.8f, Qt::DotLine));
grid->attach(this);
QwtLinearScaleEngine* yScaleEngine = new QwtLinearScaleEngine();
setAxisScaleEngine(QwtPlot::yLeft, yScaleEngine);
......@@ -280,7 +272,7 @@ void IncrementalPlot::appendData(QString key, double *x, double *y, int size)
const QColor &c = getNextColor();
curve->setSymbol(QwtSymbol(QwtSymbol::XCross,
QBrush(c), QPen(c, 1.2f), QSize(5, 5)) );
QBrush(c), QPen(c, symbolWidth), QSize(5, 5)) );
curve->attach(this);
} else {
......
......@@ -86,11 +86,6 @@ public:
/** @brief Read out data from a curve */
int data(QString key, double* r_x, double* r_y, int maxSize);
float symbolWidth;
float curveWidth;
float gridWidth;
float scaleWidth;
public slots:
/** @brief Append one data point */
void appendData(QString key, double x, double y);
......
......@@ -54,7 +54,6 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval):
//lastMaxTimeAdded = QTime();
curves = QMap<QString, QwtPlotCurve*>();
data = QMap<QString, TimeSeriesData*>();
scaleMaps = QMap<QString, QwtScaleMap*>();
......@@ -63,14 +62,6 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval):
setAutoReplot(false);
// Set grid
QwtPlotGrid *grid = new QwtPlotGrid;
grid->setMinPen(QPen(Qt::darkGray, 0, Qt::DotLine));
grid->setMajPen(QPen(Qt::gray, 0, Qt::DotLine));
grid->enableXMin(true);
// TODO xmin?
grid->attach(this);
// Set left scale
//setAxisOptions(QwtPlot::yLeft, QwtAutoScale::Logarithmic);
......@@ -87,15 +78,6 @@ LinechartPlot::LinechartPlot(QWidget *parent, int plotid, quint64 interval):
plotLayout()->setAlignCanvasToScales(true);
// Set canvas background
setCanvasBackground(QColor(40, 40, 40));
// Enable zooming
//zoomer = new Zoomer(canvas());
zoomer = new ScrollZoomer(canvas());
zoomer->setRubberBandPen(QPen(Qt::blue, 1.2, Qt::DotLine));
zoomer->setTrackerPen(QPen(Qt::blue));
// Start QTimer for plot update
updateTimer = new QTimer(this);
connect(updateTimer, SIGNAL(timeout()), this, SLOT(paintRealtime()));
......@@ -400,22 +382,6 @@ quint64 LinechartPlot::getWindowPosition()
return plotPosition;
}
/**
* @brief Set the color of a curve
*
* This method emits the colorSet(id, color) signal.
*
* @param id The id-string of the curve
* @param color The newly assigned color
**/
void LinechartPlot::setCurveColor(QString id, QColor color)
{
QwtPlotCurve* curve = curves.value(id);
curve->setPen(color);
emit colorSet(id, color);
}
/**
* @brief Set the scaling of the (vertical) y axis
* The mapping of the variable values on the drawing pane can be
......@@ -495,6 +461,20 @@ void LinechartPlot::showCurve(QString id)
// curves.value(id)->show();
//}
/**
* @brief Set the color of a curve
*
* This method emits the colorSet(id, color) signal.
*
* @param id The id-string of the curve
* @param color The newly assigned color
**/
void LinechartPlot::setCurveColor(QString id, QColor color)
{
QwtPlotCurve* curve = curves.value(id);
curve->setPen(color);
}
/**
* @brief Check the visibility of a curve
*
......
......@@ -175,7 +175,6 @@ public:
quint64 getPlotInterval();
quint64 getDataInterval();
quint64 getWindowPosition();
QList<QColor> getColorMap();
/** @brief Get the short-term mean of a curve */
double getMean(QString id);
......@@ -215,7 +214,13 @@ public slots:
// Functions referring to the currently active plot
void setVisible(QString id, bool visible);
//void showCurve(QString id, int position);
/**
* @brief Set the color of a curve
*
* @param id The id-string of the curve
* @param color The newly assigned color
**/
void setCurveColor(QString id, QColor color);
/** @brief Enforce the use of the receive timestamp */
......@@ -291,13 +296,6 @@ signals:
* @param color The curve color in the diagram
**/
void curveAdded(QString idstring);
/**
* @brief This signal is emitted when a curve gets assigned a color
*
* @param idstring The id-string of the curve
* @param color The curve color in the diagram
**/
void colorSet(QString idstring, QColor color);
/**
* @brief This signal is emitted when a curve is removed
*
......
......@@ -61,7 +61,6 @@ LinechartWidget::LinechartWidget(int systemid, QWidget *parent) : QWidget(parent
plotWindowLock(),
curveListIndex(0),
curveListCounter(0),
listedCurves(new QList<QString>()),
curveLabels(new QMap<QString, QLabel*>()),
curveMeans(new QMap<QString, QLabel*>()),
curveMedians(new QMap<QString, QLabel*>()),
......@@ -154,8 +153,6 @@ LinechartWidget::~LinechartWidget()
stopLogging();
if (activePlot) delete activePlot;
activePlot = NULL;
delete listedCurves;
listedCurves = NULL;
}
void LinechartWidget::selectActiveSystem(int mav)
......
......@@ -95,7 +95,7 @@ public slots:
void appendData(int uasId, const QString& curve, const QString& unit, quint64 value, quint64 usec);
/** @brief Append double data to the given curve. */
void appendData(int uasId, const QString& curve, const QString& unit, double value, quint64 usec);
void takeButtonClick(bool checked);
void setPlotWindowPosition(int scrollBarValue);
void setPlotWindowPosition(quint64 position);
......@@ -138,7 +138,6 @@ protected:
int curveListIndex;
int curveListCounter; ///< Counter of curves in curve list
QList<QString>* listedCurves; ///< Curves listed
QMap<QString, QLabel*>* curveLabels; ///< References to the curve labels
QMap<QString, QLabel*> curveNameLabels; ///< References to the curve labels
QMap<QString, QString> curveNames; ///< Full curve names
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment