Customizable graph colors

This commit is contained in:
Jan Käberich 2020-10-22 21:12:33 +02:00
parent 978ac89aa9
commit 74e068d8d1
22 changed files with 266 additions and 97 deletions

View File

@ -5,6 +5,7 @@ HEADERS += \
Calibration/calkit.h \ Calibration/calkit.h \
Calibration/calkitdialog.h \ Calibration/calkitdialog.h \
Calibration/measurementmodel.h \ Calibration/measurementmodel.h \
CustomWidgets/colorpickerbutton.h \
CustomWidgets/siunitedit.h \ CustomWidgets/siunitedit.h \
CustomWidgets/tilewidget.h \ CustomWidgets/tilewidget.h \
CustomWidgets/toggleswitch.h \ CustomWidgets/toggleswitch.h \
@ -47,6 +48,7 @@ SOURCES += \
Calibration/calkit.cpp \ Calibration/calkit.cpp \
Calibration/calkitdialog.cpp \ Calibration/calkitdialog.cpp \
Calibration/measurementmodel.cpp \ Calibration/measurementmodel.cpp \
CustomWidgets/colorpickerbutton.cpp \
CustomWidgets/qwtplotpiecewisecurve.cpp \ CustomWidgets/qwtplotpiecewisecurve.cpp \
CustomWidgets/siunitedit.cpp \ CustomWidgets/siunitedit.cpp \
CustomWidgets/tilewidget.cpp \ CustomWidgets/tilewidget.cpp \

View File

@ -0,0 +1,35 @@
#include "colorpickerbutton.h"
#include <QColorDialog>
ColorPickerButton::ColorPickerButton(QWidget *parent)
: QPushButton(parent)
{
color = Qt::white;
connect(this, &ColorPickerButton::clicked, this, &ColorPickerButton::changeColor);
updateBackground();
}
void ColorPickerButton::setColor(const QColor &color)
{
this->color = color;
updateBackground();
}
const QColor &ColorPickerButton::getColor()
{
return color;
}
void ColorPickerButton::changeColor()
{
auto newColor = QColorDialog::getColor(color, parentWidget(), "Select color", QColorDialog::DontUseNativeDialog);
if(newColor.isValid() && newColor != color) {
setColor(newColor);
emit colorChanged(newColor);
}
}
void ColorPickerButton::updateBackground()
{
setStyleSheet("background-color:"+color.name());
}

View File

@ -0,0 +1,23 @@
#ifndef COLORPICKERBUTTON_H
#define COLORPICKERBUTTON_H
#include <QPushButton>
class ColorPickerButton : public QPushButton
{
Q_OBJECT
public:
ColorPickerButton(QWidget *parent = nullptr);
void setColor(const QColor& color);
const QColor& getColor();
signals:
void colorChanged(const QColor& color);
private slots:
void changeColor();
private:
void updateBackground();
QColor color;
};
#endif // COLORPICKERBUTTON_H

View File

