refs #709, load info GUI component

This commit is contained in:
Klaus Basan
2016-07-15 19:58:16 +02:00
parent 876b4c9c22
commit 10a1fcebf7
3 changed files with 626 additions and 0 deletions

View File

@@ -0,0 +1,123 @@
/* 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 "dbloadoverviewcomponent.h"
#include "ui_dbloadoverviewcomponent.h"
#include "blackcore/webdataservices.h"
#include "blackgui/guiapplication.h"
using namespace BlackGui;
using namespace BlackMisc;
using namespace BlackMisc::Network;
namespace BlackGui
{
namespace Components
{
CDbLoadOverviewComponent::CDbLoadOverviewComponent(QWidget *parent) :
QFrame(parent),
ui(new Ui::CDbLoadOverviewComponent)
{
ui->setupUi(this);
ui->lbl_DatabaseUrl->setTextFormat(Qt::RichText);
ui->lbl_DatabaseUrl->setTextInteractionFlags(Qt::TextBrowserInteraction);
ui->lbl_DatabaseUrl->setOpenExternalLinks(true);
connect(ui->pb_ReloadAircraft, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed);
connect(ui->pb_ReloadAirlines, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed);
connect(ui->pb_ReloadCountries, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed);
connect(ui->pb_ReloadLiveries, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed);
connect(ui->pb_ReloadModels, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed);
connect(ui->pb_ReloadDistributors, &QPushButton::pressed, this, &CDbLoadOverviewComponent::ps_reloadPressed);
QTimer::singleShot(2000, this, &CDbLoadOverviewComponent::ps_setValues);
}
CDbLoadOverviewComponent::~CDbLoadOverviewComponent()
{ }
void CDbLoadOverviewComponent::ps_setValues()
{
if (!sGui) { return; }
if (!sGui->getWebDataServices()) { return; }
ui->le_AircraftIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AircraftIcaoEntity));
ui->le_AirlineIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AirlineIcaoEntity));
ui->le_LiveriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::LiveryEntity));
ui->le_ModelsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::ModelEntity));
ui->le_CountriesCacheTs->setText(cacheTimestampForEntity(CEntityFlags::CountryEntity));
ui->le_DistributorsCacheTs->setText(cacheTimestampForEntity(CEntityFlags::DistributorEntity));
ui->le_AircraftIcaoDbTs->setText(dbTimestampForEntity(CEntityFlags::AircraftIcaoEntity));
ui->le_AirlineIcaoDbTs->setText(dbTimestampForEntity(CEntityFlags::AirlineIcaoEntity));
ui->le_LiveriesDbTs->setText(dbTimestampForEntity(CEntityFlags::LiveryEntity));
ui->le_ModelsDbTs->setText(dbTimestampForEntity(CEntityFlags::ModelEntity));
ui->le_CountriesDbTs->setText(dbTimestampForEntity(CEntityFlags::CountryEntity));
ui->le_DistributorsDbTs->setText(dbTimestampForEntity(CEntityFlags::DistributorEntity));
ui->le_AircraftIcaoCacheCount->setText(cacheCountForEntity(CEntityFlags::AircraftIcaoEntity));
ui->le_AirlineIcaoCacheCount->setText(cacheCountForEntity(CEntityFlags::AirlineIcaoEntity));
ui->le_LiveriesCacheCount->setText(cacheCountForEntity(CEntityFlags::LiveryEntity));
ui->le_ModelsCacheCount->setText(cacheCountForEntity(CEntityFlags::ModelEntity));
ui->le_CountriesCacheCount->setText(cacheCountForEntity(CEntityFlags::CountryEntity));
ui->le_DistributorsCacheCount->setText(cacheCountForEntity(CEntityFlags::DistributorEntity));
ui->le_AircraftIcaoDbCount->setText(dbCountForEntity(CEntityFlags::AircraftIcaoEntity));
ui->le_AirlineIcaoDbCount->setText(dbCountForEntity(CEntityFlags::AirlineIcaoEntity));
ui->le_LiveriesDbCount->setText(dbCountForEntity(CEntityFlags::LiveryEntity));
ui->le_ModelsDbCount->setText(dbCountForEntity(CEntityFlags::ModelEntity));
ui->le_CountriesDbCount->setText(dbCountForEntity(CEntityFlags::CountryEntity));
ui->le_DistributorsDbCount->setText(cacheCountForEntity(CEntityFlags::DistributorEntity));
const QString urlHtml("<a href=\"%1\">Open</a>");
const QString url = sGui->getGlobalSetup().getDbHomePageUrl().getFullUrl();
ui->lbl_DatabaseUrl->setText(urlHtml.arg(url));
ui->lbl_DatabaseUrl->setToolTip(url);
}
QString CDbLoadOverviewComponent::formattedTimestamp(const QDateTime &dateTime)
{
if (!dateTime.isValid()) { return "-"; }
return dateTime.toUTC().toString("MM-dd hh:mm:ss");
}
QString CDbLoadOverviewComponent::cacheTimestampForEntity(CEntityFlags::Entity entity)
{
const QDateTime ts = sGui->getWebDataServices()->getCacheTimestamp(entity);
return formattedTimestamp(ts);
}
QString CDbLoadOverviewComponent::dbTimestampForEntity(CEntityFlags::Entity entity)
{
const QDateTime ts = sGui->getWebDataServices()->getDbLatestEntityTimestamp(entity);
return formattedTimestamp(ts);
}
QString CDbLoadOverviewComponent::cacheCountForEntity(CEntityFlags::Entity entity)
{
const int c = sGui->getWebDataServices()->getCacheCount(entity);
return c < 0 ? "-" : QString::number(c);
}
QString CDbLoadOverviewComponent::dbCountForEntity(CEntityFlags::Entity entity)
{
const int c = sGui->getWebDataServices()->getDbInfoCount(entity);
return c < 0 ? "-" : QString::number(c);
}
void CDbLoadOverviewComponent::ps_reloadPressed()
{
QObject *sender = QObject::sender();
CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(sender->objectName());
sGui->getWebDataServices()->triggerRead(entity);
}
} // ns
} // ns

View File

@@ -0,0 +1,66 @@
/* 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.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_DBLOADOVERVIEWCOMPONENT_H
#define BLACKGUI_COMPONENTS_DBLOADOVERVIEWCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackmisc/network/entityflags.h"
#include <QFrame>
#include <QScopedPointer>
namespace Ui { class CDbLoadOverviewComponent; }
namespace BlackGui
{
namespace Components
{
/*!
* Overview about load state of DB data
*/
class BLACKGUI_EXPORT CDbLoadOverviewComponent : public QFrame
{
Q_OBJECT
public:
//! Constructor
explicit CDbLoadOverviewComponent(QWidget *parent = nullptr);
//! Destructor
virtual ~CDbLoadOverviewComponent();
private:
QScopedPointer<Ui::CDbLoadOverviewComponent> ui;
//! Init the value panel
void ps_setValues();
//! Timestamp
static QString formattedTimestamp(const QDateTime &dateTime);
//! Formatted ts for entity
static QString cacheTimestampForEntity(BlackMisc::Network::CEntityFlags::Entity entity);
//! Formatted ts for entity
static QString dbTimestampForEntity(BlackMisc::Network::CEntityFlags::Entity entity);
//! Formatted count for entity
static QString cacheCountForEntity(BlackMisc::Network::CEntityFlags::Entity entity);
//! Formatted count for entity
static QString dbCountForEntity(BlackMisc::Network::CEntityFlags::Entity entity);
private slots:
//! Reload
void ps_reloadPressed();
};
} // ns
} // ns
#endif // guard

