diff --git a/tools/lammps-gui/chartviewer.cpp b/tools/lammps-gui/chartviewer.cpp index 6c7bafc58f..15bcd5d77b 100644 --- a/tools/lammps-gui/chartviewer.cpp +++ b/tools/lammps-gui/chartviewer.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,16 @@ using namespace QtCharts; +// brush color index must be kept in sync with preferences + +static const QList 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), @@ -66,24 +77,24 @@ ChartWindow::ChartWindow(const QString &_filename, QWidget *parent) : chartYlabel = new QLineEdit(""); // plot smoothing - int smoothchoice = settings.value("smoothchoice",2).toInt(); + int smoothchoice = settings.value("smoothchoice", 2).toInt(); switch (smoothchoice) { - case 0: - do_raw = true; - do_smooth = false; - break; - case 1: - do_raw = false; - do_smooth = true; - break; - case 2: // fallthrough - default: - do_raw = true; - do_smooth = true; - break; + case 0: + do_raw = true; + do_smooth = false; + break; + case 1: + do_raw = false; + do_smooth = true; + break; + case 2: // fallthrough + default: + do_raw = true; + do_smooth = true; + break; } // list of choices must be kepy in sync with list in preferences - smooth = new QComboBox; + smooth = new QComboBox; smooth->addItem("Raw"); smooth->addItem("Smooth"); smooth->addItem("Both"); @@ -597,11 +608,19 @@ static QList calc_sgsmooth(const QList &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); diff --git a/tools/lammps-gui/preferences.cpp b/tools/lammps-gui/preferences.cpp index 4b59e6c155..6b0d3f796f 100644 --- a/tools/lammps-gui/preferences.cpp +++ b/tools/lammps-gui/preferences.cpp @@ -217,6 +217,10 @@ void Preferences::accept() if (field) settings->setValue("xlabel", field->text()); combo = tabWidget->findChild("smoothchoice"); if (combo) settings->setValue("smoothchoice", combo->currentIndex()); + combo = tabWidget->findChild("rawbrush"); + if (combo) settings->setValue("rawbrush", combo->currentIndex()); + combo = tabWidget->findChild("smoothbrush"); + if (combo) settings->setValue("smoothbrush", combo->currentIndex()); spin = tabWidget->findChild("smoothwindow"); if (spin) settings->setValue("smoothwindow", spin->value()); spin = tabWidget->findChild("smoothorder"); @@ -308,7 +312,7 @@ GeneralTab::GeneralTab(QSettings *_settings, LammpsWrapper *_lammps, QWidget *pa auto https_proxy = QString::fromLocal8Bit(qgetenv("https_proxy")); if (https_proxy.isEmpty()) { - https_proxy = settings->value("https_proxy", "").toString(); + https_proxy = settings->value("https_proxy", "").toString(); auto *proxyedit = new QLineEdit(https_proxy); proxyedit->setObjectName("proxyval"); gridlayout->addWidget(proxyedit, 3, 1); @@ -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);