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