Fixed clazy warnings: unnecessary containers and containers being detached in range-for loops.

This commit is contained in:
Mat Sutcliffe
2018-12-17 17:42:44 +00:00
parent 684ffeb671
commit 462172a87f
18 changed files with 114 additions and 139 deletions

View File

@@ -76,7 +76,7 @@ namespace BlackCore
if (m_plugins.isEmpty()) { return 0; } if (m_plugins.isEmpty()) { return 0; }
int c = 0; int c = 0;
for (PluginExtended &pi : m_plugins.values()) for (PluginExtended &pi : m_plugins)
{ {
if (!pi.listener) { continue; } if (!pi.listener) { continue; }
if (!pi.listener->isRunning()) { continue; } if (!pi.listener->isRunning()) { continue; }

View File

@@ -420,12 +420,12 @@ namespace BlackGui
{ {
ui->cb_OtherVersions->clear(); ui->cb_OtherVersions->clear();
const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion(); const QMap<QString, CApplicationInfo> otherVersions = CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion();
for (const QString &directory : otherVersions.keys()) for (const auto &pair : makePairsRange(otherVersions))
{ {
const CApplicationInfo info(otherVersions.value(directory)); const CApplicationInfo &info(pair.second);
if (info.isNull()) if (info.isNull())
{ {
const QString infoString = CDirectoryUtils::decodeNormalizedDirectory(directory); const QString infoString = CDirectoryUtils::decodeNormalizedDirectory(pair.first);
ui->cb_OtherVersions->addItem(infoString); ui->cb_OtherVersions->addItem(infoString);
} }
else else
@@ -433,7 +433,7 @@ namespace BlackGui
static const QString item("swift %1 (%2)"); static const QString item("swift %1 (%2)");
ui->cb_OtherVersions->addItem(item.arg(info.getVersionString(), info.getPlatform())); ui->cb_OtherVersions->addItem(item.arg(info.getVersionString(), info.getPlatform()));
} }
m_otherVersionDirs.push_back(directory); m_otherVersionDirs.push_back(pair.first);
} }
} }

View File

