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

@@ -22,10 +22,10 @@
* *
***************************************************************************/
# include <QMessageBox>
# include <QString>
# include <QCompleter>
# include <algorithm>
#include <QMessageBox>
#include <QString>
#include <QCompleter>
#include <algorithm>
#include <memory>
#include <array>
@@ -132,24 +132,24 @@ const std::string DlgAddProperty::GroupBase = "Base";
* situation.
*/
DlgAddProperty::DlgAddProperty(QWidget* parent,
App::PropertyContainer* container)
DlgAddProperty::DlgAddProperty(QWidget* parent, App::PropertyContainer* container)
: DlgAddProperty(parent, container, nullptr)
{
}
{}
DlgAddProperty::DlgAddProperty(QWidget* parent,
ViewProviderVarSet* viewProvider)
: DlgAddProperty(parent,
viewProvider ? viewProvider->getObject<App::PropertyContainer>() : nullptr,
viewProvider)
{
}
DlgAddProperty::DlgAddProperty(QWidget* parent, ViewProviderVarSet* viewProvider)
: DlgAddProperty(
parent,
viewProvider ? viewProvider->getObject<App::PropertyContainer>() : nullptr,
viewProvider
)
{}
DlgAddProperty::DlgAddProperty(QWidget* parent,
App::PropertyContainer* container,
ViewProviderVarSet* viewProvider)
DlgAddProperty::DlgAddProperty(
QWidget* parent,
App::PropertyContainer* container,
ViewProviderVarSet* viewProvider
)
: QDialog(parent)
, container(container)
, ui(new Ui_DlgAddProperty)
@@ -167,10 +167,9 @@ DlgAddProperty::~DlgAddProperty() = default;
void DlgAddProperty::setupMacroRedirector()
{
setValueRedirector = std::make_unique<MacroManager::MacroRedirector>([this](MacroManager::LineType /*type*/,
const char* line) {
this->setValueCommand = line;
});
setValueRedirector = std::make_unique<MacroManager::MacroRedirector>(
[this](MacroManager::LineType /*type*/, const char* line) { this->setValueCommand = line; }
);
}
int DlgAddProperty::findLabelRow(const char* labelName, QFormLayout* layout)
@@ -193,7 +192,7 @@ int DlgAddProperty::findLabelRow(const char* labelName, QFormLayout* layout)
void DlgAddProperty::removeExistingWidget(QFormLayout* formLayout, int labelRow)
{
if (QLayoutItem* existingItem = formLayout->itemAt(labelRow, QFormLayout::FieldRole)) {
if (QWidget *existingWidget = existingItem->widget()) {
if (QWidget* existingWidget = existingItem->widget()) {
formLayout->removeWidget(existingWidget);
existingWidget->deleteLater();
}
@@ -201,8 +200,7 @@ void DlgAddProperty::removeExistingWidget(QFormLayout* formLayout, int labelRow)
}
void DlgAddProperty::setWidgetForLabel(const char* labelName, QWidget* widget,
QLayout* layout)
void DlgAddProperty::setWidgetForLabel(const char* labelName, QWidget* widget, QLayout* layout)
{
auto formLayout = qobject_cast<QFormLayout*>(layout);
if (formLayout == nullptr) {
@@ -220,11 +218,11 @@ void DlgAddProperty::setWidgetForLabel(const char* labelName, QWidget* widget,
formLayout->setWidget(labelRow, QFormLayout::FieldRole, widget);
}
void DlgAddProperty::populateGroup(EditFinishedComboBox& comboBox,
const App::PropertyContainer* container)
void DlgAddProperty::populateGroup(EditFinishedComboBox& comboBox, const App::PropertyContainer* container)
{
auto paramGroup = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/PropertyView");
"User parameter:BaseApp/Preferences/PropertyView"
);
std::string lastGroup = paramGroup->GetASCII("NewPropertyGroup");
std::vector<App::Property*> properties;
@@ -252,8 +250,7 @@ void DlgAddProperty::populateGroup(EditFinishedComboBox& comboBox,
comboBox.addItem(QString::fromStdString(groupName));
}
if (!lastGroup.empty() &&
std::ranges::find(groupNames, lastGroup) != groupNames.end()) {
if (!lastGroup.empty() && std::ranges::find(groupNames, lastGroup) != groupNames.end()) {
comboBox.setEditText(QString::fromStdString(lastGroup));
}
else {
@@ -270,8 +267,12 @@ void DlgAddProperty::initializeGroup()
setWidgetForLabel("labelGroup", &comboBoxGroup, layout());
populateGroup(comboBoxGroup, container);
connComboBoxGroup = connect(&comboBoxGroup, &EditFinishedComboBox::editFinished,
this, &DlgAddProperty::onGroupFinished);
connComboBoxGroup = connect(
&comboBoxGroup,
&EditFinishedComboBox::editFinished,
this,
&DlgAddProperty::onGroupFinished
);
}
std::vector<Base::Type> DlgAddProperty::getSupportedTypes()
@@ -280,10 +281,9 @@ std::vector<Base::Type> DlgAddProperty::getSupportedTypes()
std::vector<Base::Type> allTypes;
Base::Type::getAllDerivedFrom(Base::Type::fromName("App::Property"), allTypes);
std::ranges::copy_if(allTypes, std::back_inserter(supportedTypes),
[&](const Base::Type& type) {
return type.canInstantiate() && isTypeWithEditor(type);
});
std::ranges::copy_if(allTypes, std::back_inserter(supportedTypes), [&](const Base::Type& type) {
return type.canInstantiate() && isTypeWithEditor(type);
});
std::ranges::sort(supportedTypes, [](Base::Type a, Base::Type b) {
return strcmp(a.getName(), b.getName()) < 0;
@@ -295,19 +295,21 @@ std::vector<Base::Type> DlgAddProperty::getSupportedTypes()
void DlgAddProperty::initializeTypes()
{
auto paramGroup = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/PropertyView");
"User parameter:BaseApp/Preferences/PropertyView"
);
auto lastType = Base::Type::fromName(
paramGroup->GetASCII("NewPropertyType", "App::PropertyLength").c_str());
paramGroup->GetASCII("NewPropertyType", "App::PropertyLength").c_str()
);
if (lastType.isBad()) {
lastType = App::PropertyLength::getClassTypeId();
}
std::vector<Base::Type> types = getSupportedTypes();
for(const auto& type : types) {
for (const auto& type : types) {
ui->comboBoxType->addItem(QString::fromLatin1(type.getName()));
if (type == lastType) {
ui->comboBoxType->setCurrentIndex(ui->comboBoxType->count()-1);
ui->comboBoxType->setCurrentIndex(ui->comboBoxType->count() - 1);
}
}
@@ -317,8 +319,12 @@ void DlgAddProperty::initializeTypes()
ui->comboBoxType->setCompleter(&completerType);
ui->comboBoxType->setInsertPolicy(QComboBox::NoInsert);
connComboBoxType = connect(ui->comboBoxType, &QComboBox::currentTextChanged,
this, &DlgAddProperty::onTypeChanged);
connComboBoxType = connect(
ui->comboBoxType,
&QComboBox::currentTextChanged,
this,
&DlgAddProperty::onTypeChanged
);
}
void DlgAddProperty::removeSelectionEditor()
@@ -334,8 +340,7 @@ void DlgAddProperty::removeSelectionEditor()
void DlgAddProperty::addEnumEditor(PropertyItem* propertyItem)
{
auto* values =
static_cast<PropertyStringListItem*>(PropertyStringListItem::create());
auto* values = static_cast<PropertyStringListItem*>(PropertyStringListItem::create());
values->setParent(propertyItem);
values->setPropertyName(QLatin1String(QT_TRANSLATE_NOOP("App::Property", "Enum")));
if (propertyItem->childCount() > 0) {
@@ -343,16 +348,16 @@ void DlgAddProperty::addEnumEditor(PropertyItem* propertyItem)
delete child;
}
propertyItem->appendChild(values);
editor.reset(values->createEditor(this, [this]() {
this->valueChangedEnum();
}, FrameOption::WithFrame));
editor.reset(
values->createEditor(this, [this]() { this->valueChangedEnum(); }, FrameOption::WithFrame)
);
}
void DlgAddProperty::addNormalEditor(PropertyItem* propertyItem)
{
editor.reset(propertyItem->createEditor(this, [this]() {
this->valueChanged();
}, FrameOption::WithFrame));
editor.reset(
propertyItem->createEditor(this, [this]() { this->valueChanged(); }, FrameOption::WithFrame)
);
}
void DlgAddProperty::addEditor(PropertyItem* propertyItem)
@@ -433,20 +438,20 @@ bool DlgAddProperty::isTypeWithEditor(const Base::Type& type)
return type.isDerivedFrom(t);
};
return std::ranges::find(typesWithEditor, type) != typesWithEditor.end() ||
std::ranges::any_of(subTypesWithEditor, isDerivedFromType);
return std::ranges::find(typesWithEditor, type) != typesWithEditor.end()
|| std::ranges::any_of(subTypesWithEditor, isDerivedFromType);
}
bool DlgAddProperty::isTypeWithEditor(const std::string& type)
{
Base::Type propType =
Base::Type::getTypeIfDerivedFrom(type.c_str(), App::Property::getClassTypeId(), true);
Base::Type propType
= Base::Type::getTypeIfDerivedFrom(type.c_str(), App::Property::getClassTypeId(), true);
return isTypeWithEditor(propType);
}
static PropertyItem *createPropertyItem(App::Property *prop)
static PropertyItem* createPropertyItem(App::Property* prop)
{
const char *editor = prop->getEditorName();
const char* editor = prop->getEditorName();
if (Base::Tools::isNullOrEmpty(editor)) {
return nullptr;
}
@@ -466,9 +471,10 @@ void DlgAddProperty::createEditorForType(const Base::Type& type)
// When prop goes out of scope, it can be deleted because we obtained the
// propertyItem (if applicable) and we initialized the editor with the data
// from the property.
std::unique_ptr<App::Property, void(*)(App::Property*)> prop(
static_cast<App::Property*>(propInstance),
[](App::Property* p) { delete p; });
std::unique_ptr<App::Property, void (*)(App::Property*)> prop(
static_cast<App::Property*>(propInstance),
[](App::Property* p) { delete p; }
);
prop->setContainer(container);
propertyItem.reset(createPropertyItem(prop.get()));
@@ -484,8 +490,8 @@ void DlgAddProperty::initializeValue()
{
std::string type = ui->comboBoxType->currentText().toStdString();
Base::Type propType =
Base::Type::getTypeIfDerivedFrom(type.c_str(), App::Property::getClassTypeId(), true);
Base::Type propType
= Base::Type::getTypeIfDerivedFrom(type.c_str(), App::Property::getClassTypeId(), true);
if (propType.isBad()) {
return;
}
@@ -505,8 +511,8 @@ void DlgAddProperty::setTitle()
void DlgAddProperty::setAddEnabled(bool enabled)
{
QPushButton *addButton = ui->buttonBox->button(QDialogButtonBox::Ok);
QPushButton *cancelButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
QPushButton* addButton = ui->buttonBox->button(QDialogButtonBox::Ok);
QPushButton* cancelButton = ui->buttonBox->button(QDialogButtonBox::Cancel);
cancelButton->setDefault(!enabled);
addButton->setDefault(enabled);
addButton->setEnabled(enabled);
@@ -519,14 +525,15 @@ void DlgAddProperty::initializeWidgets(ViewProviderVarSet* viewProvider)
initializeValue();
if (viewProvider) {
connect(this, &QDialog::finished,
this, [viewProvider](int result) { viewProvider->onFinished(result); });
connect(this, &QDialog::finished, this, [viewProvider](int result) {
viewProvider->onFinished(result);
});
}
connLineEditNameTextChanged = connect(ui->lineEditName, &QLineEdit::textChanged,
this, &DlgAddProperty::onNameChanged);
connLineEditNameTextChanged
= connect(ui->lineEditName, &QLineEdit::textChanged, this, &DlgAddProperty::onNameChanged);
setTitle();
QPushButton *addButton = ui->buttonBox->button(QDialogButtonBox::Ok);
QPushButton* addButton = ui->buttonBox->button(QDialogButtonBox::Ok);
addButton->setText(tr("Add"));
setAddEnabled(false);
@@ -541,19 +548,17 @@ void DlgAddProperty::initializeWidgets(ViewProviderVarSet* viewProvider)
bool DlgAddProperty::propertyExists(const std::string& name)
{
App::Property* prop = container->getPropertyByName(name.c_str());
return prop && prop->getContainer() == container &&
!(propertyItem && propertyItem->getFirstProperty() == prop);
return prop && prop->getContainer() == container
&& !(propertyItem && propertyItem->getFirstProperty() == prop);
}
bool DlgAddProperty::isNameValid()
{
std::string name = ui->lineEditName->text().toStdString();
return !name.empty() &&
name == Base::Tools::getIdentifier(name) &&
!App::ExpressionParser::isTokenAConstant(name) &&
!App::ExpressionParser::isTokenAUnit(name) &&
!propertyExists(name);
return !name.empty() && name == Base::Tools::getIdentifier(name)
&& !App::ExpressionParser::isTokenAConstant(name)
&& !App::ExpressionParser::isTokenAUnit(name) && !propertyExists(name);
}
bool DlgAddProperty::isGroupValid()
@@ -565,8 +570,8 @@ bool DlgAddProperty::isGroupValid()
bool DlgAddProperty::isTypeValid()
{
std::string type = ui->comboBoxType->currentText().toStdString();
return Base::Type::fromName(type.c_str()).isDerivedFrom(App::Property::getClassTypeId()) &&
type != "App::Property";
return Base::Type::fromName(type.c_str()).isDerivedFrom(App::Property::getClassTypeId())
&& type != "App::Property";
}
bool DlgAddProperty::isDocument() const
@@ -633,8 +638,8 @@ void DlgAddProperty::removeEditor()
bool DlgAddProperty::isEnumPropertyItem() const
{
return ui->comboBoxType->currentText() ==
QString::fromLatin1(App::PropertyEnumeration::getClassTypeId().getName());
return ui->comboBoxType->currentText()
== QString::fromLatin1(App::PropertyEnumeration::getClassTypeId().getName());
}
bool DlgAddProperty::isSubLinkPropertyItem() const
@@ -769,7 +774,7 @@ bool DlgAddProperty::clear(FieldChange fieldChange)
return valueNeedsReset;
}
void DlgAddProperty::onNameChanged([[maybe_unused]]const QString& text)
void DlgAddProperty::onNameChanged([[maybe_unused]] const QString& text)
{
bool valueNeedsReset = clear(FieldChange::Name);
if (isNameValid() && isTypeValid()) {
@@ -828,8 +833,7 @@ void DlgAddProperty::changeEvent(QEvent* e)
void DlgAddProperty::valueChangedEnum()
{
auto* propEnum =
static_cast<App::PropertyEnumeration*>(propertyItem->getFirstProperty());
auto* propEnum = static_cast<App::PropertyEnumeration*>(propertyItem->getFirstProperty());
if (propEnum == nullptr || propertyItem->childCount() == 0) {
return;
}
@@ -839,8 +843,9 @@ void DlgAddProperty::valueChangedEnum()
QStringList enumValues = data.toStringList();
// convert to std::vector<std::string>
std::vector<std::string> enumValuesVec;
std::ranges::transform(enumValues, std::back_inserter(enumValuesVec),
[](const QString& value) { return value.toStdString(); });
std::ranges::transform(enumValues, std::back_inserter(enumValuesVec), [](const QString& value) {
return value.toStdString();
});
propEnum->setEnums(enumValuesVec);
}
@@ -862,7 +867,8 @@ void DlgAddProperty::openTransaction()
transactionID = App::GetApplication().setActiveTransaction("Add property");
}
void DlgAddProperty::critical(const QString& title, const QString& text) {
void DlgAddProperty::critical(const QString& title, const QString& text)
{
static bool criticalDialogShown = false;
if (!criticalDialogShown) {
Base::StateLocker locker(criticalDialogShown);
@@ -870,9 +876,13 @@ void DlgAddProperty::critical(const QString& title, const QString& text) {
}
}
void DlgAddProperty::recordMacroAdd(const App::PropertyContainer* container,
const std::string& type, const std::string& name,
const std::string& group, const std::string& doc) const
void DlgAddProperty::recordMacroAdd(
const App::PropertyContainer* container,
const std::string& type,
const std::string& name,
const std::string& group,
const std::string& doc
) const
{
std::ostringstream command;
command << "App.getDocument('";
@@ -888,8 +898,7 @@ void DlgAddProperty::recordMacroAdd(const App::PropertyContainer* container,
FC_ERR("Cannot record macro for container of type " << container->getTypeId().getName());
return;
}
command << ".addProperty('" << type << "', '" << name << "', '" <<
group << "', '" << doc + "')";
command << ".addProperty('" << type << "', '" << name << "', '" << group << "', '" << doc + "')";
Application::Instance->macroManager()->addLine(Gui::MacroManager::App, command.str().c_str());
}
@@ -905,18 +914,19 @@ App::Property* DlgAddProperty::createProperty()
};
try {
App::Property* prop = container->addDynamicProperty(type.c_str(), name.c_str(),
group.c_str(), doc.c_str());
App::Property* prop
= container->addDynamicProperty(type.c_str(), name.c_str(), group.c_str(), doc.c_str());
MacroManager::MacroRedirector redirector(recordAddCommand);
recordMacroAdd(container, type, name, group, doc);
return prop;
}
catch (Base::Exception& e) {
e.reportException();
critical(QObject::tr("Add property"),
QObject::tr("Failed to add property to '%1': %2").arg(
QString::fromLatin1(container->getFullName().c_str()),
QString::fromUtf8(e.what())));
critical(
QObject::tr("Add property"),
QObject::tr("Failed to add property to '%1': %2")
.arg(QString::fromLatin1(container->getFullName().c_str()), QString::fromUtf8(e.what()))
);
return nullptr;
}
}
@@ -942,7 +952,8 @@ void DlgAddProperty::clearFields()
setAddEnabled(false);
}
void DlgAddProperty::addDocumentation() {
void DlgAddProperty::addDocumentation()
{
/* Since there is no check on documentation (we accept any string), there
* is no signal handler for the documentation field. This method updates
* the property that is being added with the text inserted as
@@ -976,14 +987,14 @@ void DlgAddProperty::accept()
setValueRedirector = nullptr;
Application::Instance->macroManager()->addLine(MacroManager::LineType::App, addCommand.c_str());
Application::Instance->macroManager()->addLine(MacroManager::LineType::App,
setValueCommand.c_str());
Application::Instance->macroManager()->addLine(MacroManager::LineType::App, setValueCommand.c_str());
setupMacroRedirector();
std::string group = comboBoxGroup.currentText().toStdString();
std::string type = ui->comboBoxType->currentText().toStdString();
auto paramGroup = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/PropertyView");
"User parameter:BaseApp/Preferences/PropertyView"
);
paramGroup->SetASCII("NewPropertyType", type.c_str());
paramGroup->SetASCII("NewPropertyGroup", group.c_str());