refs #525, stash view

* allow to stash and unstash models from vPilot and own models
* removed stash main area and moved it into mapping component
* own stash component
* use the new functions for modles/views from the prevuous steps
This commit is contained in:
Klaus Basan
2015-12-02 01:31:54 +01:00
parent 8e852b19ae
commit f7cb21c78c
9 changed files with 450 additions and 153 deletions

View File

@@ -53,17 +53,11 @@ namespace BlackGui
return this->ui->comp_DataInfoArea; return this->ui->comp_DataInfoArea;
} }
CDbStashComponent *CDataMainInfoAreaComponent::getStashComponent() const
{
return this->ui->comp_Stash;
}
void CDataMainInfoAreaComponent::setProvider(BlackMisc::Network::IWebDataServicesProvider *provider) void CDataMainInfoAreaComponent::setProvider(BlackMisc::Network::IWebDataServicesProvider *provider)
{ {
Q_ASSERT_X(provider, Q_FUNC_INFO, "Missing provider"); Q_ASSERT_X(provider, Q_FUNC_INFO, "Missing provider");
this->ui->comp_DataInfoArea->setProvider(provider); this->ui->comp_DataInfoArea->setProvider(provider);
this->ui->comp_Mapping->setProvider(provider); this->ui->comp_Mapping->setProvider(provider);
this->ui->comp_Stash->setProvider(provider);
} }
void CDataMainInfoAreaComponent::displayLog() void CDataMainInfoAreaComponent::displayLog()
@@ -86,7 +80,6 @@ namespace BlackGui
case InfoAreaData: case InfoAreaData:
case InfoAreaMapping: case InfoAreaMapping:
case InfoAreaSettings: case InfoAreaSettings:
case InfoAreaStash:
case InfoAreaLog: case InfoAreaLog:
default: default:
return QSize(800, 600); return QSize(800, 600);
@@ -106,8 +99,6 @@ namespace BlackGui
return CIcons::appSettings16(); return CIcons::appSettings16();
case InfoAreaLog: case InfoAreaLog:
return CIcons::appLog16(); return CIcons::appLog16();
case InfoAreaStash:
return CIcons::appDbStash16();
default: default:
return CIcons::empty(); return CIcons::empty();
} }

View File

