refs #568, allow to stash from DB data view (model view)

* added required signal slots
* moved models for stashing into aircraft model view
* allow to unselect when stashed
* fixed DB object highlighting and resize row height automatically
This commit is contained in:
Klaus Basan
2016-01-09 03:37:07 +01:00
parent 0326356f43
commit 11ee49a382
12 changed files with 209 additions and 106 deletions

View File

@@ -11,6 +11,7 @@
#include "blackgui/components/datamaininfoareacomponent.h"
#include "blackgui/components/dbliverycomponent.h"
#include "blackgui/components/dbaircrafticaocomponent.h"
#include "blackgui/components/dbmodelcomponent.h"
#include "blackgui/components/dbstashcomponent.h"
#include "ui_datamaininfoareacomponent.h"
#include "blackmisc/icons.h"
@@ -34,6 +35,8 @@ namespace BlackGui
connect(ui->comp_Mapping, &CDbMappingComponent::filterByLivery, ui->comp_DataInfoArea->getLiveryComponent(), &CDbLiveryComponent::filter);
connect(ui->comp_Mapping, &CDbMappingComponent::filterByAircraftIcao, ui->comp_DataInfoArea->getAircraftComponent(), &CDbAircraftIcaoComponent::filter);
connect(ui->comp_Mapping, &CDbMappingComponent::requestUpdatedData, ui->comp_DataInfoArea, &CDataInfoAreaComponent::requestUpdatedData);
connect(ui->comp_DataInfoArea->getModelComponent(), &CDbModelComponent::requestStash, ui->comp_Mapping, &CDbMappingComponent::stashModels);
}
CDataMainInfoAreaComponent::~CDataMainInfoAreaComponent()

View File

@@ -38,10 +38,8 @@ namespace BlackGui
this->ui->comp_StashAircraft->setMappingComponent(this);
this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel);
this->ui->tvp_AircraftModelsForVPilot->setAllowStash(true);
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
this->ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping);
this->ui->tvp_OwnAircraftModels->setAllowStash(true);
this->ui->tvp_OwnAircraftModels->addFilterDialog();
// connects
@@ -50,6 +48,8 @@ namespace BlackGui
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::requestStash, this, &CDbMappingComponent::stashSelectedModels);
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest);
@@ -58,13 +58,12 @@ namespace BlackGui
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_Distributor->setMappingMode();
ui->editor_Livery->setMappingMode();
ui->editor_AircraftIcao->setMappingMode(true);
ui->editor_Distributor->setMappingMode(true);
ui->editor_Livery->setMappingMode(true);
this->ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16());
this->ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16());
@@ -83,15 +82,16 @@ namespace BlackGui
bool canUseVPilot = true; // further restriction could go here
bool withVPilotRights = canUseVPilot && this->m_user.get().isMappingAdmin();
this->m_withVPilot = withVPilotRights;
static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(TabVPliot));
static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(TabVPilot));
if (this->m_vPilot1stInit && canUseVPilot)
{
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CStashMenu(this, true));
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged);
connect(&m_vPilotReader, &CVPilotRulesReader::readFinished, this, &CDbMappingComponent::ps_onLoadVPilotDataFinished);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::toggledHighlightStashedModels, this, &CDbMappingComponent::ps_onStashedModelsChanged);
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CMappingVPilotMenu(this, true));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
@@ -109,7 +109,7 @@ namespace BlackGui
}
else
{
this->ui->tw_ModelsToBeMapped->removeTab(TabVPliot);
this->ui->tw_ModelsToBeMapped->removeTab(TabVPilot);
}
}
@@ -184,7 +184,7 @@ namespace BlackGui
{
case TabOwnModels:
return ui->tvp_OwnAircraftModels->hasSelectedModelsToStash();
case TabVPliot:
case TabVPilot:
return ui->tvp_AircraftModelsForVPilot->hasSelectedModelsToStash();
default:
break;
@@ -199,7 +199,7 @@ namespace BlackGui
{
case TabOwnModels:
return ui->tvp_OwnAircraftModels;
case TabVPliot:
case TabVPilot:
return ui->tvp_AircraftModelsForVPilot;
case TabStash:
return ui->comp_StashAircraft->getView();
@@ -216,7 +216,7 @@ namespace BlackGui
{
case TabOwnModels:
return ui->tvp_OwnAircraftModels->selectedObjects();
case TabVPliot:
case TabVPilot:
return ui->tvp_AircraftModelsForVPilot->selectedObjects();
default:
break;
@@ -524,6 +524,16 @@ namespace BlackGui
return model;
}
CStatusMessage CDbMappingComponent::stashModel(const CAircraftModel &model)
{
return this->ui->comp_StashAircraft->stashModel(model);
}
CStatusMessageList CDbMappingComponent::stashModels(const CAircraftModelList &models)
{
return this->ui->comp_StashAircraft->stashModels(models);
}
void CDbMappingComponent::CMappingSimulatorModelMenu::customMenu(QMenu &menu) const
{
CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators();
@@ -578,21 +588,5 @@ namespace BlackGui
{
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->hasModelsToStash())
{
menu.addAction(CIcons::appMappings16(), "Stash", mapComp, SLOT(stashSelectedModels()), CShortcut::keyStash());
}
this->nestedCustomMenu(menu);
}
CDbMappingComponent *CDbMappingComponent::CStashMenu::mappingComponent() const
{
return qobject_cast<CDbMappingComponent *>(this->parent());
}
} // ns
} // ns

