From eb18c2f9db7767138e2a13efa5ee717b55f2e56a Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 23 Sep 2021 11:00:50 +0200 Subject: [PATCH] Gui: modernize some classes --- src/Gui/PythonWrapper.cpp | 8 +++---- src/Gui/PythonWrapper.h | 4 ++-- src/Gui/UiLoader.cpp | 4 ++-- src/Gui/UiLoader.h | 6 ++--- src/Gui/WidgetFactory.cpp | 46 +++++++++++++++++++-------------------- src/Gui/WidgetFactory.h | 8 +++---- 6 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/Gui/PythonWrapper.cpp b/src/Gui/PythonWrapper.cpp index cb4e9ba0aa..d210f8c753 100644 --- a/src/Gui/PythonWrapper.cpp +++ b/src/Gui/PythonWrapper.cpp @@ -154,7 +154,7 @@ PythonToCppFunc toCppPointerCheckFuncQuantity(PyObject* obj) if (PyObject_TypeCheck(obj, &(Base::QuantityPy::Type))) return toCppPointerConvFuncQuantity; else - return 0; + return nullptr; } void BaseQuantity_PythonToCpp_QVariant(PyObject* pyIn, void* cppOut) @@ -167,7 +167,7 @@ PythonToCppFunc isBaseQuantity_PythonToCpp_QVariantConvertible(PyObject* obj) { if (PyObject_TypeCheck(obj, &(Base::QuantityPy::Type))) return BaseQuantity_PythonToCpp_QVariant; - return 0; + return nullptr; } #if defined (HAVE_PYSIDE) @@ -360,7 +360,7 @@ QObject* PythonWrapper::toQObject(const Py::Object& pyobject) return reinterpret_cast(ptr); #endif - return 0; + return nullptr; } QGraphicsItem* PythonWrapper::toQGraphicsItem(PyObject* pyPtr) @@ -413,7 +413,7 @@ QIcon *PythonWrapper::toQIcon(PyObject *pyobj) #else Q_UNUSED(pyobj); #endif - return 0; + return nullptr; } Py::Object PythonWrapper::fromQDir(const QDir& dir) diff --git a/src/Gui/PythonWrapper.h b/src/Gui/PythonWrapper.h index 7b5a8929ab..d12e81df15 100644 --- a/src/Gui/PythonWrapper.h +++ b/src/Gui/PythonWrapper.h @@ -48,8 +48,8 @@ public: bool toCString(const Py::Object&, std::string&); QObject* toQObject(const Py::Object&); QGraphicsItem* toQGraphicsItem(PyObject* ptr); - Py::Object fromQObject(QObject*, const char* className=0); - Py::Object fromQWidget(QWidget*, const char* className=0); + Py::Object fromQObject(QObject*, const char* className=nullptr); + Py::Object fromQWidget(QWidget*, const char* className=nullptr); const char* getWrapperName(QObject*) const; /*! Create a Python wrapper for the icon. The icon must be created on the heap diff --git a/src/Gui/UiLoader.cpp b/src/Gui/UiLoader.cpp index d41f6058db..54a6accfe8 100644 --- a/src/Gui/UiLoader.cpp +++ b/src/Gui/UiLoader.cpp @@ -60,7 +60,7 @@ Py::Object wrapFromWidgetFactory(const Py::Tuple& args, const std::function 1) { QObject* object = wrap.toQObject(args[1]); if (object) @@ -537,7 +537,7 @@ QWidget* UiLoader::createWidget(const QString & className, QWidget * parent, PyObject *UiLoaderPy::PyMake(struct _typeobject * /*type*/, PyObject * args, PyObject * /*kwds*/) { if (!PyArg_ParseTuple(args, "")) - return 0; + return nullptr; return new UiLoaderPy(); } diff --git a/src/Gui/UiLoader.h b/src/Gui/UiLoader.h index 3ba1f6b85d..8fea2e0048 100644 --- a/src/Gui/UiLoader.h +++ b/src/Gui/UiLoader.h @@ -106,14 +106,14 @@ private: class UiLoader : public QUiLoader { public: - UiLoader(QObject* parent=0); + UiLoader(QObject* parent=nullptr); virtual ~UiLoader(); /** * Creates a widget of the type \a className with the parent \a parent. * For more details see the documentation to QWidgetFactory. */ - QWidget* createWidget(const QString & className, QWidget * parent=0, + QWidget* createWidget(const QString & className, QWidget * parent=nullptr, const QString& name = QString()); private: @@ -125,7 +125,7 @@ private: class UiLoaderPy : public Py::PythonExtension { public: - static void init_type(void); // announce properties and methods + static void init_type(); // announce properties and methods UiLoaderPy(); ~UiLoaderPy(); diff --git a/src/Gui/WidgetFactory.cpp b/src/Gui/WidgetFactory.cpp index 70c30fdc3e..2ba90ac294 100644 --- a/src/Gui/WidgetFactory.cpp +++ b/src/Gui/WidgetFactory.cpp @@ -52,26 +52,26 @@ using namespace Gui; -Gui::WidgetFactoryInst* Gui::WidgetFactoryInst::_pcSingleton = NULL; +Gui::WidgetFactoryInst* Gui::WidgetFactoryInst::_pcSingleton = nullptr; WidgetFactoryInst& WidgetFactoryInst::instance() { - if (_pcSingleton == 0L) + if (_pcSingleton == nullptr) _pcSingleton = new WidgetFactoryInst; return *_pcSingleton; } void WidgetFactoryInst::destruct () { - if (_pcSingleton != 0) + if (_pcSingleton != nullptr) delete _pcSingleton; - _pcSingleton = 0; + _pcSingleton = nullptr; } /** * Creates a widget with the name \a sName which is a child of \a parent. * To create an instance of this widget once it must has been registered. - * If there is no appropriate widget registered 0 is returned. + * If there is no appropriate widget registered nullptr is returned. */ QWidget* WidgetFactoryInst::createWidget (const char* sName, QWidget* parent) const { @@ -84,7 +84,7 @@ QWidget* WidgetFactoryInst::createWidget (const char* sName, QWidget* parent) co #else Base::Console().Log("\"%s\" is not registered\n", sName); #endif - return 0; + return nullptr; } try { @@ -100,7 +100,7 @@ QWidget* WidgetFactoryInst::createWidget (const char* sName, QWidget* parent) co Base::Console().Log("%s does not inherit from \"QWidget\"\n", sName); #endif delete w; - return 0; + return nullptr; } // set the parent to the widget @@ -113,7 +113,7 @@ QWidget* WidgetFactoryInst::createWidget (const char* sName, QWidget* parent) co /** * Creates a widget with the name \a sName which is a child of \a parent. * To create an instance of this widget once it must has been registered. - * If there is no appropriate widget registered 0 is returned. + * If there is no appropriate widget registered nullptr is returned. */ Gui::Dialog::PreferencePage* WidgetFactoryInst::createPreferencePage (const char* sName, QWidget* parent) const { @@ -126,7 +126,7 @@ Gui::Dialog::PreferencePage* WidgetFactoryInst::createPreferencePage (const char #else Base::Console().Log("Cannot create an instance of \"%s\"\n", sName); #endif - return 0; + return nullptr; } if (qobject_cast(w)) { @@ -139,7 +139,7 @@ Gui::Dialog::PreferencePage* WidgetFactoryInst::createPreferencePage (const char Base::Console().Error("%s does not inherit from 'Gui::Dialog::PreferencePage'\n", sName); #endif delete w; - return 0; + return nullptr; } // set the parent to the widget @@ -153,7 +153,7 @@ Gui::Dialog::PreferencePage* WidgetFactoryInst::createPreferencePage (const char * Creates a preference widget with the name \a sName and the preference name \a sPref * which is a child of \a parent. * To create an instance of this widget once it must has been registered. - * If there is no appropriate widget registered 0 is returned. + * If there is no appropriate widget registered nullptr is returned. * After creation of this widget its recent preferences are restored automatically. */ QWidget* WidgetFactoryInst::createPrefWidget(const char* sName, QWidget* parent, const char* sPref) @@ -161,7 +161,7 @@ QWidget* WidgetFactoryInst::createPrefWidget(const char* sName, QWidget* parent, QWidget* w = createWidget(sName); // this widget class is not registered if (!w) - return 0; // no valid QWidget object + return nullptr; // no valid QWidget object // set the parent to the widget w->setParent(parent); @@ -178,7 +178,7 @@ QWidget* WidgetFactoryInst::createPrefWidget(const char* sName, QWidget* parent, Base::Console().Error("%s does not inherit from \"PrefWidget\"\n", w->metaObject()->className()); #endif delete w; - return 0; + return nullptr; } return w; @@ -186,7 +186,7 @@ QWidget* WidgetFactoryInst::createPrefWidget(const char* sName, QWidget* parent, // ---------------------------------------------------- -WidgetFactorySupplier* WidgetFactorySupplier::_pcSingleton = 0L; +WidgetFactorySupplier* WidgetFactorySupplier::_pcSingleton = nullptr; WidgetFactorySupplier & WidgetFactorySupplier::instance() { @@ -201,7 +201,7 @@ void WidgetFactorySupplier::destruct() // delete the widget factory and all its producers first WidgetFactoryInst::destruct(); delete _pcSingleton; - _pcSingleton=0; + _pcSingleton=nullptr; } // ---------------------------------------------------- @@ -254,13 +254,13 @@ void* PrefPagePyProducer::Produce () const QWidget* widget = new Gui::Dialog::PreferencePagePython(page); if (!widget->layout()) { delete widget; - widget = 0; + widget = nullptr; } return widget; } catch (Py::Exception&) { PyErr_Print(); - return 0; + return nullptr; } } @@ -405,7 +405,7 @@ void PyResource::init_type() add_varargs_method("connect",&PyResource::connect); } -PyResource::PyResource() : myDlg(0) +PyResource::PyResource() : myDlg(nullptr) { } @@ -462,7 +462,7 @@ void PyResource::load(const char* name) } } - QWidget* w=0; + QWidget* w=nullptr; try { UiLoader loader; loader.setLanguageChangeEnabled(true); @@ -497,7 +497,7 @@ bool PyResource::connect(const char* sender, const char* signal, PyObject* cb) if ( !myDlg ) return false; - QObject* objS=0L; + QObject* objS=nullptr; QList list = myDlg->findChildren(); QList::const_iterator it = list.begin(); QObject *obj; @@ -534,7 +534,7 @@ Py::Object PyResource::repr() /** * Searches for a widget and its value in the argument object \a args * to returns its value as Python object. - * In the case it fails 0 is returned. + * In the case it fails nullptr is returned. */ Py::Object PyResource::value(const Py::Tuple& args) { @@ -605,7 +605,7 @@ Py::Object PyResource::value(const Py::Tuple& args) /** * Searches for a widget, its value name and the new value in the argument object \a args * to set even this new value. - * In the case it fails 0 is returned. + * In the case it fails nullptr is returned. */ Py::Object PyResource::setValue(const Py::Tuple& args) { @@ -693,7 +693,7 @@ Py::Object PyResource::show(const Py::Tuple&) /** * Searches for the sender, the signal and the callback function to connect with - * in the argument object \a args. In the case it fails 0 is returned. + * in the argument object \a args. In the case it fails nullptr is returned. */ Py::Object PyResource::connect(const Py::Tuple& args) { diff --git a/src/Gui/WidgetFactory.h b/src/Gui/WidgetFactory.h index db59c16535..929483783c 100644 --- a/src/Gui/WidgetFactory.h +++ b/src/Gui/WidgetFactory.h @@ -55,8 +55,8 @@ public: static WidgetFactoryInst& instance(); static void destruct (); - QWidget* createWidget (const char* sName, QWidget* parent=0) const; - Gui::Dialog::PreferencePage* createPreferencePage (const char* sName, QWidget* parent=0) const; + QWidget* createWidget (const char* sName, QWidget* parent=nullptr) const; + Gui::Dialog::PreferencePage* createPreferencePage (const char* sName, QWidget* parent=nullptr) const; QWidget* createPrefWidget(const char* sName, QWidget* parent, const char* sPref); private: @@ -330,7 +330,7 @@ private: class PyResource : public Py::PythonExtension { public: - static void init_type(void); // announce properties and methods + static void init_type(); // announce properties and methods PyResource(); ~PyResource(); @@ -383,7 +383,7 @@ class GuiExport PreferencePagePython : public PreferencePage Q_OBJECT public: - PreferencePagePython(const Py::Object& dlg, QWidget* parent = 0); + PreferencePagePython(const Py::Object& dlg, QWidget* parent = nullptr); virtual ~PreferencePagePython(); void loadSettings();