@@ -26,7 +26,6 @@ namespace BlackGui
{ {
class CLogComponent; class CLogComponent;
class CDbMappingComponent; class CDbMappingComponent;
class CDbStashComponent;
class CDataInfoAreaComponent; class CDataInfoAreaComponent;
/** /**
@@ -45,9 +44,8 @@ namespace BlackGui
// index must match tab index! // index must match tab index!
InfoAreaData = 0, InfoAreaData = 0,
InfoAreaMapping = 1, InfoAreaMapping = 1,
InfoAreaStash = 2, InfoAreaSettings = 2,
InfoAreaSettings = 3, InfoAreaLog = 3,
InfoAreaLog = 4,
InfoAreaNone = -1 InfoAreaNone = -1
}; };
@@ -66,9 +64,6 @@ namespace BlackGui
//! Mapping component //! Mapping component
CDataInfoAreaComponent *getDataInfoAreaComponent() const; CDataInfoAreaComponent *getDataInfoAreaComponent() const;
//! Stash component
CDbStashComponent *getStashComponent() const;
//! Set data reader //! Set data reader
virtual void setProvider(BlackMisc::Network::IWebDataServicesProvider *provider) override; virtual void setProvider(BlackMisc::Network::IWebDataServicesProvider *provider) override;

View File

@@ -172,73 +172,6 @@
</layout> </layout>
</widget> </widget>
</widget> </widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dwp_Stash">
<property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set>
</property>
<property name="windowTitle">
<string>Stash</string>
</property>
<attribute name="dockWidgetArea">
<number>4</number>
</attribute>
<widget class="QWidget" name="qw_StashOuter">
<layout class="QVBoxLayout" name="vl_StashOuter">
<property name="spacing">
<number>0</number>
</property>
<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="QFrame" name="fr_StashInner">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="vl_StashInner">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Components::CDbStashComponent" name="comp_Stash">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>
<widget class="BlackGui::CDockWidgetInfoArea" name="dwp_Settings"> <widget class="BlackGui::CDockWidgetInfoArea" name="dwp_Settings">
<property name="allowedAreas"> <property name="allowedAreas">
<set>Qt::TopDockWidgetArea</set> <set>Qt::TopDockWidgetArea</set>
@@ -405,12 +338,6 @@
<header>blackgui/components/dbmappingcomponent.h</header> <header>blackgui/components/dbmappingcomponent.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>BlackGui::Components::CDbStashComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/dbstashcomponent.h</header>
<container>1</container>
</customwidget>
<customwidget> <customwidget>
<class>BlackGui::Components::CDataSettingsComponent</class> <class>BlackGui::Components::CDataSettingsComponent</class>
<extends>QFrame</extends> <extends>QFrame</extends>

View File

@@ -9,10 +9,11 @@
#include "dbmappingcomponent.h" #include "dbmappingcomponent.h"
#include "ui_dbmappingcomponent.h" #include "ui_dbmappingcomponent.h"
#include "blackgui/guiutility.h"
#include "blackmisc/simulation/fscommon/aircraftcfgparser.h" #include "blackmisc/simulation/fscommon/aircraftcfgparser.h"
#include "blackmisc/logmessage.h" #include "blackmisc/logmessage.h"
#include "blackmisc/project.h" #include "blackmisc/project.h"
#include "blackgui/guiutility.h"
using namespace BlackCore; using namespace BlackCore;
using namespace BlackMisc; using namespace BlackMisc;
@@ -34,17 +35,26 @@ namespace BlackGui
{ {
ui->setupUi(this); ui->setupUi(this);
this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel); this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel);
connect(ui->editor_Model, &CModelMappingForm::requestSave, this, &CDbMappingComponent::save); this->ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModel);
connect(ui->editor_Model, &CModelMappingForm::requestSave, this, &CDbMappingComponent::saveSingleModelToDb);
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged); connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onOwnModelsCountChanged);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged);
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true); ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
ui->tvp_OwnAircraftModels->setCustomMenu(new CStashMenu(this, true));
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get());
// how to display forms
ui->editor_AircraftIcao->setMappingMode(); ui->editor_AircraftIcao->setMappingMode();
ui->editor_Distributor->setMappingMode(); ui->editor_Distributor->setMappingMode();
ui->editor_Livery->setMappingMode(); ui->editor_Livery->setMappingMode();
this->ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16());
this->ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16());
this->initVPilotLoading(); this->initVPilotLoading();
} }
@@ -58,18 +68,19 @@ namespace BlackGui
bool canUseVPilot = CProject::isRunningOnWindowsNtPlatform() && CProject::isCompiledWithMsFlightSimulatorSupport(); bool canUseVPilot = CProject::isRunningOnWindowsNtPlatform() && CProject::isCompiledWithMsFlightSimulatorSupport();
bool withVPilotRights = canUseVPilot && this->m_user.get().isMappingAdmin(); bool withVPilotRights = canUseVPilot && this->m_user.get().isMappingAdmin();
this->m_withVPilot = withVPilotRights; this->m_withVPilot = withVPilotRights;
static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(1)); static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(TabVPliot));
if (this->m_vPilot1stInit && canUseVPilot) if (this->m_vPilot1stInit && canUseVPilot)
{ {
ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CStashMenu(this, true));
connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged); connect(ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged);
connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished); connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished);
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this)); this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this, true));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(m_cachedVPilotModels.get());
} }
this->m_vPilot1stInit = false; this->m_vPilot1stInit = false;
this->ui->tab_VPilot->setEnabled(withVPilotRights); this->ui->tab_VPilot->setEnabled(withVPilotRights);
this->ui->tab_VPilot->setVisible(withVPilotRights); this->ui->tab_VPilot->setVisible(withVPilotRights);
if (withVPilotRights) if (withVPilotRights)
@@ -78,7 +89,7 @@ namespace BlackGui
} }
else else
{ {
this->ui->tw_ModelsToBeMapped->removeTab(1); this->ui->tw_ModelsToBeMapped->removeTab(TabVPliot);
} }
} }
@@ -122,6 +133,43 @@ namespace BlackGui
if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); } if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); }
} }
bool CDbMappingComponent::hasModelsForStash() const
{
TabIndex tab = currentTabIndex();
switch (tab)
{
case TabOwnModels:
return ui->tvp_OwnAircraftModels->hasSelection();
case TabVPliot:
return ui->tvp_AircraftModelsForVPilot->hasSelection();
default:
break;
}
return false;
}
CAircraftModelList CDbMappingComponent::getModelsForStash() const
{
if (!hasModelsForStash()) { return CAircraftModelList(); }
TabIndex tab = currentTabIndex();
switch (tab)
{
case TabOwnModels:
return ui->tvp_OwnAircraftModels->selectedObjects();
case TabVPliot:
return ui->tvp_AircraftModelsForVPilot->selectedObjects();
default:
break;
}
return CAircraftModelList();
}
CDbMappingComponent::TabIndex CDbMappingComponent::currentTabIndex() const
{
int t = ui->tw_ModelsToBeMapped->currentIndex();
return static_cast<TabIndex>(t);
}
CStatusMessageList CDbMappingComponent::validate(bool withNestedForms) const CStatusMessageList CDbMappingComponent::validate(bool withNestedForms) const
{ {
CStatusMessageList msgs(this->ui->editor_Model->validate(!withNestedForms)); CStatusMessageList msgs(this->ui->editor_Model->validate(!withNestedForms));
@@ -134,7 +182,7 @@ namespace BlackGui
return msgs; return msgs;
} }
void CDbMappingComponent::save() void CDbMappingComponent::saveSingleModelToDb()
{ {
CStatusMessageList msgs(validate(true)); CStatusMessageList msgs(validate(true));
if (msgs.hasErrorMessages()) if (msgs.hasErrorMessages())
@@ -145,7 +193,7 @@ namespace BlackGui
} }
CAircraftModel model(getAircraftModel()); CAircraftModel model(getAircraftModel());
msgs = this->asyncWriteModel(model); msgs = this->asyncWriteModelToDb(model);
if (!msgs.isEmpty()) if (!msgs.isEmpty())
{ {
CLogMessage(this).preformatted(msgs); CLogMessage(this).preformatted(msgs);
@@ -203,12 +251,30 @@ namespace BlackGui
if (success) if (success)
{ {
CLogMessage(this).info("Loading vPilot ruleset completed"); CLogMessage(this).info("Loading vPilot ruleset completed");
const CAircraftModelList models(this->m_vPilotReader.getAsModels());
if (this->ui->tvp_AircraftModelsForVPilot->displayAutomatically()) if (this->ui->tvp_AircraftModelsForVPilot->displayAutomatically())
{ {
this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync( this->ui->tvp_AircraftModelsForVPilot->updateContainerMaybeAsync(models);
this->m_vPilotReader.getAsModels()
);
} }
QTime t;
t.start();
m_cachedVPilotModels.set(models);
qint64 e = t.elapsed();
qDebug() << e;
CLogMessage(this).info("Written %1 vPilot rules to cache") << models.size();
/**
t.start();
QString x = models.toJsonString();
e = t.elapsed();
t.start();
CAircraftModelList ml;
ml.convertFromJson(x);
e = t.elapsed();
t.start();
**/
} }
else else
{ {
@@ -245,6 +311,17 @@ namespace BlackGui
this->ui->tw_ModelsToBeMapped->setTabText(i, o); this->ui->tw_ModelsToBeMapped->setTabText(i, o);
} }
void CDbMappingComponent::ps_onStashCountChanged(int count, bool withFilter)
{
Q_UNUSED(count);
Q_UNUSED(withFilter);
int i = this->ui->tw_ModelsToBeMapped->indexOf(this->ui->tab_StashAircraftModels);
QString o = this->ui->tw_ModelsToBeMapped->tabText(i);
QString f = this->ui->comp_StashAircraft->getView()->derivedModel()->hasFilter() ? "F" : "";
o = CGuiUtility::replaceTabCountValue(o, this->ui->comp_StashAircraft->getView()->rowCount()) + f;
this->ui->tw_ModelsToBeMapped->setTabText(i, o);
}
void CDbMappingComponent::ps_requestSimulatorModels() void CDbMappingComponent::ps_requestSimulatorModels()
{ {
QAction *a = qobject_cast<QAction *>(QObject::sender()); QAction *a = qobject_cast<QAction *>(QObject::sender());
@@ -259,6 +336,19 @@ namespace BlackGui
this->initVPilotLoading(); this->initVPilotLoading();
} }
void CDbMappingComponent::stashSelectedModels()
{
if (!this->hasModelsForStash()) { return; }
CStatusMessageList msgs =
this->ui->comp_StashAircraft->stashModels(
this->getModelsForStash()
);
if (msgs.hasWarningOrErrorMessages())
{
// maybe log, popup?
}
}
void CDbMappingComponent::ps_onModelRowSelected(const QModelIndex &index) void CDbMappingComponent::ps_onModelRowSelected(const QModelIndex &index)
{ {
QObject *sender = QObject::sender(); QObject *sender = QObject::sender();
@@ -319,13 +409,14 @@ namespace BlackGui
{ {
if (success && this->m_modelLoader) if (success && this->m_modelLoader)
{ {
CLogMessage(this).info("Loading of models completed"); const CAircraftModelList models(this->m_modelLoader->getAircraftModels());
CLogMessage(this).info("Loading %1 of models completed") << models.size();
if (this->ui->tvp_OwnAircraftModels->displayAutomatically()) if (this->ui->tvp_OwnAircraftModels->displayAutomatically())
{ {
this->ui->tvp_OwnAircraftModels->updateContainer( this->ui->tvp_OwnAircraftModels->updateContainer(models);
this->m_modelLoader->getAircraftModels()
);
} }
this->m_cachedOwnModels.set(models);
CLogMessage(this).info("Written %1 own models to cache") << models.size();
} }
else else
{ {
@@ -347,6 +438,9 @@ namespace BlackGui
void CDbMappingComponent::CMappingSimulatorModelMenu::customMenu(QMenu &menu) const void CDbMappingComponent::CMappingSimulatorModelMenu::customMenu(QMenu &menu) const
{ {
CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators(); CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators();
bool empty = sims.isNoSimulator() || sims.isUnspecified();
if (!empty)
{
QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models"); QMenu *load = menu.addMenu(CIcons::appModels16(), "Load installed models");
QAction *a = nullptr; QAction *a = nullptr;
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent()); CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
@@ -374,11 +468,13 @@ namespace BlackGui
} }
menu.addSeparator(); menu.addSeparator();
} }
this->nestedCustomMenu(menu);
}
void CDbMappingComponent::CMappingVPilotMenu::customMenu(QMenu &menu) const void CDbMappingComponent::CMappingVPilotMenu::customMenu(QMenu &menu) const
{ {
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent()); CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access parent"); Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access mapping component");
bool canUseVPilot = mappingComponent()->withVPilot(); bool canUseVPilot = mappingComponent()->withVPilot();
if (canUseVPilot) if (canUseVPilot)
@@ -386,6 +482,7 @@ namespace BlackGui
menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData())); menu.addAction(CIcons::appMappings16(), "Load vPilot Rules", mapComp, SLOT(ps_loadVPilotData()));
menu.addSeparator(); menu.addSeparator();
} }
this->nestedCustomMenu(menu);
} }
CDbMappingComponent *CDbMappingComponent::CMappingVPilotMenu::mappingComponent() const CDbMappingComponent *CDbMappingComponent::CMappingVPilotMenu::mappingComponent() const
@@ -393,5 +490,20 @@ namespace BlackGui
return qobject_cast<CDbMappingComponent *>(this->parent()); return qobject_cast<CDbMappingComponent *>(this->parent());
} }
void CDbMappingComponent::CStashMenu::customMenu(QMenu &menu) const
{
CDbMappingComponent *mapComp = qobject_cast<CDbMappingComponent *>(this->parent());
Q_ASSERT_X(mapComp, Q_FUNC_INFO, "Cannot access mapping component");
if (mapComp->hasModelsForStash())
{
menu.addAction(CIcons::appMappings16(), "Stash", mapComp, SLOT(stashSelectedModels()));
}
this->nestedCustomMenu(menu);
}
CDbMappingComponent *CDbMappingComponent::CStashMenu::mappingComponent() const
{
return qobject_cast<CDbMappingComponent *>(this->parent());
}
} // ns } // ns
} // ns } // ns

