refs #322, included context menu and methods for injecting test data (ATC stations) in GUI

This commit is contained in:
Klaus Basan
2014-09-04 01:31:28 +02:00
parent 87e87013f9
commit e4545f23d2
14 changed files with 124 additions and 5 deletions

View File

@@ -10,6 +10,7 @@
#include "airspace_monitor.h" #include "airspace_monitor.h"
#include "blackcore/blackcorefreefunctions.h" #include "blackcore/blackcorefreefunctions.h"
#include "blackmisc/project.h" #include "blackmisc/project.h"
#include "blackmisc/testing.h"
#include "blackmisc/indexvariantmap.h" #include "blackmisc/indexvariantmap.h"
namespace BlackCore namespace BlackCore
@@ -218,6 +219,14 @@ namespace BlackCore
} }
} }
void CAirspaceMonitor::testCreateDummyOnlineAtcStations(int number)
{
this->m_atcStationsOnline.push_back(
BlackMisc::Aviation::CTesting::createAtcStations(number)
);
emit this->changedAtcStationsOnline();
}
void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname) void CAirspaceMonitor::ps_realNameReplyReceived(const CCallsign &callsign, const QString &realname)
{ {
if (realname.isEmpty()) return; if (realname.isEmpty()) return;

View File

@@ -72,6 +72,9 @@ namespace BlackCore
//! Request to update ATC stations' ATIS data from the network //! Request to update ATC stations' ATIS data from the network
void requestAtisUpdates(); void requestAtisUpdates();
//! Create dummy entries for performance tests
void testCreateDummyOnlineAtcStations(int number);
signals: signals:
//! Online ATC stations were changed //! Online ATC stations were changed
void changedAtcStationsOnline(); void changedAtcStationsOnline();

View File

@@ -183,6 +183,9 @@ namespace BlackCore
//! Request ATIS updates (for all stations) //! Request ATIS updates (for all stations)
virtual void requestAtisUpdates() = 0; virtual void requestAtisUpdates() = 0;
//! Create dummy ATC stations for performance tests etc.
virtual void testCreateDummyOnlineAtcStations(int number) = 0;
protected: protected:
//! Constructor //! Constructor
IContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {} IContextNetwork(CRuntimeConfig::ContextMode mode, CRuntime *runtime) : CContext(mode, runtime) {}

View File

@@ -381,6 +381,14 @@ namespace BlackCore
this->m_airspace->requestAtisUpdates(); this->m_airspace->requestAtisUpdates();
} }
/*
* Create dummy ATC stations
*/
void CContextNetwork::testCreateDummyOnlineAtcStations(int number)
{
this->m_airspace->testCreateDummyOnlineAtcStations(number);
}
/* /*
* Request METAR * Request METAR
*/ */

View File

@@ -128,6 +128,9 @@ namespace BlackCore
//! \copydoc IContextNetwork::requestAtisUpdates //! \copydoc IContextNetwork::requestAtisUpdates
virtual void requestAtisUpdates() override; virtual void requestAtisUpdates() override;
//! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations
virtual void testCreateDummyOnlineAtcStations(int number) override;
//! Gracefully shut down, e.g. for thread safety //! Gracefully shut down, e.g. for thread safety
void gracefulShutdown(); void gracefulShutdown();

View File

@@ -126,6 +126,11 @@ namespace BlackCore
this->m_dBusInterface->callDBus(QLatin1Literal("requestAtisUpdates")); this->m_dBusInterface->callDBus(QLatin1Literal("requestAtisUpdates"));
} }
void CContextNetworkProxy::testCreateDummyOnlineAtcStations(int number)
{
this->m_dBusInterface->callDBus(QLatin1Literal("testCreateDummyOnlineAtcStations"), number);
}
BlackMisc::CStatusMessageList CContextNetworkProxy::connectToNetwork(uint loginMode) BlackMisc::CStatusMessageList CContextNetworkProxy::connectToNetwork(uint loginMode)
{ {
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessageList>(QLatin1Literal("connectToNetwork"), loginMode); return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessageList>(QLatin1Literal("connectToNetwork"), loginMode);

View File

@@ -106,6 +106,10 @@ namespace BlackCore
//! \copydoc IContextNetwork::requestAtisUpdates //! \copydoc IContextNetwork::requestAtisUpdates
virtual void requestAtisUpdates() override; virtual void requestAtisUpdates() override;
//! \copydoc IContextNetwork::testCreateDummyOnlineAtcStations
virtual void testCreateDummyOnlineAtcStations(int number) override;
}; };
} }

