mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
* added update timer for simulated aircraft * in same step streamlined handling of CUpdateTimer
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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::CAircraftComponent> ui;
|
||||
CUpdateTimer *m_updateTimer = nullptr;
|
||||
QScopedPointer<CUpdateTimer> m_updateTimer;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -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());
|
||||
|
||||
@@ -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::CAtcStationComponent> ui;
|
||||
CUpdateTimer *m_updateTimer = nullptr;
|
||||
QScopedPointer<CUpdateTimer> 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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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::CMappingComponent> ui;
|
||||
QScopedPointer<CUpdateTimer> m_updateTimer;
|
||||
QCompleter *m_modelCompleter = nullptr;
|
||||
bool m_missedSimulatedAircraftUpdate = true;
|
||||
BlackGui::Views::CCheckBoxDelegate *m_currentMappingsViewDelegate = nullptr;
|
||||
|
||||
private slots:
|
||||
void ps_backgroundUpdate();
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -81,7 +81,7 @@ namespace BlackGui
|
||||
int getUpdateIntervalMs() const;
|
||||
|
||||
QScopedPointer<Ui::CSimulatorComponent> ui;
|
||||
CUpdateTimer *m_updateTimer = nullptr;
|
||||
QScopedPointer<CUpdateTimer> m_updateTimer;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -28,10 +28,10 @@ namespace BlackGui
|
||||
public:
|
||||
//! Construct a timer which forwards messages to the given slot of parent.
|
||||
template <typename F, typename P>
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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::CUserComponent> ui;
|
||||
CUpdateTimer *m_updateTimer;
|
||||
QScopedPointer<CUpdateTimer> m_updateTimer;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user