support setting graph colors in preferences

This commit is contained in:
Axel Kohlmeyer
2025-04-13 16:56:21 -04:00
parent 00673999af
commit f181ca6aec
2 changed files with 65 additions and 18 deletions

View File

@ -27,6 +27,7 @@
#include <QLabel>
#include <QLayout>
#include <QLineSeries>
#include <QList>
#include <QMenu>
#include <QMenuBar>
#include <QPushButton>
@ -43,6 +44,16 @@
using namespace QtCharts;
// brush color index must be kept in sync with preferences
static const QList<QBrush> mybrushes = {
QBrush(QColor(0, 0, 0)), // black
QBrush(QColor(100, 150, 255)), // blue
QBrush(QColor(255, 125, 125)), // red
QBrush(QColor(100, 200, 100)), // green
QBrush(QColor(120, 120, 120)), // grey
};
ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")), saveAsAct(nullptr),
exportCsvAct(nullptr), exportDatAct(nullptr), exportYamlAct(nullptr), closeAct(nullptr),
@ -597,11 +608,19 @@ static QList<QPointF> calc_sgsmooth(const QList<QPointF> &input, const int windo
void ChartViewer::update_smooth()
{
QSettings settings;
settings.beginGroup("charts");
int rawidx = settings.value("rawbrush", 1).toInt();
int smoothidx = settings.value("smoothbrush", 2).toInt();
if ((rawidx < 0) || (rawidx >= mybrushes.size())) rawidx = 0;
if ((smoothidx < 0) || (smoothidx >= mybrushes.size())) smoothidx = 0;
settings.endGroup();
auto allseries = chart->series();
if (do_raw) {
// add raw data if not in chart
if (!allseries.contains(series)) {
series->setPen(QPen(QBrush(QColor(100, 150, 255)), 3, Qt::SolidLine, Qt::RoundCap));
series->setPen(QPen(mybrushes[rawidx], 3, Qt::SolidLine, Qt::RoundCap));
chart->addSeries(series);
series->attachAxis(xaxis);
series->attachAxis(yaxis);
@ -612,7 +631,7 @@ void ChartViewer::update_smooth()
if (series->count() > (2 * window)) {
if (!smooth) {
smooth = new QLineSeries;
smooth->setPen(QPen(QBrush(QColor(255, 125, 125)), 3, Qt::SolidLine, Qt::RoundCap));
smooth->setPen(QPen(mybrushes[smoothidx], 3, Qt::SolidLine, Qt::RoundCap));
chart->addSeries(smooth);
smooth->attachAxis(xaxis);
smooth->attachAxis(yaxis);

View File

@ -217,6 +217,10 @@ void Preferences::accept()
if (field) settings->setValue("xlabel", field->text());
combo = tabWidget->findChild<QComboBox *>("smoothchoice");
if (combo) settings->setValue("smoothchoice", combo->currentIndex());
combo = tabWidget->findChild<QComboBox *>("rawbrush");
if (combo) settings->setValue("rawbrush", combo->currentIndex());
combo = tabWidget->findChild<QComboBox *>("smoothbrush");
if (combo) settings->setValue("smoothbrush", combo->currentIndex());
spin = tabWidget->findChild<QSpinBox *>("smoothwindow");
if (spin) settings->setValue("smoothwindow", spin->value());
spin = tabWidget->findChild<QSpinBox *>("smoothorder");
@ -674,6 +678,26 @@ ChartsTab::ChartsTab(QSettings *_settings, QWidget *parent) : QWidget(parent), s
smoothval->setObjectName("smoothchoice");
smoothval->setCurrentIndex(settings->value("smoothchoice", 2).toInt());
auto *rawbrlbl = new QLabel("Raw plot color:");
auto *rawbrush = new QComboBox;
rawbrush->addItem("Black");
rawbrush->addItem("Blue");
rawbrush->addItem("Red");
rawbrush->addItem("Green");
rawbrush->addItem("Gray");
rawbrush->setObjectName("rawbrush");
rawbrush->setCurrentIndex(settings->value("rawbrush", 1).toInt());
auto *smoothbrlbl = new QLabel("Smooth plot color:");
auto *smoothbrush = new QComboBox;
smoothbrush->addItem("Black");
smoothbrush->addItem("Blue");
smoothbrush->addItem("Red");
smoothbrush->addItem("Green");
smoothbrush->addItem("Gray");
smoothbrush->setObjectName("smoothbrush");
smoothbrush->setCurrentIndex(settings->value("smoothbrush", 2).toInt());
auto *smwindlbl = new QLabel("Default smoothing window:");
auto *smwindval = new QSpinBox;
smwindval->setRange(5, 999);
@ -707,6 +731,10 @@ ChartsTab::ChartsTab(QSettings *_settings, QWidget *parent) : QWidget(parent), s
grid->addWidget(xlabeltxt, i++, 1, Qt::AlignTop);
grid->addWidget(smoothlbl, i, 0, Qt::AlignTop);
grid->addWidget(smoothval, i++, 1, Qt::AlignTop);
grid->addWidget(rawbrlbl, i, 0, Qt::AlignTop);
grid->addWidget(rawbrush, i++, 1, Qt::AlignTop);
grid->addWidget(smoothbrlbl, i, 0, Qt::AlignTop);
grid->addWidget(smoothbrush, i++, 1, Qt::AlignTop);
grid->addWidget(smwindlbl, i, 0, Qt::AlignTop);
grid->addWidget(smwindval, i++, 1, Qt::AlignTop);
grid->addWidget(smordrlbl, i, 0, Qt::AlignTop);