1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-04 16:01:14 -05:00

Implemented a list of source configuration in the Preset object with add or update and find best match methods

This commit is contained in:
f4exb 2015-10-01 08:54:56 +02:00
parent eb08ef55b3
commit c85813b577
2 changed files with 129 additions and 0 deletions

View File

@ -18,6 +18,25 @@ public:
};
typedef QList<ChannelConfig> ChannelConfigs;
struct SourceConfig
{
QString m_sourceId;
QString m_sourceSerial;
int m_sourceSequence;
QByteArray m_config;
SourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence,
const QByteArray& config) :
m_sourceId(sourceId),
m_sourceSerial(sourceSerial),
m_sourceSequence(sourceSequence),
m_config(config)
{ }
};
typedef QList<SourceConfig> SourceConfigs;
Preset();
void resetToDefaults();
@ -55,6 +74,15 @@ public:
const int getSourceSequence() const { return m_sourceSequence; }
const QByteArray& getSourceConfig() const { return m_sourceConfig; }
void addOrUpdateSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence,
const QByteArray& config);
const QByteArray* findBestSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence);
protected:
// group and preset description
QString m_group;
@ -77,6 +105,9 @@ protected:
// channels and configurations
ChannelConfigs m_channelConfigs;
// sources and configurations
SourceConfigs m_sourceConfigs;
// screen and dock layout
QByteArray m_layout;
};

View File

@ -83,3 +83,101 @@ bool Preset::deserialize(const QByteArray& data)
return false;
}
}
void Preset::addOrUpdateSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence,
const QByteArray& config)
{
SourceConfigs::iterator it = m_sourceConfigs.begin();
for (; it != m_sourceConfigs.end(); ++it)
{
if (it->m_sourceId == sourceId)
{
if (sourceSerial.isNull() || sourceSerial.isEmpty())
{
if (it->m_sourceSequence == sourceSequence)
{
break;
}
}
else
{
if (it->m_sourceSerial == sourceSerial)
{
break;
}
}
}
}
if (it == m_sourceConfigs.end())
{
m_sourceConfigs.push_back(SourceConfig(sourceId, sourceSerial, sourceSequence, config));
}
else
{
it->m_config = config;
}
}
const QByteArray* Preset::findBestSourceConfig(const QString& sourceId,
const QString& sourceSerial,
int sourceSequence)
{
SourceConfigs::const_iterator it = m_sourceConfigs.begin();
SourceConfigs::const_iterator itFirstOfKind = m_sourceConfigs.end();
SourceConfigs::const_iterator itMatchSequence = m_sourceConfigs.end();
for (; it != m_sourceConfigs.end(); ++it)
{
if (it->m_sourceId == sourceId)
{
if (itFirstOfKind == m_sourceConfigs.end())
{
itFirstOfKind = it;
}
if (sourceSerial.isNull() || sourceSerial.isEmpty())
{
if (it->m_sourceSequence == sourceSequence)
{
break;
}
}
else
{
if (it->m_sourceSerial == sourceSerial)
{
break;
}
else if(it->m_sourceSequence == sourceSequence)
{
itMatchSequence = it;
}
}
}
}
if (it == m_sourceConfigs.end()) // no exact match
{
if (itMatchSequence != m_sourceConfigs.end()) // match sequence ?
{
return &(itMatchSequence->m_config);
}
else if (itFirstOfKind != m_sourceConfigs.end()) // match source type ?
{
return &(itFirstOfKind->m_config);
}
else // definitely not found !
{
return 0;
}
}
else // exact match
{
return &(it->m_config);
}
}