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 <QLabel>
#include <QLayout> #include <QLayout>
#include <QLineSeries> #include <QLineSeries>
#include <QList>
#include <QMenu> #include <QMenu>
#include <QMenuBar> #include <QMenuBar>
#include <QPushButton> #include <QPushButton>
@ -43,6 +44,16 @@
using namespace QtCharts; 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) : ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")), saveAsAct(nullptr), QWidget(parent), menu(new QMenuBar), file(new QMenu("&File")), saveAsAct(nullptr),
exportCsvAct(nullptr), exportDatAct(nullptr), exportYamlAct(nullptr), closeAct(nullptr), exportCsvAct(nullptr), exportDatAct(nullptr), exportYamlAct(nullptr), closeAct(nullptr),
@ -66,24 +77,24 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) :
chartYlabel = new QLineEdit(""); chartYlabel = new QLineEdit("");
// plot smoothing // plot smoothing
int smoothchoice = settings.value("smoothchoice",2).toInt(); int smoothchoice = settings.value("smoothchoice", 2).toInt();
switch (smoothchoice) { switch (smoothchoice) {
case 0: case 0:
do_raw = true; do_raw = true;
do_smooth = false; do_smooth = false;
break; break;
case 1: case 1:
do_raw = false; do_raw = false;
do_smooth = true; do_smooth = true;
break; break;
case 2: // fallthrough case 2: // fallthrough
default: default:
do_raw = true; do_raw = true;
do_smooth = true; do_smooth = true;
break; break;
} }
// list of choices must be kepy in sync with list in preferences // list of choices must be kepy in sync with list in preferences
smooth = new QComboBox; smooth = new QComboBox;
smooth->addItem("Raw"); smooth->addItem("Raw");
smooth->addItem("Smooth"); smooth->addItem("Smooth");
smooth->addItem("Both"); smooth->addItem("Both");
@ -597,11 +608,19 @@ static QList<QPointF> calc_sgsmooth(const QList<QPointF> &input, const int windo
void ChartViewer::update_smooth() 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(); auto allseries = chart->series();
if (do_raw) { if (do_raw) {
// add raw data if not in chart // add raw data if not in chart
if (!allseries.contains(series)) { 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); chart->addSeries(series);
series->attachAxis(xaxis); series->attachAxis(xaxis);
series->attachAxis(yaxis); series->attachAxis(yaxis);
@ -612,7 +631,7 @@ void ChartViewer::update_smooth()
if (series->count() > (2 * window)) { if (series->count() > (2 * window)) {
if (!smooth) { if (!smooth) {
smooth = new QLineSeries; 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); chart->addSeries(smooth);
smooth->attachAxis(xaxis); smooth->attachAxis(xaxis);
smooth->attachAxis(yaxis); smooth->attachAxis(yaxis);

View File

@ -217,6 +217,10 @@ void Preferences::accept()
if (field) settings->setValue("xlabel", field->text()); if (field) settings->setValue("xlabel", field->text());
combo = tabWidget->findChild<QComboBox *>("smoothchoice"); combo = tabWidget->findChild<QComboBox *>("smoothchoice");
if (combo) settings->setValue("smoothchoice", combo->currentIndex()); 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"); spin = tabWidget->findChild<QSpinBox *>("smoothwindow");
if (spin) settings->setValue("smoothwindow", spin->value()); if (spin) settings->setValue("smoothwindow", spin->value());
spin = tabWidget->findChild<QSpinBox *>("smoothorder"); spin = tabWidget->findChild<QSpinBox *>("smoothorder");
@ -308,7 +312,7 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa
auto https_proxy = QString::fromLocal8Bit(qgetenv("https_proxy")); auto https_proxy = QString::fromLocal8Bit(qgetenv("https_proxy"));
if (https_proxy.isEmpty()) { if (https_proxy.isEmpty()) {
https_proxy = settings->value("https_proxy", "").toString(); https_proxy = settings->value("https_proxy", "").toString();
auto *proxyedit = new QLineEdit(https_proxy); auto *proxyedit = new QLineEdit(https_proxy);
proxyedit->setObjectName("proxyval"); proxyedit->setObjectName("proxyval");
gridlayout->addWidget(proxyedit, 3, 1); gridlayout->addWidget(proxyedit, 3, 1);
@ -674,6 +678,26 @@ ChartsTab::ChartsTab(QSettings *_settings, QWidget *parent) : QWidget(parent), s
smoothval->setObjectName("smoothchoice"); smoothval->setObjectName("smoothchoice");
smoothval->setCurrentIndex(settings->value("smoothchoice", 2).toInt()); 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 *smwindlbl = new QLabel("Default smoothing window:");
auto *smwindval = new QSpinBox; auto *smwindval = new QSpinBox;
smwindval->setRange(5, 999); 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(xlabeltxt, i++, 1, Qt::AlignTop);
grid->addWidget(smoothlbl, i, 0, Qt::AlignTop); grid->addWidget(smoothlbl, i, 0, Qt::AlignTop);
grid->addWidget(smoothval, i++, 1, 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(smwindlbl, i, 0, Qt::AlignTop);
grid->addWidget(smwindval, i++, 1, Qt::AlignTop); grid->addWidget(smwindval, i++, 1, Qt::AlignTop);
grid->addWidget(smordrlbl, i, 0, Qt::AlignTop); grid->addWidget(smordrlbl, i, 0, Qt::AlignTop);