swift
Loading...
Searching...
No Matches
dbaircrafticaocomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2015 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QDateTime>
7#include <QStringBuilder>
8#include <QtGlobal>
9
11#include "ui_dbaircrafticaocomponent.h"
12
15#include "gui/guiapplication.h"
17#include "gui/views/viewbase.h"
18
19using namespace swift::core;
20using namespace swift::misc::network;
21using namespace swift::misc::aviation;
22using namespace swift::gui::views;
23
25{
28 {
29 ui->setupUi(this);
30 this->setViewWithIndicator(ui->tvp_AircraftIcao);
31 ui->tvp_AircraftIcao->setResizeMode(CAircraftIcaoCodeView::ResizingOff);
32
33 ui->tvp_AircraftIcao->allowDragDrop(true, false);
34 ui->tvp_AircraftIcao->setFilterWidget(ui->filter_AircraftIcao);
35 ui->tvp_AircraftIcao->menuAddItems(CViewBaseNonTemplate::MenuCopy);
36
37 connect(ui->tvp_AircraftIcao, &CAircraftIcaoCodeView::requestNewBackendData, this,
38 &CDbAircraftIcaoComponent::onReload);
39 connect(sGui->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbAircraftIcaoComponent::onIcaoRead,
41 connect(sGui->getWebDataServices(), &CWebDataServices::entityDownloadProgress, this,
42 &CDbAircraftIcaoComponent::onEntityDownloadProgress, Qt::QueuedConnection);
44 sGui->getWebDataServices()->getAircraftIcaoCodesCount());
45 }
46
48
50
51 void CDbAircraftIcaoComponent::filter(const CAircraftIcaoCode &icao) { ui->filter_AircraftIcao->filter(icao); }
52
54 {
55 if (!icao.isLoadedFromDb())
56 {
57 return false;
58 }
59 return ui->tvp_AircraftIcao->selectDbKey(icao.getDbKey());
60 }
61
62 void CDbAircraftIcaoComponent::onIcaoRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count)
63 {
64 using namespace std::chrono_literals;
65
66 Q_UNUSED(count);
67 if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices())
68 {
69 return;
70 }
71 if (!entity.testFlag(CEntityFlags::AircraftIcaoEntity))
72 {
73 return;
74 }
75
77 {
78 this->showOverlayHTMLMessage(QStringLiteral("Updating %1").arg(CEntityFlags::entitiesToString(entity)), 2s);
79 ui->tvp_AircraftIcao->updateContainerMaybeAsync(sGui->getWebDataServices()->getAircraftIcaoCodes());
80 }
81 else
82 {
83 this->showOverlayHTMLMessage(u"Current state: " % CEntityFlags::entitiesToString(entity) % u" " %
85 10s);
86 }
87 }
88
89 void CDbAircraftIcaoComponent::onEntityDownloadProgress(CEntityFlags::Entity entity, int logId, int progress,
90 qint64 current, qint64 max, const QUrl &url)
91 {
92 using namespace std::chrono_literals;
93
95 {
96 return;
97 }
98 this->showDownloadProgress(progress, current, max, url, 5s);
99 Q_UNUSED(logId);
100 }
101
102 void CDbAircraftIcaoComponent::onReload()
103 {
104 if (!sGui || sGui->isShuttingDown())
105 {
106 return;
107 }
109 }
110} // namespace swift::gui::components
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
void entityDownloadProgress(swift::misc::network::CEntityFlags::Entity entity, int logId, int progress, qint64 current, qint64 max, const QUrl &url)
Download progress for an entity.
swift::misc::network::CEntityFlags::Entity triggerLoadingDirectlyFromDb(swift::misc::network::CEntityFlags::Entity whatToRead, const QDateTime &newerThan=QDateTime())
Trigger reload from DB, loads the DB data and bypasses the caches checks and info objects.
void dataRead(swift::misc::network::CEntityFlags::Entity entity, swift::misc::network::CEntityFlags::ReadState state, int number, const QUrl &url)
Combined read signal.
void setViewWithIndicator(swift::gui::views::CViewBaseNonTemplate *viewWithIndicator)
Set the corresponding view.
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
void showDownloadProgress(int progress, qint64 current, qint64 max, const QUrl &url, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
COverlayMessagesFrame(QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor.
swift::gui::views::CAircraftIcaoCodeView * view() const
Get the view.
bool selectAircraftIcao(const swift::misc::aviation::CAircraftIcaoCode &icao)
Select aircraft ICAO object.
CDbAircraftIcaoComponent(QWidget *parent=nullptr)
Constructor.
void filter(const swift::misc::aviation::CAircraftIcaoCode &icao)
Filter by ICAO as default.
void requestNewBackendData()
Load data from backend (where it makes sense).
@ MenuCopy
copy (for copy/paste)
Definition viewbase.h:132
bool selectDbKey(const KeyType &key)
Select given DB key.
Value object for ICAO classification.
bool isLoadedFromDb() const
Loaded from DB.
Definition datastore.cpp:58
static bool isFinishedReadState(ReadState state)
Any finished state.
@ AircraftIcaoEntity
ICAO codes for aircraft.
Definition entityflags.h:30
static const QString & stateToString(ReadState flag)
Convert to string.
static QString entitiesToString(CEntityFlags::Entity entities, const QString &separator=", ")
Entities to string list.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
Definition actionbind.cpp:7
High level reusable GUI components.
Views, mainly QTableView.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QueuedConnection
QWidget(QWidget *parent, Qt::WindowFlags f)