From abea7f7aab2420a246000d7b27f65e5b771b6c74 Mon Sep 17 00:00:00 2001
From: "Joachim Wuttke (o)" <j.wuttke@fz-juelich.de>
Date: Tue, 31 Oct 2023 10:05:32 +0100
Subject: [PATCH] correct some variable shadowing

---
 GUI/Model/Model/ParameterTreeUtil.cpp          | 12 ++++++------
 GUI/Support/Util/String.cpp                    | 18 ++++++++++--------
 GUI/View/Import/RealDataSelectorWidget.cpp     |  8 ++++----
 GUI/View/Instrument/InstrumentView.cpp         | 13 ++++++-------
 .../Instrument/PolarizationAnalysisEditor.cpp  | 10 +++++-----
 GUI/View/Item/ItemViewOverlayButtons.cpp       |  6 +++---
 GUI/View/JobControl/JobListing.cpp             |  9 ++++-----
 GUI/View/PlotSpecular/SpecularPlot.cpp         | 16 ++++++++--------
 GUI/View/PlotUtil/ColorMap.cpp                 |  6 +++---
 Resample/Processed/Slicer.cpp                  |  8 ++++----
 Sample/Particle/PolyhedralUtil.cpp             |  4 ++--
 Sample/StandardSamples/FeNiBilayerBuilder.cpp  | 14 +++++++-------
 .../StandardSamples/SlicedCylindersBuilder.cpp |  8 ++++----
 13 files changed, 66 insertions(+), 66 deletions(-)

diff --git a/GUI/Model/Model/ParameterTreeUtil.cpp b/GUI/Model/Model/ParameterTreeUtil.cpp
index 9d1a8e0082a..bdaebb90a0b 100644
--- a/GUI/Model/Model/ParameterTreeUtil.cpp
+++ b/GUI/Model/Model/ParameterTreeUtil.cpp
@@ -114,14 +114,14 @@ void ParameterTreeBuilder::addSample()
 
         int iLayout = 0;
         for (auto* layout : layer->layoutItems()) {
-            auto* label = new ParameterLabelItem("Layout" + QString::number(iLayout++), layerLabel);
+            auto* label2 = new ParameterLabelItem("Layout" + QString::number(iLayout++), layerLabel);
             if (!layout->totalDensityIsDefinedByInterference())
-                addParameterItem(label, layout->ownDensity());
+                addParameterItem(label2, layout->ownDensity());
 
-            addInterference(label, layout);
+            addInterference(label2, layout);
 
             for (auto* p : layout->itemsWithParticles())
-                addItemWithParticles(label, p, true);
+                addItemWithParticles(label2, p, true);
         }
     }
 }
