refs #377 usability improvements

* allow to toggle between single, multi and extended selection
* all DB data can be read by menu
* fixed load/save (test data) from disk
This commit is contained in:
Klaus Basan
2016-01-20 01:05:02 +01:00
parent ef259539c5
commit 551f3348f4
7 changed files with 85 additions and 24 deletions

View File

@@ -82,8 +82,14 @@ namespace BlackGui
bool CDataInfoAreaComponent::writeDbDataToResourceDir() const
{
bool s = hasProvider() &&
this->writeDbDataToDisk(CProject::getSwiftStaticDbFilesDir());
if (!this->hasProvider() || !this->canConnectSwiftDb())
{
CLogMessage(this).warning("No connection to DB yet, no new data loaded which can be written");
return false;
}
// write to disk
bool s = this->writeDbDataToDisk(CProject::getSwiftStaticDbFilesDir());
if (s)
{
CLogMessage(this).info("Written DB data");
@@ -103,7 +109,7 @@ namespace BlackGui
// info
if (s)
{
CLogMessage(this).info("Read DB data: %1") << CProject::getSwiftStaticDbFilesDir();
CLogMessage(this).info("Read DB data from directory: %1") << CProject::getSwiftStaticDbFilesDir();
this->ui->comp_DbAircraftIcao->showLoadIndicator();
this->ui->comp_DbAirlineIcao->showLoadIndicator();
this->ui->comp_DbCountries->showLoadIndicator();
@@ -155,6 +161,11 @@ namespace BlackGui
}
}
void CDataInfoAreaComponent::requestUpdateOfAllDbData()
{
this->triggerRead(CEntityFlags::AllDbEntities, QDateTime());
}
void CDataInfoAreaComponent::requestUpdatedData(CEntityFlags::Entity entity)
{
bool requested = false;

View File

@@ -89,6 +89,9 @@ namespace BlackGui
//! Load from resource dir
bool readDbDataFromResourceDir();
//! Request update of all DB data
void requestUpdateOfAllDbData();
//! Load new data (based on timestamp, incremental)
void requestUpdatedData(BlackMisc::Network::CEntityFlags::Entity entity);

View File

@@ -58,7 +58,7 @@ namespace BlackGui
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
ui->tvp_OwnAircraftModels->setCustomMenu(new CMappingSimulatorModelMenu(this));
ui->tvp_OwnAircraftModels->setCustomMenu(new CRemoveDbModelsMenu(this));
ui->tvp_OwnAircraftModels->setCustomMenu(new CModelStashTools(this));
ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(this->m_cachedOwnModels.get());
// how to display forms
@@ -94,7 +94,7 @@ namespace BlackGui
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 CRemoveDbModelsMenu(this));
this->ui->tvp_AircraftModelsForVPilot->setCustomMenu(new CModelStashTools(this));
this->ui->tvp_AircraftModelsForVPilot->setDisplayAutomatically(true);
this->ui->tvp_AircraftModelsForVPilot->addFilterDialog();
const CAircraftModelList cachedModels(m_cachedVPilotModels.get());
@@ -165,6 +165,7 @@ namespace BlackGui
void CDbMappingComponent::setProvider(BlackMisc::Network::IWebDataServicesProvider *provider)
{
CWebDataServicesAware::setProvider(provider);
this->m_autostashDialog->setProvider(provider);
this->ui->editor_Livery->setProvider(provider);
this->ui->editor_Distributor->setProvider(provider);
this->ui->editor_AircraftIcao->setProvider(provider);
@@ -309,6 +310,11 @@ namespace BlackGui
}
}
void CDbMappingComponent::ps_displayAutoStashingDialog()
{
this->m_autostashDialog->setVisible(true);
}
void CDbMappingComponent::ps_removeDbModelsFromView()
{
QStringList modelStrings(this->getModelStrings());
@@ -447,7 +453,7 @@ namespace BlackGui
if (!sims.isEmpty()) { o = o.append(" ").append(sims); }
}
QString f = this->ui->tvp_OwnAircraftModels->derivedModel()->hasFilter() ? "F" : "";
o = CGuiUtility::replaceTabCountValue(o, this->ui->tvp_AircraftModelsForVPilot->rowCount()) + f;
o = CGuiUtility::replaceTabCountValue(o, this->ui->tvp_OwnAircraftModels->rowCount()) + f;
this->ui->tw_ModelsToBeMapped->setTabText(i, o);
}
@@ -628,26 +634,34 @@ namespace BlackGui
return qobject_cast<CDbMappingComponent *>(this->parent());
}
void CDbMappingComponent::CRemoveDbModelsMenu::customMenu(QMenu &menu) const
void CDbMappingComponent::CModelStashTools::customMenu(QMenu &menu) const
{
CDbMappingComponent *mapComp = mappingComponent();
Q_ASSERT_X(mapComp, Q_FUNC_INFO, "no mapping component");
int dbModels = mapComp->getModelsCount();
if (dbModels > 0)
bool canConnectDb = mapComp->canConnectSwiftDb();
if (canConnectDb)
{
if (!mapComp->currentModelView()->isEmpty())
{
this->addSeparator(menu);
int dbModels = mapComp->getModelsCount();
if (dbModels > 0)
{
// we have keys and data where we could delete them from
const QString msgDelete("Delete " + QString::number(dbModels) + " DB model(s) from " + mapComp->currentTabText());
menu.addAction(CIcons::delete16(), msgDelete, mapComp, SLOT(ps_removeDbModelsFromView()));
}
// we have keys and data where we could delete them from
QString m("Delete " + QString::number(dbModels) + " DB model(s) from " + mapComp->currentTabText());
menu.addAction(CIcons::delete16(), m, mapComp, SLOT(ps_removeDbModelsFromView()));
const QString msgAutoStash("Auto stashing");
menu.addAction(CIcons::appDbStash16(), msgAutoStash, mapComp, SLOT(ps_displayAutoStashingDialog()));
}
}
this->nestedCustomMenu(menu);
}
CDbMappingComponent *CDbMappingComponent::CRemoveDbModelsMenu::mappingComponent() const
CDbMappingComponent *CDbMappingComponent::CModelStashTools::mappingComponent() const
{
return qobject_cast<CDbMappingComponent *>(this->parent());
}

