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/datamaininfoareacomponent.h"
#include "blackgui/components/dbliverycomponent.h" #include "blackgui/components/dbliverycomponent.h"
#include "blackgui/components/dbaircrafticaocomponent.h" #include "blackgui/components/dbaircrafticaocomponent.h"
#include "blackgui/components/dbmodelcomponent.h"
#include "blackgui/components/dbstashcomponent.h" #include "blackgui/components/dbstashcomponent.h"
#include "ui_datamaininfoareacomponent.h" #include "ui_datamaininfoareacomponent.h"
#include "blackmisc/icons.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::filterByLivery, ui->comp_DataInfoArea->getLiveryComponent(), &CDbLiveryComponent::filter);
connect(ui->comp_Mapping, &CDbMappingComponent::filterByAircraftIcao, ui->comp_DataInfoArea->getAircraftComponent(), &CDbAircraftIcaoComponent::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_Mapping, &CDbMappingComponent::requestUpdatedData, ui->comp_DataInfoArea, &CDataInfoAreaComponent::requestUpdatedData);
connect(ui->comp_DataInfoArea->getModelComponent(), &CDbModelComponent::requestStash, ui->comp_Mapping, &CDbMappingComponent::stashModels);
} }
CDataMainInfoAreaComponent::~CDataMainInfoAreaComponent() CDataMainInfoAreaComponent::~CDataMainInfoAreaComponent()

View File

