refs #709, smaller version of status bar component

This commit is contained in:
Klaus Basan
2016-07-16 20:14:08 +02:00
parent 6f840f4fd6
commit 876b4c9c22
5 changed files with 325 additions and 50 deletions

View File

@@ -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<CLedWidget *> 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<CLedWidget *> &leds, CEntityFlags::ReadState readState)
void CInfoBarWebReadersStatusBase::setLedReadStates(const QList<CLedWidget *> &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<CLedWidget *> CInfoBarWebReadersStatusComponent::entityToLeds(CEntityFlags::Entity entity) const
QList<CLedWidget *> CInfoBarWebReadersStatusBase::entityToLeds(CEntityFlags::Entity entity) const
{
QList<CLedWidget *> 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

View File

@@ -13,6 +13,7 @@
#define BLACKGUI_INFOBARWEBREADERSSTATUSCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackgui/led.h"
#include "blackmisc/network/entityflags.h"
#include <QFrame>
@@ -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::CInfoBarWebReadersStatusComponent> ui;
QTimer m_timer { this };
//! Init
void init();
//! Set LED states
void setLedReadStates(const QList<CLedWidget *> &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::CInfoBarWebReadersStatusComponent> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -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

View File

@@ -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 <QScopedPointer>
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::CInfoBarWebReadersStatusSmallComponent> ui;
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,151 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CInfoBarWebReadersStatusSmallComponent</class>
<widget class="QFrame" name="CInfoBarWebReadersStatusSmallComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>381</width>
<height>20</height>
</rect>
</property>
<property name="windowTitle">
<string>Frame</string>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="hl_CInfobarWebReaderStatusSmallComponent">
<property name="leftMargin">
<number>2</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>2</number>
</property>
<property name="bottomMargin">
<number>2</number>
</property>
<item>
<widget class="QLabel" name="lbl_SwiftDb">
<property name="text">
<string>DB</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_SwiftDb" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_DataReady">
<property name="toolTip">
<string>Mappings ready</string>
</property>
<property name="text">
<string>| data</string>
</property>
<property name="indent">
<number>6</number>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_DataReady" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Models">
<property name="toolTip">
<string>models</string>
</property>
<property name="text">
<string>| mod.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_Models" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Liveries">
<property name="toolTip">
<string>liveries</string>
</property>
<property name="text">
<string>| liv.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_Liveries" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Distributors">
<property name="toolTip">
<string>distributors</string>
</property>
<property name="text">
<string>| dist.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_Distributors" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Aircraft">
<property name="toolTip">
<string>aircraft</string>
</property>
<property name="text">
<string>| ac.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_IcaoAircraft" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Airlines">
<property name="toolTip">
<string>airlines</string>
</property>
<property name="text">
<string>| al.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_IcaoAirline" native="true"/>
</item>
<item>
<widget class="QLabel" name="lbl_Countries">
<property name="toolTip">
<string>countries</string>
</property>
<property name="text">
<string>| ctry.</string>
</property>
</widget>
</item>
<item>
<widget class="BlackGui::CLedWidget" name="led_Countries" native="true"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::CLedWidget</class>
<extends>QWidget</extends>
<header>blackgui/led.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>