View File

@@ -53,7 +53,7 @@ namespace BlackGui
NoValidTab = -1,
TabStash = 0,
TabOwnModels = 1,
TabVPliot = 2
TabVPilot = 2
};
//! Constructor
@@ -74,7 +74,7 @@ namespace BlackGui
//! Any models which can be stashed
bool hasModelsToStash() const;
//! The models to be stashed
//! The models to be stashed from currently activated tab (table view)
BlackMisc::Simulation::CAircraftModelList getModelsToStash() const;
//! Stashed models
@@ -93,6 +93,13 @@ namespace BlackGui
//! \note not guaranteed to be valid, just snapshot of as it state
BlackMisc::Simulation::CAircraftModel getAircraftModel() const;
public slots:
//! Stash model
BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model);
//! Stash models
BlackMisc::CStatusMessageList stashModels(const BlackMisc::Simulation::CAircraftModelList &models);
signals:
//! Request to filter by livery
void filterByLivery(const BlackMisc::Aviation::CLivery &livery);
@@ -220,24 +227,6 @@ namespace BlackGui
//! Mapping component
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;
private:
//! Mapping component
CDbMappingComponent *mappingComponent() const;
};
};
} // ns
} // ns

View File

@@ -10,6 +10,7 @@
#include "dbmodelcomponent.h"
#include "dbmappingcomponent.h"
#include "blackgui/stylesheetutility.h"
#include "blackgui/shortcut.h"
#include "blackmisc/simulation/aircraftmodel.h"
#include "ui_dbmodelcomponent.h"
#include <functional>
@@ -33,11 +34,13 @@ namespace BlackGui
this->setViewWithIndicator(this->ui->tvp_AircraftModel);
this->ui->tvp_AircraftModel->setAircraftModelMode(CAircraftModelListModel::Database);
connect(this->ui->tvp_AircraftModel, &CAircraftModelView::requestNewBackendData, this, &CDbModelComponent::ps_reload);
connect(this->ui->tvp_AircraftModel, &CAircraftModelView::requestStash, this, &CDbModelComponent::requestStash);
connect(&CStyleSheetUtility::instance(), &CStyleSheetUtility::styleSheetsChanged, this, &CDbModelComponent::ps_onStyleSheetChanged);
// filter and drag and drop
// configure view
this->ui->tvp_AircraftModel->setFilterWidget(this->ui->filter_AircraftModelFilter);
this->ui->tvp_AircraftModel->allowDragDropValueObjects(true, false);
this->ui->tvp_AircraftModel->menuAddItems(CAircraftModelView::MenuStashModels);
}
CDbModelComponent::~CDbModelComponent()
@@ -59,6 +62,11 @@ namespace BlackGui
}
}
bool CDbModelComponent::hasModels() const
{
return !this->ui->tvp_AircraftModel->isEmpty();
}
void CDbModelComponent::requestUpdatedData()
{
QDateTime ts;
@@ -92,5 +100,32 @@ namespace BlackGui
{
// code goes here
}
void CDbModelComponent::ps_stashSelectedModels()
{
if (!this->ui->tvp_AircraftModel->hasSelection()) { return; }
const CAircraftModelList models(this->ui->tvp_AircraftModel->selectedObjects());
if (!models.isEmpty())
{
emit requestStash(models);
}
}
void CDbModelComponent::CStashMenu::customMenu(QMenu &menu) const
{
CDbModelComponent *modelComponent = qobject_cast<CDbModelComponent *>(this->parent());
Q_ASSERT_X(modelComponent, Q_FUNC_INFO, "Cannot access model component");
if (modelComponent->hasModels())
{
menu.addAction(CIcons::appMappings16(), "Stash", modelComponent, SLOT(ps_stashSelectedModels()), CShortcut::keyStash());
}
this->nestedCustomMenu(menu);
}
CDbModelComponent *CDbModelComponent::CStashMenu::modelComponent() const
{
return qobject_cast<CDbModelComponent *>(this->parent());
}
} // ns
} // ns

