refs #358, GUI for installed / matched models

* model / view / component classes
This commit is contained in:
Klaus Basan
2014-12-15 17:44:23 +01:00
parent 819c4cb0db
commit 4a94a125f2
12 changed files with 477 additions and 3 deletions

View File

@@ -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"

View File

@@ -467,7 +467,7 @@
<number>0</number>
</property>
<item>
<widget class="QTabWidget" name="comp_Mappings">
<widget class="BlackGui::Components::CMappingComponent" name="comp_Mappings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -633,6 +633,12 @@
<header>blackgui/components/textmessagecomponent.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>BlackGui::Components::CMappingComponent</class>
<extends>QTabWidget</extends>
<header>blackgui/components/mappingcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="../../blackmisc/blackmisc.qrc"/>

View File

@@ -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

View File

@@ -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 <QTabWidget>
#include <QScopedPointer>
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::CMappingComponent> ui;
//! Changed count
void ps_countChanged(int count);
};
} // namespace
} // namespace
#endif // guard

View File

@@ -0,0 +1,93 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CMappingComponent</class>
<widget class="QTabWidget" name="CMappingComponent">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>TabWidget</string>
</property>
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="tb_CurrentMappings">
<attribute name="title">
<string>Current mappings</string>
</attribute>
<layout class="QVBoxLayout" name="vl_CurrentMappings">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Views::CAircraftModelView" name="tvp_CurrentMappings">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tb_AircraftModels">
<attribute name="title">
<string>Aircraft models</string>
</attribute>
<layout class="QVBoxLayout" name="vl_AircraftModels">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Views::CAircraftModelView" name="tvp_AircraftModels">
<property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget>
</item>
</layout>
</widget>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Views::CAircraftModelView</class>
<extends>QTableView</extends>
<header>blackgui/views/aircraftmodelview.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@@ -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

View File

@@ -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 <QAbstractItemModel>
#include <QDBusConnection>
namespace BlackGui
{
namespace Models
{
//! Aircraft model list model
class CAircraftModelListModel : public CListModelBase<BlackMisc::Network::CAircraftModel, BlackMisc::Network::CAircraftModelList>
{
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

View File

@@ -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));

View File

@@ -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<BlackMisc::Network::CServer, BlackMisc::Network::CServerList>;
template class CListModelBase<BlackMisc::Network::CUser, BlackMisc::Network::CUserList>;
template class CListModelBase<BlackMisc::Network::CClient, BlackMisc::Network::CClientList>;
template class CListModelBase<BlackMisc::Network::CAircraftModel, BlackMisc::Network::CAircraftModelList>;
template class CListModelBase<BlackMisc::Network::CAircraftMapping, BlackMisc::Network::CAircraftMappingList>;
template class CListModelBase<BlackMisc::Settings::CSettingKeyboardHotkey, BlackMisc::Settings::CSettingKeyboardHotkeyList>;
} // namespace

View File

@@ -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 <QHeaderView>
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);
}
}
}

View File

@@ -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<Models::CAircraftModelListModel, BlackMisc::Network::CAircraftModelList>
{
public:
//! Constructor
explicit CAircraftModelView(QWidget *parent = nullptr);
//! Set display mode
void setAircraftModelMode(Models::CAircraftModelListModel::AircraftModelMode mode);
};
}
}
#endif // guard

View File

@@ -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<BlackGui::Models::CServerListModel, BlackMisc::Network::CServerList>;
template class CViewBase<BlackGui::Models::CUserListModel, BlackMisc::Network::CUserList>;
template class CViewBase<BlackGui::Models::CClientListModel, BlackMisc::Network::CClientList>;
template class CViewBase<BlackGui::Models::CAircraftModelListModel, BlackMisc::Network::CAircraftModelList>;
template class CViewBase<BlackGui::Models::CKeyboardKeyListModel, BlackMisc::Settings::CSettingKeyboardHotkeyList>;
} // namespace