@ -6,6 +6,8 @@ Generator::Generator(AppWindow *window)
{ {
central = new SignalgeneratorWidget(); central = new SignalgeneratorWidget();
auto pref = Preferences::getInstance();
// set initial values // set initial values
if(pref.Startup.RememberSweepSettings) { if(pref.Startup.RememberSweepSettings) {
QSettings s; QSettings s;

View File

@ -184,6 +184,7 @@ SpectrumAnalyzer::SpectrumAnalyzer(AppWindow *window)
qRegisterMetaType<Protocol::SpectrumAnalyzerResult>("SpectrumResult"); qRegisterMetaType<Protocol::SpectrumAnalyzerResult>("SpectrumResult");
// Set initial sweep settings // Set initial sweep settings
auto pref = Preferences::getInstance();
if(pref.Startup.RememberSweepSettings) { if(pref.Startup.RememberSweepSettings) {
LoadSweepSettings(); LoadSweepSettings();
} else { } else {
@ -364,6 +365,7 @@ void SpectrumAnalyzer::ConstrainAndUpdateFrequencies()
void SpectrumAnalyzer::LoadSweepSettings() void SpectrumAnalyzer::LoadSweepSettings()
{ {
QSettings s; QSettings s;
auto pref = Preferences::getInstance();
settings.f_start = s.value("SAStart", pref.Startup.SA.start).toULongLong(); settings.f_start = s.value("SAStart", pref.Startup.SA.start).toULongLong();
settings.f_stop = s.value("SAStop", pref.Startup.SA.stop).toULongLong(); settings.f_stop = s.value("SAStop", pref.Startup.SA.stop).toULongLong();
ConstrainAndUpdateFrequencies(); ConstrainAndUpdateFrequencies();

View File

@ -1,6 +1,5 @@
#include "tracebodeplot.h" #include "tracebodeplot.h"
#include <QGridLayout> #include <QGridLayout>
#include <qwt_plot_grid.h>
#include "qwtplotpiecewisecurve.h" #include "qwtplotpiecewisecurve.h"
#include "qwt_series_data.h" #include "qwt_series_data.h"
#include "trace.h" #include "trace.h"
@ -13,9 +12,12 @@
#include <qwt_symbol.h> #include <qwt_symbol.h>
#include <qwt_picker_machine.h> #include <qwt_picker_machine.h>
#include "bodeplotaxisdialog.h" #include "bodeplotaxisdialog.h"
#include <preferences.h>
using namespace std; using namespace std;
set<TraceBodePlot*> TraceBodePlot::allPlots;
static double AxisTransformation(TraceBodePlot::YAxisType type, complex<double> data) { static double AxisTransformation(TraceBodePlot::YAxisType type, complex<double> data) {
switch(type) { switch(type) {
case TraceBodePlot::YAxisType::Magnitude: return 20*log10(abs(data)); break; case TraceBodePlot::YAxisType::Magnitude: return 20*log10(abs(data)); break;
@ -58,16 +60,14 @@ TraceBodePlot::TraceBodePlot(TraceModel &model, QWidget *parent)
selectedMarker(nullptr) selectedMarker(nullptr)
{ {
plot = new QwtPlot(this); plot = new QwtPlot(this);
plot->setCanvasBackground(Background);
auto pal = plot->palette();
pal.setColor(QPalette::Window, Background);
pal.setColor(QPalette::WindowText, Border);
pal.setColor(QPalette::Text, Border);
auto canvas = new QwtPlotCanvas(plot); auto canvas = new QwtPlotCanvas(plot);
canvas->setFrameStyle(QFrame::Plain); canvas->setFrameStyle(QFrame::Plain);
plot->setCanvas(canvas); plot->setCanvas(canvas);
plot->setPalette(pal);
plot->setAutoFillBackground(true); plot->setAutoFillBackground(true);
grid = new QwtPlotGrid();
grid->attach(plot);
setColorFromPreferences();
auto selectPicker = new BodeplotPicker(plot->xBottom, plot->yLeft, QwtPicker::NoRubberBand, QwtPicker::ActiveOnly, plot->canvas()); auto selectPicker = new BodeplotPicker(plot->xBottom, plot->yLeft, QwtPicker::NoRubberBand, QwtPicker::ActiveOnly, plot->canvas());
selectPicker->setStateMachine(new QwtPickerClickPointMachine); selectPicker->setStateMachine(new QwtPickerClickPointMachine);
@ -81,15 +81,11 @@ TraceBodePlot::TraceBodePlot(TraceModel &model, QWidget *parent)
// Marker movement // Marker movement
connect(drawPicker, SIGNAL(moved(QPointF)), this, SLOT(moved(QPointF))); connect(drawPicker, SIGNAL(moved(QPointF)), this, SLOT(moved(QPointF)));
QwtPlotGrid *grid = new QwtPlotGrid();
grid->setMajorPen(QPen(Divisions, 1.0, Qt::DotLine));
grid->attach(plot);
auto layout = new QGridLayout; auto layout = new QGridLayout;
layout->addWidget(plot); layout->addWidget(plot);
layout->setContentsMargins(0, 0, 0, 0); layout->setContentsMargins(0, 0, 0, 0);
setLayout(layout); setLayout(layout);
plot->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); plot->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
// plot->plotLayout()->setAlignCanvasToScales(true);
initializeTraceInfo(model); initializeTraceInfo(model);
setAutoFillBackground(true); setAutoFillBackground(true);
@ -101,6 +97,8 @@ TraceBodePlot::TraceBodePlot(TraceModel &model, QWidget *parent)
setXAxis(true, 0, 6000000000, 600000000); setXAxis(true, 0, 6000000000, 600000000);
// get notified when the span changes // get notified when the span changes
connect(&model, &TraceModel::SpanChanged, this, qOverload<double, double>(&TraceBodePlot::setXAxis)); connect(&model, &TraceModel::SpanChanged, this, qOverload<double, double>(&TraceBodePlot::setXAxis));
allPlots.insert(this);
} }
TraceBodePlot::~TraceBodePlot() TraceBodePlot::~TraceBodePlot()
@ -111,6 +109,7 @@ TraceBodePlot::~TraceBodePlot()
} }
} }
delete drawPicker; delete drawPicker;
allPlots.erase(this);
} }
void TraceBodePlot::setXAxis(double min, double max) void TraceBodePlot::setXAxis(double min, double max)
@ -187,32 +186,16 @@ void TraceBodePlot::enableTrace(Trace *t, bool enabled)
} }
} }
void TraceBodePlot::updateGraphColors()
{
for(auto p : allPlots) {
p->setColorFromPreferences();
}
}
void TraceBodePlot::updateContextMenu() void TraceBodePlot::updateContextMenu()
{ {
contextmenu->clear(); contextmenu->clear();
// for(int axis = 0;axis < 2;axis++) {
// QMenu *axisMenu;
// if(axis == 0) {
// axisMenu = contextmenu->addMenu("Primary Axis");
// } else {
// axisMenu = contextmenu->addMenu("Secondary Axis");
// }
// auto group = new QActionGroup(this);
// for(int i=0;i<(int) YAxisType::Last;i++) {
// auto action = new QAction(AxisTypeToName((YAxisType) i));
// action->setCheckable(true);
// group->addAction(action);
// if(YAxis[axis].type == (YAxisType) i) {
// action->setChecked(true);
// }
// connect(action, &QAction::triggered, [=](bool active) {
// if(active) {
// setYAxisType(axis, (YAxisType) i);
// }
// });
// }
// axisMenu->addActions(group->actions());
// }
auto setup = new QAction("Axis setup..."); auto setup = new QAction("Axis setup...");
connect(setup, &QAction::triggered, [this]() { connect(setup, &QAction::triggered, [this]() {
auto setup = new BodeplotAxisDialog(this); auto setup = new BodeplotAxisDialog(this);
@ -483,13 +466,18 @@ void TraceBodePlot::moved(const QPointF pos)
if(!selectedMarker || !selectedCurve) { if(!selectedMarker || !selectedCurve) {
return; return;
} }
// int index = selectedCurve->closestPoint(pos.toPoint());
// qDebug() << index;
// if(index < 0) {
// // unable to find closest point
// return;
// }
// selectedMarker->setFrequency(selectedCurve->sample(index).x());
selectedMarker->setFrequency(pos.x()); selectedMarker->setFrequency(pos.x());
} }
void TraceBodePlot::setColorFromPreferences()
{
auto pref = Preferences::getInstance();
plot->setCanvasBackground(pref.General.graphColors.background);
auto pal = plot->palette();
pal.setColor(QPalette::Window, pref.General.graphColors.background);
pal.setColor(QPalette::WindowText, pref.General.graphColors.axis);
pal.setColor(QPalette::Text, pref.General.graphColors.axis);
plot->setPalette(pal);
grid->setPen(pref.General.graphColors.divisions);
}

View File

@ -7,7 +7,7 @@
#include <qwt_plot_curve.h> #include <qwt_plot_curve.h>
#include <qwt_series_data.h> #include <qwt_series_data.h>
#include <qwt_plot_marker.h> #include <qwt_plot_marker.h>
#include <qwt_plot_grid.h>
#include <qwt_plot_picker.h> #include <qwt_plot_picker.h>
// Derived plotpicker, exposing transformation functions // Derived plotpicker, exposing transformation functions
@ -45,6 +45,9 @@ public:
void setXAxis(bool autorange, double min, double max, double div); void setXAxis(bool autorange, double min, double max, double div);
void enableTrace(Trace *t, bool enabled) override; void enableTrace(Trace *t, bool enabled) override;
// Applies potentially changed colors to all bodeplots
static void updateGraphColors();
protected: protected:
virtual void updateContextMenu(); virtual void updateContextMenu();
virtual bool supported(Trace *t); virtual bool supported(Trace *t);
@ -60,6 +63,7 @@ private slots:
void clicked(const QPointF pos); void clicked(const QPointF pos);
void moved(const QPointF pos); void moved(const QPointF pos);
private: private:
void setColorFromPreferences();
QString AxisTypeToName(YAxisType type); QString AxisTypeToName(YAxisType type);
void enableTraceAxis(Trace *t, int axis, bool enabled); void enableTraceAxis(Trace *t, int axis, bool enabled);
bool supported(Trace *t, YAxisType type); bool supported(Trace *t, YAxisType type);
@ -89,10 +93,14 @@ private:
std::map<Trace*, CurveData> curves[2]; std::map<Trace*, CurveData> curves[2];
std::map<TraceMarker*, QwtPlotMarker*> markers; std::map<TraceMarker*, QwtPlotMarker*> markers;
QwtPlot *plot; QwtPlot *plot;
QwtPlotGrid *grid;
TraceMarker *selectedMarker; TraceMarker *selectedMarker;
QwtPlotCurve *selectedCurve; QwtPlotCurve *selectedCurve;
BodeplotPicker *drawPicker; BodeplotPicker *drawPicker;
// keep track of all created plots for changing colors
static std::set<TraceBodePlot*> allPlots;
}; };
#endif // TRACEBODEPLOT_H #endif // TRACEBODEPLOT_H

View File

@ -10,7 +10,10 @@ TraceEditDialog::TraceEditDialog(Trace &t, QWidget *parent) :
{ {
ui->setupUi(this); ui->setupUi(this);
ui->name->setText(t.name()); ui->name->setText(t.name());
setColor(trace.color()); ui->color->setColor(trace.color());
connect(ui->color, &ColorPickerButton::colorChanged, [=](const QColor& color){
trace.setColor(color);
});
ui->GSource->setId(ui->bLive, 0); ui->GSource->setId(ui->bLive, 0);
ui->GSource->setId(ui->bFile, 1); ui->GSource->setId(ui->bFile, 1);
@ -98,13 +101,6 @@ TraceEditDialog::~TraceEditDialog()
delete ui; delete ui;
} }
void TraceEditDialog::on_color_clicked()
{
auto color = QColorDialog::getColor(trace.color(), this, "Select color", QColorDialog::DontUseNativeDialog);
setColor(color);
}
void TraceEditDialog::on_buttonBox_accepted() void TraceEditDialog::on_buttonBox_accepted()
{ {
trace.setName(ui->name->text()); trace.setName(ui->name->text());
@ -139,13 +135,3 @@ void TraceEditDialog::on_buttonBox_accepted()
} }
delete this; delete this;
} }
void TraceEditDialog::setColor(QColor c)
{
QPalette pal = ui->color->palette();
pal.setColor(QPalette::Button, c);
ui->color->setAutoFillBackground(true);
ui->color->setPalette(pal);
ui->color->update();
trace.setColor(c);
}

View File

@ -17,11 +17,9 @@ public:
~TraceEditDialog(); ~TraceEditDialog();
private slots: private slots:
void on_color_clicked();
void on_buttonBox_accepted(); void on_buttonBox_accepted();
private: private:
void setColor(QColor c);
Ui::TraceEditDialog *ui; Ui::TraceEditDialog *ui;
Trace &trace; Trace &trace;
bool VNAtrace; bool VNAtrace;

View File

@ -37,7 +37,7 @@
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
<widget class="QPushButton" name="color"> <widget class="ColorPickerButton" name="color">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch> <horstretch>0</horstretch>
@ -162,6 +162,11 @@
<header>CustomWidgets/touchstoneimport.h</header> <header>CustomWidgets/touchstoneimport.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>ColorPickerButton</class>
<extends>QPushButton</extends>
<header>CustomWidgets/colorpickerbutton.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections> <connections>

View File

@ -117,6 +117,8 @@ QString TraceMarker::readableData()
return ret; return ret;
} }
break; break;
default:
return "Unknown marker type";
} }
} }
@ -378,6 +380,7 @@ void TraceMarker::adjustSettings(double value)
case Type::Delta: case Type::Delta:
default: default:
setFrequency(value); setFrequency(value);
/* no break */
case Type::Lowpass: case Type::Lowpass:
case Type::Highpass: case Type::Highpass:
case Type::Bandpass: case Type::Bandpass:
@ -396,6 +399,7 @@ void TraceMarker::update()
} }
switch(type) { switch(type) {
case Type::Manual: case Type::Manual:
case Type::Delta:
// nothing to do // nothing to do
break; break;
case Type::Maximum: case Type::Maximum:

View File

@ -1,8 +1,8 @@
#include "traceplot.h" #include "traceplot.h"
const QColor TracePlot::Background = QColor(0,0,0); //const QColor TracePlot::Background = QColor(0,0,0);
const QColor TracePlot::Border = QColor(255,255,255); //const QColor TracePlot::Border = QColor(255,255,255);
const QColor TracePlot::Divisions = QColor(255,255,255); //const QColor TracePlot::Divisions = QColor(255,255,255);
#include "tracemarker.h" #include "tracemarker.h"
std::set<TracePlot*> TracePlot::plots; std::set<TracePlot*> TracePlot::plots;

View File

@ -25,9 +25,9 @@ signals:
void deleted(TracePlot*); void deleted(TracePlot*);
protected: protected:
static const QColor Background;// = QColor(0,0,0); // static const QColor Background;// = QColor(0,0,0);
static const QColor Border;// = QColor(255,255,255); // static const QColor Border;// = QColor(255,255,255);
static const QColor Divisions;// = QColor(255,255,255); // static const QColor Divisions;// = QColor(255,255,255);
static constexpr int MinUpdateInterval = 100; static constexpr int MinUpdateInterval = 100;
// need to be called in derived class constructor // need to be called in derived class constructor
void initializeTraceInfo(TraceModel &model); void initializeTraceInfo(TraceModel &model);

View File

@ -4,6 +4,7 @@
#include <math.h> #include <math.h>
#include "tracemarker.h" #include "tracemarker.h"
#include <QDebug> #include <QDebug>
#include "preferences.h"
using namespace std; using namespace std;
@ -92,13 +93,15 @@ void TraceSmithChart::draw(QPainter * painter, double width_factor) {
// painter->setFont(font); // painter->setFont(font);
// painter->drawText(-512, -512, title); // painter->drawText(-512, -512, title);
auto pref = Preferences::getInstance();
// Outer circle // Outer circle
painter->setPen(QPen(Border, 1.5 * width_factor)); painter->setPen(QPen(pref.General.graphColors.axis, 1.5 * width_factor));
QRectF rectangle(-smithCoordMax, -smithCoordMax, 2*smithCoordMax, 2*smithCoordMax); QRectF rectangle(-smithCoordMax, -smithCoordMax, 2*smithCoordMax, 2*smithCoordMax);
painter->drawArc(rectangle, 0, 5760); painter->drawArc(rectangle, 0, 5760);
constexpr int Circles = 6; constexpr int Circles = 6;
painter->setPen(QPen(Divisions, 0.5 * width_factor, Qt::DashLine)); painter->setPen(QPen(pref.General.graphColors.divisions, 0.5 * width_factor, Qt::DashLine));
for(int i=1;i<Circles;i++) { for(int i=1;i<Circles;i++) {
rectangle.adjust(2*smithCoordMax/Circles, smithCoordMax/Circles, 0, -smithCoordMax/Circles); rectangle.adjust(2*smithCoordMax/Circles, smithCoordMax/Circles, 0, -smithCoordMax/Circles);
painter->drawArc(rectangle, 0, 5760); painter->drawArc(rectangle, 0, 5760);
@ -162,10 +165,11 @@ void TraceSmithChart::replot()
void TraceSmithChart::paintEvent(QPaintEvent * /* the event */) void TraceSmithChart::paintEvent(QPaintEvent * /* the event */)
{ {
auto pref = Preferences::getInstance();
QPainter painter(this); QPainter painter(this);
painter.setRenderHint(QPainter::Antialiasing); painter.setRenderHint(QPainter::Antialiasing);
painter.setBackground(QBrush(Background)); painter.setBackground(QBrush(pref.General.graphColors.background));
painter.fillRect(0, 0, width(), height(), QBrush(Background)); painter.fillRect(0, 0, width(), height(), QBrush(pref.General.graphColors.background));
double side = qMin(width(), height()) * screenUsage; double side = qMin(width(), height()) * screenUsage;

View File

@ -417,6 +417,7 @@ VNA::VNA(AppWindow *window)
qRegisterMetaType<Protocol::Datapoint>("Datapoint"); qRegisterMetaType<Protocol::Datapoint>("Datapoint");
// Set initial sweep settings // Set initial sweep settings
auto pref = Preferences::getInstance();
if(pref.Acquisition.alwaysExciteBothPorts) { if(pref.Acquisition.alwaysExciteBothPorts) {
settings.excitePort1 = 1; settings.excitePort1 = 1;
settings.excitePort2 = 1; settings.excitePort2 = 1;
@ -539,7 +540,7 @@ void VNA::UpdateStatusPanel()
void VNA::SettingsChanged() void VNA::SettingsChanged()
{ {
settings.suppressPeaks = pref.Acquisition.suppressPeaks ? 1 : 0; settings.suppressPeaks = Preferences::getInstance().Acquisition.suppressPeaks ? 1 : 0;
if(window->getDevice()) { if(window->getDevice()) {
window->getDevice()->Configure(settings); window->getDevice()->Configure(settings);
} }
@ -675,8 +676,7 @@ void VNA::SetAveraging(unsigned int averages)
void VNA::ExcitationRequired(bool port1, bool port2) void VNA::ExcitationRequired(bool port1, bool port2)
{ {
qDebug() << pref.Acquisition.alwaysExciteBothPorts; if(Preferences::getInstance().Acquisition.alwaysExciteBothPorts) {
if(pref.Acquisition.alwaysExciteBothPorts) {
port1 = true; port1 = true;
port2 = true; port2 = true;
} }
@ -771,6 +771,7 @@ void VNA::ConstrainAndUpdateFrequencies()
void VNA::LoadSweepSettings() void VNA::LoadSweepSettings()
{ {
auto pref = Preferences::getInstance();
QSettings s; QSettings s;
settings.f_start = s.value("SweepStart", pref.Startup.DefaultSweep.start).toULongLong(); settings.f_start = s.value("SweepStart", pref.Startup.DefaultSweep.start).toULongLong();
settings.f_stop = s.value("SweepStop", pref.Startup.DefaultSweep.stop).toULongLong(); settings.f_stop = s.value("SweepStop", pref.Startup.DefaultSweep.stop).toULongLong();

View File

@ -55,7 +55,7 @@ AppWindow::AppWindow(QWidget *parent)
QCoreApplication::setOrganizationName("VNA"); QCoreApplication::setOrganizationName("VNA");
QCoreApplication::setApplicationName("Application"); QCoreApplication::setApplicationName("Application");
pref.load(); Preferences::getInstance().load();
device = nullptr; device = nullptr;
ui->setupUi(this); ui->setupUi(this);
@ -108,9 +108,9 @@ AppWindow::AppWindow(QWidget *parent)
} }
}); });
connect(ui->actionPreferences, &QAction::triggered, [=](){ connect(ui->actionPreferences, &QAction::triggered, [=](){
qDebug() << pref.Acquisition.alwaysExciteBothPorts; Preferences::getInstance().edit();
pref.edit(); // settings might have changed, update necessary stuff
qDebug() << pref.Acquisition.alwaysExciteBothPorts; TraceBodePlot::updateGraphColors();
}); });
setWindowTitle("VNA"); setWindowTitle("VNA");
@ -131,7 +131,7 @@ AppWindow::AppWindow(QWidget *parent)
qRegisterMetaType<Protocol::Datapoint>("Datapoint"); qRegisterMetaType<Protocol::Datapoint>("Datapoint");
// List available devices // List available devices
if(UpdateDeviceList() && pref.Startup.ConnectToFirstDevice) { if(UpdateDeviceList() && Preferences::getInstance().Startup.ConnectToFirstDevice) {
// at least one device available // at least one device available
ConnectToDevice(); ConnectToDevice();
} }
@ -145,7 +145,7 @@ void AppWindow::closeEvent(QCloseEvent *event)
if(Mode::getActiveMode()) { if(Mode::getActiveMode()) {
Mode::getActiveMode()->deactivate(); Mode::getActiveMode()->deactivate();
} }
pref.store(); Preferences::getInstance().store();
QMainWindow::closeEvent(event); QMainWindow::closeEvent(event);
} }
@ -244,11 +244,6 @@ void AppWindow::CreateToolbars()
tb_reference->setObjectName("Reference Toolbar"); tb_reference->setObjectName("Reference Toolbar");
} }
Preferences &AppWindow::getPreferenceRef()
{
return pref;
}
int AppWindow::UpdateDeviceList() int AppWindow::UpdateDeviceList()
{ {
deviceActionGroup->setExclusive(true); deviceActionGroup->setExclusive(true);

View File

@ -34,8 +34,6 @@ public:
QStackedWidget *getCentral() const; QStackedWidget *getCentral() const;
Device *getDevice() const; Device *getDevice() const;
Preferences &getPreferenceRef();
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
private slots: private slots:
@ -60,8 +58,6 @@ private:
} reference; } reference;
} toolbars; } toolbars;
Preferences pref;
Device *device; Device *device;
DeviceLog deviceLog; DeviceLog deviceLog;
QString deviceSerial; QString deviceSerial;

View File

@ -10,7 +10,6 @@ QButtonGroup* Mode::modeButtonGroup = nullptr;
Mode::Mode(AppWindow *window, QString name) Mode::Mode(AppWindow *window, QString name)
: window(window), : window(window),
pref(window->getPreferenceRef()),
name(name), name(name),
central(nullptr) central(nullptr)
{ {

View File

@ -29,8 +29,6 @@ protected:
std::set<QToolBar*> toolbars; std::set<QToolBar*> toolbars;
std::set<QDockWidget*> docks; std::set<QDockWidget*> docks;
Preferences &pref;
private: private:
static Mode *activeMode; static Mode *activeMode;
static QWidget *cornerWidget; static QWidget *cornerWidget;

View File

@ -7,6 +7,8 @@
using namespace std; using namespace std;
Preferences Preferences::instance;
PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) : PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::PreferencesDialog), ui(new Ui::PreferencesDialog),
@ -100,6 +102,9 @@ PreferencesDialog::PreferencesDialog(Preferences *pref, QWidget *parent) :
p->Startup.SA.signalID = ui->StartupSASignalID->isChecked(); p->Startup.SA.signalID = ui->StartupSASignalID->isChecked();
p->Acquisition.alwaysExciteBothPorts = ui->AcquisitionAlwaysExciteBoth->isChecked(); p->Acquisition.alwaysExciteBothPorts = ui->AcquisitionAlwaysExciteBoth->isChecked();
p->Acquisition.suppressPeaks = ui->AcquisitionSuppressPeaks->isChecked(); p->Acquisition.suppressPeaks = ui->AcquisitionSuppressPeaks->isChecked();
p->General.graphColors.background = ui->GeneralGraphBackground->getColor();
p->General.graphColors.axis = ui->GeneralGraphAxis->getColor();
p->General.graphColors.divisions = ui->GeneralGraphDivisions->getColor();
accept(); accept();
}); });
@ -135,6 +140,10 @@ void PreferencesDialog::setInitialGUIState()
ui->AcquisitionAlwaysExciteBoth->setChecked(p->Acquisition.alwaysExciteBothPorts); ui->AcquisitionAlwaysExciteBoth->setChecked(p->Acquisition.alwaysExciteBothPorts);
ui->AcquisitionSuppressPeaks->setChecked(p->Acquisition.suppressPeaks); ui->AcquisitionSuppressPeaks->setChecked(p->Acquisition.suppressPeaks);
ui->GeneralGraphBackground->setColor(p->General.graphColors.background);
ui->GeneralGraphAxis->setColor(p->General.graphColors.axis);
ui->GeneralGraphDivisions->setColor(p->General.graphColors.divisions);
} }
void Preferences::load() void Preferences::load()