View File

@@ -19,6 +19,7 @@
#include "blackgui/menudelegate.h"
#include "blackgui/enableforviewbasedindicator.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/components/dbautostashingcomponent.h"
#include "blackgui/views/aircraftmodelview.h"
#include "blackmisc/simulation/aircraftmodelloader.h"
#include "blackmisc/simulation/fscommon/vpilotrulesreader.h"
@@ -175,11 +176,15 @@ namespace BlackGui
//! Stash current model
void ps_stashCurrentModel();
//! Display auto stashing dialog
void ps_displayAutoStashingDialog();
//! Remove DB models from current view
void ps_removeDbModelsFromView();
private:
QScopedPointer<Ui::CDbMappingComponent> ui;
QScopedArrayPointer<CDbAutoStashingComponent> m_autostashDialog { new CDbAutoStashingComponent(this) };
BlackMisc::Simulation::FsCommon::CVPilotRulesReader m_vPilotReader; //!< read vPilot rules
BlackMisc::CData<BlackCore::Data::VPilotAircraftModels> m_cachedVPilotModels { this, &CDbMappingComponent::ps_onVPilotCacheChanged }; //!< cache for latest vPilot rules
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
@@ -240,13 +245,15 @@ namespace BlackGui
CDbMappingComponent *mappingComponent() const;
};
//! Menu for removing DB models from current view
//! Menu for tools:
//! 1) removing DB models from current view and
//! 2) for auto stashing
//! \note This is a specific menu for that very component
class CRemoveDbModelsMenu : public BlackGui::IMenuDelegate
class CModelStashTools : public BlackGui::IMenuDelegate
{
public:
//! Constructor
CRemoveDbModelsMenu(CDbMappingComponent *mappingComponent, bool separator = true) :
CModelStashTools(CDbMappingComponent *mappingComponent, bool separator = true) :
BlackGui::IMenuDelegate(mappingComponent, separator)
{}

View File

@@ -207,11 +207,15 @@ namespace BlackGui
{
if (sm == SingleSelection)
{
menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode()));
QAction *a = menu.addAction(QIcon(), "Switch to multi selection", this, SLOT(ps_toggleSelectionMode()));
a->setData("multi");
a = menu.addAction(QIcon(), "Switch to extended selection", this, SLOT(ps_toggleSelectionMode()));
a->setData("extended");
}
else if (sm == MultiSelection || sm == ExtendedSelection)
{
menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode()));
QAction *a = menu.addAction(QIcon(), "Switch to single selection", this, SLOT(ps_toggleSelectionMode()));
a->setData("single");
}
}
if (sm != NoSelection)
@@ -533,9 +537,29 @@ namespace BlackGui
{
if (this->selectionMode() == SingleSelection)
{
this->setSelectionMode(this->m_originalSelectionMode);
QAction *action = qobject_cast<QAction *>(sender());
if (action && action->data().canConvert<QString>())
{
QString data(action->data().toString().toLower());
if (data.startsWith('e'))
{
this->setSelectionMode(ExtendedSelection);
}
else if (data.startsWith('m'))
{
this->setSelectionMode(MultiSelection);
}
else
{
this->setSelectionMode(this->m_originalSelectionMode);
}
}
else
{
this->setSelectionMode(this->m_originalSelectionMode);
}
}
else if (this->selectionMode() == MultiSelection)
else if (this->selectionMode() == MultiSelection || this->selectionMode() == ExtendedSelection)
{
this->setSelectionMode(SingleSelection);
}

View File

@@ -39,9 +39,10 @@ namespace BlackMisc
DistributorEntity = 1 << 6, ///< distributors
LiveryEntity = 1 << 7, ///< liveries
ModelEntity = 1 << 8, ///< models
AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, ///< all ICAO codes
AllIcaoEntities = AircraftIcaoEntity | AirlineIcaoEntity, ///< all ICAO codes
AllIcaoAndCountries = AircraftIcaoEntity | AirlineIcaoEntity | CountryEntity, ///< all ICAO codes and countries
DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, ///< Combinded
DistributorLiveryModel = DistributorEntity | LiveryEntity | ModelEntity, ///< Combinded
AllDbEntities = AllIcaoEntities | DistributorLiveryModel, ///< All DB stuff
AllEntities = 0xFFFF ///< everything
};
Q_DECLARE_FLAGS(Entity, EntityFlag)

View File

@@ -156,10 +156,11 @@ void CSwiftData::initDynamicMenus()
{
Q_ASSERT_X(this->ui->comp_MainInfoArea, Q_FUNC_INFO, "Missing main info area");
Q_ASSERT_X(this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), Q_FUNC_INFO, "Missing DB info area");
this->ui->menu_Mapping->addAction(CIcons::load16(), "Load DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(readDbDataFromResourceDir()));
if (CProject::isRunningInDeveloperEnvironment() && this->m_webDataReader && this->m_webDataReader->canConnectSwiftDb())
this->ui->menu_Mapping->addAction(CIcons::database16(), "Load all DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(requestUpdateOfAllDbData()));
this->ui->menu_Mapping->addAction(CIcons::load16(), "Load DB test data from disk", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(readDbDataFromResourceDir()));
if (CProject::isRunningInDeveloperEnvironment())
{
this->ui->menu_Mapping->addAction(CIcons::save16(), "Save DB data", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(writeDbDataToResourceDir()));
this->ui->menu_Mapping->addAction(CIcons::save16(), "Save DB test data to disk", this->ui->comp_MainInfoArea->getDataInfoAreaComponent(), SLOT(writeDbDataToResourceDir()));
}
}
}