wiRedPanda
Logic Circuit Simulator
Loading...
Searching...
No Matches
Application.h
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
7
8#pragma once
9
10#include <exception>
11#include <utility>
12
13#include <QApplication>
14#include <QMetaObject>
15#include <QPointer>
16#include <QString>
17
30{
31 QString what;
33 QString file;
34 int line = 0;
35};
36
44class Application : public QApplication
45{
46 Q_OBJECT
47
48 friend class TestApplication;
49
50public:
56 Application(int &argc, char **argv);
57
62 static Application *instance();
63
65 // Same D0/D2 ABI-variant gap as App/Wiring/Port.h's destructor, for a different reason:
66 // every real Application is a stack-local value in main()/runTestSuite() (single instance,
67 // one per process), destroyed via normal scope-exit at process end -- never `delete`d
68 // through any pointer. Grepped every Application::instance() use in the repo: all read-only
69 // (setPalette/font/installTranslator/removeTranslator), none ever delete it, so this class's
70 // own D0 (deleting destructor) never runs; only the direct D1 (complete-object) path does.
71 ~Application() override = default; // LCOV_EXCL_LINE
72
73 // --- Event Handling ---
74
76 bool notify(QObject *receiver, QEvent *event) override;
77
81 inline static bool interactiveMode = true;
82
88 inline static bool renderingEnabled = true;
89
93 inline static bool migrationEnabled = true;
94
98 static bool isSentryDenyMessage(const QString &message);
99
100 // --- Exception handling ---
101
111 static void handleException(const ExceptionInfo &info, const QObject *context);
112
136 template <typename Body>
137 static void guardedSlot(const QObject *context, Body &&body) noexcept
138 {
139 try {
140 std::forward<Body>(body)();
141 } catch (const std::exception &e) {
142 // Synchronous report: tested deferred (Qt::QueuedConnection) on
143 // macOS and the modal QMessageBox::exec() deep inside the queued
144 // dispatch hangs (run 25285325668 — 300 s timeout). The catch
145 // here is below the noexcept boundary so std::terminate is not
146 // triggered; the modal dialog runs in the slot's frame and
147 // returns cleanly before the slot exits.
148 handleException(makeExceptionInfo(e), context);
149 }
150 }
151
152private:
153 Q_DISABLE_COPY(Application)
154
155
157 static ExceptionInfo makeExceptionInfo(const std::exception &e);
158};
Custom QApplication that wraps event dispatch with exception handling.
Definition Application.h:45
static bool migrationEnabled
Definition Application.h:93
static bool isSentryDenyMessage(const QString &message)
bool notify(QObject *receiver, QEvent *event) override
static void guardedSlot(const QObject *context, Body &&body) noexcept
Wraps a slot body in try/catch and reports any exception synchronously, inside the slot's own stack f...
static bool renderingEnabled
Definition Application.h:88
Application(int &argc, char **argv)
Constructs the application with command-line arguments.
static Application * instance()
Returns the application instance cast to Application*.
~Application() override=default
Destructor.
friend class TestApplication
Definition Application.h:48
static void handleException(const ExceptionInfo &info, const QObject *context)
Centralised exception-reporting handler used by both Application::notify (defence-in-depth on Linux/W...
static bool interactiveMode
Definition Application.h:81
Value-captured exception details safe to forward across an event-loop boundary.
Definition Application.h:30
QString what
The translated message for QMessageBox display.
Definition Application.h:31
QString englishMessage
English message for Sentry; equals what for non-Pandaception types.
Definition Application.h:32
QString file
Throw-site file when the exception is a Pandaception, else empty.
Definition Application.h:33
int line
Throw-site line when the exception is a Pandaception, else 0.
Definition Application.h:34