mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
refs #239, added a helper class for timer based pulls
* changed user componet to use new component * all new components (aircraft, ATC stations) will use this timer * it is implemented as "has a" timer based component, as inheriting from 2 QObjects would be problematic
This commit is contained in:
29
src/blackgui/timerbasedcomponent.cpp
Normal file
29
src/blackgui/timerbasedcomponent.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "timerbasedcomponent.h"
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
CTimerBasedComponent::CTimerBasedComponent(const char *slot, QObject *parent) :
|
||||||
|
QObject(parent), m_timer(nullptr)
|
||||||
|
{
|
||||||
|
this->m_timer = new QTimer(this);
|
||||||
|
this->connect(this->m_timer, SIGNAL(timeout()), parent, slot);
|
||||||
|
}
|
||||||
|
|
||||||
|
CTimerBasedComponent::~CTimerBasedComponent()
|
||||||
|
{
|
||||||
|
this->m_timer->stop();
|
||||||
|
this->disconnect(this->parent());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTimerBasedComponent::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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // guard
|
||||||
34
src/blackgui/timerbasedcomponent.h
Normal file
34
src/blackgui/timerbasedcomponent.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
#ifndef BLACKGUI_TIMERBASEDCOMPONENT_H
|
||||||
|
#define BLACKGUI_TIMERBASEDCOMPONENT_H
|
||||||
|
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
|
namespace BlackGui
|
||||||
|
{
|
||||||
|
|
||||||
|
//! Timer based componenet
|
||||||
|
class CTimerBasedComponent: public QObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Constructor
|
||||||
|
CTimerBasedComponent(const char *slot, QObject *parent);
|
||||||
|
|
||||||
|
//! Destructor
|
||||||
|
~CTimerBasedComponent();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
//! Update time, time < 100 stops updates
|
||||||
|
void setUpdateInterval(int milliSeconds);
|
||||||
|
|
||||||
|
//! Update time
|
||||||
|
void setUpdateIntervalSeconds(int seconds) { this->setUpdateInterval(1000 * seconds); }
|
||||||
|
|
||||||
|
//! Stop timer
|
||||||
|
void stopTimer() { this->setUpdateInterval(-1); }
|
||||||
|
|
||||||
|
private:
|
||||||
|
QTimer *m_timer;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
@@ -3,13 +3,11 @@
|
|||||||
|
|
||||||
namespace BlackGui
|
namespace BlackGui
|
||||||
{
|
{
|
||||||
|
|
||||||
CUserComponent::CUserComponent(QWidget *parent) :
|
CUserComponent::CUserComponent(QWidget *parent) :
|
||||||
QTabWidget(parent), CRuntimeBasedComponent(nullptr, false), ui(new Ui::CUserComponent), m_timer(nullptr)
|
QTabWidget(parent), CRuntimeBasedComponent(nullptr, false), ui(new Ui::CUserComponent), m_timerComponent(nullptr)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
this->m_timer = new QTimer(this);
|
this->m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
||||||
this->connect(this->m_timer, &QTimer::timeout, this, &CUserComponent::update);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserComponent::~CUserComponent()
|
CUserComponent::~CUserComponent()
|
||||||
@@ -29,15 +27,4 @@ namespace BlackGui
|
|||||||
this->ui->tvp_AllUsers->update(this->getIContextNetwork()->getUsers());
|
this->ui->tvp_AllUsers->update(this->getIContextNetwork()->getUsers());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CUserComponent::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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} // guard
|
} // guard
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define BLACKGUI_USERCOMPONENT_H
|
#define BLACKGUI_USERCOMPONENT_H
|
||||||
|
|
||||||
#include "blackgui/runtimebasedcomponent.h"
|
#include "blackgui/runtimebasedcomponent.h"
|
||||||
|
#include "blackgui/timerbasedcomponent.h"
|
||||||
#include "blackmisc/nwuserlist.h"
|
#include "blackmisc/nwuserlist.h"
|
||||||
|
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
@@ -24,19 +25,25 @@ namespace BlackGui
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
~CUserComponent();
|
~CUserComponent();
|
||||||
|
|
||||||
|
//! Timer for updating
|
||||||
|
CTimerBasedComponent *getTimerComponent() { return this->m_timerComponent; }
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//! Update users
|
//! Update users
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
//! Update time, time < 100 stops updates
|
//! \copydoc CTimerBasedComponent::setUpdateIntervalSeconds
|
||||||
void setUpdateInterval(int milliSeconds);
|
void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->setUpdateIntervalSeconds(seconds); }
|
||||||
|
|
||||||
//! Update time
|
//! \copydoc CTimerBasedComponent::setUpdateInterval
|
||||||
void setUpdateIntervalSeconds(int seconds) { this->setUpdateInterval(1000 * seconds); }
|
void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->setUpdateInterval(milliSeconds); }
|
||||||
|
|
||||||
|
//! \copydoc CTimerBasedComponent::stopTimer
|
||||||
|
void stopTimer() { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->stopTimer(); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::CUserComponent *ui;
|
Ui::CUserComponent *ui;
|
||||||
QTimer *m_timer;
|
CTimerBasedComponent *m_timerComponent;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user