summaryrefslogtreecommitdiff
path: root/examples/svg/network/bearercloud/bearercloud.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-09-06 17:54:23 +0200
committerMarc Mutz <marc.mutz@kdab.com>2016-09-13 19:58:19 +0000
commit74bc4617dd5a38abb60aff8b252001cb2ff9c7b8 (patch)
tree8368a44500af57a0880d89b47ddc73f9b38d6530 /examples/svg/network/bearercloud/bearercloud.cpp
parent4c44cffd7b376900fc41169365ae03c7c65d95b6 (diff)
downloadqtsvg-74bc4617dd5a38abb60aff8b252001cb2ff9c7b8.tar.gz
Eradicate Q_FOREACH loops and mark the module as Q_FOREACH-free
In BearerCloud::timerEvent(), bite the bullet and use a std::vector instead of a QList to avoid repeated qAsConst() applications. In BearerCloud::configurationRemoved() and configurationChanged(), instead of iterating over QMultiMap::uniqueKeys() and QMap::remove(), iterate directly over the QMultiMap and remove the desired elements. Cache a QString. In BearerCloud::updateConfigurations(), instead of using while !isEmpty() takeFirst() on a local copy of a QList, simply iterate over the QList (now made const) using C++11 ranged for. In tst_QSvgGenerator, replace a QList of statically-known size with a C array. Change-Id: Ic0dd1c67d0819fe6167f2bce248f9b910be65803 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'examples/svg/network/bearercloud/bearercloud.cpp')
-rw-r--r--examples/svg/network/bearercloud/bearercloud.cpp39
1 files changed, 25 insertions, 14 deletions
diff --git a/examples/svg/network/bearercloud/bearercloud.cpp b/examples/svg/network/bearercloud/bearercloud.cpp
index 1ec711e..bf2a444 100644
--- a/examples/svg/network/bearercloud/bearercloud.cpp
+++ b/examples/svg/network/bearercloud/bearercloud.cpp
@@ -113,17 +113,19 @@ void BearerCloud::cloudMoved()
void BearerCloud::timerEvent(QTimerEvent *)
{
- QList<Cloud *> clouds;
- foreach (QGraphicsItem *item, items()) {
+ std::vector<Cloud *> clouds;
+ const auto graphicsItems = items();
+ clouds.reserve(graphicsItems.size());
+ for (QGraphicsItem *item : graphicsItems) {
if (Cloud *cloud = qgraphicsitem_cast<Cloud *>(item))
- clouds << cloud;
+ clouds.push_back(cloud);
}
- foreach (Cloud *cloud, clouds)
+ for (Cloud *cloud : clouds)
cloud->calculateForces();
bool cloudsMoved = false;
- foreach (Cloud *cloud, clouds)
+ for (Cloud *cloud : clouds)
cloudsMoved |= cloud->advance();
if (!cloudsMoved) {
@@ -158,8 +160,13 @@ void BearerCloud::configurationAdded(const QNetworkConfiguration &config)
//! [3]
void BearerCloud::configurationRemoved(const QNetworkConfiguration &config)
{
- foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys())
- configStates.remove(state, config.identifier());
+ const auto id = config.identifier();
+ for (auto it = configStates.begin(), end = configStates.end(); it != end; /* erasing */) {
+ if (it.value() == id)
+ it = configStates.erase(it);
+ else
+ ++it;
+ }
Cloud *item = configurations.take(config.identifier());
@@ -173,10 +180,15 @@ void BearerCloud::configurationRemoved(const QNetworkConfiguration &config)
//! [4]
void BearerCloud::configurationChanged(const QNetworkConfiguration &config)
{
- foreach (const QNetworkConfiguration::StateFlags &state, configStates.uniqueKeys())
- configStates.remove(state, config.identifier());
+ const auto id = config.identifier();
+ for (auto it = configStates.begin(), end = configStates.end(); it != end; /* erasing */) {
+ if (it.value() == id)
+ it = configStates.erase(it);
+ else
+ ++it;
+ }
- configStates.insert(config.state(), config.identifier());
+ configStates.insert(config.state(), id);
cloudMoved();
}
@@ -185,10 +197,9 @@ void BearerCloud::configurationChanged(const QNetworkConfiguration &config)
//! [1]
void BearerCloud::updateConfigurations()
{
- QList<QNetworkConfiguration> allConfigurations = manager.allConfigurations();
-
- while (!allConfigurations.isEmpty())
- configurationAdded(allConfigurations.takeFirst());
+ const auto allConfigurations = manager.allConfigurations();
+ for (const QNetworkConfiguration &config : allConfigurations)
+ configurationAdded(config);
cloudMoved();
}