From 1330bb851332fb86b61a0461eb23ac3349c31883 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 18 May 2015 01:57:35 +0200 Subject: [PATCH] refs #420, refs #421 improved view update for simualted aircraft * added update timer for simulated aircraft * in same step streamlined handling of CUpdateTimer --- src/blackgui/components/aircraftcomponent.cpp | 5 ++-- src/blackgui/components/aircraftcomponent.h | 8 +---- .../components/atcstationcomponent.cpp | 4 +-- src/blackgui/components/atcstationcomponent.h | 14 ++------- src/blackgui/components/mappingcomponent.cpp | 29 ++++++++++++++++--- src/blackgui/components/mappingcomponent.h | 8 ++++- .../components/simulatorcomponent.cpp | 4 +-- src/blackgui/components/simulatorcomponent.h | 2 +- src/blackgui/components/updatetimer.cpp | 6 ++-- src/blackgui/components/updatetimer.h | 18 ++++++------ src/blackgui/components/usercomponent.cpp | 5 ++-- src/blackgui/components/usercomponent.h | 8 +---- 12 files changed, 59 insertions(+), 52 deletions(-) diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index 25e7e0680..51a806f84 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -29,13 +29,13 @@ namespace BlackGui CAircraftComponent::CAircraftComponent(QWidget *parent) : QTabWidget(parent), - ui(new Ui::CAircraftComponent) + ui(new Ui::CAircraftComponent), + m_updateTimer(new CUpdateTimer("CAircraftComponent", &CAircraftComponent::update, this)) { ui->setupUi(this); this->tabBar()->setExpanding(false); this->ui->tvp_AirportsInRange->setResizeMode(CAirportView::ResizingOnce); - m_updateTimer = new CUpdateTimer(&CAircraftComponent::update, this); this->ui->tvp_AircraftInRange->setAircraftMode(CSimulatedAircraftListModel::InfoMode); this->ui->tvp_AircraftInRange->configureMenu(true, false, false); @@ -43,7 +43,6 @@ namespace BlackGui connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestTextMessageWidget, this, &CAircraftComponent::requestTextMessageWidget); connect(this->ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestHighlightInSimulator, this, &CAircraftComponent::ps_onMenuHighlightInSimulator); connect(this->ui->tvp_AirportsInRange, &CSimulatedAircraftView::rowCountChanged, this, &CAircraftComponent::ps_onRowCountChanged); - } CAircraftComponent::~CAircraftComponent() diff --git a/src/blackgui/components/aircraftcomponent.h b/src/blackgui/components/aircraftcomponent.h index 1ba22b3d5..2dfbee3ad 100644 --- a/src/blackgui/components/aircraftcomponent.h +++ b/src/blackgui/components/aircraftcomponent.h @@ -41,9 +41,6 @@ namespace BlackGui //! Destructor ~CAircraftComponent(); - //! Timer for updating - CUpdateTimer *getTimerComponent() { return this->m_updateTimer; } - //! Aircraft in range int countAircraft() const; @@ -61,9 +58,6 @@ namespace BlackGui //! \copydoc CTimerBasedComponent::setUpdateIntervalSeconds void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - //! \copydoc CTimerBasedComponent::setUpdateInterval - void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateInterval(milliSeconds); } - //! \copydoc CTimerBasedComponent::stopTimer void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } @@ -86,7 +80,7 @@ namespace BlackGui private: QScopedPointer ui; - CUpdateTimer *m_updateTimer = nullptr; + QScopedPointer m_updateTimer; }; } // ns } // ns diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index 2d50f3dca..7401c203f 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -29,11 +29,11 @@ namespace BlackGui { CAtcStationComponent::CAtcStationComponent(QWidget *parent) : QTabWidget(parent), - ui(new Ui::CAtcStationComponent) + ui(new Ui::CAtcStationComponent), + m_updateTimer(new CUpdateTimer("CAtcStationComponent", &CAtcStationComponent::update, this)) { ui->setupUi(this); this->tabBar()->setExpanding(false); - this->m_updateTimer = new CUpdateTimer(&CAtcStationComponent::update, this); // some icons this->ui->pb_AtcStationsAtisReload->setIcon(CIcons::atis()); diff --git a/src/blackgui/components/atcstationcomponent.h b/src/blackgui/components/atcstationcomponent.h index c3862a08d..cffc4747b 100644 --- a/src/blackgui/components/atcstationcomponent.h +++ b/src/blackgui/components/atcstationcomponent.h @@ -27,9 +27,7 @@ namespace BlackGui { namespace Components { - /*! - * ATC stations component - */ + //! ATC stations component class BLACKGUI_EXPORT CAtcStationComponent : public QTabWidget, public CEnableForDockWidgetInfoArea, @@ -42,10 +40,7 @@ namespace BlackGui explicit CAtcStationComponent(QWidget *parent = nullptr); //! Destructor - ~CAtcStationComponent(); - - //! Timer for updating - CUpdateTimer *getTimerComponent() { return this->m_updateTimer; } + virtual ~CAtcStationComponent(); //! Number of booked stations int countBookedStations() const; @@ -64,9 +59,6 @@ namespace BlackGui //! \copydoc CTimerBasedComponent::setUpdateIntervalSeconds void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - //! \copydoc CTimerBasedComponent::setUpdateInterval - void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateInterval(milliSeconds); } - //! \copydoc CTimerBasedComponent::stopTimer void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } @@ -122,7 +114,7 @@ namespace BlackGui const QString &originator(); QScopedPointer ui; - CUpdateTimer *m_updateTimer = nullptr; + 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 diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp index 2be6d9216..0022e5e6a 100644 --- a/src/blackgui/components/mappingcomponent.cpp +++ b/src/blackgui/components/mappingcomponent.cpp @@ -36,7 +36,9 @@ namespace BlackGui { CMappingComponent::CMappingComponent(QWidget *parent) : - QFrame(parent), ui(new Ui::CMappingComponent) + QFrame(parent), + ui(new Ui::CMappingComponent), + m_updateTimer(new CUpdateTimer("CMappingComponent", &CMappingComponent::ps_backgroundUpdate, this)) { ui->setupUi(this); this->ui->tvp_AircraftModels->setAircraftModelMode(CAircraftModelListModel::ModelOnly); @@ -63,9 +65,12 @@ namespace BlackGui this->m_currentMappingsViewDelegate = new CCheckBoxDelegate(":/diagona/icons/diagona/icons/tick.png", ":/diagona/icons/diagona/icons/cross.png", this); this->ui->tvp_SimulatedAircraft->setItemDelegateForColumn(0, this->m_currentMappingsViewDelegate); - //! Aircraft previews + // Aircraft previews connect(this->ui->cb_AircraftIconDisplayed, &QCheckBox::stateChanged, this, &CMappingComponent::ps_onModelPreviewChanged); this->ui->lbl_AircraftIconDisplayed->setText("Icon displayed here"); + + // Updates + this->m_updateTimer->setUpdateInterval(10 * 1000); } CMappingComponent::~CMappingComponent() @@ -381,11 +386,17 @@ namespace BlackGui return o; } - void CMappingComponent::updateSimulatedAircraftView() + void CMappingComponent::updateSimulatedAircraftView(bool forceUpdate) { Q_ASSERT_X(getIContextNetwork(), Q_FUNC_INFO, "missing network context"); Q_ASSERT_X(getIContextSimulator(), Q_FUNC_INFO, "missing simulator context"); - if (this->isVisibleWidget()) { return; } + if (!forceUpdate && !this->isVisibleWidget()) + { + m_missedSimulatedAircraftUpdate = true; + return; + } + + m_missedSimulatedAircraftUpdate = false; if (getIContextSimulator()->getSimulatorStatus() > 0) { const CSimulatedAircraftList aircraft(getIContextNetwork()->getAircraftInRange()); @@ -397,5 +408,15 @@ namespace BlackGui } } + void CMappingComponent::ps_backgroundUpdate() + { + if (this->m_missedSimulatedAircraftUpdate) + { + // update, normally when view is invisible, + // but we want an update from time to have some data when user switches to view + this->updateSimulatedAircraftView(true); + } + } + } // namespace } // namespace diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h index 444dbbd07..cbefe5888 100644 --- a/src/blackgui/components/mappingcomponent.h +++ b/src/blackgui/components/mappingcomponent.h @@ -15,6 +15,7 @@ #include "blackgui/blackguiexport.h" #include "blackgui/components/enableforruntime.h" #include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackgui/components/updatetimer.h" #include "blackgui/views/checkboxdelegate.h" #include "blackmisc/simulation/simulatedaircraft.h" #include "blackmisc/simulation/aircraftmodellist.h" @@ -121,10 +122,15 @@ namespace BlackGui private: static const QString &mappingtOriginator(); - void updateSimulatedAircraftView(); + void updateSimulatedAircraftView(bool forceUpdate = false); QScopedPointer ui; + QScopedPointer m_updateTimer; QCompleter *m_modelCompleter = nullptr; + bool m_missedSimulatedAircraftUpdate = true; BlackGui::Views::CCheckBoxDelegate *m_currentMappingsViewDelegate = nullptr; + + private slots: + void ps_backgroundUpdate(); }; } // namespace diff --git a/src/blackgui/components/simulatorcomponent.cpp b/src/blackgui/components/simulatorcomponent.cpp index f237110ae..ed304fce3 100644 --- a/src/blackgui/components/simulatorcomponent.cpp +++ b/src/blackgui/components/simulatorcomponent.cpp @@ -27,13 +27,13 @@ namespace BlackGui CSimulatorComponent::CSimulatorComponent(QWidget *parent) : QTabWidget(parent), CEnableForDockWidgetInfoArea(), - ui(new Ui::CSimulatorComponent) + ui(new Ui::CSimulatorComponent), + m_updateTimer(new CUpdateTimer("CSimulatorComponent", &CSimulatorComponent::update, this)) { ui->setupUi(this); this->ui->tvp_LiveData->setIconMode(true); this->ui->tvp_LiveData->setAutoResizeFrequency(10); // only resize every n-th time this->addOrUpdateByName("info", "no data yet", CIcons::StandardIconWarning16); - m_updateTimer = new CUpdateTimer(&CSimulatorComponent::update, this); } CSimulatorComponent::~CSimulatorComponent() diff --git a/src/blackgui/components/simulatorcomponent.h b/src/blackgui/components/simulatorcomponent.h index 00d9011a5..c077b015e 100644 --- a/src/blackgui/components/simulatorcomponent.h +++ b/src/blackgui/components/simulatorcomponent.h @@ -81,7 +81,7 @@ namespace BlackGui int getUpdateIntervalMs() const; QScopedPointer ui; - CUpdateTimer *m_updateTimer = nullptr; + QScopedPointer m_updateTimer; }; } } diff --git a/src/blackgui/components/updatetimer.cpp b/src/blackgui/components/updatetimer.cpp index c6a2f6cb2..9616f605b 100644 --- a/src/blackgui/components/updatetimer.cpp +++ b/src/blackgui/components/updatetimer.cpp @@ -13,18 +13,20 @@ namespace BlackGui { namespace Components { - void CUpdateTimer::initTimers() + 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(); - if (this->parent()) this->disconnect(this->parent()); } void CUpdateTimer::setUpdateInterval(int milliSeconds) diff --git a/src/blackgui/components/updatetimer.h b/src/blackgui/components/updatetimer.h index 1d2a5337f..1f947870e 100644 --- a/src/blackgui/components/updatetimer.h +++ b/src/blackgui/components/updatetimer.h @@ -28,10 +28,10 @@ namespace BlackGui public: //! Construct a timer which forwards messages to the given slot of parent. template - CUpdateTimer(F slot, P *parent) : QObject(parent) + CUpdateTimer(const QString &name, F slot, P *parent) : QObject(parent) { Q_ASSERT(parent); - this->initTimers(); + 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); @@ -40,7 +40,7 @@ namespace BlackGui } //! Destructor - ~CUpdateTimer(); + virtual ~CUpdateTimer(); //! Date/time of 1/1/1970, used to init timestamp values as "outdated" static const QDateTime &epoch() @@ -50,7 +50,7 @@ namespace BlackGui } public slots: - //! Update time, time < 100 stops updates + //! Update time, time < 100ms stops updates void setUpdateInterval(int milliSeconds); //! Update time @@ -66,10 +66,10 @@ namespace BlackGui void fireTimer(); private: - void initTimers(); //!< init timers - QTimer *m_timer = nullptr; //!< periodically updating - QTimer *m_timerSingleShot = nullptr; //!< single update + 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 17846a248..15883bf50 100644 --- a/src/blackgui/components/usercomponent.cpp +++ b/src/blackgui/components/usercomponent.cpp @@ -26,12 +26,11 @@ namespace BlackGui QTabWidget(parent), CEnableForDockWidgetInfoArea(), CEnableForRuntime(nullptr, false), - ui(new Ui::CUserComponent), m_updateTimer(nullptr) + ui(new Ui::CUserComponent), + m_updateTimer(new CUpdateTimer("CUserComponent", &CUserComponent::update, this)) { ui->setupUi(this); this->tabBar()->setExpanding(false); - this->m_updateTimer = new CUpdateTimer(&CUserComponent::update, this); - connect(this->ui->tvp_AllUsers, &CUserView::rowCountChanged, this, &CUserComponent::ps_onCountChanged); connect(this->ui->tvp_Clients, &CClientView::rowCountChanged, this, &CUserComponent::ps_onCountChanged); } diff --git a/src/blackgui/components/usercomponent.h b/src/blackgui/components/usercomponent.h index 86df10945..2d99ea67e 100644 --- a/src/blackgui/components/usercomponent.h +++ b/src/blackgui/components/usercomponent.h @@ -42,9 +42,6 @@ namespace BlackGui //! Destructor ~CUserComponent(); - //! Timer for updating - CUpdateTimer *getTimerComponent() { return this->m_updateTimer; } - //! Number of clients int countClients() const; @@ -58,9 +55,6 @@ namespace BlackGui //! \copydoc CTimerBasedComponent::setUpdateIntervalSeconds void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); } - //! \copydoc CTimerBasedComponent::setUpdateInterval - void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateInterval(milliSeconds); } - //! \copydoc CTimerBasedComponent::stopTimer void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); } @@ -77,7 +71,7 @@ namespace BlackGui private: QScopedPointer ui; - CUpdateTimer *m_updateTimer; + QScopedPointer m_updateTimer; }; } }