View File

@@ -13,6 +13,7 @@
#define BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H #define BLACKGUI_COMPONENTS_DBMAPPINGCOMPONENT_H
#include "blackcore/data/authenticateduser.h" #include "blackcore/data/authenticateduser.h"
#include "blackcore/data/aircraftmodels.h"
#include "blackgui/blackguiexport.h" #include "blackgui/blackguiexport.h"
#include "blackgui/overlaymessagesframe.h" #include "blackgui/overlaymessagesframe.h"
#include "blackgui/menudelegate.h" #include "blackgui/menudelegate.h"
@@ -43,6 +44,16 @@ namespace BlackGui
Q_OBJECT Q_OBJECT
public: public:
//! Tab index
//! Must match real tab index
enum TabIndex
{
NoValidTab = -1,
TabStash = 0,
TabOwnModels = 1,
TabVPliot = 2
};
//! Constructor //! Constructor
explicit CDbMappingComponent(QWidget *parent = nullptr); explicit CDbMappingComponent(QWidget *parent = nullptr);
@@ -58,6 +69,15 @@ namespace BlackGui
//! With vPilot rules //! With vPilot rules
bool withVPilot() const { return m_withVPilot; } bool withVPilot() const { return m_withVPilot; }
//! And models which can be stashed
bool hasModelsForStash() const;
//! The model to be stashed
BlackMisc::Simulation::CAircraftModelList getModelsForStash() const;
//! Current tab index
TabIndex currentTabIndex() const;
signals: signals:
//! Request to filter by livery //! Request to filter by livery
void filterByLivery(const BlackMisc::Aviation::CLivery &livery); void filterByLivery(const BlackMisc::Aviation::CLivery &livery);
@@ -73,7 +93,7 @@ namespace BlackGui
BlackMisc::CStatusMessageList validate(bool withNestedForms) const; BlackMisc::CStatusMessageList validate(bool withNestedForms) const;
//! Save //! Save
void save(); void saveSingleModelToDb();
//! Resize so that selection is easy (larger table view) //! Resize so that selection is easy (larger table view)
void resizeForSelect(); void resizeForSelect();
@@ -81,6 +101,9 @@ namespace BlackGui
//! Resize so that mapping is easier //! Resize so that mapping is easier
void resizeForMapping(); void resizeForMapping();
//! Stash models
void stashSelectedModels();
private slots: private slots:
//! Load the vPilot rules //! Load the vPilot rules
void ps_loadVPilotData(); void ps_loadVPilotData();
@@ -91,6 +114,9 @@ namespace BlackGui
//! Row count for vPilot data changed //! Row count for vPilot data changed
void ps_onVPilotCountChanged(int count, bool withFilter); void ps_onVPilotCountChanged(int count, bool withFilter);
//! Stash count has been changed
void ps_onStashCountChanged(int count, bool withFilter);
//! Row has been selected //! Row has been selected
void ps_onModelRowSelected(const QModelIndex &index); void ps_onModelRowSelected(const QModelIndex &index);
@@ -111,8 +137,10 @@ namespace BlackGui
private: private:
QScopedPointer<Ui::CDbMappingComponent> ui; QScopedPointer<Ui::CDbMappingComponent> ui;
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; BlackCore::CData<BlackCore::Data::VPilotAircraftModels> m_cachedVPilotModels { this }; //!< cache for latest vPilot rules
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
BlackCore::CData<BlackCore::Data::OwnSimulatorAircraftModels> m_cachedOwnModels { this }; //!< cache for latest models
BlackCore::CData<BlackCore::Data::AuthenticatedUser> m_user {this, &CDbMappingComponent::ps_userChanged}; BlackCore::CData<BlackCore::Data::AuthenticatedUser> m_user {this, &CDbMappingComponent::ps_userChanged};
bool m_vPilot1stInit = true; bool m_vPilot1stInit = true;
bool m_withVPilot = false; bool m_withVPilot = false;
@@ -143,13 +171,13 @@ namespace BlackGui
}; };
//! The menu for loading and handling VPilot rules for mapping //! The menu for loading and handling VPilot rules for mapping
//! \note This is specific for that very component //! \note This is a specific menu for that very component
class CMappingVPilotMenu : public BlackGui::IMenuDelegate class CMappingVPilotMenu : public BlackGui::IMenuDelegate
{ {
public: public:
//! Constructor //! Constructor
CMappingVPilotMenu(CDbMappingComponent *mappingComponent) : CMappingVPilotMenu(CDbMappingComponent *mappingComponent, bool separatorAtEnd) :
BlackGui::IMenuDelegate(mappingComponent) BlackGui::IMenuDelegate(mappingComponent, separatorAtEnd)
{} {}
//! \copydoc IMenuDelegate::customMenu //! \copydoc IMenuDelegate::customMenu
@@ -158,8 +186,23 @@ namespace BlackGui
private: private:
CDbMappingComponent *mappingComponent() const; CDbMappingComponent *mappingComponent() const;
}; };
};
//! The menu for stashing models
//! \note This is a specific menu for that very component
class CStashMenu : public BlackGui::IMenuDelegate
{
public:
//! Constructor
CStashMenu(CDbMappingComponent *mappingComponent, bool separatorAtEnd) :
BlackGui::IMenuDelegate(mappingComponent, separatorAtEnd)
{}
//! \copydoc IMenuDelegate::customMenu
virtual void customMenu(QMenu &menu) const override;
CDbMappingComponent *mappingComponent() const;
};
};
} // ns } // ns
} // ns } // ns
#endif // guard #endif // guard

