add method to remove elements from PropertyLinkSubList

This commit is contained in:
wmayer
2017-09-13 12:19:09 +02:00
parent 9354a28659
commit f52b54e4f3
2 changed files with 33 additions and 3 deletions

View File

@@ -719,7 +719,7 @@ void PropertyLinkSubList::setValue(DocumentObject* lValue, const std::vector<str
hasSetValue();
}
const string PropertyLinkSubList::getPyReprString()
const string PropertyLinkSubList::getPyReprString() const
{
assert(this->_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<DocumentObject*> links;
std::vector<std::string> subs;
links.reserve(this->_lValueList.size() - num);
subs.reserve(this->_lSubList.size() - num);
for (std::size_t i=0; i<this->_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<int>(num);
}
void PropertyLinkSubList::setSubListValues(const std::vector<PropertyLinkSubList::SubSet>& values)
{
std::vector<DocumentObject*> links;