@@ -38,10 +38,8 @@ namespace BlackGui
this->ui->comp_StashAircraft->setMappingComponent(this); this->ui->comp_StashAircraft->setMappingComponent(this);
this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel); this->ui->tvp_AircraftModelsForVPilot->setAircraftModelMode(CAircraftModelListModel::VPilotRuleModel);
this->ui->tvp_AircraftModelsForVPilot->setAllowStash(true);
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog(); this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
this->ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping); this->ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping);
this->ui->tvp_OwnAircraftModels->setAllowStash(true);
this->ui->tvp_OwnAircraftModels->addFilterDialog(); this->ui->tvp_OwnAircraftModels->addFilterDialog();
// connects // connects
@@ -50,6 +48,8 @@ namespace BlackGui
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->tvp_OwnAircraftModels, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); 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::rowCountChanged, this, &CDbMappingComponent::ps_onStashCountChanged);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected); connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(ui->comp_StashAircraft->getView(), &CAircraftModelView::requestHandlingOfStashDrop, this, &CDbMappingComponent::ps_handleStashDropRequest); 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->setDisplayAutomatically(true);
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this)); ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
ui->tvp_OwnAircraftModels->setCustomMenu(new CStashMenu(this, true));
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get()); ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get());
// how to display forms // how to display forms
ui->editor_AircraftIcao->setMappingMode(); ui->editor_AircraftIcao->setMappingMode(true);
ui->editor_Distributor->setMappingMode(); ui->editor_Distributor->setMappingMode(true);
ui->editor_Livery->setMappingMode(); ui->editor_Livery->setMappingMode(true);
this->ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16()); this->ui->tw_ModelsToBeMapped->setTabIcon(TabStash, CIcons::appDbStash16());
this->ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16()); this->ui->tw_ModelsToBeMapped->setTabIcon(TabOwnModels, CIcons::appModels16());
@@ -83,15 +82,16 @@ namespace BlackGui
bool canUseVPilot = true; // further restriction could go here bool canUseVPilot = true; // further restriction could go here
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(TabVPliot)); static const QString tabName(this->ui->tw_ModelsToBeMapped->tabText(TabVPilot));
if (this->m_vPilot1stInit && canUseVPilot) 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::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::rowCountChanged, this, &CDbMappingComponent::ps_onVPilotCountChanged); connect(this->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);
connect(this->ui->tvp_AircraftModelsForVPilot, &CAircraftModelView::requestStash, this, &CDbMappingComponent::stashSelectedModels); 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->setCustomMenu(new CMappingVPilotMenu(this, true));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true); this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog(); this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
@@ -109,7 +109,7 @@ namespace BlackGui
} }
else else
{ {
this->ui->tw_ModelsToBeMapped->removeTab(TabVPliot); this->ui->tw_ModelsToBeMapped->removeTab(TabVPilot);
} }
} }
@@ -184,7 +184,7 @@ namespace BlackGui
{ {
case TabOwnModels: case TabOwnModels:
return ui->tvp_OwnAircraftModels->hasSelectedModelsToStash(); return ui->tvp_OwnAircraftModels->hasSelectedModelsToStash();
case TabVPliot: case TabVPilot:
return ui->tvp_AircraftModelsForVPilot->hasSelectedModelsToStash(); return ui->tvp_AircraftModelsForVPilot->hasSelectedModelsToStash();
default: default:
break; break;
@@ -199,7 +199,7 @@ namespace BlackGui
{ {
case TabOwnModels: case TabOwnModels:
return ui->tvp_OwnAircraftModels; return ui->tvp_OwnAircraftModels;
case TabVPliot: case TabVPilot:
return ui->tvp_AircraftModelsForVPilot; return ui->tvp_AircraftModelsForVPilot;
case TabStash: case TabStash:
return ui->comp_StashAircraft->getView(); return ui->comp_StashAircraft->getView();
@@ -216,7 +216,7 @@ namespace BlackGui
{ {
case TabOwnModels: case TabOwnModels:
return ui->tvp_OwnAircraftModels->selectedObjects(); return ui->tvp_OwnAircraftModels->selectedObjects();
case TabVPliot: case TabVPilot:
return ui->tvp_AircraftModelsForVPilot->selectedObjects(); return ui->tvp_AircraftModelsForVPilot->selectedObjects();
default: default:
break; break;
@@ -524,6 +524,16 @@ namespace BlackGui
return model; 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 void CDbMappingComponent::CMappingSimulatorModelMenu::customMenu(QMenu &menu) const
{ {
CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators(); CSimulatorInfo sims = CSimulatorInfo::getLocallyInstalledSimulators();
@@ -578,21 +588,5 @@ 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->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
} // ns } // ns

View File

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

View File

@@ -10,6 +10,7 @@
#include "dbmodelcomponent.h" #include "dbmodelcomponent.h"
#include "dbmappingcomponent.h" #include "dbmappingcomponent.h"
#include "blackgui/stylesheetutility.h" #include "blackgui/stylesheetutility.h"
#include "blackgui/shortcut.h"
#include "blackmisc/simulation/aircraftmodel.h" #include "blackmisc/simulation/aircraftmodel.h"
#include "ui_dbmodelcomponent.h" #include "ui_dbmodelcomponent.h"
#include <functional> #include <functional>
@@ -33,11 +34,13 @@ namespace BlackGui
this->setViewWithIndicator(this->ui->tvp_AircraftModel); this->setViewWithIndicator(this->ui->tvp_AircraftModel);
this->ui->tvp_AircraftModel->setAircraftModelMode(CAircraftModelListModel::Database); this->ui->tvp_AircraftModel->setAircraftModelMode(CAircraftModelListModel::Database);
connect(this->ui->tvp_AircraftModel, &CAircraftModelView::requestNewBackendData, this, &CDbModelComponent::ps_reload); 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); 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->setFilterWidget(this->ui->filter_AircraftModelFilter);
this->ui->tvp_AircraftModel->allowDragDropValueObjects(true, false); this->ui->tvp_AircraftModel->allowDragDropValueObjects(true, false);
this->ui->tvp_AircraftModel->menuAddItems(CAircraftModelView::MenuStashModels);
} }
CDbModelComponent::~CDbModelComponent() CDbModelComponent::~CDbModelComponent()
@@ -59,6 +62,11 @@ namespace BlackGui
} }
} }
bool CDbModelComponent::hasModels() const
{
return !this->ui->tvp_AircraftModel->isEmpty();
}
void CDbModelComponent::requestUpdatedData() void CDbModelComponent::requestUpdatedData()
{ {
QDateTime ts; QDateTime ts;
@@ -92,5 +100,32 @@ namespace BlackGui
{ {
// code goes here // 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
} // ns } // ns

View File

@@ -16,6 +16,7 @@
#include "blackgui/enableforviewbasedindicator.h" #include "blackgui/enableforviewbasedindicator.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h" #include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/components/dbmappingcomponentaware.h" #include "blackgui/components/dbmappingcomponentaware.h"
#include "blackgui/menudelegate.h"
#include "blackmisc/network/webdataservicesprovider.h" #include "blackmisc/network/webdataservicesprovider.h"
#include <QFrame> #include <QFrame>
#include <QScopedPointer> #include <QScopedPointer>
@@ -51,6 +52,13 @@ namespace BlackGui
//! Get latest model if any //! Get latest model if any
BlackMisc::Simulation::CAircraftModel getLatestModel() const; 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: public slots:
//! Load new data //! Load new data
void requestUpdatedData(); void requestUpdatedData();
@@ -65,8 +73,29 @@ namespace BlackGui
//! Style sheet changed //! Style sheet changed
void ps_onStyleSheetChanged(); void ps_onStyleSheetChanged();
//! Stash the selected models
void ps_stashSelectedModels();
private: private:
QScopedPointer<Ui::CDbModelComponent> ui; 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
} // ns } // ns

View File

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

View File

@@ -36,7 +36,7 @@ namespace BlackGui
this->standardInit(new CAircraftModelListModel(CAircraftModelListModel::OwnSimulatorModel, this)); this->standardInit(new CAircraftModelListModel(CAircraftModelListModel::OwnSimulatorModel, this));
// shortcut // shortcut
new QShortcut(CShortcut::keyStash(), this, SLOT(ps_stashShortcut()), nullptr, Qt::WidgetShortcut); new QShortcut(CShortcut::keyStash(), this, SLOT(ps_requestStash()), nullptr, Qt::WidgetShortcut);
// default mode // default mode
CAircraftModelListModel::AircraftModelMode mode = derivedModel()->getModelMode(); CAircraftModelListModel::AircraftModelMode mode = derivedModel()->getModelMode();
@@ -56,12 +56,10 @@ namespace BlackGui
this->m_menus = MenuBackend; this->m_menus = MenuBackend;
break; break;
case CAircraftModelListModel::VPilotRuleModel: case CAircraftModelListModel::VPilotRuleModel:
this->m_menus = MenuRefresh | MenuHighlightDbData;; this->m_menus = MenuRefresh | MenuStashing | MenuHighlightDbData;
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
break; break;
case CAircraftModelListModel::OwnSimulatorModelMapping: case CAircraftModelListModel::OwnSimulatorModelMapping:
this->m_menus = MenuDisplayAutomatically | MenuHighlightDbData; this->m_menus = MenuDisplayAutomatically | MenuStashing | MenuHighlightDbData;
this->setCustomMenu(new CHighlightStashedModelsMenu(this, true));
break; break;
case CAircraftModelListModel::OwnSimulatorModel: case CAircraftModelListModel::OwnSimulatorModel:
default: default:
@@ -93,7 +91,7 @@ namespace BlackGui
bool CAircraftModelView::hasSelectedModelsToStash() const bool CAircraftModelView::hasSelectedModelsToStash() const
{ {
return m_allowStash && hasSelection(); return m_menus.testFlag(MenuStashModels) && hasSelection();
} }
void CAircraftModelView::setImplementedMetaTypeIds() void CAircraftModelView::setImplementedMetaTypeIds()
@@ -215,26 +213,50 @@ namespace BlackGui
} // valid mime? } // valid mime?
} }
void CAircraftModelView::customMenu(QMenu &menu) const
{
bool added = false;
if (this->m_menus.testFlag(MenuStashModels))
{
menu.addAction(CIcons::appDbStash16(), "Stash", this, SLOT(ps_requestStash()));
QAction *a = menu.addAction(CIcons::appDbStash16(), "Stashing clears selection", this, SLOT(ps_stashingClearsSelection()));
a->setCheckable(true);
a->setChecked(m_stashingClearsSelection);
added = true;
}
if (this->m_menus.testFlag(MenuHighlightStashed))
{
// this function requires someone provides the model strings to be highlighted
QAction *a = menu.addAction(CIcons::appDbStash16(), "Highlight stashed", this, SLOT(ps_toggleHighlightStashedModels()));
a->setCheckable(true);
a->setChecked(this->derivedModel()->highlightDbData());
added = true;
}
if (added) { menu.addSeparator(); }
CViewWithDbObjects::customMenu(menu);
}
void CAircraftModelView::ps_toggleHighlightStashedModels() void CAircraftModelView::ps_toggleHighlightStashedModels()
{ {
bool h = derivedModel()->highlightGivenModelStrings(); bool h = derivedModel()->highlightGivenModelStrings();
derivedModel()->setHighlightModelsStrings(!h); derivedModel()->setHighlightModelsStrings(!h);
emit toggledHighlightStashedModels();
} }
void CAircraftModelView::ps_stashShortcut() void CAircraftModelView::ps_stashingClearsSelection()
{ {
if (!m_allowStash) { return; } this->m_stashingClearsSelection = !this->m_stashingClearsSelection;
emit requestStash();
} }
void CAircraftModelView::CHighlightStashedModelsMenu::customMenu(QMenu &menu) const void CAircraftModelView::ps_requestStash()
{ {
const CAircraftModelView *mv = qobject_cast<const CAircraftModelView *>(parent()); if (!m_menus.testFlag(MenuStashModels)) { return; }
Q_ASSERT_X(mv, Q_FUNC_INFO, "no view"); if (!this->hasSelection()) { return; }
QAction *a = menu.addAction(CIcons::appDbStash16(), "Highlight stashed models", mv, SLOT(ps_toggleHighlightStashedModels())); emit requestStash(this->selectedObjects());
a->setCheckable(true); if (this->m_stashingClearsSelection)
a->setChecked(mv->derivedModel()->highlightGivenModelStrings()); {
this->nestedCustomMenu(menu); this->clearSelection();
}
} }
} // namespace } // namespace
} // namespace } // namespace

