Changeset - 3da4b5482573
[Not reviewed]
settings
0 11 2
Hasan Yavuz ÖZDERYA - 9 years ago 2016-09-04 17:56:19
hy@ozderya.net
implemented settings for simple binary reader
13 files changed with 189 insertions and 14 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -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}
src/binarystreamreader.cpp
Show inline comments
 
@@ -179,7 +179,6 @@ void BinaryStreamReader::onDataReady()
 
    delete channelSamples;
 
}
 

	
 

	
 
template<typename T> 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);
 
}
src/binarystreamreader.h
Show inline comments
 
@@ -20,6 +20,8 @@
 
#ifndef BINARYSTREAMREADER_H
 
#define BINARYSTREAMREADER_H
 

	
 
#include <QSettings>
 

	
 
#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);
src/binarystreamreadersettings.cpp
Show inline comments
 
@@ -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();
 
}
src/binarystreamreadersettings.h
Show inline comments
 
@@ -21,6 +21,8 @@
 
#define BINARYSTREAMREADERSETTINGS_H
 

	
 
#include <QWidget>
 
#include <QSettings>
 

	
 
#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);
src/dataformatpanel.cpp
Show inline comments
 
@@ -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);
 
}
src/endiannessbox.cpp
Show inline comments
 
@@ -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);
 
    }
 
}
src/endiannessbox.h
Show inline comments
 
@@ -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
src/numberformat.cpp
Show inline comments
 
new file 100644
 
/*
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#include <QMap>
 

	
 
#include "numberformat.h"
 

	
 
QMap<NumberFormat, QString> 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);
 
}
src/numberformat.h
Show inline comments
 
new file 100644
 
/*
 
  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 <http://www.gnu.org/licenses/>.
 
*/
 

	
 
#ifndef NUMBERFORMAT_H
 
#define NUMBERFORMAT_H
 

	
 
#include <QString>
 

	
 
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
src/numberformatbox.cpp
Show inline comments
 
@@ -54,3 +54,8 @@ NumberFormat NumberFormatBox::currentSel
 
{
 
    return (NumberFormat) buttonGroup.checkedId();
 
}
 

	
 
void NumberFormatBox::setSelection(NumberFormat nf)
 
{
 
    buttonGroup.button(nf)->setChecked(true);
 
}
src/numberformatbox.h
Show inline comments
 
@@ -23,21 +23,12 @@
 
#include <QWidget>
 
#include <QButtonGroup>
 

	
 
#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
src/setting_defines.h
Show inline comments
 
@@ -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
0 comments (0 inline, 0 general)