diff options
author | Mike Krus <mike.krus@kdab.com> | 2017-12-27 15:28:55 +0000 |
---|---|---|
committer | Sean Harmer <sean.harmer@kdab.com> | 2018-01-14 11:47:57 +0000 |
commit | 1ea7122cad14c14d56474528a429bcb5b94101d0 (patch) | |
tree | fed50664f191ab828e621381b6ef48e056e2301a /src | |
parent | e5c16bb630345e819e8eeaf1733eeca694afe6ae (diff) |
Prevent potential containers detaching
Found by Clazy clazy-range-loop
Change-Id: I4956f9be2b7b3f986b2fc83c1d883829314a8b6c
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/animation/backend/gltfimporter.cpp | 2 | ||||
-rw-r--r-- | src/core/aspects/qabstractaspect.cpp | 3 | ||||
-rw-r--r-- | src/plugins/sceneparsers/gltf/gltfimporter.cpp | 3 | ||||
-rw-r--r-- | src/plugins/sceneparsers/gltfexport/gltfexporter.cpp | 52 | ||||
-rw-r--r-- | src/render/framegraph/qrendercapture.cpp | 2 | ||||
-rw-r--r-- | src/render/geometry/skeleton.cpp | 3 | ||||
-rw-r--r-- | src/render/jobs/filterlayerentityjob.cpp | 2 | ||||
-rw-r--r-- | src/render/jobs/pickboundingvolumeutils.cpp | 3 | ||||
-rw-r--r-- | src/render/jobs/updateskinningpalettejob.cpp | 3 |
9 files changed, 45 insertions, 28 deletions
diff --git a/src/animation/backend/gltfimporter.cpp b/src/animation/backend/gltfimporter.cpp index 4111c2e3c..d9c0cb9a6 100644 --- a/src/animation/backend/gltfimporter.cpp +++ b/src/animation/backend/gltfimporter.cpp @@ -784,7 +784,7 @@ bool GLTFImporter::processJSONSkin(const QJsonObject &json) bool GLTFImporter::processJSONAnimation(const QJsonObject &json) { - Animation animation(json); + const Animation animation(json); for (const auto &channel : animation.channels) { if (channel.samplerIndex == -1) diff --git a/src/core/aspects/qabstractaspect.cpp b/src/core/aspects/qabstractaspect.cpp index dd1f37da4..2e37df60b 100644 --- a/src/core/aspects/qabstractaspect.cpp +++ b/src/core/aspects/qabstractaspect.cpp @@ -238,7 +238,8 @@ void QAbstractAspectPrivate::clearBackendNode(const QNodeDestroyedChangePtr &cha { // Each QNodeDestroyedChange may contain info about a whole sub-tree of nodes that // are being destroyed. Iterate over them and process each in turn - for (const auto &idAndType : change->subtreeIdsAndTypes()) { + const auto subTree = change->subtreeIdsAndTypes(); + for (const auto &idAndType : subTree) { const QMetaObject *metaObj = idAndType.type; QBackendNodeMapperPtr backendNodeMapper; diff --git a/src/plugins/sceneparsers/gltf/gltfimporter.cpp b/src/plugins/sceneparsers/gltf/gltfimporter.cpp index 426194746..9b8057334 100644 --- a/src/plugins/sceneparsers/gltf/gltfimporter.cpp +++ b/src/plugins/sceneparsers/gltf/gltfimporter.cpp @@ -1581,7 +1581,8 @@ void GLTFImporter::processJSONExtensions(const QString &id, const QJsonObject &j // level GLTF item. if (id == KEY_COMMON_MAT) { const auto lights = jsonObject.value(KEY_LIGHTS).toObject(); - for (const auto &lightKey : lights.keys()) { + const auto keys = lights.keys(); + for (const auto &lightKey : keys) { const auto light = lights.value(lightKey).toObject(); auto lightType = light.value(KEY_TYPE).toString(); const auto lightValues = light.value(lightType).toObject(); diff --git a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp index ba100e095..56c94a19c 100644 --- a/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp +++ b/src/plugins/sceneparsers/gltfexport/gltfexporter.cpp @@ -394,7 +394,7 @@ bool GLTFExporter::exportScene(QEntity *sceneRoot, const QString &outDir, QFile::Permissions targetPermissions = gltfFile.permissions(); // Copy exported scene to actual export directory - for (const auto &sourceFileStr : m_exportedFiles) { + for (const auto &sourceFileStr : qAsConst(m_exportedFiles)) { QFileInfo fiSource(m_exportDir + sourceFileStr); QFileInfo fiDestination(finalExportDir + sourceFileStr); if (fiDestination.exists()) { @@ -548,7 +548,7 @@ void GLTFExporter::copyTextures() void GLTFExporter::createShaders() { qCDebug(GLTFExporterLog, "Creating shaders..."); - for (const auto &si : m_shaderInfo) { + for (const auto &si : qAsConst(m_shaderInfo)) { const QString fileName = m_exportDir + si.uri; QFile f(fileName); if (f.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate)) { @@ -571,7 +571,8 @@ void GLTFExporter::parseEntities(const QEntity *entity, Node *parentNode) node->uniqueName = newNodeName(); int irrelevantComponents = 0; - for (auto component : entity->components()) { + const auto components = entity->components(); + for (auto component : components) { if (auto mesh = qobject_cast<QGeometryRenderer *>(component)) m_meshMap.insert(node, mesh); else if (auto material = qobject_cast<QMaterial *>(component)) @@ -812,7 +813,8 @@ void GLTFExporter::parseMeshes() uint stride(0); - for (QAttribute *att : meshGeometry->attributes()) { + const auto attributes = meshGeometry->attributes(); + for (QAttribute *att : attributes) { if (att->attributeType() == QAttribute::IndexAttribute) { indexAttrib = att; indexPtr = reinterpret_cast<const quint16 *>(att->buffer()->data().constData()); @@ -969,11 +971,12 @@ void GLTFExporter::parseMeshes() qCDebug(GLTFExporterLog, " Vertex buffer size (bytes): %i", vertexBuf.size()); qCDebug(GLTFExporterLog, " Index buffer size (bytes): %i", indexBuf.size()); QStringList sl; - for (const auto &bv : meshInfo.views) + const auto views = meshInfo.views; + for (const auto &bv : views) sl << bv.name; qCDebug(GLTFExporterLog) << " buffer views:" << sl; sl.clear(); - for (const auto &acc : meshInfo.accessors) + for (const auto &acc : qAsConst(meshInfo.accessors)) sl << acc.name; qCDebug(GLTFExporterLog) << " accessors:" << sl; qCDebug(GLTFExporterLog, " material: '%ls'", @@ -1091,7 +1094,8 @@ void GLTFExporter::parseTechniques(QMaterial *material) int techniqueCount = 0; qCDebug(GLTFExporterLog, " Parsing material techniques..."); - for (auto technique : material->effect()->techniques()) { + const auto techniques = material->effect()->techniques(); + for (auto technique : techniques) { QString techName; if (m_techniqueIdMap.contains(technique)) { techName = m_techniqueIdMap.value(technique); @@ -1116,7 +1120,8 @@ void GLTFExporter::parseRenderPasses(QTechnique *technique) int passCount = 0; qCDebug(GLTFExporterLog, " Parsing render passes for technique..."); - for (auto pass : technique->renderPasses()) { + const auto renderPasses = technique->renderPasses(); + for (auto pass : renderPasses) { QString name; if (m_renderPassIdMap.contains(pass)) { name = m_renderPassIdMap.value(pass); @@ -1158,7 +1163,7 @@ QString GLTFExporter::addShaderInfo(QShaderProgram::ShaderType type, QByteArray if (code.isEmpty()) return QString(); - for (const auto &si : m_shaderInfo) { + for (const auto &si : qAsConst(m_shaderInfo)) { if (si.type == QShaderProgram::Vertex && code == si.code) return si.name; } @@ -1223,7 +1228,7 @@ bool GLTFExporter::saveScene() m_obj["buffers"] = buffers; QJsonObject bufferViews; - for (const auto &bv : bvList) { + for (const auto &bv : qAsConst(bvList)) { QJsonObject bufferView; bufferView["buffer"] = QStringLiteral("buf"); bufferView["byteLength"] = int(bv.length); @@ -1236,7 +1241,7 @@ bool GLTFExporter::saveScene() m_obj["bufferViews"] = bufferViews; QJsonObject accessors; - for (const auto &acc : accList) { + for (const auto &acc : qAsConst(accList)) { QJsonObject accessor; accessor["bufferView"] = acc.bufferView; accessor["byteOffset"] = int(acc.offset); @@ -1265,7 +1270,8 @@ bool GLTFExporter::saveScene() QJsonObject prim; prim["mode"] = 4; // triangles QJsonObject attrs; - for (const auto &acc : meshInfo.accessors) { + const auto meshAccessors = meshInfo.accessors; + for (const auto &acc : meshAccessors) { if (acc.usage != QStringLiteral("INDEX")) attrs[acc.usage] = acc.name; else @@ -1282,7 +1288,7 @@ bool GLTFExporter::saveScene() m_obj["meshes"] = meshes; QJsonObject cameras; - for (auto camInfo : qAsConst(m_cameraInfo)) { + for (const auto &camInfo : qAsConst(m_cameraInfo)) { QJsonObject camera; QJsonObject proj; proj["znear"] = camInfo.znear; @@ -1394,14 +1400,16 @@ bool GLTFExporter::saveScene() QJsonObject effectObj; QJsonObject paramObj; - for (QParameter *param : effect->parameters()) + const auto effectParameters = effect->parameters(); + for (QParameter *param : effectParameters) exportParameter(paramObj, param->name(), param->value()); if (!effect->objectName().isEmpty()) effectObj["name"] = effect->objectName(); if (!paramObj.isEmpty()) effectObj["parameters"] = paramObj; QJsonArray techs; - for (auto tech : effect->techniques()) + const auto effectTechniques = effect->techniques(); + for (auto tech : effectTechniques) techs << m_techniqueIdMap.value(tech); effectObj["techniques"] = techs; effects[effectName] = effectObj; @@ -1419,13 +1427,16 @@ bool GLTFExporter::saveScene() QJsonObject paramObj; QJsonArray renderPassArr; - for (QFilterKey *filterKey : technique->filterKeys()) + const auto techniqueFilterKeys = technique->filterKeys(); + for (QFilterKey *filterKey : techniqueFilterKeys) setVarToJSonObject(filterKeyObj, filterKey->name(), filterKey->value()); - for (QRenderPass *pass : technique->renderPasses()) + const auto techniqueRenderPasses = technique->renderPasses(); + for (QRenderPass *pass : techniqueRenderPasses) renderPassArr << m_renderPassIdMap.value(pass); - for (QParameter *param : technique->parameters()) + const auto techniqueParameters = technique->parameters(); + for (QParameter *param : techniqueParameters) exportParameter(paramObj, param->name(), param->value()); const QGraphicsApiFilter *gFilter = technique->graphicsApiFilter(); @@ -1517,7 +1528,7 @@ bool GLTFExporter::saveScene() // Save shaders for custom materials QJsonObject shaders; - for (const auto &si : m_shaderInfo) { + for (const auto &si : qAsConst(m_shaderInfo)) { QJsonObject shaderObj; shaderObj["uri"] = si.uri; shaders[si.name] = shaderObj; @@ -1885,7 +1896,8 @@ void GLTFExporter::exportRenderStates(QJsonObject &jsonObj, const QRenderPass *p { QJsonArray enableStates; QJsonObject funcObj; - for (QRenderState *state : pass->renderStates()) { + const auto renderStates = pass->renderStates(); + for (QRenderState *state : renderStates) { QJsonArray arr; if (qobject_cast<QAlphaCoverage *>(state)) { enableStates << GL_SAMPLE_ALPHA_TO_COVERAGE; diff --git a/src/render/framegraph/qrendercapture.cpp b/src/render/framegraph/qrendercapture.cpp index 28bc41b91..7d40c33dc 100644 --- a/src/render/framegraph/qrendercapture.cpp +++ b/src/render/framegraph/qrendercapture.cpp @@ -253,7 +253,7 @@ QRenderCapturePrivate::QRenderCapturePrivate() QRenderCapturePrivate::~QRenderCapturePrivate() { Q_Q(QRenderCapture); - for (QRenderCaptureReply *reply : m_waitingReplies) + for (QRenderCaptureReply *reply : qAsConst(m_waitingReplies)) reply->disconnect(q); } diff --git a/src/render/geometry/skeleton.cpp b/src/render/geometry/skeleton.cpp index 075936f37..615b76c88 100644 --- a/src/render/geometry/skeleton.cpp +++ b/src/render/geometry/skeleton.cpp @@ -365,7 +365,8 @@ void Skeleton::processJointHierarchy(Qt3DCore::QNodeId jointId, skeletonData.jointIndices.insert(jointHandle, jointIndex); // Recurse to the children - for (const auto childJointId : joint->childJointIds()) + const auto childIds = joint->childJointIds(); + for (const auto childJointId : childIds) processJointHierarchy(childJointId, jointIndex, skeletonData); } diff --git a/src/render/jobs/filterlayerentityjob.cpp b/src/render/jobs/filterlayerentityjob.cpp index c9138a9e4..0ed2ed559 100644 --- a/src/render/jobs/filterlayerentityjob.cpp +++ b/src/render/jobs/filterlayerentityjob.cpp @@ -210,7 +210,7 @@ void FilterLayerEntityJob::filterLayerAndEntity() FrameGraphManager *frameGraphManager = m_manager->frameGraphManager(); LayerManager *layerManager = m_manager->layerManager(); - for (const Qt3DCore::QNodeId layerFilterId : m_layerFilterIds) { + for (const Qt3DCore::QNodeId layerFilterId : qAsConst(m_layerFilterIds)) { LayerFilterNode *layerFilter = static_cast<LayerFilterNode *>(frameGraphManager->lookupNode(layerFilterId)); Qt3DCore::QNodeIdVector layerIds = layerFilter->layerIds(); diff --git a/src/render/jobs/pickboundingvolumeutils.cpp b/src/render/jobs/pickboundingvolumeutils.cpp index 73095f497..564c1e86c 100644 --- a/src/render/jobs/pickboundingvolumeutils.cpp +++ b/src/render/jobs/pickboundingvolumeutils.cpp @@ -588,7 +588,8 @@ bool HierarchicalEntityPicker::collectHits(Entity *root) } // and pick children - for (auto child: current.first->children()) + const auto children = current.first->children(); + for (auto child: children) worklist.push_back({child, current.second || !child->componentHandle<ObjectPicker>().isNull()}); } diff --git a/src/render/jobs/updateskinningpalettejob.cpp b/src/render/jobs/updateskinningpalettejob.cpp index 4ed196713..41ec573ce 100644 --- a/src/render/jobs/updateskinningpalettejob.cpp +++ b/src/render/jobs/updateskinningpalettejob.cpp @@ -103,7 +103,8 @@ void UpdateSkinningPaletteJob::findDirtyArmatures(Entity *entity, if (!armatureHandle.isNull() && !armatures.contains(armatureHandle)) armatures.push_back(armatureHandle); - for (const auto child : entity->children()) + const auto children = entity->children(); + for (const auto child : children) findDirtyArmatures(child, armatures); } |