diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index 9cac35e7e..61404d92b 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -68,6 +68,7 @@ namespace BlackGui this->ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16()); this->ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16()); + this->ui->comp_StashAircraft->getView()->setCustomMenu(new CApplyDbDataMenu(this)); // vPilot this->initVPilotLoading(); @@ -342,6 +343,55 @@ namespace BlackGui this->m_autoFilterInDbViews = !this->m_autoFilterInDbViews; } + void CDbMappingComponent::ps_applyDbData() + { + QAction *sender = qobject_cast(this->sender()); + if (!sender) { return; } + QString cn(sender->data().toString()); + if (cn.isEmpty()) { return; } + if (this->ui->comp_StashAircraft->getView()->selectedRowCount() < 1) { return; } + + CStatusMessageList msgs; + if (CLivery().getClassName() == cn) + { + msgs = this->ui->editor_Livery->validate(true); + if (!msgs.hasErrorMessages()) + { + this->ui->comp_StashAircraft->applyToSelected(this->ui->editor_Livery->getValue()); + } + } + else if (CDistributor().getClassName() == cn) + { + msgs = this->ui->editor_Distributor->validate(); + if (!msgs.hasErrorMessages()) + { + this->ui->comp_StashAircraft->applyToSelected(this->ui->editor_Distributor->getValue()); + } + } + else if (CAircraftIcaoCode().getClassName() == cn) + { + msgs = this->ui->editor_AircraftIcao->validate(); + if (!msgs.hasErrorMessages()) + { + this->ui->comp_StashAircraft->applyToSelected(this->ui->editor_AircraftIcao->getValue()); + } + } + else if (CAirlineIcaoCode().getClassName() == cn) + { + msgs = this->ui->editor_Livery->validateAirlineIcao(); + if (!msgs.hasErrorMessages()) + { + this->ui->comp_StashAircraft->applyToSelected(this->ui->editor_Livery->getValueAirlineIcao()); + } + } + + // errors if any + if (msgs.hasErrorMessages()) + { + this->showMessages(msgs); + } + } + void CDbMappingComponent::resizeForSelect() { int h = this->height(); @@ -698,7 +748,7 @@ namespace BlackGui } // auto filter in DB views - QAction *a = menu.addAction(CIcons::filter16(), "Auto filtering (DB views)", mapComp, SLOT(ps_toggleAutoFiltering())); + QAction *a = menu.addAction(CIcons::filter16(), "Auto filtering in DB views (on/off)", mapComp, SLOT(ps_toggleAutoFiltering())); a->setCheckable(true); a->setChecked(mapComp->m_autoFilterInDbViews); } @@ -710,5 +760,36 @@ namespace BlackGui { return qobject_cast(this->parent()); } + + void CDbMappingComponent::CApplyDbDataMenu::customMenu(QMenu &menu) const + { + CDbMappingComponent *mapComp = mappingComponent(); + Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component"); + + if (mapComp->currentTabIndex() == CDbMappingComponent::TabStash && mapComp->currentModelView()->hasSelection()) + { + // stash view and selection + QMenu *subMenu = menu.addMenu(CIcons::database16(), "Apply DB data (to selected)"); + QAction *a = nullptr; + + a = subMenu->addAction(CIcons::appAircraftIcao16(), "Current aircraft ICAO", mapComp, SLOT(ps_applyDbData())); + a->setData(CAircraftIcaoCode().getClassName()); + + a = subMenu->addAction(CIcons::appDistributors16(), "Current distributor", mapComp, SLOT(ps_applyDbData())); + a->setData(CDistributor().getClassName()); + + a = subMenu->addAction(CIcons::appLiveries16(), "Current livery", mapComp, SLOT(ps_applyDbData())); + a->setData(CLivery().getClassName()); + + // a = subMenu->addAction(CIcons::appAirlineIcao16(), "Current airline ICAO", mapComp, SLOT(ps_applyDbData())); + // a->setData(CAirlineIcaoCode().getClassName()); + } + this->nestedCustomMenu(menu); + } + + CDbMappingComponent *CDbMappingComponent::CApplyDbDataMenu::mappingComponent() const + { + return qobject_cast(this->parent()); + } } // ns } // ns diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index 5233bacee..f95504e9d 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -138,7 +138,7 @@ namespace BlackGui //! Request to filter by distributor void filterByDistributor(const BlackMisc::Simulation::CDistributor &distributor); - //! Request latest (incrementall) data from backend + //! Request latest (incremental) data from backend void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entities); private slots: @@ -199,6 +199,9 @@ namespace BlackGui //! Toggle auto filtering void ps_toggleAutoFiltering(); + //! Apply current DB data from form + void ps_applyDbData(); + private: QScopedPointer ui; QScopedArrayPointer m_autostashDialog { new CDbAutoStashingComponent(this) }; @@ -260,6 +263,7 @@ namespace BlackGui //! Menu for tools: //! 1) removing DB models from current view and //! 2) for auto stashing + //! 3) toggle auto filtering //! \note This is a specific menu for that very component class CModelStashTools : public BlackGui::IMenuDelegate { @@ -276,6 +280,23 @@ namespace BlackGui //! Mapping component CDbMappingComponent *mappingComponent() const; }; + + //! Apply DB data to selected models + class CApplyDbDataMenu : public BlackGui::IMenuDelegate + { + public: + //! Constructor + CApplyDbDataMenu(CDbMappingComponent *mappingComponent, bool separator = true) : + BlackGui::IMenuDelegate(mappingComponent, separator) + {} + + //! \copydoc IMenuDelegate::customMenu + virtual void customMenu(QMenu &menu) const override; + + private: + //! Mapping component + CDbMappingComponent *mappingComponent() const; + }; }; } // ns } // ns diff --git a/src/blackgui/editors/liveryform.cpp b/src/blackgui/editors/liveryform.cpp index b7cf2a8f3..5cb1cb882 100644 --- a/src/blackgui/editors/liveryform.cpp +++ b/src/blackgui/editors/liveryform.cpp @@ -59,6 +59,11 @@ namespace BlackGui return livery; } + CAirlineIcaoCode CLiveryForm::getValueAirlineIcao() const + { + return this->ui->editor_AirlineIcao->getValue(); + } + void CLiveryForm::setValue(const CLivery &livery) { this->ui->livery_Selector->setLivery(livery); @@ -88,6 +93,11 @@ namespace BlackGui return msgs; } + CStatusMessageList CLiveryForm::validateAirlineIcao() const + { + return this->ui->editor_AirlineIcao->validate(); + } + void CLiveryForm::allowDrop(bool allowDrop) { this->ui->drop_DropData->allowDrop(allowDrop); diff --git a/src/blackgui/editors/liveryform.h b/src/blackgui/editors/liveryform.h index 3a3185eaf..526681103 100644 --- a/src/blackgui/editors/liveryform.h +++ b/src/blackgui/editors/liveryform.h @@ -45,9 +45,15 @@ namespace BlackGui //! Value BlackMisc::Aviation::CLivery getValue() const; + //! Embedded ariline + BlackMisc::Aviation::CAirlineIcaoCode getValueAirlineIcao() const; + //! Validate, empty list means OK BlackMisc::CStatusMessageList validate(bool withNestedForms) const; + //! Validate airline ICAO code only + BlackMisc::CStatusMessageList validateAirlineIcao() const; + //! Allow to drop void allowDrop(bool allowDrop);