SketcherGui: apply clang-format

This commit is contained in:
Abdullah Tahiri
2023-05-25 15:09:30 +02:00
committed by abdullahtahiriyo
parent fd8b50d23f
commit ec899d75c6
98 changed files with 17648 additions and 13572 deletions

View File

@@ -1,30 +1,30 @@
/***************************************************************************
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
* Copyright (c) 2014 Abdullah Tahiri <abdullah.tahiri.yo@gmail.com> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
# include <memory>
# include <QDebug>
# include <QTextStream>
#include <QDebug>
#include <QTextStream>
#include <memory>
#endif
#include <Base/Tools.h>
@@ -45,12 +45,11 @@ PropertyConstraintListItem::PropertyConstraintListItem()
}
PropertyConstraintListItem::~PropertyConstraintListItem()
{
}
{}
QVariant PropertyConstraintListItem::toString(const QVariant& prop) const
{
const QList<Base::Quantity>& value = prop.value< QList<Base::Quantity> >();
const QList<Base::Quantity>& value = prop.value<QList<Base::Quantity>>();
QString str;
QTextStream out(&str);
out << "[";
@@ -65,21 +64,21 @@ QVariant PropertyConstraintListItem::toString(const QVariant& prop) const
void PropertyConstraintListItem::initialize()
{
const Sketcher::PropertyConstraintList* list = static_cast<const Sketcher::PropertyConstraintList*>(getPropertyData()[0]);
const std::vector< Sketcher::Constraint * > &vals = list->getValues();
const Sketcher::PropertyConstraintList* list =
static_cast<const Sketcher::PropertyConstraintList*>(getPropertyData()[0]);
const std::vector<Sketcher::Constraint*>& vals = list->getValues();
int id = 1;
int iNamed = 0;
std::vector<PropertyUnitItem *> unnamed;
std::vector<PropertyUnitItem*> unnamed;
for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) {
if ((*it)->Type == Sketcher::Distance || // Datum constraint
(*it)->Type == Sketcher::DistanceX ||
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Radius ||
(*it)->Type == Sketcher::Diameter ||
(*it)->Type == Sketcher::Angle ) {
for (std::vector<Sketcher::Constraint*>::const_iterator it = vals.begin(); it != vals.end();
++it, ++id) {
if ((*it)->Type == Sketcher::Distance ||// Datum constraint
(*it)->Type == Sketcher::DistanceX || (*it)->Type == Sketcher::DistanceY
|| (*it)->Type == Sketcher::Radius || (*it)->Type == Sketcher::Diameter
|| (*it)->Type == Sketcher::Angle) {
PropertyUnitItem* item = static_cast<PropertyUnitItem*>(PropertyUnitItem::create());
@@ -108,7 +107,7 @@ void PropertyConstraintListItem::initialize()
this->appendChild(item);
}
item->bind(list->createPath(id-1));
item->bind(list->createPath(id - 1));
item->setAutoApply(false);
}
}
@@ -116,7 +115,9 @@ void PropertyConstraintListItem::initialize()
// now deal with the unnamed
if (iNamed == 0) {
onlyUnnamed = true;
for (std::vector< PropertyUnitItem* >::const_iterator it = unnamed.begin();it != unnamed.end(); ++it) {
for (std::vector<PropertyUnitItem*>::const_iterator it = unnamed.begin();
it != unnamed.end();
++it) {
(*it)->setParent(this);
this->appendChild((*it));
}
@@ -124,12 +125,15 @@ void PropertyConstraintListItem::initialize()
else {
onlyUnnamed = false;
if (!unnamed.empty()) {
PropertyConstraintListItem* item = static_cast<PropertyConstraintListItem*>(PropertyConstraintListItem::create());
PropertyConstraintListItem* item =
static_cast<PropertyConstraintListItem*>(PropertyConstraintListItem::create());
item->setParent(this);
item->setPropertyName(tr("Unnamed"));
this->appendChild(item);
for (std::vector< PropertyUnitItem* >::const_iterator it = unnamed.begin();it != unnamed.end(); ++it) {
for (std::vector<PropertyUnitItem*>::const_iterator it = unnamed.begin();
it != unnamed.end();
++it) {
(*it)->setParent(item);
item->appendChild((*it));
}
@@ -145,8 +149,9 @@ void PropertyConstraintListItem::assignProperty(const App::Property* prop)
if (!prop->getTypeId().isDerivedFrom(Sketcher::PropertyConstraintList::getClassTypeId()))
return;
const Sketcher::PropertyConstraintList* list = static_cast<const Sketcher::PropertyConstraintList*>(prop);
const std::vector< Sketcher::Constraint * > &vals = list->getValues();
const Sketcher::PropertyConstraintList* list =
static_cast<const Sketcher::PropertyConstraintList*>(prop);
const std::vector<Sketcher::Constraint*>& vals = list->getValues();
// search for the group of unnamed items if available and take it out
int numUnnamed = 0;
@@ -166,19 +171,19 @@ void PropertyConstraintListItem::assignProperty(const App::Property* prop)
int numNamed = this->childCount();
this->onlyUnnamed = true;
for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) {
if ((*it)->Type == Sketcher::Distance || // Datum constraint
(*it)->Type == Sketcher::DistanceX ||
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Radius ||
(*it)->Type == Sketcher::Diameter ||
(*it)->Type == Sketcher::Angle ) {
for (std::vector<Sketcher::Constraint*>::const_iterator it = vals.begin(); it != vals.end();
++it, ++id) {
if ((*it)->Type == Sketcher::Distance ||// Datum constraint
(*it)->Type == Sketcher::DistanceX || (*it)->Type == Sketcher::DistanceY
|| (*it)->Type == Sketcher::Radius || (*it)->Type == Sketcher::Diameter
|| (*it)->Type == Sketcher::Angle) {
PropertyUnitItem* child = nullptr;
if ((*it)->Name.empty()) {
// search inside the group item for unnamed constraints
if (!unnamed) {
unnamed = static_cast<PropertyConstraintListItem*>(PropertyConstraintListItem::create());
unnamed = static_cast<PropertyConstraintListItem*>(
PropertyConstraintListItem::create());
unnamed->setPropertyName(tr("Unnamed"));
}
@@ -217,7 +222,7 @@ void PropertyConstraintListItem::assignProperty(const App::Property* prop)
child->setPropertyName(name);
child->setObjectName(internalName);
child->bind(list->createPath(id-1));
child->bind(list->createPath(id - 1));
child->setAutoApply(false);
}
}
@@ -232,7 +237,8 @@ void PropertyConstraintListItem::assignProperty(const App::Property* prop)
QVariant PropertyConstraintListItem::value(const App::Property* prop) const
{
assert(prop && prop->getTypeId().isDerivedFrom(Sketcher::PropertyConstraintList::getClassTypeId()));
assert(prop
&& prop->getTypeId().isDerivedFrom(Sketcher::PropertyConstraintList::getClassTypeId()));
PropertyConstraintListItem* self = const_cast<PropertyConstraintListItem*>(this);
@@ -242,17 +248,17 @@ QVariant PropertyConstraintListItem::value(const App::Property* prop) const
QList<Base::Quantity> subquantities;
bool onlyNamed = true;
const std::vector< Sketcher::Constraint * > &vals = static_cast<const Sketcher::PropertyConstraintList*>(prop)->getValues();
for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) {
if ((*it)->Type == Sketcher::Distance || // Datum constraint
(*it)->Type == Sketcher::DistanceX ||
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Radius ||
(*it)->Type == Sketcher::Diameter ||
(*it)->Type == Sketcher::Angle ) {
const std::vector<Sketcher::Constraint*>& vals =
static_cast<const Sketcher::PropertyConstraintList*>(prop)->getValues();
for (std::vector<Sketcher::Constraint*>::const_iterator it = vals.begin(); it != vals.end();
++it, ++id) {
if ((*it)->Type == Sketcher::Distance ||// Datum constraint
(*it)->Type == Sketcher::DistanceX || (*it)->Type == Sketcher::DistanceY
|| (*it)->Type == Sketcher::Radius || (*it)->Type == Sketcher::Diameter
|| (*it)->Type == Sketcher::Angle) {
Base::Quantity quant;
if ((*it)->Type == Sketcher::Angle ) {
if ((*it)->Type == Sketcher::Angle) {
double datum = Base::toDegrees<double>((*it)->getValue());
quant.setUnit(Base::Unit::Angle);
quant.setValue(datum);
@@ -271,11 +277,13 @@ QVariant PropertyConstraintListItem::value(const App::Property* prop) const
if ((*it)->Name.empty() && !onlyUnnamed) {
onlyNamed = false;
subquantities.append(quant);
PropertyItem* child = self->child(self->childCount()-1);
PropertyConstraintListItem* unnamednode = qobject_cast<PropertyConstraintListItem*>(child);
PropertyItem* child = self->child(self->childCount() - 1);
PropertyConstraintListItem* unnamednode =
qobject_cast<PropertyConstraintListItem*>(child);
if (unnamednode) {
unnamednode->blockEvent = true;
unnamednode->setProperty(internalName.toLatin1(), QVariant::fromValue<Base::Quantity>(quant));
unnamednode->setProperty(internalName.toLatin1(),
QVariant::fromValue<Base::Quantity>(quant));
unnamednode->blockEvent = false;
}
else {
@@ -285,7 +293,8 @@ QVariant PropertyConstraintListItem::value(const App::Property* prop) const
}
else {
self->blockEvent = true;
self->setProperty(internalName.toLatin1(), QVariant::fromValue<Base::Quantity>(quant));
self->setProperty(internalName.toLatin1(),
QVariant::fromValue<Base::Quantity>(quant));
self->blockEvent = false;
}
}
@@ -294,14 +303,14 @@ QVariant PropertyConstraintListItem::value(const App::Property* prop) const
// The quantities of unnamed constraints are only needed for display purposes inside toString()
if (!onlyUnnamed && !onlyNamed) {
self->blockEvent = true;
self->setProperty("Unnamed", QVariant::fromValue< QList<Base::Quantity> >(subquantities));
self->setProperty("Unnamed", QVariant::fromValue<QList<Base::Quantity>>(subquantities));
self->blockEvent = false;
}
return QVariant::fromValue< QList<Base::Quantity> >(quantities);
return QVariant::fromValue<QList<Base::Quantity>>(quantities);
}
bool PropertyConstraintListItem::event (QEvent* ev)
bool PropertyConstraintListItem::event(QEvent* ev)
{
if (ev->type() == QEvent::DynamicPropertyChange) {
if (!blockEvent) {
@@ -315,23 +324,24 @@ bool PropertyConstraintListItem::event (QEvent* ev)
int id = 0;
if (dynamic_cast<SketcherGui::PropertyConstraintListItem*>(this->parent())) {
item = static_cast<Sketcher::PropertyConstraintList*>(this->parent()->getFirstProperty());
item = static_cast<Sketcher::PropertyConstraintList*>(
this->parent()->getFirstProperty());
}
else {
item = static_cast<Sketcher::PropertyConstraintList*>(getFirstProperty());
}
const std::vector< Sketcher::Constraint * > &vals = item->getValues();
for (std::vector< Sketcher::Constraint* >::const_iterator it = vals.begin();it != vals.end(); ++it, ++id) {
if ((*it)->Type == Sketcher::Distance || // Datum constraint
(*it)->Type == Sketcher::DistanceX ||
(*it)->Type == Sketcher::DistanceY ||
(*it)->Type == Sketcher::Radius ||
(*it)->Type == Sketcher::Diameter ||
(*it)->Type == Sketcher::Angle ) {
const std::vector<Sketcher::Constraint*>& vals = item->getValues();
for (std::vector<Sketcher::Constraint*>::const_iterator it = vals.begin();
it != vals.end();
++it, ++id) {
if ((*it)->Type == Sketcher::Distance ||// Datum constraint
(*it)->Type == Sketcher::DistanceX || (*it)->Type == Sketcher::DistanceY
|| (*it)->Type == Sketcher::Radius || (*it)->Type == Sketcher::Diameter
|| (*it)->Type == Sketcher::Angle) {
// Get the internal name
QString internalName = QString::fromLatin1("Constraint%1").arg(id+1);
QString internalName = QString::fromLatin1("Constraint%1").arg(id + 1);
if (internalName == propName) {
double datum = quant.getValue();
if ((*it)->Type == Sketcher::Angle)
@@ -355,25 +365,26 @@ void PropertyConstraintListItem::setValue(const QVariant& value)
Q_UNUSED(value);
}
QWidget* PropertyConstraintListItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
QWidget* PropertyConstraintListItem::createEditor(QWidget* parent, const QObject* receiver,
const char* method) const
{
Q_UNUSED(receiver);
Q_UNUSED(method);
QLineEdit *le = new QLineEdit(parent);
QLineEdit* le = new QLineEdit(parent);
le->setFrame(false);
le->setReadOnly(true);
return le;
}
void PropertyConstraintListItem::setEditorData(QWidget *editor, const QVariant& data) const
void PropertyConstraintListItem::setEditorData(QWidget* editor, const QVariant& data) const
{
QLineEdit* le = qobject_cast<QLineEdit*>(editor);
le->setText(toString(data).toString());
}
QVariant PropertyConstraintListItem::editorData(QWidget *editor) const
QVariant PropertyConstraintListItem::editorData(QWidget* editor) const
{
QLineEdit *le = qobject_cast<QLineEdit*>(editor);
QLineEdit* le = qobject_cast<QLineEdit*>(editor);
return QVariant(le->text());
}