View File

@@ -43,9 +43,6 @@ namespace BlackGui
//! Apply to selected objects //! Apply to selected objects
int applyToSelected(const BlackMisc::Simulation::CDistributor &distributor); int applyToSelected(const BlackMisc::Simulation::CDistributor &distributor);
//! Allow to stash
void setAllowStash(bool stash) { m_allowStash = stash; }
//! Has any models to stash and it is allowed to stash //! Has any models to stash and it is allowed to stash
bool hasSelectedModelsToStash() const; bool hasSelectedModelsToStash() const;
@@ -60,7 +57,10 @@ namespace BlackGui
signals: signals:
//! Request to stash if applicable //! Request to stash if applicable
void requestStash(); void requestStash(const BlackMisc::Simulation::CAircraftModelList &models);
//! Highligh stashed models has been toggled
void toggledHighlightStashedModels();
//! Request further handling of drops I cannot handle on my own //! Request further handling of drops I cannot handle on my own
void requestHandlingOfStashDrop(const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcao); void requestHandlingOfStashDrop(const BlackMisc::Aviation::CAirlineIcaoCode &airlineIcao);
@@ -69,26 +69,21 @@ namespace BlackGui
//! \copydoc QTableView::dropEvent //! \copydoc QTableView::dropEvent
virtual void dropEvent(QDropEvent *event) override; virtual void dropEvent(QDropEvent *event) override;
//! \copydoc CViewBaseNonTemplate::customMenu
virtual void customMenu(QMenu &menu) const override;
private slots: private slots:
//! Highlight stashed models //! Highlight stashed models
void ps_toggleHighlightStashedModels(); void ps_toggleHighlightStashedModels();
//! Toggle if stashing unselects
void ps_stashingClearsSelection();
//! Stash shortcut pressed //! Stash shortcut pressed
void ps_stashShortcut(); void ps_requestStash();
private: private:
bool m_allowStash = false; //!< allow to stash bool m_stashingClearsSelection = true; //!< stashing unselects
//! Custom menu for the models which have been loaded
class CHighlightStashedModelsMenu : public BlackGui::IMenuDelegate
{
public:
//! Constructor
CHighlightStashedModelsMenu(CAircraftModelView *parent, bool separatorAtEnd) : IMenuDelegate(parent, separatorAtEnd) {}
//! \copydoc IMenuDelegate::customMenu
virtual void customMenu(QMenu &menu) const override;
};
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -208,24 +208,30 @@ namespace BlackGui
// resizing // resizing
menu.addAction(BlackMisc::CIcons::resize16(), "Full resize", this, SLOT(fullResizeToContents())); menu.addAction(BlackMisc::CIcons::resize16(), "Full resize", this, SLOT(fullResizeToContents()));
if (m_rowResizeMode == Interactive)
{
menu.addAction(BlackMisc::CIcons::resizeVertical16(), "Resize rows to content", this, SLOT(rowsResizeModeToContent()));
}
else
{
menu.addAction(BlackMisc::CIcons::resizeVertical16(), "Resize rows interactive", this, SLOT(rowsResizeModeToInteractive()));
}
// resize to content might decrease performance, // resize to content might decrease performance,
// so I only allow changing to "content resizing" if size matches // so I only allow changing to "content resizing" if size matches
bool enabled = !this->reachedResizeThreshold(); bool enabled = !this->reachedResizeThreshold();
bool autoResize = this->m_resizeMode == ResizingAuto;
// when not auto let set how we want to resize rows
if (m_rowResizeMode == Interactive)
{
QAction *a = menu.addAction(BlackMisc::CIcons::resizeVertical16(), " Resize rows to content (auto)", this, SLOT(rowsResizeModeToContent()));
a->setEnabled(enabled && !autoResize);
}
else
{
QAction *a = menu.addAction(BlackMisc::CIcons::resizeVertical16(), "Resize rows interactive", this, SLOT(rowsResizeModeToInteractive()));
a->setEnabled(!autoResize);
}
QAction *actionInteractiveResize = new QAction(&menu); QAction *actionInteractiveResize = new QAction(&menu);
actionInteractiveResize->setObjectName(this->objectName().append("ActionResizing")); actionInteractiveResize->setObjectName(this->objectName().append("ActionResizing"));
actionInteractiveResize->setIconText("Resize (auto)"); actionInteractiveResize->setIconText("Resize (auto)");
actionInteractiveResize->setIcon(CIcons::viewMultiColumn()); actionInteractiveResize->setIcon(CIcons::viewMultiColumn());
actionInteractiveResize->setCheckable(true); actionInteractiveResize->setCheckable(true);
actionInteractiveResize->setChecked(this->m_resizeMode == ResizingAuto); actionInteractiveResize->setChecked(autoResize);
actionInteractiveResize->setEnabled(enabled); actionInteractiveResize->setEnabled(enabled);
menu.addAction(actionInteractiveResize); menu.addAction(actionInteractiveResize);
connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::ps_toggleResizeMode); connect(actionInteractiveResize, &QAction::toggled, this, &CViewBaseNonTemplate::ps_toggleResizeMode);

