mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-01 05:26:45 +08:00
Ref T489, better progress indication in DB load dialog
This commit is contained in:
committed by
Mat Sutcliffe
parent
fee2f8c5a0
commit
3c0c61ae19
@@ -13,10 +13,14 @@
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackcore/db/databaseutils.h"
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
#include "blackmisc/logmessage.h"
|
||||
|
||||
#include <QDialogButtonBox>
|
||||
#include <QModelIndexList>
|
||||
#include <QPointer>
|
||||
#include <QStringBuilder>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Network;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackMisc::Simulation::Data;
|
||||
@@ -42,6 +46,7 @@ namespace BlackGui
|
||||
ui->wi_Consolidate->setVisible(false);
|
||||
ui->comp_SimulatorSelector->setRememberSelection(true);
|
||||
connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbLoadDataDialog::onDataRead, Qt::QueuedConnection);
|
||||
connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this, &CDbLoadDataDialog::onEntityDownloadProgress, Qt::QueuedConnection);
|
||||
connect(ui->bb_loadDataDialog, &QDialogButtonBox::clicked, this, &CDbLoadDataDialog::onButtonClicked);
|
||||
connect(ui->pb_Consolidate, &QPushButton::clicked, this, &CDbLoadDataDialog::consolidate);
|
||||
connect(this, &CDbLoadDataDialog::rejected, this, &CDbLoadDataDialog::onRejected);
|
||||
@@ -70,8 +75,8 @@ namespace BlackGui
|
||||
|
||||
QStringList CDbLoadDataDialog::selectedEntities() const
|
||||
{
|
||||
const QModelIndexList indexes = ui->lv_Entities->selectionModel()->selectedIndexes();
|
||||
QStringList entities;
|
||||
const QModelIndexList indexes = ui->lv_Entities->selectionModel()->selectedIndexes();
|
||||
for (const QModelIndex &index : indexes)
|
||||
{
|
||||
entities.append(index.data(Qt::DisplayRole).toString());
|
||||
@@ -100,10 +105,19 @@ namespace BlackGui
|
||||
|
||||
void CDbLoadDataDialog::onDataRead(CEntityFlags::Entity entity, CEntityFlags::ReadState state, int number)
|
||||
{
|
||||
if (m_pendingEntities == CEntityFlags::NoEntity) { return; } // no triggered from here
|
||||
if (state == CEntityFlags::ReadStarted) { return; }
|
||||
if (m_pendingEntities == CEntityFlags::NoEntity) { return; } // not triggered from here
|
||||
if (!m_pendingEntities.testFlag(CEntityFlags::entityToEntityFlag(entity))) { return; }
|
||||
|
||||
const QString e = CEntityFlags::entitiesToString(entity);
|
||||
const QString s = CEntityFlags::stateToString(state);
|
||||
|
||||
ui->le_Info->setText(e % u" " % s);
|
||||
if (!CEntityFlags::isFinishedReadStateOrFailure(state)) { return; }
|
||||
if (state == CEntityFlags::ReadFailed)
|
||||
{
|
||||
CLogMessage(this).warning(u"Read failed for %1") << e;
|
||||
}
|
||||
|
||||
m_pendingEntities &= ~entity;
|
||||
const int pending = CEntityFlags::numberOfEntities(m_pendingEntities);
|
||||
const int max = ui->pb_Loading->maximum();
|
||||
@@ -116,8 +130,6 @@ namespace BlackGui
|
||||
m_pendingEntitiesCount -= number;
|
||||
ui->pb_Loading->setValue(max - m_pendingEntitiesCount);
|
||||
}
|
||||
const QString e = CEntityFlags::entitiesToString(entity);
|
||||
ui->le_Info->setText(e);
|
||||
if (pending < 1)
|
||||
{
|
||||
m_pendingEntitiesCount = -1;
|
||||
@@ -132,12 +144,27 @@ namespace BlackGui
|
||||
if (defaultConsolidate)
|
||||
{
|
||||
m_autoConsolidate = true;
|
||||
QTimer::singleShot(1000, this, &CDbLoadDataDialog::consolidate);
|
||||
QPointer<CDbLoadDataDialog> self(this); // 2nd "self"/"myself" for cppcheck identicalConditionAfterEarlyExit
|
||||
QTimer::singleShot(1000, this, [ = ]
|
||||
{
|
||||
if (!self) { return; }
|
||||
self->consolidate();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void CDbLoadDataDialog::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url)
|
||||
{
|
||||
Q_UNUSED(entity);
|
||||
Q_UNUSED(logId);
|
||||
Q_UNUSED(progress);
|
||||
Q_UNUSED(current);
|
||||
Q_UNUSED(max);
|
||||
Q_UNUSED(url);
|
||||
}
|
||||
|
||||
void CDbLoadDataDialog::onRejected()
|
||||
{
|
||||
m_pendingEntities = CEntityFlags::NoEntity;
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <QDialog>
|
||||
#include <QScopedPointer>
|
||||
#include <QStringListModel>
|
||||
#include <QUrl>
|
||||
#include <QAbstractButton>
|
||||
|
||||
namespace Ui { class CDbLoadDataDialog; }
|
||||
@@ -52,9 +53,12 @@ namespace BlackGui
|
||||
//! Button clicked
|
||||
void onButtonClicked(QAbstractButton *button);
|
||||
|
||||
//! Data have been read
|
||||
//! Data are/have been read
|
||||
void onDataRead(BlackMisc::Network::CEntityFlags::Entity entity, BlackMisc::Network::CEntityFlags::ReadState state, int number);
|
||||
|
||||
//! Download progress
|
||||
void onEntityDownloadProgress(BlackMisc::Network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url);
|
||||
|
||||
//! Dialog rejected
|
||||
void onRejected();
|
||||
|
||||
@@ -66,7 +70,7 @@ namespace BlackGui
|
||||
BlackMisc::Simulation::Data::CModelSetCaches m_sets { true, this }; //!< caches
|
||||
BlackMisc::Simulation::Data::CModelCaches m_models { true, this }; //!< models
|
||||
int m_pendingEntitiesCount = -1;
|
||||
bool m_consolidating = false; //! currently consolidating
|
||||
bool m_consolidating = false; //! currently consolidating
|
||||
bool m_autoConsolidate = false;
|
||||
};
|
||||
} // ns
|
||||
|
||||
@@ -51,7 +51,7 @@
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="wi_WorkStatus" native="true">
|
||||
<layout class="QHBoxLayout" name="hl_LoadStatus" stretch="1,3">
|
||||
<layout class="QHBoxLayout" name="hl_LoadStatus">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="le_Info">
|
||||
<property name="readOnly">
|
||||
|
||||
@@ -83,6 +83,12 @@ namespace BlackMisc
|
||||
return state == ReadFinished || state == ReadFinishedRestricted;
|
||||
}
|
||||
|
||||
bool CEntityFlags::isFinishedReadStateOrFailure(CEntityFlags::ReadState state)
|
||||
{
|
||||
if (isFinishedReadState(state)) { return true; }
|
||||
return state == ReadFailed || state == ReadSkipped;
|
||||
}
|
||||
|
||||
int CEntityFlags::numberOfEntities(CEntityFlags::Entity entities)
|
||||
{
|
||||
const int c = static_cast<int>(std::bitset<(sizeof(entities) * 8)>(entities).count());
|
||||
@@ -91,7 +97,7 @@ namespace BlackMisc
|
||||
|
||||
const QString &CEntityFlags::stateToString(CEntityFlags::ReadState flag)
|
||||
{
|
||||
static const QString f("finised");
|
||||
static const QString f("finished");
|
||||
static const QString fr("finished (restricted)");
|
||||
static const QString p("parsing");
|
||||
static const QString fa("failed");
|
||||
@@ -101,12 +107,12 @@ namespace BlackMisc
|
||||
|
||||
switch (flag)
|
||||
{
|
||||
case ReadFinished: return f;
|
||||
case ReadFinishedRestricted: return fr;
|
||||
case ReadParsing: return p;
|
||||
case ReadFailed: return fa;
|
||||
case ReadSkipped: return s;
|
||||
case ReadStarted: return st;
|
||||
case ReadFinished: return f;
|
||||
case ReadParsing: return p;
|
||||
case ReadFailed: return fa;
|
||||
case ReadSkipped: return s;
|
||||
case ReadStarted: return st;
|
||||
default:
|
||||
BLACK_VERIFY_X(false, Q_FUNC_INFO, "wrong flags");
|
||||
return x;
|
||||
|
||||
@@ -90,6 +90,9 @@ namespace BlackMisc
|
||||
//! Any finished state
|
||||
static bool isFinishedReadState(ReadState state);
|
||||
|
||||
//! Any finished state
|
||||
static bool isFinishedReadStateOrFailure(ReadState state);
|
||||
|
||||
//! Represented number of entities
|
||||
static int numberOfEntities(CEntityFlags::Entity entities);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user