kopia lustrzana https://github.com/f4exb/sdrangel
Implemented a list of source configuration in the Preset object with add or update and find best match methods
rodzic
eb08ef55b3
commit
c85813b577
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue