Multiple sources for the same preset. Working more or less

pull/6/head
f4exb 2015-10-02 04:04:38 +02:00
rodzic 51914b4767
commit 83d6d9d190
8 zmienionych plików z 200 dodań i 46 usunięć

Wyświetl plik

@ -103,7 +103,7 @@ private:
PluginManager* m_pluginManager;
void loadSettings();
void loadPresetSettings(Preset* preset);
void loadPresetSettings(const Preset* preset);
void savePresetSettings(Preset* preset);
void saveSettings();

Wyświetl plik

@ -47,8 +47,10 @@ public:
void registerSampleSource(const QString& sourceName, PluginInterface* plugin);
void loadSettings(Preset* preset);
void loadSettings(const Preset* preset);
void loadSourceSettings(const Preset* preset);
void saveSettings(Preset* preset);
void saveSourceSettings(Preset* preset);
void freeAll();

Wyświetl plik

@ -0,0 +1,34 @@
#ifndef INCLUDE_SETTINGS_H
#define INCLUDE_SETTINGS_H
#include <QString>
#include "preferences.h"
#include "preset.h"
class MainSettings {
public:
MainSettings();
~MainSettings();
void load();
void save() const;
void resetToDefaults();
Preset* newPreset(const QString& group, const QString& description);
void deletePreset(const Preset* preset);
int getPresetCount() const { return m_presets.count(); }
const Preset* getPreset(int index) const { return m_presets[index]; }
Preset* getWorkingPreset() { return &m_workingPreset; }
int getSourceIndex() const { return m_preferences.getSourceIndex(); }
void setSourceIndex(int value) { m_preferences.setSourceIndex(value); }
protected:
Preferences m_preferences;
Preset m_workingPreset;
typedef QList<Preset*> Presets;
Presets m_presets;
};
#endif // INCLUDE_SETTINGS_H

Wyświetl plik

@ -64,19 +64,8 @@ public:
void setSourceConfig(const QString& sourceId, const QString& sourceSerial, int sourceSequence, const QByteArray& config)
{
addOrUpdateSourceConfig(sourceId, sourceSerial, sourceSequence, config);
/*
m_sourceId = sourceId;
m_sourceSerial = sourceSerial;
m_sourceSequence = sourceSequence;
m_sourceConfig = config;*/
}
/*
const QString& getSourceId() const { return m_sourceId; }
const QString& getSourceSerial() const { return m_sourceSerial; }
const int getSourceSequence() const { return m_sourceSequence; }
const QByteArray& getSourceConfig() const { return m_sourceConfig; }*/
void addOrUpdateSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence,
@ -84,7 +73,7 @@ public:
const QByteArray* findBestSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence);
int sourceSequence) const;
protected:
// group and preset description

Wyświetl plik

@ -124,9 +124,10 @@ MainWindow::MainWindow(QWidget* parent) :
if (nbSources > 0)
{
//bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
m_pluginManager->selectSampleSource(sampleSourceIndex);
bool sampleSourceSignalsBlocked = ui->sampleSource->blockSignals(true);
ui->sampleSource->setCurrentIndex(sampleSourceIndex);
//ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
ui->sampleSource->blockSignals(sampleSourceSignalsBlocked);
}
qDebug() << "MainWindow::MainWindow: load current preset settings...";
@ -211,12 +212,13 @@ void MainWindow::loadSettings()
}
}
void MainWindow::loadPresetSettings(Preset* preset)
void MainWindow::loadPresetSettings(const Preset* preset)
{
qDebug("MainWindow::loadPresetSettings: preset [%s | %s]",
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
ui->glSpectrumGUI->deserialize(preset->getSpectrumConfig());
m_pluginManager->loadSettings(preset);
// has to be last step
@ -229,7 +231,6 @@ void MainWindow::saveSettings()
savePresetSettings(m_settings.getWorkingPreset());
m_settings.save();
}
void MainWindow::savePresetSettings(Preset* preset)
@ -238,6 +239,8 @@ void MainWindow::savePresetSettings(Preset* preset)
qPrintable(preset->getGroup()),
qPrintable(preset->getDescription()));
preset->setSpectrumConfig(ui->glSpectrumGUI->serialize());
preset->clearChannels();
m_pluginManager->saveSettings(preset);
preset->setLayout(saveState());
@ -498,14 +501,16 @@ void MainWindow::on_presetLoad_clicked()
if(item == 0)
{
qDebug("MainWindow::on_presetLoad_clicked: item null");
updatePresetControls();
return;
}
Preset* preset = qvariant_cast<Preset*>(item->data(0, Qt::UserRole));
const Preset* preset = qvariant_cast<const Preset*>(item->data(0, Qt::UserRole));
if(preset == 0)
{
qDebug("MainWindow::on_presetLoad_clicked: preset null");
return;
}
@ -556,10 +561,10 @@ void MainWindow::on_action_Preferences_triggered()
void MainWindow::on_sampleSource_currentIndexChanged(int index)
{
savePresetSettings(m_settings.getWorkingPreset());
m_pluginManager->saveSourceSettings(m_settings.getWorkingPreset());
m_pluginManager->selectSampleSource(ui->sampleSource->currentIndex());
m_settings.setSourceIndex(ui->sampleSource->currentIndex());
m_pluginManager->loadSettings(m_settings.getWorkingPreset());
m_pluginManager->loadSourceSettings(m_settings.getWorkingPreset());
}
void MainWindow::on_action_About_triggered()

