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

@@ -21,11 +21,9 @@
***************************************************************************/
# include <cassert>
# include <QFile>
# include <QTextStream>
#include <cassert>
#include <QFile>
#include <QTextStream>
#include <App/Application.h>
@@ -44,7 +42,7 @@ using namespace Gui;
MacroFile::MacroFile() = default;
void MacroFile::open(const char *sName)
void MacroFile::open(const char* sName)
{
// check
#if _DEBUG
@@ -53,8 +51,9 @@ void MacroFile::open(const char *sName)
// Convert from Utf-8
this->macroName = QString::fromUtf8(sName);
if (!this->macroName.endsWith(QLatin1String(".FCMacro")))
if (!this->macroName.endsWith(QLatin1String(".FCMacro"))) {
this->macroName += QLatin1String(".FCMacro");
}
this->macroInProgress.clear();
this->openMacro = true;
@@ -79,7 +78,7 @@ bool MacroFile::commit()
// sort import lines and avoid duplicates
QTextStream str(&file);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
str.setCodec("UTF-8");
#endif
QStringList importCommand;
@@ -87,8 +86,7 @@ bool MacroFile::commit()
QStringList body;
for (const auto& it : std::as_const(this->macroInProgress)) {
if (it.startsWith(QLatin1String("import ")) ||
it.startsWith(QLatin1String("#import "))) {
if (it.startsWith(QLatin1String("import ")) || it.startsWith(QLatin1String("#import "))) {
if (importCommand.indexOf(it) == -1) {
importCommand.push_back(it);
}
@@ -203,10 +201,12 @@ bool MacroOutputOption::isAppCommand(int type)
// ----------------------------------------------------------------------------
MacroManager::MacroManager()
: pyDebugger(new PythonDebugger())
: pyDebugger(new PythonDebugger())
{
// Attach to the Parametergroup regarding macros
this->params = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/Macro");
this->params = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Macro"
);
this->params->Attach(this);
this->params->NotifyAll();
}
@@ -219,17 +219,17 @@ MacroManager::~MacroManager()
std::stack<std::function<void(MacroManager::LineType, const char*)>> MacroManager::redirectFuncs;
void MacroManager::OnChange(Base::Subject<const char*> &rCaller, const char * sReason)
void MacroManager::OnChange(Base::Subject<const char*>& rCaller, const char* sReason)
{
(void)rCaller;
(void)sReason;
option.recordGui = this->params->GetBool("RecordGui", true);
option.guiAsComment = this->params->GetBool("GuiAsComment", true);
option.recordGui = this->params->GetBool("RecordGui", true);
option.guiAsComment = this->params->GetBool("GuiAsComment", true);
option.scriptToPyConsole = this->params->GetBool("ScriptToPyConsole", true);
this->localEnv = this->params->GetBool("LocalEnvironment", true);
this->localEnv = this->params->GetBool("LocalEnvironment", true);
}
void MacroManager::open(MacroType eType, const char *sName)
void MacroManager::open(MacroType eType, const char* sName)
{
// check
#if _DEBUG
@@ -249,8 +249,7 @@ void MacroManager::commit()
Base::Console().log("Commit macro: %s\n", (const char*)macroName.toUtf8());
}
else {
Base::Console().error("Cannot open file to write macro: %s\n",
(const char*)macroName.toUtf8());
Base::Console().error("Cannot open file to write macro: %s\n", (const char*)macroName.toUtf8());
cancel();
}
}
@@ -258,7 +257,7 @@ void MacroManager::commit()
void MacroManager::cancel()
{
QString macroName = macroFile.fileName();
Base::Console().log("Cancel macro: %s\n",(const char*)macroName.toUtf8());
Base::Console().log("Cancel macro: %s\n", (const char*)macroName.toUtf8());
macroFile.cancel();
}
@@ -273,8 +272,9 @@ void MacroManager::addLine(LineType Type, const char* sLine)
return;
}
std::function<void(LineType, const char*)> redirectFunc =
redirectFuncs.empty() ? nullptr : redirectFuncs.top();
std::function<void(LineType, const char*)> redirectFunc = redirectFuncs.empty()
? nullptr
: redirectFuncs.top();
if (redirectFunc) {
redirectFunc(Type, sLine);
return;
@@ -297,14 +297,14 @@ void MacroManager::processPendingLines()
{
decltype(buffer.pendingLine) lines;
lines.swap(buffer.pendingLine);
for (auto &v : lines) {
for (auto& v : lines) {
addLine(static_cast<LineType>(v.first), v.second.c_str());
}
}
void MacroManager::makeComment(QStringList& lines) const
{
for (auto &line : lines) {
for (auto& line : lines) {
if (!line.startsWith(QLatin1String("#"))) {
line.prepend(QLatin1String("# "));
}
@@ -328,7 +328,7 @@ void MacroManager::addToOutput(LineType type, const char* line)
// search for the Python console
auto console = getPythonConsole();
if (console) {
for(auto &line : lines) {
for (auto& line : lines) {
console->printStatement(line);
}
}
@@ -337,7 +337,7 @@ void MacroManager::addToOutput(LineType type, const char* line)
void MacroManager::setModule(const char* sModule)
{
if (macroFile.isOpen() && sModule && *sModule != '\0') {
if (macroFile.isOpen() && sModule && *sModule != '\0') {
macroFile.append(QStringLiteral("import %1").arg(QString::fromLatin1(sModule)));
}
}
@@ -352,45 +352,52 @@ PythonConsole* MacroManager::getPythonConsole() const
return this->pyConsole;
}
namespace Gui {
class PythonRedirector
namespace Gui
{
class PythonRedirector
{
public:
PythonRedirector(const char* type, PyObject* obj)
: std_out(type)
, out(obj)
{
public:
PythonRedirector(const char* type, PyObject* obj) : std_out(type), out(obj)
{
if (out) {
Base::PyGILStateLocker lock;
old = PySys_GetObject(std_out);
PySys_SetObject(std_out, out);
}
if (out) {
Base::PyGILStateLocker lock;
old = PySys_GetObject(std_out);
PySys_SetObject(std_out, out);
}
~PythonRedirector()
{
if (out) {
Base::PyGILStateLocker lock;
PySys_SetObject(std_out, old);
Py_DECREF(out);
}
}
~PythonRedirector()
{
if (out) {
Base::PyGILStateLocker lock;
PySys_SetObject(std_out, old);
Py_DECREF(out);
}
private:
const char* std_out;
PyObject* out;
PyObject* old{nullptr};
};
}
}
void MacroManager::run(MacroType eType, const char *sName)
private:
const char* std_out;
PyObject* out;
PyObject* old {nullptr};
};
} // namespace Gui
void MacroManager::run(MacroType eType, const char* sName)
{
Q_UNUSED(eType);
try {
ParameterGrp::handle hGrp = App::GetApplication().GetUserParameter()
.GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("OutputWindow");
PyObject* pyout = hGrp->GetBool("RedirectPythonOutput",true) ? new OutputStdout : nullptr;
PyObject* pyerr = hGrp->GetBool("RedirectPythonErrors",true) ? new OutputStderr : nullptr;
PythonRedirector std_out("stdout",pyout);
PythonRedirector std_err("stderr",pyerr);
//The given path name is expected to be Utf-8
ParameterGrp::handle hGrp = App::GetApplication()
.GetUserParameter()
.GetGroup("BaseApp")
->GetGroup("Preferences")
->GetGroup("OutputWindow");
PyObject* pyout = hGrp->GetBool("RedirectPythonOutput", true) ? new OutputStdout : nullptr;
PyObject* pyerr = hGrp->GetBool("RedirectPythonErrors", true) ? new OutputStderr : nullptr;
PythonRedirector std_out("stdout", pyout);
PythonRedirector std_err("stderr", pyerr);
// The given path name is expected to be Utf-8
Base::Interpreter().runFile(sName, this->localEnv);
}
catch (const Base::SystemExitException&) {
@@ -400,7 +407,7 @@ void MacroManager::run(MacroType eType, const char *sName)
e.reportException();
}
catch (const Base::Exception& e) {
qWarning("%s",e.what());
qWarning("%s", e.what());
}
}