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;

View File

@@ -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<SubSet>&);
std::vector<SubSet> getSubListValues() const;