View File

@ -30,6 +30,9 @@ private:
class Preferences { class Preferences {
public: public:
static Preferences& getInstance() {
return instance;
}
void load(); void load();
void store(); void store();
void edit(); void edit();
@ -62,13 +65,22 @@ public:
bool alwaysExciteBothPorts; bool alwaysExciteBothPorts;
bool suppressPeaks; bool suppressPeaks;
} Acquisition; } Acquisition;
struct {
struct {
QColor background;
QColor axis;
QColor divisions;
} graphColors;
} General;
private: private:
Preferences(){};
static Preferences instance;
using SettingDescription = struct { using SettingDescription = struct {
QPointerVariant var; QPointerVariant var;
QString name; QString name;
QVariant def; QVariant def;
}; };
const std::array<SettingDescription, 17> descr = {{ const std::array<SettingDescription, 20> descr = {{
{&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true}, {&Startup.ConnectToFirstDevice, "Startup.ConnectToFirstDevice", true},
{&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false}, {&Startup.RememberSweepSettings, "Startup.RememberSweepSettings", false},
{&Startup.DefaultSweep.start, "Startup.DefaultSweep.start", 1000000.0}, {&Startup.DefaultSweep.start, "Startup.DefaultSweep.start", 1000000.0},
@ -86,6 +98,9 @@ private:
{&Startup.SA.signalID, "Startup.SA.signalID", true}, {&Startup.SA.signalID, "Startup.SA.signalID", true},
{&Acquisition.alwaysExciteBothPorts, "Acquisition.alwaysExciteBothPorts", true}, {&Acquisition.alwaysExciteBothPorts, "Acquisition.alwaysExciteBothPorts", true},
{&Acquisition.suppressPeaks, "Acquisition.suppressPeaks", true}, {&Acquisition.suppressPeaks, "Acquisition.suppressPeaks", true},
{&General.graphColors.background, "General.graphColors.background", QColor(Qt::black)},
{&General.graphColors.axis, "General.graphColors.axis", QColor(Qt::white)},
{&General.graphColors.divisions, "General.graphColors.divisions", QColor(Qt::gray)},
}}; }};
}; };

