swift
Loading...
Searching...
No Matches
usercomponent.cpp
1// SPDX-FileCopyrightText: Copyright (C) 2013 swift Project Community / Contributors
2// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-swift-pilot-client-1
3
5
6#include <QString>
7#include <QTabBar>
8
9#include "ui_usercomponent.h"
10
12#include "gui/guiapplication.h"
13#include "gui/guiutility.h"
15#include "gui/views/userview.h"
18
19using namespace swift::misc::network;
20using namespace swift::gui;
21using namespace swift::gui::views;
22using namespace swift::gui::settings;
23using namespace swift::core;
24using namespace swift::core::context;
25
27{
29 {
30 ui->setupUi(this);
31 this->setCurrentIndex(0);
32 this->tabBar()->setExpanding(false);
33 this->tabBar()->setUsesScrollButtons(true);
34 connect(ui->tvp_AllUsers, &CUserView::modelDataChangedDigest, this, &CUserComponent::onCountChanged);
35 connect(ui->tvp_AllUsers, &CUserView::requestTextMessageWidget, this,
37 connect(ui->tvp_Clients, &CClientView::modelDataChangedDigest, this, &CUserComponent::onCountChanged);
38 connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this,
39 &CUserComponent::onConnectionStatusChanged);
40 connect(&m_updateTimer, &QTimer::timeout, this, &CUserComponent::update);
41 this->onSettingsChanged();
42 }
43
45
47 {
48 Q_ASSERT(ui->tvp_Clients);
49 return ui->tvp_Clients->rowCount();
50 }
51
53 {
54 Q_ASSERT(ui->tvp_AllUsers);
55 return ui->tvp_AllUsers->rowCount();
56 }
57
59 {
60 if (!sGui || sGui->isShuttingDown() || !sGui->getIContextNetwork())
61 {
62 return;
63 }
64 Q_ASSERT(ui->tvp_AllUsers);
65 Q_ASSERT(ui->tvp_Clients);
66
67 if (sGui->getIContextNetwork()->isConnected())
68 {
69 bool withData = countUsers() > 0 || countClients() > 0;
70 if (withData && !isVisibleWidget())
71 {
72 // Skip update, invisible
73 return;
74 }
75
76 // load data
77 const CUserList users = sGui->getIContextNetwork()->getUsers();
78 ui->tvp_AllUsers->updateContainer(users);
79 ui->tvp_Clients->updateContainer(sGui->getIContextNetwork()->getClientsForCallsigns(users.getCallsigns()));
80 }
81 }
82
83 void CUserComponent::onCountChanged(int count, bool withFilter)
84 {
85 Q_UNUSED(count);
86 Q_UNUSED(withFilter);
87 int iu = this->indexOf(ui->tb_AllUsers);
88 int ic = this->indexOf(ui->tb_Clients);
89 QString u = this->tabBar()->tabText(iu);
90 QString c = this->tabBar()->tabText(ic);
93 this->tabBar()->setTabText(iu, u);
94 this->tabBar()->setTabText(ic, c);
95 }
96
97 void CUserComponent::onConnectionStatusChanged(const CConnectionStatus &from, const CConnectionStatus &to)
98 {
99 Q_UNUSED(from);
100 if (to.isDisconnected())
101 {
102 ui->tvp_AllUsers->clear();
103 ui->tvp_Clients->clear();
104 m_updateTimer.stop();
105 }
106 else if (to.isConnected())
107 {
108 m_updateTimer.start();
109 }
110 }
111
112 void CUserComponent::onSettingsChanged()
113 {
114 const CViewUpdateSettings settings = m_settings.get();
115 const int ms = settings.getAtcUpdateTime().toMs();
116 m_updateTimer.setInterval(ms);
117 }
118} // namespace swift::gui::components
void connectionStatusChanged(const swift::misc::network::CConnectionStatus &from, const swift::misc::network::CConnectionStatus &to)
Connection status changed.
static QString replaceTabCountValue(const QString &oldName, int count)
Replace count in name such as "stations (4)".
void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign)
Request a text message.
CUserComponent(QWidget *parent=nullptr)
Constructor.
int countClients() const
Number of clients.
int countUsers() const
Number of users.
const swift::misc::physical_quantities::CTime & getAtcUpdateTime() const
Get time.
void requestTextMessageWidget(const swift::misc::aviation::CCallsign &callsign)
Request a text message.
void modelDataChangedDigest(int count, bool withFilter)
Model data changed,.
swift::misc::aviation::CCallsignSet getCallsigns() const
All callsigns.
Value object encapsulating information about a connection status.
bool isDisconnected() const
Query status.
Value object encapsulating a list of voice rooms.
Definition userlist.h:26
int toMs() const
Convenience functions when used with timers etc.
Definition time.cpp:150
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.
GUI related classes.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
void setExpanding(bool enabled)
void setTabText(int index, const QString &text)
QString tabText(int index) const const
void setUsesScrollButtons(bool useButtons)
QTabWidget(QWidget *parent)
void setCurrentIndex(int index)
int indexOf(const QWidget *w) const const
QTabBar * tabBar() const const
void start()
void stop()
void timeout()
QWidget(QWidget *parent, Qt::WindowFlags f)