Allow to select COM frequencies from ATC view (context menu)

* added functions in component to select COM frequencies
* changed views to contain ObjectType in template
* function to obtain selected objects in view base class
This commit is contained in:
Klaus Basan
2014-12-22 21:17:13 +01:00
parent d0b5fc1249
commit b26fa651ed
25 changed files with 182 additions and 55 deletions

View File

@@ -20,7 +20,7 @@ namespace BlackCore
case CRuntimeConfig::Remote: case CRuntimeConfig::Remote:
return new BlackCore::CContextOwnAircraftProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent); return new BlackCore::CContextOwnAircraftProxy(BlackCore::CDBusServer::ServiceName, conn, mode, parent);
default: default:
qFatal("Always initialize an ownaircraft context"); qFatal("Always initialize an ownAircraft context");
return nullptr; return nullptr;
} }
} }

View File

@@ -105,6 +105,9 @@ namespace BlackCore
//! \todo remove "own", left over from past //! \todo remove "own", left over from past
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) = 0; virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) = 0;
//! Tune in a com frequency
virtual bool updateComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator) = 0;
//! Set current pilot //! Set current pilot
virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) = 0; virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) = 0;

View File

@@ -179,6 +179,31 @@ namespace BlackCore
return changed; return changed;
} }
/*
* COM frequency
*/
bool CContextOwnAircraft::updateComFrequency(const CFrequency &frequency, int comUnit, const QString &originator)
{
CComSystem::ComUnit unit = static_cast<CComSystem::ComUnit>(comUnit);
if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return false; }
if (!CComSystem::isValidComFrequency(frequency)) { return false; }
CComSystem com1 = this->m_ownAircraft.getCom1System();
CComSystem com2 = this->m_ownAircraft.getCom2System();
CTransponder xpdr = this->m_ownAircraft.getTransponder();
if (unit == CComSystem::Com1)
{
com1.setFrequencyActive(frequency);
}
else
{
com2.setFrequencyActive(frequency);
}
return updateOwnCockpit(com1, com2, xpdr, originator);
}
/*
* Pilot
*/
bool CContextOwnAircraft::updatePilot(const CUser &pilot, const QString &originator) bool CContextOwnAircraft::updatePilot(const CUser &pilot, const QString &originator)
{ {
if (this->m_ownAircraft.getPilot() == pilot) { return false; } if (this->m_ownAircraft.getPilot() == pilot) { return false; }

View File

@@ -55,6 +55,9 @@ namespace BlackCore
//! \copydoc IContextOwnAircraft::updateOwnCockpit //! \copydoc IContextOwnAircraft::updateOwnCockpit
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override; virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updateComFrequency
virtual bool updateComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updatePilot //! \copydoc IContextOwnAircraft::updatePilot
virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override; virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override;

View File

@@ -64,6 +64,11 @@ namespace BlackCore
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updateOwnCockpit"), com1, com2, transponder, originator); return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updateOwnCockpit"), com1, com2, transponder, originator);
} }
bool CContextOwnAircraftProxy::updateComFrequency(const PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator)
{
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updateComFrequency"), frequency, comUnit, originator);
}
bool CContextOwnAircraftProxy::updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) bool CContextOwnAircraftProxy::updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator)
{ {
return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updatePilot"), pilot, originator); return this->m_dBusInterface->callDBusRet<bool>(QLatin1Literal("updatePilot"), pilot, originator);

View File

@@ -61,6 +61,9 @@ namespace BlackCore
//! \copydoc IContextOwnAircraft::updateOwnCockpit //! \copydoc IContextOwnAircraft::updateOwnCockpit
virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override; virtual bool updateOwnCockpit(const BlackMisc::Aviation::CComSystem &com1, const BlackMisc::Aviation::CComSystem &com2, const BlackMisc::Aviation::CTransponder &transponder, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updateComFrequency
virtual bool updateComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, int comUnit, const QString &originator) override;
//! \copydoc IContextOwnAircraft::updatePilot //! \copydoc IContextOwnAircraft::updatePilot
virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override; virtual bool updatePilot(const BlackMisc::Network::CUser &pilot, const QString &originator) override;

View File

@@ -14,12 +14,14 @@
#include "blackmisc/avinformationmessage.h" #include "blackmisc/avinformationmessage.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackcore/context_network.h" #include "blackcore/context_network.h"
#include "blackcore/context_ownaircraft.h"
using namespace BlackGui; using namespace BlackGui;
using namespace BlackGui::Models; using namespace BlackGui::Models;
using namespace BlackGui::Views; using namespace BlackGui::Views;
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackMisc::PhysicalQuantities;
using namespace BlackCore; using namespace BlackCore;
namespace BlackGui namespace BlackGui
@@ -57,6 +59,7 @@ namespace BlackGui
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_requestOnlineStationsUpdate);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged); connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged);
connect(this->ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::ps_setComFrequency);
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked); connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged); connect(this->ui->tvp_AtcStationsBooked, &CAtcStationView::countChanged, this, &CAtcStationComponent::ps_countChanged);
@@ -241,6 +244,13 @@ namespace BlackGui
this->tabBar()->setTabText(ib, b); this->tabBar()->setTabText(ib, b);
} }
void CAtcStationComponent::ps_setComFrequency(const PhysicalQuantities::CFrequency &frequency, CComSystem::ComUnit unit)
{
if (unit != CComSystem::Com1 && unit != CComSystem::Com2) { return; }
if (!CComSystem::isValidComFrequency(frequency)) { return; }
this->getIContextOwnAircraft()->updateComFrequency(frequency, static_cast<int>(unit), originator());
}
void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index) void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index)
{ {
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset this->ui->te_AtcStationsOnlineInfo->setText(""); // reset

View File

@@ -15,9 +15,7 @@
#include "blackgui/components/enableforruntime.h" #include "blackgui/components/enableforruntime.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/components/updatetimer.h" #include "blackgui/components/updatetimer.h"
#include "blackmisc/avatcstation.h" #include "blackmisc/avatcstation.h"
#include <QTabWidget> #include <QTabWidget>
#include <QModelIndex> #include <QModelIndex>
#include <QScopedPointer> #include <QScopedPointer>
@@ -111,6 +109,9 @@ namespace BlackGui
//! Count has been changed //! Count has been changed
void ps_countChanged(int count); void ps_countChanged(int count);
//! Set COM frequency
void ps_setComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit);
private: private:
QScopedPointer<Ui::CAtcStationComponent> ui; QScopedPointer<Ui::CAtcStationComponent> ui;
CUpdateTimer *m_updateTimer = nullptr; CUpdateTimer *m_updateTimer = nullptr;
@@ -118,7 +119,16 @@ namespace BlackGui
QDateTime m_timestampOnlineStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed QDateTime m_timestampOnlineStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed
QDateTime m_timestampLastReadBookedStations = CUpdateTimer::epoch(); //!< stations read QDateTime m_timestampLastReadBookedStations = CUpdateTimer::epoch(); //!< stations read
QDateTime m_timestampBookedStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed QDateTime m_timestampBookedStationsChanged = CUpdateTimer::epoch(); //!< stations marked as changed
const QString &originator()
{
// string is generated once, the timestamp allows to use multiple
// components (as long as they are not generated at the same ms)
static const QString o = QString("ATCSTATIOCOMPONENT:").append(QString::number(QDateTime::currentMSecsSinceEpoch()));
return o;
}
}; };
} } // namespace
} } // namespace
#endif // guard #endif // guard