View File

@@ -9,11 +9,13 @@
#include "blackmisc/avinformationmessage.h" #include "blackmisc/avinformationmessage.h"
#include "atcstationcomponent.h" #include "atcstationcomponent.h"
#include "../views/atcstationview.h"
#include "ui_atcstationcomponent.h" #include "ui_atcstationcomponent.h"
//! \file //! \file
using namespace BlackGui::Models; using namespace BlackGui::Models;
using namespace BlackGui::Views;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackCore; using namespace BlackCore;
@@ -36,10 +38,11 @@ namespace BlackGui
Q_ASSERT(connected); Q_ASSERT(connected);
connected = this->connect(this->ui->pb_AtcStationsLoadMetar, SIGNAL(clicked()), this, SLOT(getMetar())); connected = this->connect(this->ui->pb_AtcStationsLoadMetar, SIGNAL(clicked()), this, SLOT(getMetar()));
Q_ASSERT(connected); Q_ASSERT(connected);
this->connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::ps_atcStationsTabChanged); connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::ps_atcStationsTabChanged);
this->connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected); connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected);
this->connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis); connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis);
this->connect(this->ui->pb_ReloadAtcStationsBooked, &QPushButton::clicked, this, &CAtcStationComponent::ps_reloadAtcStationsBooked); connect(this->ui->pb_ReloadAtcStationsBooked, &QPushButton::clicked, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::ps_testCreateDummyOnlineAtcStations);
} }
CAtcStationComponent::~CAtcStationComponent() CAtcStationComponent::~CAtcStationComponent()
@@ -137,6 +140,14 @@ namespace BlackGui
} }
} }
void CAtcStationComponent::ps_testCreateDummyOnlineAtcStations(int number)
{
if (this->getIContextNetwork())
{
this->getIContextNetwork()->testCreateDummyOnlineAtcStations(number);
}
}
void CAtcStationComponent::changedAtcStationOnlineConnectionStatus(const CAtcStation &station, bool added) void CAtcStationComponent::changedAtcStationOnlineConnectionStatus(const CAtcStation &station, bool added)
{ {
this->ui->tvp_AtcStationsOnline->changedAtcStationConnectionStatus(station, added); this->ui->tvp_AtcStationsOnline->changedAtcStationConnectionStatus(station, added);

View File

@@ -88,6 +88,9 @@ namespace BlackGui
//! Connection status has been changed //! Connection status has been changed
void ps_connectionStatusChanged(uint from, uint to, const QString &message); void ps_connectionStatusChanged(uint from, uint to, const QString &message);
//! Request dummy ATC online stations
void ps_testCreateDummyOnlineAtcStations(int number);
private: private:
Ui::CAtcStationComponent *ui; Ui::CAtcStationComponent *ui;
CTimerBasedComponent *m_timerComponent; CTimerBasedComponent *m_timerComponent;

View File

@@ -8,6 +8,7 @@
*/ */
#include "atcstationview.h" #include "atcstationview.h"
#include "blackmisc/testing.h"
#include <QHeaderView> #include <QHeaderView>
using namespace BlackMisc; using namespace BlackMisc;
@@ -48,5 +49,15 @@ namespace BlackGui
this->resizeColumnsToContents(); this->resizeColumnsToContents();
this->resizeRowsToContents(); this->resizeRowsToContents();
} }
void CAtcStationView::customMenu(QMenu &menu) const
{
if (BlackMisc::CProject::isDebugBuild())
{
menu.addAction("Test: 1k ATC online stations", this, SLOT(ps_testRequest1kAtcOnlineDummies()));
menu.addAction("Test: 3k ATC online stations", this, SLOT(ps_testRequest3kAtcOnlineDummies()));
}
CViewBase::customMenu(menu);
}
} }
} }

