SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
cwkeyersettings.cpp
Go to the documentation of this file.
1 // Copyright (C) 2016 F4EXB //
3 // written by Edouard Griffiths //
4 // //
5 // This program is free software; you can redistribute it and/or modify //
6 // it under the terms of the GNU General Public License as published by //
7 // the Free Software Foundation as version 3 of the License, or //
8 // (at your option) any later version. //
9 // //
10 // This program is distributed in the hope that it will be useful, //
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of //
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
13 // GNU General Public License V3 for more details. //
14 // //
15 // You should have received a copy of the GNU General Public License //
16 // along with this program. If not, see <http://www.gnu.org/licenses/>. //
18 
19 #include "util/simpleserializer.h"
20 #include "cwkeyersettings.h"
21 
23 {
25 }
26 
28 {
29  m_loop = false;
30  m_mode = CWNone;
31  m_sampleRate = 48000;
32  m_text = "";
33  m_wpm = 13;
34  m_keyboardIambic = true;
35  m_dotKey = Qt::Key_Period;
36  m_dotKeyModifiers = Qt::NoModifier;
37  m_dashKey = Qt::Key_Minus;
38  m_dashKeyModifiers = Qt::NoModifier;
39 }
40 
41 QByteArray CWKeyerSettings::serialize() const
42 {
43  SimpleSerializer s(1);
44 
45  s.writeBool(2, m_loop);
46  s.writeS32(3, (int) m_mode);
47  s.writeS32(4, m_sampleRate);
48  s.writeString(5, m_text);
49  s.writeS32(6, m_wpm);
50  s.writeS32(7, (int) m_dotKey);
51  s.writeU32(8, (unsigned int) m_dotKeyModifiers);
52  s.writeS32(9, (int) m_dashKey);
53  s.writeU32(10, (unsigned int) m_dashKeyModifiers);
55 
56  return s.final();
57 }
58 
59 bool CWKeyerSettings::deserialize(const QByteArray& data)
60 {
61  SimpleDeserializer d(data);
62 
63  if (!d.isValid())
64  {
66  return false;
67  }
68 
69  if (d.getVersion() == 1)
70  {
71  int intval;
72  unsigned int uintval;
73 
74  d.readBool(2, &m_loop, false);
75  d.readS32(3, &intval, 0);
76  m_mode = (CWMode) intval;
77  d.readS32(4, &m_sampleRate, 48000);
78  d.readString(5, &m_text, "");
79  d.readS32(6, &m_wpm, 13);
80  d.readS32(7, &intval, (int) Qt::Key_Period);
81  m_dotKey = (Qt::Key) (intval < 0 ? 0 : intval);
82  d.readU32(8, &uintval, 0);
83  m_dotKeyModifiers = (Qt::KeyboardModifiers) uintval;
84  d.readS32(9, &intval, (int) Qt::Key_Minus);
85  m_dashKey = (Qt::Key) (intval < 0 ? 0 : intval);
86  d.readU32(10, &uintval, 0);
87  m_dashKeyModifiers = (Qt::KeyboardModifiers) uintval;
88  d.readBool(11, &m_keyboardIambic, true);
89 
90  return true;
91  }
92  else
93  {
95  return false;
96  }
97 }
bool readU32(quint32 id, quint32 *result, quint32 def=0) const
bool readString(quint32 id, QString *result, const QString &def=QString::null) const
bool readBool(quint32 id, bool *result, bool def=false) const
bool isValid() const
bool readS32(quint32 id, qint32 *result, qint32 def=0) const
bool deserialize(const QByteArray &data)
void writeS32(quint32 id, qint32 value)
quint32 getVersion() const
Qt::KeyboardModifiers m_dotKeyModifiers
void writeU32(quint32 id, quint32 value)
Qt::KeyboardModifiers m_dashKeyModifiers
void writeBool(quint32 id, bool value)
void writeString(quint32 id, const QString &value)
const QByteArray & final()
QByteArray serialize() const