View File

@@ -42,7 +42,7 @@ namespace BlackGui
CAircraftComponent *CMainInfoAreaComponent::getAircraftComponent() CAircraftComponent *CMainInfoAreaComponent::getAircraftComponent()
{ {
return this->ui->comp_Aircrafts; return this->ui->comp_Aircraft;
} }
CUserComponent *CMainInfoAreaComponent::getUserComponent() CUserComponent *CMainInfoAreaComponent::getUserComponent()

View File

@@ -78,7 +78,7 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dwp_Aircrafts"> <widget class="BlackGui::CDockWidgetInfoArea" name="dwp_Aircraft">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>127</width> <width>127</width>
@@ -97,7 +97,7 @@
<attribute name="dockWidgetArea"> <attribute name="dockWidgetArea">
<number>4</number> <number>4</number>
</attribute> </attribute>
<widget class="QWidget" name="qw_AircraftsInner"> <widget class="QWidget" name="qw_AircraftInner">
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>0</width> <width>0</width>
@@ -121,7 +121,7 @@
<number>0</number> <number>0</number>
</property> </property>
<item> <item>
<widget class="BlackGui::Components::CAircraftComponent" name="comp_Aircrafts"> <widget class="BlackGui::Components::CAircraftComponent" name="comp_Aircraft">
<property name="sizePolicy"> <property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred"> <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch> <horstretch>0</horstretch>