View File

@@ -14,6 +14,7 @@
#include "viewbase.h" #include "viewbase.h"
#include "../models/atcstationlistmodel.h" #include "../models/atcstationlistmodel.h"
#include "blackmisc/project.h"
namespace BlackGui namespace BlackGui
{ {
@@ -22,6 +23,7 @@ namespace BlackGui
//! ATC stations view //! ATC stations view
class CAtcStationView : public CViewBase<Models::CAtcStationListModel> class CAtcStationView : public CViewBase<Models::CAtcStationListModel>
{ {
Q_OBJECT
public: public:
@@ -31,10 +33,21 @@ namespace BlackGui
//! Set station mode //! Set station mode
void setStationMode(Models::CAtcStationListModel::AtcStationMode stationMode); void setStationMode(Models::CAtcStationListModel::AtcStationMode stationMode);
signals:
//! Request some dummy ATC stations
void testRequestDummyAtcOnlineStations(int number);
public slots: public slots:
//! \copydoc CAtcStationListModel::changedAtcStationConnectionStatus //! \copydoc CAtcStationListModel::changedAtcStationConnectionStatus
void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added);
protected:
//! \copydoc CViewBase::customMenu
virtual void customMenu(QMenu &menu) const override;
private slots:
void ps_testRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); }
void ps_testRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); }
}; };
} }
} }

View File

@@ -13,6 +13,8 @@
//! \file //! \file
#include <QTableView> #include <QTableView>
#include <QMenu>
#include <QPoint>
namespace BlackGui namespace BlackGui
{ {
@@ -101,6 +103,8 @@ namespace BlackGui
{ {
this->setSortingEnabled(true); this->setSortingEnabled(true);
if (model) { this->setModel(this->m_model); } if (model) { this->setModel(this->m_model); }
this->setContextMenuPolicy(Qt::CustomContextMenu);
connect(this, &QWidget::customContextMenuRequested, this, &CViewBase::ps_customMenuRequested);
} }
//! Destructor //! Destructor
@@ -134,8 +138,24 @@ namespace BlackGui
this->horizontalHeader()->setStretchLastSection(true); this->horizontalHeader()->setStretchLastSection(true);
} }
ModelClass *m_model = nullptr; //!< corresponding model //! Method creating the menu
//! \remarks override this method to contribute to the menu
virtual void customMenu(QMenu &menu) const
{
Q_UNUSED(menu);
}
private slots:
//! Custom menu was requested
void ps_customMenuRequested(QPoint pos)
{
QMenu menu;
this->customMenu(menu);
if (menu.isEmpty()) { return; }
QPoint globalPos = this->mapToGlobal(pos);
menu.exec(globalPos);
}
}; };
} }
} }

View File

@@ -137,6 +137,26 @@ namespace BlackMisc
return getMajorMinor(1); return getMajorMinor(1);
} }
bool CProject::isDebugBuild()
{
#ifdef QT_DEBUG
return true;
#else
return false;
#endif
}
bool CProject::isReleaseBuild()
{
#ifdef QT_NO_DEBUG
return true;
#else
return false;
#endif
}
int CProject::getMajorMinor(int index) int CProject::getMajorMinor(int index)
{ {
QString v = version(); QString v = version();

View File

@@ -66,6 +66,12 @@ namespace BlackMisc
//! Version minor //! Version minor
static int versionMinor(); static int versionMinor();
//! Debug build?
static bool isDebugBuild();
//! Release build?
static bool isReleaseBuild();
private: private:
//! Constructor //! Constructor
CProject() {} CProject() {}