swift
Loading...
Searching...
No Matches
aircraftmodelvalidationcomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2019 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QPointer>
7
8#include "ui_aircraftmodelvalidationcomponent.h"
9
11#include "gui/guiapplication.h"
12
13using namespace swift::misc;
14using namespace swift::misc::simulation;
15using namespace swift::core::context;
16
18{
21 {
22 ui->setupUi(this);
23 ui->comp_Simulator->setMode(CSimulatorSelector::ComboBox);
24 ui->comp_Simulator->setRememberSelection(false);
25 ui->comp_Messages->setNoSorting(); // keep order
26 ui->tvp_InvalidModels->setValidationContextMenu(false);
27
28 const CAircraftMatcherSetup setup = m_matchingSettings.get();
29 ui->cb_EnableStartupCheck->setChecked(setup.doVerificationAtStartup());
30 ui->cb_OnlyIfErrorsOrWarnings->setChecked(setup.onlyShowVerificationWarningsAndErrors());
31
32 connect(ui->cb_EnableStartupCheck, &QCheckBox::toggled, this,
33 &CAircraftModelValidationComponent::onCheckAtStartupChanged);
34 connect(ui->cb_OnlyIfErrorsOrWarnings, &QCheckBox::toggled, this,
35 &CAircraftModelValidationComponent::onOnlyErrorWarningChanged);
36
37 connect(ui->pb_TempDisableInvalid, &QPushButton::released, this,
38 &CAircraftModelValidationComponent::onTempDisabledButtonClicked, Qt::QueuedConnection);
39 connect(ui->pb_TempDisableSelected, &QPushButton::released, this,
40 &CAircraftModelValidationComponent::onTempDisabledButtonClicked, Qt::QueuedConnection);
41 connect(ui->pb_RemoveInvalid, &QPushButton::released, this,
42 &CAircraftModelValidationComponent::onRemoveButtonClicked, Qt::QueuedConnection);
43 connect(ui->pb_RemoveSelected, &QPushButton::released, this,
44 &CAircraftModelValidationComponent::onRemoveButtonClicked, Qt::QueuedConnection);
45
46 connect(ui->pb_TriggerValidation, &QPushButton::released, this,
47 &CAircraftModelValidationComponent::triggerValidation, Qt::QueuedConnection);
48 connect(ui->pb_Help, &QPushButton::released, this, &CAircraftModelValidationComponent::showHelp,
50
51 // 1st init when running in distributed environment
53 const qint64 lastResults = m_lastResults;
54 QTimer::singleShot(2500, this, [=, this] {
55 if (!myself || !sGui || sGui->isShuttingDown())
56 {
57 return;
58 }
59 if (m_lastResults > lastResults)
60 {
61 return;
62 } // values received in meantime
63 myself->requestLastResults();
64 });
65 }
66
68
70 const CAircraftModelList &valid,
71 const CAircraftModelList &invalid, bool stopped,
72 const CStatusMessageList &msgs)
73 {
74 // swift::misc::simulation::CBackgroundValidation
75 Q_UNUSED(simulator)
76 Q_UNUSED(valid)
77
78 constexpr std::chrono::seconds MsgTimeout { 15000 };
79 m_lastResults = QDateTime::currentMSecsSinceEpoch();
80 ui->tvp_InvalidModels->updateContainerMaybeAsync(invalid);
81 ui->comp_Simulator->setValue(simulator);
82 ui->comp_Messages->clear();
83 if (!msgs.isEmpty())
84 {
85 ui->comp_Messages->appendStatusMessagesToList(msgs);
86 }
87
88 // pre-select tab
89 if (invalid.isEmpty() && !msgs.isEmpty())
90 {
91 // messages but no invalid models
92 ui->tw_CAircraftModelValidationComponent->setCurrentWidget(ui->tb_Messages);
93 }
94 else
95 {
96 ui->tw_CAircraftModelValidationComponent->setCurrentWidget(ui->tb_InvalidModels);
97 }
98
99 const CAircraftMatcherSetup setup = m_matchingSettings.get();
100 ui->cb_EnableStartupCheck->setChecked(setup.doVerificationAtStartup());
101 ui->pb_TempDisableInvalid->setEnabled(!invalid.isEmpty());
102 ui->pb_TempDisableSelected->setEnabled(!invalid.isEmpty());
103 ui->pb_RemoveInvalid->setEnabled(!invalid.isEmpty());
104 ui->pb_RemoveSelected->setEnabled(!invalid.isEmpty());
105
106 const QString msg =
107 stopped ?
108 QStringLiteral("Validation for '%1' stopped, maybe your models are not accessible or too many issues")
109 .arg(simulator.toQString(true)) :
110 QStringLiteral("Validated for '%1'. Valid: %2 Invalid: %3")
111 .arg(simulator.toQString(true))
112 .arg(valid.size())
113 .arg(invalid.size());
114 ui->lbl_Summay->setText(msg);
115 if (stopped)
116 {
117 this->showOverlayHTMLMessage(msg, MsgTimeout);
118 }
119 else if (msgs.hasWarningOrErrorMessages() || !invalid.isEmpty())
120 {
121 this->showOverlayHTMLMessage(u"There are warnings or errors, please check the messages and invalid models.",
122 MsgTimeout);
123 }
124 else
125 {
126 this->showOverlayHTMLMessage(u"There are NO warnings or errors, your set looks good.", MsgTimeout);
127 }
128 }
129
130 void CAircraftModelValidationComponent::tempDisableModels(const CAircraftModelList &models)
131 {
132 if (models.isEmpty())
133 {
134 return;
135 }
136 if (!sGui || sGui->isShuttingDown() || !sGui->supportsContexts())
137 {
138 return;
139 }
140 if (!sGui->getIContextSimulator())
141 {
142 return;
143 }
144 sGui->getIContextSimulator()->disableModelsForMatching(models, true);
145 this->saveInvalidModels(models);
146 }
147
148 void CAircraftModelValidationComponent::onCheckAtStartupChanged(bool checked)
149 {
150 CAircraftMatcherSetup setup = m_matchingSettings.get();
151 if (setup.doVerificationAtStartup() == checked)
152 {
153 return;
154 }
155 setup.setVerificationAtStartup(checked);
156 const CStatusMessage msg = m_matchingSettings.setAndSave(setup);
157 Q_UNUSED(msg)
158 }
159
160 void CAircraftModelValidationComponent::onOnlyErrorWarningChanged(bool checked)
161 {
162 CAircraftMatcherSetup setup = m_matchingSettings.get();
163 if (setup.onlyShowVerificationWarningsAndErrors() == checked)
164 {
165 return;
166 }
168 const CStatusMessage msg = m_matchingSettings.setAndSave(setup);
169 Q_UNUSED(msg)
170 }
171
172 void CAircraftModelValidationComponent::triggerValidation()
173 {
174 using namespace std::chrono_literals;
175 if (!sGui || sGui->isShuttingDown() || !sGui->supportsContexts())
176 {
177 return;
178 }
180 {
181 return;
182 }
184 {
185 this->showOverlayHTMLMessage("Validation in progress", 5s);
186 return;
187 }
188
189 const CSimulatorInfo simulator = ui->comp_Simulator->getValue();
191 {
192 this->showOverlayHTMLMessage(QStringLiteral("Triggered validation for '%1'").arg(simulator.toQString(true)),
193 5s);
194 }
195 else
196 {
198 QStringLiteral("Cannot trigger validation for '%1'").arg(simulator.toQString(true)), 5s);
199 }
200 }
201
202 void CAircraftModelValidationComponent::requestLastResults()
203 {
204 using namespace std::chrono_literals;
205
206 if (!sGui || sGui->isShuttingDown() || !sGui->supportsContexts())
207 {
208 return;
209 }
211 {
212 return;
213 }
215 {
216 this->showOverlayHTMLMessage("Validation in progress", 5s);
217 return;
218 }
220 }
221
222 void CAircraftModelValidationComponent::onTempDisabledButtonClicked()
223 {
224 using namespace std::chrono_literals;
225
226 if (!sGui || sGui->isShuttingDown())
227 {
228 return;
229 }
230
231 CAircraftModelList disableModels;
232 const QObject *sender = QObject::sender();
233 if (sender == ui->pb_TempDisableInvalid)
234 {
235 disableModels = ui->tvp_InvalidModels->container();
236 }
237 else if (sender == ui->pb_TempDisableSelected)
238 {
239 disableModels = ui->tvp_InvalidModels->selectedObjects();
240 }
241
242 if (disableModels.isEmpty())
243 {
244 this->showOverlayHTMLMessage("No models disabled", 4s);
245 }
246 else
247 {
248 this->tempDisableModels(disableModels);
249 this->showOverlayHTMLMessage(QStringLiteral("%1 models disabled").arg(disableModels.size()));
250 }
251 }
252
253 void CAircraftModelValidationComponent::onRemoveButtonClicked()
254 {
255 using namespace std::chrono_literals;
256
257 if (!sGui || sGui->isShuttingDown())
258 {
259 return;
260 }
262 {
263 return;
264 }
265
266 CAircraftModelList removeModels;
267 const QObject *sender = QObject::sender();
268 if (sender == ui->pb_RemoveInvalid)
269 {
270 removeModels = ui->tvp_InvalidModels->container();
271 }
272 else if (sender == ui->pb_RemoveSelected)
273 {
274 removeModels = ui->tvp_InvalidModels->selectedObjects();
275 }
276
277 if (removeModels.isEmpty())
278 {
279 this->showOverlayHTMLMessage("No models removed", 4s);
280 }
281 else
282 {
284 this, tr("Model validation"),
285 tr("Do you really want to delete %1 models from model set?").arg(removeModels.sizeInt()),
287 if (ret != QMessageBox::Ok)
288 {
289 return;
290 }
291
292 const int r = sGui->getIContextSimulator()->removeModelsFromSet(removeModels);
293 this->showOverlayHTMLMessage(QStringLiteral("%1 models removed").arg(r));
294 }
295 }
296
297 void CAircraftModelValidationComponent::showHelp()
298 {
299 if (!sGui || sGui->isShuttingDown())
300 {
301 return;
302 }
303 sGui->showHelp("model_set_validation");
304 }
305
306 void CAircraftModelValidationComponent::saveInvalidModels(const CAircraftModelList &models) const
307 {
308 const CStatusMessage m = models.saveInvalidModels();
309 Q_UNUSED(m)
310 }
311} // namespace swift::gui::components
bool isShuttingDown() const
Is application shutting down?
const context::IContextSimulator * getIContextSimulator() const
Direct access to contexts if a CCoreFacade has been initialized.
bool supportsContexts(bool ignoreShutdownTest=false) const
Supports contexts.
virtual bool isValidationInProgress() const =0
Validation in progress.
virtual int removeModelsFromSet(const swift::misc::simulation::CAircraftModelList &removeModels)=0
Remove models from set.
virtual bool triggerModelSetValidation(const swift::misc::simulation::CSimulatorInfo &simulator)=0
Trigger model set validation.
void showHelp(const QString &subpath={}) const
Show help page (online help).
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
COverlayMessagesFrame(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor.
void validatedModelSet(const swift::misc::simulation::CSimulatorInfo &simulator, const swift::misc::simulation::CAircraftModelList &valid, const swift::misc::simulation::CAircraftModelList &invalid, bool stopped, const swift::misc::CStatusMessageList &msgs)
Validated a model set.
size_type size() const
Returns number of elements in the sequence.
Definition sequence.h:273
bool isEmpty() const
Synonym for empty.
Definition sequence.h:285
int sizeInt() const
Avoid compiler warnings when using with int.
Definition sequence.h:276
Status messages, e.g. from Core -> GUI.
bool hasWarningOrErrorMessages() const
Warning or error messages.
const CONTAINER & container() const
Container.
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
bool onlyShowVerificationWarningsAndErrors() const
Verification only shown for warning/errors?
void setOnlyShowVerificationWarningsAndErrors(bool only)
Set the "show only errors" mode.
bool doVerificationAtStartup() const
Verification at startup?
void setVerificationAtStartup(bool verify)
Set startup verification.
Value object encapsulating a list of aircraft models.
CStatusMessage saveInvalidModels() const
Save/load invalid models.
Simple hardcoded info about the corresponding simulator.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Free functions in swift::misc.
void toggled(bool checked)
qint64 currentMSecsSinceEpoch()
QMessageBox::StandardButton question(QWidget *parent, const QString &title, const QString &text, QMessageBox::StandardButtons buttons, QMessageBox::StandardButton defaultButton)
QObject(QObject *parent)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QObject * sender() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QString arg(Args &&... args) const const
QueuedConnection
QWidget(QWidget *parent, Qt::WindowFlags f)