View File

@@ -141,7 +141,7 @@ namespace BlackGui
*/ */
void CSettingsComponent::ps_networkServerSelected(QModelIndex index) void CSettingsComponent::ps_networkServerSelected(QModelIndex index)
{ {
const CServer clickedServer = this->ui->tvp_SettingsTnServers->at<CServer>(index); const CServer clickedServer = this->ui->tvp_SettingsTnServers->at(index);
this->ui->frp_ServerForm->setServer(clickedServer); this->ui->frp_ServerForm->setServer(clickedServer);
} }
@@ -198,7 +198,7 @@ namespace BlackGui
{ {
QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex(); QModelIndex i = this->ui->tvp_SettingsMiscHotkeys->currentIndex();
if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return; if (i.row() < 0 || i.row() >= this->ui->tvp_SettingsMiscHotkeys->rowCount()) return;
CSettingKeyboardHotkey hotkey = this->ui->tvp_SettingsMiscHotkeys->at<CSettingKeyboardHotkey>(i); CSettingKeyboardHotkey hotkey = this->ui->tvp_SettingsMiscHotkeys->at(i);
CSettingKeyboardHotkey defaultHotkey; CSettingKeyboardHotkey defaultHotkey;
defaultHotkey.setFunction(hotkey.getFunction()); defaultHotkey.setFunction(hotkey.getFunction());
this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultHotkey); this->ui->tvp_SettingsMiscHotkeys->derivedModel()->update(i, defaultHotkey);

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Aircrafts view //! Aircrafts view
class CAircraftModelView : public CViewBase<Models::CAircraftModelListModel, BlackMisc::Network::CAircraftModelList> class CAircraftModelView : public CViewBase<Models::CAircraftModelListModel, BlackMisc::Network::CAircraftModelList, BlackMisc::Network::CAircraftModel>
{ {
public: public:

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Aircrafts view //! Aircrafts view
class CAircraftView : public CViewBase<Models::CAircraftListModel, BlackMisc::Aviation::CAircraftList> class CAircraftView : public CViewBase<Models::CAircraftListModel, BlackMisc::Aviation::CAircraftList, BlackMisc::Aviation::CAircraft>
{ {
public: public:

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Airports view //! Airports view
class CAirportView : public CViewBase<Models::CAirportListModel, BlackMisc::Aviation::CAirportList> class CAirportView : public CViewBase<Models::CAirportListModel, BlackMisc::Aviation::CAirportList, BlackMisc::Aviation::CAirport>
{ {
public: public:

View File

@@ -8,10 +8,12 @@
*/ */
#include "atcstationview.h" #include "atcstationview.h"
#include "blackmisc/avatcstationlist.h"
#include "blackmisc/testing.h" #include "blackmisc/testing.h"
#include <QHeaderView> #include <QHeaderView>
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation;
using namespace BlackGui::Models; using namespace BlackGui::Models;
namespace BlackGui namespace BlackGui
@@ -59,7 +61,29 @@ namespace BlackGui
menu.addAction(CIcons::tableSheet16(), "Test: 3k ATC online stations", this, SLOT(ps_testRequest3kAtcOnlineDummies())); menu.addAction(CIcons::tableSheet16(), "Test: 3k ATC online stations", this, SLOT(ps_testRequest3kAtcOnlineDummies()));
menu.addSeparator(); menu.addSeparator();
} }
if (this->hasSelection())
{
menu.addAction(CIcons::appCockpit16(), "Tune in COM1", this, SLOT(ps_tuneInAtcCom1()));
menu.addAction(CIcons::appCockpit16(), "Tune in COM2", this, SLOT(ps_tuneInAtcCom2()));
menu.addSeparator();
}
CViewBase::customMenu(menu); CViewBase::customMenu(menu);
} }
}
} void CAtcStationView::ps_tuneInAtcCom1()
{
CAtcStationList l = this->selectedObjects();
if (l.isEmpty()) { return; }
emit this->requestComFrequency(l.front().getFrequency(), CComSystem::Com1);
}
void CAtcStationView::ps_tuneInAtcCom2()
{
CAtcStationList l = this->selectedObjects();
if (l.isEmpty()) { return; }
emit this->requestComFrequency(l.front().getFrequency(), CComSystem::Com2);
}
} // namespace
} // namespace

