Gui: Prepare for clang-format (#16051)

* Gui: Prepare for clang-format

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
wwmayer
2024-09-02 17:48:55 +02:00
committed by GitHub
parent e98ffc3060
commit 977e13795a
31 changed files with 4133 additions and 3093 deletions

View File

@@ -22,15 +22,15 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QCheckBox>
# include <QLabel>
# include <QLineEdit>
# include <QListWidget>
# include <QListWidgetItem>
# include <QMenu>
# include <QTextStream>
# include <QToolButton>
# include <QVBoxLayout>
#include <QCheckBox>
#include <QLabel>
#include <QLineEdit>
#include <QListWidget>
#include <QListWidgetItem>
#include <QMenu>
#include <QTextStream>
#include <QToolButton>
#include <QVBoxLayout>
#endif
#include <App/ComplexGeoData.h>
@@ -52,11 +52,13 @@ using namespace Gui::DockWnd;
/* TRANSLATOR Gui::DockWnd::SelectionView */
SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)
: DockWindow(pcDocument,parent)
, SelectionObserver(true, ResolveMode::NoResolve)
, x(0.0f), y(0.0f), z(0.0f)
, openedAutomatically(false)
SelectionView::SelectionView(Gui::Document* pcDocument, QWidget* parent)
: DockWindow(pcDocument, parent)
, SelectionObserver(true, ResolveMode::NoResolve)
, x(0.0f)
, y(0.0f)
, z(0.0f)
, openedAutomatically(false)
{
setWindowTitle(tr("Selection View"));
@@ -80,13 +82,13 @@ SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)
countLabel->setText(QString::fromUtf8("0"));
countLabel->setToolTip(tr("The number of selected items"));
hLayout->addWidget(searchBox);
hLayout->addWidget(clearButton,0,Qt::AlignRight);
hLayout->addWidget(countLabel,0,Qt::AlignRight);
hLayout->addWidget(clearButton, 0, Qt::AlignRight);
hLayout->addWidget(countLabel, 0, Qt::AlignRight);
vLayout->addLayout(hLayout);
selectionView = new QListWidget(this);
selectionView->setContextMenuPolicy(Qt::CustomContextMenu);
vLayout->addWidget( selectionView );
vLayout->addWidget(selectionView);
enablePickList = new QCheckBox(this);
enablePickList->setText(tr("Picked object list"));
@@ -95,11 +97,12 @@ SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)
pickList->setVisible(false);
vLayout->addWidget(pickList);
selectionView->setMouseTracking(true); // needed for itemEntered() to work
selectionView->setMouseTracking(true); // needed for itemEntered() to work
pickList->setMouseTracking(true);
resize(200, 200);
// clang-format off
connect(clearButton, &QToolButton::clicked, searchBox, &QLineEdit::clear);
connect(searchBox, &QLineEdit::textChanged, this, &SelectionView::search);
connect(searchBox, &QLineEdit::editingFinished, this, &SelectionView::validateSearch);
@@ -109,11 +112,12 @@ SelectionView::SelectionView(Gui::Document* pcDocument, QWidget *parent)
connect(pickList, &QListWidget::itemEntered, this, &SelectionView::preselect);
connect(selectionView, &QListWidget::customContextMenuRequested, this, &SelectionView::onItemContextMenu);
connect(enablePickList, &QCheckBox::stateChanged, this, &SelectionView::onEnablePickList);
// clang-format on
}
SelectionView::~SelectionView() = default;
void SelectionView::leaveEvent(QEvent *)
void SelectionView::leaveEvent(QEvent*)
{
Selection().rmvPreselect();
}
@@ -279,7 +283,7 @@ void SelectionView::search(const QString& text)
selectionView->clear();
for (auto it : objects) {
QString label = QString::fromUtf8(it->Label.getValue());
if (label.contains(text,Qt::CaseInsensitive)) {
if (label.contains(text, Qt::CaseInsensitive)) {
searchList.push_back(it);
// save as user data
QString selObject;
@@ -310,7 +314,7 @@ void SelectionView::validateSearch()
if (doc) {
Gui::Selection().clearSelection();
for (auto it : searchList) {
Gui::Selection().addSelection(doc->getName(),it->getNameInDocument(),nullptr);
Gui::Selection().addSelection(doc->getName(), it->getNameInDocument(), nullptr);
}
}
}
@@ -318,110 +322,141 @@ void SelectionView::validateSearch()
void SelectionView::select(QListWidgetItem* item)
{
if (!item)
if (!item) {
item = selectionView->currentItem();
if (!item)
}
if (!item) {
return;
}
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.size() < 2)
if (elements.size() < 2) {
return;
}
try {
//Gui::Selection().clearSelection();
Gui::Command::runCommand(Gui::Command::Gui,"Gui.Selection.clearSelection()");
//Gui::Selection().addSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QString::fromLatin1(R"(Gui.Selection.addSelection(App.getDocument("%1").getObject("%2")))").arg(elements[0],elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}catch(Base::Exception &e) {
// Gui::Selection().clearSelection();
Gui::Command::runCommand(Gui::Command::Gui, "Gui.Selection.clearSelection()");
// Gui::Selection().addSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QString::fromLatin1(
R"(Gui.Selection.addSelection(App.getDocument("%1").getObject("%2")))")
.arg(elements[0], elements[1]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
}
catch (Base::Exception& e) {
e.ReportException();
}
}
void SelectionView::deselect()
{
QListWidgetItem *item = selectionView->currentItem();
if (!item)
QListWidgetItem* item = selectionView->currentItem();
if (!item) {
return;
}
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.size() < 2)
if (elements.size() < 2) {
return;
}
//Gui::Selection().rmvSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QString::fromLatin1(R"(Gui.Selection.removeSelection(App.getDocument("%1").getObject("%2")))").arg(elements[0],elements[1]);
// Gui::Selection().rmvSelection(elements[0].toLatin1(),elements[1].toLatin1(),0);
QString cmd = QString::fromLatin1(
R"(Gui.Selection.removeSelection(App.getDocument("%1").getObject("%2")))")
.arg(elements[0], elements[1]);
try {
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}catch(Base::Exception &e) {
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
}
catch (Base::Exception& e) {
e.ReportException();
}
}
void SelectionView::toggleSelect(QListWidgetItem* item)
{
if (!item)
if (!item) {
return;
}
std::string name = item->text().toLatin1().constData();
char *docname = &name.at(0);
char *objname = std::strchr(docname,'#');
if(!objname)
char* docname = &name.at(0);
char* objname = std::strchr(docname, '#');
if (!objname) {
return;
}
*objname++ = 0;
char *subname = std::strchr(objname,'.');
if(subname) {
char* subname = std::strchr(objname, '.');
if (subname) {
*subname++ = 0;
char *end = std::strchr(subname,' ');
if(end) *end = 0;
}else {
char *end = std::strchr(objname,' ');
if(end) *end = 0;
char* end = std::strchr(subname, ' ');
if (end) {
*end = 0;
}
}
else {
char* end = std::strchr(objname, ' ');
if (end) {
*end = 0;
}
}
QString cmd;
if(Gui::Selection().isSelected(docname,objname,subname))
if (Gui::Selection().isSelected(docname, objname, subname)) {
cmd = QString::fromLatin1("Gui.Selection.removeSelection("
"App.getDocument('%1').getObject('%2'),'%3')")
.arg(QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname));
else
"App.getDocument('%1').getObject('%2'),'%3')")
.arg(QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname));
}
else {
cmd = QString::fromLatin1("Gui.Selection.addSelection("
"App.getDocument('%1').getObject('%2'),'%3',%4,%5,%6)")
.arg(QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname))
.arg(x).arg(y).arg(z);
"App.getDocument('%1').getObject('%2'),'%3',%4,%5,%6)")
.arg(QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname))
.arg(x)
.arg(y)
.arg(z);
}
try {
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}catch(Base::Exception &e) {
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
}
catch (Base::Exception& e) {
e.ReportException();
}
}
void SelectionView::preselect(QListWidgetItem* item)
{
if (!item)
if (!item) {
return;
}
std::string name = item->text().toLatin1().constData();
char *docname = &name.at(0);
char *objname = std::strchr(docname,'#');
if(!objname)
char* docname = &name.at(0);
char* objname = std::strchr(docname, '#');
if (!objname) {
return;
}
*objname++ = 0;
char *subname = std::strchr(objname,'.');
if(subname) {
char* subname = std::strchr(objname, '.');
if (subname) {
*subname++ = 0;
char *end = std::strchr(subname,' ');
if(end) *end = 0;
}else {
char *end = std::strchr(objname,' ');
if(end) *end = 0;
char* end = std::strchr(subname, ' ');
if (end) {
*end = 0;
}
}
else {
char* end = std::strchr(objname, ' ');
if (end) {
*end = 0;
}
}
QString cmd = QString::fromLatin1("Gui.Selection.setPreselection("
"App.getDocument('%1').getObject('%2'),'%3',tp=2)")
.arg(QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname));
"App.getDocument('%1').getObject('%2'),'%3',tp=2)")
.arg(QString::fromLatin1(docname),
QString::fromLatin1(objname),
QString::fromLatin1(subname));
try {
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
}catch(Base::Exception &e) {
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
}
catch (Base::Exception& e) {
e.ReportException();
}
}
@@ -430,8 +465,9 @@ void SelectionView::zoom()
{
select();
try {
Gui::Command::runCommand(Gui::Command::Gui,"Gui.SendMsgToActiveView(\"ViewSelection\")");
}catch(Base::Exception &e) {
Gui::Command::runCommand(Gui::Command::Gui, "Gui.SendMsgToActiveView(\"ViewSelection\")");
}
catch (Base::Exception& e) {
e.ReportException();
}
}
@@ -440,53 +476,61 @@ void SelectionView::treeSelect()
{
select();
try {
Gui::Command::runCommand(Gui::Command::Gui,"Gui.runCommand(\"Std_TreeSelection\")");
}catch(Base::Exception &e) {
Gui::Command::runCommand(Gui::Command::Gui, "Gui.runCommand(\"Std_TreeSelection\")");
}
catch (Base::Exception& e) {
e.ReportException();
}
}
void SelectionView::touch()
{
QListWidgetItem *item = selectionView->currentItem();
if (!item)
QListWidgetItem* item = selectionView->currentItem();
if (!item) {
return;
}
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.size() < 2)
if (elements.size() < 2) {
return;
QString cmd = QString::fromLatin1(R"(App.getDocument("%1").getObject("%2").touch())").arg(elements[0],elements[1]);
}
QString cmd = QString::fromLatin1(R"(App.getDocument("%1").getObject("%2").touch())")
.arg(elements[0], elements[1]);
try {
Gui::Command::runCommand(Gui::Command::Doc,cmd.toLatin1());
}catch(Base::Exception &e) {
Gui::Command::runCommand(Gui::Command::Doc, cmd.toLatin1());
}
catch (Base::Exception& e) {
e.ReportException();
}
}
void SelectionView::toPython()
{
QListWidgetItem *item = selectionView->currentItem();
if (!item)
QListWidgetItem* item = selectionView->currentItem();
if (!item) {
return;
}
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.size() < 2)
if (elements.size() < 2) {
return;
}
try {
QString cmd = QString::fromLatin1(R"(obj = App.getDocument("%1").getObject("%2"))").arg(elements[0], elements[1]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
QString cmd = QString::fromLatin1(R"(obj = App.getDocument("%1").getObject("%2"))")
.arg(elements[0], elements[1]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
if (elements.length() > 2) {
App::Document* doc = App::GetApplication().getDocument(elements[0].toLatin1());
App::DocumentObject* obj = doc->getObject(elements[1].toLatin1());
QString property = getProperty(obj);
cmd = QString::fromLatin1(R"(shp = App.getDocument("%1").getObject("%2").%3)")
.arg(elements[0], elements[1], property);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
.arg(elements[0], elements[1], property);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
if (supportPart(obj, elements[2])) {
cmd = QString::fromLatin1(R"(elt = App.getDocument("%1").getObject("%2").%3.%4)")
.arg(elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
.arg(elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
}
}
}
@@ -497,9 +541,10 @@ void SelectionView::toPython()
void SelectionView::showPart()
{
QListWidgetItem *item = selectionView->currentItem();
if (!item)
QListWidgetItem* item = selectionView->currentItem();
if (!item) {
return;
}
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.length() > 2) {
App::Document* doc = App::GetApplication().getDocument(elements[0].toLatin1());
@@ -509,9 +554,10 @@ void SelectionView::showPart()
if (!module.isEmpty() && !property.isEmpty() && supportPart(obj, elements[2])) {
try {
Gui::Command::addModule(Gui::Command::Gui, module.toLatin1());
QString cmd = QString::fromLatin1(R"(%1.show(App.getDocument("%2").getObject("%3").%4.%5))")
QString cmd =
QString::fromLatin1(R"(%1.show(App.getDocument("%2").getObject("%3").%4.%5))")
.arg(module, elements[0], elements[1], property, elements[2]);
Gui::Command::runCommand(Gui::Command::Gui,cmd.toLatin1());
Gui::Command::runCommand(Gui::Command::Gui, cmd.toLatin1());
}
catch (const Base::Exception& e) {
e.ReportException();
@@ -532,12 +578,15 @@ QString SelectionView::getModule(const char* type) const
std::string::size_type pos = temp.find_first_of("::");
std::string module;
if (pos != std::string::npos)
module = std::string(temp,0,pos);
if (module != "App")
if (pos != std::string::npos) {
module = std::string(temp, 0, pos);
}
if (module != "App") {
prefix = module;
else
}
else {
break;
}
typeId = typeId.getParent();
}
@@ -568,8 +617,9 @@ bool SelectionView::supportPart(App::DocumentObject* obj, const QString& part) c
const Data::ComplexGeoData* geometry = data->getComplexData();
std::vector<const char*> types = geometry->getElementTypes();
for (auto it : types) {
if (part.startsWith(QString::fromLatin1(it)))
if (part.startsWith(QString::fromLatin1(it))) {
return true;
}
}
}
}
@@ -579,39 +629,43 @@ bool SelectionView::supportPart(App::DocumentObject* obj, const QString& part) c
void SelectionView::onItemContextMenu(const QPoint& point)
{
QListWidgetItem *item = selectionView->itemAt(point);
if (!item)
QListWidgetItem* item = selectionView->itemAt(point);
if (!item) {
return;
}
QMenu menu;
QAction *selectAction = menu.addAction(tr("Select only"), this, [&]{
QAction* selectAction = menu.addAction(tr("Select only"), this, [&] {
this->select(nullptr);
});
selectAction->setIcon(QIcon::fromTheme(QString::fromLatin1("view-select")));
selectAction->setToolTip(tr("Selects only this object"));
QAction *deselectAction = menu.addAction(tr("Deselect"), this, &SelectionView::deselect);
QAction* deselectAction = menu.addAction(tr("Deselect"), this, &SelectionView::deselect);
deselectAction->setIcon(QIcon::fromTheme(QString::fromLatin1("view-unselectable")));
deselectAction->setToolTip(tr("Deselects this object"));
QAction *zoomAction = menu.addAction(tr("Zoom fit"), this, &SelectionView::zoom);
QAction* zoomAction = menu.addAction(tr("Zoom fit"), this, &SelectionView::zoom);
zoomAction->setIcon(QIcon::fromTheme(QString::fromLatin1("zoom-fit-best")));
zoomAction->setToolTip(tr("Selects and fits this object in the 3D window"));
QAction *gotoAction = menu.addAction(tr("Go to selection"), this, &SelectionView::treeSelect);
QAction* gotoAction = menu.addAction(tr("Go to selection"), this, &SelectionView::treeSelect);
gotoAction->setToolTip(tr("Selects and locates this object in the tree view"));
QAction *touchAction = menu.addAction(tr("Mark to recompute"), this, &SelectionView::touch);
QAction* touchAction = menu.addAction(tr("Mark to recompute"), this, &SelectionView::touch);
touchAction->setIcon(QIcon::fromTheme(QString::fromLatin1("view-refresh")));
touchAction->setToolTip(tr("Mark this object to be recomputed"));
QAction *toPythonAction = menu.addAction(tr("To python console"), this, &SelectionView::toPython);
QAction* toPythonAction =
menu.addAction(tr("To python console"), this, &SelectionView::toPython);
toPythonAction->setIcon(QIcon::fromTheme(QString::fromLatin1("applications-python")));
toPythonAction->setToolTip(tr("Reveals this object and its subelements in the python console."));
toPythonAction->setToolTip(
tr("Reveals this object and its subelements in the python console."));
QStringList elements = item->data(Qt::UserRole).toStringList();
if (elements.length() > 2) {
// subshape-specific entries
QAction *showPart = menu.addAction(tr("Duplicate subshape"), this, &SelectionView::showPart);
QAction* showPart =
menu.addAction(tr("Duplicate subshape"), this, &SelectionView::showPart);
showPart->setIcon(QIcon(QString::fromLatin1(":/icons/ClassBrowser/member.svg")));
showPart->setToolTip(tr("Creates a standalone copy of this subshape in the document"));
}
@@ -619,24 +673,26 @@ void SelectionView::onItemContextMenu(const QPoint& point)
}
void SelectionView::onUpdate()
{
}
{}
bool SelectionView::onMsg(const char* /*pMsg*/,const char** /*ppReturn*/)
bool SelectionView::onMsg(const char* /*pMsg*/, const char** /*ppReturn*/)
{
return false;
}
void SelectionView::hideEvent(QHideEvent *ev) {
void SelectionView::hideEvent(QHideEvent* ev)
{
DockWindow::hideEvent(ev);
}
void SelectionView::showEvent(QShowEvent *ev) {
void SelectionView::showEvent(QShowEvent* ev)
{
enablePickList->setChecked(Selection().needPickedList());
Gui::DockWindow::showEvent(ev);
}
void SelectionView::onEnablePickList() {
void SelectionView::onEnablePickList()
{
bool enabled = enablePickList->isChecked();
Selection().enablePickedList(enabled);
pickList->setVisible(enabled);