Created a Serializable interface for where only the serialization methods are needed from an object. Applied to AM demod channel marker

This commit is contained in:
f4exb 2017-10-01 16:52:23 +02:00
parent f10d486b28
commit 2b2b0eff8d
5 changed files with 53 additions and 9 deletions

View File

@ -104,7 +104,7 @@ void AMDemodGUI::channelMarkerChanged()
m_settings.m_udpPort = m_channelMarker.getUDPSendPort(),
m_settings.m_rgbColor = m_channelMarker.getColor().rgb();
displayUDPAddress();
m_settings.m_channelMarkerBytes = m_channelMarker.serialize();
//m_settings.m_channelMarkerBytes = m_channelMarker.serialize();
applySettings();
}
@ -202,6 +202,7 @@ AMDemodGUI::AMDemodGUI(PluginAPI* pluginAPI, DeviceSourceAPI *deviceAPI, QWidget
m_channelMarker.setUDPSendPort(9999);
m_channelMarker.setVisible(true);
setTitleColor(m_channelMarker.getColor());
m_settings.setChannelMarker(&m_channelMarker);
connect(&m_channelMarker, SIGNAL(changed()), this, SLOT(channelMarkerChanged()));
@ -281,7 +282,7 @@ void AMDemodGUI::updateChannelMarker()
{
m_channelMarker.blockSignals(true);
m_channelMarker.deserialize(m_settings.m_channelMarkerBytes);
//m_channelMarker.deserialize(m_settings.m_channelMarkerBytes);
this->setWindowTitle(m_channelMarker.getTitle());
m_channelMarker.blockSignals(false);

View File

@ -16,9 +16,11 @@
#include "dsp/dspengine.h"
#include "util/simpleserializer.h"
#include "settings/serializable.h"
#include "amdemodsettings.h"
AMDemodSettings::AMDemodSettings()
AMDemodSettings::AMDemodSettings() :
m_channelMarker(0)
{
resetToDefaults();
}
@ -45,7 +47,11 @@ QByteArray AMDemodSettings::serialize() const
s.writeS32(2, m_rfBandwidth/100);
s.writeS32(4, m_volume*10);
s.writeS32(5, m_squelch);
s.writeBlob(6, m_channelMarkerBytes);
if (m_channelMarker) {
s.writeBlob(6, m_channelMarker->serialize());
}
s.writeU32(7, m_rgbColor);
s.writeBool(8, m_bandpassEnable);
return s.final();
@ -74,7 +80,12 @@ bool AMDemodSettings::deserialize(const QByteArray& data)
m_volume = tmp * 0.1;
d.readS32(5, &tmp, -40);
m_squelch = tmp;
d.readBlob(6, &m_channelMarkerBytes);
d.readBlob(6, &bytetmp);
if (m_channelMarker) {
m_channelMarker->deserialize(bytetmp);
}
d.readU32(7, &m_rgbColor);
d.readBool(8, &m_bandpassEnable, false);
return true;

View File

@ -19,6 +19,8 @@
#include <QByteArray>
class Serializable;
struct AMDemodSettings
{
int m_inputSampleRate;
@ -33,10 +35,11 @@ struct AMDemodSettings
QString m_udpAddress;
quint16 m_udpPort;
quint32 m_rgbColor;
QByteArray m_channelMarkerBytes;
Serializable *m_channelMarker;
AMDemodSettings();
void resetToDefaults();
void setChannelMarker(Serializable *channelMarker) { m_channelMarker = channelMarker; }
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
};

View File

@ -5,9 +5,10 @@
#include <QColor>
#include <QByteArray>
#include "settings/serializable.h"
#include "util/export.h"
class SDRANGEL_API ChannelMarker : public QObject {
class SDRANGEL_API ChannelMarker : public QObject, public Serializable {
Q_OBJECT
public:
@ -76,8 +77,8 @@ public:
const QString& getDisplayAddressSend() const { return m_displayAddressSend; }
const QString& getDisplayAddressReceive() const { return m_displayAddressReceive; }
QByteArray serialize() const;
bool deserialize(const QByteArray& data);
virtual QByteArray serialize() const;
virtual bool deserialize(const QByteArray& data);
protected:
static QRgb m_colorTable[];

View File

@ -0,0 +1,28 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2017 Edouard Griffiths, F4EXB. //
// //
// This program 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 as version 3 of the License, or //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////
#ifndef SDRBASE_SETTINGS_SERIALIZABLE_H_
#define SDRBASE_SETTINGS_SERIALIZABLE_H_
class Serializable
{
public:
virtual ~Serializable() {}
virtual QByteArray serialize() const = 0;
virtual bool deserialize(const QByteArray& data) = 0;
};
#endif /* SDRBASE_SETTINGS_SERIALIZABLE_H_ */