From 6fda875e8f42baa107f4ee5c4e0167ec6b20d171 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Fri, 2 Oct 2015 14:50:19 +0200 Subject: [PATCH] refs #475, added a utility class so the load indicator of a view can be triggered from the framing component --- .../components/dbaircrafticaocomponent.cpp | 1 + .../components/dbaircrafticaocomponent.h | 2 + .../components/dbairlineicaocomponent.cpp | 2 +- .../components/dbairlineicaocomponent.h | 2 + .../components/dbcountrycomponent.cpp | 2 +- src/blackgui/components/dbcountrycomponent.h | 2 + .../components/dbdistributorcomponent.cpp | 2 +- .../components/dbdistributorcomponent.h | 2 + src/blackgui/components/dbliverycomponent.cpp | 1 + src/blackgui/components/dbliverycomponent.h | 2 + .../components/dbmappingcomponent.cpp | 17 ++++-- src/blackgui/components/dbmappingcomponent.h | 2 + src/blackgui/components/dbmodelcomponent.cpp | 2 +- src/blackgui/components/dbmodelcomponent.h | 2 + src/blackgui/enableforviewbasedindicator.cpp | 55 +++++++++++++++++++ src/blackgui/enableforviewbasedindicator.h | 50 +++++++++++++++++ 16 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 src/blackgui/enableforviewbasedindicator.cpp create mode 100644 src/blackgui/enableforviewbasedindicator.h diff --git a/src/blackgui/components/dbaircrafticaocomponent.cpp b/src/blackgui/components/dbaircrafticaocomponent.cpp index 268ed41d3..d63aae668 100644 --- a/src/blackgui/components/dbaircrafticaocomponent.cpp +++ b/src/blackgui/components/dbaircrafticaocomponent.cpp @@ -25,6 +25,7 @@ namespace BlackGui ui(new Ui::CDbAircraftIcaoComponent) { ui->setupUi(this); + this->setViewWithIndicator(this->ui->tvp_AircraftIcao); this->ui->tvp_AircraftIcao->setResizeMode(CViewBaseNonTemplate::ResizingOff); connect(this->ui->tvp_AircraftIcao, &CAircraftIcaoCodeView::requestNewBackendData, this, &CDbAircraftIcaoComponent::ps_reload); diff --git a/src/blackgui/components/dbaircrafticaocomponent.h b/src/blackgui/components/dbaircrafticaocomponent.h index efe6b882e..b847a2d77 100644 --- a/src/blackgui/components/dbaircrafticaocomponent.h +++ b/src/blackgui/components/dbaircrafticaocomponent.h @@ -13,6 +13,7 @@ #define BLACKGUI_COMPONENTS_DBAIRCRAFTICAOCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/network/webdataservicesprovider.h" #include @@ -30,6 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbAircraftIcaoComponent : public QFrame, public CEnableForDockWidgetInfoArea, + public CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/components/dbairlineicaocomponent.cpp b/src/blackgui/components/dbairlineicaocomponent.cpp index 1e0f422b4..17985eaee 100644 --- a/src/blackgui/components/dbairlineicaocomponent.cpp +++ b/src/blackgui/components/dbairlineicaocomponent.cpp @@ -22,10 +22,10 @@ namespace BlackGui { CDbAirlineIcaoComponent::CDbAirlineIcaoComponent(QWidget *parent) : QFrame(parent), - CWebDataServicesAware(nullptr), ui(new Ui::CDbAirlineIcaoComponent) { ui->setupUi(this); + this->setViewWithIndicator(this->ui->tvp_AirlineIcao); this->ui->tvp_AirlineIcao->setResizeMode(CViewBaseNonTemplate::ResizingOff); this->ui->tvp_AirlineIcao->setResizeMode(CViewBaseNonTemplate::ResizingOff); this->ui->tvp_AirlineIcao->allowDragDropValueObjects(true, false); diff --git a/src/blackgui/components/dbairlineicaocomponent.h b/src/blackgui/components/dbairlineicaocomponent.h index 193044b3f..971343f25 100644 --- a/src/blackgui/components/dbairlineicaocomponent.h +++ b/src/blackgui/components/dbairlineicaocomponent.h @@ -13,6 +13,7 @@ #define BLACKGUI_COMPONENTS_DBAIRLINEICAOCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/network/webdataservicesprovider.h" #include @@ -30,6 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbAirlineIcaoComponent : public QFrame, public CEnableForDockWidgetInfoArea, + public BlackGui::CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/components/dbcountrycomponent.cpp b/src/blackgui/components/dbcountrycomponent.cpp index f51cd6ab6..185924c88 100644 --- a/src/blackgui/components/dbcountrycomponent.cpp +++ b/src/blackgui/components/dbcountrycomponent.cpp @@ -22,10 +22,10 @@ namespace BlackGui { CDbCountryComponent::CDbCountryComponent(QWidget *parent) : QFrame(parent), - CWebDataServicesAware(nullptr), ui(new Ui::CDbCountryComponent) { ui->setupUi(this); + this->setViewWithIndicator(this->ui->tvp_Countries); this->ui->tvp_Countries->setResizeMode(CViewBaseNonTemplate::ResizingOnce); connect(this->ui->tvp_Countries, &CCountryView::requestNewBackendData, this, &CDbCountryComponent::ps_reload); diff --git a/src/blackgui/components/dbcountrycomponent.h b/src/blackgui/components/dbcountrycomponent.h index dce125b63..aa8d45c33 100644 --- a/src/blackgui/components/dbcountrycomponent.h +++ b/src/blackgui/components/dbcountrycomponent.h @@ -13,6 +13,7 @@ #define BLACKGUI_COMPONENTS_DBCOUNTRYCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/network/webdataservicesprovider.h" #include @@ -30,6 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbCountryComponent : public QFrame, public CEnableForDockWidgetInfoArea, + public BlackGui::CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/components/dbdistributorcomponent.cpp b/src/blackgui/components/dbdistributorcomponent.cpp index 512b5f671..0ed1abbce 100644 --- a/src/blackgui/components/dbdistributorcomponent.cpp +++ b/src/blackgui/components/dbdistributorcomponent.cpp @@ -21,10 +21,10 @@ namespace BlackGui { CDbDistributorComponent::CDbDistributorComponent(QWidget *parent) : QFrame(parent), - CWebDataServicesAware(nullptr), ui(new Ui::CDbDistributorComponent) { ui->setupUi(this); + this->setViewWithIndicator(this->ui->tvp_Distributors); this->ui->tvp_Distributors->setResizeMode(CViewBaseNonTemplate::ResizingAuto); this->ui->tvp_Distributors->allowDragDropValueObjects(true, false); connect(this->ui->tvp_Distributors, &CDistributorView::requestNewBackendData, this, &CDbDistributorComponent::ps_reload); diff --git a/src/blackgui/components/dbdistributorcomponent.h b/src/blackgui/components/dbdistributorcomponent.h index f87e02548..6e960c115 100644 --- a/src/blackgui/components/dbdistributorcomponent.h +++ b/src/blackgui/components/dbdistributorcomponent.h @@ -13,6 +13,7 @@ #define BLACKGUI_COMPONENTS_DBDISTRIBUTORCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/network/webdataservicesprovider.h" #include @@ -30,6 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbDistributorComponent : public QFrame, public CEnableForDockWidgetInfoArea, + public BlackGui::CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/components/dbliverycomponent.cpp b/src/blackgui/components/dbliverycomponent.cpp index 3b3f3d794..f39ed9d99 100644 --- a/src/blackgui/components/dbliverycomponent.cpp +++ b/src/blackgui/components/dbliverycomponent.cpp @@ -26,6 +26,7 @@ namespace BlackGui ui(new Ui::CDbLiveryComponent) { ui->setupUi(this); + this->setViewWithIndicator(this->ui->tvp_Liveries); connect(this->ui->tvp_Liveries, &CLiveryView::requestNewBackendData, this, &CDbLiveryComponent::ps_reload); // filter and drag and drop diff --git a/src/blackgui/components/dbliverycomponent.h b/src/blackgui/components/dbliverycomponent.h index 61fc710e0..be104790b 100644 --- a/src/blackgui/components/dbliverycomponent.h +++ b/src/blackgui/components/dbliverycomponent.h @@ -13,6 +13,7 @@ #define BLACKGUI_COMPONENTS_DBLIVERYCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/network/webdataservicesprovider.h" #include @@ -30,6 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbLiveryComponent : public QFrame, public CEnableForDockWidgetInfoArea, + public BlackGui::CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp index dcebb4c61..9b6eb76f9 100644 --- a/src/blackgui/components/dbmappingcomponent.cpp +++ b/src/blackgui/components/dbmappingcomponent.cpp @@ -13,6 +13,7 @@ #include "blackmisc/logmessage.h" #include "blackmisc/project.h" #include "blackgui/guiutility.h" +#include "blackgui/roles.h" using namespace BlackMisc; using namespace BlackMisc::Aviation; @@ -54,10 +55,11 @@ namespace BlackGui void CDbMappingComponent::initVPilotLoading() { - if (CProject::isRunningOnWindowsNtPlatform() && CProject::isCompiledWithMsFlightSimulatorSupport()) + if (CRoles::roles().isAdmin() && + CProject::isRunningOnWindowsNtPlatform() && + CProject::isCompiledWithMsFlightSimulatorSupport()) { this->m_withVPilot = true; - this->ui->tab_VPilot->setEnabled(true); this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this)); this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); @@ -67,8 +69,10 @@ namespace BlackGui else { this->m_withVPilot = false; - this->ui->tab_VPilot->setEnabled(false); } + this->ui->tab_VPilot->setEnabled(m_withVPilot); + this->ui->tab_VPilot->setVisible(m_withVPilot); + this->ui->tw_ModelsToBeMapped->removeTab(1); } bool CDbMappingComponent::initModelLoader(const CSimulatorInfo &simInfo) @@ -365,8 +369,11 @@ namespace BlackGui CDbMappingComponent *mapComp = qobject_cast(this->parent()); Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access parent"); - menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData())); - menu.addSeparator(); + if (CRoles::roles().isAdmin()) + { + menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData())); + menu.addSeparator(); + } } } // ns diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h index d0bd760b7..f82f8e3b5 100644 --- a/src/blackgui/components/dbmappingcomponent.h +++ b/src/blackgui/components/dbmappingcomponent.h @@ -15,6 +15,7 @@ #include "blackgui/blackguiexport.h" #include "blackgui/overlaymessagesframe.h" #include "blackgui/menudelegate.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/simulation/aircraftmodelloader.h" #include "blackmisc/simulation/fscommon/vpilotrulesreader.h" @@ -35,6 +36,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbMappingComponent : public BlackGui::COverlayMessagesFrame, public CEnableForDockWidgetInfoArea, + public BlackGui::CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/components/dbmodelcomponent.cpp b/src/blackgui/components/dbmodelcomponent.cpp index b24678e6c..6775915c0 100644 --- a/src/blackgui/components/dbmodelcomponent.cpp +++ b/src/blackgui/components/dbmodelcomponent.cpp @@ -23,10 +23,10 @@ namespace BlackGui { CDbModelComponent::CDbModelComponent(QWidget *parent) : QFrame(parent), - CWebDataServicesAware(nullptr), // provider not yet available ui(new Ui::CDbModelComponent) { ui->setupUi(this); + this->setViewWithIndicator(this->ui->tvp_AircraftModel); this->ui->tvp_AircraftModel->setAircraftModelMode(CAircraftModelListModel::Database); connect(this->ui->tvp_AircraftModel, &CAircraftModelView::requestNewBackendData, this, &CDbModelComponent::ps_reload); connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CDbModelComponent::ps_onStyleSheetChanged); diff --git a/src/blackgui/components/dbmodelcomponent.h b/src/blackgui/components/dbmodelcomponent.h index 2df14a767..616e89117 100644 --- a/src/blackgui/components/dbmodelcomponent.h +++ b/src/blackgui/components/dbmodelcomponent.h @@ -13,6 +13,7 @@ #define BLACKUI_COMPONENTS_DBMODELCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackmisc/network/webdataservicesprovider.h" #include @@ -30,6 +31,7 @@ namespace BlackGui class BLACKGUI_EXPORT CDbModelComponent : public QFrame, public CEnableForDockWidgetInfoArea, + public BlackGui::CEnableForViewBasedIndicator, public BlackMisc::Network::CWebDataServicesAware { Q_OBJECT diff --git a/src/blackgui/enableforviewbasedindicator.cpp b/src/blackgui/enableforviewbasedindicator.cpp new file mode 100644 index 000000000..1da989786 --- /dev/null +++ b/src/blackgui/enableforviewbasedindicator.cpp @@ -0,0 +1,55 @@ +/* Copyright (C) 2014 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "enableforviewbasedindicator.h" +#include "blackgui/views/viewbase.h" + +using namespace BlackMisc; +using namespace BlackGui; +using namespace BlackGui::Views; + +namespace BlackGui +{ + void CEnableForViewBasedIndicator::enableLoadIndicator(bool enable) + { + Q_ASSERT_X(m_viewWithIndicator, Q_FUNC_INFO, "Missing view to display indicator"); + if (m_viewWithIndicator) { m_viewWithIndicator->enableLoadIndicator(enable); } + } + + bool CEnableForViewBasedIndicator::isShowingLoadIndicator() const + { + Q_ASSERT_X(m_viewWithIndicator, Q_FUNC_INFO, "Missing view to display indicator"); + if (m_viewWithIndicator) { return m_viewWithIndicator->isShowingLoadIndicator(); } + return false; + } + + void CEnableForViewBasedIndicator::showLoadIndicator() + { + Q_ASSERT_X(m_viewWithIndicator, Q_FUNC_INFO, "Missing view to display indicator"); + if (m_viewWithIndicator) { m_viewWithIndicator->showLoadIndicator(); } + } + + void CEnableForViewBasedIndicator::hideLoadIndicator() + { + Q_ASSERT_X(m_viewWithIndicator, Q_FUNC_INFO, "Missing view to display indicator"); + if (m_viewWithIndicator) { m_viewWithIndicator->hideLoadIndicator(); } + } + + CEnableForViewBasedIndicator::CEnableForViewBasedIndicator(BlackGui::Views::CViewBaseNonTemplate *viewWithIndicator) + : m_viewWithIndicator(viewWithIndicator) + { + // void + } + + void CEnableForViewBasedIndicator::setViewWithIndicator(BlackGui::Views::CViewBaseNonTemplate *viewWithIndicator) + { + this->m_viewWithIndicator = viewWithIndicator; + } + +} // namespace diff --git a/src/blackgui/enableforviewbasedindicator.h b/src/blackgui/enableforviewbasedindicator.h new file mode 100644 index 000000000..30fe2f530 --- /dev/null +++ b/src/blackgui/enableforviewbasedindicator.h @@ -0,0 +1,50 @@ +/* Copyright (C) 2015 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_ENABLEFORVIEWBASEDINDICATOR_H +#define BLACKGUI_ENABLEFORVIEWBASEDINDICATOR_H + +#include "blackgui/blackguiexport.h" + +namespace BlackGui { namespace Views { class CViewBaseNonTemplate; }} + +namespace BlackGui +{ + //! Hand over indication task to an embedded view + class BLACKGUI_EXPORT CEnableForViewBasedIndicator + { + public: + //! Enable loading indicator + void enableLoadIndicator(bool enable); + + //! Showing load indicator + bool isShowingLoadIndicator() const; + + //! Show loading indicator + void showLoadIndicator(); + + //! Hide loading indicator + void hideLoadIndicator(); + + protected: + //! Constructor + CEnableForViewBasedIndicator(BlackGui::Views::CViewBaseNonTemplate *viewWithIndicator = nullptr); + + //! Set the corresponding view + void setViewWithIndicator(BlackGui::Views::CViewBaseNonTemplate *viewWithIndicator); + + private: + BlackGui::Views::CViewBaseNonTemplate *m_viewWithIndicator = nullptr; + }; + +} // namespace + +#endif // guard