@@ -259,8 +259,8 @@ ParameterLabelItem* ParameterTreeBuilder::addItemWithParticles(ParameterLabelIte
         for (auto* d : formFactor->geometryProperties())
             addParameterItem(ffLabel, *d);
     } else if (const auto* particleComposition = dynamic_cast<const CompoundItem*>(p)) {
-        for (auto* p : particleComposition->itemsWithParticles())
-            addItemWithParticles(label, p, false);
+        for (auto* pp : particleComposition->itemsWithParticles())
+            addItemWithParticles(label, pp, false);
     } else if (const auto* coreShell = dynamic_cast<const CoreAndShellItem*>(p)) {
         auto* l = addItemWithParticles(label, coreShell->coreItem(), false);
         l->setTitle(l->title() + " (Core)");
diff --git a/GUI/Support/Util/String.cpp b/GUI/Support/Util/String.cpp
index 641fef438f3..e4f8cd9657d 100644
--- a/GUI/Support/Util/String.cpp
+++ b/GUI/Support/Util/String.cpp
@@ -31,18 +31,20 @@ QString GUI::Util::String::suggestName(const QStringList& existingNames, const Q
     QRegularExpression regexp(R"(\((\d+)\))");
 
     QString baseName = name;
-    QRegularExpressionMatch matched{regexp.match(baseName)};
-    if (matched.hasMatch()) {
-        newNumber = matched.captured(1).toInt();
-        baseName.replace(matched.captured(0), "");
-        baseName = baseName.trimmed();
+    {
+	QRegularExpressionMatch matched{regexp.match(baseName)};
+	if (matched.hasMatch()) {
+	    newNumber = matched.captured(1).toInt();
+	    baseName.replace(matched.captured(0), "");
+	    baseName = baseName.trimmed();
+	}
     }
 
-    for (const auto& name : existingNames) {
-        if (name == baseName)
+    for (const auto& n : existingNames) {
+        if (n == baseName)
             newNumber = std::max(newNumber, 2);
         else {
-            QRegularExpressionMatch matched{regexp.match(name)};
+            QRegularExpressionMatch matched{regexp.match(n)};
             if (matched.hasMatch())
                 newNumber = std::max(newNumber, matched.captured(1).toInt() + 1);
         }
diff --git a/GUI/View/Import/RealDataSelectorWidget.cpp b/GUI/View/Import/RealDataSelectorWidget.cpp
index 250c8649a8c..836c6c7cf77 100644
--- a/GUI/View/Import/RealDataSelectorWidget.cpp
+++ b/GUI/View/Import/RealDataSelectorWidget.cpp
@@ -358,13 +358,13 @@ void RealDataSelectorWidget::importData2D()
 
         RealItem* realItem = nullptr;
         try {
-            std::unique_ptr<Datafield> data(IO::readData2D(fname.toStdString(), ftype));
-            if (!data)
+            std::unique_ptr<Datafield> df(IO::readData2D(fname.toStdString(), ftype));
+            if (!df)
                 continue;
             realItem = m_treeModel->injectDataItem(2);
             realItem->setRealItemName(QFileInfo(fname).baseName());
-            ASSERT(data->rank() == 2);
-            realItem->setDatafield(*data);
+            ASSERT(df->rank() == 2);
+            realItem->setDatafield(*df);
             setCurrentItem(realItem);
         } catch (std::exception& ex) {
             m_treeModel->removeDataItem(realItem);
diff --git a/GUI/View/Instrument/InstrumentView.cpp b/GUI/View/Instrument/InstrumentView.cpp
index 61a741c85d2..0da3370e48e 100644
--- a/GUI/View/Instrument/InstrumentView.cpp
+++ b/GUI/View/Instrument/InstrumentView.cpp
@@ -265,15 +265,14 @@ void InstrumentView::onFunctionalityChanged()
         QMessageBox::warning(this, "Select functionality",
                              "You have to select at least one functionality. Changing "
                              "this setting is not possible.");
-        const auto f = m_document->functionalities();
-        gisasCheck->setChecked(f.testFlag(ProjectDocument::Gisas));
-        offspecCheck->setChecked(f.testFlag(ProjectDocument::Offspec));
-        specularCheck->setChecked(f.testFlag(ProjectDocument::Specular));
-        depthProbeCheck->setChecked(f.testFlag(ProjectDocument::Depthprobe));
+        const auto ff = m_document->functionalities();
+        gisasCheck->setChecked(ff.testFlag(ProjectDocument::Gisas));
+        offspecCheck->setChecked(ff.testFlag(ProjectDocument::Offspec));
+        specularCheck->setChecked(ff.testFlag(ProjectDocument::Specular));
+        depthProbeCheck->setChecked(ff.testFlag(ProjectDocument::Depthprobe));
         return;
     }
     m_document->setFunctionalities(f);
-    if (gProjectDocument.has_value()) {
+    if (gProjectDocument.has_value())
         appSettings->setDefaultFunctionalities(toVariant(f));
-    }
 }
diff --git a/GUI/View/Instrument/PolarizationAnalysisEditor.cpp b/GUI/View/Instrument/PolarizationAnalysisEditor.cpp
index 330cfb144f7..d9dad508ae4 100644
--- a/GUI/View/Instrument/PolarizationAnalysisEditor.cpp
+++ b/GUI/View/Instrument/PolarizationAnalysisEditor.cpp
@@ -83,7 +83,7 @@ DoubleSpinBox* PolarizationAnalysisEditor::createSpinBox(DoubleProperty& d)
     return sb;
 }
 
-void PolarizationAnalysisEditor::addBlochRow(QFormLayout* parentLayout, VectorProperty& d)
+void PolarizationAnalysisEditor::addBlochRow(QFormLayout* parentLayout, VectorProperty& v)
 {
     auto* layout = new QHBoxLayout;
 
@@ -92,11 +92,11 @@ void PolarizationAnalysisEditor::addBlochRow(QFormLayout* parentLayout, VectorPr
         layout->addWidget(createSpinBox(d));
     };
 
-    add(d.x());
-    add(d.y());
-    add(d.z());
+    add(v.x());
+    add(v.y());
+    add(v.z());
 
     layout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding));
 
-    parentLayout->addRow(d.label() + ":", layout);
+    parentLayout->addRow(v.label() + ":", layout);
 }
diff --git a/GUI/View/Item/ItemViewOverlayButtons.cpp b/GUI/View/Item/ItemViewOverlayButtons.cpp
index 8250c9de3b5..0867364a989 100644
--- a/GUI/View/Item/ItemViewOverlayButtons.cpp
+++ b/GUI/View/Item/ItemViewOverlayButtons.cpp
@@ -201,10 +201,10 @@ ItemViewOverlayButtons::ItemViewOverlayButtons(QObject* parent)
 
 void ItemViewOverlayButtons::updateRecursive(const QModelIndex& index)
 {
-    const auto hoverIfNecessary = [&](QModelIndex index) {
+    const auto hoverIfNecessary = [&](QModelIndex i) {
         QPoint viewPortMousePos = m_view->mapFromGlobal(QCursor::pos());
-        if (m_view->indexAt(viewPortMousePos) == index)
-            if (auto* w = dynamic_cast<ItemViewOverlayWidget*>(m_view->indexWidget(index)))
+        if (m_view->indexAt(viewPortMousePos) == i)
+            if (auto* w = dynamic_cast<ItemViewOverlayWidget*>(m_view->indexWidget(i)))
                 w->hover(true);
     };
 
diff --git a/GUI/View/JobControl/JobListing.cpp b/GUI/View/JobControl/JobListing.cpp
index e25c81b333e..34591a67b72 100644
--- a/GUI/View/JobControl/JobListing.cpp
+++ b/GUI/View/JobControl/JobListing.cpp
@@ -192,11 +192,10 @@ void JobListing::equalizeSelectedToJob(JobItem* srcJob)
     for (const QModelIndex& index : indexes) {
         JobItem* job = m_model->jobItemForIndex(index);
         if (job != srcJob) {
-            Data2DItem* data = job->data2DItem();
-            if (data) {
-                data->setXrange(srcData->lowerX(), srcData->upperX());
-                data->setYrange(srcData->lowerY(), srcData->upperY());
-                data->setZrange(srcData->lowerZ(), srcData->upperZ());
+            if (Data2DItem* di = job->data2DItem()) {
+                di->setXrange(srcData->lowerX(), srcData->upperX());
+                di->setYrange(srcData->lowerY(), srcData->upperY());
+                di->setZrange(srcData->lowerZ(), srcData->upperZ());
             }
         }
     }
diff --git a/GUI/View/PlotSpecular/SpecularPlot.cpp b/GUI/View/PlotSpecular/SpecularPlot.cpp
index 94303d008e3..f079b182ad1 100644
--- a/GUI/View/PlotSpecular/SpecularPlot.cpp
+++ b/GUI/View/PlotSpecular/SpecularPlot.cpp
@@ -263,22 +263,22 @@ void SpecularPlot::setDataFromItem(Data1DItem* item)
     QCPGraph* graph = m_graph_map.value(item);
     graph->data()->clear();
 
-    const Datafield* data = item->c_field();
-    if (!data)
+    const Datafield* df = item->c_field();
+    if (!df)
         return;
 
-    for (size_t i = 0; i < data->size(); ++i) {
-        double x = data->frame().projectedCoord(i, 0);
-        double y = data->operator[](i);
+    for (size_t i = 0; i < df->size(); ++i) {
+        double x = df->frame().projectedCoord(i, 0);
+        double y = df->operator[](i);
         graph->addData(x, y);
     }
 
     // set error bars
-    if (data->hasErrorSigmas()) {
+    if (df->hasErrorSigmas()) {
         ASSERT(m_errorbar_map.contains(item));
         QCPErrorBars* errorBars = m_errorbar_map.value(item);
-        for (size_t i = 0; i < data->size(); ++i) {
-            double y_Err = data->errorSigmas()[i];
+        for (size_t i = 0; i < df->size(); ++i) {
+            double y_Err = df->errorSigmas()[i];
             errorBars->addData(y_Err);
         }
     }
diff --git a/GUI/View/PlotUtil/ColorMap.cpp b/GUI/View/PlotUtil/ColorMap.cpp
index d164deb37d4..f9400e3dbe0 100644
--- a/GUI/View/PlotUtil/ColorMap.cpp
+++ b/GUI/View/PlotUtil/ColorMap.cpp
@@ -356,8 +356,8 @@ void ColorMap::setDataFromItem()
     const Data2DItem* ii = data2DItem();
     if (!ii)
         return;
-    const Datafield* data = ii->c_field();
-    if (!data) {
+    const Datafield* df = ii->c_field();
+    if (!df) {
         m_colorMap->data()->clear();
         return;
     }
@@ -368,7 +368,7 @@ void ColorMap::setDataFromItem()
 
     for (int iy = 0; iy < ny; ++iy)
         for (int ix = 0; ix < nx; ++ix)
-            m_colorMap->data()->setCell(ix, iy, (*data)[iy * nx + ix]);
+            m_colorMap->data()->setCell(ix, iy, (*df)[iy * nx + ix]);
 }
 
 //! Sets the appearance of color scale (visibility, gradient type) from intensity item.
diff --git a/Resample/Processed/Slicer.cpp b/Resample/Processed/Slicer.cpp
index 3063d34588d..2f7e034726a 100644
--- a/Resample/Processed/Slicer.cpp
+++ b/Resample/Processed/Slicer.cpp
@@ -292,10 +292,10 @@ OwningVector<IReParticle> Compute::Slicing::particlesInSlice(const IParticle* pa
         std::vector<double> weights;
         std::vector<Material> materials;
         double volume = 0;
-        for (const auto* p : crystal->basis()->decompose()) {
-            volume += p->volume();
-            weights.push_back(p->volume());
-            materials.push_back(p->avgeMaterial());
+        for (const auto* pp : crystal->basis()->decompose()) {
+            volume += pp->volume();
+            weights.push_back(pp->volume());
+            materials.push_back(pp->avgeMaterial());
         }
         mc->setAdmixedFraction(volume / unit_cell_volume);
         mc->setAdmixedMaterial(
diff --git a/Sample/Particle/PolyhedralUtil.cpp b/Sample/Particle/PolyhedralUtil.cpp
index 20f3cdd3f96..64e200f0f49 100644
--- a/Sample/Particle/PolyhedralUtil.cpp
+++ b/Sample/Particle/PolyhedralUtil.cpp
@@ -21,8 +21,8 @@
 Span PolyhedralUtil::spanZ(const std::vector<R3>& vertices, const IRotation* rotation)
 {
     ASSERT(vertices.size());
-    const R3& v = vertices[0];
-    double z0 = (rotation ? rotation->transformed(v) : v).z();
+    const R3& v0 = vertices[0];
+    double z0 = (rotation ? rotation->transformed(v0) : v0).z();
     Span result(z0, z0);
     for (size_t i = 1; i < vertices.size(); ++i) {
         const R3& v = vertices[i];
diff --git a/Sample/StandardSamples/FeNiBilayerBuilder.cpp b/Sample/StandardSamples/FeNiBilayerBuilder.cpp
index ccaae0aba16..73027cf003a 100644
--- a/Sample/StandardSamples/FeNiBilayerBuilder.cpp
+++ b/Sample/StandardSamples/FeNiBilayerBuilder.cpp
@@ -130,7 +130,7 @@ private:
 
 std::unique_ptr<MultiLayer> FeNiBilayer::constructSample()
 {
-    auto sample = std::make_unique<MultiLayer>();
+    auto result = std::make_unique<MultiLayer>();
 
     auto m_ambient = MaterialBySLD("Ambient", 0.0, 0.0);
     auto m_Fe =
@@ -146,16 +146,16 @@ std::unique_ptr<MultiLayer> FeNiBilayer::constructSample()
     Layer l_Ni{m_Ni, thicknessNi};
 
     LayerRoughness roughness{sigmaRoughness, 0., 0.};
-    sample->addLayer(Layer{m_ambient});
+    result->addLayer(Layer{m_ambient});
 
     for (auto i = 0; i < NBilayers; ++i) {
-        sample->addLayerWithTopRoughness(l_Fe, roughness);
-        sample->addLayerWithTopRoughness(l_Ni, roughness);
+        result->addLayerWithTopRoughness(l_Fe, roughness);
+        result->addLayerWithTopRoughness(l_Ni, roughness);
     }
 
-    sample->addLayerWithTopRoughness(Layer{m_Substrate}, roughness);
-    sample->setRoughnessModel(roughnessModel);
-    return sample;
+    result->addLayerWithTopRoughness(Layer{m_Substrate}, roughness);
+    result->setRoughnessModel(roughnessModel);
+    return result;
 }
 
 } // namespace
diff --git a/Sample/StandardSamples/SlicedCylindersBuilder.cpp b/Sample/StandardSamples/SlicedCylindersBuilder.cpp
index 22a77c969f8..01c4bc25aba 100644
--- a/Sample/StandardSamples/SlicedCylindersBuilder.cpp
+++ b/Sample/StandardSamples/SlicedCylindersBuilder.cpp
@@ -14,14 +14,14 @@
 
 #include "Sample/StandardSamples/SlicedCylindersBuilder.h"
 #include "Base/Const/Units.h"
-#include <numbers>
-using std::numbers::pi;
 #include "Sample/Aggregate/ParticleLayout.h"
 #include "Sample/HardParticle/Cylinder.h"
 #include "Sample/Material/MaterialFactoryFuncs.h"
 #include "Sample/Multilayer/Layer.h"
 #include "Sample/Multilayer/MultiLayer.h"
 #include "Sample/Particle/Particle.h"
+#include <numbers>
+using std::numbers::pi;
 
 namespace {
 
@@ -32,10 +32,10 @@ const int n_slices(3);
 
 //! Returns SLD input (in inverse square Angstroms) for MaterialBySLD from _delta_ and _beta_,
 //! i.e. the input for RefractiveMaterial.
-complex_t getSLDFromN(double wavelength, double delta, double beta)
+complex_t getSLDFromN(double _wavelength, double delta, double beta)
 {
     complex_t result{2 * delta - delta * delta + beta * beta, 2 * beta - 2 * delta * beta};
-    return result * pi / (wavelength * wavelength) * (Units::angstrom * Units::angstrom);
+    return result * pi / (_wavelength * _wavelength) * (Units::angstrom * Units::angstrom);
 }
 
 complex_t averageSLD(complex_t sld_p, complex_t sld_l, double eff_vol)
-- 
GitLab