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,12 +20,12 @@
* *
***************************************************************************/
# include <limits>
# include <QKeyEvent>
# include <QLineEdit>
# include <QStyle>
# include <QStyleOptionSpinBox>
# include <QStylePainter>
#include <limits>
#include <QKeyEvent>
#include <QLineEdit>
#include <QStyle>
#include <QStyleOptionSpinBox>
#include <QStylePainter>
#include <boost/math/special_functions/round.hpp>
@@ -44,7 +44,7 @@ using namespace App;
using namespace Base;
ExpressionSpinBox::ExpressionSpinBox(QAbstractSpinBox* sb)
: spinbox(sb)
: spinbox(sb)
{
lineedit = spinbox->findChild<QLineEdit*>();
// Set Margins
@@ -55,9 +55,7 @@ ExpressionSpinBox::ExpressionSpinBox(QAbstractSpinBox* sb)
lineedit->setAlignment(Qt::AlignVCenter);
makeLabel(lineedit);
QObject::connect(iconLabel, &ExpressionLabel::clicked, [this]() {
this->openFormulaDialog();
});
QObject::connect(iconLabel, &ExpressionLabel::clicked, [this]() { this->openFormulaDialog(); });
}
ExpressionSpinBox::~ExpressionSpinBox() = default;
@@ -71,7 +69,7 @@ int ExpressionSpinBox::getMargin()
#endif
}
void ExpressionSpinBox::bind(const App::ObjectIdentifier &_path)
void ExpressionSpinBox::bind(const App::ObjectIdentifier& _path)
{
ExpressionBinding::bind(_path);
@@ -84,8 +82,7 @@ void ExpressionSpinBox::showIcon()
}
void ExpressionSpinBox::validateInput()
{
}
{}
void ExpressionSpinBox::showInvalidExpression(const QString& tip)
{
@@ -99,15 +96,15 @@ void ExpressionSpinBox::showInvalidExpression(const QString& tip)
void ExpressionSpinBox::showValidExpression(ExpressionSpinBox::Number number)
{
std::unique_ptr<Expression> result(getExpression()->eval());
auto * value = freecad_cast<NumberExpression*>(result.get());
auto* value = freecad_cast<NumberExpression*>(result.get());
if (value) {
switch (number) {
case Number::SetIfNumber:
setNumberExpression(value);
break;
case Number::KeepCurrent:
break;
case Number::SetIfNumber:
setNumberExpression(value);
break;
case Number::KeepCurrent:
break;
}
spinbox->setReadOnly(true);
@@ -142,7 +139,7 @@ void ExpressionSpinBox::updateExpression()
clearExpression();
}
}
catch (const Base::Exception & e) {
catch (const Base::Exception& e) {
showInvalidExpression(QString::fromLatin1(e.what()));
}
}
@@ -155,7 +152,7 @@ void ExpressionSpinBox::setExpression(std::shared_ptr<Expression> expr)
ExpressionBinding::setExpression(expr);
validateInput();
}
catch (const Base::Exception & e) {
catch (const Base::Exception& e) {
showInvalidExpression(QString::fromLatin1(e.what()));
}
}
@@ -183,26 +180,29 @@ void ExpressionSpinBox::openFormulaDialog()
{
Q_ASSERT(isBound());
auto * qprop = freecad_cast<PropertyQuantity*>(getPath().getProperty());
auto* qprop = freecad_cast<PropertyQuantity*>(getPath().getProperty());
Unit unit;
if (qprop)
if (qprop) {
unit = qprop->getUnit();
}
auto box = new Gui::Dialog::DlgExpressionInput(getPath(), getExpression(), unit, spinbox);
QObject::connect(box, &Gui::Dialog::DlgExpressionInput::finished, [this, box]() {
if (box->result() == QDialog::Accepted)
if (box->result() == QDialog::Accepted) {
setExpression(box->getExpression());
else if (box->discardedFormula())
}
else if (box->discardedFormula()) {
setExpression(std::shared_ptr<Expression>());
}
updateExpression();
box->deleteLater();
});
box->show();
QPoint pos = spinbox->mapToGlobal(QPoint(0,0));
box->move(pos-box->expressionPosition());
QPoint pos = spinbox->mapToGlobal(QPoint(0, 0));
box->move(pos - box->expressionPosition());
Gui::adjustDialogPosition(box);
}
@@ -231,15 +231,15 @@ void ExpressionSpinBox::drawControl(QStyleOptionSpinBox& opt)
// ----------------------------------------------------------------------------
UnsignedValidator::UnsignedValidator( QObject * parent )
: QValidator( parent )
UnsignedValidator::UnsignedValidator(QObject* parent)
: QValidator(parent)
{
b = 0;
t = std::numeric_limits<unsigned>::max();
b = 0;
t = std::numeric_limits<unsigned>::max();
}
UnsignedValidator::UnsignedValidator( uint minimum, uint maximum, QObject * parent )
: QValidator( parent )
UnsignedValidator::UnsignedValidator(uint minimum, uint maximum, QObject* parent)
: QValidator(parent)
{
b = minimum;
t = maximum;
@@ -247,94 +247,108 @@ UnsignedValidator::UnsignedValidator( uint minimum, uint maximum, QObject * pare
UnsignedValidator::~UnsignedValidator() = default;
QValidator::State UnsignedValidator::validate( QString & input, int & ) const
QValidator::State UnsignedValidator::validate(QString& input, int&) const
{
QString stripped = input.trimmed();
if ( stripped.isEmpty() )
if (stripped.isEmpty()) {
return Intermediate;
}
bool ok;
uint entered = input.toUInt( &ok );
if ( !ok )
uint entered = input.toUInt(&ok);
if (!ok) {
return Invalid;
else if ( entered < b )
}
else if (entered < b) {
return Intermediate;
else if ( entered > t )
}
else if (entered > t) {
return Invalid;
}
// else if ( entered < b || entered > t )
// return Invalid;
else
else {
return Acceptable;
}
}
void UnsignedValidator::setRange( uint minimum, uint maximum )
void UnsignedValidator::setRange(uint minimum, uint maximum)
{
b = minimum;
t = maximum;
}
void UnsignedValidator::setBottom( uint bottom )
void UnsignedValidator::setBottom(uint bottom)
{
setRange( bottom, top() );
setRange(bottom, top());
}
void UnsignedValidator::setTop( uint top )
void UnsignedValidator::setTop(uint top)
{
setRange( bottom(), top );
setRange(bottom(), top);
}
namespace Gui {
namespace Gui
{
class UIntSpinBoxPrivate
{
public:
UnsignedValidator * mValidator{nullptr};
UnsignedValidator* mValidator {nullptr};
UIntSpinBoxPrivate() = default;
unsigned mapToUInt( int v ) const
unsigned mapToUInt(int v) const
{
using int_limits = std::numeric_limits<int>;
using uint_limits = std::numeric_limits<unsigned>;
unsigned ui;
if ( v == int_limits::min() ) {
if (v == int_limits::min()) {
ui = 0;
} else if ( v == int_limits::max() ) {
}
else if (v == int_limits::max()) {
ui = uint_limits::max();
} else if ( v < 0 ) {
}
else if (v < 0) {
v -= int_limits::min();
ui = static_cast<unsigned>(v);
} else {
}
else {
ui = static_cast<unsigned>(v);
ui -= int_limits::min();
} return ui;
}
return ui;
}
int mapToInt( unsigned v ) const
int mapToInt(unsigned v) const
{
using int_limits = std::numeric_limits<int>;
using uint_limits = std::numeric_limits<unsigned>;
int in;
if ( v == uint_limits::max() ) {
if (v == uint_limits::max()) {
in = int_limits::max();
} else if ( v == 0 ) {
}
else if (v == 0) {
in = int_limits::min();
} else if ( v > static_cast<unsigned int>(int_limits::max()) ) {
}
else if (v > static_cast<unsigned int>(int_limits::max())) {
v += int_limits::min();
in = static_cast<int>(v);
} else {
}
else {
in = v;
in += int_limits::min();
} return in;
}
return in;
}
};
} // namespace Gui
} // namespace Gui
UIntSpinBox::UIntSpinBox (QWidget* parent)
: QSpinBox (parent)
, ExpressionSpinBox(this)
UIntSpinBox::UIntSpinBox(QWidget* parent)
: QSpinBox(parent)
, ExpressionSpinBox(this)
{
d = new UIntSpinBoxPrivate;
d->mValidator = new UnsignedValidator(this->minimum(), this->maximum(), this);
d->mValidator = new UnsignedValidator(this->minimum(), this->maximum(), this);
connect(this, qOverload<int>(&QSpinBox::valueChanged), this, &UIntSpinBox::valueChange);
setRange(0, 99);
setValue(0);
@@ -344,7 +358,8 @@ UIntSpinBox::UIntSpinBox (QWidget* parent)
UIntSpinBox::~UIntSpinBox()
{
delete d->mValidator;
delete d; d = nullptr;
delete d;
d = nullptr;
}
void UIntSpinBox::setRange(uint minVal, uint maxVal)
@@ -355,7 +370,7 @@ void UIntSpinBox::setRange(uint minVal, uint maxVal)
updateValidator();
}
QValidator::State UIntSpinBox::validate (QString & input, int & pos) const
QValidator::State UIntSpinBox::validate(QString& input, int& pos) const
{
return d->mValidator->validate(input, pos);
}
@@ -383,8 +398,9 @@ uint UIntSpinBox::minimum() const
void UIntSpinBox::setMinimum(uint minVal)
{
uint maxVal = maximum();
if (maxVal < minVal)
if (maxVal < minVal) {
maxVal = minVal;
}
setRange(minVal, maxVal);
}
@@ -396,12 +412,13 @@ uint UIntSpinBox::maximum() const
void UIntSpinBox::setMaximum(uint maxVal)
{
uint minVal = minimum();
if (minVal > maxVal)
if (minVal > maxVal) {
minVal = maxVal;
}
setRange(minVal, maxVal);
}
QString UIntSpinBox::textFromValue (int v) const
QString UIntSpinBox::textFromValue(int v) const
{
uint val = d->mapToUInt(v);
QString s;
@@ -409,7 +426,7 @@ QString UIntSpinBox::textFromValue (int v) const
return s;
}
int UIntSpinBox::valueFromText (const QString & text) const
int UIntSpinBox::valueFromText(const QString& text) const
{
bool ok;
QString s = text;
@@ -427,7 +444,7 @@ void UIntSpinBox::updateValidator()
d->mValidator->setRange(this->minimum(), this->maximum());
}
bool UIntSpinBox::apply(const std::string & propName)
bool UIntSpinBox::apply(const std::string& propName)
{
if (!ExpressionBinding::apply(propName)) {
Gui::Command::doCommand(Gui::Command::Doc, "%s = %u", propName.c_str(), value());
@@ -442,16 +459,17 @@ void UIntSpinBox::setNumberExpression(App::NumberExpression* expr)
setValue(boost::math::round(expr->getValue()));
}
void UIntSpinBox::resizeEvent(QResizeEvent * event)
void UIntSpinBox::resizeEvent(QResizeEvent* event)
{
QAbstractSpinBox::resizeEvent(event);
resizeWidget();
}
void UIntSpinBox::keyPressEvent(QKeyEvent *event)
void UIntSpinBox::keyPressEvent(QKeyEvent* event)
{
if (!handleKeyEvent(event->text()))
if (!handleKeyEvent(event->text())) {
QAbstractSpinBox::keyPressEvent(event);
}
}
void UIntSpinBox::paintEvent(QPaintEvent*)
@@ -466,8 +484,7 @@ void UIntSpinBox::paintEvent(QPaintEvent*)
IntSpinBox::IntSpinBox(QWidget* parent)
: QSpinBox(parent)
, ExpressionSpinBox(this)
{
}
{}
IntSpinBox::~IntSpinBox() = default;
@@ -477,8 +494,9 @@ bool IntSpinBox::apply(const std::string& propName)
Gui::Command::doCommand(Gui::Command::Doc, "%s = %d", propName.c_str(), value());
return true;
}
else
else {
return false;
}
}
void IntSpinBox::setNumberExpression(App::NumberExpression* expr)
@@ -486,16 +504,17 @@ void IntSpinBox::setNumberExpression(App::NumberExpression* expr)
setValue(boost::math::round(expr->getValue()));
}
void IntSpinBox::resizeEvent(QResizeEvent * event)
void IntSpinBox::resizeEvent(QResizeEvent* event)
{
QAbstractSpinBox::resizeEvent(event);
resizeWidget();
}
void IntSpinBox::keyPressEvent(QKeyEvent *event)
void IntSpinBox::keyPressEvent(QKeyEvent* event)
{
if (!handleKeyEvent(event->text()))
if (!handleKeyEvent(event->text())) {
QAbstractSpinBox::keyPressEvent(event);
}
}
void IntSpinBox::paintEvent(QPaintEvent*)
@@ -510,8 +529,7 @@ void IntSpinBox::paintEvent(QPaintEvent*)
DoubleSpinBox::DoubleSpinBox(QWidget* parent)
: QDoubleSpinBox(parent)
, ExpressionSpinBox(this)
{
}
{}
DoubleSpinBox::~DoubleSpinBox() = default;
@@ -530,16 +548,17 @@ void DoubleSpinBox::setNumberExpression(App::NumberExpression* expr)
setValue(expr->getValue());
}
void DoubleSpinBox::resizeEvent(QResizeEvent * event)
void DoubleSpinBox::resizeEvent(QResizeEvent* event)
{
QAbstractSpinBox::resizeEvent(event);
resizeWidget();
}
void DoubleSpinBox::keyPressEvent(QKeyEvent *event)
void DoubleSpinBox::keyPressEvent(QKeyEvent* event)
{
if (!handleKeyEvent(event->text()))
if (!handleKeyEvent(event->text())) {
QDoubleSpinBox::keyPressEvent(event);
}
}
void DoubleSpinBox::paintEvent(QPaintEvent*)