App: extend Document::findObject to allow to search by label

This commit is contained in:
wmayer
2020-06-27 15:58:23 +02:00
parent 1f741aa511
commit 79e11ce8a1
4 changed files with 40 additions and 27 deletions
+20 -4
View File
@@ -4546,15 +4546,31 @@ std::vector< DocumentObject* > Document::getObjectsWithExtension(const Base::Typ
}
std::vector<DocumentObject*> Document::findObjects(const Base::Type& typeId, const char* objname) const
std::vector<DocumentObject*> Document::findObjects(const Base::Type& typeId, const char* objname, const char* label) const
{
boost::regex rx(objname);
boost::cmatch what;
boost::regex rx_name, rx_label;
if (objname)
rx_name.set_expression(objname);
if (label)
rx_label.set_expression(label);
std::vector<DocumentObject*> Objects;
DocumentObject* found = nullptr;
for (std::vector<DocumentObject*>::const_iterator it = d->objectArray.begin(); it != d->objectArray.end(); ++it) {
if ((*it)->getTypeId().isDerivedFrom(typeId)) {
if (boost::regex_match((*it)->getNameInDocument(), what, rx))
Objects.push_back(*it);
found = *it;
if (!rx_name.empty() && !boost::regex_search((*it)->getNameInDocument(), what, rx_name))
found = nullptr;
if (!rx_label.empty() && !boost::regex_search((*it)->Label.getValue(), what, rx_label))
found = nullptr;
if (found)
Objects.push_back(found);
}
}
return Objects;