@@ -25,7 +25,7 @@ namespace BlackGui
{ {
ui->setupUi(this); ui->setupUi(this);
m_allCheckBoxes = this->findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly); m_allCheckBoxes = this->findChildren<QCheckBox *>(QString(), Qt::FindDirectChildrenOnly);
for (QCheckBox *cb : m_allCheckBoxes) for (QCheckBox *cb : as_const(m_allCheckBoxes))
{ {
connect(cb, &QCheckBox::stateChanged, this, &CInterpolationSetupForm::onCheckboxChanged); connect(cb, &QCheckBox::stateChanged, this, &CInterpolationSetupForm::onCheckboxChanged);
} }

View File

@@ -329,7 +329,7 @@ namespace BlackGui
void CInfoArea::adjustSizeForAllDockWidgets() void CInfoArea::adjustSizeForAllDockWidgets()
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
dw->adjustSize(); dw->adjustSize();
} }
@@ -337,7 +337,7 @@ namespace BlackGui
void CInfoArea::floatAllWidgets() void CInfoArea::floatAllWidgets()
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
if (dw->isFloating()) { continue; } if (dw->isFloating()) { continue; }
dw->toggleFloating(); dw->toggleFloating();
@@ -346,7 +346,7 @@ namespace BlackGui
void CInfoArea::allFloatingOnTop() void CInfoArea::allFloatingOnTop()
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
const bool f = dw->isFloating(); const bool f = dw->isFloating();
CGuiUtility::stayOnTop(f, dw); CGuiUtility::stayOnTop(f, dw);
@@ -479,11 +479,11 @@ namespace BlackGui
void CInfoArea::displayStatusMessage(const CStatusMessage &statusMessage) void CInfoArea::displayStatusMessage(const CStatusMessage &statusMessage)
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
dw->displayStatusMessage(statusMessage); dw->displayStatusMessage(statusMessage);
} }
for (CInfoArea *ia : m_childInfoAreas) for (CInfoArea *ia : as_const(m_childInfoAreas))
{ {
ia->displayStatusMessage(statusMessage); ia->displayStatusMessage(statusMessage);
} }
@@ -491,11 +491,11 @@ namespace BlackGui
void CInfoArea::displayStatusMessages(const CStatusMessageList &statusMessages) void CInfoArea::displayStatusMessages(const CStatusMessageList &statusMessages)
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
dw->displayStatusMessages(statusMessages); dw->displayStatusMessages(statusMessages);
} }
for (CInfoArea *ia : m_childInfoAreas) for (CInfoArea *ia : as_const(m_childInfoAreas))
{ {
ia->displayStatusMessages(statusMessages); ia->displayStatusMessages(statusMessages);
} }
@@ -503,7 +503,7 @@ namespace BlackGui
void CInfoArea::setDockArea(Qt::DockWidgetArea area) void CInfoArea::setDockArea(Qt::DockWidgetArea area)
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
Qt::DockWidgetAreas newAreas = static_cast<Qt::DockWidgetAreas>(area); Qt::DockWidgetAreas newAreas = static_cast<Qt::DockWidgetAreas>(area);
Qt::DockWidgetAreas oldAreas = dw->allowedAreas(); Qt::DockWidgetAreas oldAreas = dw->allowedAreas();
@@ -624,7 +624,7 @@ namespace BlackGui
void CInfoArea::unTabifyAllWidgets() void CInfoArea::unTabifyAllWidgets()
{ {
if (m_dockWidgetInfoAreas.size() < 2) return; if (m_dockWidgetInfoAreas.size() < 2) return;
CDockWidgetInfoArea *first = m_dockWidgetInfoAreas.first(); CDockWidgetInfoArea *first = m_dockWidgetInfoAreas.constFirst();
for (int i = 1; i < m_dockWidgetInfoAreas.size(); i++) for (int i = 1; i < m_dockWidgetInfoAreas.size(); i++)
{ {
CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i); CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i);
@@ -641,7 +641,7 @@ namespace BlackGui
void CInfoArea::connectTopLevelChanged() void CInfoArea::connectTopLevelChanged()
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
connect(dw, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CInfoArea::onWidgetTopLevelChanged); connect(dw, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CInfoArea::onWidgetTopLevelChanged);
} }
@@ -753,7 +753,7 @@ namespace BlackGui
void CInfoArea::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features) void CInfoArea::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features)
{ {
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
dw->setFeatures(features); dw->setFeatures(features);
} }
@@ -826,7 +826,7 @@ namespace BlackGui
{ {
if (show == m_showTabTexts) { return; } if (show == m_showTabTexts) { return; }
m_showTabTexts = show; m_showTabTexts = show;
for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas))
{ {
dw->showTitleWhenDocked(show); dw->showTitleWhenDocked(show);
} }

View File

