From 4a94a125f26300ca3f2e6062a92058459ef22a16 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 15 Dec 2014 17:44:23 +0100 Subject: [PATCH] refs #358, GUI for installed / matched models * model / view / component classes --- .../components/allmaininfoareacomponents.h | 1 + .../components/maininfoareacomponent.ui | 8 +- src/blackgui/components/mappingcomponent.cpp | 97 +++++++++++++++++++ src/blackgui/components/mappingcomponent.h | 72 ++++++++++++++ src/blackgui/components/mappingcomponent.ui | 93 ++++++++++++++++++ .../models/aircraftmodellistmodel.cpp | 77 +++++++++++++++ src/blackgui/models/aircraftmodellistmodel.h | 52 ++++++++++ src/blackgui/models/clientlistmodel.cpp | 2 +- src/blackgui/models/listmodelbase.cpp | 6 +- src/blackgui/views/aircraftmodelview.cpp | 32 ++++++ src/blackgui/views/aircraftmodelview.h | 37 +++++++ src/blackgui/views/viewbase.cpp | 3 + 12 files changed, 477 insertions(+), 3 deletions(-) create mode 100644 src/blackgui/components/mappingcomponent.cpp create mode 100644 src/blackgui/components/mappingcomponent.h create mode 100644 src/blackgui/components/mappingcomponent.ui create mode 100644 src/blackgui/models/aircraftmodellistmodel.cpp create mode 100644 src/blackgui/models/aircraftmodellistmodel.h create mode 100644 src/blackgui/views/aircraftmodelview.cpp create mode 100644 src/blackgui/views/aircraftmodelview.h diff --git a/src/blackgui/components/allmaininfoareacomponents.h b/src/blackgui/components/allmaininfoareacomponents.h index 5ddcb7b9c..762e37556 100644 --- a/src/blackgui/components/allmaininfoareacomponents.h +++ b/src/blackgui/components/allmaininfoareacomponents.h @@ -14,6 +14,7 @@ #include "aircraftcomponent.h" #include "cockpitcomponent.h" #include "usercomponent.h" +#include "mappingcomponent.h" #include "textmessagecomponent.h" #include "simulatorcomponent.h" #include "flightplancomponent.h" diff --git a/src/blackgui/components/maininfoareacomponent.ui b/src/blackgui/components/maininfoareacomponent.ui index f5c2c5084..c177f4569 100644 --- a/src/blackgui/components/maininfoareacomponent.ui +++ b/src/blackgui/components/maininfoareacomponent.ui @@ -467,7 +467,7 @@ 0 - + 0 @@ -633,6 +633,12 @@
blackgui/components/textmessagecomponent.h
1 + + BlackGui::Components::CMappingComponent + QTabWidget +
blackgui/components/mappingcomponent.h
+ 1 +
diff --git a/src/blackgui/components/mappingcomponent.cpp b/src/blackgui/components/mappingcomponent.cpp new file mode 100644 index 000000000..391d7fbf9 --- /dev/null +++ b/src/blackgui/components/mappingcomponent.cpp @@ -0,0 +1,97 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "blackcore/context_simulator.h" +#include "../views/aircraftmodelview.h" +#include "../models/aircraftmodellistmodel.h" +#include "../guiutility.h" +#include "mappingcomponent.h" +#include "ui_mappingcomponent.h" + +using namespace BlackCore; +using namespace BlackGui; +using namespace BlackGui::Views; +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Components + { + + CMappingComponent::CMappingComponent(QWidget *parent) : + QTabWidget(parent), ui(new Ui::CMappingComponent) + { + ui->setupUi(this); + this->ui->tvp_CurrentMappings->setAircraftModelMode(CAircraftModelListModel::MappedModel); + this->ui->tvp_AircraftModels->setAircraftModelMode(CAircraftModelListModel::ModelOnly); + this->ui->tvp_CurrentMappings->setResizeMode(CAircraftModelView::ResizingOnce); + this->ui->tvp_AircraftModels->setResizeMode(CAircraftModelView::ResizingOff); + + connect(this->ui->tvp_AircraftModels, &CAircraftModelView::requestUpdate, this, &CMappingComponent::ps_aircraftModelsLoaded); + connect(this->ui->tvp_CurrentMappings, &CAircraftModelView::requestUpdate, this, &CMappingComponent::ps_onMappingsChanged); + connect(this->ui->tvp_AircraftModels, &CAircraftModelView::countChanged, this, &CMappingComponent::ps_countChanged); + connect(this->ui->tvp_CurrentMappings, &CAircraftModelView::countChanged, this, &CMappingComponent::ps_countChanged); + } + + CMappingComponent::~CMappingComponent() + { } + + int CMappingComponent::countCurrentMappings() const + { + Q_ASSERT(this->ui->tvp_CurrentMappings); + return this->ui->tvp_CurrentMappings->rowCount(); + } + + int CMappingComponent::countAircraftModels() const + { + Q_ASSERT(this->ui->tvp_AircraftModels); + return this->ui->tvp_AircraftModels->rowCount(); + } + + void CMappingComponent::runtimeHasBeenSet() + { + Q_ASSERT(getIContextSimulator()); + connect(getIContextSimulator(), &IContextSimulator::installedAircraftModelsChanged, this, &CMappingComponent::ps_aircraftModelsLoaded); + connect(getIContextSimulator(), &IContextSimulator::modelMatchingCompleted, this, &CMappingComponent::ps_modelMatched); + } + + void CMappingComponent::ps_aircraftModelsLoaded() + { + Q_ASSERT(getIContextSimulator()); + this->ui->tvp_AircraftModels->updateContainer(getIContextSimulator()->getInstalledModels()); + } + + void CMappingComponent::ps_modelMatched(const BlackMisc::Network::CAircraftModel &model) + { + Q_UNUSED(model); + ps_onMappingsChanged(); + } + + void CMappingComponent::ps_onMappingsChanged() + { + Q_ASSERT(getIContextSimulator()); + this->ui->tvp_CurrentMappings->updateContainer(getIContextSimulator()->getCurrentlyMatchedModels()); + } + + void CMappingComponent::ps_countChanged(int count) + { + Q_UNUSED(count); + int am = this->indexOf(this->ui->tb_AircraftModels); + int cm = this->indexOf(this->ui->tb_CurrentMappings); + QString a = this->tabBar()->tabText(am); + QString c = this->tabBar()->tabText(cm); + a = CGuiUtility::replaceTabCountValue(a, this->countAircraftModels()); + c = CGuiUtility::replaceTabCountValue(c, this->countCurrentMappings()); + this->tabBar()->setTabText(am, a); + this->tabBar()->setTabText(cm, c); + } + + } // namespace +} // namespace + diff --git a/src/blackgui/components/mappingcomponent.h b/src/blackgui/components/mappingcomponent.h new file mode 100644 index 000000000..11a9df2ea --- /dev/null +++ b/src/blackgui/components/mappingcomponent.h @@ -0,0 +1,72 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_MAPPINGCOMPONENT_H +#define BLACKGUI_MAPPINGCOMPONENT_H + +#include "blackgui/components/enableforruntime.h" +#include "blackgui/components/enablefordockwidgetinfoarea.h" +#include "blackmisc/nwaircraftmodel.h" +#include +#include + +namespace Ui { class CMappingComponent; } + +namespace BlackGui +{ + namespace Components + { + //! Mappings, models etc. + class CMappingComponent : + public QTabWidget, + public CEnableForDockWidgetInfoArea, + public CEnableForRuntime + { + Q_OBJECT + + public: + //! Constructor + explicit CMappingComponent(QWidget *parent = nullptr); + + //! Destructor + ~CMappingComponent(); + + //! Number of current mappings + int countCurrentMappings() const; + + //! Numer of models + int countAircraftModels() const; + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + void runtimeHasBeenSet() override; + + private slots: + //! Aircraft models available + void ps_aircraftModelsLoaded(); + + //! Mappings changed + void ps_onMappingsChanged(); + + //! Model matched + void ps_modelMatched(const BlackMisc::Network::CAircraftModel &model); + + private: + QScopedPointer ui; + + //! Changed count + void ps_countChanged(int count); + }; + + } // namespace +} // namespace + +#endif // guard diff --git a/src/blackgui/components/mappingcomponent.ui b/src/blackgui/components/mappingcomponent.ui new file mode 100644 index 000000000..d4e8e2945 --- /dev/null +++ b/src/blackgui/components/mappingcomponent.ui @@ -0,0 +1,93 @@ + + + CMappingComponent + + + + 0 + 0 + 400 + 300 + + + + TabWidget + + + 0 + + + + Current mappings + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + Aircraft models + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + QAbstractItemView::SingleSelection + + + QAbstractItemView::SelectRows + + + false + + + + + + + + + BlackGui::Views::CAircraftModelView + QTableView +
blackgui/views/aircraftmodelview.h
+
+
+ + +
diff --git a/src/blackgui/models/aircraftmodellistmodel.cpp b/src/blackgui/models/aircraftmodellistmodel.cpp new file mode 100644 index 000000000..afd4ee002 --- /dev/null +++ b/src/blackgui/models/aircraftmodellistmodel.cpp @@ -0,0 +1,77 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "aircraftmodellistmodel.h" +#include "blackmisc/avaircrafticao.h" +#include "blackmisc/icons.h" +#include "blackmisc/blackmiscfreefunctions.h" + +using namespace BlackMisc; +using namespace BlackMisc::Aviation; +using namespace BlackMisc::Network; + +namespace BlackGui +{ + namespace Models + { + /* + * Constructor + */ + CAircraftModelListModel::CAircraftModelListModel(AircraftModelMode mode, QObject *parent) : CListModelBase("CAircraftModelListModel", parent) + { + this->setAircraftModelMode(mode); + + // force strings for translation in resource files + (void)QT_TRANSLATE_NOOP("CAircraftModelListModel", "callsign"); + (void)QT_TRANSLATE_NOOP("CAircraftModelListModel", "combined type"); + (void)QT_TRANSLATE_NOOP("CAircraftModelListModel", "model"); + } + + void CAircraftModelListModel::setAircraftModelMode(CAircraftModelListModel::AircraftModelMode mode) + { + if (this->m_mode == mode) return; + this->m_mode = mode; + this->m_columns.clear(); + switch (mode) + { + case NotSet: + case ModelOnly: + this->m_columns.addColumn(CColumn::standardString("model", { CAircraftModel::IndexModelString})); + this->m_columns.addColumn(CColumn::standardString("description", { CAircraftModel::IndexDescription})); + this->m_columns.addColumn(CColumn::standardString("filename", { CAircraftModel::IndexFileName})); + + // default sort order + this->setSortColumnByPropertyIndex(CAircraftModel::IndexModelString); + this->m_sortOrder = Qt::AscendingOrder; + break; + + case MappedModel: + this->m_columns.addColumn(CColumn::standardValueObject("call", "callsign", CAircraftModel::IndexCallsign)); + this->m_columns.addColumn(CColumn::standardString("model", { CAircraftModel::IndexModelString})); + this->m_columns.addColumn(CColumn::standardString("ac", "aircraft ICAO", { CAircraftModel::IndexIcao, CAircraftIcao::IndexAircraftDesignator})); + this->m_columns.addColumn(CColumn::standardString("al", "airline ICAO", { CAircraftModel::IndexIcao, CAircraftIcao::IndexAirlineDesignator})); + // this->m_columns.addColumn(CColumn::standardString("ct", "combined type", { CAircraftModel::IndexIcao, CAircraftIcao::IndexCombinedAircraftType})); + this->m_columns.addColumn(CColumn("q.?", "queried", CAircraftModel::IndexHasQueriedModelString, + new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "queried", "not queried"))); + this->m_columns.addColumn(CColumn::standardString("description", { CAircraftModel::IndexDescription})); + this->m_columns.addColumn(CColumn::standardString("filename", { CAircraftModel::IndexFileName})); + + // default sort order + this->setSortColumnByPropertyIndex(CAircraftModel::IndexModelString); + this->m_sortOrder = Qt::AscendingOrder; + break; + + default: + qFatal("Wrong mode"); + break; + } + } + + } // namespace +} // namespace diff --git a/src/blackgui/models/aircraftmodellistmodel.h b/src/blackgui/models/aircraftmodellistmodel.h new file mode 100644 index 000000000..76f854ca7 --- /dev/null +++ b/src/blackgui/models/aircraftmodellistmodel.h @@ -0,0 +1,52 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_AIRCRAFTMODELLISTMODEL_H +#define BLACKGUI_AIRCRAFTMODELLISTMODEL_H + +#include "blackmisc/nwaircraftmodellist.h" +#include "blackgui/models/listmodelbase.h" +#include +#include + +namespace BlackGui +{ + namespace Models + { + + //! Aircraft model list model + class CAircraftModelListModel : public CListModelBase + { + + public: + //! How to display + enum AircraftModelMode { + NotSet, + ModelOnly, + MappedModel + }; + + //! Constructor + explicit CAircraftModelListModel(AircraftModelMode mode, QObject *parent = nullptr); + + //! Destructor + virtual ~CAircraftModelListModel() {} + + //! Mode + void setAircraftModelMode(CAircraftModelListModel::AircraftModelMode stationMode); + + private: + AircraftModelMode m_mode = NotSet; //!< current mode + + }; + } +} +#endif // guard diff --git a/src/blackgui/models/clientlistmodel.cpp b/src/blackgui/models/clientlistmodel.cpp index fa67e81d7..b9d56eec5 100644 --- a/src/blackgui/models/clientlistmodel.cpp +++ b/src/blackgui/models/clientlistmodel.cpp @@ -32,7 +32,7 @@ namespace BlackGui this->m_columns.addColumn(CColumn("capabilities", CClient::IndexVoiceCapabilitiesIcon)); this->m_columns.addColumn(CColumn::standardString("capabilities", CClient::IndexCapabilitiesString)); this->m_columns.addColumn(CColumn::standardString("model", {CClient::IndexModel, CAircraftModel::IndexModelString})); - this->m_columns.addColumn(CColumn("q.?", "queried", {CClient::IndexModel, CAircraftModel::IndexIsQueriedModelString}, + this->m_columns.addColumn(CColumn("q.?", "queried", {CClient::IndexModel, CAircraftModel::IndexHasQueriedModelString}, new CBoolIconFormatter(CIcons::StandardIconTick16, CIcons::StandardIconCross16, "queried", "not queried"))); this->m_columns.addColumn(CColumn::standardString("server", CClient::IndexServer)); diff --git a/src/blackgui/models/listmodelbase.cpp b/src/blackgui/models/listmodelbase.cpp index eca3a60d5..9b96df79a 100644 --- a/src/blackgui/models/listmodelbase.cpp +++ b/src/blackgui/models/listmodelbase.cpp @@ -16,6 +16,8 @@ #include "blackmisc/nwserverlist.h" #include "blackmisc/nwuserlist.h" #include "blackmisc/nwclientlist.h" +#include "blackmisc/nwaircraftmodellist.h" +#include "blackmisc/nwaircraftmappinglist.h" #include "blackmisc/setkeyboardhotkeylist.h" #include "blackmisc/blackmiscfreefunctions.h" @@ -202,7 +204,7 @@ namespace BlackGui { if (index.row() < 0 || index.row() >= this->m_container.size()) { - static const ObjectType def{}; // default object + static const ObjectType def {}; // default object return def; } else @@ -326,6 +328,8 @@ namespace BlackGui template class CListModelBase; template class CListModelBase; template class CListModelBase; + template class CListModelBase; + template class CListModelBase; template class CListModelBase; } // namespace diff --git a/src/blackgui/views/aircraftmodelview.cpp b/src/blackgui/views/aircraftmodelview.cpp new file mode 100644 index 000000000..2eb2b7803 --- /dev/null +++ b/src/blackgui/views/aircraftmodelview.cpp @@ -0,0 +1,32 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "aircraftmodelview.h" +#include + +using namespace BlackMisc; +using namespace BlackGui::Models; + +namespace BlackGui +{ + namespace Views + { + CAircraftModelView::CAircraftModelView(QWidget *parent) : CViewBase(parent) + { + this->m_withMenuItemClear = true; + this->m_withMenuItemRefresh = true; + this->standardInit(new CAircraftModelListModel(CAircraftModelListModel::ModelOnly, this)); + } + + void CAircraftModelView::setAircraftModelMode(CAircraftModelListModel::AircraftModelMode mode) + { + this->m_model->setAircraftModelMode(mode); + } + } +} diff --git a/src/blackgui/views/aircraftmodelview.h b/src/blackgui/views/aircraftmodelview.h new file mode 100644 index 000000000..67610beec --- /dev/null +++ b/src/blackgui/views/aircraftmodelview.h @@ -0,0 +1,37 @@ +/* Copyright (C) 2013 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKGUI_AIRCRAFTMODELVIEW_H +#define BLACKGUI_AIRCRAFTMODELVIEW_H + +#include "viewbase.h" +#include "../models/aircraftmodellistmodel.h" + +namespace BlackGui +{ + namespace Views + { + //! Aircrafts view + class CAircraftModelView : public CViewBase + { + + public: + + //! Constructor + explicit CAircraftModelView(QWidget *parent = nullptr); + + //! Set display mode + void setAircraftModelMode(Models::CAircraftModelListModel::AircraftModelMode mode); + + }; + } +} +#endif // guard diff --git a/src/blackgui/views/viewbase.cpp b/src/blackgui/views/viewbase.cpp index 8519a8203..3d566c841 100644 --- a/src/blackgui/views/viewbase.cpp +++ b/src/blackgui/views/viewbase.cpp @@ -12,6 +12,8 @@ #include "../models/namevariantpairlistmodel.h" #include "../models/atcstationlistmodel.h" #include "../models/aircraftlistmodel.h" +#include "../models/aircraftmodellistmodel.h" +#include "../models/airportlistmodel.h" #include "../models/airportlistmodel.h" #include "../models/serverlistmodel.h" #include "../models/userlistmodel.h" @@ -267,6 +269,7 @@ namespace BlackGui template class CViewBase; template class CViewBase; template class CViewBase; + template class CViewBase; template class CViewBase; } // namespace