View File

@@ -77,10 +77,14 @@ namespace BlackGui
MenuFilter = 1 << 5, ///< filter can be opened MenuFilter = 1 << 5, ///< filter can be opened
MenuSave = 1 << 6, ///< save as JSON MenuSave = 1 << 6, ///< save as JSON
MenuLoad = 1 << 7, ///< load from JSON MenuLoad = 1 << 7, ///< load from JSON
MenuLoadAndSave = MenuLoad | MenuSave, MenuLoadAndSave = MenuLoad | MenuSave,
MenuDefault = MenuClear | MenuDisplayAutomatically, MenuDefault = MenuClear | MenuDisplayAutomatically,
// special menu, should be in derived class but enums cannot be derived // special menus, should be in derived classes, but enums cannot be inherited
MenuHighlightDbData = 1 << 8, ///< highlight DB data // maybe shifted in the future to elsewhere
MenuHighlightDbData = 1 << 8, ///< highlight DB data
MenuHighlightStashed = 1 << 9, ///< highlight stashed models
MenuStashModels = 1 << 10, ///< stash models
MenuStashing = MenuHighlightStashed | MenuStashModels,
}; };
Q_DECLARE_FLAGS(Menu, MenuFlag) Q_DECLARE_FLAGS(Menu, MenuFlag)
@@ -332,6 +336,12 @@ namespace BlackGui
//! Save JSON called by shortcut //! Save JSON called by shortcut
virtual void ps_saveJsonShortcut(); virtual void ps_saveJsonShortcut();
// ------------ slots of CViewDbObjects ----------------
// need to be declared here and overridden, as this is the only part with valid Q_OBJECT
//! Highlight DB data
virtual void ps_toggleHighlightDbData() {}
private slots: private slots:
//! Custom menu was requested //! Custom menu was requested
void ps_customMenuRequested(QPoint pos); void ps_customMenuRequested(QPoint pos);
@@ -480,6 +490,8 @@ namespace BlackGui
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::performUpdateContainer //! \copydoc BlackGui::Views::CViewBaseNonTemplate::performUpdateContainer
virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize) override; virtual int performUpdateContainer(const BlackMisc::CVariant &variant, bool sort, bool resize) override;
// --------------------------------------------- SLOTS start here -----------------------------------------
//! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_filterDialogFinished //! \copydoc BlackGui::Views::CViewBaseNonTemplate::ps_filterDialogFinished
//! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT //! \remarks Actually a slot, but not defined as such as the template does not support Q_OBJECT
virtual bool ps_filterDialogFinished(int status) override; virtual bool ps_filterDialogFinished(int status) override;

