diff --git a/src/blackcore/pluginmanagersimulator.cpp b/src/blackcore/pluginmanagersimulator.cpp index ecddd4b0f..3be99ec42 100644 --- a/src/blackcore/pluginmanagersimulator.cpp +++ b/src/blackcore/pluginmanagersimulator.cpp @@ -76,7 +76,7 @@ namespace BlackCore if (m_plugins.isEmpty()) { return 0; } int c = 0; - for (PluginExtended &pi : m_plugins.values()) + for (PluginExtended &pi : m_plugins) { if (!pi.listener) { continue; } if (!pi.listener->isRunning()) { continue; } diff --git a/src/blackgui/components/copyconfigurationcomponent.cpp b/src/blackgui/components/copyconfigurationcomponent.cpp index 07a94102f..266b4a2aa 100644 --- a/src/blackgui/components/copyconfigurationcomponent.cpp +++ b/src/blackgui/components/copyconfigurationcomponent.cpp @@ -420,12 +420,12 @@ namespace BlackGui { ui->cb_OtherVersions->clear(); const QMap 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()) { - const QString infoString = CDirectoryUtils::decodeNormalizedDirectory(directory); + const QString infoString = CDirectoryUtils::decodeNormalizedDirectory(pair.first); ui->cb_OtherVersions->addItem(infoString); } else @@ -433,7 +433,7 @@ namespace BlackGui static const QString item("swift %1 (%2)"); ui->cb_OtherVersions->addItem(item.arg(info.getVersionString(), info.getPlatform())); } - m_otherVersionDirs.push_back(directory); + m_otherVersionDirs.push_back(pair.first); } } diff --git a/src/blackgui/editors/interpolationsetupform.cpp b/src/blackgui/editors/interpolationsetupform.cpp index 9fe32e199..374434dec 100644 --- a/src/blackgui/editors/interpolationsetupform.cpp +++ b/src/blackgui/editors/interpolationsetupform.cpp @@ -25,7 +25,7 @@ namespace BlackGui { ui->setupUi(this); m_allCheckBoxes = this->findChildren(QString(), Qt::FindDirectChildrenOnly); - for (QCheckBox *cb : m_allCheckBoxes) + for (QCheckBox *cb : as_const(m_allCheckBoxes)) { connect(cb, &QCheckBox::stateChanged, this, &CInterpolationSetupForm::onCheckboxChanged); } diff --git a/src/blackgui/infoarea.cpp b/src/blackgui/infoarea.cpp index 896260f18..ef9796cc8 100644 --- a/src/blackgui/infoarea.cpp +++ b/src/blackgui/infoarea.cpp @@ -329,7 +329,7 @@ namespace BlackGui void CInfoArea::adjustSizeForAllDockWidgets() { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { dw->adjustSize(); } @@ -337,7 +337,7 @@ namespace BlackGui void CInfoArea::floatAllWidgets() { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { if (dw->isFloating()) { continue; } dw->toggleFloating(); @@ -346,7 +346,7 @@ namespace BlackGui void CInfoArea::allFloatingOnTop() { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { const bool f = dw->isFloating(); CGuiUtility::stayOnTop(f, dw); @@ -479,11 +479,11 @@ namespace BlackGui void CInfoArea::displayStatusMessage(const CStatusMessage &statusMessage) { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { dw->displayStatusMessage(statusMessage); } - for (CInfoArea *ia : m_childInfoAreas) + for (CInfoArea *ia : as_const(m_childInfoAreas)) { ia->displayStatusMessage(statusMessage); } @@ -491,11 +491,11 @@ namespace BlackGui void CInfoArea::displayStatusMessages(const CStatusMessageList &statusMessages) { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { dw->displayStatusMessages(statusMessages); } - for (CInfoArea *ia : m_childInfoAreas) + for (CInfoArea *ia : as_const(m_childInfoAreas)) { ia->displayStatusMessages(statusMessages); } @@ -503,7 +503,7 @@ namespace BlackGui void CInfoArea::setDockArea(Qt::DockWidgetArea area) { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { Qt::DockWidgetAreas newAreas = static_cast(area); Qt::DockWidgetAreas oldAreas = dw->allowedAreas(); @@ -624,7 +624,7 @@ namespace BlackGui void CInfoArea::unTabifyAllWidgets() { 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++) { CDockWidgetInfoArea *after = m_dockWidgetInfoAreas.at(i); @@ -641,7 +641,7 @@ namespace BlackGui void CInfoArea::connectTopLevelChanged() { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { connect(dw, &CDockWidgetInfoArea::widgetTopLevelChanged, this, &CInfoArea::onWidgetTopLevelChanged); } @@ -753,7 +753,7 @@ namespace BlackGui void CInfoArea::setFeaturesForDockableWidgets(QDockWidget::DockWidgetFeatures features) { - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { dw->setFeatures(features); } @@ -826,7 +826,7 @@ namespace BlackGui { if (show == m_showTabTexts) { return; } m_showTabTexts = show; - for (CDockWidgetInfoArea *dw : m_dockWidgetInfoAreas) + for (CDockWidgetInfoArea *dw : as_const(m_dockWidgetInfoAreas)) { dw->showTitleWhenDocked(show); } diff --git a/src/blackgui/menus/menuaction.cpp b/src/blackgui/menus/menuaction.cpp index 9cb76de7e..7d718852e 100644 --- a/src/blackgui/menus/menuaction.cpp +++ b/src/blackgui/menus/menuaction.cpp @@ -171,7 +171,7 @@ namespace BlackGui QList CMenuActions::getQActions() const { QList qActions; - for (const CMenuAction &a : this->toQList()) + for (const CMenuAction &a : m_actions) { qActions.append(a.getQAction()); } @@ -243,7 +243,7 @@ namespace BlackGui { CMenuAction a; CMenuActions menuActions; - for (const CMenuAction &action : actions.toQList()) + for (const CMenuAction &action : actions.m_actions) { a = this->addAction(action); menuActions.addAction(a); @@ -431,7 +431,7 @@ namespace BlackGui CMenuActions::operator QList() const { QList qActions; - for (const CMenuAction &a : toQList()) + for (const CMenuAction &a : m_actions) { if (!a.getQAction()) { continue; } qActions.append(a.getQAction()); diff --git a/src/blackgui/models/atcstationtreemodel.cpp b/src/blackgui/models/atcstationtreemodel.cpp index 9de535951..ea7cd73a8 100644 --- a/src/blackgui/models/atcstationtreemodel.cpp +++ b/src/blackgui/models/atcstationtreemodel.cpp @@ -69,7 +69,7 @@ namespace BlackGui QStandardItemModel::clear(); int visibleColumns = 0; - for (const QString &suffix : m_suffixes) + for (const QString &suffix : as_const(m_suffixes)) { // ownership of QStandardItem is taken by model QStandardItem *typeFolderFirstColumn = new QStandardItem(CCallsign::atcSuffixToIcon(suffix).toQIcon(), suffix); diff --git a/src/blackinput/win/joystickwindows.cpp b/src/blackinput/win/joystickwindows.cpp index 9ec6c6f20..c2cf9cdef 100644 --- a/src/blackinput/win/joystickwindows.cpp +++ b/src/blackinput/win/joystickwindows.cpp @@ -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; bool isPressed = state.rgbButtons[buttonIndex] & 0x80; @@ -187,7 +187,7 @@ namespace BlackInput CJoystickWindows::~CJoystickWindows() { // 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; } diff --git a/src/blackmisc/applicationinfolist.cpp b/src/blackmisc/applicationinfolist.cpp index b63f846c0..989025ec8 100644 --- a/src/blackmisc/applicationinfolist.cpp +++ b/src/blackmisc/applicationinfolist.cpp @@ -49,9 +49,8 @@ namespace BlackMisc CDirectoryUtils::currentApplicationDataDirectoryMapWithoutCurrentVersion() : CDirectoryUtils::applicationDataDirectoryMapWithoutCurrentVersion(); - for (const QString &directory : otherVersions.keys()) + for (const CApplicationInfo &info : otherVersions) { - CApplicationInfo info(otherVersions.value(directory)); this->push_back(info); } return this->size(); diff --git a/src/blackmisc/aviation/aircrafticaocodelist.cpp b/src/blackmisc/aviation/aircrafticaocodelist.cpp index 47c4def06..6ddfdab2a 100644 --- a/src/blackmisc/aviation/aircrafticaocodelist.cpp +++ b/src/blackmisc/aviation/aircrafticaocodelist.cpp @@ -304,35 +304,21 @@ namespace BlackMisc QMap count; for (const CAircraftIcaoCode &icao : *this) { - if (!icao.hasManufacturer()) continue; - const QString m(icao.getManufacturer()); - if (count.contains(m)) - { - count[m]++; - } - else - { - count[m] = 1; - } + if (!icao.hasManufacturer()) { continue; } + count[icao.getManufacturer()]++; } return count; } QPair CAircraftIcaoCodeList::maxCountManufacturer() const { - if (this->isEmpty()) return QPair("", 0); const QMap counts(countManufacturers()); - QPair max; - for (const QString &m : counts.keys()) + if (counts.isEmpty()) return { {}, 0 }; + const auto pair = *std::max_element(counts.keyValueBegin(), counts.keyValueEnd(), [](const auto &a, const auto &b) { - const int mv = counts[m]; - if (mv > max.second) - { - max.first = m; - max.second = mv; - } - } - return max; + return a.second < b.second; + }); + return { pair.first, pair.second }; } CAircraftIcaoCodeList CAircraftIcaoCodeList::fromDatabaseJson(const QJsonArray &array, bool ignoreIncompleteAndDuplicates, CAircraftIcaoCodeList *inconsistent) diff --git a/src/blackmisc/datacache.cpp b/src/blackmisc/datacache.cpp index 0d1a97821..8243b7189 100644 --- a/src/blackmisc/datacache.cpp +++ b/src/blackmisc/datacache.cpp @@ -423,7 +423,7 @@ namespace BlackMisc if (updateUuid) { m_admittedQueue.clear(); } else if (! m_admittedQueue.isEmpty()) { m_admittedQueue.intersect(QSet::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); } } diff --git a/src/blackmisc/dictionary.h b/src/blackmisc/dictionary.h index 127d1ef0a..e063e60ba 100644 --- a/src/blackmisc/dictionary.h +++ b/src/blackmisc/dictionary.h @@ -318,6 +318,26 @@ namespace BlackMisc //! Returns const iterator at the end of the dictionary 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 void clear() { m_impl.clear(); } @@ -369,8 +389,8 @@ namespace BlackMisc //! 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); } - //! Return a range of all keys - CRange> keys() const { return makeRange(Iterators::makeKeyIterator(begin()), end()); } + //! Return a range of all keys (does not allocate a temporary container) + auto keys() const { return makeRange(keyBegin(), keyEnd()); } //! Remove all items with key from the dictionary 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 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 values() const { return makeRange(begin(), end()); } //! Copy assignment. @@ -407,7 +427,6 @@ namespace BlackMisc Value &operator [](const Key &key) { return m_impl[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]; } //! Test for equality. diff --git a/src/blackmisc/fileutils.cpp b/src/blackmisc/fileutils.cpp index 2d2382c82..07ee677a9 100644 --- a/src/blackmisc/fileutils.cpp +++ b/src/blackmisc/fileutils.cpp @@ -289,7 +289,7 @@ namespace BlackMisc QString last; QStringList result; - for (const QString &path : dirs) + for (const QString &path : as_const(dirs)) { if (path.isEmpty()) { continue; } if (last.isEmpty() || !path.startsWith(last, cs)) diff --git a/src/blackmisc/iterator.h b/src/blackmisc/iterator.h index 458ce9506..9c392ce76 100644 --- a/src/blackmisc/iterator.h +++ b/src/blackmisc/iterator.h @@ -95,54 +95,6 @@ namespace BlackMisc return Private::makeInsertIterator(container, THasPushBack()); } - /*! - * 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 KeyIterator - : public std::iterator().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. * @@ -325,14 +277,6 @@ namespace BlackMisc QVector m_iterators; }; - /*! - * Construct a KeyIterator of the appropriate type from deduced template function argument. - */ - template auto makeKeyIterator(I iterator) -> KeyIterator - { - return { iterator }; - } - /*! * Construct a TransformIterator of the appropriate type from deduced template function arguments. */ diff --git a/src/blackmisc/range.h b/src/blackmisc/range.h index c08c102a2..b18033891 100644 --- a/src/blackmisc/range.h +++ b/src/blackmisc/range.h @@ -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. */ template 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. + * + * 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 + auto makePairsRange(const T &container) + { + return makeRange(container.keyValueBegin(), container.keyValueEnd()); } /*! @@ -345,6 +358,20 @@ namespace BlackMisc template 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 + void makePairsRange(T &container) = delete; + + /*! + * Pairs range for a temporary would be unsafe. + */ + template + void makePairsRange(const T &&container) = delete; + /* * Member functions of CRangeBase template defined out of line, because they depend on CRange etc. */ diff --git a/src/blackmisc/simulation/aircraftmodellist.cpp b/src/blackmisc/simulation/aircraftmodellist.cpp index 0088b00d8..0c8df92a7 100644 --- a/src/blackmisc/simulation/aircraftmodellist.cpp +++ b/src/blackmisc/simulation/aircraftmodellist.cpp @@ -352,11 +352,11 @@ namespace BlackMisc { const QMap modelStrings = this->countPerModelString(); 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; diff --git a/src/blackmisc/simulation/interpolationsetupprovider.cpp b/src/blackmisc/simulation/interpolationsetupprovider.cpp index 4a28d95bc..718ee89c1 100644 --- a/src/blackmisc/simulation/interpolationsetupprovider.cpp +++ b/src/blackmisc/simulation/interpolationsetupprovider.cpp @@ -62,9 +62,9 @@ namespace BlackMisc { const SetupsPerCallsign setups = this->getSetupsPerCallsign(); 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; } @@ -146,19 +146,19 @@ namespace BlackMisc void IInterpolationSetupProvider::clearInterpolationLogCallsigns() { - SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign(); + const SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign(); if (setupsCopy.isEmpty()) { return; } // potential risk, changes inbetween in another thread are missed now // on the other side, we keep locks for a minimal time frame SetupsPerCallsign setupsToKeep; 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); if (setup.isEqualToGlobal(global)) { continue; } - setupsToKeep.insert(cs, setup); + setupsToKeep.insert(pair.first, setup); } { QWriteLocker l(&m_lockSetup); @@ -184,9 +184,9 @@ namespace BlackMisc { const SetupsPerCallsign setupsCopy = this->getSetupsPerCallsign(); 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; } diff --git a/src/plugins/simulator/fsxcommon/simconnectobject.cpp b/src/plugins/simulator/fsxcommon/simconnectobject.cpp index 48cefbb93..94920bd0c 100644 --- a/src/plugins/simulator/fsxcommon/simconnectobject.cpp +++ b/src/plugins/simulator/fsxcommon/simconnectobject.cpp @@ -296,7 +296,7 @@ namespace BlackSimPlugin if (this->isEmpty()) { return CCallsignSet(); } if (!withoutProbes) { return CCallsignSet(this->keys()); } CCallsignSet callsigns; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isAircraft()) { callsigns.insert(simObject.getCallsign().asString()); } } @@ -315,7 +315,7 @@ namespace BlackSimPlugin CSimConnectObject CSimConnectObjects::getSimObjectForObjectId(DWORD objectId) const { - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.getObjectId() == objectId) { return simObject; } } @@ -326,7 +326,7 @@ namespace BlackSimPlugin { if (this->isEmpty()) { return CSimConnectObject(); } CSimConnectObject oldestSimObj = *this->begin(); - for (const CSimConnectObject &simObj : this->values()) + for (const CSimConnectObject &simObj : *this) { if (!simObj.hasCreatedTimestamp()) { continue; } if (!oldestSimObj.hasCreatedTimestamp() || oldestSimObj.getCreatedTimestamp() > simObj.getCreatedTimestamp()) @@ -339,7 +339,7 @@ namespace BlackSimPlugin CSimConnectObject CSimConnectObjects::getSimObjectForRequestId(DWORD requestId) const { - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.getRequestId() == requestId) { return simObject; } } @@ -390,7 +390,7 @@ namespace BlackSimPlugin bool CSimConnectObjects::containsPendingAdded() const { - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isPendingAdded()) { return true; } } @@ -399,7 +399,7 @@ namespace BlackSimPlugin bool CSimConnectObjects::containsPendingRemoved() const { - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isPendingRemoved()) { return true; } } @@ -409,7 +409,7 @@ namespace BlackSimPlugin int CSimConnectObjects::countPendingAdded() const { int c = 0; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isPendingAdded()) { c++; } } @@ -419,7 +419,7 @@ namespace BlackSimPlugin int CSimConnectObjects::countPendingRemoved() const { int c = 0; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isPendingRemoved()) { c++; } } @@ -429,7 +429,7 @@ namespace BlackSimPlugin int CSimConnectObjects::countConfirmedAdded() { int c = 0; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : as_const(*this)) { if (simObject.isConfirmedAdded()) { c++; } } @@ -439,7 +439,7 @@ namespace BlackSimPlugin CCallsignSet CSimConnectObjects::getPendingAddedCallsigns() const { CCallsignSet callsigns; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isPendingAdded()) { callsigns.push_back(simObject.getCallsign()); } } @@ -449,7 +449,7 @@ namespace BlackSimPlugin CCallsignSet CSimConnectObjects::getPendingRemovedCallsigns() const { CCallsignSet callsigns; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.isPendingRemoved()) { callsigns.push_back(simObject.getCallsign()); } } @@ -459,7 +459,7 @@ namespace BlackSimPlugin QList CSimConnectObjects::getByType(CSimConnectObject::SimObjectType type) const { QList objs; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.getType() == type) { objs.push_back(simObject); } } @@ -468,7 +468,7 @@ namespace BlackSimPlugin CSimConnectObject CSimConnectObjects::getNotPendingProbe() const { - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending()) { return simObject; } } @@ -478,7 +478,7 @@ namespace BlackSimPlugin CSimConnectObject CSimConnectObjects::getOldestNotPendingProbe() const { CSimConnectObject oldestProbe; - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.getType() == CSimConnectObject::TerrainProbe && !simObject.isPending()) { @@ -493,7 +493,7 @@ namespace BlackSimPlugin bool CSimConnectObjects::containsType(CSimConnectObject::SimObjectType type) const { - for (const CSimConnectObject &simObject : this->values()) + for (const CSimConnectObject &simObject : *this) { if (simObject.getType() == type) { return true; } } @@ -516,7 +516,7 @@ namespace BlackSimPlugin CSimConnectObjects removedObjects; 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 if (type != CSimConnectObject::AllTypes && simObject.getType() != type) { continue; } diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index 35bd78d33..ce6ccce96 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -1103,7 +1103,7 @@ namespace BlackSimPlugin const CCallsignSet aircraftCallsignsInRange(this->getAircraftInRangeCallsigns()); CSimulatedAircraftList toBeAddedAircraft; // aircraft still to be added 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"); if (pendingSimObj.isTerrainProbe() || aircraftCallsignsInRange.contains(pendingSimObj.getCallsign()))