Gui: Use auto and range-based for (#7481)

* On lines where the variable type is obvious from inspection, avoid repeating the type using auto. 
* When possible use a ranged for loop instead of begin() and end() iterators
This commit is contained in:
berniev
2022-09-15 04:25:13 +10:00
committed by GitHub
parent d7792826b4
commit 75acacd1b7
175 changed files with 2051 additions and 2057 deletions

View File

@@ -77,7 +77,7 @@ void AlignmentGroup::addView(App::DocumentObject* pView)
if (pView) {
App::Document* rDoc = pView->getDocument();
Gui::Document* pDoc = Gui::Application::Instance->getDocument(rDoc);
Gui::ViewProviderDocumentObject* pProvider = static_cast<Gui::ViewProviderDocumentObject*>
auto pProvider = static_cast<Gui::ViewProviderDocumentObject*>
(pDoc->getViewProvider(pView));
this->_views.push_back(pProvider);
}
@@ -149,7 +149,7 @@ void AlignmentGroup::setRandomColor()
SoPath* selectionPath = searchAction.getPath();
if (selectionPath) {
SoMaterial* material = static_cast<SoMaterial*>(selectionPath->getTail());
auto material = static_cast<SoMaterial*>(selectionPath->getTail());
material->diffuseColor.setValue(r, g, b);
}
}
@@ -199,13 +199,13 @@ void AlignmentGroup::setAlignable(bool align)
{
std::vector<Gui::ViewProviderDocumentObject*>::iterator it;
for (it = this->_views.begin(); it != this->_views.end(); ++it) {
App::PropertyBool* pAlignMode = dynamic_cast<App::PropertyBool*>((*it)->getPropertyByName("AlignMode"));
auto pAlignMode = dynamic_cast<App::PropertyBool*>((*it)->getPropertyByName("AlignMode"));
if (pAlignMode) {
pAlignMode->setValue(align);
}
// leaving alignment mode
else if (!align){
App::PropertyColor* pColor = dynamic_cast<App::PropertyColor*>((*it)->getPropertyByName("ShapeColor"));
auto pColor = dynamic_cast<App::PropertyColor*>((*it)->getPropertyByName("ShapeColor"));
if (pColor)
pColor->touch(); // resets to color defined by property
}
@@ -243,7 +243,7 @@ Base::BoundBox3d AlignmentGroup::getBoundingBox() const
std::vector<Gui::ViewProviderDocumentObject*>::const_iterator it;
for (it = this->_views.begin(); it != this->_views.end(); ++it) {
if ((*it)->isDerivedFrom(Gui::ViewProviderGeometryObject::getClassTypeId())) {
App::GeoFeature* geo = static_cast<App::GeoFeature*>((*it)->getObject());
auto geo = static_cast<App::GeoFeature*>((*it)->getObject());
const App::PropertyComplexGeoData* prop = geo->getPropertyOfGeometry();
if (prop)
box.Add(prop->getBoundingBox());
@@ -289,8 +289,8 @@ void MovableGroupModel::addGroup(const MovableGroup& grp)
void MovableGroupModel::addGroups(const std::map<int, MovableGroup>& grps)
{
for (std::map<int, MovableGroup>::const_iterator it = grps.begin(); it != grps.end(); ++it)
this->_groups.push_back(it->second);
for (const auto & grp : grps)
this->_groups.push_back(grp.second);
}
void MovableGroupModel::removeActiveGroup()
@@ -392,8 +392,8 @@ public:
_viewer.back()->setDocument(pcDocument);
}
QFrame* vbox = new QFrame(this);
QVBoxLayout* layout = new QVBoxLayout();
auto vbox = new QFrame(this);
auto layout = new QVBoxLayout();
layout->setMargin(0);
layout->setSpacing(0);
vbox->setLayout(layout);
@@ -420,8 +420,8 @@ public:
setupSettings();
if (smoothing) {
for (std::vector<int>::size_type i = 0; i != _viewer.size(); i++)
_viewer[i]->getSoRenderManager()->getGLRenderAction()->setSmoothing(true);
for (const auto & i : _viewer)
i->getSoRenderManager()->getGLRenderAction()->setSmoothing(true);
}
static_cast<SoGroup*>(getViewer(0)->getSoRenderManager()->getSceneGraph())->
@@ -442,16 +442,16 @@ public:
}
SoNode* setupHeadUpDisplay(const QString& text) const
{
SoSeparator* hudRoot = new SoSeparator;
auto hudRoot = new SoSeparator;
hudRoot->ref();
SoOrthographicCamera* hudCam = new SoOrthographicCamera();
auto hudCam = new SoOrthographicCamera();
hudCam->viewportMapping = SoCamera::LEAVE_ALONE;
// Set the position in the window.
// [0, 0] is in the center of the screen.
//
SoTranslation* hudTrans = new SoTranslation;
auto hudTrans = new SoTranslation;
hudTrans->translation.setValue(-0.95f, -0.95f, 0.0f);
QFont font = this->font();
@@ -474,7 +474,7 @@ public:
painter.end();
SoSFImage sfimage;
Gui::BitmapFactory().convert(image, sfimage);
SoImage* hudImage = new SoImage();
auto hudImage = new SoImage();
hudImage->image = sfimage;
// Assemble the parts...
@@ -575,14 +575,14 @@ public:
static
void syncCameraCB(void * data, SoSensor * s)
{
ManualAlignment* self = static_cast<ManualAlignment*>(data);
auto self = static_cast<ManualAlignment*>(data);
if (!self->myViewer)
return; // already destroyed
SoCamera* cam1 = self->myViewer->getViewer(0)->getSoRenderManager()->getCamera();
SoCamera* cam2 = self->myViewer->getViewer(1)->getSoRenderManager()->getCamera();
if (!cam1 || !cam2)
return; // missing camera
SoNodeSensor* sensor = static_cast<SoNodeSensor*>(s);
auto sensor = static_cast<SoNodeSensor*>(s);
SoNode* node = sensor->getAttachedNode();
if (node && node->getTypeId().isDerivedFrom(SoCamera::getClassTypeId())) {
if (node == cam1) {
@@ -986,8 +986,8 @@ void ManualAlignment::align()
if (ok && myDocument) {
// Align views
myDocument->openCommand(QT_TRANSLATE_NOOP("Command", "Align"));
for (std::vector<App::DocumentObject*>::iterator it = pViews.begin(); it != pViews.end(); ++it)
alignObject(*it);
for (const auto & pView : pViews)
alignObject(pView);
myDocument->commitCommand();
// the alignment was successful so show it in the right view now
@@ -1106,7 +1106,7 @@ bool ManualAlignment::computeAlignment(const std::vector<PickedPoint>& movPts,
void ManualAlignment::alignObject(App::DocumentObject *obj)
{
if (obj->getTypeId().isDerivedFrom(App::GeoFeature::getClassTypeId())) {
App::GeoFeature* geom = static_cast<App::GeoFeature*>(obj);
auto geom = static_cast<App::GeoFeature*>(obj);
geom->transformPlacement(this->myTransform);
}
}
@@ -1131,7 +1131,7 @@ SoNode* ManualAlignment::pickedPointsSubGraph(const SbVec3f& p, const SbVec3f& n
int index = (id-1) % 10;
SoRegPoint* probe = new SoRegPoint();
auto probe = new SoRegPoint();
probe->base.setValue(p);
probe->normal.setValue(n);
probe->color.setValue(color_table[index][0],color_table[index][1],color_table[index][2]);
@@ -1158,7 +1158,7 @@ void ManualAlignment::slotDeletedObject(const Gui::ViewProvider& Obj)
if (Obj.getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
// remove the view provider immediately from the split window
bool found = false;
Gui::ViewProviderDocumentObject* vp = const_cast<Gui::ViewProviderDocumentObject*>
auto vp = const_cast<Gui::ViewProviderDocumentObject*>
(static_cast<const Gui::ViewProviderDocumentObject*>(&Obj));
if (myAlignModel.activeGroup().hasView(vp)) {
myViewer->getViewer(0)->removeViewProvider(vp);
@@ -1215,14 +1215,14 @@ void ManualAlignment::probePickedCallback(void * ud, SoEventCallback * n)
{
Q_UNUSED(ud);
Gui::View3DInventorViewer* view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
auto view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
const SoEvent* ev = n->getEvent();
if (ev->getTypeId() == SoMouseButtonEvent::getClassTypeId()) {
// set as handled
n->getAction()->setHandled();
n->setHandled();
const SoMouseButtonEvent * mbe = static_cast<const SoMouseButtonEvent *>(ev);
auto mbe = static_cast<const SoMouseButtonEvent *>(ev);
if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) {
// if we are in 'align' mode then handle the click event
ManualAlignment* self = ManualAlignment::instance();
@@ -1231,9 +1231,9 @@ void ManualAlignment::probePickedCallback(void * ud, SoEventCallback * n)
Gui::WaitCursor wc;
const SoPickedPoint * point = view->getPickedPoint(n);
if (point) {
Gui::ViewProvider* vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
auto vp = static_cast<Gui::ViewProvider*>(view->getViewProviderByPath(point->getPath()));
if (vp && vp->getTypeId().isDerivedFrom(Gui::ViewProviderDocumentObject::getClassTypeId())) {
Gui::ViewProviderDocumentObject* that = static_cast<Gui::ViewProviderDocumentObject*>(vp);
auto that = static_cast<Gui::ViewProviderDocumentObject*>(vp);
if (self->applyPickedProbe(that, point)) {
const SbVec3f& vec = point->getPoint();
Gui::getMainWindow()->showMessage(