# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2016-09-04 17:56:19 # Node ID 3da4b54825738d3adaa1c038ee601e55ea78f04a # Parent c2fad2d38a6060d9113cc166283134e23115715d implemented settings for simple binary reader diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ add_executable(${PROGRAM_NAME} WIN32 src/framedreader.cpp src/framedreadersettings.cpp src/plotmanager.cpp + src/numberformat.cpp misc/windows_icon.rc ${UI_FILES} ${RES_FILES} diff --git a/src/binarystreamreader.cpp b/src/binarystreamreader.cpp --- a/src/binarystreamreader.cpp +++ b/src/binarystreamreader.cpp @@ -179,7 +179,6 @@ void BinaryStreamReader::onDataReady() delete channelSamples; } - template double BinaryStreamReader::readSampleAs() { T data; @@ -204,3 +203,13 @@ void BinaryStreamReader::addChannelData( _channelMan->addChannelData(channel, data, size); sampleCount += size; } + +void BinaryStreamReader::saveSettings(QSettings* settings) +{ + _settingsWidget.saveSettings(settings); +} + +void BinaryStreamReader::loadSettings(QSettings* settings) +{ + _settingsWidget.loadSettings(settings); +} diff --git a/src/binarystreamreader.h b/src/binarystreamreader.h --- a/src/binarystreamreader.h +++ b/src/binarystreamreader.h @@ -20,6 +20,8 @@ #ifndef BINARYSTREAMREADER_H #define BINARYSTREAMREADER_H +#include + #include "abstractreader.h" #include "binarystreamreadersettings.h" @@ -36,6 +38,10 @@ public: QWidget* settingsWidget(); unsigned numOfChannels(); void enable(bool enabled = true); + /// Stores settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads settings from a `QSettings`. + void loadSettings(QSettings* settings); public slots: void pause(bool); diff --git a/src/binarystreamreadersettings.cpp b/src/binarystreamreadersettings.cpp --- a/src/binarystreamreadersettings.cpp +++ b/src/binarystreamreadersettings.cpp @@ -21,6 +21,7 @@ #include "ui_binarystreamreadersettings.h" #include "utils.h" +#include "setting_defines.h" BinaryStreamReaderSettings::BinaryStreamReaderSettings(QWidget *parent) : QWidget(parent), @@ -61,3 +62,43 @@ Endianness BinaryStreamReaderSettings::e { return ui->endiBox->currentSelection(); } + +void BinaryStreamReaderSettings::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Binary); + settings->setValue(SG_Binary_NumOfChannels, numOfChannels()); + settings->setValue(SG_Binary_NumberFormat, numberFormatToStr(numberFormat())); + settings->setValue(SG_Binary_Endianness, + endianness() == LittleEndian ? "little" : "big"); + settings->endGroup(); +} + +void BinaryStreamReaderSettings::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Binary); + + // load number of channels + ui->spNumOfChannels->setValue( + settings->value(SG_Binary_NumOfChannels, numOfChannels()).toInt()); + + // load number format + NumberFormat nfSetting = + strToNumberFormat(settings->value(SG_Binary_NumberFormat, + QString()).toString()); + if (nfSetting == NumberFormat_INVALID) nfSetting = numberFormat(); + ui->nfBox->setSelection(nfSetting); + + // load endianness + QString endiannessSetting = + settings->value(SG_Binary_Endianness, QString()).toString(); + if (endiannessSetting == "little") + { + ui->endiBox->setSelection(LittleEndian); + } + else if (endiannessSetting == "big") + { + ui->endiBox->setSelection(BigEndian); + } // else don't change + + settings->endGroup(); +} diff --git a/src/binarystreamreadersettings.h b/src/binarystreamreadersettings.h --- a/src/binarystreamreadersettings.h +++ b/src/binarystreamreadersettings.h @@ -21,6 +21,8 @@ #define BINARYSTREAMREADERSETTINGS_H #include +#include + #include "numberformatbox.h" #include "endiannessbox.h" @@ -40,6 +42,11 @@ public: NumberFormat numberFormat(); Endianness endianness(); + /// Stores settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads settings from a `QSettings`. + void loadSettings(QSettings* settings); + signals: void numOfChannelsChanged(unsigned); void numberFormatChanged(NumberFormat); diff --git a/src/dataformatpanel.cpp b/src/dataformatpanel.cpp --- a/src/dataformatpanel.cpp +++ b/src/dataformatpanel.cpp @@ -169,6 +169,9 @@ void DataFormatPanel::saveSettings(QSett settings->setValue(SG_DataFormat_Format, format); settings->endGroup(); + + // save reader settings + bsReader.saveSettings(settings); } void DataFormatPanel::loadSettings(QSettings* settings) @@ -196,4 +199,7 @@ void DataFormatPanel::loadSettings(QSett } // else current selection stays settings->endGroup(); + + // load reader settings + bsReader.loadSettings(settings); } diff --git a/src/endiannessbox.cpp b/src/endiannessbox.cpp --- a/src/endiannessbox.cpp +++ b/src/endiannessbox.cpp @@ -48,3 +48,15 @@ Endianness EndiannessBox::currentSelecti return BigEndian; } } + +void EndiannessBox::setSelection(Endianness endianness) +{ + if (endianness == LittleEndian) + { + ui->rbLittleE->setChecked(true); + } + else // big endian + { + ui->rbBigE->setChecked(true); + } +} diff --git a/src/endiannessbox.h b/src/endiannessbox.h --- a/src/endiannessbox.h +++ b/src/endiannessbox.h @@ -40,7 +40,10 @@ public: explicit EndiannessBox(QWidget *parent = 0); ~EndiannessBox(); - Endianness currentSelection(); ///< currently selected endianness + /// currently selected endianness + Endianness currentSelection(); + /// change the currently selected endianness + void setSelection(Endianness endianness); signals: /// Signaled when endianness selection is changed diff --git a/src/numberformat.cpp b/src/numberformat.cpp new file mode 100644 --- /dev/null +++ b/src/numberformat.cpp @@ -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 . +*/ + +#include + +#include "numberformat.h" + +QMap mapping({ + {NumberFormat_uint8, "uint8"}, + {NumberFormat_uint16, "uint16"}, + {NumberFormat_uint32, "uint32"}, + {NumberFormat_int8, "int8"}, + {NumberFormat_int16, "int16"}, + {NumberFormat_int32, "int32"}, + {NumberFormat_float, "float"} + }); + +QString numberFormatToStr(NumberFormat nf) +{ + return mapping.value(nf); +} + +NumberFormat strToNumberFormat(QString str) +{ + return mapping.key(str, NumberFormat_INVALID); +} diff --git a/src/numberformat.h b/src/numberformat.h new file mode 100644 --- /dev/null +++ b/src/numberformat.h @@ -0,0 +1,43 @@ +/* + 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 NUMBERFORMAT_H +#define NUMBERFORMAT_H + +#include + +enum NumberFormat +{ + NumberFormat_uint8, + NumberFormat_uint16, + NumberFormat_uint32, + NumberFormat_int8, + NumberFormat_int16, + NumberFormat_int32, + NumberFormat_float, + NumberFormat_INVALID ///< used for error cases +}; + +/// Convert `NumberFormat` to string for representation +QString numberFormatToStr(NumberFormat nf); + +/// Convert string to `NumberFormat` +NumberFormat strToNumberFormat(QString str); + +#endif // NUMBERFORMAT_H diff --git a/src/numberformatbox.cpp b/src/numberformatbox.cpp --- a/src/numberformatbox.cpp +++ b/src/numberformatbox.cpp @@ -54,3 +54,8 @@ NumberFormat NumberFormatBox::currentSel { return (NumberFormat) buttonGroup.checkedId(); } + +void NumberFormatBox::setSelection(NumberFormat nf) +{ + buttonGroup.button(nf)->setChecked(true); +} diff --git a/src/numberformatbox.h b/src/numberformatbox.h --- a/src/numberformatbox.h +++ b/src/numberformatbox.h @@ -23,21 +23,12 @@ #include #include +#include "numberformat.h" + namespace Ui { class NumberFormatBox; } -enum NumberFormat -{ - NumberFormat_uint8, - NumberFormat_uint16, - NumberFormat_uint32, - NumberFormat_int8, - NumberFormat_int16, - NumberFormat_int32, - NumberFormat_float, -}; - class NumberFormatBox : public QWidget { Q_OBJECT @@ -46,7 +37,10 @@ public: explicit NumberFormatBox(QWidget *parent = 0); ~NumberFormatBox(); - NumberFormat currentSelection(); ///< returns the currently selected number format + /// returns the currently selected number format + NumberFormat currentSelection(); + /// change the currently selected number format + void setSelection(NumberFormat nf); signals: /// Signaled when number format selection is changed diff --git a/src/setting_defines.h b/src/setting_defines.h --- a/src/setting_defines.h +++ b/src/setting_defines.h @@ -23,6 +23,7 @@ const char SettingGroup_MainWindow[] = "MainWindow"; const char SettingGroup_Port[] = "Port"; const char SettingGroup_DataFormat[] = "DataFormat"; +const char SettingGroup_Binary[] = "DataFormat_Binary"; const char SettingGroup_Channels[] = "Channels"; const char SettingGroup_Plot[] = "Plot"; const char SettingGroup_Commands[] = "Commands"; @@ -44,4 +45,9 @@ const char SG_Port_FlowControl[] = "flow // data format panel keys const char SG_DataFormat_Format[] = "format"; +// binary stream reader keys +const char SG_Binary_NumOfChannels[] = "numOfChannels"; +const char SG_Binary_NumberFormat[] = "numberFormat"; +const char SG_Binary_Endianness[] = "endianness"; + #endif // SETTING_DEFINES_H