From 876b4c9c226bc37de5f9d71df504143098fcbf4a Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 16 Jul 2016 20:14:08 +0200 Subject: [PATCH] refs #709, smaller version of status bar component --- .../infobarwebreadersstatuscomponent.cpp | 86 ++++++---- .../infobarwebreadersstatuscomponent.h | 67 +++++--- .../infobarwebreadersstatussmallcomponent.cpp | 29 ++++ .../infobarwebreadersstatussmallcomponent.h | 42 +++++ .../infobarwebreadersstatussmallcomponent.ui | 151 ++++++++++++++++++ 5 files changed, 325 insertions(+), 50 deletions(-) create mode 100644 src/blackgui/components/infobarwebreadersstatussmallcomponent.cpp create mode 100644 src/blackgui/components/infobarwebreadersstatussmallcomponent.h create mode 100644 src/blackgui/components/infobarwebreadersstatussmallcomponent.ui diff --git a/src/blackgui/components/infobarwebreadersstatuscomponent.cpp b/src/blackgui/components/infobarwebreadersstatuscomponent.cpp index a03b4bbaf..6ebcc9899 100644 --- a/src/blackgui/components/infobarwebreadersstatuscomponent.cpp +++ b/src/blackgui/components/infobarwebreadersstatuscomponent.cpp @@ -10,7 +10,6 @@ #include "blackcore/webdataservices.h" #include "blackgui/components/infobarwebreadersstatuscomponent.h" #include "blackgui/guiapplication.h" -#include "blackgui/led.h" #include "blackmisc/verify.h" #include "ui_infobarwebreadersstatuscomponent.h" @@ -25,61 +24,61 @@ namespace BlackGui { namespace Components { - CInfoBarWebReadersStatusComponent::CInfoBarWebReadersStatusComponent(QWidget *parent) : - QFrame(parent), ui(new Ui::CInfoBarWebReadersStatusComponent) + CInfoBarWebReadersStatusBase::CInfoBarWebReadersStatusBase(QWidget *parent) : QFrame(parent) + { } + + void CInfoBarWebReadersStatusBase::init() { Q_ASSERT_X(sGui, Q_FUNC_INFO, "No sGui"); Q_ASSERT_X(sGui->hasWebDataServices(), Q_FUNC_INFO, "No web data services"); - ui->setupUi(this); this->initLeds(); - bool c = connect(&m_timer, &QTimer::timeout, this, &CInfoBarWebReadersStatusComponent::ps_checkServerAndData); + bool c = connect(&m_timer, &QTimer::timeout, this, &CInfoBarWebReadersStatusBase::ps_checkServerAndData); Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect"); m_timer.setInterval(30 * 1000); m_timer.start(); - m_timer.setObjectName("CInfoBarWebReadersStatusComponent::CheckSwiftDbTimer"); - c = connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CInfoBarWebReadersStatusComponent::ps_dataRead); + m_timer.setObjectName("CInfoBarWebReadersStatusBase::CheckSwiftDbTimer"); + c = connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CInfoBarWebReadersStatusBase::ps_dataRead); Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect"); Q_UNUSED(c); } - CInfoBarWebReadersStatusComponent::~CInfoBarWebReadersStatusComponent() + CInfoBarWebReadersStatusBase::~CInfoBarWebReadersStatusBase() { m_timer.stop(); } - void CInfoBarWebReadersStatusComponent::initLeds() + void CInfoBarWebReadersStatusBase::initLeds() { CLedWidget::LedShape shape = CLedWidget::Circle; - this->ui->led_DataReady->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "all data ready", "data missing", 14); + this->led_DataReady->setValues(CLedWidget::Yellow, CLedWidget::Black, shape, "all data ready", "data missing", 14); - this->ui->led_IcaoAircraft->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); - this->ui->led_IcaoAirline->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); - this->ui->led_Countries->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); - - this->ui->led_Models->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); - this->ui->led_Liveries->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); - this->ui->led_Distributors->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); + this->led_IcaoAircraft->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); + this->led_IcaoAirline->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); + this->led_Countries->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); + this->led_Models->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); + this->led_Liveries->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); + this->led_Distributors->setValues(CLedWidget::Yellow, CLedWidget::Black, CLedWidget::Red, shape, "reading", "idle", "failed", 14); } - void CInfoBarWebReadersStatusComponent::ps_dataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count) + void CInfoBarWebReadersStatusBase::ps_dataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count) { Q_UNUSED(count); QList leds = this->entityToLeds(entity); if (!leds.isEmpty()) { this->setLedReadStates(leds, readState); } } - void CInfoBarWebReadersStatusComponent::ps_checkServerAndData() + void CInfoBarWebReadersStatusBase::ps_checkServerAndData() { bool swift = sGui && sGui->getWebDataServices()->canConnectSwiftDb(); - this->ui->led_SwiftDb->setOn(swift); + this->led_SwiftDb->setOn(swift); bool allData = hasAllData(); - this->ui->led_DataReady->setOn(allData); + this->led_DataReady->setOn(allData); } - void CInfoBarWebReadersStatusComponent::setLedReadStates(const QList &leds, CEntityFlags::ReadState readState) + void CInfoBarWebReadersStatusBase::setLedReadStates(const QList &leds, CEntityFlags::ReadState readState) { for (CLedWidget *led : leds) { @@ -87,7 +86,7 @@ namespace BlackGui } } - void CInfoBarWebReadersStatusComponent::setLedReadState(CLedWidget *led, CEntityFlags::ReadState readState) + void CInfoBarWebReadersStatusBase::setLedReadState(CLedWidget *led, CEntityFlags::ReadState readState) { Q_ASSERT_X(led, Q_FUNC_INFO, "no LED"); int blinkTime = 2.5 * 1000; @@ -109,27 +108,50 @@ namespace BlackGui } } - QList CInfoBarWebReadersStatusComponent::entityToLeds(CEntityFlags::Entity entity) const + QList CInfoBarWebReadersStatusBase::entityToLeds(CEntityFlags::Entity entity) const { QList leds; - if (entity.testFlag(CEntityFlags::CountryEntity)) { leds << ui->led_Countries; } - if (entity.testFlag(CEntityFlags::DistributorEntity)) { leds << ui->led_Distributors; } - if (entity.testFlag(CEntityFlags::AircraftIcaoEntity)) { leds << ui->led_IcaoAircraft; } - if (entity.testFlag(CEntityFlags::AirlineIcaoEntity)) { leds << ui->led_IcaoAirline; } - if (entity.testFlag(CEntityFlags::LiveryEntity)) { leds << ui->led_Liveries; } - if (entity.testFlag(CEntityFlags::ModelEntity)) { leds << ui->led_Models; } + if (entity.testFlag(CEntityFlags::CountryEntity)) { leds << this->led_Countries; } + if (entity.testFlag(CEntityFlags::DistributorEntity)) { leds << this->led_Distributors; } + if (entity.testFlag(CEntityFlags::AircraftIcaoEntity)) { leds << this->led_IcaoAircraft; } + if (entity.testFlag(CEntityFlags::AirlineIcaoEntity)) { leds << this->led_IcaoAirline; } + if (entity.testFlag(CEntityFlags::LiveryEntity)) { leds << this->led_Liveries; } + if (entity.testFlag(CEntityFlags::ModelEntity)) { leds << this->led_Models; } return leds; } - bool CInfoBarWebReadersStatusComponent::hasAllData() const + bool CInfoBarWebReadersStatusBase::hasAllData() const { if (!sGui) { return false; } return sGui->getWebDataServices()->getAirlineIcaoCodesCount() > 0 && sGui->getWebDataServices()->getAircraftIcaoCodesCount() > 0 && sGui->getWebDataServices()->getDistributorsCount() > 0 && sGui->getWebDataServices()->getModelsCount() > 0 && - sGui->getWebDataServices()->getLiveriesCount() > 0; + sGui->getWebDataServices()->getLiveriesCount() > 0 && + sGui->getWebDataServices()->getCountriesCount() > 0; } + void CInfoBarWebReadersStatusBase::setLeds(CLedWidget *ledDb, CLedWidget *dataReady, CLedWidget *ledIcaoAircraft, CLedWidget *ledIcaoAirline, CLedWidget *ledCountries, CLedWidget *ledDistributors, CLedWidget *ledLiveries, CLedWidget *ledModels) + { + this->led_SwiftDb = ledDb; + this->led_DataReady = dataReady; + this->led_IcaoAircraft = ledIcaoAircraft; + this->led_IcaoAirline = ledIcaoAirline; + this->led_Countries = ledCountries; + this->led_Distributors = ledDistributors; + this->led_Liveries = ledLiveries; + this->led_Models = ledModels; + } + + CInfoBarWebReadersStatusComponent::CInfoBarWebReadersStatusComponent(QWidget *parent) : + CInfoBarWebReadersStatusBase(parent), ui(new Ui::CInfoBarWebReadersStatusComponent) + { + ui->setupUi(this); + this->setLeds(ui->led_SwiftDb, ui->led_DataReady, ui->led_IcaoAircraft, ui->led_IcaoAirline, ui->led_Countries, ui->led_Distributors, ui->led_Liveries, ui->led_Models); + this->init(); + } + + CInfoBarWebReadersStatusComponent::~CInfoBarWebReadersStatusComponent() + { } } // namespace } // namespace diff --git a/src/blackgui/components/infobarwebreadersstatuscomponent.h b/src/blackgui/components/infobarwebreadersstatuscomponent.h index 11bfa13c9..dbfc3c47f 100644 --- a/src/blackgui/components/infobarwebreadersstatuscomponent.h +++ b/src/blackgui/components/infobarwebreadersstatuscomponent.h @@ -13,6 +13,7 @@ #define BLACKGUI_INFOBARWEBREADERSSTATUSCOMPONENT_H #include "blackgui/blackguiexport.h" +#include "blackgui/led.h" #include "blackmisc/network/entityflags.h" #include @@ -24,39 +25,31 @@ class QWidget; namespace Ui { class CInfoBarWebReadersStatusComponent; } - namespace BlackGui { class CLedWidget; - namespace Components { //! Info bar displaying status of web readers(swift DB, ...) - class BLACKGUI_EXPORT CInfoBarWebReadersStatusComponent : - public QFrame + class BLACKGUI_EXPORT CInfoBarWebReadersStatusBase : public QFrame { Q_OBJECT public: - //! Constructor - explicit CInfoBarWebReadersStatusComponent(QWidget *parent = nullptr); - //!Destructor - ~CInfoBarWebReadersStatusComponent(); + ~CInfoBarWebReadersStatusBase(); //! Init the LEDs void initLeds(); - private slots: - //! Data have been read - void ps_dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); + protected: + QTimer m_timer { this }; //!< check timer - //! Check server status - void ps_checkServerAndData(); + //! Constructor + explicit CInfoBarWebReadersStatusBase(QWidget *parent = nullptr); - private: - QScopedPointer ui; - QTimer m_timer { this }; + //! Init + void init(); //! Set LED states void setLedReadStates(const QList &leds, BlackMisc::Network::CEntityFlags::ReadState readState); @@ -69,7 +62,45 @@ namespace BlackGui //! All data read bool hasAllData() const; + + //! Initial setup of leds + void setLeds(BlackGui::CLedWidget *ledDb, BlackGui::CLedWidget *dataReady, + BlackGui::CLedWidget *led_IcaoAircraft, BlackGui::CLedWidget *led_IcaoAirline, BlackGui::CLedWidget *led_Countries, + BlackGui::CLedWidget *led_Distributors, BlackGui::CLedWidget *led_Liveries, BlackGui::CLedWidget *led_Models); + + private slots: + //! Data have been read + void ps_dataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState readState, int count); + + //! Check server status + void ps_checkServerAndData(); + + private: + BlackGui::CLedWidget *led_SwiftDb = nullptr; + BlackGui::CLedWidget *led_DataReady = nullptr; + BlackGui::CLedWidget *led_IcaoAircraft = nullptr; + BlackGui::CLedWidget *led_IcaoAirline = nullptr; + BlackGui::CLedWidget *led_Countries = nullptr; + BlackGui::CLedWidget *led_Distributors = nullptr; + BlackGui::CLedWidget *led_Liveries = nullptr; + BlackGui::CLedWidget *led_Models = nullptr; }; - } -} + + //! Info bar displaying status of web readers(swift DB, ...) + class BLACKGUI_EXPORT CInfoBarWebReadersStatusComponent : public CInfoBarWebReadersStatusBase + { + Q_OBJECT + + public: + //! Constructor + explicit CInfoBarWebReadersStatusComponent(QWidget *parent = nullptr); + + //!Destructor + ~CInfoBarWebReadersStatusComponent(); + + private: + QScopedPointer ui; + }; + } // ns +} // ns #endif // guard diff --git a/src/blackgui/components/infobarwebreadersstatussmallcomponent.cpp b/src/blackgui/components/infobarwebreadersstatussmallcomponent.cpp new file mode 100644 index 000000000..c4360fb4c --- /dev/null +++ b/src/blackgui/components/infobarwebreadersstatussmallcomponent.cpp @@ -0,0 +1,29 @@ +/* Copyright (C) 2016 + * 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 "infobarwebreadersstatussmallcomponent.h" +#include "ui_infobarwebreadersstatussmallcomponent.h" + +namespace BlackGui +{ + namespace Components + { + CInfoBarWebReadersStatusSmallComponent::CInfoBarWebReadersStatusSmallComponent(QWidget *parent) : + CInfoBarWebReadersStatusBase(parent), + ui(new Ui::CInfoBarWebReadersStatusSmallComponent) + { + ui->setupUi(this); + this->setLeds(ui->led_SwiftDb, ui->led_DataReady, ui->led_IcaoAircraft, ui->led_IcaoAirline, ui->led_Countries, ui->led_Distributors, ui->led_Liveries, ui->led_Models); + this->init(); + } + + CInfoBarWebReadersStatusSmallComponent::~CInfoBarWebReadersStatusSmallComponent() + { } + } // ns +} // ns diff --git a/src/blackgui/components/infobarwebreadersstatussmallcomponent.h b/src/blackgui/components/infobarwebreadersstatussmallcomponent.h new file mode 100644 index 000000000..23c5e307b --- /dev/null +++ b/src/blackgui/components/infobarwebreadersstatussmallcomponent.h @@ -0,0 +1,42 @@ +/* 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_COMPONENTS_INFOBARWEBREADERSSTATUSSMALLCOMPONENT_H +#define BLACKGUI_COMPONENTS_INFOBARWEBREADERSSTATUSSMALLCOMPONENT_H + +#include "infobarwebreadersstatuscomponent.h" +#include + +namespace Ui { class CInfoBarWebReadersStatusSmallComponent; } +namespace BlackGui +{ + namespace Components + { + /*! + * Smaller version of CInfoBarWebReadersStatusComponent + */ + class BLACKGUI_EXPORT CInfoBarWebReadersStatusSmallComponent : public CInfoBarWebReadersStatusBase + { + Q_OBJECT + + public: + //! Constructor + explicit CInfoBarWebReadersStatusSmallComponent(QWidget *parent = nullptr); + + //! Destructor + ~CInfoBarWebReadersStatusSmallComponent(); + + private: + QScopedPointer ui; + }; + } // ns +} // ns +#endif // guard diff --git a/src/blackgui/components/infobarwebreadersstatussmallcomponent.ui b/src/blackgui/components/infobarwebreadersstatussmallcomponent.ui new file mode 100644 index 000000000..d5c24ffe7 --- /dev/null +++ b/src/blackgui/components/infobarwebreadersstatussmallcomponent.ui @@ -0,0 +1,151 @@ + + + CInfoBarWebReadersStatusSmallComponent + + + + 0 + 0 + 381 + 20 + + + + Frame + + + QFrame::StyledPanel + + + QFrame::Raised + + + + 2 + + + 2 + + + 2 + + + 2 + + + + + DB + + + + + + + + + + Mappings ready + + + | data + + + 6 + + + + + + + + + + models + + + | mod. + + + + + + + + + + liveries + + + | liv. + + + + + + + + + + distributors + + + | dist. + + + + + + + + + + aircraft + + + | ac. + + + + + + + + + + airlines + + + | al. + + + + + + + + + + countries + + + | ctry. + + + + + + + + + + + BlackGui::CLedWidget + QWidget +
blackgui/led.h
+ 1 +
+
+ + +