diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 194b268..b0ef184 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -31,7 +31,8 @@ SOURCES += main.cpp\ dbcmaineditor.cpp \ dbcsignaleditor.cpp \ framefileio.cpp \ - filecomparatorwindow.cpp + filecomparatorwindow.cpp \ + mainsettingsdialog.cpp HEADERS += mainwindow.h \ can_structs.h \ @@ -53,7 +54,8 @@ HEADERS += mainwindow.h \ dbcsignaleditor.h \ framefileio.h \ config.h \ - filecomparatorwindow.h + filecomparatorwindow.h \ + mainsettingsdialog.h FORMS += mainwindow.ui \ graphingwindow.ui \ @@ -65,7 +67,8 @@ FORMS += mainwindow.ui \ framesenderwindow.ui \ dbcmaineditor.ui \ dbcsignaleditor.ui \ - filecomparatorwindow.ui + filecomparatorwindow.ui \ + mainsettingsdialog.ui DISTFILES += diff --git a/config.h b/config.h index 35d9393..65a1be2 100644 --- a/config.h +++ b/config.h @@ -1,7 +1,7 @@ #ifndef CONFIG #define CONFIG -#define VERSION 115 +#define VERSION 116 #endif // CONFIG diff --git a/mainsettingsdialog.cpp b/mainsettingsdialog.cpp new file mode 100644 index 0000000..0cae4f2 --- /dev/null +++ b/mainsettingsdialog.cpp @@ -0,0 +1,60 @@ +#include "mainsettingsdialog.h" +#include "ui_mainsettingsdialog.h" + +MainSettingsDialog::MainSettingsDialog(QWidget *parent) : + QDialog(parent), + ui(new Ui::MainSettingsDialog) +{ + ui->setupUi(this); + + settings = new QSettings(); + + //update the GUI with all the settings we have stored giving things + //defaults if nothing was stored (if this is the first time) + ui->cbDisplayHex->setChecked(settings->value("Main/UseHex", true).toBool()); + ui->cbFlowAutoRef->setChecked(settings->value("FlowView/AutoRef", false).toBool()); + ui->cbFlowUseTimestamp->setChecked(settings->value("FlowView/UseTimestamp", true).toBool()); + ui->cbInfoAutoExpand->setChecked(settings->value("InfoCompare/AutoExpand", false).toBool()); + ui->cbMainAutoScroll->setChecked(settings->value("Main/AutoScroll", false).toBool()); + ui->cbPlaybackLoop->setChecked(settings->value("Playback/AutoLoop", false).toBool()); + ui->cbRestorePositions->setChecked(settings->value("Main/SaveRestorePositions", true).toBool()); + ui->cbValidate->setChecked(settings->value("Main/ValidateComm", true).toBool()); + ui->spinPlaybackSpeed->setValue(settings->value("Playback/DefSpeed", 5).toInt()); + + //just for simplicity they all call the same function and that function updates all settings at once + connect(ui->cbDisplayHex, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbFlowAutoRef, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbFlowUseTimestamp, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbInfoAutoExpand, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbMainAutoScroll, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbPlaybackLoop, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbRestorePositions, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->cbValidate, SIGNAL(toggled(bool)), this, SLOT(updateSettings())); + connect(ui->spinPlaybackSpeed, SIGNAL(valueChanged(int)), this, SLOT(updateSettings())); +} + +MainSettingsDialog::~MainSettingsDialog() +{ + delete ui; + delete settings; +} + +void MainSettingsDialog::closeEvent(QCloseEvent *event) +{ + settings->sync(); +} + +void MainSettingsDialog::updateSettings() +{ + settings->setValue("Main/UseHex", ui->cbDisplayHex->isChecked()); + settings->setValue("FlowView/AutoRef", ui->cbFlowAutoRef->isChecked()); + settings->setValue("FlowView/UseTimestamp", ui->cbFlowUseTimestamp->isChecked()); + settings->setValue("InfoCompare/AutoExpand", ui->cbInfoAutoExpand->isChecked()); + settings->setValue("Main/AutoScroll", ui->cbMainAutoScroll->isChecked()); + settings->setValue("Playback/AutoLoop", ui->cbPlaybackLoop->isChecked()); + settings->setValue("Main/SaveRestorePositions", ui->cbRestorePositions->isChecked()); + settings->setValue("Main/ValidateComm", ui->cbValidate->isChecked()); + settings->setValue("Playback/DefSpeed", ui->spinPlaybackSpeed->value()); + + settings->sync(); +} diff --git a/mainsettingsdialog.h b/mainsettingsdialog.h new file mode 100644 index 0000000..d350d00 --- /dev/null +++ b/mainsettingsdialog.h @@ -0,0 +1,29 @@ +#ifndef MAINSETTINGSDIALOG_H +#define MAINSETTINGSDIALOG_H + +#include +#include + +namespace Ui { +class MainSettingsDialog; +} + +class MainSettingsDialog : public QDialog +{ + Q_OBJECT + +public: + explicit MainSettingsDialog(QWidget *parent = 0); + ~MainSettingsDialog(); + +private slots: + void updateSettings(); + +private: + Ui::MainSettingsDialog *ui; + QSettings *settings; + + void closeEvent(QCloseEvent *event); +}; + +#endif // MAINSETTINGSDIALOG_H diff --git a/mainsettingsdialog.ui b/mainsettingsdialog.ui new file mode 100644 index 0000000..87d4b43 --- /dev/null +++ b/mainsettingsdialog.ui @@ -0,0 +1,140 @@ + + + MainSettingsDialog + + + + 0 + 0 + 400 + 580 + + + + Main Settings + + + + + + General Settings: + + + + + + Save/Restore window positions and sizes + + + + + + + Display values as hexadecimal + + + + + + + Validate GVRET connection + + + + + + + + + + Main Form Settings: + + + + + + Autoscroll main frame window by default + + + + + + + + + + Flowview Settings: + + + + + + Use timestamp mode by default + + + + + + + Set Auto Reference by default + + + + + + + + + + Playback Window Settings: + + + + + + Loop by default + + + + + + + + + Default playback speed (ms) + + + + + + + 1000 + + + + + + + + + + + + File Info and Comparator Settings: + + + + + + Auto expand all nodes + + + + + + + + + + + diff --git a/mainwindow.cpp b/mainwindow.cpp index 819e0d1..3b1bbf7 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -38,6 +38,11 @@ MainWindow::MainWindow(QWidget *parent) : { ui->setupUi(this); + //These things are used by QSettings to set up setting storage + QCoreApplication::setOrganizationName("EVTV"); + QCoreApplication::setOrganizationDomain("evtv.me"); + QCoreApplication::setApplicationName("SavvyCAN"); + selfRef = this; this->setWindowTitle("Savvy CAN V" + QString::number(VERSION)); @@ -102,6 +107,7 @@ MainWindow::MainWindow(QWidget *parent) : frameSenderWindow = NULL; dbcMainEditor = NULL; comparatorWindow = NULL; + settingsDialog = NULL; dbcHandler = new DBCHandler; bDirty = false; @@ -131,6 +137,7 @@ MainWindow::MainWindow(QWidget *parent) : connect(ui->actionSingle_Multi_State, SIGNAL(triggered(bool)), this, SLOT(showSingleMultiWindow())); connect(ui->actionFile_Comparison, SIGNAL(triggered(bool)), this, SLOT(showComparisonWindow())); connect(ui->btnNormalize, SIGNAL(clicked(bool)), this, SLOT(normalizeTiming())); + connect(ui->actionPreferences, SIGNAL(triggered(bool)), this, SLOT(showSettingsDialog())); lbStatusConnected.setText(tr("Not connected")); updateFileStatus(); @@ -159,6 +166,7 @@ MainWindow::~MainWindow() { serialWorkerThread.quit(); serialWorkerThread.wait(); + //delete worker; if (graphingWindow) { @@ -202,6 +210,12 @@ MainWindow::~MainWindow() delete dbcMainEditor; } + if (settingsDialog) + { + settingsDialog->close(); + delete settingsDialog; + } + delete ui; delete dbcHandler; model->clearFrames(); @@ -587,6 +601,12 @@ void MainWindow::gotDeviceInfo(int build, int swCAN) lbStatusConnected.setText(str); } +void MainWindow::showSettingsDialog() +{ + if (!settingsDialog) settingsDialog = new MainSettingsDialog(); + settingsDialog->show(); +} + void MainWindow::showGraphingWindow() { if (!graphingWindow) graphingWindow = new GraphingWindow(model->getListReference()); diff --git a/mainwindow.h b/mainwindow.h index d3527f6..36715fe 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -16,6 +16,7 @@ #include "filecomparatorwindow.h" #include "dbchandler.h" #include "dbcmaineditor.h" +#include "mainsettingsdialog.h" namespace Ui { class MainWindow; @@ -47,6 +48,7 @@ private slots: void showRangeWindow(); void showFuzzyScopeWindow(); void showComparisonWindow(); + void showSettingsDialog(); void exitApp(); void handleSaveDecoded(); void changeBaudRates(); @@ -97,6 +99,7 @@ private: FrameSenderWindow *frameSenderWindow; DBCMainEditor *dbcMainEditor; FileComparatorWindow *comparatorWindow; + MainSettingsDialog *settingsDialog; //various private storage QLabel lbStatusConnected; diff --git a/mainwindow.ui b/mainwindow.ui index ce7faad..653f26b 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -280,20 +280,14 @@ + + - - - TopToolBarArea - - - false - - @@ -375,6 +369,11 @@ File Comparison + + + Preferences + +