wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Common.cpp
Go to the documentation of this file.
1// Copyright 2015 - 2026, GIBIS-UNIFESP and the wiRedPanda contributors
2// SPDX-License-Identifier: GPL-3.0-or-later
3
4#include "App/Core/Common.h"
5
6Q_LOGGING_CATEGORY(zero, "0")
7Q_LOGGING_CATEGORY(one, "1")
8Q_LOGGING_CATEGORY(two, "2")
9Q_LOGGING_CATEGORY(three, "3")
10Q_LOGGING_CATEGORY(four, "4")
11Q_LOGGING_CATEGORY(five, "5")
12
13void Comment::setVerbosity(const int verbosity)
14{
15 QString rules;
16
17 // Category i carries detail level i (0 = coarsest). A given verbosity
18 // enables categories 0..verbosity-1; verbosity 5 means "everything"
19 // (category five included — the old fall-through cascade appended
20 // "5 = false" in every case, so category five was unreachable). Values
21 // above 5 behave like 5; negative / 0 (the production default) disable
22 // all output.
23 for (int i = 0; i <= 5; ++i) {
24 const bool enabled = (i < 5) ? (verbosity > i) : (verbosity >= 5);
25 rules += QString("%1 = %2\n").arg(i).arg(enabled ? "true" : "false");
26 }
27
28 QLoggingCategory::setFilterRules(rules);
29
30 // Include file line and function name in debug output for faster navigation.
31 qSetMessagePattern("%{if-debug}%{line}: %{function} => %{endif}%{message}");
32}
33
34Pandaception::Pandaception(const QString &translatedMessage, const QString &englishMessage,
35 const char *file, int line)
36 // std::runtime_error carries the translated message so that what() shown in
37 // the UI respects the current locale. The English copy is kept separately
38 // for crash-reporting backends (Sentry) that need a language-stable string.
39 : std::runtime_error(translatedMessage.toStdString())
40 , m_englishMessage(englishMessage)
41 , m_file(file)
42 , m_line(line)
43{
44}
45
46// Key function — see header for rationale. Must remain out-of-line and
47// non-inline so the Itanium ABI emits Pandaception's typeinfo here only.
49
51{
52 return m_englishMessage;
53}
54
55const char *Pandaception::file() const
56{
57 return m_file;
58}
59
61{
62 return m_line;
63}
Common logging utilities, the Pandaception error type, and helper macros.
Controls the verbosity level of diagnostic logging categories.
Definition Common.h:37
static void setVerbosity(const int verbosity)
Sets the active logging verbosity level.
Definition Common.cpp:13
QString englishMessage() const
Returns the English (non-translated) message for logging and crash reports.
Definition Common.cpp:50
const char * file() const
Returns the source file where the exception was thrown, or nullptr.
Definition Common.cpp:55
Pandaception(const QString &translatedMessage, const QString &englishMessage, const char *file=nullptr, int line=0)
Constructs the exception with throw-site location for Sentry.
Definition Common.cpp:34
~Pandaception() override
int line() const
Returns the source line where the exception was thrown, or 0.
Definition Common.cpp:60