View File

@@ -70,21 +70,35 @@ namespace BlackGui
return delta; return delta;
} }
template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
int CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::replaceOrAddObjectsByKey(const ContainerType &container)
{
if (container.isEmpty()) { return 0; }
ContainerType copy(this->container());
int c = copy.replaceOrAddObjectsByKey(container);
if (c == 0) { return 0; }
this->updateContainerMaybeAsync(copy);
return c;
}
template <class ModelClass, class ContainerType, class ObjectType, class KeyType> template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(QMenu &menu) const void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::customMenu(QMenu &menu) const
{ {
CViewBase<ModelClass, ContainerType, ObjectType>::customMenu(menu); CViewBase<ModelClass, ContainerType, ObjectType>::customMenu(menu);
if (this->m_menus.testFlag(CViewBase<ModelClass, ContainerType, ObjectType>::MenuHighlightDbData)) if (this->m_menus.testFlag(CViewBase<ModelClass, ContainerType, ObjectType>::MenuHighlightDbData))
{ {
menu.addSeparator(); if (!menu.isEmpty())
QAction *a = menu.addAction(CIcons::database16(), "Highlight DB data", this, SLOT(ps_toggleDbData())); {
menu.addSeparator();
}
QAction *a = menu.addAction(CIcons::database16(), "Highlight DB data", this, SLOT(ps_toggleHighlightDbData()));
a->setCheckable(true); a->setCheckable(true);
a->setChecked(this->derivedModel()->highlightDbData()); a->setChecked(this->derivedModel()->highlightDbData());
} }
} }
template <class ModelClass, class ContainerType, class ObjectType, class KeyType> template <class ModelClass, class ContainerType, class ObjectType, class KeyType>
void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleDbData() void CViewWithDbObjects<ModelClass, ContainerType, ObjectType, KeyType>::ps_toggleHighlightDbData()
{ {
bool h = this->derivedModel()->highlightDbData(); bool h = this->derivedModel()->highlightDbData();
this->derivedModel()->setHighlightDbData(!h); this->derivedModel()->setHighlightDbData(!h);

View File

@@ -37,6 +37,9 @@ namespace BlackGui
//! Remove keys //! Remove keys
int removeDbKeys(const QList<KeyType> &keys); int removeDbKeys(const QList<KeyType> &keys);
//! Update or insert data (based on DB key)
int replaceOrAddObjectsByKey(const ContainerType &container);
protected: protected:
//! Constructor //! Constructor
explicit CViewWithDbObjects(QWidget *parent = nullptr); explicit CViewWithDbObjects(QWidget *parent = nullptr);
@@ -44,9 +47,9 @@ namespace BlackGui
//! \copydoc QWidget::customMenu //! \copydoc QWidget::customMenu
virtual void customMenu(QMenu &menu) const override; virtual void customMenu(QMenu &menu) const override;
private slots: protected slots:
//! Highlight DB data //! \copydoc CViewBaseNonTemplate::ps_toggleHighlightDbData
void ps_toggleDbData(); virtual void ps_toggleHighlightDbData() override;
}; };
} // namespace } // namespace
} // namespace } // namespace