swift
Loading...
Searching...
No Matches
dbownmodelsetcomponent.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 <QAction>
7#include <QDesktopServices>
8#include <QDialog>
9#include <QFlags>
10#include <QIcon>
11#include <QLineEdit>
12#include <QPointer>
13#include <QPushButton>
14#include <QString>
15#include <QStringBuilder>
16#include <QWidget>
17#include <Qt>
18#include <QtGlobal>
19
20#include "ui_dbownmodelsetcomponent.h"
21
27#include "gui/guiapplication.h"
28#include "gui/guiutility.h"
29#include "gui/menus/aircraftmodelmenus.h"
30#include "gui/menus/menuaction.h"
34#include "gui/views/viewbase.h"
35#include "misc/icons.h"
36#include "misc/logmessage.h"
38#include "misc/orderable.h"
43
44using namespace swift::misc;
45using namespace swift::misc::simulation;
46using namespace swift::gui::models;
47using namespace swift::gui::menus;
48using namespace swift::gui::views;
49
51{
54 {
55 ui->setupUi(this);
56 ui->tvp_OwnModelSet->setAircraftModelMode(CAircraftModelListModel::OwnModelSet);
57 ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuStashing);
58 ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh |
62 ui->tvp_OwnModelSet->addFilterDialog();
63 ui->tvp_OwnModelSet->setCustomMenu(new CLoadModelSetMenu(this));
64 ui->tvp_OwnModelSet->setCustomMenu(new CConsolidateWithDbDataMenu(ui->tvp_OwnModelSet, this));
65 ui->tvp_OwnModelSet->setCustomMenu(new CConsolidateWithSimulatorModels(ui->tvp_OwnModelSet, this));
66 ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuLoadAndSave | CAircraftModelView::MenuRefresh |
68 ui->tvp_OwnModelSet->setSorting(CAircraftModel::IndexOrderString);
69 ui->tvp_OwnModelSet->initAsOrderable();
70
71 const CSimulatorInfo sim = ui->comp_SimulatorSelector->getValue();
72 ui->tvp_OwnModelSet->setCorrespondingSimulator(sim, m_simulatorSettings.getSimulatorDirectoryOrDefault(sim));
73 ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
74 ui->comp_SimulatorSelector->setRememberSelectionAndSetToLastSelection();
75 const CSimulatorInfo simulator = ui->comp_SimulatorSelector->getValue();
76 ui->le_Simulator->setText(simulator.toQString(true));
77
79 ui->pb_SaveAsSetForSimulator->setStyleSheet("padding-left: 3px; padding-right: 3px;");
80
81 connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
83 connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
85 connect(ui->pb_ShowStatistics, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
87 connect(ui->pb_FirstSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
89 connect(ui->pb_Clear, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
91 connect(ui->pb_CopyFromAnotherSwift, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
93 connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::buttonClicked,
95
98 connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged, this,
99 &CDbOwnModelSetComponent::onRowCountChanged, Qt::QueuedConnection);
100 connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this,
101 &CDbOwnModelSetComponent::viewModelChanged, Qt::QueuedConnection);
102 connect(ui->tvp_OwnModelSet, &CAircraftModelView::requestUpdate, this,
103 &CDbOwnModelSetComponent::updateViewToCurrentModels, Qt::QueuedConnection);
105 &CDbOwnModelSetComponent::onJsonDataLoaded, Qt::QueuedConnection);
106
107 this->triggerSetSimulatorDeferred(simulator);
108 }
109
111
112 views::CAircraftModelView *CDbOwnModelSetComponent::view() const { return ui->tvp_OwnModelSet; }
113
115 {
116 using namespace std::chrono_literals;
117
118 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
119 this->setSimulator(simulator);
120 if (models.isEmpty())
121 {
122 ui->tvp_OwnModelSet->clear();
123 return;
124 }
125
126 CAircraftModelList cleanModelList(
127 models.matchesSimulator(simulator)); // remove those not matching the simulator
128 const int diff = models.size() - cleanModelList.size();
129 if (diff > 0)
130 {
131 const CStatusMessage m =
132 CStatusMessage(this).warning(u"Removed %1 models from set, because not matching %2")
133 << diff << simulator.toQString(true);
135 }
136 cleanModelList.resetOrder();
137 ui->tvp_OwnModelSet->updateContainerMaybeAsync(cleanModelList);
138 }
139
141 {
142 using namespace std::chrono_literals;
143
144 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
145 if (models.isEmpty())
146 {
147 return 0;
148 }
149 CAircraftModelList cleanModelList(
150 models.matchesSimulator(simulator)); // remove those not matching the simulator
151 const int diff = models.size() - cleanModelList.size();
152 if (diff > 0)
153 {
154 const CStatusMessage m =
155 CStatusMessage(this).warning(u"Removed %1 models from set, because not matching %2")
156 << diff << simulator.toQString(true);
158 }
159 if (cleanModelList.isEmpty())
160 {
161 return 0;
162 }
163 CAircraftModelList updatedModels(ui->tvp_OwnModelSet->container());
164 updatedModels.replaceOrAddModelsWithString(cleanModelList, Qt::CaseInsensitive);
165 updatedModels.resetOrder();
166 ui->tvp_OwnModelSet->updateContainerMaybeAsync(updatedModels);
167 return diff;
168 }
169
171 {
172 return ui->tvp_OwnModelSet->container();
173 }
174
175 int CDbOwnModelSetComponent::getModelSetCountFromView() const { return ui->tvp_OwnModelSet->container().size(); }
176
178 {
179 return this->addToModelSet(CAircraftModelList({ model }), simulator);
180 }
181
183 const CSimulatorInfo &simulator)
184 {
185 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
186 if (models.isEmpty())
187 {
188 return { this, CStatusMessage::SeverityInfo, u"No data", true };
189 }
190 if (!this->getModelSetSimulator().isSingleSimulator())
191 {
192 // no sim yet, we set it
193 this->setSimulator(simulator);
194 }
195 if (simulator != this->getModelSetSimulator())
196 {
197 // only currently selected sim allowed
198 return { this, CStatusMessage::SeverityError,
199 u"Cannot add data for " % simulator.toQString(true) % u" to " %
200 this->getModelSetSimulator().toQString(true),
201 true };
202 }
203
204 const bool allowExcludedModels = m_modelSettings.get().getAllowExcludedModels();
206 int d = updateModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
207 if (d > 0)
208 {
209 if (!allowExcludedModels)
210 {
211 updateModels.removeIfExcluded();
212 }
213 updateModels.resetOrder();
214 ui->tvp_OwnModelSet->updateContainerMaybeAsync(updateModels);
215 return { this, CStatusMessage::SeverityInfo,
216 u"Modified " % QString::number(d) % u" entries in model set " %
217 this->getModelSetSimulator().toQString(true),
218 true };
219 }
220 else
221 {
222 return { this, CStatusMessage::SeverityInfo, u"No data modified in model set", true };
223 }
224 }
225
227 {
229 if (component)
230 {
232 &CDbOwnModelSetComponent::tabIndexChanged);
233 }
234 }
235
236 void CDbOwnModelSetComponent::enableButtons(bool firstSet, bool newSet)
237 {
238 ui->pb_FirstSet->setEnabled(firstSet);
239 ui->pb_CreateNewSet->setEnabled(newSet);
240 }
241
242 void CDbOwnModelSetComponent::tabIndexChanged(int index) { Q_UNUSED(index) }
243
244 void CDbOwnModelSetComponent::buttonClicked()
245 {
246 using namespace std::chrono_literals;
247
248 const QObject *sender = QObject::sender();
249 if (!sender)
250 {
251 return;
252 }
253
254 if (sender == ui->pb_CreateNewSet)
255 {
256 this->createNewSet();
257 return;
258 }
259
260 if (sender == ui->pb_LoadExistingSet)
261 {
262 ui->tvp_OwnModelSet->showFileLoadDialog();
263 return;
264 }
265
266 if (sender == ui->pb_SaveAsSetForSimulator)
267 {
268 const CAircraftModelList ownModelSet(ui->tvp_OwnModelSet->container());
269 if (!ownModelSet.isEmpty())
270 {
271 const CSimulatorInfo sim = this->getSelectedSimulator();
272 const CStatusMessage m = this->setCachedModels(ownModelSet, sim);
274 if (m.isSuccess())
275 {
276 const QString msg = QStringLiteral("Saved model set for '%1'").arg(sim.toQString(true));
277
278 // display either as overlay of componet or view
279 if (!this->showMappingComponentOverlayHtmlMessage(msg, 5s))
280 {
281 ui->tvp_OwnModelSet->showOverlayHTMLMessage(msg, 5s);
282 }
283 }
284 else
285 {
287 {
288 ui->tvp_OwnModelSet->showOverlayMessage(m);
289 }
290 }
291 }
292 return;
293 }
294
295 if (sender == ui->pb_ShowStatistics)
296 {
297 this->showModelStatistics();
298 return;
299 }
300
301 if (sender == ui->pb_FirstSet)
302 {
303 this->firstSet();
304 return;
305 }
306
307 if (sender == ui->pb_CopyFromAnotherSwift)
308 {
309 this->copyFromAnotherSwift();
310 return;
311 }
312
313 if (sender == ui->pb_Clear)
314 {
315 ui->tvp_OwnModelSet->clear();
316 return;
317 }
318 }
319
320 void CDbOwnModelSetComponent::onRowCountChanged(int count, bool withFilter)
321 {
322 Q_UNUSED(count)
323 Q_UNUSED(withFilter)
324
325 const int realUnfilteredCount = ui->tvp_OwnModelSet->container().size();
326 const bool canSave = this->getModelSetSimulator().isSingleSimulator() && (realUnfilteredCount > 0);
327 ui->pb_SaveAsSetForSimulator->setEnabled(canSave);
328 if (canSave)
329 {
330 this->setSaveFileName(this->getModelSetSimulator());
331 ui->pb_SaveAsSetForSimulator->setText(
332 QStringLiteral("save '%1'").arg(this->getModelSetSimulator().toQString(true)));
333 }
334 else
335 {
336 ui->pb_SaveAsSetForSimulator->setText("save");
337 }
338 }
339
340 void CDbOwnModelSetComponent::onJsonDataLoaded(const CSimulatorInfo &simulator)
341 {
342 if (simulator.isSingleSimulator())
343 {
344 this->setSimulator(simulator);
345 }
346 }
347
348 void CDbOwnModelSetComponent::distributorPreferencesChanged()
349 {
350 const CDistributorListPreferences preferences = m_distributorPreferences.getThreadLocal();
351 const CSimulatorInfo simuulator = preferences.getLastUpdatedSimulator();
352 if (simuulator.isSingleSimulator())
353 {
354 this->updateDistributorOrder(simuulator);
355 }
356 }
357
358 void CDbOwnModelSetComponent::reduceModels()
359 {
360 if (!m_reduceModelsDialog)
361 {
362 m_reduceModelsDialog.reset(new CDbReduceModelDuplicates(this));
363 }
364
365 CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer();
366 const CSimulatorInfo simulator = this->getModelSetSimulator();
367 m_reduceModelsDialog->setModels(models, simulator);
368 const auto ret = static_cast<QDialog::DialogCode>(m_reduceModelsDialog->exec());
369 if (ret != QDialog::Accepted)
370 {
371 return;
372 }
373 const CAircraftModelList removeModels = m_reduceModelsDialog->getRemoveCandidates();
374 const CSimulatorInfo removeSimulator = m_reduceModelsDialog->getSimulator();
375 if (removeModels.isEmpty())
376 {
377 return;
378 }
379 const QStringList modelStrings = removeModels.getModelStringList(false);
380 models.removeModelsWithString(modelStrings, Qt::CaseInsensitive); // by strings also removes if id is missing
381 this->setModelSet(models, removeSimulator);
382 }
383
384 void CDbOwnModelSetComponent::removeExcludedModels()
385 {
386 const CSimulatorInfo simulator = this->getModelSetSimulator();
387 CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer();
388 const int r = models.removeIfExcluded();
389 if (r < 1)
390 {
391 return;
392 }
393 this->setModelSet(models, simulator);
394 }
395
396 void CDbOwnModelSetComponent::removeNonDBModels()
397 {
398 const CSimulatorInfo simulator = this->getModelSetSimulator();
399 CAircraftModelList models = ui->tvp_OwnModelSet->containerOrFilteredContainer();
400 const int r = models.removeObjectsWithoutDbKey();
401 if (r < 1)
402 {
403 return;
404 }
405 this->setModelSet(models, simulator);
406 }
407
408 void CDbOwnModelSetComponent::viewModelChanged()
409 {
410 const bool hasData = ui->tvp_OwnModelSet->rowCount() > 0;
411 ui->pb_SaveAsSetForSimulator->setEnabled(hasData);
412 }
413
414 void CDbOwnModelSetComponent::setSaveFileName(const CSimulatorInfo &simulator)
415 {
416 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
417 const QString name("modelset" + simulator.toQString(true));
418 ui->tvp_OwnModelSet->setSaveFileName(name);
419 }
420
421 void CDbOwnModelSetComponent::updateViewToCurrentModels()
422 {
423 const CAircraftModelList models(this->getModelSet());
424 ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
425 }
426
427 void CDbOwnModelSetComponent::createNewSet()
428 {
429 // make sure both tabs display the same simulator
430 // since we use the component also in the launcher wizard, mc might not be existing
431 const CSimulatorInfo simulator(this->getModelSetSimulator());
432 if (!simulator.isSingleSimulator())
433 {
434 // Ref T630, avoid invalid simulator
435 CLogMessage(this).error(u"No single simulator!");
436 return;
437 }
438
439 CDbMappingComponent *mc = this->getMappingComponent();
440 if (!mc)
441 {
442 CLogMessage(this).error(u"No mapping component available!");
443 return;
444 }
445
446 mc->setOwnModelsSimulator(simulator);
447 if (!m_modelSetFormDialog)
448 {
449 m_modelSetFormDialog.reset(new CDbOwnModelSetFormDialog(this));
450 m_modelSetFormDialog->setMappingComponent(this->getMappingComponent());
451 }
452
453 if (mc->getOwnModelsCount() > 0)
454 {
455 m_modelSetFormDialog->setModal(true);
456 m_modelSetFormDialog->reloadData();
457 const auto rc = static_cast<QDialog::DialogCode>(m_modelSetFormDialog->exec());
458 if (rc == QDialog::Accepted)
459 {
460 this->setModelSet(m_modelSetFormDialog->getModelSet(), m_modelSetFormDialog->getSimulatorInfo());
461 }
462 }
463 else
464 {
465 const CStatusMessage m = CStatusMessage(this).error(u"No model data for %1") << simulator.toQString(true);
466 mc->showOverlayMessage(m);
467 }
468 }
469
470 void CDbOwnModelSetComponent::firstSet()
471 {
472 if (!m_firstModelSetDialog)
473 {
474 m_firstModelSetDialog.reset(new CFirstModelSetDialog(this));
475 }
476 m_firstModelSetDialog->show();
477 }
478
479 void CDbOwnModelSetComponent::copyFromAnotherSwift()
480 {
481 if (!m_copyFromAnotherSwiftDialog)
482 {
483 m_copyFromAnotherSwiftDialog.reset(new CCopyModelsFromOtherSwiftVersionsDialog(this));
484 }
485 m_copyFromAnotherSwiftDialog->show();
486 }
487
489 {
490 if (m_simulator == simulator)
491 {
492 return;
493 } // avoid unnecessary signals
494 if (simulator.isNoSimulator())
495 {
496 return;
497 }
498 Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
499
500 m_simulator = simulator;
501 ui->comp_SimulatorSelector->setValue(simulator);
502 ui->tvp_OwnModelSet->setCorrespondingSimulator(simulator,
503 m_simulatorSettings.getSimulatorDirectoryOrDefault(m_simulator));
504 ui->le_Simulator->setText(simulator.toQString(true));
505 this->synchronizeCache(simulator);
506 this->updateViewToCurrentModels();
507 }
508
510 {
511 ui->comp_SimulatorSelector->setMode(mode);
512 }
513
515 {
516 this->admitCache(simulator); // trigger loading
517
519 QTimer::singleShot(1000, this, [=, this] {
520 if (!sApp || sApp->isShuttingDown())
521 {
522 return;
523 }
524 if (!myself)
525 {
526 return;
527 }
528 this->setSimulator(simulator);
529 });
530 }
531
532 void CDbOwnModelSetComponent::showModelStatistics()
533 {
534 const CAircraftModelList set(this->getModelSetFromView());
535 if (!m_modelStatisticsDialog)
536 {
537 m_modelStatisticsDialog.reset(new CAircraftModelStatisticsDialog(this));
538 }
539 m_modelStatisticsDialog->analyzeModels(set);
540 m_modelStatisticsDialog->show();
541 }
542
543 void CDbOwnModelSetComponent::updateDistributorOrder(const CSimulatorInfo &simulator)
544 {
545 CAircraftModelList modelSet = this->getCachedModels(simulator);
546 if (modelSet.isEmpty())
547 {
548 return;
549 }
550 const CDistributorListPreferences preferences = m_distributorPreferences.getThreadLocal();
551 const CDistributorList distributors = preferences.getDistributors(simulator);
552 if (distributors.isEmpty())
553 {
554 return;
555 }
556 modelSet.updateDistributorOrder(distributors);
557 this->setCachedModels(modelSet, simulator);
558
559 // display?
560 const CSimulatorInfo currentSimulator(this->getModelSetSimulator());
561 if (simulator == currentSimulator)
562 {
563 ui->tvp_OwnModelSet->updateContainerAsync(modelSet);
564 }
565 }
566
567 bool CDbOwnModelSetComponent::runsInDialog() { return CGuiUtility::findParentDialog(this, 5); }
568
569 void CDbOwnModelSetComponent::CLoadModelSetMenu::customMenu(CMenuActions &menuActions)
570 {
571 // for the moment I use all sims, I could restrict to CSimulatorInfo::getLocallyInstalledSimulators();
572 const CSimulatorInfo sims = CSimulatorInfo::allSimulators();
573 const bool noSims = sims.isNoSimulator() || sims.isUnspecified();
574 if (!noSims)
575 {
576 auto *ownModelSetComp = qobject_cast<CDbOwnModelSetComponent *>(this->parent());
577 Q_ASSERT_X(ownModelSetComp, Q_FUNC_INFO, "Cannot access parent");
578 if (m_setActions.isEmpty())
579 {
580 if (sims.isP3D())
581 {
582 auto *a = new QAction(CIcons::appModels16(), "P3D models", this);
583 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
584 Q_UNUSED(checked)
585 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::P3D));
586 });
587 m_setActions.append(a);
588
589 a = new QAction(CIcons::appModels16(), "New set P3D models", this);
590 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
591 Q_UNUSED(checked)
592 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::P3D));
593 });
594 m_setNewActions.append(a);
595 }
596 if (sims.isXPlane())
597 {
598 auto *a = new QAction(CIcons::appModels16(), "XPlane models", this);
599 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
600 Q_UNUSED(checked)
601 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::XPLANE));
602 });
603 m_setActions.append(a);
604
605 a = new QAction(CIcons::appModels16(), "New set XPlane models", this);
606 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
607 Q_UNUSED(checked)
608 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::XPLANE));
609 });
610 m_setNewActions.append(a);
611 }
612 if (sims.isFG())
613 {
614 auto *a = new QAction(CIcons::appModels16(), "FG models", this);
615 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
616 Q_UNUSED(checked)
617 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::FG));
618 });
619 m_setActions.append(a);
620
621 a = new QAction(CIcons::appModels16(), "New set FG models", this);
622 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
623 Q_UNUSED(checked)
624 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::FG));
625 });
626 m_setNewActions.append(a);
627 }
628 if (sims.isMSFS())
629 {
630 auto *a = new QAction(CIcons::appModels16(), "MSFS models", this);
631 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
632 Q_UNUSED(checked)
633 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::MSFS));
634 });
635 m_setActions.append(a);
636
637 a = new QAction(CIcons::appModels16(), "New set MSFS models", this);
638 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
639 Q_UNUSED(checked)
640 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::MSFS));
641 });
642 m_setNewActions.append(a);
643 }
644 if (sims.isMSFS2024())
645 {
646 auto *a = new QAction(CIcons::appModels16(), "MSFS2024 models", this);
647 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
648 Q_UNUSED(checked)
649 ownModelSetComp->setSimulator(CSimulatorInfo(CSimulatorInfo::MSFS2024));
650 });
651 m_setActions.append(a);
652
653 a = new QAction(CIcons::appModels16(), "New set MSFS2024 models", this);
654 connect(a, &QAction::triggered, ownModelSetComp, [ownModelSetComp](bool checked) {
655 Q_UNUSED(checked)
656 ownModelSetComp->setModelSet(CAircraftModelList(), CSimulatorInfo(CSimulatorInfo::MSFS2024));
657 });
658 m_setNewActions.append(a);
659 }
660
661 auto *a = new QAction(CIcons::appDistributors16(), "Apply distributor preferences", this);
662 connect(a, &QAction::triggered, ownModelSetComp,
663 &CDbOwnModelSetComponent::distributorPreferencesChanged, Qt::QueuedConnection);
664 m_setActions.append(a);
665
666 a = new QAction(CIcons::delete16(), "Reduce models (remove duplicates)", this);
667 connect(a, &QAction::triggered, ownModelSetComp, &CDbOwnModelSetComponent::reduceModels,
669 m_setActions.append(a);
670
671 a = new QAction(CIcons::delete16(), "Remove excluded models", this);
672 connect(a, &QAction::triggered, ownModelSetComp, &CDbOwnModelSetComponent::removeExcludedModels,
674 m_setActions.append(a);
675
676 a = new QAction(CIcons::delete16(), "Remove non DB models", this);
677 connect(a, &QAction::triggered, ownModelSetComp, &CDbOwnModelSetComponent::removeNonDBModels,
679 m_setActions.append(a);
680 }
681 menuActions.addMenuModelSet();
682 menuActions.addActions(m_setActions, CMenuAction::pathModelSet());
683 menuActions.addActions(m_setNewActions, CMenuAction::pathModelSetNew());
684 }
685 this->nestedCustomMenu(menuActions);
686 }
687} // namespace swift::gui::components
static QDialog * findParentDialog(QWidget *widget)
Find parent dialog if there is any, otherwise null.
bool showMappingComponentOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Overlay messages.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
bool showMappingComponentOverlayHtmlMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Overlay messages.
virtual void setMappingComponent(CDbMappingComponent *component)
Set the corresponding component.
void tabIndexChanged(int index)
Tab index has been changed.
const swift::misc::simulation::CAircraftModelList & getModelSetFromView() const
Current model set for simulator CDbOwnModelSetComponent::getModelSetSimulator.
swift::misc::simulation::CAircraftModelList getModelSet() const
Cached models for current simulator.
int getModelSetCountFromView() const
Current sount of model set for simulator CDbOwnModelSetComponent::getModelSetSimulator.
int replaceOrAddModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Replace or add models provided for a given simulator.
swift::misc::simulation::CSimulatorInfo getSelectedSimulator() const
Simulator.
void setSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Simulator.
swift::misc::CStatusMessage addToModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Add to model set.
views::CAircraftModelView * view() const
Corresponding view.
void setSimulatorSelectorMode(CSimulatorSelector::Mode mode)
How to display.
swift::misc::simulation::CSimulatorInfo getModelSetSimulator() const
Model set is for simulator.
void setMappingComponent(CDbMappingComponent *component)
Set the corresponding component.
void triggerSetSimulatorDeferred(const swift::misc::simulation::CSimulatorInfo &simulator)
Deferred init of simulator.
CDbOwnModelSetComponent(QWidget *parent=nullptr)
Constructor.
void setModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Set the model set for a given simulator.
int updateModels(const swift::misc::simulation::CAircraftModelList &models)
Update models.
void enableButtons(bool firstSet, bool newSet)
Enable buttons.
void changed(const swift::misc::simulation::CSimulatorInfo &simulator)
Value has been changed.
Merge/update with simulator models (e.g. remove no longer existing models).
static const QString & pathModelSetNew()
Model set, new set.
Definition menuaction.h:157
static const QString & pathModelSet()
Model set.
Definition menuaction.h:150
CMenuActions addActions(const CMenuActions &actions)
Add menu actions, returns last valid QAction.
CMenuAction addMenuModelSet()
Model set menu.
void nestedCustomMenu(CMenuActions &menuActions) const
Delegate down one level.
void jsonModelsForSimulatorLoaded(const swift::misc::simulation::CSimulatorInfo &simulator)
Models for simulator loaded (JSON).
void modelChanged()
Model bas been changed (means data in view have been changed).
void requestUpdate()
Ask for new data from currently loaded data.
void modelDataChanged(int count, bool withFilter)
Model data changed.
@ MenuClear
allow clearing the view via menu
Definition viewbase.h:120
@ MenuDisplayAutomaticallyAndRefresh
should come together
Definition viewbase.h:125
@ MenuRefresh
allow refreshing the view via menu
Definition viewbase.h:122
@ MenuOrderable
items can be ordered (if container is swift::misc::IOrderableList
Definition viewbase.h:131
@ MenuBackend
allow to request data from backend
Definition viewbase.h:123
@ MenuRemoveSelectedRows
allow to remove selected rows
Definition viewbase.h:121
@ MenuMaterializeFilter
materialize filter (filtered data become model data)
Definition viewbase.h:127
const T & getThreadLocal() const
Read the current value.
Definition valuecache.h:403
static const QPixmap & appModels16()
Models.
static const QPixmap & appDistributors16()
Distributors.
static const QPixmap & delete16()
Delete.
static void preformatted(const CStatusMessage &statusMessage)
Sends a verbatim, preformatted message to the log.
Derived & warning(const char16_t(&format)[N])
Set the severity to warning, providing a format string.
Derived & error(const char16_t(&format)[N])
Set the severity to error, providing a format string.
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
Streamable status message, e.g.
bool isSuccess() const
Operation considered successful.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
const CONTAINER & container() const
Container.
void resetOrder(int offset=0)
Set order member to current order.
int removeObjectsWithoutDbKey()
Remove objects without key.
QString toQString(bool i18n=false) const
Cast as QString.
Definition mixinstring.h:74
Aircraft model (used by another pilot, my models on disk).
Value object encapsulating a list of aircraft models.
QStringList getModelStringList(bool sort=true) const
Model strings.
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
Replace or add based on model string.
int removeIfExcluded()
Remove if excluded CAircraftModel::Exclude.
int removeModelsWithString(const CAircraftModelList &models, Qt::CaseSensitivity sensitivity)
Remove those models with given model strings.
int updateDistributorOrder(const CDistributorList &distributors)
From given CDistributorList update the model`s distributor order.
Value object encapsulating a list of distributors.
const CSimulatorInfo & getLastUpdatedSimulator() const
Last updated simulator.
const CDistributorList & getDistributors(const CSimulatorInfo &simulator) const
Get distributors.
Simple hardcoded info about the corresponding simulator.
static const CSimulatorInfo & allSimulators()
All simulators.
bool isSingleSimulator() const
Single simulator selected.
bool isNoSimulator() const
No simulator?
bool isUnspecified() const
Unspecified simulator.
void admitCache(const CSimulatorInfo &simulator)
Look like IMultiSimulatorModelCaches interface.
CAircraftModelList getCachedModels(const CSimulatorInfo &simulator) const
Look like IMultiSimulatorModelCaches interface.
CStatusMessage setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
Look like IMultiSimulatorModelCaches interface.
void synchronizeCache(const CSimulatorInfo &simulator)
Look like IMultiSimulatorModelCaches interface.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
void clicked(bool checked)
void triggered(bool checked)
QFrame(QWidget *parent, Qt::WindowFlags f)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
QObject * sender() const const
QString number(double n, char format, int precision)
CaseInsensitive
QueuedConnection
QWidget(QWidget *parent, Qt::WindowFlags f)