refs #709, use load indicator for load overview

(indicating reloading)
This commit is contained in:
Klaus Basan
2016-07-18 01:38:50 +02:00
parent ff4097504c
commit 31921f34ef
5 changed files with 90 additions and 33 deletions

View File

@@ -14,6 +14,7 @@
#include "blackgui/guiapplication.h"
using namespace BlackGui;
using namespace BlackCore;
using namespace BlackMisc;
using namespace BlackMisc::Network;
@@ -25,6 +26,9 @@ namespace BlackGui
QFrame(parent),
ui(new Ui::CDbLoadOverviewComponent)
{
Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui");
Q_ASSERT_X(sGui->getWebDataServices(), Q_FUNC_INFO, "no data services");
ui->setupUi(this);
ui->lbl_DatabaseUrl->setTextFormat(Qt::RichText);
@@ -37,6 +41,7 @@ namespace BlackGui
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);
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLoadOverviewComponent::ps_dataLoaded);
QTimer::singleShot(2000, this, &CDbLoadOverviewComponent::ps_setValues);
}
@@ -48,6 +53,7 @@ namespace BlackGui
{
if (!sGui) { return; }
if (!sGui->getWebDataServices()) { return; }
CDbLoadOverviewComponent::syncronizeCaches();
ui->le_AircraftIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AircraftIcaoEntity));
ui->le_AirlineIcaoCacheTs->setText(cacheTimestampForEntity(CEntityFlags::AirlineIcaoEntity));
@@ -83,6 +89,17 @@ namespace BlackGui
ui->lbl_DatabaseUrl->setToolTip(url);
}
void CDbLoadOverviewComponent::showLoading()
{
if (!this->m_loadIndicator)
{
this->m_loadIndicator = new CLoadIndicator(64, 64, this);
}
const QPoint middle = this->rect().center();
this->m_loadIndicator->centerLoadIndicator(middle);
this->m_loadIndicator->startAnimation(true);
}
QString CDbLoadOverviewComponent::formattedTimestamp(const QDateTime &dateTime)
{
if (!dateTime.isValid()) { return "-"; }
@@ -113,11 +130,32 @@ namespace BlackGui
return c < 0 ? "-" : QString::number(c);
}
void CDbLoadOverviewComponent::syncronizeCaches()
{
sGui->getWebDataServices()->syncronizeDbCaches(CEntityFlags::AllDbEntities);
}
void CDbLoadOverviewComponent::ps_reloadPressed()
{
if (this->m_reloading) { return; }
QObject *sender = QObject::sender();
CEntityFlags::Entity entity = CEntityFlags::singleEntityByName(sender->objectName());
sGui->getWebDataServices()->triggerRead(entity);
CEntityFlags::Entity triggeredEntity = sGui->getWebDataServices()->triggerReloadFromDb(entity);
if (triggeredEntity == CEntityFlags::NoEntity) { return; }
this->m_reloading = true;
this->showLoading();
}
void CDbLoadOverviewComponent::ps_dataLoaded(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number)
{
Q_UNUSED(number);
if (!CEntityFlags::anySwiftDbEntity(entity)) { return; }
if (state == CEntityFlags::ReadFinished || state == CEntityFlags::ReadFinishedRestricted)
{
if (this->m_loadIndicator) { this->m_loadIndicator->stopAnimation(); }
this->m_reloading = false;
this->ps_setValues();
}
}
} // ns
} // ns

View File

@@ -13,6 +13,7 @@
#define BLACKGUI_COMPONENTS_DBLOADOVERVIEWCOMPONENT_H
#include "blackgui/blackguiexport.h"
#include "blackgui/loadindicator.h"
#include "blackmisc/network/entityflags.h"
#include <QFrame>
#include <QScopedPointer>
@@ -38,9 +39,11 @@ namespace BlackGui
private:
QScopedPointer<Ui::CDbLoadOverviewComponent> ui;
BlackGui::CLoadIndicator *m_loadIndicator = nullptr; //!< load indicator if needed
bool m_reloading = false;
//! Init the value panel
void ps_setValues();
//! Show loading
void showLoading();
//! Timestamp
static QString formattedTimestamp(const QDateTime &dateTime);
@@ -57,9 +60,18 @@ namespace BlackGui
//! Formatted count for entity
static QString dbCountForEntity(BlackMisc::Network::CEntityFlags::Entity entity);
//! Syncronize caches
static void syncronizeCaches();
private slots:
//! Reload
void ps_reloadPressed();
//! Init the value panel
void ps_setValues();
//! Data have been loaded
void ps_dataLoaded(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
};
} // ns
} // ns

