From 2aa232bef97cdfa1b89522af92aee455d564533d Mon Sep 17 00:00:00 2001 From: Uwe Date: Sat, 5 Nov 2022 19:48:23 +0100 Subject: [PATCH] [PD] TaskDlgRevolutionParameters: fix some CI warnings - reported here: https://github.com/FreeCAD/FreeCAD/pull/7667/commits/f0a0e563 - and here: https://github.com/FreeCAD/FreeCAD/pull/7719/commits/8f3f17f8 --- .../Gui/TaskRevolutionParameters.cpp | 70 +++++++++---------- .../PartDesign/Gui/TaskRevolutionParameters.h | 5 +- 2 files changed, 35 insertions(+), 40 deletions(-) diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp index 69d18f613257..3a986a78d9c7 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.cpp @@ -47,33 +47,32 @@ using namespace Gui; /* TRANSLATOR PartDesignGui::TaskRevolutionParameters */ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* RevolutionView, QWidget *parent) - : TaskSketchBasedParameters(RevolutionView, parent, "PartDesign_Revolution", tr("Revolution parameters")) - , ui(new Ui_TaskRevolutionParameters) + : TaskSketchBasedParameters(RevolutionView, parent, "PartDesign_Revolution", tr("Revolution parameters")), + ui(new Ui_TaskRevolutionParameters), proxy(new QWidget(this)) { // we need a separate container widget to add all controls to - proxy = new QWidget(this); ui->setupUi(proxy); QMetaObject::connectSlotsByName(this); this->groupLayout()->addWidget(proxy); - //bind property mirrors - PartDesign::ProfileBased* pcFeat = static_cast(vp->getObject()); - if (pcFeat->isDerivedFrom(PartDesign::Revolution::getClassTypeId())) { - PartDesign::Revolution* rev = static_cast(vp->getObject()); + // bind property mirrors + if (auto *rev = dynamic_cast(vp->getObject())) { this->propAngle = &(rev->Angle); this->propMidPlane = &(rev->Midplane); this->propReferenceAxis = &(rev->ReferenceAxis); this->propReversed = &(rev->Reversed); ui->revolveAngle->bind(rev->Angle); - } else { - assert(pcFeat->isDerivedFrom(PartDesign::Groove::getClassTypeId())); - PartDesign::Groove* rev = static_cast(vp->getObject()); + } + else if (auto *rev = dynamic_cast(vp->getObject())) { this->propAngle = &(rev->Angle); this->propMidPlane = &(rev->Midplane); this->propReferenceAxis = &(rev->ReferenceAxis); this->propReversed = &(rev->Reversed); ui->revolveAngle->bind(rev->Angle); } + else { + throw Base::TypeError("The ViewProvider is not a Groove or a Revolution."); + } ui->checkBoxMidplane->setChecked(propMidPlane->getValue()); ui->checkBoxReversed->setChecked(propReversed->getValue()); @@ -88,15 +87,16 @@ TaskRevolutionParameters::TaskRevolutionParameters(PartDesignGui::ViewProvider* setFocus (); - //show the parts coordinate system axis for selection + // show the parts coordinate system axis for selection PartDesign::Body * body = PartDesign::Body::findBodyOf ( vp->getObject () ); - if(body) { + if (body) { try { App::Origin *origin = body->getOrigin(); - ViewProviderOrigin* vpOrigin; - vpOrigin = static_cast(Gui::Application::Instance->getViewProvider(origin)); + auto *vpOrigin = static_cast( + Gui::Application::Instance->getViewProvider(origin)); vpOrigin->setTemporaryVisibility(true, false); - } catch (const Base::Exception &ex) { + } + catch (const Base::Exception &ex) { ex.ReportException(); } } @@ -109,17 +109,15 @@ void TaskRevolutionParameters::fillAxisCombo(bool forceRefill) if (axesInList.empty()) forceRefill = true;//not filled yet, full refill - if (forceRefill){ + if (forceRefill) { ui->axis->clear(); - - for(size_t i = 0; i < axesInList.size(); i++){ - delete axesInList[i]; - } - this->axesInList.clear(); + axesInList.clear(); //add sketch axes - PartDesign::ProfileBased* pcFeat = static_cast(vp->getObject()); - Part::Part2DObject* pcSketch = dynamic_cast(pcFeat->Profile.getValue()); + auto *pcFeat = dynamic_cast(vp->getObject()); + if (!pcFeat) + throw Base::TypeError("The ViewProvider is not ProfileBased."); + auto *pcSketch = static_cast(pcFeat->Profile.getValue()); if (pcSketch){ addAxisToCombo(pcSketch,"V_Axis",QObject::tr("Vertical sketch axis")); addAxisToCombo(pcSketch,"H_Axis",QObject::tr("Horizontal sketch axis")); @@ -176,23 +174,23 @@ void TaskRevolutionParameters::addAxisToCombo(App::DocumentObject* linkObj, QString itemText) { this->ui->axis->addItem(itemText); - this->axesInList.push_back(new App::PropertyLinkSub()); + this->axesInList.emplace_back(); App::PropertyLinkSub &lnk = *(axesInList[axesInList.size()-1]); lnk.setValue(linkObj,std::vector(1,linkSubname)); } void TaskRevolutionParameters::connectSignals() { - connect(ui->revolveAngle, SIGNAL(valueChanged(double)), - this, SLOT(onAngleChanged(double))); - connect(ui->axis, SIGNAL(activated(int)), - this, SLOT(onAxisChanged(int))); - connect(ui->checkBoxMidplane, SIGNAL(toggled(bool)), - this, SLOT(onMidplane(bool))); - connect(ui->checkBoxReversed, SIGNAL(toggled(bool)), - this, SLOT(onReversed(bool))); - connect(ui->checkBoxUpdateView, SIGNAL(toggled(bool)), - this, SLOT(onUpdateView(bool))); + connect(ui->revolveAngle, qOverload(&QuantitySpinBox::valueChanged), this, + &TaskRevolutionParameters::onAngleChanged); + connect(ui->axis, qOverload(&QComboBox::activated), this, + &TaskRevolutionParameters::onAxisChanged); + connect(ui->checkBoxMidplane, &QCheckBox::toggled, this, + &TaskRevolutionParameters::onMidplane); + connect(ui->checkBoxReversed, &QCheckBox::toggled, this, + &TaskRevolutionParameters::onReversed); + connect(ui->checkBoxUpdateView, &QCheckBox::toggled, this, + &TaskRevolutionParameters::onUpdateView); } void TaskRevolutionParameters::updateUI() @@ -353,9 +351,7 @@ TaskRevolutionParameters::~TaskRevolutionParameters() ex.ReportException(); } - for (size_t i = 0; i < axesInList.size(); i++) { - delete axesInList[i]; - } + axesInList.clear(); } void TaskRevolutionParameters::changeEvent(QEvent *e) diff --git a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h index d4a02e227f2e..12a9af46c5d4 100644 --- a/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h +++ b/src/Mod/PartDesign/Gui/TaskRevolutionParameters.h @@ -70,7 +70,6 @@ private Q_SLOTS: protected: void onSelectionChanged(const Gui::SelectionChanges& msg) override; void changeEvent(QEvent *e) override; - bool updateView() const; void getReferenceAxis(App::DocumentObject *&obj, std::vector &sub) const; double getAngle() const; bool getMidplane() const; @@ -88,8 +87,8 @@ private Q_SLOTS: void updateUI(); private: - QWidget* proxy; std::unique_ptr ui; + QWidget *proxy; /** * @brief axesInList is the list of links corresponding to axis combo; must @@ -99,7 +98,7 @@ private Q_SLOTS: * It is a list of pointers, because properties prohibit assignment. Use new * when adding stuff, and delete when removing stuff. */ - std::vector axesInList; + std::vector> axesInList; }; /// simulation dialog for the TaskView