From d419b325fbc42c0bad4a54503f741e0c8ba7ed8b Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 13 Mar 2022 14:09:04 +0100 Subject: [PATCH] Fem: Fix several coverity issues: * make SelectionChangeModes an enum class * CID 350596: Uninitialized scalar field * CID 350572: Uncaught exception * CID 350647: Uncaught exception --- .../Fem/Gui/TaskFemConstraintDisplacement.cpp | 6 ++++-- src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp | 6 ++++-- .../Gui/TaskFemConstraintFluidBoundary.cpp | 8 ++++--- src/Mod/Fem/Gui/TaskFemConstraintForce.cpp | 8 ++++--- src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp | 6 ++++-- .../Fem/Gui/TaskFemConstraintOnBoundary.cpp | 21 ++++++++++--------- src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h | 4 ++-- src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp | 6 ++++-- src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp | 6 ++++-- .../Fem/Gui/TaskFemConstraintTemperature.cpp | 6 ++++-- 10 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp index 9cb973b81a..bb0a64911f 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintDisplacement.cpp @@ -569,8 +569,10 @@ void TaskFemConstraintDisplacement::changeEvent(QEvent *) void TaskFemConstraintDisplacement::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp index 278cc88da0..4fb76c7eed 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFixed.cpp @@ -250,8 +250,10 @@ void TaskFemConstraintFixed::changeEvent(QEvent *) void TaskFemConstraintFixed::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp index c810fdcec0..dfbd6e3492 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintFluidBoundary.cpp @@ -561,7 +561,7 @@ void TaskFemConstraintFluidBoundary::onButtonDirection(const bool pressed) Q_UNUSED(pressed) - clearButtons(none); + clearButtons(SelectionChangeModes::none); //get vector of selected objects of active document std::vector selection = Gui::Selection().getSelectionEx(); @@ -871,8 +871,10 @@ void TaskFemConstraintFluidBoundary::changeEvent(QEvent *e) void TaskFemConstraintFluidBoundary::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp index 215854d28a..ecefbb5d47 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintForce.cpp @@ -318,7 +318,7 @@ void TaskFemConstraintForce::onButtonDirection(const bool pressed) // sets the normal vector of the currently selecteed planar face as direction Q_UNUSED(pressed) - clearButtons(none); + clearButtons(SelectionChangeModes::none); auto link = getDirection(Gui::Selection().getSelectionEx()); if (!link.first) { @@ -409,8 +409,10 @@ void TaskFemConstraintForce::changeEvent(QEvent *e) void TaskFemConstraintForce::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp index c86daf5dbc..77390e8048 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintHeatflux.cpp @@ -380,8 +380,10 @@ void TaskFemConstraintHeatflux::changeEvent(QEvent *e) void TaskFemConstraintHeatflux::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp index 5163f35f85..264cb51c04 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.cpp @@ -59,6 +59,7 @@ using namespace Gui; TaskFemConstraintOnBoundary::TaskFemConstraintOnBoundary(ViewProviderFemConstraint *ConstraintView, QWidget *parent, const char* pixmapname) : TaskFemConstraint(ConstraintView, parent, pixmapname) + , selChangeMode(SelectionChangeModes::none) { ConstraintView->highlightReferences(true); } @@ -74,12 +75,12 @@ void TaskFemConstraintOnBoundary::_addToSelection(bool checked) { const auto& selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document if (selection.empty()) { - this->clearButtons(refAdd); - selChangeMode = refAdd; + this->clearButtons(SelectionChangeModes::refAdd); + selChangeMode = SelectionChangeModes::refAdd; ConstraintView->highlightReferences(true); } else { this->addToSelection(); - clearButtons(none); + clearButtons(SelectionChangeModes::none); } } else { exitSelectionChangeMode(); @@ -92,12 +93,12 @@ void TaskFemConstraintOnBoundary::_removeFromSelection(bool checked) { const auto& selection = Gui::Selection().getSelectionEx(); //gets vector of selected objects of active document if (selection.empty()) { - this->clearButtons(refRemove); - selChangeMode = refRemove; + this->clearButtons(SelectionChangeModes::refRemove); + selChangeMode = SelectionChangeModes::refRemove; ConstraintView->highlightReferences(true); } else { this->removeFromSelection(); - clearButtons(none); + clearButtons(SelectionChangeModes::none); } } else { exitSelectionChangeMode(); @@ -108,15 +109,15 @@ void TaskFemConstraintOnBoundary::onSelectionChanged(const Gui::SelectionChanges { if (msg.Type == Gui::SelectionChanges::AddSelection) { switch (selChangeMode) { - case refAdd: + case SelectionChangeModes::refAdd: // TODO: Optimize to just perform actions on the newly selected item. Suggestion from PartDesign: // ui->lw_references->addItem(makeRefText(msg.pObjectName, msg.pSubName)); this->addToSelection(); break; - case refRemove: + case SelectionChangeModes::refRemove: this->removeFromSelection(); break; - case none: + case SelectionChangeModes::none: return; default: return; @@ -127,7 +128,7 @@ void TaskFemConstraintOnBoundary::onSelectionChanged(const Gui::SelectionChanges void TaskFemConstraintOnBoundary::exitSelectionChangeMode() { - selChangeMode = none; + selChangeMode = SelectionChangeModes::none; Gui::Selection().clearSelection(); } diff --git a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h index 908174a245..a5d4b7cd6f 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h +++ b/src/Mod/Fem/Gui/TaskFemConstraintOnBoundary.h @@ -50,7 +50,7 @@ class TaskFemConstraintOnBoundary : public TaskFemConstraint Q_OBJECT public: - TaskFemConstraintOnBoundary(ViewProviderFemConstraint *ConstraintView, QWidget *parent = 0, const char* pixmapname = ""); + TaskFemConstraintOnBoundary(ViewProviderFemConstraint *ConstraintView, QWidget *parent = nullptr, const char* pixmapname = ""); ~TaskFemConstraintOnBoundary(); protected Q_SLOTS: @@ -60,7 +60,7 @@ protected Q_SLOTS: virtual void removeFromSelection() = 0; protected: - enum SelectionChangeModes {none, refAdd, refRemove}; + enum class SelectionChangeModes {none, refAdd, refRemove}; virtual void onSelectionChanged(const Gui::SelectionChanges&) override; virtual void clearButtons(const SelectionChangeModes notThis) = 0; void exitSelectionChangeMode(); diff --git a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp index 5d8412ae96..15b5792a52 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintPressure.cpp @@ -266,8 +266,10 @@ void TaskFemConstraintPressure::changeEvent(QEvent *) void TaskFemConstraintPressure::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp index dd1f5942c5..7c20a8a3e1 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintSpring.cpp @@ -266,8 +266,10 @@ void TaskFemConstraintSpring::changeEvent(QEvent *) void TaskFemConstraintSpring::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //************************************************************************** diff --git a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp index 9073a18ad4..6f019d141f 100644 --- a/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp +++ b/src/Mod/Fem/Gui/TaskFemConstraintTemperature.cpp @@ -322,8 +322,10 @@ void TaskFemConstraintTemperature::changeEvent(QEvent *) void TaskFemConstraintTemperature::clearButtons(const SelectionChangeModes notThis) { - if (notThis != refAdd) ui->btnAdd->setChecked(false); - if (notThis != refRemove) ui->btnRemove->setChecked(false); + if (notThis != SelectionChangeModes::refAdd) + ui->btnAdd->setChecked(false); + if (notThis != SelectionChangeModes::refRemove) + ui->btnRemove->setChecked(false); } //**************************************************************************