View File

@@ -6,8 +6,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>266</width> <width>264</width>
<height>618</height> <height>616</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -62,6 +62,38 @@
<property name="currentIndex"> <property name="currentIndex">
<number>0</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="tab_StashAircraftModels">
<attribute name="title">
<string>Stashed aircraft</string>
</attribute>
<layout class="QHBoxLayout" name="hl_StashedAircraft">
<property name="spacing">
<number>4</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>2</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="BlackGui::Components::CDbStashComponent" name="comp_StashAircraft">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_OwnModels"> <widget class="QWidget" name="tab_OwnModels">
<attribute name="title"> <attribute name="title">
<string>Own models</string> <string>Own models</string>
@@ -91,7 +123,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::MultiSelection</enum>
</property> </property>
<property name="selectionBehavior"> <property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum> <enum>QAbstractItemView::SelectRows</enum>
@@ -132,7 +164,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::SingleSelection</enum> <enum>QAbstractItemView::MultiSelection</enum>
</property> </property>
<property name="selectionBehavior"> <property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum> <enum>QAbstractItemView::SelectRows</enum>
@@ -194,7 +226,7 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>245</width> <width>243</width>
<height>375</height> <height>375</height>
</rect> </rect>
</property> </property>
@@ -370,6 +402,12 @@
<header>blackgui/overlaymessagesframe.h</header> <header>blackgui/overlaymessagesframe.h</header>
<container>1</container> <container>1</container>
</customwidget> </customwidget>
<customwidget>
<class>BlackGui::Components::CDbStashComponent</class>
<extends>QFrame</extends>
<header>blackgui/components/dbstashcomponent.h</header>
<container>1</container>
</customwidget>
</customwidgets> </customwidgets>
<resources/> <resources/>
<connections/> <connections/>

