swift
dbcountrycomponent.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 <QtGlobal>
7 
8 #include "ui_dbcountrycomponent.h"
9 
10 #include "core/application.h"
11 #include "core/webdataservices.h"
13 #include "gui/guiapplication.h"
14 #include "gui/views/countryview.h"
15 #include "gui/views/viewbase.h"
16 
17 using namespace swift::core;
18 using namespace swift::misc::network;
19 using namespace swift::gui::views;
20 
21 namespace swift::gui::components
22 {
23  CDbCountryComponent::CDbCountryComponent(QWidget *parent) : QFrame(parent), ui(new Ui::CDbCountryComponent)
24  {
25  ui->setupUi(this);
26  this->setViewWithIndicator(ui->tvp_Countries);
27  ui->tvp_Countries->setResizeMode(CViewBaseNonTemplate::ResizingOnce);
28  connect(ui->tvp_Countries, &CCountryView::requestNewBackendData, this, &CDbCountryComponent::onReload);
29 
30  // filter and drag and drop
31  ui->tvp_Countries->setFilterWidget(ui->filter_CountryComponent);
32  ui->tvp_Countries->allowDragDrop(true, false);
33 
34  connect(sApp->getWebDataServices(), &CWebDataServices::dataRead, this, &CDbCountryComponent::onCountriesRead,
35  Qt::QueuedConnection);
36  this->onCountriesRead(CEntityFlags::CountryEntity, CEntityFlags::ReadFinished,
38  }
39 
41 
42  void CDbCountryComponent::onCountriesRead(CEntityFlags::Entity entity, CEntityFlags::ReadState readState, int count,
43  const QUrl &url)
44  {
45  Q_UNUSED(count)
46  Q_UNUSED(url)
47 
48  if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; }
49  if (entity.testFlag(CEntityFlags::CountryEntity) && CEntityFlags::isFinishedReadState(readState))
50  {
51  ui->tvp_Countries->updateContainerMaybeAsync(sApp->getWebDataServices()->getCountries());
52  }
53  }
54 
55  void CDbCountryComponent::onReload()
56  {
57  if (!sGui || sGui->isShuttingDown() || !sGui->getWebDataServices()) { return; }
58  sApp->getWebDataServices()->triggerLoadingDirectlyFromDb(CEntityFlags::CountryEntity);
59  }
60 } // namespace swift::gui::components
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
Definition: application.cpp:71
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::CCountryList getCountries() const
Countries.
int getCountriesCount() const
Country count.
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 setViewWithIndicator(swift::gui::views::CViewBaseNonTemplate *viewWithIndicator)
Set the corresponding view.
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.
Definition: aboutdialog.cpp:13
Views, mainly QTableView.