8 #include "ui_interpolationsetupcomponent.h"
18 using namespace swift::misc::aviation;
19 using namespace swift::misc::simulation;
20 using namespace swift::core::context;
24 CInterpolationSetupComponent::CInterpolationSetupComponent(QWidget *parent)
28 ui->cb_IgnoreGlobal->setChecked(
true);
29 ui->tvp_InterpolationSetup->menuAddItems(CInterpolationSetupView::MenuRemoveSelectedRows);
31 connect(ui->pb_Save, &QPushButton::clicked,
this, &CInterpolationSetupComponent::saveSetup);
32 connect(ui->pb_DeleteOrReset, &QPushButton::clicked,
this, &CInterpolationSetupComponent::removeOrResetSetup);
33 connect(ui->pb_Reload, &QPushButton::clicked,
this, &CInterpolationSetupComponent::reloadSetup,
34 Qt::QueuedConnection);
35 connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::doubleClicked,
this,
36 &CInterpolationSetupComponent::onRowDoubleClicked);
37 connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::modelChanged,
this,
38 &CInterpolationSetupComponent::onModelChanged, Qt::QueuedConnection);
39 connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::modelDataChanged,
this,
40 &CInterpolationSetupComponent::onModelChanged, Qt::QueuedConnection);
41 connect(ui->tvp_InterpolationSetup, &CInterpolationSetupView::objectsDeleted,
this,
42 &CInterpolationSetupComponent::onObjectsDeleted, Qt::QueuedConnection);
43 connect(ui->rb_Callsign, &QRadioButton::released,
this, &CInterpolationSetupComponent::onModeChanged);
44 connect(ui->rb_Global, &QRadioButton::released,
this, &CInterpolationSetupComponent::onModeChanged);
48 &CInterpolationSetupComponent::onSetupChanged, Qt::QueuedConnection);
51 ui->rb_Global->setChecked(
true);
53 QPointer<CInterpolationSetupComponent> myself(
this);
56 if (!myself) {
return; }
57 this->onModeChanged();
62 if (!myself) {
return; }
63 this->onSetupChanged();
71 return ui->rb_Callsign->isChecked() ? CInterpolationSetupComponent::SetupPerCallsign :
72 CInterpolationSetupComponent::SetupGlobal;
75 void CInterpolationSetupComponent::onRowDoubleClicked(
const QModelIndex &index)
77 if (!index.isValid()) {
return; }
79 ui->form_InterpolationSetup->setValue(setup);
80 ui->comp_CallsignCompleter->setCallsign(setup.
getCallsign());
81 ui->comp_CallsignCompleter->setReadOnly(
false);
82 ui->rb_Callsign->setChecked(
true);
85 void CInterpolationSetupComponent::onModeChanged()
88 bool enableCallsign =
false;
89 if (this->
getSetupMode() == CInterpolationSetupComponent::SetupGlobal) { this->setUiValuesFromGlobal(); }
90 else { enableCallsign =
true; }
91 this->displaySetupsPerCallsign();
92 ui->comp_CallsignCompleter->setReadOnly(!enableCallsign);
93 ui->pb_DeleteOrReset->setText(enableCallsign ?
"delete" :
"reset");
96 void CInterpolationSetupComponent::onModelChanged()
101 void CInterpolationSetupComponent::onReloadSetup()
104 this->displaySetupsPerCallsign();
107 void CInterpolationSetupComponent::reloadSetup()
109 const bool global = (this->
getSetupMode() == CInterpolationSetupComponent::SetupGlobal);
110 const bool overlay = QObject::sender() == ui->pb_Reload;
111 if (!this->checkPrerequisites(!global, overlay)) {
return; }
116 ui->form_InterpolationSetup->setValue(gs);
120 const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(
false);
124 ui->form_InterpolationSetup->setValue(setup);
128 void CInterpolationSetupComponent::saveSetup()
130 const bool global = (this->
getSetupMode() == CInterpolationSetupComponent::SetupGlobal);
131 if (!this->checkPrerequisites(!global,
true)) {
return; }
142 const QPointer<CInterpolationSetupComponent> myself(
this);
144 if (!myself) {
return; }
150 const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(
false);
153 const bool ignoreGlobal = ui->cb_IgnoreGlobal->isChecked();
161 CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container();
162 const int replaced = setups.replaceOrAddObjectByCallsign(setup);
163 if (replaced < 1) {
return; }
164 const bool set = this->setSetupsToContext(setups);
165 if (!set) {
return; }
167 const QPointer<CInterpolationSetupComponent> myself(
this);
169 if (!myself) {
return; }
170 this->displaySetupsPerCallsign();
175 void CInterpolationSetupComponent::removeOrResetSetup()
177 const bool global = (this->
getSetupMode() == CInterpolationSetupComponent::SetupGlobal);
178 if (!this->checkPrerequisites(!global,
true)) {}
189 const CCallsign cs = ui->comp_CallsignCompleter->getCallsign(
false);
190 CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container();
191 const int removed = setups.removeByCallsign(cs);
192 if (removed < 1) {
return; }
193 const bool set = this->setSetupsToContext(setups);
194 if (!set) {
return; }
196 const QPointer<CInterpolationSetupComponent> myself(
this);
198 if (!myself) {
return; }
199 this->displaySetupsPerCallsign();
204 void CInterpolationSetupComponent::setUiValuesFromGlobal()
206 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
209 ui->form_InterpolationSetup->setValue(setup);
212 void CInterpolationSetupComponent::displaySetupsPerCallsign()
214 Q_ASSERT_X(
sGui, Q_FUNC_INFO,
"Missing sGui");
215 const CInterpolationSetupList setups =
217 ui->tvp_InterpolationSetup->updateContainerMaybeAsync(setups);
220 bool CInterpolationSetupComponent::checkPrerequisites(
bool checkSim,
bool showOverlay)
243 bool CInterpolationSetupComponent::setSetupsToContext(
const CInterpolationSetupList &setups,
bool force)
246 if (!force && setups == m_lastSetSetups) {
return false; }
247 const bool ignoreGlobal = ui->cb_IgnoreGlobal->isChecked();
249 m_lastSetSetups = setups;
253 void CInterpolationSetupComponent::onSetupChanged()
256 this->displaySetupsPerCallsign();
259 void CInterpolationSetupComponent::onObjectsDeleted(
const CVariant &deletedObjects)
261 if (deletedObjects.
canConvert<CInterpolationSetupList>())
263 const CInterpolationSetupList deletedSetups = deletedObjects.
value<CInterpolationSetupList>();
264 if (deletedSetups.isEmpty()) {
return; }
268 CInterpolationSetupList setups = ui->tvp_InterpolationSetup->container();
269 setups.removeByCallsigns(deletedSetups.getCallsigns());
270 const bool set = this->setSetupsToContext(setups,
true);
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
virtual bool setInterpolationAndRenderingSetupsPerCallsign(const swift::misc::simulation::CInterpolationSetupList &setups, bool ignoreSameAsGlobal)=0
Set all setups per callsign.
virtual void setInterpolationAndRenderingSetupGlobal(const swift::misc::simulation::CInterpolationAndRenderingSetupGlobal &setup)=0
Set the global setup.
bool isSimulatorAvailable() const
Simulator avialable (driver available)?
virtual swift::misc::simulation::CInterpolationSetupList getInterpolationAndRenderingSetupsPerCallsign() const =0
Get all setups per callsign.
virtual swift::misc::simulation::CInterpolationAndRenderingSetupPerCallsign getInterpolationAndRenderingSetupPerCallsignOrDefault(const swift::misc::aviation::CCallsign &callsign) const =0
Get the setup for callsign, if not existing the global setup.
virtual swift::misc::simulation::CInterpolationAndRenderingSetupGlobal getInterpolationAndRenderingSetupGlobal() const =0
The global setup.
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show single message.
Using this class provides a QFrame with the overlay functionality already integrated.
virtual ~CInterpolationSetupComponent()
Destructor.
Mode getSetupMode() const
Setup mode.
Class for emitting a log message.
Derived & validationError(const char16_t(&format)[N])
Set the severity to error, providing a format string, and adding the validation category.
Derived & validationWarning(const char16_t(&format)[N])
Set the severity to warning, providing a format string, and adding the validation category.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Streamable status message, e.g.
Wrapper around QVariant which provides transparent access to CValueObject methods of the contained ob...
T value() const
Return the value converted to the type T.
bool canConvert(int typeId) const
True if this variant can be converted to the type with the given metatype ID.
Value object encapsulating information of a callsign.
bool isValid() const
Valid callsign?
QString toQString(bool i18n=false) const
Cast as QString.
bool setLogInterpolation(bool log)
Log.interpolation.
Value object for interpolator and rendering.
void setBaseValues(const CInterpolationAndRenderingSetupBase &baseValues)
Set all base values.
Value object for interpolator and rendering per callsign.
bool isEqualToGlobal(const CInterpolationAndRenderingSetupGlobal &globalSetup) const
Equal to global setup?
const aviation::CCallsign & getCallsign() const
Get callsign.
void setCallsign(const aviation::CCallsign &callsign)
Set callsign.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Views, mainly QTableView.
Free functions in swift::misc.
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...