refs #743, bottom bar to switch simulator for own models

(like for model set, not only by context menu but also by radio buttons)
This commit is contained in:
Klaus Basan
2016-10-02 23:26:13 +02:00
committed by Mathew Sutcliffe
parent 09bd981e81
commit c4a61c275d
3 changed files with 125 additions and 9 deletions

View File

@@ -10,6 +10,7 @@
#include "blackcore/webdataservices.h"
#include "blackcore/db/databaseutils.h"
#include "blackgui/components/dbownmodelscomponent.h"
#include "blackgui/components/simulatorselector.h"
#include "blackgui/guiapplication.h"
#include "blackgui/menus/aircraftmodelmenus.h"
#include "blackgui/menus/menuaction.h"
@@ -41,6 +42,7 @@ namespace BlackGui
ui(new Ui::CDbOwnModelsComponent)
{
ui->setupUi(this);
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping);
ui->tvp_OwnAircraftModels->addFilterDialog();
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
@@ -51,8 +53,8 @@ namespace BlackGui
// should be single simulator or no simulator (default)
this->m_simulatorSelection.synchronize();
const CSimulatorInfo simulator(this->m_simulatorSelection.get());
const bool s = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator);
if (s)
const bool succes = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator);
if (succes)
{
this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly);
}
@@ -61,6 +63,10 @@ namespace BlackGui
CLogMessage(this).error("Init of model loader failed in component");
}
ui->comp_SimulatorSelector->setValue(simulator);
ui->le_Simulator->setText(simulator.toQString());
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelsComponent::ps_requestSimulatorModelsWithCacheInBackground);
// menu
ui->tvp_OwnAircraftModels->setCustomMenu(new CConsolidateWithDbDataMenu(ui->tvp_OwnAircraftModels, this, false));
}
@@ -98,6 +104,13 @@ namespace BlackGui
return this->m_modelLoader->getAircraftModels();
}
CAircraftModelList CDbOwnModelsComponent::getOwnCachedModels(const CSimulatorInfo &simulator) const
{
static const CAircraftModelList empty;
if (!this->m_modelLoader) { return empty; }
return this->m_modelLoader->getCachedAircraftModels(simulator);
}
CAircraftModelList CDbOwnModelsComponent::getOwnSelectedModels() const
{
return ui->tvp_OwnAircraftModels->selectedObjects();
@@ -122,6 +135,18 @@ namespace BlackGui
return this->m_modelLoader->getAircraftModelsCount();
}
QString CDbOwnModelsComponent::getInfoString() const
{
if (!this->m_modelLoader) { return ""; }
return this->m_modelLoader->getInfoString();
}
QString CDbOwnModelsComponent::getInfoStringFsFamily() const
{
if (!this->m_modelLoader) { return ""; }
return this->m_modelLoader->getInfoStringFsFamily();
}
CStatusMessage CDbOwnModelsComponent::updateViewAndCache(const CAircraftModelList &models)
{
const CStatusMessage m = this->m_modelLoader->setCachedModels(models, this->getOwnModelsSimulator());
@@ -196,8 +221,7 @@ namespace BlackGui
QString CDbOwnModelsComponent::directorySelector(const CSimulatorInfo &simulatorInfo)
{
const QString text("Open directory (%1)");
const QString dir = QFileDialog::getExistingDirectory(nullptr, text.arg(simulatorInfo.toQString()),
"",
const QString dir = QFileDialog::getExistingDirectory(nullptr, text.arg(simulatorInfo.toQString()), "",
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
return dir;
}
@@ -222,7 +246,7 @@ namespace BlackGui
connect(this->m_loadActions[0], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked)
{
Q_UNUSED(checked);
ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FSX), IAircraftModelLoader::InBackgroundWithCache);
ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::FSX));
});
}
menuActions.addAction(this->m_loadActions[0], CMenuAction::pathSimulator());
@@ -235,7 +259,7 @@ namespace BlackGui
connect(this->m_loadActions[1], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked)
{
Q_UNUSED(checked);
ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::P3D), IAircraftModelLoader::InBackgroundWithCache);
ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::P3D));
});
}
menuActions.addAction(this->m_loadActions[1], CMenuAction::pathSimulator());
@@ -248,7 +272,7 @@ namespace BlackGui
connect(this->m_loadActions[2], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked)
{
Q_UNUSED(checked);
ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::FS9), IAircraftModelLoader::InBackgroundWithCache);
ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::FS9));
});
}
menuActions.addAction(this->m_loadActions[2], CMenuAction::pathSimulator());
@@ -261,7 +285,7 @@ namespace BlackGui
connect(this->m_loadActions[3], &QAction::triggered, ownModelsComp, [ownModelsComp](bool checked)
{
Q_UNUSED(checked);
ownModelsComp->ps_requestSimulatorModels(CSimulatorInfo(CSimulatorInfo::XPLANE), IAircraftModelLoader::InBackgroundWithCache);
ownModelsComp->ps_requestSimulatorModelsWithCacheInBackground(CSimulatorInfo(CSimulatorInfo::XPLANE));
});
}
menuActions.addAction(this->m_loadActions[3], CMenuAction::pathSimulator());
@@ -435,11 +459,18 @@ namespace BlackGui
CLogMessage(this).error("Loading of models failed, simulator %1") << simulator.toQString();
}
ui->tvp_OwnAircraftModels->hideLoadIndicator();
ui->le_Simulator->setText(simulator.toQString());
ui->comp_SimulatorSelector->setValue(simulator);
}
void CDbOwnModelsComponent::ps_requestSimulatorModels(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode, const QString &directory)
{
this->ps_loadInstalledModels(simulator, mode, directory);
}
void CDbOwnModelsComponent::ps_requestSimulatorModelsWithCacheInBackground(const CSimulatorInfo &simulator)
{
this->ps_requestSimulatorModels(simulator, IAircraftModelLoader::InBackgroundWithCache);
}
} // ns
} // ns

