modernize C++: avoid bind

In many cases std::bind() is kept because the code is much simpler
This commit is contained in:
wmayer
2023-08-08 19:10:49 +02:00
committed by wwmayer
parent c765d64891
commit 948cbfccd9
80 changed files with 240 additions and 30 deletions

View File

@@ -477,6 +477,7 @@ Document* Application::newDocument(const char * Name, const char * UserName, boo
DocMap[name] = doc;
_pActiveDoc = doc;
//NOLINTBEGIN
// connect the signals to the application for the new document
_pActiveDoc->signalBeforeChange.connect(std::bind(&App::Application::slotBeforeChangeDocument, this, sp::_1, sp::_2));
_pActiveDoc->signalChanged.connect(std::bind(&App::Application::slotChangedDocument, this, sp::_1, sp::_2));
@@ -497,6 +498,7 @@ Document* Application::newDocument(const char * Name, const char * UserName, boo
_pActiveDoc->signalStartSave.connect(std::bind(&App::Application::slotStartSaveDocument, this, sp::_1, sp::_2));
_pActiveDoc->signalFinishSave.connect(std::bind(&App::Application::slotFinishSaveDocument, this, sp::_1, sp::_2));
_pActiveDoc->signalChangePropertyEditor.connect(std::bind(&App::Application::slotChangePropertyEditor, this, sp::_1, sp::_2));
//NOLINTEND
// make sure that the active document is set in case no GUI is up
{

View File

@@ -546,8 +546,10 @@ class DocumentWeakPtrT::Private {
public:
explicit Private(App::Document* doc) : _document(doc) {
if (doc) {
//NOLINTBEGIN
connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(std::bind
(&Private::deletedDocument, this, sp::_1));
//NOLINTEND
}
}
@@ -626,6 +628,7 @@ public:
void set(App::DocumentObject* obj) {
object = obj;
if (obj) {
//NOLINTBEGIN
indocument = true;
connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(std::bind
(&Private::deletedDocument, this, sp::_1));
@@ -634,6 +637,7 @@ public:
(&Private::createdObject, this, sp::_1));
connectDocumentDeletedObject = doc->signalDeletedObject.connect(std::bind
(&Private::deletedObject, this, sp::_1));
//NOLINTEND
}
}
App::DocumentObject* get() const noexcept {
@@ -701,12 +705,14 @@ bool DocumentObjectWeakPtrT::operator!= (const DocumentObjectWeakPtrT& p) const
DocumentObserver::DocumentObserver() : _document(nullptr)
{
//NOLINTBEGIN
this->connectApplicationCreatedDocument = App::GetApplication().signalNewDocument.connect(std::bind
(&DocumentObserver::slotCreatedDocument, this, sp::_1));
this->connectApplicationDeletedDocument = App::GetApplication().signalDeleteDocument.connect(std::bind
(&DocumentObserver::slotDeletedDocument, this, sp::_1));
this->connectApplicationActivateDocument = App::GetApplication().signalActiveDocument.connect(std::bind
(&DocumentObserver::slotActivateDocument, this, sp::_1));
//NOLINTEND
}
DocumentObserver::DocumentObserver(Document* doc) : DocumentObserver()
@@ -735,6 +741,7 @@ void DocumentObserver::attachDocument(Document* doc)
detachDocument();
_document = doc;
//NOLINTBEGIN
this->connectDocumentCreatedObject = _document->signalNewObject.connect(std::bind
(&DocumentObserver::slotCreatedObject, this, sp::_1));
this->connectDocumentDeletedObject = _document->signalDeletedObject.connect(std::bind
@@ -745,6 +752,7 @@ void DocumentObserver::attachDocument(Document* doc)
(&DocumentObserver::slotRecomputedObject, this, sp::_1));
this->connectDocumentRecomputed = _document->signalRecomputed.connect(std::bind
(&DocumentObserver::slotRecomputedDocument, this, sp::_1));
//NOLINTEND
}
}

View File

@@ -78,6 +78,7 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj
}\
while(0);
//NOLINTBEGIN
#define FC_PY_ELEMENT_ARG2(_name1, _name2) do {\
FC_PY_GetCallable(obj.ptr(), "slot" #_name1, py##_name1.py);\
if (!py##_name1.py.isNone())\
@@ -115,6 +116,7 @@ DocumentObserverPython::DocumentObserverPython(const Py::Object& obj) : inst(obj
FC_PY_ELEMENT_ARG2(ChangePropertyEditor, ChangePropertyEditor)
FC_PY_ELEMENT_ARG2(BeforeAddingDynamicExtension, BeforeAddingDynamicExtension)
FC_PY_ELEMENT_ARG2(AddedDynamicExtension, AddedDynamicExtension)
//NOLINTEND
}
DocumentObserverPython::~DocumentObserverPython() = default;

View File

@@ -352,8 +352,10 @@ void GroupExtension::extensionOnChanged(const Property* p) {
_Conns.clear();
for(auto obj : Group.getValue()) {
if(obj && obj->getNameInDocument()) {
//NOLINTBEGIN
_Conns[obj] = obj->signalChanged.connect(std::bind(
&GroupExtension::slotChildChanged,this,sp::_1, sp::_2));
//NOLINTEND
}
}
}

View File

@@ -1539,8 +1539,10 @@ void LinkBaseExtension::updateGroup() {
if(!conn.connected()) {
FC_LOG("new group connection " << getExtendedObject()->getFullName()
<< " -> " << group->getFullName());
//NOLINTBEGIN
conn = group->signalChanged.connect(
std::bind(&LinkBaseExtension::slotChangedPlainGroup,this,sp::_1,sp::_2));
//NOLINTEND
}
std::size_t count = children.size();
ext->getAllChildren(children,childSet);
@@ -1553,8 +1555,10 @@ void LinkBaseExtension::updateGroup() {
if(!conn.connected()) {
FC_LOG("new group connection " << getExtendedObject()->getFullName()
<< " -> " << child->getFullName());
//NOLINTBEGIN
conn = child->signalChanged.connect(
std::bind(&LinkBaseExtension::slotChangedPlainGroup,this,sp::_1,sp::_2));
//NOLINTEND
}
}
}

View File

@@ -73,10 +73,12 @@ private:
MergeDocuments::MergeDocuments(App::Document* doc) : guiup(false), verbose(true), stream(nullptr), appdoc(doc)
{
//NOLINTBEGIN
connectExport = doc->signalExportObjects.connect
(std::bind(&MergeDocuments::exportObject, this, sp::_1, sp::_2));
connectImport = doc->signalImportObjects.connect
(std::bind(&MergeDocuments::importObject, this, sp::_1, sp::_2));
//NOLINTEND
QCoreApplication* app = QCoreApplication::instance();
if (app && app->inherits("QApplication")) {

View File

@@ -181,12 +181,16 @@ void PropertyExpressionEngine::hasSetValue()
std::string key = objName + propName;
auto &propDeps = pimpl->propMap[key];
if(propDeps.empty()) {
if(!propName.empty())
//NOLINTBEGIN
if(!propName.empty()) {
pimpl->conns.emplace_back(obj->signalChanged.connect(std::bind(
&PropertyExpressionEngine::slotChangedProperty,this,sp::_1,sp::_2)));
else
}
else {
pimpl->conns.emplace_back(obj->signalChanged.connect(std::bind(
&PropertyExpressionEngine::slotChangedObject,this,sp::_1,sp::_2)));
}
//NOLINTEND
}
propDeps.push_back(e.first);
}

View File

@@ -2661,6 +2661,7 @@ public:
myPos = pos;
myPath = myPos->first.toUtf8().constData();
App::Application &app = App::GetApplication();
//NOLINTBEGIN
connFinishRestoreDocument = app.signalFinishRestoreDocument.connect(
std::bind(&DocInfo::slotFinishRestoreDocument,this,sp::_1));
connPendingReloadDocument = app.signalPendingReloadDocument.connect(
@@ -2669,6 +2670,7 @@ public:
std::bind(&DocInfo::slotDeleteDocument,this,sp::_1));
connSaveDocument = app.signalSaveDocument.connect(
std::bind(&DocInfo::slotSaveDocument,this,sp::_1));
//NOLINTEND
QString fullpath(getFullPath());
if(fullpath.isEmpty())