From 1d95c26e2ee4e522a2b3dbdd56035517307f1ed5 Mon Sep 17 00:00:00 2001 From: Uwe Date: Mon, 18 Jul 2022 03:34:22 +0200 Subject: [PATCH] [Gui] remove more superfluous nullptr checks --- src/Gui/Application.cpp | 2 +- src/Gui/BitmapFactory.cpp | 2 +- src/Gui/Control.cpp | 2 +- src/Gui/DockWindowManager.cpp | 2 +- src/Gui/DocumentObserver.cpp | 2 +- src/Gui/GraphvizView.cpp | 19 ++++++------------- src/Gui/ManualAlignment.cpp | 2 +- src/Gui/NaviCube.cpp | 2 +- src/Gui/NavigationStyle.cpp | 16 ++++++++-------- src/Gui/PythonConsole.cpp | 4 ++-- src/Gui/PythonDebugger.cpp | 12 ++++++------ src/Gui/Quarter/DragDropHandler.cpp | 2 +- src/Gui/Quarter/KeyboardP.cpp | 2 +- src/Gui/Quarter/QuarterWidgetP.cpp | 2 +- src/Gui/Selection.cpp | 2 +- src/Gui/SoFCSelectionAction.cpp | 4 ++-- src/Gui/SoFCUnifiedSelection.cpp | 2 +- src/Gui/Tree.cpp | 2 +- src/Gui/View3DInventorExamples.cpp | 6 +++--- src/Gui/View3DInventorViewer.cpp | 4 ++-- src/Gui/ViewProviderMeasureDistance.cpp | 2 +- src/Gui/WorkbenchManager.cpp | 2 +- src/Gui/propertyeditor/PropertyItem.cpp | 2 +- 23 files changed, 45 insertions(+), 52 deletions(-) diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index 086d60b08e..0d6278dcd1 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -443,7 +443,7 @@ Application::Application(bool GUIenabled) for (; meth->ml_name != nullptr; meth++) { PyObject *descr; descr = PyCFunction_NewEx(meth,nullptr,nullptr); - if (descr == nullptr) + if (!descr) break; if (PyDict_SetItemString(dict, meth->ml_name, descr) != 0) break; diff --git a/src/Gui/BitmapFactory.cpp b/src/Gui/BitmapFactory.cpp index 1f9537e698..fb9e8138bc 100644 --- a/src/Gui/BitmapFactory.cpp +++ b/src/Gui/BitmapFactory.cpp @@ -91,7 +91,7 @@ BitmapFactoryInst* BitmapFactoryInst::_pcSingleton = nullptr; BitmapFactoryInst& BitmapFactoryInst::instance(void) { - if (_pcSingleton == nullptr) + if (!_pcSingleton) { _pcSingleton = new BitmapFactoryInst; std::map::const_iterator it; diff --git a/src/Gui/Control.cpp b/src/Gui/Control.cpp index 00d3e29616..725ec387fc 100644 --- a/src/Gui/Control.cpp +++ b/src/Gui/Control.cpp @@ -256,7 +256,7 @@ bool ControlSingleton::isAllowedAlterSelection(void) const ControlSingleton& ControlSingleton::instance(void) { - if (_pcSingleton == nullptr) + if (!_pcSingleton) _pcSingleton = new ControlSingleton; return *_pcSingleton; } diff --git a/src/Gui/DockWindowManager.cpp b/src/Gui/DockWindowManager.cpp index 2e7d2b0ea7..3a4bce1854 100644 --- a/src/Gui/DockWindowManager.cpp +++ b/src/Gui/DockWindowManager.cpp @@ -102,7 +102,7 @@ DockWindowManager* DockWindowManager::_instance = nullptr; DockWindowManager* DockWindowManager::instance() { - if ( _instance == nullptr ) + if (!_instance) _instance = new DockWindowManager; return _instance; } diff --git a/src/Gui/DocumentObserver.cpp b/src/Gui/DocumentObserver.cpp index e0e7acc8aa..a5cb320fbb 100644 --- a/src/Gui/DocumentObserver.cpp +++ b/src/Gui/DocumentObserver.cpp @@ -422,7 +422,7 @@ void DocumentObserver::attachDocument(Document* doc) { detachDocument(); - if (doc == nullptr) + if (!doc) return; this->connectDocumentCreatedObject = doc->signalNewObject.connect(std::bind diff --git a/src/Gui/GraphvizView.cpp b/src/Gui/GraphvizView.cpp index 8af0912aac..b32af17a5e 100644 --- a/src/Gui/GraphvizView.cpp +++ b/src/Gui/GraphvizView.cpp @@ -164,8 +164,7 @@ GraphvizGraphicsView::GraphvizGraphicsView(QGraphicsScene* scene, QWidget* paren void GraphvizGraphicsView::mousePressEvent(QMouseEvent* e) { - if(e && e->button() == Qt::LeftButton) - { + if (e && e->button() == Qt::LeftButton) { isPanning = true; panStart = e->pos(); e->accept(); @@ -179,20 +178,14 @@ void GraphvizGraphicsView::mousePressEvent(QMouseEvent* e) void GraphvizGraphicsView::mouseMoveEvent(QMouseEvent *e) { - if(e == nullptr) - { + if (!e) return; - } - if(isPanning) - { - auto* horizontalScrollbar = horizontalScrollBar(); - auto* verticalScrollbar = verticalScrollBar(); - if(horizontalScrollbar == nullptr || - verticalScrollbar == nullptr) - { + if (isPanning) { + auto *horizontalScrollbar = horizontalScrollBar(); + auto *verticalScrollbar = verticalScrollBar(); + if (!horizontalScrollbar || !verticalScrollbar) return; - } auto direction = e->pos() - panStart; horizontalScrollbar->setValue(horizontalScrollbar->value() - direction.x()); diff --git a/src/Gui/ManualAlignment.cpp b/src/Gui/ManualAlignment.cpp index e7bae457e2..a518dda19c 100644 --- a/src/Gui/ManualAlignment.cpp +++ b/src/Gui/ManualAlignment.cpp @@ -518,7 +518,7 @@ public: static void reorientCamera(SoCamera * cam, const SbRotation & rot) { - if (cam == nullptr) + if (!cam) return; // Find global coordinates of focal point. diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index fe72a8f9bc..e3fec48882 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -903,7 +903,7 @@ void NaviCubeImplementation::drawNaviCube(bool pickMode) { // FIXME actually now that we have Qt5, we could probably do this earlier (as we do not need the opengl context) if (!m_NaviCubeInitialised) { QtGLWidget* gl = static_cast(m_View3DInventorViewer->viewport()); - if (gl == nullptr) + if (!gl) return; initNaviCube(gl); m_NaviCubeInitialised = true; diff --git a/src/Gui/NavigationStyle.cpp b/src/Gui/NavigationStyle.cpp index 2713c7df19..fff661220a 100644 --- a/src/Gui/NavigationStyle.cpp +++ b/src/Gui/NavigationStyle.cpp @@ -325,7 +325,7 @@ void NavigationStyle::seekToPoint(const SbVec3f& scenepos) SbBool NavigationStyle::lookAtPoint(const SbVec2s screenpos) { SoCamera* cam = viewer->getSoRenderManager()->getCamera(); - if (cam == nullptr) + if (!cam) return false; SoRayPickAction rpaction(viewer->getSoRenderManager()->getViewportRegion()); @@ -348,7 +348,7 @@ SbBool NavigationStyle::lookAtPoint(const SbVec2s screenpos) void NavigationStyle::lookAtPoint(const SbVec3f& pos) { SoCamera* cam = viewer->getSoRenderManager()->getCamera(); - if (cam == nullptr) + if (!cam) return; PRIVATE(this)->rotationCenterFound = false; @@ -407,7 +407,7 @@ void NavigationStyle::lookAtPoint(const SbVec3f& pos) void NavigationStyle::setCameraOrientation(const SbRotation& rot, SbBool moveToCenter) { SoCamera* cam = viewer->getSoRenderManager()->getCamera(); - if (cam == nullptr) + if (!cam) return; // Find global coordinates of focal point. @@ -597,7 +597,7 @@ void NavigationStyle::viewAll() */ void NavigationStyle::reorientCamera(SoCamera * cam, const SbRotation & rot) { - if (cam == nullptr) + if (!cam) return; // Find global coordinates of focal point. @@ -617,7 +617,7 @@ void NavigationStyle::reorientCamera(SoCamera * cam, const SbRotation & rot) void NavigationStyle::panCamera(SoCamera * cam, float aspectratio, const SbPlane & panplane, const SbVec2f & currpos, const SbVec2f & prevpos) { - if (cam == nullptr) // can happen for empty scenegraph + if (!cam) // can happen for empty scenegraph return; if (currpos == prevpos) // useless invocation return; @@ -648,7 +648,7 @@ void NavigationStyle::pan(SoCamera* camera) // The plane we're projecting the mouse coordinates to get 3D // coordinates should stay the same during the whole pan // operation, so we should calculate this value here. - if (camera == nullptr) { // can happen for empty scenegraph + if (!camera) { // can happen for empty scenegraph this->panningplane = SbPlane(SbVec3f(0, 0, 1), 0); } else { @@ -678,7 +678,7 @@ void NavigationStyle::panToCenter(const SbPlane & pplane, const SbVec2f & currpo */ void NavigationStyle::zoom(SoCamera * cam, float diffvalue) { - if (cam == nullptr) // can happen for empty scenegraph + if (!cam) // can happen for empty scenegraph return; SoType t = cam->getTypeId(); SbName tname = t.getName(); @@ -860,7 +860,7 @@ void NavigationStyle::setRotationCenter(const SbVec3f& cnt) SbVec3f NavigationStyle::getFocalPoint() const { SoCamera* cam = viewer->getSoRenderManager()->getCamera(); - if (cam == nullptr) + if (!cam) return SbVec3f(0,0,0); // Find global coordinates of focal point. diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index 8317833eb4..66d003d5f3 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -300,10 +300,10 @@ void InteractiveInterpreter::runCode(PyCodeObject* code) const Base::PyGILStateLocker lock; PyObject *module, *dict, *presult; /* "exec code in d, d" */ module = PyImport_AddModule("__main__"); /* get module, init python */ - if (module == nullptr) + if (!module) throw Base::PyException(); /* not incref'd */ dict = PyModule_GetDict(module); /* get dict namespace */ - if (dict == nullptr) + if (!dict) throw Base::PyException(); /* not incref'd */ // It seems that the return value is always 'None' or Null diff --git a/src/Gui/PythonDebugger.cpp b/src/Gui/PythonDebugger.cpp index cd44e9b1c2..955dc910ac 100644 --- a/src/Gui/PythonDebugger.cpp +++ b/src/Gui/PythonDebugger.cpp @@ -438,18 +438,18 @@ void PythonDebugger::runFile(const QString& fn) module = PyImport_AddModule("__main__"); dict = PyModule_GetDict(module); dict = PyDict_Copy(dict); - if (PyDict_GetItemString(dict, "__file__") == nullptr) { - PyObject *f = PyUnicode_FromString((const char*)pxFileName); - if (f == nullptr) { + if (!PyDict_GetItemString(dict, "__file__")) { + PyObject *pyObj = PyUnicode_FromString((const char*)pxFileName); + if (!pyObj) { fclose(fp); return; } - if (PyDict_SetItemString(dict, "__file__", f) < 0) { - Py_DECREF(f); + if (PyDict_SetItemString(dict, "__file__", pyObj) < 0) { + Py_DECREF(pyObj); fclose(fp); return; } - Py_DECREF(f); + Py_DECREF(pyObj); } PyObject *result = PyRun_File(fp, (const char*)pxFileName, Py_file_input, dict, dict); diff --git a/src/Gui/Quarter/DragDropHandler.cpp b/src/Gui/Quarter/DragDropHandler.cpp index f8b957c42b..d72d8379b4 100644 --- a/src/Gui/Quarter/DragDropHandler.cpp +++ b/src/Gui/Quarter/DragDropHandler.cpp @@ -155,7 +155,7 @@ DragDropHandlerP::dropEvent(QDropEvent * event) // attempt to import it root = SoDB::readAll(&in); - if (root == nullptr) + if (!root) return; // set new scenegraph diff --git a/src/Gui/Quarter/KeyboardP.cpp b/src/Gui/Quarter/KeyboardP.cpp index 5ff7acdf02..b73e81c414 100644 --- a/src/Gui/Quarter/KeyboardP.cpp +++ b/src/Gui/Quarter/KeyboardP.cpp @@ -45,7 +45,7 @@ KeyboardP::KeyboardP(Keyboard * publ) PUBLIC(this) = publ; this->keyboard = new SoKeyboardEvent; - if (keyboardmap == nullptr) { + if (!keyboardmap) { keyboardmap = new KeyMap; keypadmap = new KeyMap; this->initKeyMap(); diff --git a/src/Gui/Quarter/QuarterWidgetP.cpp b/src/Gui/Quarter/QuarterWidgetP.cpp index ea59fc0fb2..c7031c4452 100644 --- a/src/Gui/Quarter/QuarterWidgetP.cpp +++ b/src/Gui/Quarter/QuarterWidgetP.cpp @@ -136,7 +136,7 @@ QuarterWidgetP::getCacheContextId() const QuarterWidgetP_cachecontext * QuarterWidgetP::findCacheContext(QuarterWidget * widget, const QtGLWidget * sharewidget) { - if (cachecontext_list == nullptr) { + if (!cachecontext_list) { // FIXME: static memory leak cachecontext_list = new SbList ; } diff --git a/src/Gui/Selection.cpp b/src/Gui/Selection.cpp index fb1b5e7f52..eb1dbb8b95 100644 --- a/src/Gui/Selection.cpp +++ b/src/Gui/Selection.cpp @@ -1818,7 +1818,7 @@ SelectionSingleton* SelectionSingleton::_pcSingleton = nullptr; SelectionSingleton& SelectionSingleton::instance(void) { - if (_pcSingleton == nullptr) + if (!_pcSingleton) _pcSingleton = new SelectionSingleton; return *_pcSingleton; } diff --git a/src/Gui/SoFCSelectionAction.cpp b/src/Gui/SoFCSelectionAction.cpp index 98a24c8b8e..45e7455426 100644 --- a/src/Gui/SoFCSelectionAction.cpp +++ b/src/Gui/SoFCSelectionAction.cpp @@ -1030,7 +1030,7 @@ SoBoxSelectionRenderActionP::initBoxGraph() void SoBoxSelectionRenderActionP::updateBbox(const SoPath * path) { - if (this->camerasearch == nullptr) { + if (!this->camerasearch) { this->camerasearch = new SoSearchAction; } @@ -1047,7 +1047,7 @@ SoBoxSelectionRenderActionP::updateBbox(const SoPath * path) this->localRoot->insertChild(this->camerasearch->getPath()->getTail(), 0); this->camerasearch->reset(); - if (this->bboxaction == nullptr) { + if (!this->bboxaction) { this->bboxaction = new SoGetBoundingBoxAction(SbViewportRegion(100, 100)); } this->bboxaction->setViewportRegion(PUBLIC(this)->getViewportRegion()); diff --git a/src/Gui/SoFCUnifiedSelection.cpp b/src/Gui/SoFCUnifiedSelection.cpp index 83af95d097..b5db3b52b1 100644 --- a/src/Gui/SoFCUnifiedSelection.cpp +++ b/src/Gui/SoFCUnifiedSelection.cpp @@ -1203,7 +1203,7 @@ std::pair SoFCSelectionRoot::findActionContex bool SoFCSelectionRoot::renderBBox(SoGLRenderAction *action, SoNode *node, SbColor color) { auto data = (SoFCBBoxRenderInfo*) so_bbox_storage->get(); - if (data->bboxaction == nullptr) { + if (!data->bboxaction) { // The viewport region will be replaced every time the action is // used, so we can just feed it a dummy here. data->bboxaction = new SoGetBoundingBoxAction(SbViewportRegion()); diff --git a/src/Gui/Tree.cpp b/src/Gui/Tree.cpp index 44b3328c7d..3e894122fd 100644 --- a/src/Gui/Tree.cpp +++ b/src/Gui/Tree.cpp @@ -3306,7 +3306,7 @@ bool DocumentItem::createNewItem(const Gui::ViewProviderDocumentObject& obj, pdata->updateChildren(true); entry.insert(pdata); } - else if (pdata->rootItem && parent == nullptr) { + else if (pdata->rootItem && !parent) { Base::Console().Warning("DocumentItem::slotNewObject: Cannot add view provider twice.\n"); return false; } diff --git a/src/Gui/View3DInventorExamples.cpp b/src/Gui/View3DInventorExamples.cpp index efb48ef4bd..df8b4904a7 100644 --- a/src/Gui/View3DInventorExamples.cpp +++ b/src/Gui/View3DInventorExamples.cpp @@ -276,7 +276,7 @@ void LightManip(SoSeparator * root) SoInput in; in.setBuffer((void *)scenegraph, std::strlen(scenegraph)); SoSeparator * _root = SoDB::readAll( &in ); - if ( _root == nullptr ) // Shouldn't happen. + if (!_root) // Shouldn't happen. return; root->addChild(_root); root->ref(); @@ -290,7 +290,7 @@ void LightManip(SoSeparator * root) sa.setSearchingAll( false ); sa.apply( root ); SoPath * path = sa.getPath(); - if ( path == nullptr) // Shouldn't happen. + if (!path) // Shouldn't happen. return; SoPointLightManip * manip = new SoPointLightManip; @@ -396,7 +396,7 @@ timersensorcallback(void * data, SoSensor *) void AnimationTexture(SoSeparator * root) { // Scene graph - if ( root == nullptr ) // Shouldn't happen. + if (!root) // Shouldn't happen. return; // Generate a julia set to use as a texturemap diff --git a/src/Gui/View3DInventorViewer.cpp b/src/Gui/View3DInventorViewer.cpp index e034b39c9d..8af18590b4 100644 --- a/src/Gui/View3DInventorViewer.cpp +++ b/src/Gui/View3DInventorViewer.cpp @@ -2772,7 +2772,7 @@ void View3DInventorViewer::setCameraType(SoType t) // close camera but we don't have this other ugly effect. SoCamera* cam = this->getSoRenderManager()->getCamera(); - if(cam == nullptr) + if(!cam) return; static_cast(cam)->heightAngle = (float)(M_PI / 4.0); @@ -2814,7 +2814,7 @@ namespace Gui { void View3DInventorViewer::moveCameraTo(const SbRotation& rot, const SbVec3f& pos, int steps, int ms) { SoCamera* cam = this->getSoRenderManager()->getCamera(); - if (cam == nullptr) + if (!cam) return; CameraAnimation anim(cam, rot, pos); diff --git a/src/Gui/ViewProviderMeasureDistance.cpp b/src/Gui/ViewProviderMeasureDistance.cpp index 8a25195df4..3871767958 100644 --- a/src/Gui/ViewProviderMeasureDistance.cpp +++ b/src/Gui/ViewProviderMeasureDistance.cpp @@ -337,7 +337,7 @@ void ViewProviderMeasureDistance::measureDistanceCallback(void * ud, SoEventCall if (mbe->getButton() == SoMouseButtonEvent::BUTTON1 && mbe->getState() == SoButtonEvent::DOWN) { const SoPickedPoint * point = n->getPickedPoint(); - if (point == nullptr) { + if (!point) { Base::Console().Message("No point picked.\n"); return; } diff --git a/src/Gui/WorkbenchManager.cpp b/src/Gui/WorkbenchManager.cpp index 5de48db826..6830f7275b 100644 --- a/src/Gui/WorkbenchManager.cpp +++ b/src/Gui/WorkbenchManager.cpp @@ -37,7 +37,7 @@ WorkbenchManager* WorkbenchManager::_instance = nullptr; WorkbenchManager* WorkbenchManager::instance() { - if (_instance == nullptr) + if (!_instance) _instance = new WorkbenchManager; return _instance; } diff --git a/src/Gui/propertyeditor/PropertyItem.cpp b/src/Gui/propertyeditor/PropertyItem.cpp index 31eecf44a8..86c6ce9ccb 100644 --- a/src/Gui/propertyeditor/PropertyItem.cpp +++ b/src/Gui/propertyeditor/PropertyItem.cpp @@ -69,7 +69,7 @@ Gui::PropertyEditor::PropertyItemFactory* Gui::PropertyEditor::PropertyItemFacto PropertyItemFactory& PropertyItemFactory::instance() { - if (_singleton == nullptr) + if (!_singleton) _singleton = new PropertyItemFactory; return *_singleton; }