Added updating of user views:

* timers
* loading of objects
* refactoring of some methods
This commit is contained in:
Klaus Basan
2014-01-22 17:44:16 +01:00
parent 8008218d28
commit fb3d7e4d28
6 changed files with 184 additions and 60 deletions

View File

@@ -33,7 +33,8 @@ MainWindow::MainWindow(GuiModes::WindowMode windowMode, QWidget *parent) :
// contexts
m_contextApplication(nullptr), m_contextNetwork(nullptr), m_contextVoice(nullptr), m_contextSettings(nullptr),
// timers
m_timerUpdateAtcStationsOnline(nullptr), m_timerUpdateAircraftsInRange(nullptr), m_timerCollectedCockpitUpdates(nullptr), m_timerContextWatchdog(nullptr),
m_timerUpdateAtcStationsOnline(nullptr), m_timerUpdateAircraftsInRange(nullptr), m_timerUpdateUsers(nullptr),
m_timerCollectedCockpitUpdates(nullptr), m_timerContextWatchdog(nullptr),
// context menus
m_contextMenuAudio(nullptr)
{
@@ -67,29 +68,8 @@ void MainWindow::gracefulShutdown()
this->m_infoWindow = nullptr;
}
// if we have a context, we shut some things down
if (this->m_contextNetworkAvailable)
{
if (this->m_contextNetwork->isConnected())
{
if (this->m_contextVoiceAvailable)
{
this->m_contextVoice->leaveAllVoiceRooms();
}
this->m_contextNetwork->disconnectFromNetwork();
}
}
if (this->m_timerUpdateAircraftsInRange)
{
this->m_timerUpdateAircraftsInRange->stop();
this->m_timerUpdateAircraftsInRange->disconnect(this);
}
if (this->m_timerUpdateAtcStationsOnline)
{
this->m_timerUpdateAtcStationsOnline->stop();
this->m_timerUpdateAtcStationsOnline->disconnect(this);
}
// shut down all timers
this->stopUpdateTimers(true);
if (this->m_timerContextWatchdog)
{
this->m_timerContextWatchdog->stop();
@@ -100,6 +80,21 @@ void MainWindow::gracefulShutdown()
this->m_timerCollectedCockpitUpdates->stop();
this->m_timerCollectedCockpitUpdates->disconnect(this);
}
// if we have a context, we shut some things down
if (this->m_contextNetworkAvailable)
{
if (this->m_contextNetwork->isConnected())
{
if (this->m_contextVoiceAvailable)
{
this->m_contextVoice->leaveAllVoiceRooms();
this->m_contextVoice->disconnect(this); // break down signal / slots
}
this->m_contextNetwork->disconnectFromNetwork();
this->m_contextNetwork->disconnect(this); // avoid any status update signals, etc.
}
}
}
/*
@@ -266,17 +261,12 @@ void MainWindow::connectionTerminated()
*/
void MainWindow::connectionStatusChanged(uint /** from **/, uint to)
{
// CContextNetwork::ConnectionStatus statusFrom = static_cast<CContextNetwork::ConnectionStatus>(from);
INetwork::ConnectionStatus statusTo = static_cast<INetwork::ConnectionStatus>(to);
// always
this->updateGuiStatusInformation();
if (statusTo == INetwork::Connected)
{
QTimer::singleShot(5 * 1000, this, SLOT(reloadAircraftsInRange()));
QTimer::singleShot(5 * 1000, this, SLOT(reloadAtcStationsOnline()));
}
INetwork::ConnectionStatus newStatus = static_cast<INetwork::ConnectionStatus>(to);
if (newStatus == INetwork::Connected)
this->startUpdateTimers();
else if (newStatus == INetwork::Disconnected || newStatus == INetwork::DisconnectedError)
this->stopUpdateTimers();
}
/*
@@ -291,12 +281,18 @@ void MainWindow::timerBasedUpdates()
this->m_timerUpdateAtcStationsOnline->start(t);
this->reloadAtcStationsOnline();
}
if (sender == this->m_timerUpdateAircraftsInRange)
else if (sender == this->m_timerUpdateAircraftsInRange)
{
int t = this->ui->hs_SettingsGuiAircraftRefreshTime->value() * 1000;
this->m_timerUpdateAircraftsInRange->start(t);
this->reloadAircraftsInRange();
}
else if (sender == this->m_timerUpdateUsers)
{
int t = this->ui->hs_SettingsGuiUserRefreshTime->value() * 1000;
this->m_timerUpdateUsers->start(t);
this->reloadAllUsers();
}
else if (sender == this->m_timerContextWatchdog)
{
this->setContextAvailability();
@@ -436,3 +432,14 @@ void MainWindow::displayOverlayInfo(const CStatusMessage &message)
this->displayOverlayInfo(message.getMessage());
// further code goes here, such as marking errors as red ...
}
/*
* Read users
*/
void MainWindow::reloadAllUsers()
{
if (!this->isContextNetworkAvailableCheck()) return;
this->m_allUsers->update(this->m_contextNetwork->getUsers());
this->ui->tv_AllUsers->resizeColumnsToContents();
this->ui->tv_AllUsers->resizeRowsToContents();
}