View File

@@ -9,6 +9,12 @@
#include "dbstashcomponent.h" #include "dbstashcomponent.h"
#include "ui_dbstashcomponent.h" #include "ui_dbstashcomponent.h"
#include "blackmisc/icons.h"
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackMisc::Network;
using namespace BlackGui::Models;
namespace BlackGui namespace BlackGui
{ {
@@ -19,19 +25,79 @@ namespace BlackGui
ui(new Ui::CDbStashComponent) ui(new Ui::CDbStashComponent)
{ {
ui->setupUi(this); ui->setupUi(this);
this->ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel);
connect(this->ui->pb_Unstash, &QPushButton::pressed, this, &CDbStashComponent::ps_onUnstashPressed);
connect(this->ui->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::ps_onValidatePressed);
ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true));
} }
CDbStashComponent::~CDbStashComponent() CDbStashComponent::~CDbStashComponent()
{ } { }
void CDbStashComponent::setProvider(BlackMisc::Network::IWebDataServicesProvider *provider) void CDbStashComponent::setProvider(IWebDataServicesProvider *provider)
{ {
CWebDataServicesAware::setProvider(provider); CWebDataServicesAware::setProvider(provider);
} }
void CDbStashComponent::gracefulShutdown() void CDbStashComponent::gracefulShutdown()
{ {
// shutdown
}
CStatusMessage CDbStashComponent::validateStashModel(const CAircraftModel &model) const
{
static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
if (this->ui->tvp_StashAircraftModels->container().containsModelStringOrId(model))
{
const QString msg("Model \"%1\" already stashed");
return CStatusMessage(cats, CStatusMessage::SeverityError, msg.arg(model.getModelString()));
}
return CStatusMessage();
}
CStatusMessage CDbStashComponent::stashModel(const CAircraftModel &model)
{
CStatusMessage m(validateStashModel(model));
if (!m.isWarningOrAbove())
{
this->ui->tvp_StashAircraftModels->insert(model);
}
return m;
}
CStatusMessageList CDbStashComponent::stashModels(const CAircraftModelList &models)
{
if (models.isEmpty()) { return CStatusMessageList(); }
CStatusMessageList msgs;
for (const CAircraftModel &model : models)
{
CStatusMessage m(stashModel(model));
if (m.isWarningOrAbove()) { msgs.push_back(m); }
}
return msgs;
}
const Views::CAircraftModelView *CDbStashComponent::getView() const
{
return ui->tvp_StashAircraftModels;
}
void CDbStashComponent::ps_onUnstashPressed()
{
this->ui->tvp_StashAircraftModels->removeSelectedRows();
}
void CDbStashComponent::ps_onValidatePressed()
{
if (this->ui->tvp_StashAircraftModels->isEmpty()) { return; }
}
void CDbStashComponent::CStashModelsMenu::customMenu(QMenu &menu) const
{
menu.addAction(CIcons::database16(), "Unstash", this->parent(), SLOT(ps_onUnstashPressed()));
nestedCustomMenu(menu);
} }
} // ns } // ns