View File

@ -51,6 +51,11 @@
<string>Acquisition</string> <string>Acquisition</string>
</property> </property>
</item> </item>
<item>
<property name="text">
<string>General</string>
</property>
</item>
</widget> </widget>
</item> </item>
<item> <item>
@ -68,7 +73,7 @@
</size> </size>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>2</number>
</property> </property>
<widget class="QWidget" name="Startup"> <widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4"> <layout class="QHBoxLayout" name="horizontalLayout_4">
@ -449,6 +454,95 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="General">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QGroupBox" name="groupBox_5">
<property name="title">
<string>Graph colors</string>
</property>
<layout class="QFormLayout" name="formLayout_4">
<item row="0" column="0">
<widget class="QLabel" name="label_15">
<property name="text">
<string>Background:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="ColorPickerButton" name="GeneralGraphBackground">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_16">
<property name="text">
<string>Axis:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="ColorPickerButton" name="GeneralGraphAxis">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_17">
<property name="text">
<string>Divisions:</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="ColorPickerButton" name="GeneralGraphDivisions">
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -474,6 +568,11 @@
<extends>QLineEdit</extends> <extends>QLineEdit</extends>
<header>CustomWidgets/siunitedit.h</header> <header>CustomWidgets/siunitedit.h</header>
</customwidget> </customwidget>
<customwidget>
<class>ColorPickerButton</class>
<extends>QPushButton</extends>
<header>CustomWidgets/colorpickerbutton.h</header>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>