View File

@@ -122,6 +122,7 @@ private:
BlackMisc::Voice::CVoiceRoom m_voiceRoomCom2;
QTimer *m_timerUpdateAtcStationsOnline; /*!< timer for update of stations */
QTimer *m_timerUpdateAircraftsInRange; /*!< timer for update of aircrafts */
QTimer *m_timerUpdateUsers; /*!< timer dor update of users */
QTimer *m_timerCollectedCockpitUpdates; /*!< collect cockpit updates over a short period before sending */
QTimer *m_timerContextWatchdog; /*!< core available? */
QPixmap m_resPixmapConnectionConnected;
@@ -265,6 +266,17 @@ private:
*/
void initContextMenus();
/*!
* \brief Start all update timers
*/
void startUpdateTimers();
/*!
* \brief Stop all update timers
* \param disconnect also disconnect signal/slots
*/
void stopUpdateTimers(bool disconnect = false);
private slots:
//
@@ -286,6 +298,11 @@ private slots:
*/
void reloadAircraftsInRange();
/*!
* \brief Reload all (online) users
*/
void reloadAllUsers();
/*!
* \brief Reload own aircraft
* \return

View File

@@ -388,7 +388,7 @@ QSizeGrip {
<enum>QFrame::NoFrame</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>7</number>
</property>
<widget class="QWidget" name="pg_StatusPage">
<property name="sizePolicy">
@@ -830,7 +830,17 @@ QSizeGrip {
<number>0</number>
</property>
<item>
<widget class="QTableView" name="tv_AllUsers"/>
<widget class="QTableView" name="tv_AllUsers">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
@@ -1364,10 +1374,30 @@ QSizeGrip {
</widget>
</item>
<item row="1" column="0">
<widget class="QTableView" name="tv_CockpitVoiceRoom1"/>
<widget class="QTableView" name="tv_CockpitVoiceRoom1">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
<item row="1" column="1">
<widget class="QTableView" name="tv_CockpitVoiceRoom2"/>
<widget class="QTableView" name="tv_CockpitVoiceRoom2">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</item>
@@ -2010,6 +2040,35 @@ QSizeGrip {
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lbl_SettingsGuiUserRefreshTime">
<property name="text">
<string>User refresh time (5-30s)</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QSlider" name="hs_SettingsGuiUserRefreshTime">
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>30</number>
</property>
<property name="singleStep">
<number>5</number>
</property>
<property name="pageStep">
<number>5</number>
</property>
<property name="value">
<number>10</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>

View File

@@ -45,10 +45,10 @@ bool MainWindow::reloadOwnAircraft()
if (selectedRooms.size() == 2)
{
this->m_voiceRoomCom1 = this->ui->cb_CockpitVoiceRoom1Override->isChecked() ?
this->ui->le_CockpitVoiceRoomCom1->text().trimmed() :
CVoiceRoom(this->ui->le_CockpitVoiceRoomCom1->text().trimmed()) :
selectedRooms[0];
this->m_voiceRoomCom2 = this->ui->cb_CockpitVoiceRoom2Override->isChecked() ?
this->ui->le_CockpitVoiceRoomCom2->text().trimmed() :
CVoiceRoom(this->ui->le_CockpitVoiceRoomCom2->text().trimmed()) :
selectedRooms[1];
}
}

View File

@@ -3,6 +3,7 @@
#include "blackgui/atcstationlistmodel.h"
#include "blackcore/dbus_server.h"
#include "blackcore/context_network.h"
#include "blackmisc/vvoiceroom.h"
using namespace BlackCore;
using namespace BlackMisc;
@@ -13,6 +14,7 @@ using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Geo;
using namespace BlackMisc::Settings;
using namespace BlackMisc::Math;
using namespace BlackMisc::Voice;
/*
* Cockpit values
@@ -107,28 +109,40 @@ void MainWindow::updateCockpitFromContext()
//
// Voice room override
//
if (!this->ui->cb_CockpitVoiceRoom1Override->isChecked())
if (this->m_contextVoiceAvailable)
{
if (!this->ui->cb_CockpitVoiceRoom1Override->isChecked() && this->m_voiceRoomCom1.isValid())
bool com1Connected = this->m_voiceRoomCom1.isConnected();
bool com2Connected = this->m_voiceRoomCom2.isConnected();
Q_ASSERT(this->m_usersVoiceCom1);
Q_ASSERT(this->m_usersVoiceCom2);
this->m_usersVoiceCom1->update(this->m_contextVoice->getCom1RoomUsers());
this->ui->tv_CockpitVoiceRoom1->resizeColumnsToContents();
this->ui->tv_CockpitVoiceRoom1->resizeRowsToContents();
this->m_usersVoiceCom2->update(this->m_contextVoice->getCom2RoomUsers());
this->ui->tv_CockpitVoiceRoom2->resizeColumnsToContents();
this->ui->tv_CockpitVoiceRoom2->resizeRowsToContents();
// display URL if not override mode
if (!this->ui->cb_CockpitVoiceRoom1Override->isChecked())
{
QString s(this->m_voiceRoomCom1.isConnected() ? "*" : "");
s.append(this->m_voiceRoomCom1.getVoiceRoomUrl());
// no override
QString s = com1Connected ?
QString("*%1").arg(this->m_voiceRoomCom1.getVoiceRoomUrl()) :
"";
this->ui->le_CockpitVoiceRoomCom1->setText(s);
}
else
this->ui->le_CockpitVoiceRoomCom1->setText("");
}
if (!this->ui->cb_CockpitVoiceRoom2Override->isChecked())
{
if (this->m_voiceRoomCom2.isValid())
// display URL if not override mode
if (!this->ui->cb_CockpitVoiceRoom2Override->isChecked())
{
QString s(this->m_voiceRoomCom2.isConnected() ? "*" : "");
s.append(this->m_voiceRoomCom2.getVoiceRoomUrl());
// no overrride
QString s = com2Connected ?
QString("*%1").arg(this->m_voiceRoomCom2.getVoiceRoomUrl()) :
"";
this->ui->le_CockpitVoiceRoomCom2->setText(s);
}
else
this->ui->le_CockpitVoiceRoomCom2->setText("");
}
}
@@ -259,11 +273,11 @@ void MainWindow::voiceRoomOverride()
this->ui->le_CockpitVoiceRoomCom2->setReadOnly(!this->ui->cb_CockpitVoiceRoom2Override->isChecked());
if (this->ui->cb_CockpitVoiceRoom1Override->isChecked())
{
this->m_voiceRoomCom1 = this->ui->cb_CockpitVoiceRoom1Override->text().trimmed();
this->m_voiceRoomCom1 = CVoiceRoom(this->ui->cb_CockpitVoiceRoom1Override->text().trimmed());
}
if (this->ui->cb_CockpitVoiceRoom2Override->isChecked())
{
this->m_voiceRoomCom2 = this->ui->cb_CockpitVoiceRoom2Override->text().trimmed();
this->m_voiceRoomCom2 = CVoiceRoom(this->ui->cb_CockpitVoiceRoom2Override->text().trimmed());
}
}

View File

@@ -119,6 +119,7 @@ void MainWindow::init(GuiModes::CoreMode coreMode)
// timer
if (this->m_timerUpdateAircraftsInRange == nullptr) this->m_timerUpdateAircraftsInRange = new QTimer(this);
if (this->m_timerUpdateAtcStationsOnline == nullptr) this->m_timerUpdateAtcStationsOnline = new QTimer(this);
if (this->m_timerUpdateUsers == nullptr) this->m_timerUpdateUsers = new QTimer(this);
if (this->m_timerContextWatchdog == nullptr) this->m_timerContextWatchdog = new QTimer(this);
if (this->m_timerCollectedCockpitUpdates == nullptr) this->m_timerCollectedCockpitUpdates = new QTimer(this);
@@ -162,12 +163,11 @@ void MainWindow::init(GuiModes::CoreMode coreMode)
Q_ASSERT(connect);
this->connect(this->m_timerUpdateAircraftsInRange, &QTimer::timeout, this, &MainWindow::timerBasedUpdates);
this->connect(this->m_timerUpdateAtcStationsOnline, &QTimer::timeout, this, &MainWindow::timerBasedUpdates);
this->connect(this->m_timerUpdateUsers, &QTimer::timeout, this, &MainWindow::timerBasedUpdates);
this->connect(this->m_timerContextWatchdog, &QTimer::timeout, this, &MainWindow::timerBasedUpdates);
this->connect(this->m_timerCollectedCockpitUpdates, &QTimer::timeout, this, &MainWindow::sendCockpitUpdates);
// start timers
this->m_timerUpdateAircraftsInRange->start(10 * 1000);
this->m_timerUpdateAtcStationsOnline->start(10 * 1000);
// start timers, update timers will be started when network is connected
this->m_timerContextWatchdog->start(2 * 1000);
// init availability
@@ -313,6 +313,33 @@ void MainWindow::initialDataReads()
{
// connection is already established
this->reloadAircraftsInRange();
this->reloadAllUsers();
this->reloadAtcStationsOnline();
this->updateGuiStatusInformation();
}
}
/*
* Start update timers
*/
void MainWindow::startUpdateTimers()
{
this->m_timerUpdateAircraftsInRange->start(this->ui->hs_SettingsGuiAircraftRefreshTime->value() * 1000);
this->m_timerUpdateAtcStationsOnline->start(this->ui->hs_SettingsGuiAtcRefreshTime->value() * 1000);
this->m_timerUpdateUsers->start(this->ui->hs_SettingsGuiUserRefreshTime->value() * 1000);
}
/*
* Stop udate timers
*/
void MainWindow::stopUpdateTimers(bool disconnect)
{
this->m_timerUpdateAircraftsInRange->stop();
this->m_timerUpdateAtcStationsOnline->stop();
this->m_timerUpdateUsers->stop();
if (!disconnect) return;
this->disconnect(this->m_timerUpdateAircraftsInRange);
this->disconnect(this->m_timerUpdateAtcStationsOnline);
this->disconnect(this->m_timerUpdateUsers);
}