# HG changeset patch # User Hasan Yavuz ÖZDERYA # Date 2016-09-17 10:55:44 # Node ID 3b329010cce9a869e69792e55dd404f0f43e0f30 # Parent b4ed0efa2e8b298fc6828750e34f0b6aa1f7fab9 # Parent 1f184be53adee56667ddaa94858c70ae8cc247d1 Merge with settings 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/serialplot.pro b/serialplot.pro --- a/serialplot.pro +++ b/serialplot.pro @@ -66,7 +66,8 @@ SOURCES += \ src/asciireader.cpp \ src/demoreader.cpp \ src/framedreader.cpp \ - src/plotmanager.cpp + src/plotmanager.cpp \ + src/numberformat.cpp HEADERS += \ src/mainwindow.h \ @@ -103,7 +104,9 @@ HEADERS += \ src/asciireader.h \ src/demoreader.h \ src/framedreader.h \ - src/plotmanager.h + src/plotmanager.h \ + src/setting_defines.h \ + src/numberformat.h FORMS += \ src/mainwindow.ui \ diff --git a/src/asciireader.cpp b/src/asciireader.cpp --- a/src/asciireader.cpp +++ b/src/asciireader.cpp @@ -159,3 +159,13 @@ void AsciiReader::onDataReady() emit dataAdded(); } } + +void AsciiReader::saveSettings(QSettings* settings) +{ + _settingsWidget.saveSettings(settings); +} + +void AsciiReader::loadSettings(QSettings* settings) +{ + _settingsWidget.loadSettings(settings); +} diff --git a/src/asciireader.h b/src/asciireader.h --- a/src/asciireader.h +++ b/src/asciireader.h @@ -20,6 +20,8 @@ #ifndef ASCIIREADER_H #define ASCIIREADER_H +#include + #include "abstractreader.h" #include "asciireadersettings.h" @@ -32,6 +34,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/asciireadersettings.cpp b/src/asciireadersettings.cpp --- a/src/asciireadersettings.cpp +++ b/src/asciireadersettings.cpp @@ -18,10 +18,13 @@ */ #include "utils.h" +#include "setting_defines.h" #include "asciireadersettings.h" #include "ui_asciireadersettings.h" +#include + AsciiReaderSettings::AsciiReaderSettings(QWidget *parent) : QWidget(parent), ui(new Ui::AsciiReaderSettings) @@ -45,3 +48,40 @@ unsigned AsciiReaderSettings::numOfChann { return ui->spNumOfChannels->value(); } + +void AsciiReaderSettings::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_ASCII); + + // save number of channels setting + QString numOfChannelsSetting = QString::number(numOfChannels()); + if (numOfChannelsSetting == "0") numOfChannelsSetting = "auto"; + settings->setValue(SG_ASCII_NumOfChannels, numOfChannelsSetting); + + settings->endGroup(); +} + +void AsciiReaderSettings::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_ASCII); + + // load number of channels + QString numOfChannelsSetting = + settings->value(SG_ASCII_NumOfChannels, numOfChannels()).toString(); + + if (numOfChannelsSetting == "auto") + { + ui->spNumOfChannels->setValue(0); + } + else + { + bool ok; + int nc = numOfChannelsSetting.toInt(&ok); + if (ok) + { + ui->spNumOfChannels->setValue(nc); + } + } + + settings->endGroup(); +} diff --git a/src/asciireadersettings.h b/src/asciireadersettings.h --- a/src/asciireadersettings.h +++ b/src/asciireadersettings.h @@ -21,6 +21,7 @@ #define ASCIIREADERSETTINGS_H #include +#include namespace Ui { class AsciiReaderSettings; @@ -35,6 +36,10 @@ public: ~AsciiReaderSettings(); unsigned numOfChannels(); + /// Stores settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads settings from a `QSettings`. + void loadSettings(QSettings* settings); signals: void numOfChannelsChanged(unsigned); diff --git a/src/binarystreamreader.cpp b/src/binarystreamreader.cpp --- a/src/binarystreamreader.cpp +++ b/src/binarystreamreader.cpp @@ -115,6 +115,9 @@ void BinaryStreamReader::onNumberFormatC sampleSize = 4; readSample = &BinaryStreamReader::readSampleAs; break; + case NumberFormat_INVALID: + Q_ASSERT(1); // never + break; } } @@ -179,7 +182,6 @@ void BinaryStreamReader::onDataReady() delete channelSamples; } - template double BinaryStreamReader::readSampleAs() { T data; @@ -204,3 +206,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/channelmanager.cpp b/src/channelmanager.cpp --- a/src/channelmanager.cpp +++ b/src/channelmanager.cpp @@ -17,11 +17,12 @@ along with serialplot. If not, see . */ -#include "channelmanager.h" - #include #include +#include "channelmanager.h" +#include "setting_defines.h" + ChannelManager::ChannelManager(unsigned numberOfChannels, unsigned numberOfSamples, QObject *parent) : QObject(parent) { @@ -143,3 +144,29 @@ void ChannelManager::addChannelData(unsi { channelBuffer(channel)->addSamples(data, size); } + +void ChannelManager::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Channels); + settings->beginWriteArray(SG_Channels_Channel); + for (unsigned i = 0; i < numOfChannels(); i++) + { + settings->setArrayIndex(i); + settings->setValue(SG_Channels_Name, channelName(i)); + } + settings->endArray(); + settings->endGroup(); +} + +void ChannelManager::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Channels); + settings->beginReadArray(SG_Channels_Channel); + for (unsigned i = 0; i < numOfChannels(); i++) + { + settings->setArrayIndex(i); + setChannelName(i, settings->value(SG_Channels_Name, channelName(i)).toString()); + } + settings->endArray(); + settings->endGroup(); +} diff --git a/src/channelmanager.h b/src/channelmanager.h --- a/src/channelmanager.h +++ b/src/channelmanager.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "framebuffer.h" @@ -39,6 +40,10 @@ public: FrameBuffer* channelBuffer(unsigned channel); QStringListModel* channelNames(); QString channelName(unsigned channel); + /// Stores channel names into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads channel names from a `QSettings`. + void loadSettings(QSettings* settings); signals: void numOfChannelsChanged(unsigned value); diff --git a/src/commandpanel.cpp b/src/commandpanel.cpp --- a/src/commandpanel.cpp +++ b/src/commandpanel.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -17,11 +17,12 @@ along with serialplot. If not, see . */ +#include +#include + #include "commandpanel.h" #include "ui_commandpanel.h" - -#include -#include +#include "setting_defines.h" CommandPanel::CommandPanel(QSerialPort* port, QWidget *parent) : QWidget(parent), @@ -46,15 +47,15 @@ CommandPanel::CommandPanel(QSerialPort* _menu.addSeparator(); command_name_counter = 0; - newCommand(); // add an empty slot by default } CommandPanel::~CommandPanel() { + commands.clear(); // UI will 'delete' actual objects delete ui; } -void CommandPanel::newCommand() +CommandWidget* CommandPanel::newCommand() { auto command = new CommandWidget(); command_name_counter++; @@ -64,6 +65,14 @@ void CommandPanel::newCommand() connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand); connect(command, &CommandWidget::focusRequested, this, &CommandPanel::focusRequested); _menu.addAction(command->sendAction()); + + // add to command list and remove on destroy + commands << command; + connect(command, &QObject::destroyed, [this](QObject* obj) + { + commands.removeOne(static_cast(obj)); + }); + return command; } void CommandPanel::sendCommand(QByteArray command) @@ -89,3 +98,66 @@ QAction* CommandPanel::newCommandAction( { return &_newCommandAction; } + +unsigned CommandPanel::numOfCommands() +{ + return commands.size(); +} + +void CommandPanel::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Commands); + settings->beginWriteArray(SG_Commands_Command); + for (int i = 0; i < commands.size(); i ++) + { + settings->setArrayIndex(i); + auto command = commands[i]; + settings->setValue(SG_Commands_Name, command->name()); + settings->setValue(SG_Commands_Type, command->isASCIIMode() ? "ascii" : "hex"); + settings->setValue(SG_Commands_Data, command->commandText()); + } + settings->endArray(); + settings->endGroup(); +} + +void CommandPanel::loadSettings(QSettings* settings) +{ + // clear all commands + while (commands.size()) + { + auto command = commands.takeLast(); + command->disconnect(); + delete command; + } + + // load commands + settings->beginGroup(SettingGroup_Commands); + unsigned size = settings->beginReadArray(SG_Commands_Command); + + for (unsigned i = 0; i < size; i ++) + { + settings->setArrayIndex(i); + auto command = newCommand(); + + // load command name + QString name = settings->value(SG_Commands_Name, "").toString(); + if (!name.isEmpty()) command->setName(name); + + // Important: type should be set before command data for correct validation + QString type = settings->value(SG_Commands_Type, "").toString(); + if (type == "ascii") + { + command->setASCIIMode(true); + } + else if (type == "hex") + { + command->setASCIIMode(false); + } // else unchanged + + // load command data + command->setCommandText(settings->value(SG_Commands_Data, "").toString()); + } + + settings->endArray(); + settings->endGroup(); +} diff --git a/src/commandpanel.h b/src/commandpanel.h --- a/src/commandpanel.h +++ b/src/commandpanel.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -23,8 +23,10 @@ #include #include #include +#include #include #include +#include #include "commandwidget.h" @@ -41,7 +43,14 @@ public: ~CommandPanel(); QMenu* menu(); + /// Action for creating a new command. QAction* newCommandAction(); + /// Stores commands into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads commands from a `QSettings`. + void loadSettings(QSettings* settings); + /// Number of commands + unsigned numOfCommands(); signals: // emitted when user tries to send an empty command @@ -52,11 +61,12 @@ private: QSerialPort* serialPort; QMenu _menu; QAction _newCommandAction; + QList commands; unsigned command_name_counter; private slots: - void newCommand(); + CommandWidget* newCommand(); void sendCommand(QByteArray command); }; diff --git a/src/commandwidget.cpp b/src/commandwidget.cpp --- a/src/commandwidget.cpp +++ b/src/commandwidget.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -101,6 +101,11 @@ bool CommandWidget::isASCIIMode() return ui->pbASCII->isChecked(); } +void CommandWidget::setASCIIMode(bool enabled) +{ + ui->pbASCII->setChecked(enabled); +} + void CommandWidget::setName(QString name) { ui->leName->setText(name); @@ -120,3 +125,14 @@ QAction* CommandWidget::sendAction() { return &_sendAction; } + +QString CommandWidget::commandText() +{ + return ui->leCommand->text(); +} + +void CommandWidget::setCommandText(QString str) +{ + ui->leCommand->selectAll(); + ui->leCommand->insert(str); +} diff --git a/src/commandwidget.h b/src/commandwidget.h --- a/src/commandwidget.h +++ b/src/commandwidget.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -39,26 +39,36 @@ public: void setName(QString name); QString name(); void setFocusToEdit(); + /// An action that triggers sending of command. QAction* sendAction(); + /// true: ascii mode, false hex mode + bool isASCIIMode(); + /// true: ascii mode, false hex mode + void setASCIIMode(bool ascii); + /// Returns the command data as text + QString commandText(); + /// Set command data as text. Text is validated according to current mode. + void setCommandText(QString str); signals: - void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked + /// emitted when delete button is clicked + void deleteRequested(CommandWidget* thisWidget); - // emitted when send button is clicked - // - // in case of hex mode, command text should be a hexadecimal - // string containing hexadecimal characters only (not even spaces) + /** + * Emitted when send button is clicked. + * + * In case of hex mode, command text should be a hexadecimal + * string containing hexadecimal characters only (not even spaces) + */ void sendCommand(QByteArray command); - // emitted when user tries to send an empty command + /// emitted when user tries to send an empty command void focusRequested(); private: Ui::CommandWidget *ui; QAction _sendAction; - bool isASCIIMode(); // true: ascii mode, false hex mode - private slots: void onDeleteClicked(); void onSendClicked(); diff --git a/src/dataformatpanel.cpp b/src/dataformatpanel.cpp --- a/src/dataformatpanel.cpp +++ b/src/dataformatpanel.cpp @@ -22,9 +22,11 @@ #include #include +#include #include #include "utils.h" +#include "setting_defines.h" #include "floatswap.h" DataFormatPanel::DataFormatPanel(QSerialPort* port, @@ -145,3 +147,63 @@ void DataFormatPanel::selectReader(Abstr currentReader = reader; } + +void DataFormatPanel::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_DataFormat); + + // save selected format + QString format; + if (currentReader == &bsReader) + { + format = "binary"; + } + else if (currentReader == &asciiReader) + { + format = "ascii"; + } + else // framed reader + { + format = "custom"; + } + settings->setValue(SG_DataFormat_Format, format); + + settings->endGroup(); + + // save reader settings + bsReader.saveSettings(settings); + asciiReader.saveSettings(settings); + framedReader.saveSettings(settings); +} + +void DataFormatPanel::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_DataFormat); + + // load selected format + QString format = settings->value( + SG_DataFormat_Format, QString()).toString(); + + if (format == "binary") + { + selectReader(&bsReader); + ui->rbBinary->setChecked(true); + } + else if (format == "ascii") + { + selectReader(&asciiReader); + ui->rbAscii->setChecked(true); + } + else if (format == "custom") + { + selectReader(&framedReader); + ui->rbFramed->setChecked(true); + } // else current selection stays + + settings->endGroup(); + + // load reader settings + bsReader.loadSettings(settings); + asciiReader.loadSettings(settings); + framedReader.loadSettings(settings); +} diff --git a/src/dataformatpanel.h b/src/dataformatpanel.h --- a/src/dataformatpanel.h +++ b/src/dataformatpanel.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "framebuffer.h" @@ -48,7 +49,12 @@ public: QWidget *parent = 0); ~DataFormatPanel(); + /// Returns currently selected number of channels unsigned numOfChannels(); + /// Stores data format panel settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads data format panel settings from a `QSettings`. + void loadSettings(QSettings* settings); public slots: void pause(bool); 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/framedreader.cpp b/src/framedreader.cpp --- a/src/framedreader.cpp +++ b/src/framedreader.cpp @@ -122,6 +122,9 @@ void FramedReader::onNumberFormatChanged sampleSize = 4; readSample = &FramedReader::readSampleAs; break; + case NumberFormat_INVALID: + Q_ASSERT(1); // never + break; } checkSettings(); @@ -350,3 +353,13 @@ template double FramedReader return double(data); } + +void FramedReader::saveSettings(QSettings* settings) +{ + _settingsWidget.saveSettings(settings); +} + +void FramedReader::loadSettings(QSettings* settings) +{ + _settingsWidget.loadSettings(settings); +} diff --git a/src/framedreader.h b/src/framedreader.h --- a/src/framedreader.h +++ b/src/framedreader.h @@ -20,6 +20,8 @@ #ifndef FRAMEDREADER_H #define FRAMEDREADER_H +#include + #include "abstractreader.h" #include "framedreadersettings.h" @@ -35,6 +37,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/framedreadersettings.cpp b/src/framedreadersettings.cpp --- a/src/framedreadersettings.cpp +++ b/src/framedreadersettings.cpp @@ -20,6 +20,7 @@ #include #include "utils.h" +#include "setting_defines.h" #include "framedreadersettings.h" #include "ui_framedreadersettings.h" @@ -150,3 +151,73 @@ bool FramedReaderSettings::isDebugModeEn { return ui->cbDebugMode->isChecked(); } + +void FramedReaderSettings::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_CustomFrame); + settings->setValue(SG_CustomFrame_NumOfChannels, numOfChannels()); + settings->setValue(SG_CustomFrame_NumberFormat, numberFormatToStr(numberFormat())); + settings->setValue(SG_CustomFrame_Endianness, + endianness() == LittleEndian ? "little" : "big"); + settings->setValue(SG_CustomFrame_FrameStart, ui->leSyncWord->text()); + settings->setValue(SG_CustomFrame_FixedSize, ui->rbFixedSize->isChecked()); + settings->setValue(SG_CustomFrame_FrameSize, ui->spSize->value()); + settings->setValue(SG_CustomFrame_Checksum, ui->cbChecksum->isChecked()); + settings->setValue(SG_CustomFrame_DebugMode, ui->cbDebugMode->isChecked()); + settings->endGroup(); +} + +void FramedReaderSettings::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_CustomFrame); + + // load number of channels + ui->spNumOfChannels->setValue( + settings->value(SG_CustomFrame_NumOfChannels, numOfChannels()).toInt()); + + // load number format + NumberFormat nfSetting = + strToNumberFormat(settings->value(SG_CustomFrame_NumberFormat, + QString()).toString()); + if (nfSetting == NumberFormat_INVALID) nfSetting = numberFormat(); + ui->nfBox->setSelection(nfSetting); + + // load endianness + QString endiannessSetting = + settings->value(SG_CustomFrame_Endianness, QString()).toString(); + if (endiannessSetting == "little") + { + ui->endiBox->setSelection(LittleEndian); + } + else if (endiannessSetting == "big") + { + ui->endiBox->setSelection(BigEndian); + } // else don't change + + // load frame start + QString frameStartSetting = + settings->value(SG_CustomFrame_FrameStart, ui->leSyncWord->text()).toString(); + auto validator = ui->leSyncWord->validator(); + validator->fixup(frameStartSetting); + int pos = 0; + if (validator->validate(frameStartSetting, pos) != QValidator::Invalid) + { + ui->leSyncWord->setText(frameStartSetting); + } + + // load frame size + ui->spSize->setValue( + settings->value(SG_CustomFrame_FrameSize, ui->spSize->value()).toInt()); + ui->rbFixedSize->setChecked( + settings->value(SG_CustomFrame_FixedSize, ui->rbFixedSize->isChecked()).toBool()); + + // load checksum + ui->cbChecksum->setChecked( + settings->value(SG_CustomFrame_Checksum, ui->cbChecksum->isChecked()).toBool()); + + // load debug mode + ui->cbDebugMode->setChecked( + settings->value(SG_CustomFrame_DebugMode, ui->cbDebugMode->isChecked()).toBool()); + + settings->endGroup(); +} diff --git a/src/framedreadersettings.h b/src/framedreadersettings.h --- a/src/framedreadersettings.h +++ b/src/framedreadersettings.h @@ -22,6 +22,7 @@ #include #include +#include #include "numberformatbox.h" #include "endiannessbox.h" @@ -47,6 +48,10 @@ public: unsigned frameSize(); /// If frame bye is enabled `0` is returned bool isChecksumEnabled(); bool isDebugModeEnabled(); + /// Save settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads settings from a `QSettings`. + void loadSettings(QSettings* settings); signals: /// If sync word is invalid (empty or 1 nibble missing at the end) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -38,12 +39,20 @@ #include "utils.h" #include "defines.h" #include "version.h" +#include "setting_defines.h" #if defined(Q_OS_WIN) && defined(QT_STATIC) #include Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) #endif +const QMap panelSettingMap({ + {0, "Port"}, + {1, "DataFormat"}, + {2, "Plot"}, + {3, "Commands"} + }); + MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), @@ -63,7 +72,8 @@ MainWindow::MainWindow(QWidget *parent) ui->tabWidget->insertTab(2, &plotControlPanel, "Plot"); ui->tabWidget->insertTab(3, &commandPanel, "Commands"); ui->tabWidget->setCurrentIndex(0); - addToolBar(portControl.toolBar()); + auto tbPortControl = portControl.toolBar(); + addToolBar(tbPortControl); ui->plotToolBar->addAction(snapshotMan.takeSnapshotAction()); ui->menuBar->insertMenu(ui->menuHelp->menuAction(), snapshotMan.menu()); @@ -78,6 +88,9 @@ MainWindow::MainWindow(QWidget *parent) this->ui->tabWidget->setCurrentWidget(&commandPanel); }); + tbPortControl->setObjectName("tbPortControl"); + ui->plotToolBar->setObjectName("tbPlot"); + setupAboutDialog(); // init view menu @@ -94,16 +107,23 @@ MainWindow::MainWindow(QWidget *parent) // init UI signals - // menu signals + // Help menu signals QObject::connect(ui->actionHelpAbout, &QAction::triggered, &aboutDialog, &QWidget::show); QObject::connect(ui->actionReportBug, &QAction::triggered, [](){QDesktopServices::openUrl(QUrl(BUG_REPORT_URL));}); + // File menu signals QObject::connect(ui->actionExportCsv, &QAction::triggered, this, &MainWindow::onExportCsv); + QObject::connect(ui->actionSaveSettings, &QAction::triggered, + this, &MainWindow::onSaveSettings); + + QObject::connect(ui->actionLoadSettings, &QAction::triggered, + this, &MainWindow::onLoadSettings); + ui->actionQuit->setShortcutContext(Qt::ApplicationShortcut); QObject::connect(ui->actionQuit, &QAction::triggered, @@ -181,10 +201,24 @@ MainWindow::MainWindow(QWidget *parent) QObject::connect(ui->actionDemoMode, &QAction::toggled, plotMan, &PlotManager::showDemoIndicator); + + // load default settings + QSettings settings("serialplot", "serialplot"); + loadAllSettings(&settings); + + // ensure command panel has 1 command if none loaded + if (!commandPanel.numOfCommands()) + { + commandPanel.newCommandAction()->trigger(); + } } MainWindow::~MainWindow() { + // save settings + QSettings settings("serialplot", "serialplot"); + saveAllSettings(&settings); + if (serialPort.isOpen()) { serialPort.close(); @@ -402,3 +436,100 @@ void MainWindow::messageHandler(QtMsgTyp ui->statusBar->showMessage(msg, 5000); } } + +void MainWindow::saveAllSettings(QSettings* settings) +{ + saveMWSettings(settings); + portControl.saveSettings(settings); + dataFormatPanel.saveSettings(settings); + channelMan.saveSettings(settings); + plotControlPanel.saveSettings(settings); + plotMan->saveSettings(settings); + commandPanel.saveSettings(settings); +} + +void MainWindow::loadAllSettings(QSettings* settings) +{ + loadMWSettings(settings); + portControl.loadSettings(settings); + dataFormatPanel.loadSettings(settings); + channelMan.loadSettings(settings); + plotControlPanel.loadSettings(settings); + plotMan->loadSettings(settings); + commandPanel.loadSettings(settings); +} + +void MainWindow::saveMWSettings(QSettings* settings) +{ + // save window geometry + settings->beginGroup(SettingGroup_MainWindow); + settings->setValue(SG_MainWindow_Size, size()); + settings->setValue(SG_MainWindow_Pos, pos()); + // save active panel + settings->setValue(SG_MainWindow_ActivePanel, + panelSettingMap.value(ui->tabWidget->currentIndex())); + // save panel minimization + settings->setValue(SG_MainWindow_HidePanels, + ui->tabWidget->hideAction.isChecked()); + // save window maximized state + settings->setValue(SG_MainWindow_Maximized, + bool(windowState() & Qt::WindowMaximized)); + // save toolbar/dockwidgets state + settings->setValue(SG_MainWindow_State, saveState()); + settings->endGroup(); +} + +void MainWindow::loadMWSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_MainWindow); + // load window geometry + resize(settings->value(SG_MainWindow_Size, size()).toSize()); + move(settings->value(SG_MainWindow_Pos, pos()).toPoint()); + + // set active panel + QString tabSetting = + settings->value(SG_MainWindow_ActivePanel, QString()).toString(); + ui->tabWidget->setCurrentIndex( + panelSettingMap.key(tabSetting, ui->tabWidget->currentIndex())); + + // hide panels + ui->tabWidget->hideAction.setChecked( + settings->value(SG_MainWindow_HidePanels, + ui->tabWidget->hideAction.isChecked()).toBool()); + + // maximize window + if (settings->value(SG_MainWindow_Maximized).toBool()) + { + showMaximized(); + } + + // load toolbar/dockwidgets state + restoreState(settings->value(SG_MainWindow_State).toByteArray()); + settings->setValue(SG_MainWindow_State, saveState()); + + settings->endGroup(); +} + +void MainWindow::onSaveSettings() +{ + QString fileName = QFileDialog::getSaveFileName( + this, tr("Save Settings"), QString(), "INI (*.ini)"); + + if (!fileName.isNull()) // user canceled + { + QSettings settings(fileName, QSettings::IniFormat); + saveAllSettings(&settings); + } +} + +void MainWindow::onLoadSettings() +{ + QString fileName = QFileDialog::getOpenFileName( + this, tr("Load Settings"), QString(), "INI (*.ini)"); + + if (!fileName.isNull()) // user canceled + { + QSettings settings(fileName, QSettings::IniFormat); + loadAllSettings(&settings); + } +} diff --git a/src/mainwindow.h b/src/mainwindow.h --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include "portcontrol.h" @@ -80,6 +81,14 @@ private: PlotControlPanel plotControlPanel; bool isDemoRunning(); + /// Stores settings for all modules + void saveAllSettings(QSettings* settings); + /// Load settings for all modules + void loadAllSettings(QSettings* settings); + /// Stores main window settings into a `QSettings` + void saveMWSettings(QSettings* settings); + /// Loads main window settings from a `QSettings` + void loadMWSettings(QSettings* settings); private slots: void onPortToggled(bool open); @@ -90,12 +99,11 @@ private slots: void onChannelNameChanged(unsigned channel, QString name); void clearPlot(); - void onSpsChanged(unsigned sps); - void enableDemo(bool enabled); - void onExportCsv(); + void onSaveSettings(); + void onLoadSettings(); }; #endif // MAINWINDOW_H diff --git a/src/mainwindow.ui b/src/mainwindow.ui --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -105,6 +105,8 @@ File + + @@ -197,6 +199,22 @@ Report a Bug on SerialPlot Website + + + Save Settings + + + Save Settings to a File + + + + + Load Settings + + + Load Settings from a File + + 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/plotcontrolpanel.cpp b/src/plotcontrolpanel.cpp --- a/src/plotcontrolpanel.cpp +++ b/src/plotcontrolpanel.cpp @@ -23,7 +23,7 @@ #include "plotcontrolpanel.h" #include "ui_plotcontrolpanel.h" - +#include "setting_defines.h" /// Used for scale range selection combobox struct Range @@ -150,3 +150,25 @@ void PlotControlPanel::setChannelNamesMo { ui->lvChannelNames->setModel(model); } + +void PlotControlPanel::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Plot); + settings->setValue(SG_Plot_NumOfSamples, numOfSamples()); + settings->setValue(SG_Plot_AutoScale, autoScale()); + settings->setValue(SG_Plot_YMax, yMax()); + settings->setValue(SG_Plot_YMin, yMin()); + settings->endGroup(); +} + +void PlotControlPanel::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Plot); + ui->spNumOfSamples->setValue( + settings->value(SG_Plot_NumOfSamples, numOfSamples()).toInt()); + ui->cbAutoScale->setChecked( + settings->value(SG_Plot_AutoScale, autoScale()).toBool()); + ui->spYmax->setValue(settings->value(SG_Plot_YMax, yMax()).toDouble()); + ui->spYmin->setValue(settings->value(SG_Plot_YMin, yMin()).toDouble()); + settings->endGroup(); +} diff --git a/src/plotcontrolpanel.h b/src/plotcontrolpanel.h --- a/src/plotcontrolpanel.h +++ b/src/plotcontrolpanel.h @@ -22,6 +22,7 @@ #include #include +#include namespace Ui { class PlotControlPanel; @@ -42,6 +43,11 @@ public: void setChannelNamesModel(QAbstractItemModel * model); + /// Stores plot settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads plot settings from a `QSettings`. + void loadSettings(QSettings* settings); + signals: void numOfSamplesChanged(int value); void scaleChanged(bool autoScaled, double yMin = 0, double yMax = 1); diff --git a/src/plotmanager.cpp b/src/plotmanager.cpp --- a/src/plotmanager.cpp +++ b/src/plotmanager.cpp @@ -22,7 +22,7 @@ #include "plot.h" #include "plotmanager.h" #include "utils.h" - +#include "setting_defines.h" PlotManager::PlotManager(QWidget* plotArea, QObject *parent) : QObject(parent), @@ -372,3 +372,36 @@ void PlotManager::onNumOfSamplesChanged( plot->onNumOfSamplesChanged(value); } } + +void PlotManager::saveSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Plot); + settings->setValue(SG_Plot_DarkBackground, darkBackgroundAction.isChecked()); + settings->setValue(SG_Plot_Grid, showGridAction.isChecked()); + settings->setValue(SG_Plot_MinorGrid, showMinorGridAction.isChecked()); + settings->setValue(SG_Plot_Legend, showLegendAction.isChecked()); + settings->setValue(SG_Plot_MultiPlot, showMultiAction.isChecked()); + settings->endGroup(); +} + +void PlotManager::loadSettings(QSettings* settings) +{ + settings->beginGroup(SettingGroup_Plot); + darkBackgroundAction.setChecked( + settings->value(SG_Plot_DarkBackground, darkBackgroundAction.isChecked()).toBool()); + darkBackground(darkBackgroundAction.isChecked()); + showGridAction.setChecked( + settings->value(SG_Plot_Grid, showGridAction.isChecked()).toBool()); + showGrid(showGridAction.isChecked()); + showMinorGridAction.setChecked( + settings->value(SG_Plot_MinorGrid, showMinorGridAction.isChecked()).toBool()); + showMinorGridAction.setEnabled(showGridAction.isChecked()); + showMinorGrid(showMinorGridAction.isChecked()); + showLegendAction.setChecked( + settings->value(SG_Plot_Legend, showLegendAction.isChecked()).toBool()); + showLegend(showLegendAction.isChecked()); + showMultiAction.setChecked( + settings->value(SG_Plot_MultiPlot, showMultiAction.isChecked()).toBool()); + setMulti(showMultiAction.isChecked()); + settings->endGroup(); +} diff --git a/src/plotmanager.h b/src/plotmanager.h --- a/src/plotmanager.h +++ b/src/plotmanager.h @@ -25,6 +25,7 @@ #include #include #include +#include #include #include "plot.h" @@ -50,6 +51,10 @@ public: unsigned numOfCurves(); /// Returns the list of actions to be inserted into the `View` menu QList menuActions(); + /// Stores plot settings into a `QSettings`. + void saveSettings(QSettings* settings); + /// Loads plot settings from a `QSettings`. + void loadSettings(QSettings* settings); public slots: /// Enable/Disable multiple plot display diff --git a/src/portcontrol.cpp b/src/portcontrol.cpp --- a/src/portcontrol.cpp +++ b/src/portcontrol.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -23,11 +23,21 @@ #include #include #include +#include #include + +#include "setting_defines.h" #include "utils.h" #define TBPORTLIST_MINWIDTH (200) +// setting mappings +const QMap paritySettingMap({ + {QSerialPort::NoParity, "none"}, + {QSerialPort::OddParity, "odd"}, + {QSerialPort::EvenParity, "even"}, + }); + PortControl::PortControl(QSerialPort* port, QWidget* parent) : QWidget(parent), ui(new Ui::PortControl), @@ -273,6 +283,22 @@ void PortControl::selectPort(QString por } } +QString PortControl::selectedPortName() +{ + QString portText = ui->cbPortList->currentText(); + int portIndex = portList.indexOf(portText); + if (portIndex < 0) // not in the list yet + { + // return the displayed name as port name + return portText; + } + else + { + // get the port name from the 'port list' + return static_cast(portList.item(portIndex))->portName(); + } +} + QToolBar* PortControl::toolBar() { return &portToolBar; @@ -292,3 +318,102 @@ void PortControl::onTbPortListActivated( { ui->cbPortList->setCurrentIndex(index); } + +QString PortControl::currentParityText() +{ + return paritySettingMap.value( + (QSerialPort::Parity) parityButtons.checkedId()); +} + +QString PortControl::currentFlowControlText() +{ + if (flowControlButtons.checkedId() == QSerialPort::HardwareControl) + { + return "hardware"; + } + else if (flowControlButtons.checkedId() == QSerialPort::SoftwareControl) + { + return "software"; + } + else // no parity + { + return "none"; + } +} + +void PortControl::saveSettings(QSettings* settings) +{ + 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(); +} + +void PortControl::loadSettings(QSettings* settings) +{ + // make sure the port is closed + if (serialPort->isOpen()) togglePort(); + + settings->beginGroup(SettingGroup_Port); + + // set port name if it exists in the current list otherwise ignore + QString portName = settings->value(SG_Port_SelectedPort, QString()).toString(); + if (!portName.isEmpty()) + { + int index = portList.indexOfName(portName); + if (index > -1) ui->cbPortList->setCurrentIndex(index); + } + + // load baud rate setting if it exists in baud rate list + QString baudSetting = settings->value( + 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(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(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(SG_Port_StopBits, stopBitsButtons.checkedId()).toInt(); + if (stopBits == QSerialPort::OneStop) + { + ui->rb1StopBit->setChecked(true); + } + else if (stopBits == QSerialPort::TwoStop) + { + ui->rb2StopBit->setChecked(true); + } + + // load flow control + QString flowControlSetting = + settings->value(SG_Port_FlowControl, currentFlowControlText()).toString(); + if (flowControlSetting == "hardware") + { + ui->rbHardwareControl->setChecked(true); + } + else if (flowControlSetting == "software") + { + ui->rbSoftwareControl->setChecked(true); + } + else + { + ui->rbNoFlowControl->setChecked(true); + } + + settings->endGroup(); +} diff --git a/src/portcontrol.h b/src/portcontrol.h --- a/src/portcontrol.h +++ b/src/portcontrol.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -27,6 +27,7 @@ #include #include #include +#include #include "portlist.h" @@ -43,8 +44,12 @@ public: ~PortControl(); QSerialPort* serialPort; + QToolBar* toolBar(); - QToolBar* toolBar(); + /// Stores port settings into a `QSettings` + void saveSettings(QSettings* settings); + /// Loads port settings from a `QSettings`. If open serial port is closed. + void loadSettings(QSettings* settings); private: Ui::PortControl *ui; @@ -60,6 +65,13 @@ private: QComboBox tbPortList; PortList portList; + /// Returns the currently selected (entered) "portName" in the UI + QString selectedPortName(); + /// Returns currently selected parity as text to be saved in settings + QString currentParityText(); + /// Returns currently selected flow control as text to be saved in settings + QString currentFlowControlText(); + public slots: void loadPortList(); void loadBaudRateList(); diff --git a/src/portlist.cpp b/src/portlist.cpp --- a/src/portlist.cpp +++ b/src/portlist.cpp @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -112,6 +112,18 @@ int PortList::indexOf(QString portText) return -1; // not found } +int PortList::indexOfName(QString portName) +{ + for (int i = 0; i < rowCount(); i++) + { + if (item(i)->data(PortNameRole) == portName) + { + return i; + } + } + return -1; // not found +} + void PortList::onRowsInserted(QModelIndex parent, int start, int end) { PortListItem* newItem = static_cast(item(start)); diff --git a/src/portlist.h b/src/portlist.h --- a/src/portlist.h +++ b/src/portlist.h @@ -1,5 +1,5 @@ /* - Copyright © 2015 Hasan Yavuz Özderya + Copyright © 2016 Hasan Yavuz Özderya This file is part of serialplot. @@ -50,7 +50,10 @@ public: PortList(QObject* parent=0); void loadPortList(); + /// Search for displayed text of the port int indexOf(QString portText); // return -1 if not found + /// Search for the actual port name + int indexOfName(QString portName); // return -1 if not found private: QStringList userEnteredPorts; 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,91 @@ +/* + 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_Binary[] = "DataFormat_Binary"; +const char SettingGroup_ASCII[] = "DataFormat_ASCII"; +const char SettingGroup_CustomFrame[] = "DataFormat_CustomFrame"; +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"; +const char SG_MainWindow_ActivePanel[] = "activePanel"; +const char SG_MainWindow_HidePanels[] = "hidePanels"; +const char SG_MainWindow_Maximized[] = "maximized"; +const char SG_MainWindow_State[] = "state"; + +// 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"; + +// 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"; + +// ascii reader keys +const char SG_ASCII_NumOfChannels[] = "numOfChannels"; + +// framed reader keys +const char SG_CustomFrame_NumOfChannels[] = "numOfChannels"; +const char SG_CustomFrame_FrameStart[] = "frameStart"; +const char SG_CustomFrame_FixedSize[] = "fixedSize"; +const char SG_CustomFrame_FrameSize[] = "frameSize"; +const char SG_CustomFrame_NumberFormat[] = "numberFormat"; +const char SG_CustomFrame_Endianness[] = "endianness"; +const char SG_CustomFrame_Checksum[] = "checksum"; +const char SG_CustomFrame_DebugMode[] = "debugMode"; + +// channel manager keys +const char SG_Channels_Channel[] = "channel"; +const char SG_Channels_Name[] = "name"; + +// plot settings keys +const char SG_Plot_NumOfSamples[] = "numOfSamples"; +const char SG_Plot_AutoScale[] = "autoScale"; +const char SG_Plot_YMax[] = "yMax"; +const char SG_Plot_YMin[] = "yMin"; +const char SG_Plot_DarkBackground[] = "darkBackground"; +const char SG_Plot_Grid[] = "grid"; +const char SG_Plot_MinorGrid[] = "minorGrid"; +const char SG_Plot_Legend[] = "legend"; +const char SG_Plot_MultiPlot[] = "multiPlot"; + +// command setting keys +const char SG_Commands_Command[] = "command"; +const char SG_Commands_Name[] = "name"; +const char SG_Commands_Type[] = "type"; +const char SG_Commands_Data[] = "data"; + +#endif // SETTING_DEFINES_H