View File

@@ -13,6 +13,8 @@
#define BLACKGUI_COMPONENTS_DBSTASHCOMPONENT_H #define BLACKGUI_COMPONENTS_DBSTASHCOMPONENT_H
#include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/menudelegate.h"
#include "blackgui/views/aircraftmodelview.h"
#include "blackmisc/network/webdataservicesprovider.h" #include "blackmisc/network/webdataservicesprovider.h"
#include <QFrame> #include <QFrame>
#include <QScopedPointer> #include <QScopedPointer>
@@ -46,10 +48,43 @@ namespace BlackGui
//! Graceful shutdown //! Graceful shutdown
void gracefulShutdown(); void gracefulShutdown();
//! Test the given model if it can be stashed
BlackMisc::CStatusMessage validateStashModel(const BlackMisc::Simulation::CAircraftModel &model) const;
//! Stash given model
BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model);
//! Stash given models
BlackMisc::CStatusMessageList stashModels(const BlackMisc::Simulation::CAircraftModelList &models);
//! The embedded view
const BlackGui::Views::CAircraftModelView *getView() const;
signals:
//! Unstash
void unstashed(BlackMisc::Simulation::CAircraftModel &model);
private slots:
//! Unstash pressed
void ps_onUnstashPressed();
//! Validate pressed
void ps_onValidatePressed();
private: private:
QScopedPointer<Ui::CDbStashComponent> ui; QScopedPointer<Ui::CDbStashComponent> ui;
};
//! Custom menu for the stashed models
class CStashModelsMenu : public BlackGui::IMenuDelegate
{
public:
//! Constructor
CStashModelsMenu(CDbStashComponent *parent, bool separatorAtEnd) : IMenuDelegate(parent, separatorAtEnd) {}
//! \copydoc IMenuDelegate::customMenu
virtual void customMenu(QMenu &menu) const override;
};
};
} // ns } // ns
} // ns } // ns