View File

@@ -70,6 +70,9 @@ namespace BlackGui
//! Own models
BlackMisc::Simulation::CAircraftModelList getOwnModels() const;
//! Own cached models from loader
BlackMisc::Simulation::CAircraftModelList getOwnCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const;
//! Own models selected in view
BlackMisc::Simulation::CAircraftModelList getOwnSelectedModels() const;
@@ -82,6 +85,12 @@ namespace BlackGui
//! Number of own models
int getOwnModelsCount() const;
//! \copydoc BlackMisc::Simulation::Data::CModelCaches::getInfoString
QString getInfoString() const;
//! \copydoc BlackMisc::Simulation::Data::CModelCaches::getInfoStringFsFamily
QString getInfoStringFsFamily() const;
//! Update view and cache
BlackMisc::CStatusMessage updateViewAndCache(const BlackMisc::Simulation::CAircraftModelList &models);
@@ -118,6 +127,9 @@ namespace BlackGui
//! Request simulator models
void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode, const QString &directory = "");
//! Request simulator models from cache
void ps_requestSimulatorModelsWithCacheInBackground(const BlackMisc::Simulation::CSimulatorInfo &simulator);
private:
QScopedPointer<Ui::CDbOwnModelsComponent> ui;
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
@@ -129,7 +141,7 @@ namespace BlackGui
//! File name for savinf
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);
//! Directory selector
//! Directory selector for given simulator
static QString directorySelector(const BlackMisc::Simulation::CSimulatorInfo &simulatorInfo);
//! The menu for loading and handling own models for mapping tasks

View File

@@ -45,6 +45,73 @@
</attribute>
</widget>
</item>
<item>
<widget class="QFrame" name="fr_Simulator">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="hl_Simulator">
<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::Components::CSimulatorSelector" name="comp_SimulatorSelector">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<spacer name="hs_Simulator">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QLabel" name="lbl_Simulator">
<property name="text">
<string>Simulator:</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="le_Simulator">
<property name="maximumSize">
<size>
<width>100</width>
<height>16777215</height>
</size>
</property>
<property name="placeholderText">
<string>Simulator</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<customwidgets>
@@ -53,6 +120,12 @@
<extends>QTableView</extends>
<header>blackgui/views/aircraftmodelview.h</header>
</customwidget>
<customwidget>
<class>BlackGui::Components::CSimulatorSelector</class>
<extends>QFrame</extends>
<header>blackgui/components/simulatorselector.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>