@@ -171,7 +171,7 @@ namespace BlackGui
QList<QAction *> CMenuActions::getQActions() const QList<QAction *> CMenuActions::getQActions() const
{ {
QList<QAction *> qActions; QList<QAction *> qActions;
for (const CMenuAction &a : this->toQList()) for (const CMenuAction &a : m_actions)
{ {
qActions.append(a.getQAction()); qActions.append(a.getQAction());
} }
@@ -243,7 +243,7 @@ namespace BlackGui
{ {
CMenuAction a; CMenuAction a;
CMenuActions menuActions; CMenuActions menuActions;
for (const CMenuAction &action : actions.toQList()) for (const CMenuAction &action : actions.m_actions)
{ {
a = this->addAction(action); a = this->addAction(action);
menuActions.addAction(a); menuActions.addAction(a);
@@ -431,7 +431,7 @@ namespace BlackGui
CMenuActions::operator QList<QAction *>() const CMenuActions::operator QList<QAction *>() const
{ {
QList<QAction *> qActions; QList<QAction *> qActions;
for (const CMenuAction &a : toQList()) for (const CMenuAction &a : m_actions)
{ {
if (!a.getQAction()) { continue; } if (!a.getQAction()) { continue; }
qActions.append(a.getQAction()); qActions.append(a.getQAction());

View File

@@ -69,7 +69,7 @@ namespace BlackGui
QStandardItemModel::clear(); QStandardItemModel::clear();
int visibleColumns = 0; int visibleColumns = 0;
for (const QString &suffix : m_suffixes) for (const QString &suffix : as_const(m_suffixes))
{ {
// ownership of QStandardItem is taken by model // ownership of QStandardItem is taken by model
QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::atcSuffixToIcon(suffix).toQIcon(), suffix); QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::atcSuffixToIcon(suffix).toQIcon(), suffix);

View File

@@ -119,7 +119,7 @@ namespace BlackInput
} }
} }
for (const CJoystickDeviceInput &input : m_joystickDeviceInputs) for (const CJoystickDeviceInput &input : as_const(m_joystickDeviceInputs))
{ {
const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0; const qint32 buttonIndex = input.m_offset - DIJOFS_BUTTON0;
bool isPressed = state.rgbButtons[buttonIndex] & 0x80; bool isPressed = state.rgbButtons[buttonIndex] & 0x80;
@@ -187,7 +187,7 @@ namespace BlackInput
CJoystickWindows::~CJoystickWindows() CJoystickWindows::~CJoystickWindows()
{ {
// All DirectInput devices need to be cleaned up before the call to CoUninitialize() // All DirectInput devices need to be cleaned up before the call to CoUninitialize()
for (CJoystickDevice *joystickDevice : m_joystickDevices) for (CJoystickDevice *joystickDevice : as_const(m_joystickDevices))
{ {
delete joystickDevice; delete joystickDevice;
} }

View File

@@ -49,9 +49,8 @@ namespace BlackMisc
CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion() : CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion() :
CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(); CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion();
for (const QString &directory : otherVersions.keys()) for (const CApplicationInfo &info : otherVersions)
{ {
CApplicationInfo info(otherVersions.value(directory));
this->push_back(info); this->push_back(info);
} }
return this->size(); return this->size();

View File

@@ -304,35 +304,21 @@ namespace BlackMisc
QMap<QString, int> count; QMap<QString, int> count;
for (const CAircraftIcaoCode &icao : *this) for (const CAircraftIcaoCode &icao : *this)
{ {
if (!icao.hasManufacturer()) continue; if (!icao.hasManufacturer()) { continue; }
const QString m(icao.getManufacturer()); count[icao.getManufacturer()]++;
if (count.contains(m))
{
count[m]++;
}
else
{
count[m] = 1;
}
} }
return count; return count;
} }
QPair<QString, int> CAircraftIcaoCodeList::maxCountManufacturer() const QPair<QString, int> CAircraftIcaoCodeList::maxCountManufacturer() const
{ {
if (this->isEmpty()) return QPair<QString, int>("", 0);
const QMap<QString, int> counts(countManufacturers()); const QMap<QString, int> counts(countManufacturers());
QPair<QString, int> max; if (counts.isEmpty()) return { {}, 0 };
for (const QString &m : counts.keys()) const auto pair = *std::max_element(counts.keyValueBegin(), counts.keyValueEnd(), [](const auto &a, const auto &b)
{ {
const int mv = counts[m]; return a.second < b.second;
if (mv > max.second) });
{ return { pair.first, pair.second };
max.first = m;
max.second = mv;
}
}
return max;
} }
CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncompleteAndDuplicates, CAircraftIcaoCodeList *inconsistent) CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncompleteAndDuplicates, CAircraftIcaoCodeList *inconsistent)

View File

@@ -423,7 +423,7 @@ namespace BlackMisc
if (updateUuid) { m_admittedQueue.clear(); } if (updateUuid) { m_admittedQueue.clear(); }
else if (! m_admittedQueue.isEmpty()) { m_admittedQueue.intersect(QSet<QString>::fromList(m_timestamps.keys())); } else if (! m_admittedQueue.isEmpty()) { m_admittedQueue.intersect(QSet<QString>::fromList(m_timestamps.keys())); }
for (const auto &key : m_timestamps.keys()) for (const auto &key : m_timestamps.keys()) // clazy:exclude=container-anti-pattern,range-loop
{ {
if (deferrals.contains(key) && ! m_admittedValues.contains(key)) { m_timestamps.remove(key); } if (deferrals.contains(key) && ! m_admittedValues.contains(key)) { m_timestamps.remove(key); }
} }

View File

@@ -318,6 +318,26 @@ namespace BlackMisc
//! Returns const iterator at the end of the dictionary //! Returns const iterator at the end of the dictionary
const_iterator cend() const { return m_impl.cend(); } const_iterator cend() const { return m_impl.cend(); }
//! Returns const iterator for iterating over keys
//! @{
auto keyBegin() const { return m_impl.keyBegin(); }
auto keyEnd() const { return m_impl.keyEnd(); }
//! @}
//! Returns iterator for iterating over keys and values together
//! @{
auto keyValueBegin() { return m_impl.keyValueBegin(); }
auto keyValueEnd() { return m_impl.keyValueEnd(); }
//! @}
//! Returns const iterator for iterating over keys and values together
//! @{
auto keyValueBegin() const { return m_impl.keyValueBegin(); }
auto constKeyValueBegin() const { return m_impl.constKeyValueBegin(); }
auto keyValueEnd() const { return m_impl.keyValueEnd(); }
auto constKeyValueEnd() const { return m_impl.constKeyValueEnd(); }
//! @}
//! Removes all items from the dictionary //! Removes all items from the dictionary
void clear() { m_impl.clear(); } void clear() { m_impl.clear(); }
@@ -369,8 +389,8 @@ namespace BlackMisc
//! Return key assigned to value or if key is not found defaultKey //! Return key assigned to value or if key is not found defaultKey
const Key key(const Value &value, const Key & defaultKey) const { return m_impl.key(value, defaultKey); } const Key key(const Value &value, const Key & defaultKey) const { return m_impl.key(value, defaultKey); }
//! Return a range of all keys //! Return a range of all keys (does not allocate a temporary container)
CRange<Iterators::KeyIterator<const_iterator>> keys() const { return makeRange(Iterators::makeKeyIterator(begin()), end()); } auto keys() const { return makeRange(keyBegin(), keyEnd()); }
//! Remove all items with key from the dictionary //! Remove all items with key from the dictionary
int remove(const Key &key) { return m_impl.remove(key); } int remove(const Key &key) { return m_impl.remove(key); }
@@ -387,7 +407,7 @@ namespace BlackMisc
//! Returns the value associated with the key or if key is not found defaultValue //! Returns the value associated with the key or if key is not found defaultValue
const Value value(const Key &key, const Value &defaultValue) const { return m_impl.value(key, defaultValue); } const Value value(const Key &key, const Value &defaultValue) const { return m_impl.value(key, defaultValue); }
//! Return a range of all values //! Return a range of all values (does not allocate a temporary container)
CRange<const_iterator> values() const { return makeRange(begin(), end()); } CRange<const_iterator> values() const { return makeRange(begin(), end()); }
//! Copy assignment. //! Copy assignment.
@@ -407,7 +427,6 @@ namespace BlackMisc
Value &operator [](const Key &key) { return m_impl[key]; } Value &operator [](const Key &key) { return m_impl[key]; }
//! Access an element by its key. //! Access an element by its key.
//! \note If dictionary does not contain any item with key, a default constructed value will be inserted.
const Value operator [](const Key &key) const { return m_impl[key]; } const Value operator [](const Key &key) const { return m_impl[key]; }
//! Test for equality. //! Test for equality.

View File

@@ -289,7 +289,7 @@ namespace BlackMisc
QString last; QString last;
QStringList result; QStringList result;
for (const QString &path : dirs) for (const QString &path : as_const(dirs))
{ {
if (path.isEmpty()) { continue; } if (path.isEmpty()) { continue; }
if (last.isEmpty() || !path.startsWith(last, cs)) if (last.isEmpty() || !path.startsWith(last, cs))

View File

@@ -95,54 +95,6 @@ namespace BlackMisc
return Private::makeInsertIterator(container, THasPushBack<T>()); return Private::makeInsertIterator(container, THasPushBack<T>());
} }
/*!
* Iterator wrapper for Qt's STL-style associative container iterators, when dereferenced return the key instead of the value.
*
* By creating a CRange from such iterators, it is possible to create a container of keys without copying them.
*/
template <class I> class KeyIterator
: public std::iterator<std::bidirectional_iterator_tag, std::decay_t<decltype(std::declval<I>().key())>>
{
public:
//! Constructor
KeyIterator(I iterator) : m_iterator(iterator) {}
//! Advance to the next element.
//! Undefined if iterator is at the end.
//! @{
KeyIterator &operator ++() { ++m_iterator; return *this; }
KeyIterator operator ++(int) { auto copy = *this; ++m_iterator; return copy; }
//! @}
//! Regress to the previous element.
//! Undefined if iterator is at the beginning.
//! @{
KeyIterator &operator --() { --m_iterator; return *this; }
KeyIterator operator --(int) { auto copy = *this; --m_iterator; return copy; }
//! @}
//! Return the value at this iterator position.
auto value() const { return m_iterator.value(); }
//! Return the key at this iterator position.
//! @{
auto key() const { return m_iterator.key(); }
auto operator *() const { return key(); }
//! @}
//! Indirection operator: pointer to the key at this iterator position.
auto operator ->() const { return &key(); }
//! Equality operators.
//! @{
bool operator ==(const KeyIterator &other) const { return m_iterator == other.m_iterator; }
bool operator !=(const KeyIterator &other) const { return m_iterator != other.m_iterator; }
//! @}
private:
I m_iterator;
};
/*! /*!
* Iterator wrapper which applies some transformation function to each element. * Iterator wrapper which applies some transformation function to each element.
* *
@@ -325,14 +277,6 @@ namespace BlackMisc
QVector<I> m_iterators; QVector<I> m_iterators;
}; };
/*!
* Construct a KeyIterator of the appropriate type from deduced template function argument.
*/
template <class I> auto makeKeyIterator(I iterator) -> KeyIterator<I>
{
return { iterator };
}
/*! /*!
* Construct a TransformIterator of the appropriate type from deduced template function arguments. * Construct a TransformIterator of the appropriate type from deduced template function arguments.
*/ */

View File

@@ -321,14 +321,27 @@ namespace BlackMisc
} }
/*! /*!
* Returns a const CRange for iterating over the keys of an associative container. * Returns a const CRange for iterating over the keys of a Qt associative container.
* *
* This is more efficient than the keys() method of the container, as it doesn't allocate memory. * This is more efficient than the keys() method of the container, as it doesn't allocate memory.
*/ */
template <class T> template <class T>
auto makeKeysRange(const T &container) auto makeKeysRange(const T &container)
{ {
return makeRange(Iterators::makeKeyIterator(container.cbegin()), container.cend()); return makeRange(container.keyBegin(), container.keyEnd());
}
/*!
* Returns a const CRange for iterating over the keys and values of a Qt associative container.
* The value_type of the returned range is std::pair<T::key_type &, T::value_type &>.
*
* This is more efficient than using the keys() method of the container and thereafter looking up each key,
* as it neither allocates memory, nor performs any key lookups.
*/
template <class T>
auto makePairsRange(const T &container)
{
return makeRange(container.keyValueBegin(), container.keyValueEnd());
} }
/*! /*!
@@ -345,6 +358,20 @@ namespace BlackMisc
template <class T> template <class T>
void makeKeysRange(const T &&container) = delete; void makeKeysRange(const T &&container) = delete;
/*!
* Pairs range for a non-const lvalue would be unsafe due to iterator invalidation on detach().
*
* \see http://doc.qt.io/qt-5/containers.html#implicit-sharing-iterator-problem
*/
template <class T>
void makePairsRange(T &container) = delete;
/*!
* Pairs range for a temporary would be unsafe.
*/
template <class T>
void makePairsRange(const T &&container) = delete;
/* /*
* Member functions of CRangeBase template defined out of line, because they depend on CRange etc. * Member functions of CRangeBase template defined out of line, because they depend on CRange etc.
*/ */

View File

@@ -352,11 +352,11 @@ namespace BlackMisc
{ {
const QMap<QString, int> modelStrings = this->countPerModelString(); const QMap<QString, int> modelStrings = this->countPerModelString();
CAircraftModelList duplicates; CAircraftModelList duplicates;
for (const QString &ms : modelStrings.keys()) for (const auto &pair : makePairsRange(modelStrings))
{ {
if (modelStrings[ms] > 1) if (pair.second > 1)
{ {
duplicates.push_back(this->findByModelString(ms, Qt::CaseInsensitive)); duplicates.push_back(this->findByModelString(pair.first, Qt::CaseInsensitive));
} }
} }
return duplicates; return duplicates;

View File

@@ -62,9 +62,9 @@ namespace BlackMisc
{ {
const SetupsPerCallsign setups = this->getSetupsPerCallsign(); const SetupsPerCallsign setups = this->getSetupsPerCallsign();
CCallsignSet callsigns; CCallsignSet callsigns;
for (const CCallsign &cs : setups.keys()) for (const auto &pair : makePairsRange(setups))
{ {
if (setups.value(cs).logInterpolation()) { callsigns.insert(cs); } if (pair.second.logInterpolation()) { callsigns.insert(pair.first); }
} }
return callsigns; return callsigns;
} }
@@ -146,19 +146,19 @@ namespace BlackMisc
void IInterpolationSetupProvider::clearInterpolationLogCallsigns() void IInterpolationSetupProvider::clearInterpolationLogCallsigns()
{ {
SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign(); const SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign();
if (setupsCopy.isEmpty()) { return; } if (setupsCopy.isEmpty()) { return; }
// potential risk, changes inbetween in another thread are missed now // potential risk, changes inbetween in another thread are missed now
// on the other side, we keep locks for a minimal time frame // on the other side, we keep locks for a minimal time frame
SetupsPerCallsign setupsToKeep; SetupsPerCallsign setupsToKeep;
CInterpolationAndRenderingSetupGlobal global = this->getInterpolationSetupGlobal(); CInterpolationAndRenderingSetupGlobal global = this->getInterpolationSetupGlobal();
for (const CCallsign &cs : setupsCopy.keys()) for (const auto &pair : makePairsRange(setupsCopy))
{ {
CInterpolationAndRenderingSetupPerCallsign setup = setupsCopy.value(cs); CInterpolationAndRenderingSetupPerCallsign setup = pair.second;
setup.setLogInterpolation(false); setup.setLogInterpolation(false);
if (setup.isEqualToGlobal(global)) { continue; } if (setup.isEqualToGlobal(global)) { continue; }
setupsToKeep.insert(cs, setup); setupsToKeep.insert(pair.first, setup);
} }
{ {
QWriteLocker l(&m_lockSetup); QWriteLocker l(&m_lockSetup);
@@ -184,9 +184,9 @@ namespace BlackMisc
{ {
const SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign(); const SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign();
if (setupsCopy.isEmpty()) { return false; } if (setupsCopy.isEmpty()) { return false; }
for (const CCallsign &cs : setupsCopy.keys()) for (const CInterpolationAndRenderingSetupPerCallsign &setup : setupsCopy)
{ {
if (setupsCopy.value(cs).logInterpolation()) { return true; } if (setup.logInterpolation()) { return true; }
} }
return false; return false;
} }

View File

@@ -296,7 +296,7 @@ namespace BlackSimPlugin
if (this->isEmpty()) { return CCallsignSet(); } if (this->isEmpty()) { return CCallsignSet(); }
if (!withoutProbes) { return CCallsignSet(this->keys()); } if (!withoutProbes) { return CCallsignSet(this->keys()); }
CCallsignSet callsigns; CCallsignSet callsigns;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isAircraft()) { callsigns.insert(simObject.getCallsign().asString()); } if (simObject.isAircraft()) { callsigns.insert(simObject.getCallsign().asString()); }
} }
@@ -315,7 +315,7 @@ namespace BlackSimPlugin
CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(DWORD objectId) const CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(DWORD objectId) const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.getObjectId() == objectId) { return simObject; } if (simObject.getObjectId() == objectId) { return simObject; }
} }
@@ -326,7 +326,7 @@ namespace BlackSimPlugin
{ {
if (this->isEmpty()) { return CSimConnectObject(); } if (this->isEmpty()) { return CSimConnectObject(); }
CSimConnectObject oldestSimObj = *this->begin(); CSimConnectObject oldestSimObj = *this->begin();
for (const CSimConnectObject &simObj : this->values()) for (const CSimConnectObject &simObj : *this)
{ {
if (!simObj.hasCreatedTimestamp()) { continue; } if (!simObj.hasCreatedTimestamp()) { continue; }
if (!oldestSimObj.hasCreatedTimestamp() || oldestSimObj.getCreatedTimestamp() > simObj.getCreatedTimestamp()) if (!oldestSimObj.hasCreatedTimestamp() || oldestSimObj.getCreatedTimestamp() > simObj.getCreatedTimestamp())
@@ -339,7 +339,7 @@ namespace BlackSimPlugin
CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.getRequestId() == requestId) { return simObject; } if (simObject.getRequestId() == requestId) { return simObject; }
} }
@@ -390,7 +390,7 @@ namespace BlackSimPlugin
bool CSimConnectObjects::containsPendingAdded() const bool CSimConnectObjects::containsPendingAdded() const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isPendingAdded()) { return true; } if (simObject.isPendingAdded()) { return true; }
} }
@@ -399,7 +399,7 @@ namespace BlackSimPlugin
bool CSimConnectObjects::containsPendingRemoved() const bool CSimConnectObjects::containsPendingRemoved() const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isPendingRemoved()) { return true; } if (simObject.isPendingRemoved()) { return true; }
} }
@@ -409,7 +409,7 @@ namespace BlackSimPlugin
int CSimConnectObjects::countPendingAdded() const int CSimConnectObjects::countPendingAdded() const
{ {
int c = 0; int c = 0;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isPendingAdded()) { c++; } if (simObject.isPendingAdded()) { c++; }
} }
@@ -419,7 +419,7 @@ namespace BlackSimPlugin
int CSimConnectObjects::countPendingRemoved() const int CSimConnectObjects::countPendingRemoved() const
{ {
int c = 0; int c = 0;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isPendingRemoved()) { c++; } if (simObject.isPendingRemoved()) { c++; }
} }
@@ -429,7 +429,7 @@ namespace BlackSimPlugin
int CSimConnectObjects::countConfirmedAdded() int CSimConnectObjects::countConfirmedAdded()
{ {
int c = 0; int c = 0;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : as_const(*this))
{ {
if (simObject.isConfirmedAdded()) { c++; } if (simObject.isConfirmedAdded()) { c++; }
} }
@@ -439,7 +439,7 @@ namespace BlackSimPlugin
CCallsignSet CSimConnectObjects::getPendingAddedCallsigns() const CCallsignSet CSimConnectObjects::getPendingAddedCallsigns() const
{ {
CCallsignSet callsigns; CCallsignSet callsigns;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isPendingAdded()) { callsigns.push_back(simObject.getCallsign()); } if (simObject.isPendingAdded()) { callsigns.push_back(simObject.getCallsign()); }
} }
@@ -449,7 +449,7 @@ namespace BlackSimPlugin
CCallsignSet CSimConnectObjects::getPendingRemovedCallsigns() const CCallsignSet CSimConnectObjects::getPendingRemovedCallsigns() const
{ {
CCallsignSet callsigns; CCallsignSet callsigns;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.isPendingRemoved()) { callsigns.push_back(simObject.getCallsign()); } if (simObject.isPendingRemoved()) { callsigns.push_back(simObject.getCallsign()); }
} }
@@ -459,7 +459,7 @@ namespace BlackSimPlugin
QList<CSimConnectObject> CSimConnectObjects::getByType(CSimConnectObject::SimObjectType type) const QList<CSimConnectObject> CSimConnectObjects::getByType(CSimConnectObject::SimObjectType type) const
{ {
QList<CSimConnectObject> objs; QList<CSimConnectObject> objs;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.getType() == type) { objs.push_back(simObject); } if (simObject.getType() == type) { objs.push_back(simObject); }
} }
@@ -468,7 +468,7 @@ namespace BlackSimPlugin
CSimConnectObject CSimConnectObjects::getNotPendingProbe() const CSimConnectObject CSimConnectObjects::getNotPendingProbe() const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending()) { return simObject; } if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending()) { return simObject; }
} }
@@ -478,7 +478,7 @@ namespace BlackSimPlugin
CSimConnectObject CSimConnectObjects::getOldestNotPendingProbe() const CSimConnectObject CSimConnectObjects::getOldestNotPendingProbe() const
{ {
CSimConnectObject oldestProbe; CSimConnectObject oldestProbe;
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending()) if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending())
{ {
@@ -493,7 +493,7 @@ namespace BlackSimPlugin
bool CSimConnectObjects::containsType(CSimConnectObject::SimObjectType type) const bool CSimConnectObjects::containsType(CSimConnectObject::SimObjectType type) const
{ {
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : *this)
{ {
if (simObject.getType() == type) { return true; } if (simObject.getType() == type) { return true; }
} }
@@ -516,7 +516,7 @@ namespace BlackSimPlugin
CSimConnectObjects removedObjects; CSimConnectObjects removedObjects;
const qint64 ts = QDateTime::currentMSecsSinceEpoch(); const qint64 ts = QDateTime::currentMSecsSinceEpoch();
for (const CSimConnectObject &simObject : this->values()) for (const CSimConnectObject &simObject : as_const(*this))
{ {
// verification takes at least a second, so we need some time before outdating // verification takes at least a second, so we need some time before outdating
if (type != CSimConnectObject::AllTypes && simObject.getType() != type) { continue; } if (type != CSimConnectObject::AllTypes && simObject.getType() != type) { continue; }

View File

@@ -1103,7 +1103,7 @@ namespace BlackSimPlugin
const CCallsignSet aircraftCallsignsInRange(this->getAircraftInRangeCallsigns()); const CCallsignSet aircraftCallsignsInRange(this->getAircraftInRangeCallsigns());
CSimulatedAircraftList toBeAddedAircraft; // aircraft still to be added CSimulatedAircraftList toBeAddedAircraft; // aircraft still to be added
CCallsignSet toBeRemovedCallsigns; CCallsignSet toBeRemovedCallsigns;
for (const CSimConnectObject &pendingSimObj : m_addPendingAircraft.values()) for (const CSimConnectObject &pendingSimObj : as_const(m_addPendingAircraft))
{ {
Q_ASSERT_X(!pendingSimObj.getCallsign().isEmpty(), Q_FUNC_INFO, "missing callsign"); Q_ASSERT_X(!pendingSimObj.getCallsign().isEmpty(), Q_FUNC_INFO, "missing callsign");
if (pendingSimObj.isTerrainProbe() || aircraftCallsignsInRange.contains(pendingSimObj.getCallsign())) if (pendingSimObj.isTerrainProbe() || aircraftCallsignsInRange.contains(pendingSimObj.getCallsign()))