swift
settingssimulatormessagescomponent.cpp
1 // SPDX-FileCopyrightText: Copyright (C) 2016 swift Project Community / Contributors
2 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3 
5 
6 #include "ui_settingssimulatormessagescomponent.h"
7 
9 
10 using namespace swift::misc;
11 using namespace swift::misc::simulation;
12 using namespace swift::misc::simulation::settings;
13 
14 namespace swift::gui::components
15 {
16  CSettingsSimulatorMessagesComponent::CSettingsSimulatorMessagesComponent(QWidget *parent)
17  : QFrame(parent), ui(new Ui::CSettingsSimulatorMessagesComponent)
18  {
19  ui->setupUi(this);
20  connect(ui->pb_Save, &QPushButton::clicked, this, &CSettingsSimulatorMessagesComponent::save,
21  Qt::QueuedConnection);
22  connect(ui->pb_Cancel, &QPushButton::clicked, this, &CSettingsSimulatorMessagesComponent::load,
23  Qt::QueuedConnection);
24 
25  this->load();
26  }
27 
29 
30  void CSettingsSimulatorMessagesComponent::save()
31  {
33  settings.setRelayGloballyEnabled(ui->cb_Messages->isChecked());
34  if (ui->rb_NoTechnicalMessages->isChecked()) { settings.disableTechnicalMessages(); }
35  else if (ui->rb_ErrorsOnly->isChecked()) { settings.setTechnicalLogSeverity(CStatusMessage::SeverityError); }
36  else if (ui->rb_ErrorsAndWarnings->isChecked())
37  {
38  settings.setTechnicalLogSeverity(CStatusMessage::SeverityWarning);
39  }
40  else if (ui->rb_ErrorWarningsInfo->isChecked())
41  {
42  settings.setTechnicalLogSeverity(CStatusMessage::SeverityInfo);
43  }
44 
45  settings.setRelayGloballyEnabled(ui->cb_Messages->isChecked());
46  CSimulatorMessagesSettings::TextMessageType mt = CSimulatorMessagesSettings::NoTextMessages;
47 
48  if (ui->cb_PrivateMessages->isChecked()) { mt |= CSimulatorMessagesSettings::TextMessagePrivate; }
49  if (ui->cb_SupervisorMessages->isChecked()) { mt |= CSimulatorMessagesSettings::TextMessageSupervisor; }
50  if (ui->cb_Com1->isChecked()) { mt |= CSimulatorMessagesSettings::TextMessagesCom1; }
51  if (ui->cb_Com2->isChecked()) { mt |= CSimulatorMessagesSettings::TextMessagesCom2; };
52  settings.setRelayTextMessages(mt);
53 
54  // save
55  this->m_settings.setAndSave(settings);
56  }
57 
58  void CSettingsSimulatorMessagesComponent::load()
59  {
60  const CSimulatorMessagesSettings settings(this->m_settings.get());
61  ui->cb_Messages->setChecked(settings.isRelayGloballyEnabled());
62  if (settings.isRelayInfoMessages()) { ui->rb_ErrorWarningsInfo->setChecked(true); }
63  else if (settings.isRelayWarningMessages()) { ui->rb_ErrorsAndWarnings->setChecked(true); }
64  else if (settings.isRelayErrorsMessages()) { ui->rb_ErrorsOnly->setChecked(true); }
65  else if (!settings.isRelayTechnicalMessages()) { ui->rb_NoTechnicalMessages->setChecked(true); }
66 
67  ui->cb_PrivateMessages->setChecked(settings.isRelayPrivateTextMessages());
68  ui->cb_SupervisorMessages->setChecked(settings.isRelaySupervisorTextMessages());
69  ui->cb_Com1->setChecked(settings.isRelayCom1TextMessages());
70  ui->cb_Com2->setChecked(settings.isRelayCom2TextMessages());
71  }
72 } // namespace swift::gui::components
CStatusMessage setAndSave(const T &value, qint64 timestamp=0)
Write and save in the same step. Must be called from the thread in which the owner lives.
Definition: valuecache.h:417
T get() const
Get a copy of the current value.
Definition: valuecache.h:408
Settings regarding message handling. Driver independent part, related to network.
bool isRelayErrorsMessages() const
Relay (technical) error messages.
void setRelayGloballyEnabled(bool enabled)
Globally enable / disable.
bool isRelayWarningMessages() const
Relay (technical) warning messages.
bool isRelayInfoMessages() const
Relay (technical) info messages.
bool isRelaySupervisorTextMessages() const
Relay supervisor messages.
void setTechnicalLogSeverity(CStatusMessage::StatusSeverity severity)
Log severity.
void setRelayTextMessages(CSimulatorMessagesSettings::TextMessageType messageType)
Relay the following message types.
High level reusable GUI components.
Definition: aboutdialog.cpp:13
Free functions in swift::misc.