diff --git a/src/blackcore/network.h b/src/blackcore/network.h index dbf2026d9..4d75d21df 100644 --- a/src/blackcore/network.h +++ b/src/blackcore/network.h @@ -139,6 +139,14 @@ namespace BlackCore status == DisconnectedFailed || status == DisconnectedLost; } + /*! + * Returns true if the given ConnectionStatus represents a connected state. + */ + static bool isConnectedStatus(ConnectionStatus status) + { + return status == Connected; + } + //////////////////////////////////////////////////////////////// //! \name Network slots //! @{ diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index d22c6ba01..0eb43bfa6 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -27,6 +27,7 @@ using namespace BlackGui; using namespace BlackGui::Views; using namespace BlackGui::Models; +using namespace BlackGui::Settings; using namespace BlackCore; using namespace BlackCore::Context; using namespace BlackMisc::Simulation; @@ -36,11 +37,9 @@ namespace BlackGui { namespace Components { - CAircraftComponent::CAircraftComponent(QWidget *parent) : QTabWidget(parent), - ui(new Ui::CAircraftComponent), - m_updateTimer(new CUpdateTimer("CAircraftComponent", &CAircraftComponent::update, this)) + ui(new Ui::CAircraftComponent) { ui->setupUi(this); this->tabBar()->setExpanding(false); @@ -55,6 +54,9 @@ namespace BlackGui connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestHighlightInSimulator, this, &CAircraftComponent::ps_onMenuHighlightInSimulator); connect(ui->tvp_AirportsInRange, &CSimulatedAircraftView::modelDataChanged, this, &CAircraftComponent::ps_onRowCountChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::ps_connectionStatusChanged); + connect(&m_updateTimer, &QTimer::timeout, this, &CAircraftComponent::update); + + this->ps_settingsChanged(); } CAircraftComponent::~CAircraftComponent() @@ -137,6 +139,11 @@ namespace BlackGui if (INetwork::isDisconnectedStatus(to)) { ui->tvp_AircraftInRange->clear(); + this->m_updateTimer.stop(); + } + else if (INetwork::isConnectedStatus(to)) + { + this->m_updateTimer.start(); } } @@ -148,5 +155,11 @@ namespace BlackGui } } + void CAircraftComponent::ps_settingsChanged() + { + const CViewUpdateSettings settings = this->m_settings.get(); + this->m_updateTimer.setInterval(settings.getAircraftUpdateTime().toMs()); + } + } // namespace } // namespace diff --git a/src/blackgui/components/aircraftcomponent.h b/src/blackgui/components/aircraftcomponent.h index 809f6d5e5..f3fd68ec6 100644 --- a/src/blackgui/components/aircraftcomponent.h +++ b/src/blackgui/components/aircraftcomponent.h @@ -14,13 +14,14 @@ #include "blackcore/network.h" #include "blackgui/blackguiexport.h" +#include "blackgui/settings/viewupdatesettings.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" -#include "blackgui/components/updatetimer.h" #include #include #include #include +#include class QWidget; @@ -30,11 +31,9 @@ namespace BlackMisc namespace Simulation { class CSimulatedAircraft; } } namespace Ui { class CAircraftComponent; } - namespace BlackGui { class CDockWidgetInfoArea; - namespace Components { //! Aircraft widget @@ -65,15 +64,9 @@ namespace BlackGui void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); public slots: - //! Update aircrafts + //! Update aircraft void update(); - //! \copydoc CUpdateTimer::setUpdateIntervalSeconds - void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - - //! \copydoc CUpdateTimer::stopTimer - void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - private slots: //! Info area tab bar has changed void ps_infoAreaTabBarChanged(int index); @@ -87,9 +80,13 @@ namespace BlackGui //! Highlight in simulator void ps_onMenuHighlightInSimulator(const BlackMisc::Simulation::CSimulatedAircraft &aircraft); + //! Settings have been changed + void ps_settingsChanged(); + private: QScopedPointer ui; - QScopedPointer m_updateTimer; + BlackMisc::CSettingReadOnly m_settings { this, &CAircraftComponent::ps_settingsChanged }; //!< settings changed + QTimer m_updateTimer { this }; }; } // ns } // ns diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 4dabd0be6..26768abd8 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -38,6 +38,7 @@ using namespace BlackGui; using namespace BlackGui::Models; using namespace BlackGui::Views; +using namespace BlackGui::Settings; using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::PhysicalQuantities; @@ -52,8 +53,7 @@ namespace BlackGui CAtcStationComponent::CAtcStationComponent(QWidget *parent) : QTabWidget(parent), CIdentifiable(this), - ui(new Ui::CAtcStationComponent), - m_updateTimer(new CUpdateTimer("CAtcStationComponent", &CAtcStationComponent::update, this)) + ui(new Ui::CAtcStationComponent) { ui->setupUi(this); this->tabBar()->setExpanding(false); @@ -90,12 +90,16 @@ namespace BlackGui connect(ui->tvp_AtcStationsBooked, &CAtcStationView::modelDataChanged, this, &CAtcStationComponent::ps_onCountChanged); connect(ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis); + connect(&m_updateTimer, &QTimer::timeout, this, &CAtcStationComponent::update); // runtime based connects this->connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnlineDigest, this, &CAtcStationComponent::ps_changedAtcStationsOnline); this->connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationsBookedDigest, this, &CAtcStationComponent::ps_changedAtcStationsBooked); this->connect(sGui->getIContextNetwork(), &IContextNetwork::changedAtcStationOnlineConnectionStatus, this, &CAtcStationComponent::changedAtcStationOnlineConnectionStatus); this->connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAtcStationComponent::ps_connectionStatusChanged); + + // settings have + this->ps_settingsChanged(); } CAtcStationComponent::~CAtcStationComponent() @@ -232,6 +236,11 @@ namespace BlackGui { ui->tvp_AtcStationsOnline->clear(); this->updateTreeView(); + this->m_updateTimer.start(); + } + else if (INetwork::isConnectedStatus(to)) + { + this->m_updateTimer.stop(); } } @@ -245,8 +254,8 @@ namespace BlackGui void CAtcStationComponent::ps_requestOnlineStationsUpdate() { - this->m_updateTimer->fireTimer(); - this->m_timestampLastReadOnlineStations = CUpdateTimer::epoch(); // mark as outdated + this->m_timestampLastReadOnlineStations.setMSecsSinceEpoch(0); // mark as outdated + this->update(); } void CAtcStationComponent::ps_infoAreaTabBarChanged(int index) @@ -281,10 +290,15 @@ namespace BlackGui sGui->getIContextOwnAircraft()->updateActiveComFrequency(frequency, unit, identifier()); } + void CAtcStationComponent::ps_settingsChanged() + { + const CViewUpdateSettings settings = this->m_settings.get(); + this->m_updateTimer.setInterval(settings.getAtcUpdateTime().toMs()); + } + void CAtcStationComponent::updateTreeView() { - // - //! \todo EXPERIMENTAL CODE: change model so we can directly use hierarchies + //! \fixme EXPERIMENTAL CODE: change model so we can directly use hierarchies QAbstractItemModel *old = (ui->tvp_AtcStationsOnlineTree->model()); ui->tvp_AtcStationsOnlineTree->setModel( ui->tvp_AtcStationsOnline->derivedModel()->toAtcGroupModel() diff --git a/src/blackgui/components/atcstationcomponent.h b/src/blackgui/components/atcstationcomponent.h index d3925d3e4..6cf9d4145 100644 --- a/src/blackgui/components/atcstationcomponent.h +++ b/src/blackgui/components/atcstationcomponent.h @@ -15,7 +15,7 @@ #include "blackcore/network.h" #include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" -#include "blackgui/components/updatetimer.h" +#include "blackgui/settings/viewupdatesettings.h" #include "blackmisc/aviation/atcstation.h" #include "blackmisc/aviation/comsystem.h" #include "blackmisc/identifiable.h" @@ -28,6 +28,7 @@ #include #include #include +#include class QWidget; @@ -36,7 +37,6 @@ namespace Ui { class CAtcStationComponent; } namespace BlackGui { class CDockWidgetInfoArea; - namespace Components { //! ATC stations component @@ -71,12 +71,6 @@ namespace BlackGui //! Update stations void update(); - //! \copydoc CUpdateTimer::setUpdateIntervalSeconds - void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - - //! \copydoc CUpdateTimer::stopTimer - void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - //! Get METAR for given ICAO airport code void getMetar(const QString &airportIcaoCode); @@ -123,14 +117,18 @@ namespace BlackGui //! Set COM frequency void ps_setComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit); + //! Settings have been changed + void ps_settingsChanged(); + private: void updateTreeView(); QScopedPointer ui; - QScopedPointer m_updateTimer; - QDateTime m_timestampLastReadOnlineStations = CUpdateTimer::epoch(); //!< stations read - QDateTime m_timestampOnlineStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed - QDateTime m_timestampLastReadBookedStations = CUpdateTimer::epoch(); //!< stations read - QDateTime m_timestampBookedStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed + QTimer m_updateTimer { this }; + QDateTime m_timestampLastReadOnlineStations; //!< stations read + QDateTime m_timestampOnlineStationsChanged; //!< stations marked as changed + QDateTime m_timestampLastReadBookedStations; //!< stations read + QDateTime m_timestampBookedStationsChanged; //!< stations marked as changed + BlackMisc::CSettingReadOnly m_settings { this, &CAtcStationComponent::ps_settingsChanged }; }; } // namespace } // namespace diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index a901a3ae5..d3e2879a0 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -11,7 +11,6 @@ #include "blackcore/context/contextsimulator.h" #include "blackcore/network.h" #include "blackgui/components/mappingcomponent.h" -#include "blackgui/components/updatetimer.h" #include "blackgui/guiapplication.h" #include "blackgui/guiutility.h" #include "blackgui/models/aircraftmodellistmodel.h" @@ -51,6 +50,7 @@ using namespace BlackGui; using namespace BlackGui::Views; using namespace BlackGui::Models; using namespace BlackGui::Filters; +using namespace BlackGui::Settings; namespace BlackGui { @@ -59,8 +59,7 @@ namespace BlackGui CMappingComponent::CMappingComponent(QWidget *parent) : QFrame(parent), CIdentifiable(this), - ui(new Ui::CMappingComponent), - m_updateTimer(new CUpdateTimer("CMappingComponent", &CMappingComponent::ps_backgroundUpdate, this)) + ui(new Ui::CMappingComponent) { ui->setupUi(this); ui->tvp_AircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModel); @@ -100,7 +99,8 @@ namespace BlackGui // Updates ui->tvp_AircraftModels->setDisplayAutomatically(false); - this->m_updateTimer->setUpdateInterval(10 * 1000); + this->ps_settingsChanged(); + connect(&m_updateTimer, &QTimer::timeout, this, &CMappingComponent::ps_backgroundUpdate); connect(sGui->getIContextSimulator(), &IContextSimulator::modelSetChanged, this, &CMappingComponent::ps_onModelSetChanged); connect(sGui->getIContextSimulator(), &IContextSimulator::modelMatchingCompleted, this, &CMappingComponent::ps_markRenderedAircraftForUpdate); @@ -441,5 +441,11 @@ namespace BlackGui this->updateRenderedAircraftView(true); } } + + void CMappingComponent::ps_settingsChanged() + { + const CViewUpdateSettings settings = this->m_settings.get(); + this->m_updateTimer.setInterval(settings.getAircraftUpdateTime().toMs()); + } } // namespace } // namespace diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index 4489925bb..18fd74d01 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -15,6 +15,7 @@ #include "blackcore/network.h" #include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackgui/settings/viewupdatesettings.h" #include "blackmisc/identifiable.h" #include "blackmisc/identifier.h" #include "blackmisc/propertyindex.h" @@ -24,6 +25,7 @@ #include #include #include +#include #include #include @@ -37,15 +39,11 @@ namespace BlackMisc namespace Simulation { class CSimulatedAircraft; } } namespace Ui { class CMappingComponent; } - namespace BlackGui { namespace Views { class CCheckBoxDelegate; } - namespace Components { - class CUpdateTimer; - //! Mappings, models etc. class BLACKGUI_EXPORT CMappingComponent : public QFrame, @@ -138,16 +136,19 @@ namespace BlackGui BlackMisc::Aviation::CCallsign validateRenderedCallsign() const; QScopedPointer ui; - bool m_missedRenderedAircraftUpdate = true; - QScopedPointer m_updateTimer; + BlackMisc::CSettingReadOnly m_settings { this, &CMappingComponent::ps_settingsChanged }; //!< settings changed + bool m_missedRenderedAircraftUpdate = true; //! Rendered aircraft need update + QTimer m_updateTimer { this }; BlackGui::Views::CCheckBoxDelegate *m_currentMappingsViewDelegate = nullptr; BlackMisc::CIdentifier m_identifier; private slots: //! Updated by timer void ps_backgroundUpdate(); - }; + //! Settings have been changed + void ps_settingsChanged(); + }; } // namespace } // namespace diff --git a/src/blackgui/components/registercomponent.cpp b/src/blackgui/components/registercomponent.cpp index 170fe8afb..abb269c2e 100644 --- a/src/blackgui/components/registercomponent.cpp +++ b/src/blackgui/components/registercomponent.cpp @@ -9,7 +9,6 @@ #include "blackcore/context/contextapplication.h" #include "blackgui/components/registercomponent.h" -#include "blackgui/components/updatetimer.h" #include "blackgui/guiapplication.h" #include "blackgui/views/identifierview.h" #include "ui_registercomponent.h" @@ -25,12 +24,15 @@ namespace BlackGui { CRegisterComponent::CRegisterComponent(QWidget *parent) : QFrame(parent), - ui(new Ui::CRegisterComponent), - m_updateTimer(new CUpdateTimer("CRegisterComponent", &CRegisterComponent::ps_update, this)) + ui(new Ui::CRegisterComponent) { ui->setupUi(this); - m_updateTimer->setUpdateIntervalSeconds(20); connect(sGui->getIContextApplication(), &IContextApplication::registrationChanged, this, &CRegisterComponent::ps_update); + + // timer is there just in case something goes wrong + connect(&m_updateTimer, &QTimer::timeout, this, &CRegisterComponent::ps_update); + m_updateTimer.setInterval(30 * 1000); + m_updateTimer.start(); } CRegisterComponent::~CRegisterComponent() diff --git a/src/blackgui/components/registercomponent.h b/src/blackgui/components/registercomponent.h index 56b0c4d09..74a73ed0b 100644 --- a/src/blackgui/components/registercomponent.h +++ b/src/blackgui/components/registercomponent.h @@ -14,19 +14,18 @@ #include #include +#include #include class QWidget; namespace Ui { class CRegisterComponent; } - namespace BlackGui { namespace Components { - class CUpdateTimer; - - //! Register components in the GUI + //! Show registered applications (registered with core) in the GUI + //! \sa BlackCore::Context::IContextApplication::getRegisteredApplications class BLACKGUI_EXPORT CRegisterComponent : public QFrame { @@ -45,7 +44,7 @@ namespace BlackGui private: QScopedPointer ui; - QScopedPointer m_updateTimer; + QTimer m_updateTimer; }; } // ns diff --git a/src/blackgui/components/settingscomponent.cpp b/src/blackgui/components/settingscomponent.cpp index f61a77c91..7a4d2e5cb 100644 --- a/src/blackgui/components/settingscomponent.cpp +++ b/src/blackgui/components/settingscomponent.cpp @@ -46,11 +46,7 @@ namespace BlackGui this->setCurrentIndex(0); // 1st tab ui->comp_DataLoadOverview->setVisibleDbRefreshButtons(false); - this->connect(ui->hs_SettingsGuiAircraftRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAircraftUpdateInterval); - this->connect(ui->hs_SettingsGuiAtcRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedAtcStationsUpdateInterval); - this->connect(ui->hs_SettingsGuiUserRefreshTime, &QSlider::valueChanged, this, &CSettingsComponent::changedUsersUpdateInterval); - this->connect(ui->comp_SettingsGuiGeneral, &CSettingsGuiComponent::changedWindowsOpacity, this, &CSettingsComponent::changedWindowsOpacity); - + connect(ui->comp_SettingsGuiGeneral, &CSettingsGuiComponent::changedWindowsOpacity, this, &CSettingsComponent::changedWindowsOpacity); connect(ui->pb_Advanced, &QPushButton::released, this, &CSettingsComponent::ps_overviewButtonClicked); connect(ui->pb_Audio, &QPushButton::released, this, &CSettingsComponent::ps_overviewButtonClicked); connect(ui->pb_Gui, &QPushButton::released, this, &CSettingsComponent::ps_overviewButtonClicked); @@ -70,21 +66,6 @@ namespace BlackGui return ui->comp_AudioSetup->playNotificationSounds(); } - int CSettingsComponent::getAtcUpdateIntervalSeconds() const - { - return ui->hs_SettingsGuiAtcRefreshTime->value(); - } - - int CSettingsComponent::getAircraftUpdateIntervalSeconds() const - { - return ui->hs_SettingsGuiAircraftRefreshTime->value(); - } - - int CSettingsComponent::getUsersUpdateIntervalSeconds() const - { - return ui->hs_SettingsGuiUserRefreshTime->value(); - } - void CSettingsComponent::setSettingsTab(CSettingsComponent::SettingTab tab) { this->setCurrentIndex(static_cast(tab)); diff --git a/src/blackgui/components/settingscomponent.h b/src/blackgui/components/settingscomponent.h index 7b29955f3..cc491b056 100644 --- a/src/blackgui/components/settingscomponent.h +++ b/src/blackgui/components/settingscomponent.h @@ -57,15 +57,6 @@ namespace BlackGui //! \copydoc CAudioSetupComponent::playNotificationSounds bool playNotificationSounds() const; - //! ATC refresh time - int getAtcUpdateIntervalSeconds() const; - - //! Aircraft refresh time - int getAircraftUpdateIntervalSeconds() const; - - //! Aircraft refresh time - int getUsersUpdateIntervalSeconds() const; - signals: //! Change the windows opacity 0..100 void changedWindowsOpacity(int opacity); diff --git a/src/blackgui/components/settingscomponent.ui b/src/blackgui/components/settingscomponent.ui index e4062cbb0..636b206db 100644 --- a/src/blackgui/components/settingscomponent.ui +++ b/src/blackgui/components/settingscomponent.ui @@ -351,138 +351,6 @@ - - - - View refresh times - - - - - - Aircraft refresh time (5-30s) - - - Aircraft rt (5-30s) - - - - - - - - 0 - 0 - - - - 5 - - - 30 - - - 5 - - - 5 - - - 10 - - - Qt::Horizontal - - - QSlider::NoTicks - - - - - - - ATC refresh time (5-30s) - - - ATC rt (5-30s) - - - - - - - - 0 - 0 - - - - 5 - - - 30 - - - 5 - - - 5 - - - 10 - - - Qt::Horizontal - - - - - - - User refresh time (5-30s) - - - User rt (5-30s) - - - - - - - - 0 - 0 - - - - 5 - - - 30 - - - 5 - - - 5 - - - 10 - - - Qt::Horizontal - - - - - lbl_SettingsGuiUserRefreshTime - lbl_SettingsGuiAtcRefreshTime - lbl_SettingsGuiAircraftRefreshTime - hs_SettingsGuiUserRefreshTime - hs_SettingsGuiAtcRefreshTime - hs_SettingsGuiAircraftRefreshTime - - @@ -514,6 +382,16 @@ + + + + + 0 + 100 + + + + @@ -635,6 +513,12 @@
blackgui/components/settingssimulatormessagescomponent.h
1 + + BlackGui::Components::CSettingsViewUpdateTimes + QFrame +
blackgui/components/settingsviewupdatetimes.h
+ 1 +
diff --git a/src/blackgui/components/simulatorcomponent.cpp b/src/blackgui/components/simulatorcomponent.cpp index db33bfc7e..fae87cc23 100644 --- a/src/blackgui/components/simulatorcomponent.cpp +++ b/src/blackgui/components/simulatorcomponent.cpp @@ -40,8 +40,7 @@ namespace BlackGui CSimulatorComponent::CSimulatorComponent(QWidget *parent) : QTabWidget(parent), CEnableForDockWidgetInfoArea(), - ui(new Ui::CSimulatorComponent), - m_updateTimer(new CUpdateTimer("CSimulatorComponent", &CSimulatorComponent::update, this)) + ui(new Ui::CSimulatorComponent) { ui->setupUi(this); ui->tvp_LiveData->setIconMode(true); @@ -49,11 +48,8 @@ namespace BlackGui this->addOrUpdateByName("info", "no data yet", CIcons::StandardIconWarning16); connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged); - this->setUpdateInterval(getUpdateIntervalMs()); - if (sGui->getIContextSimulator()->getSimulatorStatus() == 0) - { - this->stopTimer(); - } + connect(&this->m_updateTimer, &QTimer::timeout, this, &CSimulatorComponent::update); + this->ps_onSimulatorStatusChanged(sGui->getIContextSimulator()->getSimulatorStatus()); } CSimulatorComponent::~CSimulatorComponent() @@ -132,14 +128,14 @@ namespace BlackGui { if (status & ISimulator::Connected) { - int intervalMs = getUpdateIntervalMs(); - this->m_updateTimer->startTimer(intervalMs); + const int intervalMs = getUpdateIntervalMs(); + this->m_updateTimer.start(intervalMs); } else { - this->stopTimer(); - clear(); - update(); + this->m_updateTimer.stop(); + this->clear(); + this->update(); } } diff --git a/src/blackgui/components/simulatorcomponent.h b/src/blackgui/components/simulatorcomponent.h index 673e58194..f7151e319 100644 --- a/src/blackgui/components/simulatorcomponent.h +++ b/src/blackgui/components/simulatorcomponent.h @@ -14,10 +14,10 @@ #include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" -#include "blackgui/components/updatetimer.h" #include "blackmisc/icons.h" #include +#include #include #include #include @@ -32,7 +32,6 @@ namespace BlackGui { namespace Components { - //! Simulator component class BLACKGUI_EXPORT CSimulatorComponent : public QTabWidget, @@ -41,7 +40,6 @@ namespace BlackGui Q_OBJECT public: - //! Constructor explicit CSimulatorComponent(QWidget *parent = nullptr); @@ -64,15 +62,6 @@ namespace BlackGui //! Update simulator void update(); - //! \copydoc CUpdateTimer::setUpdateIntervalSeconds - void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - - //! \copydoc CUpdateTimer::setUpdateInterval - void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateInterval(milliSeconds); } - - //! \copydoc CUpdateTimer::stopTimer - void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - private slots: //! \copydoc ISimulator::simulatorStatusChanged void ps_onSimulatorStatusChanged(int status); @@ -82,7 +71,7 @@ namespace BlackGui int getUpdateIntervalMs() const; QScopedPointer ui; - QScopedPointer m_updateTimer; + QTimer m_updateTimer; }; } } diff --git a/src/blackgui/components/updatetimer.cpp b/src/blackgui/components/updatetimer.cpp deleted file mode 100644 index efd36eb2f..000000000 --- a/src/blackgui/components/updatetimer.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -#include "blackgui/components/updatetimer.h" - -namespace BlackGui -{ - namespace Components - { - void CUpdateTimer::initTimers(const QString &name) - { - this->m_timer = new QTimer(this); - this->m_timerSingleShot = new QTimer(this); - this->m_timerSingleShot->setSingleShot(true); - this->m_timer->setObjectName(name + ":periodically"); - this->m_timerSingleShot->setObjectName(name + ":singleShot"); - } - - CUpdateTimer::~CUpdateTimer() - { - if (this->parent()) { this->disconnect(this->parent()); } - this->m_timer->stop(); - this->m_timerSingleShot->stop(); - } - - void CUpdateTimer::setUpdateInterval(int milliSeconds) - { - if (milliSeconds < 100) - { - this->m_timer->stop(); - } - else - { - this->m_timer->setInterval(milliSeconds); - if (!this->m_timer->isActive()) this->m_timer->start(); - } - } - - void CUpdateTimer::fireTimer() - { - Q_ASSERT(this->m_timerSingleShot); - this->m_timer->start(); // restart other timer - this->m_timerSingleShot->start(10); - } - } // namespace -} // namespace diff --git a/src/blackgui/components/updatetimer.h b/src/blackgui/components/updatetimer.h deleted file mode 100644 index 54a272372..000000000 --- a/src/blackgui/components/updatetimer.h +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (C) 2013 - * swift project Community / Contributors - * - * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level - * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, - * including this file, may be copied, modified, propagated, or distributed except according to the terms - * contained in the LICENSE file. - */ - -//! \file - -#ifndef BLACKGUI_UPDATETIMER_H -#define BLACKGUI_UPDATETIMER_H - -#include "blackgui/blackguiexport.h" - -#include -#include -#include -#include -#include - -namespace BlackGui -{ - namespace Components - { - //! Timer used in components for updates - //! \deprecated used at the beginning of the project, likely to be removed in the future - class BLACKGUI_EXPORT CUpdateTimer: public QObject - { - Q_OBJECT - - public: - //! Construct a timer which forwards messages to the given slot of parent. - template - CUpdateTimer(const QString &name, F slot, P *parent) : QObject(parent) - { - Q_ASSERT(parent); - this->initTimers(name); - bool c = this->connect(this->m_timer, &QTimer::timeout, parent, slot); - Q_ASSERT(c); - c = this->connect(this->m_timerSingleShot, &QTimer::timeout, parent, slot); - Q_ASSERT(c); - Q_UNUSED(c); - } - - //! Destructor - virtual ~CUpdateTimer(); - - //! Date/time of 1/1/1970, used to init timestamp values as "outdated" - static const QDateTime &epoch() - { - static const QDateTime e = QDateTime::fromMSecsSinceEpoch(0); - return e; - } - - public slots: - //! Update time, time < 100ms stops updates - void setUpdateInterval(int milliSeconds); - - //! Update time - void setUpdateIntervalSeconds(int seconds) { this->setUpdateInterval(1000 * seconds); } - - //! Stop timer - void stopTimer() { this->setUpdateInterval(-1); this->m_timerSingleShot->stop(); } - - //! Start timer - void startTimer(int milliSeconds) { this->setUpdateInterval(milliSeconds);} - - //! Fire the timer straight away - void fireTimer(); - - private: - void initTimers(const QString &name); //!< init timers - QTimer *m_timer = nullptr; //!< periodically updating - QTimer *m_timerSingleShot = nullptr; //!< single update - }; - } // ns -} // ns -#endif // guard diff --git a/src/blackgui/components/usercomponent.cpp b/src/blackgui/components/usercomponent.cpp index bf77a4b68..5419a9816 100644 --- a/src/blackgui/components/usercomponent.cpp +++ b/src/blackgui/components/usercomponent.cpp @@ -21,6 +21,7 @@ using namespace BlackGui; using namespace BlackGui::Views; +using namespace BlackGui::Settings; using namespace BlackCore; using namespace BlackCore::Context; @@ -31,8 +32,7 @@ namespace BlackGui CUserComponent::CUserComponent(QWidget *parent) : QTabWidget(parent), CEnableForDockWidgetInfoArea(), - ui(new Ui::CUserComponent), - m_updateTimer(new CUpdateTimer("CUserComponent", &CUserComponent::update, this)) + ui(new Ui::CUserComponent) { ui->setupUi(this); this->tabBar()->setExpanding(false); @@ -40,6 +40,8 @@ namespace BlackGui connect(ui->tvp_AllUsers, &CUserView::modelDataChanged, this, &CUserComponent::ps_onCountChanged); connect(ui->tvp_Clients, &CClientView::modelDataChanged, this, &CUserComponent::ps_onCountChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CUserComponent::ps_connectionStatusChanged); + connect(&m_updateTimer, &QTimer::timeout, this, &CUserComponent::update); + this->ps_settingsChanged(); } CUserComponent::~CUserComponent() @@ -99,7 +101,19 @@ namespace BlackGui { ui->tvp_AllUsers->clear(); ui->tvp_Clients->clear(); + this->m_updateTimer.stop(); } + else if (INetwork::isConnectedStatus(to)) + { + this->m_updateTimer.start(); + } + } + + void CUserComponent::ps_settingsChanged() + { + const CViewUpdateSettings settings = this->m_settings.get(); + const int ms = settings.getAtcUpdateTime().toMs(); + this->m_updateTimer.setInterval(ms); } } // namespace } // namespace diff --git a/src/blackgui/components/usercomponent.h b/src/blackgui/components/usercomponent.h index c1bb45d90..a745470d9 100644 --- a/src/blackgui/components/usercomponent.h +++ b/src/blackgui/components/usercomponent.h @@ -14,18 +14,18 @@ #include "blackcore/network.h" #include "blackgui/blackguiexport.h" +#include "blackgui/settings/viewupdatesettings.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" -#include "blackgui/components/updatetimer.h" #include #include #include #include +#include class QWidget; namespace Ui { class CUserComponent; } - namespace BlackGui { namespace Components @@ -54,12 +54,6 @@ namespace BlackGui //! Update users void update(); - //! \copydoc CUpdateTimer::setUpdateIntervalSeconds - void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - - //! \copydoc CUpdateTimer::stopTimer - void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } - private slots: //! Number of elements changed void ps_onCountChanged(int count, bool withFilter); @@ -67,9 +61,13 @@ namespace BlackGui //! Connection status void ps_connectionStatusChanged(BlackCore::INetwork::ConnectionStatus from, BlackCore::INetwork::ConnectionStatus to); + //! Settings have been changed + void ps_settingsChanged(); + private: QScopedPointer ui; - QScopedPointer m_updateTimer; + QTimer m_updateTimer { this }; + BlackMisc::CSettingReadOnly m_settings { this, &CUserComponent::ps_settingsChanged }; }; } } diff --git a/src/blackgui/components/weathercomponent.h b/src/blackgui/components/weathercomponent.h index 422e92b72..0b46e1dcf 100644 --- a/src/blackgui/components/weathercomponent.h +++ b/src/blackgui/components/weathercomponent.h @@ -14,7 +14,6 @@ #include "blackgui/blackguiexport.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" -#include "blackgui/components/updatetimer.h" #include "blackcore/simulator/simulatorsettings.h" #include "blackmisc/geo/coordinategeodetic.h" #include "blackmisc/identifiable.h"