View File

@@ -21,7 +21,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! ATC stations view //! ATC stations view
class CAtcStationView : public CViewBase<Models::CAtcStationListModel, BlackMisc::Aviation::CAtcStationList> class CAtcStationView : public CViewBase<Models::CAtcStationListModel, BlackMisc::Aviation::CAtcStationList, BlackMisc::Aviation::CAtcStation>
{ {
Q_OBJECT Q_OBJECT
@@ -37,6 +37,9 @@ namespace BlackGui
//! Request some dummy ATC stations //! Request some dummy ATC stations
void testRequestDummyAtcOnlineStations(int number); void testRequestDummyAtcOnlineStations(int number);
//! Request COM frequency
void requestComFrequency(const BlackMisc::PhysicalQuantities::CFrequency &frequency, BlackMisc::Aviation::CComSystem::ComUnit unit);
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);
@@ -48,6 +51,8 @@ namespace BlackGui
private slots: private slots:
void ps_testRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); } void ps_testRequest1kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(1000); }
void ps_testRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); } void ps_testRequest3kAtcOnlineDummies() { emit this->testRequestDummyAtcOnlineStations(3000); }
void ps_tuneInAtcCom1();
void ps_tuneInAtcCom2();
}; };
} }
} }

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Client view //! Client view
class CClientView : public CViewBase<Models::CClientListModel, BlackMisc::Network::CClientList> class CClientView : public CViewBase<Models::CClientListModel, BlackMisc::Network::CClientList, BlackMisc::Network::CClient>
{ {
public: public:
//! Constructor //! Constructor

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Keyboard key view //! Keyboard key view
class CKeyboardKeyView : public CViewBase<Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList> class CKeyboardKeyView : public CViewBase<Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList, BlackMisc::Settings::CSettingKeyboardHotkey>
{ {
public: public:

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! User view //! User view
class CNameVariantPairView : public CViewBase<Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList> class CNameVariantPairView : public CViewBase<Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList, BlackMisc::CNameVariantPair>
{ {
public: public:

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Network servers //! Network servers
class CServerView : public CViewBase<Models::CServerListModel, BlackMisc::Network::CServerList> class CServerView : public CViewBase<Models::CServerListModel, BlackMisc::Network::CServerList, BlackMisc::Network::CServer>
{ {
public: public:

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! Status message view //! Status message view
class CStatusMessageView : public CViewBase<Models::CStatusMessageListModel, BlackMisc::CStatusMessageList> class CStatusMessageView : public CViewBase<Models::CStatusMessageListModel, BlackMisc::CStatusMessageList, BlackMisc::CStatusMessage>
{ {
public: public:

View File

@@ -20,7 +20,7 @@ namespace BlackGui
namespace Views namespace Views
{ {
//! User view //! User view
class CUserView : public CViewBase<Models::CUserListModel, BlackMisc::Network::CUserList> class CUserView : public CViewBase<Models::CUserListModel, BlackMisc::Network::CUserList, BlackMisc::Network::CUser>
{ {
public: public:

View File

@@ -46,7 +46,6 @@ namespace BlackGui
// scroll modes // scroll modes
this->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); this->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
this->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel); this->setHorizontalScrollMode(QAbstractItemView::ScrollPerPixel);
} }
void CViewBaseNonTemplate::customMenu(QMenu &menu) const void CViewBaseNonTemplate::customMenu(QMenu &menu) const
@@ -77,6 +76,16 @@ namespace BlackGui
return h; return h;
} }
bool CViewBaseNonTemplate::hasSelection() const
{
return this->selectionModel()->hasSelection();
}
QModelIndexList CViewBaseNonTemplate::selectedRows() const
{
return this->selectionModel()->selectedRows();
}
void CViewBaseNonTemplate::init() void CViewBaseNonTemplate::init()
{ {
int fh = qRound(1.5 * this->getHorizontalHeaderFontHeight()); int fh = qRound(1.5 * this->getHorizontalHeaderFontHeight());
@@ -152,7 +161,7 @@ namespace BlackGui
} }
} }
template <class ModelClass, class ContainerType> int CViewBase<ModelClass, ContainerType>::updateContainer(const ContainerType &container, bool sort, bool resize) template <class ModelClass, class ContainerType, class ObjectType> int CViewBase<ModelClass, ContainerType, ObjectType>::updateContainer(const ContainerType &container, bool sort, bool resize)
{ {
Q_ASSERT(this->m_model); Q_ASSERT(this->m_model);
int c = this->m_model->update(container, sort); int c = this->m_model->update(container, sort);
@@ -160,7 +169,7 @@ namespace BlackGui
return c; return c;
} }
template <class ModelClass, class ContainerType> BlackMisc::CWorker *CViewBase<ModelClass, ContainerType>::updateContainerAsync(const ContainerType &container, bool sort, bool resize) template <class ModelClass, class ContainerType, class ObjectType> BlackMisc::CWorker *CViewBase<ModelClass, ContainerType, ObjectType>::updateContainerAsync(const ContainerType &container, bool sort, bool resize)
{ {
ModelClass *model = this->derivedModel(); ModelClass *model = this->derivedModel();
auto sortColumn = model->getSortColumn(); auto sortColumn = model->getSortColumn();
@@ -175,7 +184,7 @@ namespace BlackGui
return worker; return worker;
} }
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::updateContainerMaybeAsync(const ContainerType &container, bool sort, bool resize) template <class ModelClass, class ContainerType, class ObjectType> void CViewBase<ModelClass, ContainerType, ObjectType>::updateContainerMaybeAsync(const ContainerType &container, bool sort, bool resize)
{ {
if (container.size() > asyncRowsCountThreshold && sort) if (container.size() > asyncRowsCountThreshold && sort)
{ {
@@ -188,25 +197,37 @@ namespace BlackGui
} }
} }
template <class ModelClass, class ContainerType> int CViewBase<ModelClass, ContainerType>::rowCount() const template <class ModelClass, class ContainerType, class ObjectType> ContainerType CViewBase<ModelClass, ContainerType, ObjectType>::selectedObjects() const
{
if (!this->hasSelection()) { return ContainerType(); }
ContainerType c;
QModelIndexList indexes = this->selectedRows();
for (QModelIndex &i : indexes)
{
c.push_back(this->at(i));
}
return c;
}
template <class ModelClass, class ContainerType, class ObjectType> int CViewBase<ModelClass, ContainerType, ObjectType>::rowCount() const
{ {
Q_ASSERT(this->m_model); Q_ASSERT(this->m_model);
return this->m_model->rowCount(); return this->m_model->rowCount();
} }
template <class ModelClass, class ContainerType> int CViewBase<ModelClass, ContainerType>::columnCount() const template <class ModelClass, class ContainerType, class ObjectType> int CViewBase<ModelClass, ContainerType, ObjectType>::columnCount() const
{ {
Q_ASSERT(this->m_model); Q_ASSERT(this->m_model);
return this->m_model->columnCount(QModelIndex()); return this->m_model->columnCount(QModelIndex());
} }
template <class ModelClass, class ContainerType> bool CViewBase<ModelClass, ContainerType>::isEmpty() const template <class ModelClass, class ContainerType, class ObjectType> bool CViewBase<ModelClass, ContainerType, ObjectType>::isEmpty() const
{ {
Q_ASSERT(this->m_model); Q_ASSERT(this->m_model);
return this->m_model->rowCount() < 1; return this->m_model->rowCount() < 1;
} }
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::setObjectName(const QString &name) template <class ModelClass, class ContainerType, class ObjectType> void CViewBase<ModelClass, ContainerType, ObjectType>::setObjectName(const QString &name)
{ {
// then name here is mainly set for debugging purposes so each model can be identified // then name here is mainly set for debugging purposes so each model can be identified
Q_ASSERT(m_model); Q_ASSERT(m_model);
@@ -215,7 +236,7 @@ namespace BlackGui
this->m_model->setObjectName(modelName); this->m_model->setObjectName(modelName);
} }
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::setSortIndicator() template <class ModelClass, class ContainerType, class ObjectType> void CViewBase<ModelClass, ContainerType, ObjectType>::setSortIndicator()
{ {
if (this->m_model->hasValidSortColumn()) if (this->m_model->hasValidSortColumn())
{ {
@@ -226,7 +247,7 @@ namespace BlackGui
} }
} }
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::standardInit(ModelClass *model) template <class ModelClass, class ContainerType, class ObjectType> void CViewBase<ModelClass, ContainerType, ObjectType>::standardInit(ModelClass *model)
{ {
Q_ASSERT(model || this->m_model); Q_ASSERT(model || this->m_model);
if (model) if (model)
@@ -239,7 +260,7 @@ namespace BlackGui
this->setSortIndicator(); this->setSortIndicator();
} }
template <class ModelClass, class ContainerType> void CViewBase<ModelClass, ContainerType>::performResizeToContents() template <class ModelClass, class ContainerType, class ObjectType> void CViewBase<ModelClass, ContainerType, ObjectType>::performResizeToContents()
{ {
// small set or large set? // small set or large set?
if (this->performResizing()) if (this->performResizing())
@@ -252,7 +273,7 @@ namespace BlackGui
} }
} }
template <class ModelClass, class ContainerType> int CViewBase<ModelClass, ContainerType>::performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize) template <class ModelClass, class ContainerType, class ObjectType> int CViewBase<ModelClass, ContainerType, ObjectType>::performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize)
{ {
ContainerType c; ContainerType c;
c.convertFromCVariant(variant); c.convertFromCVariant(variant);
@@ -261,16 +282,16 @@ namespace BlackGui
// see here for the reason of thess forward instantiations // see here for the reason of thess forward instantiations
// http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html // http://www.parashift.com/c++-faq/separate-template-class-defn-from-decl.html
template class CViewBase<BlackGui::Models::CStatusMessageListModel, BlackMisc::CStatusMessageList>; template class CViewBase<BlackGui::Models::CStatusMessageListModel, BlackMisc::CStatusMessageList, BlackMisc::CStatusMessage>;
template class CViewBase<BlackGui::Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList>; template class CViewBase<BlackGui::Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList, BlackMisc::CNameVariantPair>;
template class CViewBase<BlackGui::Models::CAtcStationListModel, BlackMisc::Aviation::CAtcStationList>; template class CViewBase<BlackGui::Models::CAtcStationListModel, BlackMisc::Aviation::CAtcStationList, BlackMisc::Aviation::CAtcStation>;
template class CViewBase<BlackGui::Models::CAircraftListModel, BlackMisc::Aviation::CAircraftList>; template class CViewBase<BlackGui::Models::CAircraftListModel, BlackMisc::Aviation::CAircraftList, BlackMisc::Aviation::CAircraft>;
template class CViewBase<BlackGui::Models::CAirportListModel, BlackMisc::Aviation::CAirportList>; template class CViewBase<BlackGui::Models::CAirportListModel, BlackMisc::Aviation::CAirportList, BlackMisc::Aviation::CAirport>;
template class CViewBase<BlackGui::Models::CServerListModel, BlackMisc::Network::CServerList>; template class CViewBase<BlackGui::Models::CServerListModel, BlackMisc::Network::CServerList, BlackMisc::Network::CServer>;
template class CViewBase<BlackGui::Models::CUserListModel, BlackMisc::Network::CUserList>; template class CViewBase<BlackGui::Models::CUserListModel, BlackMisc::Network::CUserList, BlackMisc::Network::CUser>;
template class CViewBase<BlackGui::Models::CClientListModel, BlackMisc::Network::CClientList>; template class CViewBase<BlackGui::Models::CClientListModel, BlackMisc::Network::CClientList, BlackMisc::Network::CClient>;
template class CViewBase<BlackGui::Models::CAircraftModelListModel, BlackMisc::Network::CAircraftModelList>; template class CViewBase<BlackGui::Models::CAircraftModelListModel, BlackMisc::Network::CAircraftModelList, BlackMisc::Network::CAircraftModel>;
template class CViewBase<BlackGui::Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList>; template class CViewBase<BlackGui::Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList, BlackMisc::Settings::CSettingKeyboardHotkey>;
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -20,6 +20,7 @@
#include <QMenu> #include <QMenu>
#include <QPoint> #include <QPoint>
#include <QFont> #include <QFont>
#include <QList>
namespace BlackGui namespace BlackGui
{ {
@@ -63,6 +64,12 @@ namespace BlackGui
//! Horizontal font height //! Horizontal font height
int getHorizontalHeaderFontHeight() const; int getHorizontalHeaderFontHeight() const;
//! Selection (selected rows)
bool hasSelection() const;
//! Selected rows if any
QModelIndexList selectedRows() const;
signals: signals:
//! Ask for new data //! Ask for new data
void requestUpdate(); void requestUpdate();
@@ -140,7 +147,7 @@ namespace BlackGui
}; };
//! Base class for views //! Base class for views
template <class ModelClass, class ContainerType> class CViewBase : public CViewBaseNonTemplate template <class ModelClass, class ContainerType, class ObjectType> class CViewBase : public CViewBaseNonTemplate
{ {
public: public:
@@ -166,7 +173,7 @@ namespace BlackGui
void updateContainerMaybeAsync(const ContainerType &container, bool sort = true, bool performResizing = true); void updateContainerMaybeAsync(const ContainerType &container, bool sort = true, bool performResizing = true);
//! Insert //! Insert
template<class ObjectType> void insert(const ObjectType &value, bool resize = true) void insert(const ObjectType &value, bool resize = true)
{ {
Q_ASSERT(this->m_model); Q_ASSERT(this->m_model);
this->m_model->insert(value); this->m_model->insert(value);
@@ -174,12 +181,15 @@ namespace BlackGui
} }
//! Value object at //! Value object at
template<class ObjectType> const ObjectType &at(const QModelIndex &index) const const ObjectType &at(const QModelIndex &index) const
{ {
Q_ASSERT(this->m_model); Q_ASSERT(this->m_model);
return this->m_model->at(index); return this->m_model->at(index);
} }
//! Selected objects
ContainerType selectedObjects() const;
//! Row count //! Row count
int rowCount() const; int rowCount() const;

View File

@@ -30,9 +30,7 @@ namespace BlackMisc
namespace Aviation namespace Aviation
{ {
/*! //! COM system (aka "radio")
* COM system (aka "radio")
*/
class CComSystem : public CValueObjectStdTuple<CComSystem, CModulator<CComSystem>> class CComSystem : public CValueObjectStdTuple<CComSystem, CModulator<CComSystem>>
{ {
public: public:
@@ -44,6 +42,14 @@ namespace BlackMisc
ChannelSpacing8_33KHz ChannelSpacing8_33KHz
}; };
//! COM unit
enum ComUnit
{
Com1,
Com2,
Com3
};
//! Default constructor //! Default constructor
CComSystem() : m_channelSpacing(ChannelSpacing25KHz) {} CComSystem() : m_channelSpacing(ChannelSpacing25KHz) {}
@@ -166,17 +172,19 @@ namespace BlackMisc
virtual bool validValues() const override; virtual bool validValues() const override;
private: private:
BLACK_ENABLE_TUPLE_CONVERSION(CComSystem) ChannelSpacing m_channelSpacing; //!< channel spacing
ChannelSpacing m_channelSpacing;
/*! /*!
* Give me channel spacing in KHz * Give me channel spacing in KHz
* \remarks Just a helper method, that is why no CFrequency is returned * \remarks Just a helper method, that is why no CFrequency is returned
*/ */
static double channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing); static double channelSpacingToFrequencyKHz(ChannelSpacing channelSpacing);
BLACK_ENABLE_TUPLE_CONVERSION(CComSystem)
}; };
} } // namespace
} } // namespace
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CComSystem, (o.m_channelSpacing)) BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Aviation::CComSystem, (o.m_channelSpacing))
Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem) Q_DECLARE_METATYPE(BlackMisc::Aviation::CComSystem)