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
48public:
54 Application(int &argc, char **argv);
55
60 static Application *instance();
61
63 ~Application() override = default;
64
65 // --- Event Handling ---
66
68 bool notify(QObject *receiver, QEvent *event) override;
69
73 inline static bool interactiveMode = true;
74
80 inline static bool renderingEnabled = true;
81
85 inline static bool migrationEnabled = true;
86
90 static bool isSentryDenyMessage(const QString &message);
91
92 // --- Exception handling ---
93
103 static void handleException(const ExceptionInfo &info, const QObject *context);
104
128 template <typename Body>
129 static void guardedSlot(const QObject *context, Body &&body) noexcept
130 {
131 try {
132 std::forward<Body>(body)();
133 } catch (const std::exception &e) {
134 // Synchronous report: tested deferred (Qt::QueuedConnection) on
135 // macOS and the modal QMessageBox::exec() deep inside the queued
136 // dispatch hangs (run 25285325668 — 300 s timeout). The catch
137 // here is below the noexcept boundary so std::terminate is not
138 // triggered; the modal dialog runs in the slot's frame and
139 // returns cleanly before the slot exits.
140 handleException(makeExceptionInfo(e), context);
141 }
142 }
143
144private:
145 Q_DISABLE_COPY(Application)
146
147
149 static ExceptionInfo makeExceptionInfo(const std::exception &e);
150};
Custom QApplication that wraps event dispatch with exception handling.
Definition Application.h:45
static bool migrationEnabled
Definition Application.h:85
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:80
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.
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:73
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