8 #include <QDesktopServices>
10 #include <QPushButton>
17 #include "ui_internalscomponent.h"
38 using namespace swift::config;
40 using namespace swift::misc::aviation;
41 using namespace swift::misc::network;
42 using namespace swift::misc::math;
43 using namespace swift::misc::physical_quantities;
44 using namespace swift::misc::simulation;
48 CInternalsComponent::CInternalsComponent(QWidget *parent) : QWidget(parent), ui(new Ui::
CInternalsComponent)
51 ui->tw_Internals->setCurrentIndex(0);
57 connect(ui->cb_DebugContextAudio, &QCheckBox::stateChanged,
this, &CInternalsComponent::enableDebug);
58 connect(ui->cb_DebugContextApplication, &QCheckBox::stateChanged,
this, &CInternalsComponent::enableDebug);
59 connect(ui->cb_DebugContextNetwork, &QCheckBox::stateChanged,
this, &CInternalsComponent::enableDebug);
60 connect(ui->cb_DebugContextOwnAircraft, &QCheckBox::stateChanged,
this, &CInternalsComponent::enableDebug);
61 connect(ui->cb_DebugContextSimulator, &QCheckBox::stateChanged,
this, &CInternalsComponent::enableDebug);
63 connect(ui->pb_SendTextMessageDirectly, &QPushButton::released,
this, &CInternalsComponent::sendTextMessage,
64 Qt::QueuedConnection);
65 connect(ui->pb_SendTextMessageDeferred, &QPushButton::released,
this, &CInternalsComponent::sendTextMessage,
66 Qt::QueuedConnection);
68 connect(ui->tb_LogStatusMessage, &QPushButton::released,
this, &CInternalsComponent::logStatusMessage);
69 connect(ui->le_StatusMessage, &QLineEdit::returnPressed,
this, &CInternalsComponent::logStatusMessage);
71 connect(ui->pb_LatestInterpolationLog, &QPushButton::released,
this, &CInternalsComponent::showLogFiles);
72 connect(ui->pb_LatestPartsLog, &QPushButton::released,
this, &CInternalsComponent::showLogFiles);
73 connect(ui->pb_SendAtis, &QPushButton::released,
this, &CInternalsComponent::sendAtis);
75 connect(ui->pb_NetworkUpdateAndReset, &QPushButton::released,
this, &CInternalsComponent::networkStatistics);
76 connect(ui->pb_NetworkUpdate, &QPushButton::released,
this, &CInternalsComponent::networkStatistics);
77 connect(ui->cb_NetworkStatistics, &QCheckBox::stateChanged,
this,
78 &CInternalsComponent::onNetworkStatisticsToggled);
82 ui->cb_CrashDumpUpload->setChecked(CCrashHandler::instance()->isCrashDumpUploadEnabled());
83 connect(ui->pb_SimulateCrash, &QPushButton::released,
this, &CInternalsComponent::simulateCrash,
84 Qt::QueuedConnection);
85 connect(ui->pb_SimulateAssert, &QPushButton::released,
this, &CInternalsComponent::simulateAssert,
86 Qt::QueuedConnection);
87 connect(ui->cb_CrashDumpUpload, &QCheckBox::toggled,
this, &CInternalsComponent::onCrashDumpUploadToggled);
91 ui->pb_SimulateCrash->setEnabled(
false);
92 ui->cb_CrashDumpUpload->setEnabled(
false);
95 this->contextFlagsToGui();
103 this->contextFlagsToGui();
104 QWidget::showEvent(event);
107 void CInternalsComponent::enableDebug(
int state)
115 const Qt::CheckState checkState =
static_cast<Qt::CheckState
>(state);
116 const bool debug = (checkState == Qt::Checked);
117 const QObject *sender = QObject::sender();
126 void CInternalsComponent::sendTextMessage()
129 if (ui->le_TxtMsgFrom->text().isEmpty()) {
return; }
130 if (ui->pte_TxtMsg->toPlainText().isEmpty()) {
return; }
131 if (ui->le_TxtMsgTo->text().isEmpty() && ui->dsb_TxtMsgFrequency->text().isEmpty()) {
return; }
134 const QObject *senderObj = QObject::sender();
135 if (senderObj == ui->pb_SendTextMessageDeferred)
141 const CCallsign sender(ui->le_TxtMsgFrom->text().trimmed());
142 const CCallsign recipient(ui->le_TxtMsgTo->text().trimmed());
143 const QString msgTxt(ui->pte_TxtMsg->toPlainText().trimmed());
144 const double freqMHz = CMathUtils::round(ui->dsb_TxtMsgFrequency->value(), 3);
146 if (recipient.isEmpty() && freqMHz >= 117.995)
150 CComSystem::roundToChannelSpacing(f, CComSystem::ChannelSpacing8_33KHz);
158 void CInternalsComponent::sendAtis()
161 if (ui->le_AtisCallsign->text().isEmpty()) {
return; }
162 if (ui->pte_Atis->toPlainText().isEmpty()) {
return; }
163 const CCallsign cs(ui->le_AtisCallsign->text());
164 const QString text(ui->pte_Atis->toPlainText());
170 void CInternalsComponent::logStatusMessage()
172 if (ui->le_StatusMessage->text().isEmpty()) {
return; }
174 if (ui->rb_StatusMessageError->isChecked()) { s = CStatusMessage::SeverityError; }
175 else if (ui->rb_StatusMessageWarning->isChecked()) { s = CStatusMessage::SeverityWarning; }
176 else if (ui->rb_StatusMessageInfo->isChecked()) { s = CStatusMessage::SeverityInfo; }
178 CLogMessage::preformatted(sm);
181 void CInternalsComponent::showLogFiles()
184 const QObject *sender = QObject::sender();
185 if (sender == ui->pb_LatestInterpolationLog) { file = CInterpolationLogger::getLatestLogFiles().first(); }
186 else if (sender == ui->pb_LatestPartsLog) { file = CInterpolationLogger::getLatestLogFiles().last(); }
188 if (file.isEmpty()) {
return; }
189 QDesktopServices::openUrl(QUrl::fromLocalFile(file));
192 void CInternalsComponent::contextFlagsToGui()
200 void CInternalsComponent::simulateCrash()
202 if (CBuildConfig::isReleaseBuild())
204 QMessageBox::information(
this,
"crash simulation",
"Not possible in release builds!");
208 const QMessageBox::StandardButton reply = QMessageBox::question(
209 this,
"crash simulation",
"Really simulate crash?", QMessageBox::Yes | QMessageBox::No);
210 if (!
sGui || reply != QMessageBox::Yes) {
return; }
211 sGui->simulateCrash();
214 void CInternalsComponent::simulateAssert()
216 if (CBuildConfig::isReleaseBuild())
218 QMessageBox::information(
this,
"ASSERT simulation",
"Not possible in release builds!");
222 const QMessageBox::StandardButton reply = QMessageBox::question(
223 this,
"ASSERT simulation",
"Really create an ASSERT?", QMessageBox::Yes | QMessageBox::No);
224 if (!
sGui || reply != QMessageBox::Yes) {
return; }
225 sGui->simulateAssert();
228 void CInternalsComponent::onCrashDumpUploadToggled(
bool checked)
232 const bool current = CCrashHandler::instance()->isCrashDumpUploadEnabled();
233 if (current == checked) {
return; }
238 void CInternalsComponent::networkStatistics()
241 const bool reset = (QObject::sender() == ui->pb_NetworkUpdateAndReset);
243 ui->pte_NetworkCalls->setPlainText(statistics);
246 void CInternalsComponent::onNetworkStatisticsToggled(
bool checked)
const context::IContextAudio * getIContextAudio() const
Direct access to contexts if a CCoreFacade has been initialized.
const context::IContextOwnAircraft * getIContextOwnAircraft() const
Direct access to contexts if a CCoreFacade has been initialized.
const context::IContextApplication * getIContextApplication() const
Direct access to contexts if a CCoreFacade has been initialized.
const context::IContextNetwork * getIContextNetwork() const
Direct access to contexts if a CCoreFacade has been initialized.
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
void enableCrashDumpUpload(bool enable)
Enable crash upload.
bool isSupportingCrashpad() const
Has crashpad support?
void setDebugEnabled(bool debug)
Set debug flag.
bool isDebugEnabled() const
Debug enabled?
virtual QString getNetworkStatistics(bool reset, const QString &separator)=0
Statistics info.
virtual void testReceivedTextMessages(const swift::misc::network::CTextMessageList &textMessages)=0
Inject a text message as received.
virtual void testReceivedAtisMessage(const swift::misc::aviation::CCallsign &callsign, const swift::misc::aviation::CInformationMessage &msg)=0
Inject an ATIS.
virtual bool setNetworkStatisticsEnable(bool enabled)=0
Statistics enable/disable.
Internals for debugging, statistics.
virtual ~CInternalsComponent()
Destructor.
virtual void showEvent(QShowEvent *event)
Class for emitting a log message.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Streamable status message, e.g.
void setCurrentUtcTime()
Set the current time as timestamp.
Value object encapsulating information of a callsign.
Value object encapsulating information of a text message.
Value object encapsulating a list of text messages.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Free functions in swift::misc.
SWIFT_MISC_EXPORT const QString & boolToOnOff(bool v)
Bool to on/off.
StatusSeverity
Status severities.
auto singleShot(int msec, QObject *target, F &&task)
Starts a single-shot timer which will call a task in the thread of the given object when it times out...