Wyświetl plik

@ -83,7 +83,7 @@ void PluginManager::registerSampleSource(const QString& sourceName, PluginInterf
m_sampleSourceRegistrations.append(SampleSourceRegistration(sourceName, plugin));
}
void PluginManager::loadSettings(Preset* preset)
void PluginManager::loadSettings(const Preset* preset)
{
fprintf(stderr, "PluginManager::loadSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
@ -142,6 +142,13 @@ void PluginManager::loadSettings(Preset* preset)
renameChannelInstances();
loadSourceSettings(preset);
}
void PluginManager::loadSourceSettings(const Preset* preset)
{
fprintf(stderr, "PluginManager::loadSourceSettings: Loading preset [%s | %s]\n", qPrintable(preset->getGroup()), qPrintable(preset->getDescription()));
if(m_sampleSourcePluginGUI != 0)
{
const QByteArray* sourceConfig = preset->findBestSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence);
@ -151,15 +158,6 @@ void PluginManager::loadSettings(Preset* preset)
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
m_sampleSourcePluginGUI->deserialize(*sourceConfig);
}
/*
qDebug("PluginManager::loadSettings: source compare [%s] vs [%s]", qPrintable(m_sampleSourceId), qPrintable(preset->getSourceId()));
// TODO: have one set of source presets per identified source (preset -> find source with name)
if(m_sampleSourceId == preset->getSourceId())
{
qDebug() << "PluginManager::loadSettings: deserializing source " << qPrintable(m_sampleSourceId);
m_sampleSourcePluginGUI->deserialize(preset->getSourceConfig());
}*/
qint64 centerFrequency = preset->getCenterFrequency();
m_sampleSourcePluginGUI->setCenterFrequency(centerFrequency);
@ -181,17 +179,8 @@ bool PluginManager::ChannelInstanceRegistration::operator<(const ChannelInstance
void PluginManager::saveSettings(Preset* preset)
{
if(m_sampleSourcePluginGUI != NULL)
{
preset->addOrUpdateSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
//preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency());
}
/*
else
{
preset->setSourceConfig(QString::null, QString::null, 0, QByteArray());
}*/
qDebug("PluginManager::saveSettings");
saveSourceSettings(preset);
qSort(m_channelInstanceRegistrations.begin(), m_channelInstanceRegistrations.end()); // sort by increasing delta frequency and type
@ -201,6 +190,18 @@ void PluginManager::saveSettings(Preset* preset)
}
}
void PluginManager::saveSourceSettings(Preset* preset)
{
qDebug("PluginManager::saveSourceSettings");
if(m_sampleSourcePluginGUI != NULL)
{
preset->addOrUpdateSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
//preset->setSourceConfig(m_sampleSourceId, m_sampleSourceSerial, m_sampleSourceSequence, m_sampleSourcePluginGUI->serialize());
preset->setCenterFrequency(m_sampleSourcePluginGUI->getCenterFrequency());
}
}
void PluginManager::freeAll()
{
m_dspEngine->stopAcquistion();

Wyświetl plik

@ -0,0 +1,94 @@
#include <QSettings>
#include <QStringList>
#include "settings/mainsettings.h"
MainSettings::MainSettings()
{
resetToDefaults();
}
MainSettings::~MainSettings()
{
for(int i = 0; i < m_presets.count(); ++i)
{
delete m_presets[i];
}
}
void MainSettings::load()
{
QSettings s;
m_preferences.deserialize(qUncompress(QByteArray::fromBase64(s.value("preferences").toByteArray())));
m_workingPreset.deserialize(qUncompress(QByteArray::fromBase64(s.value("current").toByteArray())));
QStringList groups = s.childGroups();
for(int i = 0; i < groups.size(); ++i)
{
if(groups[i].startsWith("preset"))
{
s.beginGroup(groups[i]);
Preset* preset = new Preset;
if(preset->deserialize(qUncompress(QByteArray::fromBase64(s.value("data").toByteArray()))))
{
m_presets.append(preset);
}
else
{
delete preset;
}
s.endGroup();
}
}
}
void MainSettings::save() const
{
QSettings s;
s.setValue("preferences", qCompress(m_preferences.serialize()).toBase64());
s.setValue("current", qCompress(m_workingPreset.serialize()).toBase64());
QStringList groups = s.childGroups();
for(int i = 0; i < groups.size(); ++i)
{
if(groups[i].startsWith("preset"))
{
s.remove(groups[i]);
}
}
for(int i = 0; i < m_presets.count(); ++i)
{
QString group = QString("preset-%1").arg(i + 1);
s.beginGroup(group);
s.setValue("data", qCompress(m_presets[i]->serialize()).toBase64());
s.endGroup();
}
}
void MainSettings::resetToDefaults()
{
m_preferences.resetToDefaults();
m_workingPreset.resetToDefaults();
}
Preset* MainSettings::newPreset(const QString& group, const QString& description)
{
Preset* preset = new Preset();
preset->setGroup(group);
preset->setDescription(description);
m_presets.append(preset);
return preset;
}
void MainSettings::deletePreset(const Preset* preset)
{
m_presets.removeAll((Preset*)preset);
delete (Preset*)preset;
}

Wyświetl plik

@ -34,6 +34,7 @@ QByteArray Preset::serialize() const
s.writeString(2, m_description);
s.writeU64(3, m_centerFrequency);
s.writeBlob(4, m_layout);
s.writeBlob(5, m_spectrumConfig);
s.writeS32(20, m_sourceConfigs.size());
@ -44,7 +45,7 @@ QByteArray Preset::serialize() const
s.writeS32(26 + i*4, m_sourceConfigs[i].m_sourceSequence);
s.writeBlob(27 + i*4, m_sourceConfigs[i].m_config);
qDebug("Preset::serialize: source: id: %ss, ser: %s, seq: %d",
qDebug("Preset::serialize: source: id: %s, ser: %s, seq: %d",
qPrintable(m_sourceConfigs[i].m_sourceId),
qPrintable(m_sourceConfigs[i].m_sourceSerial),
m_sourceConfigs[i].m_sourceSequence);
@ -55,6 +56,16 @@ QByteArray Preset::serialize() const
}
}
s.writeS32(200, m_channelConfigs.size());
for(int i = 0; i < m_channelConfigs.size(); i++)
{
qDebug("Preset::serialize: channel: id: %s", qPrintable(m_channelConfigs[i].m_channel));
s.writeString(201 + i * 2, m_channelConfigs[i].m_channel);
s.writeBlob(202 + i * 2, m_channelConfigs[i].m_config);
}
return s.final();
}
@ -74,6 +85,7 @@ bool Preset::deserialize(const QByteArray& data)
d.readString(2, &m_description, "no name");
d.readU64(3, &m_centerFrequency, 0);
d.readBlob(4, &m_layout);
d.readBlob(5, &m_spectrumConfig);
qDebug("Preset::deserialize: m_group: %s m_description: %s m_centerFrequency: %llu",
qPrintable(m_group),
@ -88,7 +100,9 @@ bool Preset::deserialize(const QByteArray& data)
sourcesCount = ((200-23)/4) - 1;
}
for(int i = 0; i < sourcesCount; i++)
m_sourceConfigs.clear();
for (int i = 0; i < sourcesCount; i++)
{
QString sourceId, sourceSerial;
int sourceSequence;
@ -110,7 +124,22 @@ bool Preset::deserialize(const QByteArray& data)
}
}
return true;
qint32 channelCount;
d.readS32(200, &channelCount, 0);
m_channelConfigs.clear();
for (int i = 0; i < channelCount; i++)
{
QString channel;
QByteArray config;
d.readString(201 + i * 2, &channel, "unknown-channel");
d.readBlob(202 + i * 2, &config);
qDebug("Preset::deserialize: channel: id: %s", qPrintable(channel));
m_channelConfigs.append(ChannelConfig(channel, config));
}
}
else
{
@ -159,7 +188,7 @@ void Preset::addOrUpdateSourceConfig(const QString& sourceId,
const QByteArray* Preset::findBestSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence)
int sourceSequence) const
{
SourceConfigs::const_iterator it = m_sourceConfigs.begin();
SourceConfigs::const_iterator itFirstOfKind = m_sourceConfigs.end();