Commit b8a2ef1b authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #4330 from dogmaphobic/charting

Charting Tweaks
parents 940a87b5 3262f6fc
...@@ -29,7 +29,16 @@ ...@@ -29,7 +29,16 @@
<string notr="true"/> <string notr="true"/>
</property> </property>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="margin"> <property name="leftMargin">
<number>6</number>
</property>
<property name="topMargin">
<number>6</number>
</property>
<property name="rightMargin">
<number>6</number>
</property>
<property name="bottomMargin">
<number>6</number> <number>6</number>
</property> </property>
<item> <item>
...@@ -103,8 +112,8 @@ ...@@ -103,8 +112,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>884</width> <width>879</width>
<height>491</height> <height>462</height>
</rect> </rect>
</property> </property>
</widget> </widget>
...@@ -113,7 +122,7 @@ ...@@ -113,7 +122,7 @@
<item row="3" column="0"> <item row="3" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing"> <property name="spacing">
<number>2</number> <number>4</number>
</property> </property>
<item> <item>
<widget class="QLineEdit" name="plotFilterLineEdit"> <widget class="QLineEdit" name="plotFilterLineEdit">
...@@ -139,7 +148,7 @@ ...@@ -139,7 +148,7 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>6</number>
</property> </property>
<item> <item>
<widget class="QCheckBox" name="shortNameCheckBox"> <widget class="QCheckBox" name="shortNameCheckBox">
...@@ -172,7 +181,7 @@ ...@@ -172,7 +181,7 @@
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_4"> <layout class="QVBoxLayout" name="verticalLayout_4">
<property name="spacing"> <property name="spacing">
<number>0</number> <number>6</number>
</property> </property>
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum> <enum>QLayout::SetMinimumSize</enum>
......
...@@ -2,80 +2,72 @@ ...@@ -2,80 +2,72 @@
#include "QGCApplication.h" #include "QGCApplication.h"
const QColor ChartPlot::baseColors[numColors] = { const QColor ChartPlot::baseColors[numColors] = {
QColor(242,255,128), QColor(242, 255, 128),
QColor(70,80,242), QColor(70, 80, 242),
QColor(232,33,47), QColor(232, 33, 47),
QColor(116,251,110), QColor(116, 251, 110),
QColor(81,183,244), QColor(81, 183, 244),
QColor(234,38,107), QColor(234, 38, 107),
QColor(92,247,217), QColor(92, 247, 217),
QColor(151,59,239), QColor(151, 59, 239),
QColor(231,72,28), QColor(231, 72, 28),
QColor(236,48,221), QColor(236, 48, 221),
QColor(75,133,243), QColor(75, 133, 243),
QColor(203,254,121), QColor(203, 254, 121),
QColor(104,64,240), QColor(104, 64, 240),
QColor(200,54,238), QColor(200, 54, 238),
QColor(104,250,138), QColor(104, 250, 138),
QColor(235,43,165), QColor(235, 43, 165),
QColor(98,248,176), QColor(98, 248, 176),
QColor(161,252,116), QColor(161, 252, 116),
QColor(87,231,246), QColor(87, 231, 246),
QColor(230,126,23) QColor(230, 126, 23)
}; };
ChartPlot::ChartPlot(QWidget *parent): ChartPlot::ChartPlot(QWidget* parent):
QwtPlot(parent), QwtPlot(parent),
nextColorIndex(0), _nextColorIndex(0),
symbolWidth(2.0f), _symbolWidth(2.0f),
curveWidth(2.0f), _curveWidth(2.0f),
gridWidth(0.8f) _gridWidth(0.8f)
{ {
// Initialize the list of curves. // Initialize the list of curves.
curves = QMap<QString, QwtPlotCurve*>(); _curves = QMap<QString, QwtPlotCurve*>();
// Set the grid. The colorscheme was already set in generateColorScheme(). // Set the grid. The colorscheme was already set in generateColorScheme().
grid = new QwtPlotGrid; _grid = new QwtPlotGrid;
grid->enableXMin(true); _grid->enableXMin(true);
grid->attach(this); _grid->attach(this);
_colors = QList<QColor>();
colors = QList<QColor>();
///> Color map for plots, includes 20 colors ///> Color map for plots, includes 20 colors
///> Map will start from beginning when the first 20 colors are exceeded ///> Map will start from beginning when the first 20 colors are exceeded
for (int i = 0; i < numColors; ++i) for(int i = 0; i < numColors; ++i) {
{ _colors.append(baseColors[i]);
colors.append(baseColors[i]);
} }
// Now that all objects have been initialized, color everything. // Now that all objects have been initialized, color everything.
styleChanged(qgcApp()->styleIsDark()); styleChanged(qgcApp()->styleIsDark());
} }
ChartPlot::~ChartPlot() ChartPlot::~ChartPlot()
{ {
} }
QColor ChartPlot::getNextColor() QColor ChartPlot::getNextColor()
{ {
if(nextColorIndex >= colors.count()) if(_nextColorIndex >= _colors.count()) {
{ _nextColorIndex = 0;
nextColorIndex = 0;
} }
return colors[nextColorIndex++]; return _colors[_nextColorIndex++];
} }
QColor ChartPlot::getColorForCurve(const QString &id) QColor ChartPlot::getColorForCurve(const QString& id)
{ {
return curves.value(id)->pen().color(); return _curves.value(id)->pen().color();
} }
void ChartPlot::shuffleColors() void ChartPlot::shuffleColors()
{ {
foreach (QwtPlotCurve* curve, curves) foreach(QwtPlotCurve* curve, _curves) {
{ if(curve->isVisible()) {
if (curve->isVisible()) {
QPen pen(curve->pen()); QPen pen(curve->pen());
pen.setColor(getNextColor()); pen.setColor(getNextColor());
curve->setPen(pen); curve->setPen(pen);
...@@ -86,32 +78,24 @@ void ChartPlot::shuffleColors() ...@@ -86,32 +78,24 @@ void ChartPlot::shuffleColors()
void ChartPlot::styleChanged(bool styleIsDark) void ChartPlot::styleChanged(bool styleIsDark)
{ {
// Generate a new color list for curves and recolor them. // Generate a new color list for curves and recolor them.
for (int i = 0; i < numColors; ++i) for(int i = 0; i < numColors; ++i) {
{ _colors[i] = styleIsDark ? baseColors[i].lighter(150) : baseColors[i].darker(150);
colors[i] = styleIsDark ? baseColors[i].lighter(150) : baseColors[i].darker(150);
} }
shuffleColors(); shuffleColors();
// Configure the rest of the UI colors based on the current theme. // Configure the rest of the UI colors based on the current theme.
if (styleIsDark) if(styleIsDark) {
{
// Set canvas background // Set canvas background
setCanvasBackground(QColor(0, 0, 0)); setCanvasBackground(QColor(0, 0, 0));
// Configure the plot grid. // Configure the plot grid.
grid->setMinorPen(QPen(QColor(0xAA, 0xAA, 0xAA), gridWidth, Qt::DotLine)); _grid->setMinorPen(QPen(QColor(64, 64, 64), _gridWidth, Qt::SolidLine));
grid->setMajorPen(QPen(QColor(0xDD, 0xDD, 0xDD), gridWidth, Qt::DotLine)); _grid->setMajorPen(QPen(QColor(96, 96, 96), _gridWidth, Qt::SolidLine));
} } else {
else
{
// Set canvas background // Set canvas background
setCanvasBackground(QColor(0xFF, 0xFF, 0xFF)); setCanvasBackground(QColor(0xFF, 0xFF, 0xFF));
// Configure the plot grid. // Configure the plot grid.
grid->setMinorPen(QPen(QColor(0x55, 0x55, 0x55), gridWidth, Qt::DotLine)); _grid->setMinorPen(QPen(QColor(192, 192, 192), _gridWidth, Qt::SolidLine));
grid->setMajorPen(QPen(QColor(0x22, 0x22, 0x22), gridWidth, Qt::DotLine)); _grid->setMajorPen(QPen(QColor(128, 128, 128), _gridWidth, Qt::SolidLine));
} }
// And finally refresh the widget to make sure all color changes are redrawn. // And finally refresh the widget to make sure all color changes are redrawn.
replot(); replot();
} }
...@@ -31,14 +31,15 @@ public slots: ...@@ -31,14 +31,15 @@ public slots:
protected: protected:
const static int numColors = 20; const static int numColors = 20;
const static QColor baseColors[numColors]; const static QColor baseColors[numColors];
QList<QColor> colors; ///< Colormap for curves
int nextColorIndex; ///< Next index in color map QList<QColor> _colors; ///< Colormap for curves
QMap<QString, QwtPlotCurve* > curves; ///< Plot curves int _nextColorIndex; ///< Next index in color map
QwtPlotGrid* grid; ///< Plot grid QMap<QString, QwtPlotCurve* > _curves; ///< Plot curves
QwtPlotGrid* _grid; ///< Plot grid
float symbolWidth; ///< Width of curve symbols in pixels
float curveWidth; ///< Width of curve lines in pixels float _symbolWidth; ///< Width of curve symbols in pixels
float gridWidth; ///< Width of gridlines in pixels float _curveWidth; ///< Width of curve lines in pixels
float _gridWidth; ///< Width of gridlines in pixels
}; };
#endif // CHARTPLOT_H #endif // CHARTPLOT_H
...@@ -143,7 +143,7 @@ void IncrementalPlot::showLegend(bool show) ...@@ -143,7 +143,7 @@ void IncrementalPlot::showLegend(bool show)
void IncrementalPlot::setStyleText(const QString &style) void IncrementalPlot::setStyleText(const QString &style)
{ {
styleText = style.toLower(); styleText = style.toLower();
foreach (QwtPlotCurve* curve, curves) { foreach (QwtPlotCurve* curve, _curves) {
updateStyle(curve); updateStyle(curve);
} }
replot(); replot();
...@@ -161,24 +161,24 @@ void IncrementalPlot::updateStyle(QwtPlotCurve *curve) ...@@ -161,24 +161,24 @@ void IncrementalPlot::updateStyle(QwtPlotCurve *curve)
// Update the symbol style // Update the symbol style
QwtSymbol *newSymbol = NULL; QwtSymbol *newSymbol = NULL;
if (styleText.contains("circles")) { if (styleText.contains("circles")) {
newSymbol = new QwtSymbol(QwtSymbol::Ellipse, Qt::NoBrush, QPen(oldColor, symbolWidth), QSize(6, 6)); newSymbol = new QwtSymbol(QwtSymbol::Ellipse, Qt::NoBrush, QPen(oldColor, _symbolWidth), QSize(6, 6));
} else if (styleText.contains("crosses")) { } else if (styleText.contains("crosses")) {
newSymbol = new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(oldColor, symbolWidth), QSize(5, 5)); newSymbol = new QwtSymbol(QwtSymbol::XCross, Qt::NoBrush, QPen(oldColor, _symbolWidth), QSize(5, 5));
} else if (styleText.contains("rect")) { } else if (styleText.contains("rect")) {
newSymbol = new QwtSymbol(QwtSymbol::Rect, Qt::NoBrush, QPen(oldColor, symbolWidth), QSize(6, 6)); newSymbol = new QwtSymbol(QwtSymbol::Rect, Qt::NoBrush, QPen(oldColor, _symbolWidth), QSize(6, 6));
} }
// Else-case already handled by NULL value, which indicates no symbol // Else-case already handled by NULL value, which indicates no symbol
curve->setSymbol(newSymbol); curve->setSymbol(newSymbol);
// Update the line style // Update the line style
if (styleText.contains("dotted")) { if (styleText.contains("dotted")) {
curve->setPen(QPen(oldColor, curveWidth, Qt::DotLine)); curve->setPen(QPen(oldColor, _curveWidth, Qt::DotLine));
} else if (styleText.contains("dashed")) { } else if (styleText.contains("dashed")) {
curve->setPen(QPen(oldColor, curveWidth, Qt::DashLine)); curve->setPen(QPen(oldColor, _curveWidth, Qt::DashLine));
} else if (styleText.contains("line") || styleText.contains("solid")) { } else if (styleText.contains("line") || styleText.contains("solid")) {
curve->setPen(QPen(oldColor, curveWidth, Qt::SolidLine)); curve->setPen(QPen(oldColor, _curveWidth, Qt::SolidLine));
} else { } else {
curve->setPen(QPen(oldColor, curveWidth, Qt::NoPen)); curve->setPen(QPen(oldColor, _curveWidth, Qt::NoPen));
} }
curve->setStyle(QwtPlotCurve::Lines); curve->setStyle(QwtPlotCurve::Lines);
} }
...@@ -260,22 +260,22 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s ...@@ -260,22 +260,22 @@ void IncrementalPlot::appendData(const QString &key, double *x, double *y, int s
} }
// If this is a new curve, create it. // If this is a new curve, create it.
if (!curves.contains(key)) { if (!_curves.contains(key)) {
curve = new QwtPlotCurve(key); curve = new QwtPlotCurve(key);
curves.insert(key, curve); _curves.insert(key, curve);
curve->setStyle(QwtPlotCurve::NoCurve); curve->setStyle(QwtPlotCurve::NoCurve);
curve->setPaintAttribute(QwtPlotCurve::FilterPoints); curve->setPaintAttribute(QwtPlotCurve::FilterPoints);
// Set the color. Only the pen needs to be set // Set the color. Only the pen needs to be set
const QColor &c = getNextColor(); const QColor &c = getNextColor();
curve->setPen(c, symbolWidth); curve->setPen(c, _symbolWidth);
qDebug() << "Creating curve" << key << "with color" << c; qDebug() << "Creating curve" << key << "with color" << c;
updateStyle(curve); updateStyle(curve);
curve->attach(this); curve->attach(this);
} else { } else {
curve = curves.value(key); curve = _curves.value(key);
} }
data->append(x, y, size); data->append(x, y, size);
...@@ -359,21 +359,21 @@ int IncrementalPlot::data(const QString &key, double* r_x, double* r_y, int maxS ...@@ -359,21 +359,21 @@ int IncrementalPlot::data(const QString &key, double* r_x, double* r_y, int maxS
*/ */
void IncrementalPlot::showGrid(bool show) void IncrementalPlot::showGrid(bool show)
{ {
grid->setVisible(show); _grid->setVisible(show);
replot(); replot();
} }
bool IncrementalPlot::gridEnabled() const bool IncrementalPlot::gridEnabled() const
{ {
return grid->isVisible(); return _grid->isVisible();
} }
void IncrementalPlot::removeData() void IncrementalPlot::removeData()
{ {
foreach (QwtPlotCurve* curve, curves) { foreach (QwtPlotCurve* curve, _curves) {
delete curve; delete curve;
} }
curves.clear(); _curves.clear();
foreach (CurveData* data, d_data) { foreach (CurveData* data, d_data) {
delete data; delete data;
......
...@@ -190,7 +190,7 @@ void LinechartPlot::removeTimedOutCurves() ...@@ -190,7 +190,7 @@ void LinechartPlot::removeTimedOutCurves()
{ {
// Remove this curve // Remove this curve
// Delete curves // Delete curves
QwtPlotCurve* curve = curves.take(key); QwtPlotCurve* curve = _curves.take(key);
// Delete the object // Delete the object
delete curve; delete curve;
// Set the pointer null // Set the pointer null
...@@ -276,7 +276,7 @@ void LinechartPlot::appendData(QString dataname, quint64 ms, double value) ...@@ -276,7 +276,7 @@ void LinechartPlot::appendData(QString dataname, quint64 ms, double value)
valueInterval = maxValue - minValue; valueInterval = maxValue - minValue;
// Assign dataset to curve // Assign dataset to curve
QwtPlotCurve* curve = curves.value(dataname); QwtPlotCurve* curve = _curves.value(dataname);
curve->setRawSamples(dataset->getPlotX(), dataset->getPlotY(), dataset->getPlotCount()); curve->setRawSamples(dataset->getPlotX(), dataset->getPlotY(), dataset->getPlotCount());
// qDebug() << "mintime" << minTime << "maxtime" << maxTime << "last max time" << "window position" << getWindowPosition(); // qDebug() << "mintime" << minTime << "maxtime" << maxTime << "last max time" << "window position" << getWindowPosition();
...@@ -321,7 +321,7 @@ void LinechartPlot::addCurve(QString id) ...@@ -321,7 +321,7 @@ void LinechartPlot::addCurve(QString id)
// Create new curve and set style // Create new curve and set style
QwtPlotCurve* curve = new QwtPlotCurve(id); QwtPlotCurve* curve = new QwtPlotCurve(id);
// Add curve to list // Add curve to list
curves.insert(id, curve); _curves.insert(id, curve);
curve->setStyle(QwtPlotCurve::Lines); curve->setStyle(QwtPlotCurve::Lines);
curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true); curve->setPaintAttribute(QwtPlotCurve::FilterPoints, true);
...@@ -414,15 +414,15 @@ void LinechartPlot::setScaling(int scaling) ...@@ -414,15 +414,15 @@ void LinechartPlot::setScaling(int scaling)
**/ **/
void LinechartPlot::setVisibleById(QString id, bool visible) void LinechartPlot::setVisibleById(QString id, bool visible)
{ {
if(curves.contains(id)) { if(_curves.contains(id)) {
curves.value(id)->setVisible(visible); _curves.value(id)->setVisible(visible);
if(visible) if(visible)
{ {
curves.value(id)->attach(this); _curves.value(id)->attach(this);
} }
else else
{ {
curves.value(id)->detach(); _curves.value(id)->detach();
} }
} }
} }
...@@ -467,9 +467,9 @@ void LinechartPlot::showCurve(QString id) ...@@ -467,9 +467,9 @@ void LinechartPlot::showCurve(QString id)
**/ **/
void LinechartPlot::setCurveColor(QString id, QColor color) void LinechartPlot::setCurveColor(QString id, QColor color)
{ {
QwtPlotCurve* curve = curves.value(id); QwtPlotCurve* curve = _curves.value(id);
// Change the color of the curve. // Change the color of the curve.
curve->setPen(QPen(QBrush(color), curveWidth)); curve->setPen(QPen(QBrush(color), _curveWidth));
//qDebug() << "Setting curve" << id << "to" << color; //qDebug() << "Setting curve" << id << "to" << color;
...@@ -477,7 +477,7 @@ void LinechartPlot::setCurveColor(QString id, QColor color) ...@@ -477,7 +477,7 @@ void LinechartPlot::setCurveColor(QString id, QColor color)
const QwtSymbol *oldSymbol = curve->symbol(); const QwtSymbol *oldSymbol = curve->symbol();
QwtSymbol *newSymbol = NULL; QwtSymbol *newSymbol = NULL;
if (oldSymbol) { if (oldSymbol) {
newSymbol = new QwtSymbol(oldSymbol->style(), QBrush(color), QPen(color, symbolWidth), QSize(symbolWidth, symbolWidth)); newSymbol = new QwtSymbol(oldSymbol->style(), QBrush(color), QPen(color, _symbolWidth), QSize(_symbolWidth, _symbolWidth));
} }
curve->setSymbol(newSymbol); curve->setSymbol(newSymbol);
} }
...@@ -490,7 +490,7 @@ void LinechartPlot::setCurveColor(QString id, QColor color) ...@@ -490,7 +490,7 @@ void LinechartPlot::setCurveColor(QString id, QColor color)
**/ **/
bool LinechartPlot::isVisible(QString id) bool LinechartPlot::isVisible(QString id)
{ {
return curves.value(id)->isVisible(); return _curves.value(id)->isVisible();
} }
/** /**
...@@ -499,9 +499,9 @@ bool LinechartPlot::isVisible(QString id) ...@@ -499,9 +499,9 @@ bool LinechartPlot::isVisible(QString id)
bool LinechartPlot::anyCurveVisible() bool LinechartPlot::anyCurveVisible()
{ {
bool visible = false; bool visible = false;
foreach (const QString &key, curves.keys()) foreach (const QString &key, _curves.keys())
{ {
if (curves.value(key)->isVisible()) if (_curves.value(key)->isVisible())
{ {
visible = true; visible = true;
} }
...@@ -530,7 +530,7 @@ void LinechartPlot::setAutoScroll(bool active) ...@@ -530,7 +530,7 @@ void LinechartPlot::setAutoScroll(bool active)
**/ **/
QList<QwtPlotCurve*> LinechartPlot::getCurves() QList<QwtPlotCurve*> LinechartPlot::getCurves()
{ {
return curves.values(); return _curves.values();
} }
/** /**
...@@ -702,10 +702,10 @@ void LinechartPlot::removeAllData() ...@@ -702,10 +702,10 @@ void LinechartPlot::removeAllData()
datalock.lock(); datalock.lock();
// Delete curves // Delete curves
QMap<QString, QwtPlotCurve*>::iterator i; QMap<QString, QwtPlotCurve*>::iterator i;
for(i = curves.begin(); i != curves.end(); ++i) for(i = _curves.begin(); i != _curves.end(); ++i)
{ {
// Remove from curve list // Remove from curve list
QwtPlotCurve* curve = curves.take(i.key()); QwtPlotCurve* curve = _curves.take(i.key());
// Delete the object // Delete the object
delete curve; delete curve;
// Set the pointer null // Set the pointer null
......
This diff is collapsed.
...@@ -138,7 +138,6 @@ protected: ...@@ -138,7 +138,6 @@ protected:
QAction* addNewCurve; ///< Add curve candidate to the active curves QAction* addNewCurve; ///< Add curve candidate to the active curves
QMenu* curveMenu;
QComboBox *timeScaleCmb; QComboBox *timeScaleCmb;
QToolButton* scalingLogButton; QToolButton* scalingLogButton;
......
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