[Gui] remove more superfluous nullptr checks

This commit is contained in:
Uwe
2022-07-18 03:34:22 +02:00
parent bd6ffcc7e0
commit 1d95c26e2e
23 changed files with 45 additions and 52 deletions

View File

@@ -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;

View File

@@ -91,7 +91,7 @@ BitmapFactoryInst* BitmapFactoryInst::_pcSingleton = nullptr;
BitmapFactoryInst& BitmapFactoryInst::instance(void)
{
if (_pcSingleton == nullptr)
if (!_pcSingleton)
{
_pcSingleton = new BitmapFactoryInst;
std::map<std::string,std::string>::const_iterator it;

View File

@@ -256,7 +256,7 @@ bool ControlSingleton::isAllowedAlterSelection(void) const
ControlSingleton& ControlSingleton::instance(void)
{
if (_pcSingleton == nullptr)
if (!_pcSingleton)
_pcSingleton = new ControlSingleton;
return *_pcSingleton;
}

View File

@@ -102,7 +102,7 @@ DockWindowManager* DockWindowManager::_instance = nullptr;
DockWindowManager* DockWindowManager::instance()
{
if ( _instance == nullptr )
if (!_instance)
_instance = new DockWindowManager;
return _instance;
}

View File

@@ -422,7 +422,7 @@ void DocumentObserver::attachDocument(Document* doc)
{
detachDocument();
if (doc == nullptr)
if (!doc)
return;
this->connectDocumentCreatedObject = doc->signalNewObject.connect(std::bind

View File

@@ -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());

View File

@@ -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.

View File

@@ -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<QtGLWidget*>(m_View3DInventorViewer->viewport());
if (gl == nullptr)
if (!gl)
return;
initNaviCube(gl);
m_NaviCubeInitialised = true;

View File

@@ -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.

View File

@@ -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

View File

@@ -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);

View File

@@ -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

View File

@@ -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();

View File

@@ -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 <QuarterWidgetP_cachecontext*>;
}

View File

@@ -1818,7 +1818,7 @@ SelectionSingleton* SelectionSingleton::_pcSingleton = nullptr;
SelectionSingleton& SelectionSingleton::instance(void)
{
if (_pcSingleton == nullptr)
if (!_pcSingleton)
_pcSingleton = new SelectionSingleton;
return *_pcSingleton;
}

View File

@@ -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());

View File

@@ -1203,7 +1203,7 @@ std::pair<bool,SoFCSelectionContextBasePtr*> 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());

View File

@@ -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;
}

View File

@@ -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

View File

@@ -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<SoPerspectiveCamera*>(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);

View File

@@ -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;
}

View File

@@ -37,7 +37,7 @@ WorkbenchManager* WorkbenchManager::_instance = nullptr;
WorkbenchManager* WorkbenchManager::instance()
{
if (_instance == nullptr)
if (!_instance)
_instance = new WorkbenchManager;
return _instance;
}

View File

@@ -69,7 +69,7 @@ Gui::PropertyEditor::PropertyItemFactory* Gui::PropertyEditor::PropertyItemFacto
PropertyItemFactory& PropertyItemFactory::instance()
{
if (_singleton == nullptr)
if (!_singleton)
_singleton = new PropertyItemFactory;
return *_singleton;
}