From f52b54e4f33fa8aadcae94023fc708f3cd4be3f8 Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 13 Sep 2017 12:19:09 +0200 Subject: [PATCH] add method to remove elements from PropertyLinkSubList --- src/App/PropertyLinks.cpp | 26 +++++++++++++++++++++++++- src/App/PropertyLinks.h | 10 ++++++++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index 30ddd6838c..9fdcaca62a 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -719,7 +719,7 @@ void PropertyLinkSubList::setValue(DocumentObject* lValue, const std::vector_lValueList.size() == this->_lSubList.size()); @@ -760,6 +760,30 @@ DocumentObject *PropertyLinkSubList::getValue() const return ret; } +int PropertyLinkSubList::removeValue(App::DocumentObject *lValue) +{ + assert(this->_lValueList.size() == this->_lSubList.size()); + + std::size_t num = std::count(this->_lValueList.begin(), this->_lValueList.end(), lValue); + if (num == 0) + return 0; + + std::vector links; + std::vector subs; + links.reserve(this->_lValueList.size() - num); + subs.reserve(this->_lSubList.size() - num); + + for (std::size_t i=0; i_lValueList.size(); ++i) { + if (this->_lValueList[i] != lValue) { + links.push_back(this->_lValueList[i]); + subs.push_back(this->_lSubList[i]); + } + } + + setValues(links, subs); + return static_cast(num); +} + void PropertyLinkSubList::setSubListValues(const std::vector& values) { std::vector links; diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 37e2202f06..dc7d62c0cf 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -362,11 +362,11 @@ public: return _lValueList; } - const std::string getPyReprString(); + const std::string getPyReprString() const; /** * @brief getValue emulates the action of a single-object link. - * @return reference to object, if the link os to only one object. NULL if + * @return reference to object, if the link is to only one object. NULL if * the link is empty, or links to subelements of more than one documant * object. */ @@ -376,6 +376,12 @@ public: return _lSubList; } + /** + * @brief Removes all occurrences of \a lValue in the property + * together with its sub-elements and returns the number of entries removed. + */ + int removeValue(App::DocumentObject *lValue); + void setSubListValues(const std::vector&); std::vector getSubListValues() const;