dlr-gtlab / gtlab-core

GTlab Core Framework
https://www.gtlab.de
Other
7 stars 2 forks source link

Add an overload to GtCoreDataModel::deleteFromModel that accepts lists of derived GtObjects #514

Open rainman110 opened 1 year ago

rainman110 commented 1 year ago

In GitLab by @mariusalexander on Apr 5, 2023, 09:45

Say I want to delete all children with type MyFancyObject. (MyFancyObject is a derived class of GtObject)

To archive this I have to use the following code snippet:

auto childs= findDirectChildren<MyFancyObject*>();

GtObjectList objects;
std::copy(std::cbegin(childs), std::cend(childs), std::back_inserter(objects));

gtDataModel->deleteFromModel(objects);

I have to cast the child objects into a QList<GtObject*>. IMO this should not be necessary, as the class MyFancyObject is already a subclass of GtObject. Idealy there should be a templated method that accepts any subclass of GtObject*. Furthermore it should not matter if the list is a QList, QVector or std::vector etc. It should use iterators.

rainman110 commented 1 year ago

In GitLab by @mariusalexander on Apr 5, 2023, 12:54

The same would be useful for appendChildren