add method to remove elements from PropertyLinkSubList
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user