11 #include <QModelIndex>
21 #include "ui_dbmappingcomponent.h"
37 #include "gui/menus/aircraftmodelmenus.h"
38 #include "gui/menus/menuaction.h"
54 using namespace swift::misc::aviation;
55 using namespace swift::misc::network;
56 using namespace swift::misc::simulation;
57 using namespace swift::misc::simulation::fscommon;
59 using namespace swift::gui::editors;
62 using namespace swift::gui::menus;
66 CDbMappingComponent::CDbMappingComponent(QWidget *parent)
73 ui->comp_StashAircraft->setMappingComponent(
this);
74 ui->comp_OwnModelSet->setMappingComponent(
this);
77 ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel);
78 ui->tvp_AircraftModelsForVPilot->addFilterDialog();
81 ui->comp_OwnAircraftModels->view()->setCustomMenu(
83 ui->comp_OwnAircraftModels->view()->setCustomMenu(
new CMergeWithVPilotMenu(
this));
84 ui->comp_OwnAircraftModels->view()->setCustomMenu(
new COwnModelSetMenu(
this));
85 ui->comp_OwnAircraftModels->view()->setCustomMenu(
new CStashToolsMenu(
this));
87 ui->comp_OwnModelSet->view()->setCustomMenu(
new CShowSimulatorFileMenu(ui->comp_OwnModelSet->view(),
this));
88 ui->comp_OwnModelSet->view()->setCustomMenu(
new CStashToolsMenu(
this));
90 ui->comp_StashAircraft->view()->setCustomMenu(
new CShowSimulatorFileMenu(ui->comp_StashAircraft->view(),
this));
91 ui->comp_StashAircraft->view()->setCustomMenu(
new CApplyDbDataMenu(
this));
92 ui->comp_StashAircraft->view()->setCustomMenu(
new COwnModelSetMenu(
this));
93 ui->comp_StashAircraft->view()->setCustomMenu(
new CStashToolsMenu(
this));
95 ui->comp_ModelWorkbench->view()->menuAddItems(CAircraftModelView::MenuClear |
96 CAircraftModelView::MenuRemoveSelectedRows);
97 ui->comp_ModelWorkbench->view()->setCustomMenu(
new CApplyDbDataMenu(
this));
98 ui->comp_ModelWorkbench->view()->setCustomMenu(
new COwnModelSetMenu(
this));
99 ui->comp_ModelWorkbench->view()->setCustomMenu(
new CStashToolsMenu(
this));
100 ui->comp_ModelWorkbench->view()->setCustomMenu(
new CRemovedModelsMenu(
this));
103 connect(ui->editor_ModelMapping, &CModelMappingForm::requestStash,
this,
104 &CDbMappingComponent::stashCurrentModel);
107 &CDbMappingComponent::onOwnModelsSimulatorChanged, Qt::QueuedConnection);
108 connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::doubleClicked,
this,
109 &CDbMappingComponent::onModelRowSelected);
110 connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::modelDataChangedDigest,
this,
111 &CDbMappingComponent::onOwnModelsChangedDigest, Qt::QueuedConnection);
112 connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::requestStash,
this,
114 connect(ui->comp_OwnAircraftModels->view(), &CAircraftModelView::toggledHighlightStashedModels,
this,
115 &CDbMappingComponent::onStashedModelsChangedTriggerDigest);
117 connect(ui->comp_ModelWorkbench->view(), &CAircraftModelView::doubleClicked,
this,
118 &CDbMappingComponent::onModelRowSelected);
119 connect(ui->comp_ModelWorkbench->view(), &CAircraftModelView::modelDataChangedDigest,
this,
120 &CDbMappingComponent::onWorkbenchDataChanged, Qt::QueuedConnection);
121 connect(ui->comp_ModelWorkbench->view(), &CAircraftModelView::requestStash,
this,
123 connect(ui->comp_ModelWorkbench->view(), &CAircraftModelView::toggledHighlightStashedModels,
this,
124 &CDbMappingComponent::onStashedModelsChangedTriggerDigest);
126 connect(ui->comp_StashAircraft->view(), &CAircraftModelView::modelDataChangedDigest,
this,
127 &CDbMappingComponent::onStashedModelsDataChangedDigest);
128 connect(ui->comp_StashAircraft->view(), &CAircraftModelView::doubleClicked,
this,
129 &CDbMappingComponent::onModelRowSelected);
130 connect(ui->comp_StashAircraft->view(), &CAircraftModelView::requestHandlingOfStashDrop,
this,
131 &CDbMappingComponent::handleStashDropRequest);
133 &CDbMappingComponent::onStashedModelsChangedTriggerDigest);
135 &CDbMappingComponent::onModelsSuccessfullyPublished, Qt::QueuedConnection);
137 connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::modelDataChangedDigest,
this,
138 &CDbMappingComponent::onModelSetChangedDigest, Qt::QueuedConnection);
139 connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::requestStash,
this,
142 connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged,
this, &CDbMappingComponent::onTabIndexChanged);
143 connect(ui->tw_ModelsToBeMapped, &QTabWidget::currentChanged, ui->comp_ModelMatcher,
146 connect(ui->comp_OwnModelSet->view(), &CAircraftModelView::doubleClicked,
this,
147 &CDbMappingComponent::onModelRowSelected);
150 this->onModelSetChangedDigest(ui->comp_OwnModelSet->view()->rowCount(),
151 ui->comp_OwnModelSet->view()->hasFilter());
152 this->onStashedModelsDataChangedDigest(ui->comp_StashAircraft->view()->rowCount(),
153 ui->comp_StashAircraft->view()->hasFilter());
154 this->onOwnModelsChangedDigest(ui->comp_OwnAircraftModels->view()->rowCount(),
155 ui->comp_OwnAircraftModels->view()->hasFilter());
158 ui->comp_ModelMatcher->setWorkbenchView(ui->comp_ModelWorkbench->view());
161 ui->editor_AircraftModel->setSelectOnly();
163 ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16());
164 ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16());
165 ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModelSet, CIcons::appModels16());
166 ui->tw_ModelsToBeMapped->setTabIcon(TabWorkbench, CIcons::wrench16());
169 this->setContextMenuPolicy(Qt::CustomContextMenu);
170 connect(
this, &CDbMappingComponent::customContextMenuRequested,
this,
171 &CDbMappingComponent::onCustomContextMenu);
175 this->initVPilotLoading();
180 void CDbMappingComponent::initVPilotLoading()
182 m_vPilotEnabled = this->vPilotSupport && m_swiftDbUser.
get().hasAdminRole();
183 static const QString tabName(ui->tw_ModelsToBeMapped->tabText(TabVPilot));
185 if (m_vPilot1stInit && vPilotSupport)
187 m_vPilot1stInit =
false;
188 connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked,
this,
189 &CDbMappingComponent::onModelRowSelected);
190 connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::modelDataChanged,
this,
191 &CDbMappingComponent::onVPilotDataChanged);
192 connect(&m_vPilotReader, &CVPilotRulesReader::readFinished,
this,
193 &CDbMappingComponent::onLoadVPilotDataFinished);
194 connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash,
this,
196 connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels,
this,
197 &CDbMappingComponent::onStashedModelsChangedTriggerDigest);
198 connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestUpdate,
this,
199 &CDbMappingComponent::requestVPilotDataUpdate);
201 ui->tvp_AircraftModelsForVPilot->setCustomMenu(
new CMappingVPilotMenu(
this));
202 ui->tvp_AircraftModelsForVPilot->setCustomMenu(
new CStashToolsMenu(
this));
203 ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(
true);
205 ui->tvp_AircraftModelsForVPilot->addFilterDialog();
207 ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(vPilotModels);
208 const int noModels = vPilotModels.size();
211 ui->tab_VPilot->setEnabled(m_vPilotEnabled);
212 ui->tab_VPilot->setVisible(m_vPilotEnabled);
216 ui->tw_ModelsToBeMapped->addTab(ui->tab_VPilot, tabName);
217 this->onVPilotDataChanged(ui->tvp_AircraftModelsForVPilot->rowCount(),
218 ui->tvp_AircraftModelsForVPilot->hasFilter());
222 m_vPilotFormatted =
false;
223 ui->tw_ModelsToBeMapped->removeTab(TabVPilot);
227 void CDbMappingComponent::formatVPilotView()
229 if (!m_vPilotEnabled || m_vPilotFormatted) {
return; }
230 m_vPilotFormatted =
true;
231 ui->tvp_AircraftModelsForVPilot->presizeOrFullResizeToContents();
234 CAircraftModel CDbMappingComponent::getModelFromView(
const QModelIndex &index)
const
237 const QObject *sender = QObject::sender();
240 if (sender == ui->tvp_AircraftModelsForVPilot) {
return ui->tvp_AircraftModelsForVPilot->at(index); }
241 if (sender == ui->comp_OwnAircraftModels->view()) {
return ui->comp_OwnAircraftModels->view()->at(index); }
242 if (sender == ui->comp_StashAircraft || sender == ui->comp_StashAircraft->view())
244 return ui->comp_StashAircraft->view()->at(index);
246 if (sender == ui->comp_OwnModelSet->view()) {
return ui->comp_OwnModelSet->view()->at(index); }
251 return mv->
at(index);
258 ui->comp_OwnAircraftModels->gracefulShutdown();
264 if (!mv) {
return false; }
278 case TabOwnModels:
return ui->comp_OwnAircraftModels->view();
279 case TabVPilot:
return ui->tvp_AircraftModelsForVPilot;
280 case TabWorkbench:
return ui->comp_ModelWorkbench->view();
281 case TabStash:
return ui->comp_StashAircraft->view();
282 case TabOwnModelSet:
return ui->comp_OwnModelSet->view();
283 default:
return nullptr;
287 QString CDbMappingComponent::currentTabText()
const
289 const int i = ui->tw_ModelsToBeMapped->currentIndex();
290 return ui->tw_ModelsToBeMapped->tabText(i);
293 void CDbMappingComponent::updateEditorsWhenApplicable()
295 const CAircraftModel currentEditorModel(ui->editor_ModelMapping->getValue());
296 if (!currentEditorModel.hasModelString()) {
return; }
297 const QString modelString(currentEditorModel.getModelString());
298 const CAircraftModel currentStashedModel(ui->comp_StashAircraft->getStashedModel(modelString));
299 if (!currentStashedModel.hasModelString()) {
return; }
303 bool updated =
false;
304 const CLivery stashedLivery(currentStashedModel.getLivery());
305 if (stashedLivery.hasValidDbKey())
307 if (ui->editor_AircraftModel->setLivery(stashedLivery)) { updated =
true; }
310 const CDistributor stashedDistributor(currentStashedModel.getDistributor());
311 if (stashedDistributor.hasValidDbKey())
313 if (ui->editor_AircraftModel->setDistributor(stashedDistributor)) { updated =
true; }
316 const CAircraftIcaoCode stashedIcaoCode(currentStashedModel.getAircraftIcaoCode());
317 if (stashedIcaoCode.hasValidDbKey())
319 if (ui->editor_AircraftModel->setAircraftIcao(stashedIcaoCode)) { updated =
true; }
322 if (updated) {
CLogMessage(
this).
info(u
"Updated editor data for '%1'") << modelString; }
334 return ui->comp_StashAircraft->getStashedModels();
341 return ui->comp_StashAircraft->getStashedModelStrings();
346 if (!ui->tw_ModelsToBeMapped) {
return CDbMappingComponent::NoValidTab; }
347 const int t = ui->tw_ModelsToBeMapped->currentIndex();
357 const bool allowed = this->
currentTabIndex() == CDbMappingComponent::TabOwnModels ||
368 msgs.
push_back(ui->editor_ModelMapping->validate(
false));
369 msgs.
push_back(ui->editor_AircraftModel->validate(
true));
374 msgs.
push_back(ui->editor_ModelMapping->validate(
false));
379 void CDbMappingComponent::handleStashDropRequest(
const CAirlineIcaoCode &code)
const
382 if (!stdLivery.hasValidDbKey()) {
return; }
383 ui->comp_StashAircraft->applyToSelected(stdLivery);
386 void CDbMappingComponent::stashCurrentModel()
390 if (!msgs.hasErrorMessages())
396 msgs.push_back(ui->comp_StashAircraft->stashModel(editorModel,
true, consolidate));
401 void CDbMappingComponent::displayAutoStashingDialog() { m_autoStashDialog->exec(); }
403 void CDbMappingComponent::displayAutoSimulatorStashingDialog() { m_autoSimulatorDialog->exec(); }
405 void CDbMappingComponent::removeDbModelsFromView()
408 if (modelStrings.isEmpty()) {
return; }
413 void CDbMappingComponent::showChangedAttributes()
417 ui->comp_StashAircraft->showChangedAttributes();
420 void CDbMappingComponent::toggleAutoFiltering() { m_autoFilterInDbViews = !m_autoFilterInDbViews; }
422 void CDbMappingComponent::applyFormLiveryData()
424 if (ui->comp_StashAircraft->view()->selectedRowCount() < 1) {
return; }
427 else { ui->comp_StashAircraft->applyToSelected(ui->editor_AircraftModel->getLivery()); }
430 void CDbMappingComponent::applyFormAircraftIcaoData()
432 if (ui->comp_StashAircraft->view()->selectedRowCount() < 1) {
return; }
435 else { ui->comp_StashAircraft->applyToSelected(ui->editor_AircraftModel->getAircraftIcao()); }
438 void CDbMappingComponent::applyFormDistributorData()
440 if (ui->comp_StashAircraft->view()->selectedRowCount() < 1) {
return; }
443 else { ui->comp_StashAircraft->applyToSelected(ui->editor_AircraftModel->getDistributor()); }
449 if (ui->comp_StashAircraft->view()->hasSingleSelectedRow())
451 m_modelModifyDialog->setValue(ui->comp_StashAircraft->view()->selectedObject());
454 const QDialog::DialogCode s =
static_cast<QDialog::DialogCode
>(m_modelModifyDialog->exec());
455 if (s == QDialog::Rejected) {
return; }
457 ui->comp_StashAircraft->applyToSelected(vm);
464 const int h = this->height();
465 int h2 = ui->qw_EditorsScrollArea->minimumHeight();
466 h2 = qRound(h2 * 1.10);
467 int currentSize = ui->sp_MappingComponent->sizes().last();
468 if (h2 <= currentSize) {
return; }
481 const QList<int> sizes({ h1, h2 });
482 ui->sp_MappingComponent->setSizes(sizes);
487 const int h = this->height();
490 const QList<int> sizes({ h1, h2 });
491 ui->sp_MappingComponent->setSizes(sizes);
494 void CDbMappingComponent::loadVPilotData()
499 ui->tvp_AircraftModelsForVPilot->showLoadIndicator();
504 void CDbMappingComponent::onLoadVPilotDataFinished(
bool success)
506 if (!m_vPilotEnabled) {
return; }
511 if (ui->tvp_AircraftModelsForVPilot->displayAutomatically())
513 ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(models);
517 ui->tvp_AircraftModelsForVPilot->hideLoadIndicator();
520 void CDbMappingComponent::loadRemovedModels()
522 if (!ui->comp_ModelWorkbench->view()) {
return; }
523 const QString logDir = CSwiftDirectories::logDirectory();
524 ui->comp_ModelWorkbench->view()->showFileLoadDialog(logDir);
527 void CDbMappingComponent::onVPilotCacheChanged()
529 if (ui->tvp_AircraftModelsForVPilot->displayAutomatically())
531 ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(m_vPilotReader.
getAsModelsFromCache());
533 else { ui->tvp_AircraftModelsForVPilot->hideLoadIndicator(); }
536 void CDbMappingComponent::requestVPilotDataUpdate() { this->onVPilotCacheChanged(); }
538 void CDbMappingComponent::onStashedModelsChangedTriggerDigest()
543 void CDbMappingComponent::onStashedModelsChangedDigest()
545 const bool highlightVPilot = ui->tvp_AircraftModelsForVPilot->derivedModel()->highlightModels();
546 const bool highlightOwnModels = ui->comp_OwnAircraftModels->view()->derivedModel()->highlightModels();
547 const bool highlightModelSet = ui->comp_OwnModelSet->view()->derivedModel()->highlightModels();
548 const bool highlight = highlightOwnModels || highlightModelSet || highlightVPilot;
549 if (!highlight) {
return; }
550 const QStringList stashedModels(ui->comp_StashAircraft->getStashedModelStrings());
553 ui->tvp_AircraftModelsForVPilot->derivedModel()->setHighlightModelStrings(stashedModels);
555 if (highlightOwnModels)
557 ui->comp_OwnAircraftModels->view()->derivedModel()->setHighlightModelStrings(stashedModels);
559 if (highlightModelSet)
561 ui->comp_OwnModelSet->view()->derivedModel()->setHighlightModelStrings(stashedModels);
565 void CDbMappingComponent::onTabIndexChanged(
int index)
570 case CDbMappingComponent::TabOwnModelSet:
572 ui->frp_Editors->setVisible(
true);
573 ui->editor_ModelMapping->setVisible(
true);
577 case CDbMappingComponent::TabModelMatcher:
579 ui->editor_ModelMapping->setVisible(
false);
580 ui->frp_Editors->setVisible(
false);
584 case CDbMappingComponent::TabVPilot:
587 this->formatVPilotView();
592 ui->frp_Editors->setVisible(
true);
593 ui->editor_ModelMapping->setVisible(
true);
600 void CDbMappingComponent::onModelsSuccessfullyPublished(
const CAircraftModelList &models,
bool directWrite)
602 if (models.
isEmpty()) {
return; }
603 if (!directWrite) {
return; }
607 void CDbMappingComponent::onVPilotDataChanged(
int count,
bool withFilter)
611 ui->tvp_AircraftModelsForVPilot->setTabWidgetViewText(ui->tw_ModelsToBeMapped,
612 ui->tw_ModelsToBeMapped->indexOf(ui->tab_VPilot));
615 void CDbMappingComponent::onWorkbenchDataChanged(
int count,
bool withFilter)
619 ui->comp_ModelWorkbench->view()->setTabWidgetViewText(ui->tw_ModelsToBeMapped,
620 ui->tw_ModelsToBeMapped->indexOf(ui->tab_Workbench));
623 void CDbMappingComponent::ps_addToOwnModelSet()
628 CLogMessage::preformatted(m);
631 void CDbMappingComponent::mergeWithVPilotModels()
633 if (!ui->comp_OwnAircraftModels->modelLoader()) {
return; }
635 const CSimulatorInfo sim(ui->comp_OwnAircraftModels->getOwnModelsSimulator());
636 if (!sim.isSingleSimulator() || !sim.isMicrosoftOrPrepare3DSimulator()) {
return; }
638 if (ownModels.isEmpty()) {
return; }
639 ui->comp_OwnAircraftModels->view()->showLoadIndicator();
640 CAircraftModelUtilities::mergeWithVPilotData(ownModels, m_vPilotReader.
getAsModelsFromCache(),
true);
641 ui->comp_OwnAircraftModels->updateViewAndCache(ownModels);
644 void CDbMappingComponent::mergeSelectedWithVPilotModels()
646 if (!ui->comp_OwnAircraftModels->modelLoader()) {
return; }
648 if (!ui->comp_OwnAircraftModels->view()->hasSelection()) {
return; }
649 const CSimulatorInfo sim(ui->comp_OwnAircraftModels->getOwnModelsSimulator());
650 if (!sim.isSingleSimulator() || !sim.isMicrosoftOrPrepare3DSimulator()) {
return; }
652 if (ownModels.isEmpty()) {
return; }
653 ui->comp_OwnAircraftModels->view()->showLoadIndicator();
654 CAircraftModelUtilities::mergeWithVPilotData(ownModels, m_vPilotReader.
getAsModelsFromCache(),
true);
659 ui->comp_OwnAircraftModels->updateViewAndCache(allModels);
662 void CDbMappingComponent::onCustomContextMenu(
const QPoint &point)
664 QPoint globalPos = this->mapToGlobal(point);
665 QScopedPointer<QMenu> contextMenu(
new QMenu(
this));
668 QKeySequence(
static_cast<Qt::Key
>(Qt::CTRL) + Qt::Key_M, Qt::Key_D));
670 QKeySequence(
static_cast<Qt::Key
>(Qt::CTRL) + Qt::Key_M, Qt::Key_M));
671 QAction *selectedItem = contextMenu.data()->exec(globalPos);
672 Q_UNUSED(selectedItem)
675 void CDbMappingComponent::onStashedModelsDataChangedDigest(
int count,
bool withFilter)
679 ui->comp_StashAircraft->view()->setTabWidgetViewText(
680 ui->tw_ModelsToBeMapped, ui->tw_ModelsToBeMapped->indexOf(ui->tab_StashAircraftModels));
683 this->updateEditorsWhenApplicable();
686 void CDbMappingComponent::onModelSetChangedDigest(
int count,
bool withFilter)
692 int i = ui->tw_ModelsToBeMapped->indexOf(ui->tab_OwnModelSet);
693 QString o =
"Active model set " + ui->comp_OwnModelSet->getModelSetSimulator().toQString(
true);
694 const QString f = ui->comp_OwnModelSet->view()->hasFilter() ?
"F" :
"";
696 ui->tw_ModelsToBeMapped->setTabText(i, o);
699 void CDbMappingComponent::onOwnModelsChangedDigest(
int count,
bool withFilter)
705 const int i = ui->tw_ModelsToBeMapped->indexOf(ui->tab_OwnModels);
706 static const QString ot(
"Stored own models");
708 const QString sim(ui->comp_OwnAircraftModels->getOwnModelsSimulator().toQString(
true));
709 if (!sim.isEmpty()) { o = o.append(
" ").append(sim); }
710 const QString f = ui->comp_OwnAircraftModels->view()->hasFilter() ?
"F" :
"";
712 ui->tw_ModelsToBeMapped->setTabText(i, o);
715 void CDbMappingComponent::onUserChanged() { this->initVPilotLoading(); }
724 void CDbMappingComponent::onModelRowSelected(
const QModelIndex &index)
727 if (!model.hasModelString()) {
return; }
730 bool dbModel = model.hasValidDbKey();
731 const CLivery livery(dbModel ? model.getLivery() :
734 dbModel ? model.getAircraftIcaoCode() :
737 dbModel ? model.getDistributor() :
741 ui->editor_ModelMapping->setValue(model);
744 if (livery.hasValidDbKey()) { ui->editor_AircraftModel->setLivery(livery); }
745 else { ui->editor_AircraftModel->clearLivery(); }
746 if (aircraftIcao.hasValidDbKey()) { ui->editor_AircraftModel->setAircraftIcao(aircraftIcao); }
747 else { ui->editor_AircraftModel->clearAircraftIcao(); }
748 if (distributor.hasValidDbKey()) { ui->editor_AircraftModel->setDistributor(distributor); }
749 else { ui->editor_AircraftModel->clearDistributor(); }
752 if (m_autoFilterInDbViews)
760 void CDbMappingComponent::onOwnModelsSimulatorChanged(
const CSimulatorInfo simulator)
765 ui->comp_OwnAircraftModels->clearView();
766 this->onOwnModelsChangedDigest(0,
false);
774 model.
setLivery(ui->editor_AircraftModel->getLivery());
782 return ui->comp_OwnAircraftModels->getOwnCachedModels(simulator);
787 return ui->comp_OwnAircraftModels->getOwnSelectedModels();
792 return ui->comp_OwnAircraftModels->getOwnModelForModelString(modelString);
797 return ui->comp_OwnAircraftModels->getOwnModelsSimulator();
802 ui->comp_OwnAircraftModels->setSimulator(simulator);
811 return ui->comp_OwnAircraftModels->getInfoStringFsFamily();
817 ui->comp_OwnModelSet->setSimulator(simulator);
822 return ui->comp_OwnModelSet->getModelSetFromView();
827 return ui->comp_StashAircraft->stashModel(model, replace);
832 return ui->comp_StashAircraft->stashModels(models);
838 return ui->comp_OwnModelSet->addToModelSet(models, simulator);
843 return ui->comp_StashAircraft->consolidateModel(model);
848 ui->comp_StashAircraft->replaceModelsUnvalidated(models);
851 void CDbMappingComponent::CMappingVPilotMenu::customMenu(
CMenuActions &menuActions)
854 Q_ASSERT_X(mapComp, Q_FUNC_INFO,
"Cannot access mapping component");
856 const bool canUseVPilot = mappingComponent()->withVPilot();
859 m_menuAction = menuActions.
addAction(m_menuAction, CIcons::appMappings16(),
"Load vPilot Rules",
860 CMenuAction::pathVPilot(),
this,
861 { mapComp, &CDbMappingComponent::loadVPilotData });
863 this->nestedCustomMenu(menuActions);
866 CDbMappingComponent *CDbMappingComponent::CMappingVPilotMenu::mappingComponent()
const
868 return qobject_cast<CDbMappingComponent *>(this->parent());
871 CDbMappingComponent::CStashToolsMenu::CStashToolsMenu(CDbMappingComponent *mappingComponent)
875 void CDbMappingComponent::CStashToolsMenu::customMenu(
CMenuActions &menuActions)
877 CDbMappingComponent *mapComp = mappingComponent();
878 Q_ASSERT_X(mapComp, Q_FUNC_INFO,
"no mapping component");
879 if (!mapComp->currentModelView()->isEmpty() &&
880 mapComp->currentModelView()->getMenu().testFlag(CViewBaseNonTemplate::MenuCanStashModels))
885 m_stashFiltering = menuActions.
addAction(
886 m_stashFiltering, CIcons::filter16(),
"Auto filtering in DB views (on/off)",
887 CMenuAction::pathModelStash(),
this, { mapComp, &CDbMappingComponent::toggleAutoFiltering });
888 m_stashFiltering->setCheckable(
true);
889 m_stashFiltering->setChecked(mapComp->m_autoFilterInDbViews);
891 m_autoStashing = menuActions.
addAction(m_autoStashing, CIcons::appDbStash16(),
"Auto stashing",
892 CMenuAction::pathModelStash(),
this,
893 { mapComp, &CDbMappingComponent::displayAutoStashingDialog });
894 m_autoSimulatorStashing =
895 menuActions.
addAction(m_autoSimulatorStashing, CIcons::appDbStash16(),
896 "Cross simulator updating (FSX-P3D-FS9)", CMenuAction::pathModelStash(),
this,
897 { mapComp, &CDbMappingComponent::displayAutoSimulatorStashingDialog });
898 if (mapComp->m_autoStashDialog && mapComp->m_autoStashDialog->isCompleted())
901 CIcons::appDbStash16(),
"Last auto stash run", CMenuAction::pathModelStash(),
nullptr,
905 else if (mapComp->currentTabIndex() == CDbMappingComponent::TabStash)
907 this->addStashViewSpecificMenus(menuActions);
909 this->nestedCustomMenu(menuActions);
912 void CDbMappingComponent::CStashToolsMenu::addStashViewSpecificMenus(
CMenuActions &menuActions)
914 CDbMappingComponent *mapComp = mappingComponent();
915 Q_ASSERT_X(mapComp, Q_FUNC_INFO,
"no mapping component");
918 if (dbModels > 0 && mapComp->hasStashedModels())
920 menuActions.
addMenu(CIcons::appDbStash16(),
"Stash", CMenuAction::pathModelStash());
923 const QString msgDelete(
"Delete " + QString::number(dbModels) +
" DB model(s) from '" +
924 mapComp->currentTabText() +
"'");
925 menuActions.
addAction(CIcons::delete16(), msgDelete, CMenuAction::pathModelStash(),
nullptr,
926 { mapComp, &CDbMappingComponent::removeDbModelsFromView });
929 menuActions.
addAction(CIcons::info16(),
"Show changed attributes", CMenuAction::pathModelStash(),
nullptr,
930 { mapComp, &CDbMappingComponent::showChangedAttributes });
934 CDbMappingComponent *CDbMappingComponent::CStashToolsMenu::mappingComponent()
const
936 return qobject_cast<CDbMappingComponent *>(this->parent());
939 void CDbMappingComponent::COwnModelSetMenu::customMenu(
CMenuActions &menuActions)
941 CDbMappingComponent *mapComp = mappingComponent();
942 Q_ASSERT_X(mapComp, Q_FUNC_INFO,
"no mapping component");
943 if (mapComp->canAddToModelSetTab())
947 m_menuAction, CIcons::appModels16(),
949 CMenuAction::pathModelSet(),
this, { mapComp, &CDbMappingComponent::ps_addToOwnModelSet },
952 this->nestedCustomMenu(menuActions);
955 CDbMappingComponent *CDbMappingComponent::COwnModelSetMenu::mappingComponent()
const
957 return qobject_cast<CDbMappingComponent *>(this->parent());
960 void CDbMappingComponent::CApplyDbDataMenu::customMenu(
CMenuActions &menuActions)
962 CDbMappingComponent *mapComp = mappingComponent();
963 Q_ASSERT_X(mapComp, Q_FUNC_INFO,
"no mapping component");
965 if (mapComp->currentTabIndex() == CDbMappingComponent::TabStash && mapComp->currentModelView()->hasSelection())
967 if (m_menuActions.isEmpty()) { m_menuActions = QList<QAction *>({
nullptr,
nullptr,
nullptr,
nullptr }); }
972 m_menuActions[0] = menuActions.
addAction(m_menuActions[0], CIcons::appAircraftIcao16(),
973 "Current aircraft ICAO", CMenuAction::pathModelStashEditor(),
this,
974 { mapComp, &CDbMappingComponent::applyFormAircraftIcaoData });
975 m_menuActions[1] = menuActions.
addAction(m_menuActions[1], CIcons::appDistributors16(),
976 "Current distributor", CMenuAction::pathModelStashEditor(),
this,
977 { mapComp, &CDbMappingComponent::applyFormDistributorData });
978 m_menuActions[2] = menuActions.
addAction(m_menuActions[2], CIcons::appLiveries16(),
"Current livery",
979 CMenuAction::pathModelStashEditor(),
this,
980 { mapComp, &CDbMappingComponent::applyFormLiveryData });
981 m_menuActions[3] = menuActions.
addAction(m_menuActions[3], CIcons::databaseTable16(),
982 "Modify DB model data", CMenuAction::pathModelStashEditor(),
this,
985 this->nestedCustomMenu(menuActions);
988 CDbMappingComponent *CDbMappingComponent::CApplyDbDataMenu::mappingComponent()
const
990 return qobject_cast<CDbMappingComponent *>(this->parent());
993 CDbMappingComponent::CMergeWithVPilotMenu::CMergeWithVPilotMenu(CDbMappingComponent *mappingComponent)
996 Q_ASSERT_X(mappingComponent, Q_FUNC_INFO,
"Missing vPilot reader");
999 void CDbMappingComponent::CMergeWithVPilotMenu::customMenu(
CMenuActions &menuActions)
1001 const CAircraftModelView *mv = mappingComponent()->ui->comp_OwnAircraftModels->view();
1002 const CSimulatorInfo sim = mappingComponent()->ui->comp_OwnAircraftModels->getOwnModelsSimulator();
1006 this->nestedCustomMenu(menuActions);
1010 if (m_menuActions.isEmpty()) { m_menuActions = QList<QAction *>({
nullptr,
nullptr }); }
1011 menuActions.
addMenu(
"Merge with vPilot data", CMenuAction::pathVPilot());
1012 m_menuActions[0] = menuActions.
addAction(m_menuActions[0],
"All", CMenuAction::pathVPilot(),
this,
1013 { mappingComponent(), &CDbMappingComponent::mergeWithVPilotModels });
1017 menuActions.
addAction(m_menuActions[1],
"Selected only", CMenuAction::pathVPilot(),
this,
1018 { mappingComponent(), &CDbMappingComponent::mergeSelectedWithVPilotModels });
1020 this->nestedCustomMenu(menuActions);
1023 void CDbMappingComponent::CRemovedModelsMenu::customMenu(
CMenuActions &menuActions)
1025 CDbMappingComponent *mapComp = mappingComponent();
1026 Q_ASSERT_X(mapComp, Q_FUNC_INFO,
"no mapping component");
1027 if (mapComp->isWorkbenchTab())
1031 menuActions.
addAction(m_menuAction, CIcons::appModels16(),
"Removed models", CMenuAction::pathModel(),
1032 this, { mapComp, &CDbMappingComponent::loadRemovedModels });
1034 this->nestedCustomMenu(menuActions);
1037 CDbMappingComponent *CDbMappingComponent::CRemovedModelsMenu::mappingComponent()
const
1039 return qobject_cast<CDbMappingComponent *>(this->parent());
1042 CDbMappingComponent *CDbMappingComponent::CMergeWithVPilotMenu::mappingComponent()
const
1044 return qobject_cast<CDbMappingComponent *>(this->parent());
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::aviation::CAircraftIcaoCode smartAircraftIcaoSelector(const swift::misc::aviation::CAircraftIcaoCode &icao) const
Use an ICAO object to select the best complete ICAO object from DB for it.
int getModelsCount() const
Models count.
swift::misc::aviation::CLivery getStdLiveryForAirlineCode(const swift::misc::aviation::CAirlineIcaoCode &icao) const
Standard livery for airline code.
swift::misc::simulation::CDistributor smartDistributorSelector(const swift::misc::simulation::CDistributor &distributor) const
Use distributor object to select the best complete distributor from DB.
swift::misc::aviation::CLivery smartLiverySelector(const swift::misc::aviation::CLivery &livery) const
Use a livery as template and select the best complete livery from DB for it.
QStringList getModelStrings(bool sort=false) const
Model strings.
static QString replaceTabCountValue(const QString &oldName, int count)
Replace count in name such as "stations (4)".
void showOverlayMessagesOrHTMLMessage(const swift::misc::CStatusMessageList &messages, bool appendOldMessages=false, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show multiple messages or a single message (HTML)
Using this class provides a QFrame with the overlay functionality already integrated.
static const QKeySequence & keyAddToModelSet()
Add to model set.
static QString toParenthesisString(const QKeySequence &sequence)
As string for menus etc. Looks like "(CTRL + R)".
Allows to automatically update models if found in own model set, but already existing for a sibling s...
void showLastResults()
Show last result.
bool hasSelectedModelsToStash() const
Any models which can be stashed?
TabIndex currentTabIndex() const
Current tab index.
void setOwnModelSetSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Set simulator for own models.
void replaceStashedModelsUnvalidated(const swift::misc::simulation::CAircraftModelList &models) const
Replace models, no validation.
void tabIndexChanged(int index)
Tab index has been changed.
swift::misc::CStatusMessageList stashModels(const swift::misc::simulation::CAircraftModelList &models)
Stash given models (includes validation and consolidation with DB data)
bool isStashTab() const
Is stashed view?
virtual ~CDbMappingComponent()
Destructor.
void stashSelectedModels()
Stash models.
swift::misc::simulation::CAircraftModelList getSelectedModelsToStash() const
Models to be stashed from currently activated tab (table view)
void maxTableView()
Max. space for table view.
swift::misc::simulation::CAircraftModelList getOwnSelectedModels() const
Own selected models.
swift::misc::CStatusMessage addToOwnModelSet(const swift::misc::simulation::CAircraftModelList &models, const swift::misc::simulation::CSimulatorInfo &simulator)
Add to model set.
bool canAddToModelSetTab() const
Tab can contribute to model set.
bool isWorkbenchTab() const
Is workbench tab?
int getOwnModelsCount() const
Number of own models.
swift::misc::simulation::CSimulatorInfo getOwnModelsSimulator() const
Own models for simulator.
void gracefulShutdown()
Graceful shutdown.
void requestUpdatedData(swift::misc::network::CEntityFlags::Entity entities)
Request latest (incremental) data from backend.
swift::misc::simulation::CAircraftModelList getOwnModelSet() const
Own model set.
void resizeForMapping()
Resize so that mapping is easier.
swift::misc::CStatusMessageList validateCurrentModel(bool withNestedForms) const
Validate, empty list means OK.
void filterByAircraftIcao(const swift::misc::aviation::CAircraftIcaoCode &icao)
Request to filter by aircraft ICAO.
swift::misc::simulation::CAircraftModelList getOwnModels() const
Own cached models.
views::CAircraftModelView * currentModelView() const
Current model view.
swift::misc::simulation::CAircraftModel getEditorAircraftModel() const
Unvalidated consolidated aircraft model from the editor subparts (icao, distributor)
QString getOwnModelsInfoString() const
Info string about models in cache.
void setOwnModelsSimulator(const swift::misc::simulation::CSimulatorInfo &simulator)
Set simulator for own models.
void modifyModelDialog()
Open model modify dialog.
views::CAircraftModelView * modelView(TabIndex tab) const
Current model view.
swift::misc::simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const
Own (installed) model for given model string.
swift::misc::simulation::CAircraftModelList getOwnCachedModels(const swift::misc::simulation::CSimulatorInfo &simulator) const
Own cached models.
void filterByDistributor(const swift::misc::simulation::CDistributor &distributor)
Request to filter by distributor.
swift::misc::CStatusMessage stashModel(const swift::misc::simulation::CAircraftModel &model, bool replace=false)
Stash given model (includes validation and consolidation with DB data)
void filterByLivery(const swift::misc::aviation::CLivery &livery)
Request to filter by livery.
const swift::misc::simulation::CAircraftModelList & getStashedModels() const
Any stashed models?
bool hasStashedModels() const
Any stashed models?
QString getOwnModelsInfoStringFsFamily() const
Info string without XPlane (FSX,P3D, FS9)
QStringList getStashedModelStrings() const
Stashed model strings.
swift::misc::simulation::CAircraftModel consolidateModel(const swift::misc::simulation::CAircraftModel &model) const
Consolidate with other available data.
void resizeForSelect()
Resize so that selection is easy (larger table view)
Modify model fields as dialog.
void ownModelsSimulatorChanged(const swift::misc::simulation::CSimulatorInfo &simulator)
Own models simulator has changed.
void stashedModelsChanged()
Stashed models have been changed.
void modelsSuccessfullyPublished(const swift::misc::simulation::CAircraftModelList &publishedModels, bool directWrite)
Models succesfully published.
void tabIndexChanged(int index)
Tab (where this component is embedded) has been changed.
int removeModelsWithModelString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive)
Remove models with model strings.
bool hasSelectedModelsToStash() const
Has any models to stash and it is allowed to stash.
virtual bool isEmpty() const
Empty?
virtual ContainerType selectedObjects() const
Selected objects.
const ObjectType & at(const QModelIndex &index) const
Value object at.
bool hasSelection() const
Selection (selected rows)
T get() const
Get a copy of the current value.
void inputSignal()
Received input signal, or manually trigger.
Class for emitting a log message.
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.
Derived & info(const char16_t(&format)[N])
Set the severity to info, providing a format string.
Specialized value object compliant map for variants, based on indexes.
void push_back(const T &value)
Appends an element at the end of the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
Status messages, e.g. from Core -> GUI.
bool hasWarningOrErrorMessages() const
Warning or error messages.
bool hasErrorMessages() const
Error messages.
Value object for ICAO classification.
Value object for ICAO classification.
Value object encapsulating information about an airpot.
Aircraft model (used by another pilot, my models on disk)
void setLivery(const aviation::CLivery &livery)
Livery.
void setDistributor(const CDistributor &distributor)
Set distributor.
bool setAircraftIcaoCode(const aviation::CAircraftIcaoCode &aircraftIcaoCode)
Set aircraft ICAO code.
Value object encapsulating a list of aircraft models.
int replaceOrAddModelsWithString(const CAircraftModelList &addOrReplaceList, Qt::CaseSensitivity sensitivity)
Replace or add based on model string.
Value object encapsulating information of software distributor.
Simple hardcoded info about the corresponding simulator.
bool isSingleSimulator() const
Single simulator selected.
bool isMicrosoftOrPrepare3DSimulator() const
Microsoft Simulator or P3D?
swift::misc::simulation::CAircraftModelList getAsModels()
Get as models.
void gracefulShutdown()
Graceful shutdown.
int getModelsCount() const
Get model count.
swift::misc::simulation::CAircraftModelList getAsModelsFromCache() const
Get as models from cache.
swift::misc::CWorker * readInBackground(bool convertToModels)
Load data in background thread.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.