diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -38,6 +38,7 @@ #include "utils.h" #include "defines.h" #include "version.h" +#include "setting_defines.h" #if defined(Q_OS_WIN) && defined(QT_STATIC) #include @@ -433,18 +434,18 @@ void MainWindow::loadAllSettings(QSettin void MainWindow::saveMWSettings(QSettings* settings) { // save window geometry - settings->beginGroup("MainWindow"); - settings->setValue("size", size()); - settings->setValue("pos", pos()); + settings->beginGroup(SettingGroup_MainWindow); + settings->setValue(SG_MainWindow_Size, size()); + settings->setValue(SG_MainWindow_Pos, pos()); settings->endGroup(); } void MainWindow::loadMWSettings(QSettings* settings) { // load window geometry - settings->beginGroup("MainWindow"); - resize(settings->value("size", size()).toSize()); - move(settings->value("pos", pos()).toPoint()); + settings->beginGroup(SettingGroup_MainWindow); + resize(settings->value(SG_MainWindow_Size, size()).toSize()); + move(settings->value(SG_MainWindow_Pos, pos()).toPoint()); settings->endGroup(); } diff --git a/src/portcontrol.cpp b/src/portcontrol.cpp --- a/src/portcontrol.cpp +++ b/src/portcontrol.cpp @@ -25,6 +25,8 @@ #include #include #include + +#include "setting_defines.h" #include "utils.h" #define TBPORTLIST_MINWIDTH (200) @@ -341,14 +343,13 @@ QString PortControl::currentFlowControlT void PortControl::saveSettings(QSettings* settings) { - settings->beginGroup("Port"); - settings->setValue("selectedPort", selectedPortName()); - settings->setValue("baudRate", ui->cbBaudRate->currentText()); - settings->setValue("parity", currentParityText()); - settings->setValue("dataBits", dataBitsButtons.checkedId()); - settings->setValue("stopBits", stopBitsButtons.checkedId()); - settings->setValue("flowControl", currentFlowControlText()); - + settings->beginGroup(SettingGroup_Port); + settings->setValue(SG_Port_SelectedPort, selectedPortName()); + settings->setValue(SG_Port_BaudRate, ui->cbBaudRate->currentText()); + settings->setValue(SG_Port_Parity, currentParityText()); + settings->setValue(SG_Port_DataBits, dataBitsButtons.checkedId()); + settings->setValue(SG_Port_StopBits, stopBitsButtons.checkedId()); + settings->setValue(SG_Port_FlowControl, currentFlowControlText()); settings->endGroup(); } @@ -357,10 +358,10 @@ void PortControl::loadSettings(QSettings // make sure the port is closed if (serialPort->isOpen()) togglePort(); - settings->beginGroup("Port"); + settings->beginGroup(SettingGroup_Port); // set port name if it exists in the current list otherwise ignore - QString portName = settings->value("selectedPort", QString()).toString(); + QString portName = settings->value(SG_Port_SelectedPort, QString()).toString(); if (!portName.isEmpty()) { int index = portList.indexOfName(portName); @@ -369,26 +370,26 @@ void PortControl::loadSettings(QSettings // load baud rate setting if it exists in baud rate list QString baudSetting = settings->value( - "baudRate", ui->cbBaudRate->currentText()).toString(); + SG_Port_BaudRate, ui->cbBaudRate->currentText()).toString(); int baudIndex = ui->cbBaudRate->findText(baudSetting); if (baudIndex > -1) ui->cbBaudRate->setCurrentIndex(baudIndex); // load parity setting QString parityText = - settings->value("parity", currentParityText()).toString(); + settings->value(SG_Port_Parity, currentParityText()).toString(); QSerialPort::Parity paritySetting = paritySettingMap.key( parityText, (QSerialPort::Parity) parityButtons.checkedId()); parityButtons.button(paritySetting)->setChecked(true); // load number of bits - int dataBits = settings->value("dataBits", dataBitsButtons.checkedId()).toInt(); + int dataBits = settings->value(SG_Port_Parity, dataBitsButtons.checkedId()).toInt(); if (dataBits >=5 && dataBits <= 8) { dataBitsButtons.button((QSerialPort::DataBits) dataBits)->setChecked(true); } // load stop bits - int stopBits = settings->value("stopBits", stopBitsButtons.checkedId()).toInt(); + int stopBits = settings->value(SG_Port_StopBits, stopBitsButtons.checkedId()).toInt(); if (stopBits == QSerialPort::OneStop) { ui->rb1StopBit->setChecked(true); @@ -400,7 +401,7 @@ void PortControl::loadSettings(QSettings // load flow control QString flowControlSetting = - settings->value("flowControl", currentFlowControlText()).toString(); + settings->value(SG_Port_FlowControl, currentFlowControlText()).toString(); if (flowControlSetting == "hardware") { ui->rbHardwareControl->setChecked(true); diff --git a/src/setting_defines.h b/src/setting_defines.h new file mode 100644 --- /dev/null +++ b/src/setting_defines.h @@ -0,0 +1,42 @@ +/* + Copyright © 2016 Hasan Yavuz Özderya + + This file is part of serialplot. + + serialplot is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + serialplot is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with serialplot. If not, see . +*/ + +#ifndef SETTING_DEFINES_H +#define SETTING_DEFINES_H + +const char SettingGroup_MainWindow[] = "MainWindow"; +const char SettingGroup_Port[] = "Port"; +const char SettingGroup_DataFormat[] = "DataFormat"; +const char SettingGroup_Channels[] = "Channels"; +const char SettingGroup_Plot[] = "Plot"; +const char SettingGroup_Commands[] = "Commands"; + +// mainwindow setting keys +const char SG_MainWindow_Size[] = "size"; +const char SG_MainWindow_Pos[] = "pos"; + +// port setting keys +const char SG_Port_SelectedPort[] = "selectedPort"; +const char SG_Port_BaudRate[] = "baudRate"; +const char SG_Port_Parity[] = "parity"; +const char SG_Port_DataBits[] = "dataBits"; +const char SG_Port_StopBits[] = "stopBits"; +const char SG_Port_FlowControl[] = "flowControl"; + +#endif // SETTING_DEFINES_H