View File

@@ -0,0 +1,437 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CDbLoadOverviewComponent</class>
<widget class="QFrame" name="CDbLoadOverviewComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>216</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="QGridLayout" name="gl_DbLoadOverview">
<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>
<property name="spacing">
<number>4</number>
</property>
<item row="7" column="7">
<widget class="QLineEdit" name="le_DistributorsDbTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>DB ts</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="pb_ReloadDistributors">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
</property>
</widget>
</item>
<item row="7" column="3">
<widget class="QLineEdit" name="le_DistributorsCacheCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="7" column="5">
<widget class="QLineEdit" name="le_DistributorsCacheTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>cache ts</string>
</property>
</widget>
</item>
<item row="7" column="4">
<widget class="QLineEdit" name="le_DistributorsDbCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pb_ReloadAircraft">
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pb_ReloadLiveries">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QLineEdit" name="le_ModelsCacheCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_Liveries">
<property name="text">
<string>Liveries:</string>
</property>
</widget>
</item>
<item row="1" column="7">
<widget class="QLineEdit" name="le_AircraftIcaoDbTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>DB ts</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lbl_AircraftIcao">
<property name="text">
<string>Aircraft:</string>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QLineEdit" name="le_AirlineIcaoDbTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>DB ts</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="le_AircraftIcaoCacheCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QLineEdit" name="le_AircraftIcaoCacheTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>cache ts</string>
</property>
</widget>
</item>
<item row="6" column="5">
<widget class="QLineEdit" name="le_CountriesCacheTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>cache ts</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lbl_Countries">
<property name="text">
<string>Countries:</string>
</property>
</widget>
</item>
<item row="4" column="5">
<widget class="QLineEdit" name="le_ModelsCacheTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>cache ts</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QLineEdit" name="le_AirlineIcaoCacheTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>cache ts</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="lbl_Models">
<property name="text">
<string>Models:</string>
</property>
</widget>
</item>
<item row="0" column="7">
<widget class="QLabel" name="lbl_DbTs">
<property name="text">
<string>DB ts:</string>
</property>
</widget>
</item>
<item row="6" column="3">
<widget class="QLineEdit" name="le_CountriesCacheCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="3" column="5">
<widget class="QLineEdit" name="le_LiveriesCacheTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>cache ts</string>
</property>
</widget>
</item>
<item row="6" column="7">
<widget class="QLineEdit" name="le_CountriesDbTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>DB ts</string>
</property>
</widget>
</item>
<item row="3" column="3">
<widget class="QLineEdit" name="le_LiveriesCacheCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="3" column="7">
<widget class="QLineEdit" name="le_LiveriesDbTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>DB ts</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="lbl_AirlineIcao">
<property name="text">
<string>Airline:</string>
</property>
</widget>
</item>
<item row="4" column="7">
<widget class="QLineEdit" name="le_ModelsDbTs">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>DB ts</string>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLabel" name="lbl_CacheCount">
<property name="text">
<string>Cache #:</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QLineEdit" name="le_AirlineIcaoCacheCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QLabel" name="lbl_CacheTs">
<property name="text">
<string>Cache ts:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="lbl_DbCount">
<property name="text">
<string>DB #:</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLineEdit" name="le_AircraftIcaoDbCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QLineEdit" name="le_AirlineIcaoDbCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QLineEdit" name="le_ModelsDbCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="6" column="4">
<widget class="QLineEdit" name="le_CountriesDbCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QPushButton" name="pb_ReloadModels">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pb_ReloadAirlines">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
</property>
</widget>
</item>
<item row="3" column="4">
<widget class="QLineEdit" name="le_LiveriesDbCount">
<property name="readOnly">
<bool>true</bool>
</property>
<property name="placeholderText">
<string>count</string>
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QPushButton" name="pb_ReloadCountries">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="../../blackmisc/blackmisc.qrc">
<normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</normaloff>:/pastel/icons/pastel/16/arrow-refresh.png</iconset>
</property>
</widget>
</item>
<item row="7" column="0">
<widget class="QLabel" name="lbl_Distributors">
<property name="text">
<string>Distributors:</string>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="lbl_Databse">
<property name="minimumSize">
<size>
<width>0</width>
<height>24</height>
</size>
</property>
<property name="text">
<string>Database:</string>
</property>
</widget>
</item>
<item row="8" column="3" colspan="5">
<widget class="QLabel" name="lbl_DatabaseUrl">
<property name="text">
<string>URL will go here .....</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../../blackmisc/blackmisc.qrc"/>
</resources>
<connections/>
</ui>