CAtcListManager class

This commit is contained in:
Mathew Sutcliffe
2013-08-09 00:55:46 +01:00
parent eade49799b
commit e194773c5b
7 changed files with 364 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "atclistmgr.h"
#include "network.h"
BlackCore::CAtcListManager::CAtcListManager(const BlackCoreTest::EnableTesting&)
{
}
BlackCore::CAtcListManager::CAtcListManager()
{
INetwork *net = BlackMisc::IContext::getInstance().singleton<INetwork>();
connect(net, &INetwork::atcPositionUpdate, this, &CAtcListManager::update, Qt::QueuedConnection);
connect(net, &INetwork::atcDisconnected, this, &CAtcListManager::remove, Qt::QueuedConnection);
connect(net, &INetwork::connectionStatusDisconnected, this, &CAtcListManager::clear, Qt::QueuedConnection);
}
void BlackCore::CAtcListManager::update(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range)
{
m_list.insert(BlackMisc::CAtcListEntry(callsign, freq, pos, range));
emit listChanged(m_list);
}
void BlackCore::CAtcListManager::remove(const QString& callsign)
{
m_list.remove(callsign);
emit listChanged(m_list);
}
void BlackCore::CAtcListManager::clear()
{
m_list.clear();
emit listChanged(m_list);
}

View File

@@ -0,0 +1,95 @@
/* Copyright (C) 2013 VATSIM Community / authors
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*!
\file
*/
#ifndef BLACKCORE_ATCLISTMGR_H
#define BLACKCORE_ATCLISTMGR_H
#include "blackmisc/atclist.h"
#include <QObject>
namespace BlackCoreTest
{
class EnableTesting;
}
namespace BlackCore
{
/*!
* Abstract base class that manages and provides access to a list of available ATC stations.
*/
class IAtcListManager : public QObject
{
Q_OBJECT
Q_PROPERTY(BlackMisc::CAtcList list READ getList NOTIFY listChanged)
public:
BLACK_INTERFACE(BlackCore::IAtcListManager)
/*!
* Virtual destructor.
*/
virtual ~IAtcListManager() {}
/*!
* Immutable getter.
* \return
*/
virtual const BlackMisc::CAtcList &getList() const = 0;
signals:
/*!
* Emitted whenever there is a change in the ATC list.
* \param list The new list
*/
void listChanged(const BlackMisc::CAtcList &list);
};
/*!
* Concrete ATC list manager. Implementation of IAtcListManager.
*
* Has a dependency on INetwork. An INetwork must be available through the IContext singleton.
*/
class CAtcListManager : public IAtcListManager
{
Q_OBJECT
public:
/*!
* Constructor.
*/
CAtcListManager();
virtual const BlackMisc::CAtcList& getList() const { return m_list; }
public slots:
/*!
* CAtcListManager is responsible for connecting these slots.
* \{
*/
void update(const QString& callsign, const BlackMisc::PhysicalQuantities::CFrequency& freq,
const BlackMisc::Geo::CCoordinateGeodetic& pos, const BlackMisc::PhysicalQuantities::CLength& range);
void remove(const QString& callsign);
void clear();
/*! \} */
public:
/*!
* Constructor that does not connect INetwork signals to CAtcListManager slots.
* \warning Only used for testing purposes.
*/
explicit CAtcListManager(const BlackCoreTest::EnableTesting&);
private:
BlackMisc::CAtcList m_list;
};
}//namespace BlackCore
#endif //BLACKCORE_ATCLISTMGR_H