use Qt API, not STL, for map operation

This commit is contained in:
Kevin Matz 2022-11-28 09:39:11 -05:00
parent 01c569ffa4
commit 3f78a9de01

View File

@ -238,27 +238,26 @@ void QSacnUniverse::setValue (const uint16_t addr, const uint16_t size,
*/ */
void QSacnUniverse::syncSources() void QSacnUniverse::syncSources()
{ {
// create a new list of sources
QMap<sACN::DATA::data_header, QSacnUniverse*> newSources; QMap<sACN::DATA::data_header, QSacnUniverse*> newSources;
auto headers = universe_->sources(); auto headers = universe_->sources();
for (const auto & metadata : headers) for (const auto & metadata : headers)
{ {
auto it = sources_.find(metadata); if (sources_.contains(metadata))
if (it == sources_.end()) // move the QSacnUniverse to the new list
{ // not found newSources.insert(metadata, sources_.take(metadata));
else
{ // make a new QSacnUniverse to add to the new list
auto universe = universe_->sourceUniverse(metadata); auto universe = universe_->sourceUniverse(metadata);
newSources.insert(metadata, new QSacnUniverse(this, universe)); newSources.insert(metadata, new QSacnUniverse(this, universe));
} }
else
{ // found
auto universe = sources_.take(metadata);
newSources.insert(metadata, universe);
}
} }
// delete any remaining QSacnUniverse, ie. not moved to the new list // delete any remaining sources, ie. not moved to the new list
qDeleteAll(sources_); qDeleteAll(sources_);
// accept the new list
sources_ = newSources; sources_ = newSources;
emit sourceListChanged(); emit sourceListChanged();
} }