View File

@@ -16,6 +16,7 @@
#include "blackgui/enableforviewbasedindicator.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/components/dbmappingcomponentaware.h"
#include "blackgui/menudelegate.h"
#include "blackmisc/network/webdataservicesprovider.h"
#include <QFrame>
#include <QScopedPointer>
@@ -51,6 +52,13 @@ namespace BlackGui
//! Get latest model if any
BlackMisc::Simulation::CAircraftModel getLatestModel() const;
//! Models loaded?
bool hasModels() const;
signals:
//! Request to stash the selected models
void requestStash(const BlackMisc::Simulation::CAircraftModelList &models);
public slots:
//! Load new data
void requestUpdatedData();
@@ -65,8 +73,29 @@ namespace BlackGui
//! Style sheet changed
void ps_onStyleSheetChanged();
//! Stash the selected models
void ps_stashSelectedModels();
private:
QScopedPointer<Ui::CDbModelComponent> ui;
//! The menu for stashing models
//! \note This is a specific menu for that very component
class CStashMenu : public BlackGui::IMenuDelegate
{
public:
//! Constructor
CStashMenu(CDbModelComponent *modelComponent, bool separatorAtEnd) :
BlackGui::IMenuDelegate(modelComponent, separatorAtEnd)
{}
//! \copydoc IMenuDelegate::customMenu
virtual void customMenu(QMenu &menu) const override;
private:
//! Mapping component
CDbModelComponent *modelComponent() const;
};
};
} // ns
} // ns

View File

@@ -55,12 +55,6 @@ namespace BlackGui
//! Test the given model if it can be stashed
BlackMisc::CStatusMessage validateStashModel(const BlackMisc::Simulation::CAircraftModel &model, bool allowReplace) const;
//! Stash given model
BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model, bool replace = false);
//! Stash given models
BlackMisc::CStatusMessageList stashModels(const BlackMisc::Simulation::CAircraftModelList &models);
//! Unstash given models with keys
int unstashModels(QList<int> keys);
@@ -94,6 +88,13 @@ namespace BlackGui
//! Apply object to select objects
void applyToSelected(const BlackMisc::Simulation::CDistributor &distributor, bool acceptWarnings = true);
public slots:
//! Stash given model
BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model, bool replace = false);
//! Stash given models
BlackMisc::CStatusMessageList stashModels(const BlackMisc::Simulation::CAircraftModelList &models);
signals:
//! Unstash
void unstashed(BlackMisc::Simulation::CAircraftModel &model);