View File

@@ -1,10 +1,7 @@
<?xml version='1.0'?> <?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0"> <ui version="4.0">
<class>CDbStashComponent</class> <class>CDbStashComponent</class>
<widget class="QFrame" name="CDbStashComponent"> <widget class="QFrame" name="CDbStashComponent">
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>0</x> <x>0</x>
@@ -13,11 +10,104 @@
<height>300</height> <height>300</height>
</rect> </rect>
</property> </property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="windowTitle"> <property name="windowTitle">
<string>Frame</string> <string>Frame</string>
</property> </property>
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="vl_DbStashComponent">
<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_StashAircraftModels">
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="verticalHeaderVisible">
<bool>false</bool>
</attribute>
</widget> </widget>
</item>
<item>
<widget class="QFrame" name="fr_StashHandling">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="hl_StashHandling">
<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="QPushButton" name="pb_Unstash">
<property name="text">
<string>Unstash</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Validate">
<property name="text">
<string>Validate</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pb_Save">
<property name="text">
<string>Save</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>BlackGui::Views::CAircraftModelView</class>
<extends>QTableView</extends>
<header>blackgui/views/aircraftmodelview.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>pb_Unstash</tabstop>
<tabstop>pb_Validate</tabstop>
<tabstop>pb_Save</tabstop>
<tabstop>tvp_StashAircraftModels</tabstop>
</tabstops>
<resources/>
<connections/>
</ui> </ui>