From 4b82b919d3877b0c11e7db1d841ce0d458918b73 Mon Sep 17 00:00:00 2001 From: f4exb Date: Sun, 20 Mar 2022 12:23:50 +0100 Subject: [PATCH] Implement signal when main preferences are changed. Partially implements #1139 --- sdrbase/settings/mainsettings.h | 107 +++++++++++++++++++++++++------ sdrbase/settings/preferences.cpp | 52 +++++++-------- sdrbase/settings/preferences.h | 62 +++++++++++++----- sdrgui/mainwindow.cpp | 6 +- 4 files changed, 163 insertions(+), 64 deletions(-) diff --git a/sdrbase/settings/mainsettings.h b/sdrbase/settings/mainsettings.h index bd1698774..aa67fbe6a 100644 --- a/sdrbase/settings/mainsettings.h +++ b/sdrbase/settings/mainsettings.h @@ -1,6 +1,7 @@ #ifndef INCLUDE_SETTINGS_H #define INCLUDE_SETTINGS_H +#include #include #include "device/deviceuserargs.h" #include "limerfe/limerfeusbcalib.h" @@ -15,7 +16,8 @@ class AudioDeviceManager; class AMBEEngine; -class SDRBASE_API MainSettings { +class SDRBASE_API MainSettings : public QObject { + Q_OBJECT public: MainSettings(); ~MainSettings(); @@ -68,37 +70,106 @@ public: FeatureSetPreset* getWorkingFeatureSetPreset() { return &m_workingFeatureSetPreset; } QList *getFeatureSetPresets() { return &m_featureSetPresets; } - int getSourceItemIndex() const { return m_preferences.getSourceItemIndex(); } - void setSourceItemIndex(int value) { m_preferences.setSourceItemIndex(value); } + const QString& getSourceDevice() const { return m_preferences.getSourceDevice(); } + void setSourceDevice(const QString& value) + { + m_preferences.setSourceDevice(value); + emit preferenceChanged(Preferences::SourceDevice); + } + int getSourceIndex() const { return m_preferences.getSourceIndex(); } - void setSourceIndex(int value) { m_preferences.setSourceIndex(value); } - const QString& getSourceDeviceId() const { return m_preferences.getSourceDevice(); } - void setSourceDeviceId(const QString& deviceId) { m_preferences.setSourceDevice(deviceId); } + void setSourceIndex(int value) + { + m_preferences.setSourceIndex(value); + emit preferenceChanged(Preferences::SourceIndex); + } + + int getSourceItemIndex() const { return m_preferences.getSourceItemIndex(); } + void setSourceItemIndex(int value) + { + m_preferences.setSourceItemIndex(value); + emit preferenceChanged(Preferences::SourceItemIndex); + } + + const QString& getAudioType() const { return m_preferences.getAudioType(); } + void setAudioType(const QString& value) + { + m_preferences.setAudioType(value); + emit preferenceChanged(Preferences::AudioType); + } + + const QString& getAudioDevice() const { return m_preferences.getAudioDevice(); } + void setAudioDevice(const QString& value) + { + m_preferences.setAudioDevice(value); + emit preferenceChanged(Preferences::AudioDevice); + } + + QString getStationName() const { return m_preferences.getStationName(); } + void setStationName(const QString& name) + { + m_preferences.setStationName(name); + emit preferenceChanged(Preferences::StationName); + } - void setStationName(const QString& name) { m_preferences.setStationName(name); } - void setLatitude(float latitude) { m_preferences.setLatitude(latitude); } - void setLongitude(float longitude) { m_preferences.setLongitude(longitude); } - void setAltitude(float altitude) { m_preferences.setAltitude(altitude); } - QString getStationName() const { return m_preferences.getStationName(); } float getLatitude() const { return m_preferences.getLatitude(); } - float getLongitude() const { return m_preferences.getLongitude(); } - float getAltitude() const { return m_preferences.getAltitude(); } + void setLatitude(float latitude) + { + m_preferences.setLatitude(latitude); + emit preferenceChanged(Preferences::Latitude); + } + + float getLongitude() const { return m_preferences.getLongitude(); } + void setLongitude(float longitude) + { + m_preferences.setLongitude(longitude); + emit preferenceChanged(Preferences::Longitude); + } + + float getAltitude() const { return m_preferences.getAltitude(); } + void setAltitude(float altitude) + { + m_preferences.setAltitude(altitude); + emit preferenceChanged(Preferences::Altitude); + } - void setConsoleMinLogLevel(const QtMsgType& minLogLevel) { m_preferences.setConsoleMinLogLevel(minLogLevel); } - void setFileMinLogLevel(const QtMsgType& minLogLevel) { m_preferences.setFileMinLogLevel(minLogLevel); } - void setUseLogFile(bool useLogFile) { m_preferences.setUseLogFile(useLogFile); } - void setLogFileName(const QString& value) { m_preferences.setLogFileName(value); } QtMsgType getConsoleMinLogLevel() const { return m_preferences.getConsoleMinLogLevel(); } + void setConsoleMinLogLevel(const QtMsgType& minLogLevel) + { + m_preferences.setConsoleMinLogLevel(minLogLevel); + emit preferenceChanged(Preferences::ConsoleMinLogLevel); + } + QtMsgType getFileMinLogLevel() const { return m_preferences.getFileMinLogLevel(); } + void setFileMinLogLevel(const QtMsgType& minLogLevel) + { + m_preferences.setFileMinLogLevel(minLogLevel); + emit preferenceChanged(Preferences::FileMinLogLevel); + } + bool getUseLogFile() const { return m_preferences.getUseLogFile(); } + void setUseLogFile(bool useLogFile) + { + m_preferences.setUseLogFile(useLogFile); + emit preferenceChanged(Preferences::UseLogFile); + } + const QString& getLogFileName() const { return m_preferences.getLogFileName(); } + void setLogFileName(const QString& value) + { + m_preferences.setLogFileName(value); + emit preferenceChanged(Preferences::LogFileName); + } + DeviceUserArgs& getDeviceUserArgs() { return m_hardwareDeviceUserArgs; } LimeRFEUSBCalib& getLimeRFEUSBCalib() { return m_limeRFEUSBCalib; } - const AudioDeviceManager *getAudioDeviceManager() const { return m_audioDeviceManager; } void setAudioDeviceManager(AudioDeviceManager *audioDeviceManager) { m_audioDeviceManager = audioDeviceManager; } void setAMBEEngine(AMBEEngine *ambeEngine) { m_ambeEngine = ambeEngine; } +signals: + void preferenceChanged(int); + protected: Preferences m_preferences; AudioDeviceManager *m_audioDeviceManager; diff --git a/sdrbase/settings/preferences.cpp b/sdrbase/settings/preferences.cpp index 6642a8d47..4137f196c 100644 --- a/sdrbase/settings/preferences.cpp +++ b/sdrbase/settings/preferences.cpp @@ -26,19 +26,19 @@ void Preferences::resetToDefaults() QByteArray Preferences::serialize() const { SimpleSerializer s(1); - s.writeString(2, m_sourceDevice); - s.writeString(3, m_audioType); - s.writeString(4, m_audioDevice); - s.writeS32(5, m_sourceIndex); - s.writeFloat(6, m_latitude); - s.writeFloat(7, m_longitude); - s.writeS32(8, (int) m_consoleMinLogLevel); - s.writeBool(9, m_useLogFile); - s.writeString(10, m_logFileName); - s.writeS32(11, (int) m_fileMinLogLevel); - s.writeString(12, m_stationName); - s.writeFloat(13, m_altitude); - s.writeS32(14, m_sourceItemIndex); + s.writeString((int) SourceDevice, m_sourceDevice); + s.writeString((int) AudioType, m_audioType); + s.writeString((int) AudioDevice, m_audioDevice); + s.writeS32((int) SourceIndex, m_sourceIndex); + s.writeFloat((int) Latitude, m_latitude); + s.writeFloat((int) Longitude, m_longitude); + s.writeS32((int) ConsoleMinLogLevel, (int) m_consoleMinLogLevel); + s.writeBool((int) UseLogFile, m_useLogFile); + s.writeString((int) LogFileName, m_logFileName); + s.writeS32((int) FileMinLogLevel, (int) m_fileMinLogLevel); + s.writeString((int) StationName, m_stationName); + s.writeFloat((int) Altitude, m_altitude); + s.writeS32((int) SourceItemIndex, m_sourceItemIndex); return s.final(); } @@ -55,14 +55,14 @@ bool Preferences::deserialize(const QByteArray& data) if(d.getVersion() == 1) { - d.readString(2, &m_sourceDevice); - d.readString(3, &m_audioType); - d.readString(4, &m_audioDevice); - d.readS32(5, &m_sourceIndex, 0); - d.readFloat(6, &m_latitude, 0.0f); - d.readFloat(7, &m_longitude, 0.0f); + d.readString((int) SourceDevice, &m_sourceDevice); + d.readString((int) AudioType, &m_audioType); + d.readString((int) AudioDevice, &m_audioDevice); + d.readS32((int) SourceIndex, &m_sourceIndex, 0); + d.readFloat((int) Latitude, &m_latitude, 0.0f); + d.readFloat((int) Longitude, &m_longitude, 0.0f); - d.readS32(8, &tmpInt, (int) QtDebugMsg); + d.readS32((int) ConsoleMinLogLevel, &tmpInt, (int) QtDebugMsg); if ((tmpInt == (int) QtDebugMsg) || (tmpInt == (int) QtInfoMsg) || @@ -74,13 +74,13 @@ bool Preferences::deserialize(const QByteArray& data) m_consoleMinLogLevel = QtDebugMsg; } - d.readBool(9, &m_useLogFile, false); - d.readString(10, &m_logFileName, "sdrangel.log"); + d.readBool((int) UseLogFile, &m_useLogFile, false); + d.readString((int) LogFileName, &m_logFileName, "sdrangel.log"); - d.readS32(11, &tmpInt, (int) QtDebugMsg); - d.readString(12, &m_stationName, "Home"); - d.readFloat(13, &m_altitude, 0.0f); - d.readS32(14, &m_sourceItemIndex, 0); + d.readS32((int) FileMinLogLevel, &tmpInt, (int) QtDebugMsg); + d.readString((int) StationName, &m_stationName, "Home"); + d.readFloat((int) Altitude, &m_altitude, 0.0f); + d.readS32((int) SourceItemIndex, &m_sourceItemIndex, 0); if ((tmpInt == (int) QtDebugMsg) || (tmpInt == (int) QtInfoMsg) || diff --git a/sdrbase/settings/preferences.h b/sdrbase/settings/preferences.h index cb88ecc87..2baf4c204 100644 --- a/sdrbase/settings/preferences.h +++ b/sdrbase/settings/preferences.h @@ -7,41 +7,69 @@ class SDRBASE_API Preferences { public: - Preferences(); + enum ElementType + { + SourceDevice = 2, + AudioType, + AudioDevice, + SourceIndex, + Latitude, + Longitude, + ConsoleMinLogLevel, + UseLogFile, + LogFileName, + FileMinLogLevel, + StationName, + Altitude, + SourceItemIndex + }; + + Preferences(); + Preferences(const Preferences&) = default; + Preferences& operator=(const Preferences&) = default; void resetToDefaults(); QByteArray serialize() const; bool deserialize(const QByteArray& data); - void setSourceDevice(const QString& value) { m_sourceDevice = value; } const QString& getSourceDevice() const { return m_sourceDevice; } - void setSourceIndex(const int value) { m_sourceIndex = value; } + void setSourceDevice(const QString& value) { m_sourceDevice = value; } + int getSourceIndex() const { return m_sourceIndex; } - void setSourceItemIndex(const int value) { m_sourceItemIndex = value; } + void setSourceIndex(const int value) { m_sourceIndex = value; } + int getSourceItemIndex() const { return m_sourceItemIndex; } + void setSourceItemIndex(const int value) { m_sourceItemIndex = value; } - void setAudioType(const QString& value) { m_audioType = value; } const QString& getAudioType() const { return m_audioType; } - void setAudioDevice(const QString& value) { m_audioDevice = value; } + void setAudioType(const QString& value) { m_audioType = value; } + const QString& getAudioDevice() const { return m_audioDevice; } + void setAudioDevice(const QString& value) { m_audioDevice = value; } + QString getStationName() const { return m_stationName; } void setStationName(const QString& name) { m_stationName = name; } - void setLatitude(float latitude) { m_latitude = latitude; } - void setLongitude(float longitude) { m_longitude = longitude; } - void setAltitude(float altitude) { m_altitude = altitude; } - QString getStationName() const { return m_stationName; } - float getLatitude() const { return m_latitude; } - float getLongitude() const { return m_longitude; } - float getAltitude() const { return m_altitude; } - void setConsoleMinLogLevel(const QtMsgType& minLogLevel) { m_consoleMinLogLevel = minLogLevel; } - void setFileMinLogLevel(const QtMsgType& minLogLevel) { m_fileMinLogLevel = minLogLevel; } - void setUseLogFile(bool useLogFile) { m_useLogFile = useLogFile; } - void setLogFileName(const QString& value) { m_logFileName = value; } + float getLatitude() const { return m_latitude; } + void setLatitude(float latitude) { m_latitude = latitude; } + + float getLongitude() const { return m_longitude; } + void setLongitude(float longitude) { m_longitude = longitude; } + + float getAltitude() const { return m_altitude; } + void setAltitude(float altitude) { m_altitude = altitude; } + QtMsgType getConsoleMinLogLevel() const { return m_consoleMinLogLevel; } + void setConsoleMinLogLevel(const QtMsgType& minLogLevel) { m_consoleMinLogLevel = minLogLevel; } + QtMsgType getFileMinLogLevel() const { return m_fileMinLogLevel; } + void setFileMinLogLevel(const QtMsgType& minLogLevel) { m_fileMinLogLevel = minLogLevel; } + bool getUseLogFile() const { return m_useLogFile; } + void setUseLogFile(bool useLogFile) { m_useLogFile = useLogFile; } + const QString& getLogFileName() const { return m_logFileName; } + void setLogFileName(const QString& value) { m_logFileName = value; } protected: QString m_sourceDevice; //!< Identification of the source used in R0 tab (GUI flavor) at startup diff --git a/sdrgui/mainwindow.cpp b/sdrgui/mainwindow.cpp index 4517a2b55..18ed02422 100644 --- a/sdrgui/mainwindow.cpp +++ b/sdrgui/mainwindow.cpp @@ -236,12 +236,12 @@ MainWindow::MainWindow(qtwebapp::LoggerWithFile *logger, const MainParser& parse splash->showStatusMessage("load last device or file input...", Qt::white); qDebug() << "MainWindow::MainWindow: select SampleSource from settings or default (file input)..."; qDebug() << "MainWindow::MainWindow: look for" - << m_mainCore->m_settings.getSourceDeviceId() + << m_mainCore->m_settings.getSourceDevice() << "at index" << m_mainCore->m_settings.getSourceIndex() << "and item index" << m_mainCore->m_settings.getSourceItemIndex(); int deviceIndex = DeviceEnumerator::instance()->getRxSamplingDeviceIndex( - m_mainCore->m_settings.getSourceDeviceId(), + m_mainCore->m_settings.getSourceDevice(), m_mainCore->m_settings.getSourceIndex(), m_mainCore->m_settings.getSourceItemIndex()); addSourceDevice(deviceIndex); // add the first device set with file input device as default if device in settings is not enumerated @@ -2079,7 +2079,7 @@ void MainWindow::sampleSourceChanged(int tabIndex, int newDeviceIndex) qDebug("MainWindow::sampleSourceChanged: save default starting device %s[%d:%d]", qPrintable(samplingDevice->id), samplingDevice->sequence, samplingDevice->deviceItemIndex); m_mainCore->m_settings.setSourceIndex(samplingDevice->sequence); - m_mainCore->m_settings.setSourceDeviceId(samplingDevice->id); + m_mainCore->m_settings.setSourceDevice(samplingDevice->id); m_mainCore->m_settings.setSourceItemIndex(samplingDevice->deviceItemIndex); } }