All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -20,9 +20,9 @@
* *
***************************************************************************/
# include <QLineEdit>
# include <QPixmapCache>
# include <QStyle>
#include <QLineEdit>
#include <QPixmapCache>
#include <QStyle>
#include "BitmapFactory.h"
#include "Command.h"
@@ -38,7 +38,7 @@
#include <Base/Tools.h>
FC_LOG_LEVEL_INIT("Expression",true,true)
FC_LOG_LEVEL_INIT("Expression", true, true)
using namespace Gui;
using namespace App;
@@ -63,57 +63,63 @@ void ExpressionBinding::unbind()
void Gui::ExpressionBinding::setExpression(std::shared_ptr<Expression> expr)
{
DocumentObject * docObj = path.getDocumentObject();
DocumentObject* docObj = path.getDocumentObject();
if (expr) {
const std::string error = docObj->ExpressionEngine.validateExpression(path, expr);
if (!error.empty())
if (!error.empty()) {
throw Base::RuntimeError(error.c_str());
}
}
lastExpression = getExpression();
bool transaction = !App::GetApplication().getActiveTransaction();
if(transaction) {
if (transaction) {
std::ostringstream ss;
ss << (expr?"Set":"Discard") << " expression " << docObj->Label.getValue();
ss << (expr ? "Set" : "Discard") << " expression " << docObj->Label.getValue();
App::GetApplication().setActiveTransaction(ss.str().c_str());
}
docObj->ExpressionEngine.setValue(path, expr);
if(m_autoApply)
if (m_autoApply) {
apply();
}
if(transaction)
if (transaction) {
App::GetApplication().closeActiveTransaction();
}
}
void ExpressionBinding::bind(const App::ObjectIdentifier &_path)
void ExpressionBinding::bind(const App::ObjectIdentifier& _path)
{
const Property * prop = _path.getProperty();
const Property* prop = _path.getProperty();
Q_ASSERT(prop != nullptr);
path = prop->canonicalPath(_path);
//connect to be informed about changes
DocumentObject * docObj = path.getDocumentObject();
// connect to be informed about changes
DocumentObject* docObj = path.getDocumentObject();
if (docObj) {
//NOLINTBEGIN
expressionchanged = docObj->ExpressionEngine.expressionChanged.connect(std::bind(&ExpressionBinding::expressionChange, this, sp::_1));
// NOLINTBEGIN
expressionchanged = docObj->ExpressionEngine.expressionChanged.connect(
std::bind(&ExpressionBinding::expressionChange, this, sp::_1)
);
App::Document* doc = docObj->getDocument();
objectdeleted = doc->signalDeletedObject.connect(std::bind(&ExpressionBinding::objectDeleted, this, sp::_1));
objectdeleted = doc->signalDeletedObject.connect(
std::bind(&ExpressionBinding::objectDeleted, this, sp::_1)
);
documentdeleted = App::GetApplication().signalDeleteDocument.connect(
std::bind(&ExpressionBinding::onDocumentDeleted, this, sp::_1));
//NOLINTEND
std::bind(&ExpressionBinding::onDocumentDeleted, this, sp::_1)
);
// NOLINTEND
}
}
void ExpressionBinding::bind(const Property &prop)
void ExpressionBinding::bind(const Property& prop)
{
bind(App::ObjectIdentifier(prop));
}
@@ -125,7 +131,7 @@ bool ExpressionBinding::hasExpression() const
std::shared_ptr<App::Expression> ExpressionBinding::getExpression() const
{
DocumentObject * docObj = path.getDocumentObject();
DocumentObject* docObj = path.getDocumentObject();
Q_ASSERT(isBound() && docObj != nullptr);
@@ -135,24 +141,34 @@ std::shared_ptr<App::Expression> ExpressionBinding::getExpression() const
std::string ExpressionBinding::getExpressionString(bool no_throw) const
{
try {
if (!getExpression())
if (!getExpression()) {
throw Base::RuntimeError("No expression found.");
}
return getExpression()->toString();
} catch (Base::Exception &e) {
if(no_throw)
}
catch (Base::Exception& e) {
if (no_throw) {
FC_ERR("failed to get expression string: " << e.what());
else
}
else {
throw;
} catch (std::exception &e) {
if(no_throw)
}
}
catch (std::exception& e) {
if (no_throw) {
FC_ERR("failed to get expression string: " << e.what());
else
}
else {
throw;
} catch (...) {
if(no_throw)
}
}
catch (...) {
if (no_throw) {
FC_ERR("failed to get expression string: unknown exception");
else
}
else {
throw;
}
}
return {};
}
@@ -165,15 +181,16 @@ std::string ExpressionBinding::getEscapedExpressionString() const
return escapedstr;
}
bool ExpressionBinding::assignToProperty(const std::string & propName, double value)
bool ExpressionBinding::assignToProperty(const std::string& propName, double value)
{
if (isBound()) {
const App::ObjectIdentifier & path = getPath();
const Property * prop = path.getProperty();
const App::ObjectIdentifier& path = getPath();
const Property* prop = path.getProperty();
/* Skip update if property is bound and we know it is read-only */
if (prop && prop->isReadOnly())
if (prop && prop->isReadOnly()) {
return true;
}
if (prop && prop->isDerivedFrom<App::PropertyPlacement>()) {
std::string p = path.getSubPathStr();
@@ -187,50 +204,60 @@ bool ExpressionBinding::assignToProperty(const std::string & propName, double va
return true;
}
bool ExpressionBinding::apply(const std::string & propName)
bool ExpressionBinding::apply(const std::string& propName)
{
Q_UNUSED(propName);
if (hasExpression()) {
DocumentObject * docObj = path.getDocumentObject();
DocumentObject* docObj = path.getDocumentObject();
if (!docObj)
if (!docObj) {
throw Base::RuntimeError("Document object not found.");
}
bool transaction = !App::GetApplication().getActiveTransaction();
if(transaction) {
if (transaction) {
std::ostringstream ss;
ss << "Set expression " << docObj->Label.getValue();
App::GetApplication().setActiveTransaction(ss.str().c_str());
}
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', u'%s')",
docObj->getDocument()->getName(),
docObj->getNameInDocument(),
path.toEscapedString().c_str(),
getEscapedExpressionString().c_str());
if(transaction)
Gui::Command::doCommand(
Gui::Command::Doc,
"App.getDocument('%s').%s.setExpression('%s', u'%s')",
docObj->getDocument()->getName(),
docObj->getNameInDocument(),
path.toEscapedString().c_str(),
getEscapedExpressionString().c_str()
);
if (transaction) {
App::GetApplication().closeActiveTransaction();
}
return true;
}
else {
if (isBound()) {
DocumentObject * docObj = path.getDocumentObject();
DocumentObject* docObj = path.getDocumentObject();
if (!docObj)
if (!docObj) {
throw Base::RuntimeError("Document object not found.");
}
if (lastExpression) {
bool transaction = !App::GetApplication().getActiveTransaction();
if(transaction) {
if (transaction) {
std::ostringstream ss;
ss << "Discard expression " << docObj->Label.getValue();
App::GetApplication().setActiveTransaction(ss.str().c_str());
}
Gui::Command::doCommand(Gui::Command::Doc,"App.getDocument('%s').%s.setExpression('%s', None)",
docObj->getDocument()->getName(),
docObj->getNameInDocument(),
path.toEscapedString().c_str());
if(transaction)
Gui::Command::doCommand(
Gui::Command::Doc,
"App.getDocument('%s').%s.setExpression('%s', None)",
docObj->getDocument()->getName(),
docObj->getNameInDocument(),
path.toEscapedString().c_str()
);
if (transaction) {
App::GetApplication().closeActiveTransaction();
}
}
}
@@ -240,36 +267,41 @@ bool ExpressionBinding::apply(const std::string & propName)
bool ExpressionBinding::apply()
{
Property * prop(path.getProperty());
Property* prop(path.getProperty());
assert(prop);
Q_UNUSED(prop);
DocumentObject * docObj(path.getDocumentObject());
DocumentObject* docObj(path.getDocumentObject());
if (!docObj)
if (!docObj) {
throw Base::RuntimeError("Document object not found.");
}
/* Skip updating read-only properties */
if (prop->isReadOnly())
if (prop->isReadOnly()) {
return true;
}
std::string _path = getPath().toEscapedString();
const char *path = _path.c_str();
if(path[0] == '.')
const char* path = _path.c_str();
if (path[0] == '.') {
++path;
}
return apply(Gui::Command::getObjectCmd(docObj) + "." + path);
}
void ExpressionBinding::expressionChange(const ObjectIdentifier& id) {
void ExpressionBinding::expressionChange(const ObjectIdentifier& id)
{
if(id==path)
if (id == path) {
onChange();
}
}
void ExpressionBinding::objectDeleted(const App::DocumentObject& obj)
{
DocumentObject * docObj = path.getDocumentObject();
DocumentObject* docObj = path.getDocumentObject();
if (docObj == &obj) {
unbind();
}
@@ -288,17 +320,17 @@ ExpressionWidget::ExpressionWidget() = default;
QPixmap ExpressionWidget::getIcon(const char* name, const QSize& size) const
{
QString key = QStringLiteral("%1_%2x%3")
.arg(QString::fromLatin1(name))
.arg(size.width())
.arg(size.height());
QString key
= QStringLiteral("%1_%2x%3").arg(QString::fromLatin1(name)).arg(size.width()).arg(size.height());
QPixmap icon;
if (QPixmapCache::find(key, &icon))
if (QPixmapCache::find(key, &icon)) {
return icon;
}
icon = BitmapFactory().pixmapFromSvg(name, size);
if (!icon.isNull())
if (!icon.isNull()) {
QPixmapCache::insert(key, icon);
}
return icon;
}