View File

@@ -9,7 +9,8 @@
* Class based on qLed: Copyright (C) 2010 by P. Sereno, http://www.sereno-online.com
*/
#include "blackgui/loadindicator.h"
#include "loadindicator.h"
#include "guiapplication.h"
#include <QColor>
#include <QPainter>
@@ -23,21 +24,21 @@ namespace BlackGui
: QWidget(parent)
{
this->resize(width, height);
setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
setFocusPolicy(Qt::NoFocus);
setAutoFillBackground(true);
this->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
this->setFocusPolicy(Qt::NoFocus);
this->setAutoFillBackground(true);
this->setStyleSheet("background-color: transparent;");
}
bool CLoadIndicator::isAnimated() const
{
return (m_timerId != -1);
return (this->m_timerId != -1);
}
void CLoadIndicator::setDisplayedWhenStopped(bool state)
{
m_displayedWhenStopped = state;
update();
this->m_displayedWhenStopped = state;
this->update();
}
bool CLoadIndicator::isDisplayedWhenStopped() const
@@ -45,34 +46,37 @@ namespace BlackGui
return m_displayedWhenStopped;
}
void CLoadIndicator::startAnimation()
void CLoadIndicator::startAnimation(bool processEvents)
{
m_angle = 0;
this->m_angle = 0;
this->show();
this->setEnabled(true);
if (m_timerId == -1) { m_timerId = startTimer(m_delayMs); }
if (this->m_timerId == -1) { this->m_timerId = startTimer(m_delayMs); }
if (processEvents && sGui)
{
sGui->processEventsToRefreshGui();
}
}
void CLoadIndicator::stopAnimation()
{
if (m_timerId != -1) { killTimer(m_timerId); }
m_timerId = -1;
if (this->m_timerId != -1) { killTimer(this->m_timerId); }
this->m_timerId = -1;
this->hide();
this->setEnabled(false);
update();
this->update();
}
void CLoadIndicator::setAnimationDelay(int delay)
{
if (m_timerId != -1) { killTimer(m_timerId); }
m_delayMs = delay;
if (m_timerId != -1) { m_timerId = startTimer(m_delayMs); }
if (this->m_timerId != -1) { killTimer(this->m_timerId); }
this->m_delayMs = delay;
if (this->m_timerId != -1) { this->m_timerId = startTimer(this->m_delayMs); }
}
void CLoadIndicator::setColor(const QColor &color)
{
m_color = color;
this->m_color = color;
update();
}
@@ -140,4 +144,12 @@ namespace BlackGui
}
}
void CLoadIndicator::centerLoadIndicator(const QPoint &middle)
{
const int w = this->width();
const int h = this->height();
const int x = middle.x() - w / 2;
const int y = middle.y() - h / 2;
this->setGeometry(x, y, w, h);
}
} // ns

View File

@@ -69,6 +69,9 @@ namespace BlackGui
//! Paint to another painter
void paint(QPainter &painter) const;
//! Center this load indicator
void centerLoadIndicator(const QPoint &middle);
signals:
//! Animation has been updated
void updatedAnimation();
@@ -76,7 +79,7 @@ namespace BlackGui
public slots:
//! Starts the spin animation.
//! \sa stopAnimation isAnimated
void startAnimation();
void startAnimation(bool processEvents = false);
//! Stops the spin animation.
//! \sa startAnimation isAnimated

View File

@@ -531,22 +531,14 @@ namespace BlackGui
this->m_loadIndicator = new CLoadIndicator(64, 64, this);
}
this->centerLoadIndicator();
this->m_loadIndicator->startAnimation();
if (processEvents)
{
sGui->processEventsToRefreshGui();
}
this->m_loadIndicator->startAnimation(processEvents);
}
void CViewBaseNonTemplate::centerLoadIndicator()
{
if (!m_loadIndicator) { return; }
QPoint middle = this->viewport()->geometry().center();
int w = m_loadIndicator->width();
int h = m_loadIndicator->height();
int x = middle.x() - w / 2;
int y = middle.y() - h / 2;
this->m_loadIndicator->setGeometry(x, y, w, h);
const QPoint middle = this->viewport()->geometry().center();
this->m_loadIndicator->centerLoadIndicator(middle);
}
void CViewBaseNonTemplate::hideLoadIndicator()