Part: modernize C++: return braced init list

This commit is contained in:
wmayer
2023-08-19 11:01:36 +02:00
parent e98891859e
commit 0d854a56cd
56 changed files with 128 additions and 128 deletions

View File

@@ -35,7 +35,7 @@ using namespace PartDesign;
// returns a string which represents the object e.g. when printed in python
std::string BodyPy::representation() const
{
return std::string("<body object>");
return {"<body object>"};
}

View File

@@ -77,7 +77,7 @@ TopoDS_Shape Feature::getSolid(const TopoDS_Shape& shape)
return xp.Current();
}
return TopoDS_Shape();
return {};
}
int Feature::countSolids(const TopoDS_Shape& shape, TopAbs_ShapeEnum type)

View File

@@ -1647,7 +1647,7 @@ void Hole::updateProps()
static gp_Pnt toPnt(gp_Vec dir)
{
return gp_Pnt(dir.X(), dir.Y(), dir.Z());
return {dir.X(), dir.Y(), dir.Z()};
}
App::DocumentObjectExecReturn* Hole::execute()

View File

@@ -340,16 +340,19 @@ bool getReferencedSelection(const App::DocumentObject* thisObj, const Gui::Selec
QString getRefStr(const App::DocumentObject* obj, const std::vector<std::string>& sub)
{
if (!obj)
return QString::fromLatin1("");
if (!obj) {
return {};
}
if (PartDesign::Feature::isDatum(obj))
if (PartDesign::Feature::isDatum(obj)) {
return QString::fromLatin1(obj->getNameInDocument());
else if (!sub.empty())
}
else if (!sub.empty()) {
return QString::fromLatin1(obj->getNameInDocument()) + QString::fromLatin1(":") +
QString::fromLatin1(sub.front().c_str());
else
return QString();
}
return {};
}
std::string buildLinkSubPythonStr(const App::DocumentObject* obj, const std::vector<std::string>& subs)

View File

@@ -135,7 +135,7 @@ void TaskSketchBasedParameters::exitSelectionMode()
QVariant TaskSketchBasedParameters::setUpToFace(const QString& text)
{
if (text.isEmpty())
return QVariant();
return {};
QStringList parts = text.split(QChar::fromLatin1(':'));
if (parts.length() < 2)
@@ -144,15 +144,15 @@ QVariant TaskSketchBasedParameters::setUpToFace(const QString& text)
// Check whether this is the name of an App::Plane or Part::Datum feature
App::DocumentObject* obj = vp->getObject()->getDocument()->getObject(parts[0].toLatin1());
if (!obj)
return QVariant();
return {};
if (obj->getTypeId().isDerivedFrom(App::Plane::getClassTypeId())) {
// everything is OK (we assume a Part can only have exactly 3 App::Plane objects located at the base of the feature tree)
return QVariant();
return {};
}
else if (obj->getTypeId().isDerivedFrom(Part::Datum::getClassTypeId())) {
// it's up to the document to check that the datum plane is in the same body
return QVariant();
return {};
}
else {
// We must expect that "parts[1]" is the translation of "Face" followed by an ID.
@@ -162,7 +162,7 @@ QVariant TaskSketchBasedParameters::setUpToFace(const QString& text)
QRegularExpression rx(name);
QRegularExpressionMatch match;
if (parts[1].indexOf(rx, 0, &match) < 0) {
return QVariant();
return {};
}
int faceId = match.captured(1).toInt();
@@ -200,7 +200,7 @@ QVariant TaskSketchBasedParameters::objectNameByLabel(const QString& label,
}
}
return QVariant(); // no such feature found
return {}; // no such feature found
}
QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QString& sub) const
@@ -209,7 +209,7 @@ QString TaskSketchBasedParameters::getFaceReference(const QString& obj, const QS
QString o = obj.left(obj.indexOf(QString::fromLatin1(":")));
if (o.isEmpty())
return QString();
return {};
return QString::fromLatin1(R"((App.getDocument("%1").%2, ["%3"]))")
.arg(QString::fromLatin1(doc->getName()), o, sub);
@@ -223,7 +223,7 @@ QString TaskSketchBasedParameters::make2DLabel(const App::DocumentObject* sectio
}
else if (subValues.empty()) {
Base::Console().Error("No valid subelement linked in %s\n", section->Label.getValue());
return QString();
return {};
}
else {
return QString::fromStdString((std::string(section->getNameInDocument()) + ":" + subValues[0]));

View File

@@ -190,7 +190,7 @@ std::string ViewProviderDatum::getElement(const SoDetail* detail) const
return datumType.toStdString();
}
return std::string("");
return {};
}
SoDetail* ViewProviderDatum::getDetail(const char* subelement) const

View File

@@ -248,7 +248,7 @@ std::string ViewProviderDatumCoordinateSystem::getElement(const SoDetail* detail
}
}
return std::string();
return {};
}
SoDetail* ViewProviderDatumCoordinateSystem::getDetail(const char* subelement) const

View File

@@ -53,7 +53,7 @@ std::vector<App::DocumentObject*> ViewProviderMultiTransform::claimChildren() co
{
PartDesign::MultiTransform* pcMultiTransform = static_cast<PartDesign::MultiTransform*>(getObject());
if (!pcMultiTransform)
return std::vector<App::DocumentObject*>(); // TODO: Show error?
return {}; // TODO: Show error?
std::vector<App::DocumentObject*> transformFeatures = pcMultiTransform->Transformations.getValues();
return transformFeatures;

View File

@@ -34,7 +34,7 @@ using namespace PartDesignGui;
// returns a string which represent the object e.g. when printed in python
std::string ViewProviderPy::representation() const
{
return std::string("<PartDesign::ViewProvider>");
return {"<PartDesign::ViewProvider>"};
}
PyObject *ViewProviderPy::getCustomAttributes(const char* ) const

View File

@@ -272,7 +272,7 @@ std::string ViewProviderSubShapeBinder::dropObjectEx(App::DocumentObject* obj, A
{
auto self = dynamic_cast<PartDesign::SubShapeBinder*>(getObject());
if (!self)
return std::string();
return {};
std::map<App::DocumentObject*, std::vector<std::string> > values;
if (!subname) subname = "";
std::string sub(subname);
@@ -293,7 +293,7 @@ std::string ViewProviderSubShapeBinder::dropObjectEx(App::DocumentObject* obj, A
self->setLinks(std::move(values), QApplication::keyboardModifiers() == Qt::ControlModifier);
if (self->Relative.getValue())
updatePlacement(false);
return std::string();
return {};
}