refs #661, improved own model set handling

* fixed simulator selector
* added simulator selector to own model set component
* pinned last selections
* fixed model cache to use "getCopy"
This commit is contained in:
Klaus Basan
2016-05-24 18:24:23 +02:00
parent 0ff7791532
commit c0fda8687d
7 changed files with 62 additions and 21 deletions

View File

@@ -62,10 +62,12 @@ namespace BlackGui
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuOrderable);
ui->tvp_OwnModelSet->setSorting(CAircraftModel::IndexOrderString);
ui->tvp_OwnModelSet->initAsOrderable();
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::RadioButtons);
connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(ui->pb_LoadExistingSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(ui->comp_SimulatorSelector, &CSimulatorSelector::changed, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelDataChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_modelChanged);
@@ -74,10 +76,13 @@ namespace BlackGui
const CSimulatorInfo sim = this->m_modelSetLoader.getSimulator();
if (sim.isSingleSimulator())
{
ui->tvp_OwnModelSet->updateContainerMaybeAsync(this->m_modelSetLoader.getAircraftModels());
// update display when all is set up
this->m_modelSetLoader.syncronizeCache(); // make sure data are loaded
QTimer::singleShot(500, [this, sim]()
{
this->ps_changeSimulator(sim);
});
}
const int c = this->m_modelSetLoader.getAircraftModelsCount();
this->ps_onRowCountChanged(c, ui->tvp_OwnModelSet->hasFilter());
}
CDbOwnModelSetComponent::~CDbOwnModelSetComponent()
@@ -294,7 +299,8 @@ namespace BlackGui
{
if (this->m_modelSetLoader.getSimulator() == simulator) { return; } // avoid unnecessary signals
this->m_modelSetLoader.changeSimulator(simulator);
this->ui->le_Simulator->setText(simulator.toQString(true));
ui->le_Simulator->setText(simulator.toQString(true));
ui->comp_SimulatorSelector->setValue(simulator);
}
void CDbOwnModelSetComponent::updateDistributorOrder(const CSimulatorInfo &simulator)

View File

@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
<width>796</width>
<height>224</height>
</rect>
</property>
<property name="windowTitle">
@@ -64,7 +64,23 @@
<number>0</number>
</property>
<item>
<spacer name="hs_Buttons">
<widget class="BlackGui::Components::CSimulatorSelector" name="comp_SimulatorSelector">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
</widget>
</item>
<item>
<spacer name="hs_OwnModelSetButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -158,6 +174,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/>

View File

@@ -84,15 +84,17 @@ namespace BlackGui
const CSimulatorInfo current(getValue());
if (simulator == current) { return; } // avoid unnecessary signals
// checkboxes
this->ui->cb_FSX->setChecked(simulator.fsx());
this->ui->cb_FS9->setChecked(simulator.fs9());
this->ui->cb_XPlane->setChecked(simulator.xplane());
this->ui->cb_P3D->setChecked(simulator.p3d());
if (simulator.fsx()) { this->ui->cb_FSX->setChecked(simulator.fsx()); return; }
if (simulator.fs9()) { this->ui->cb_FS9->setChecked(simulator.fs9()); return; }
if (simulator.xplane()) { this->ui->cb_XPlane->setChecked(simulator.xplane()); return; }
if (simulator.p3d()) { this->ui->cb_P3D->setChecked(simulator.p3d()); return; }
// radio buttons
if (simulator.fsx()) { this->ui->rb_FSX->setChecked(simulator.fsx()); return; }
if (simulator.fs9()) { this->ui->rb_FS9->setChecked(simulator.fs9()); return; }
if (simulator.xplane()) { this->ui->rb_XPlane->setChecked(simulator.xplane()); return; }
if (simulator.p3d()) { this->ui->rb_P3D->setChecked(simulator.p3d()); return; }
}
void CSimulatorSelector::setAll()

View File

@@ -59,7 +59,8 @@ namespace BlackMisc
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->m_caches.syncronizeCache(simulator);
if (this->getSimulator() == simulator) { return; }
this->m_caches.syncronizeCache(simulator); // also changes current simulator of caches
emit simulatorChanged(simulator);
}
@@ -74,6 +75,11 @@ namespace BlackMisc
return this->m_caches.getCachedModels(simulator);
}
int CAircraftModelSetLoader::getAircraftModelsCount() const
{
return getAircraftModels().size();
}
CAircraftModel CAircraftModelSetLoader::getModelForModelString(const QString &modelString) const
{
if (modelString.isEmpty()) { return CAircraftModel(); }

View File

@@ -51,6 +51,9 @@ namespace BlackMisc
//! Destructor
virtual ~CAircraftModelSetLoader();
//! Make sure cache is syncronized
bool syncronizeCache();
//! The loaded models
//! \threadsafe
BlackMisc::Simulation::CAircraftModelList getAircraftModels() const;
@@ -61,7 +64,7 @@ namespace BlackMisc
//! Count of loaded models
//! \threadsafe
int getAircraftModelsCount() const { return getAircraftModels().size(); }
int getAircraftModelsCount() const;
//! Model for given model string
//! \threadsafe
@@ -110,9 +113,6 @@ namespace BlackMisc
//! Cache timestamp
QDateTime getCacheTimestamp() const;
//! Make sure cache is syncronized
bool syncronizeCache();
//! Any cached data?
bool hasCachedData() const;

View File

@@ -50,10 +50,10 @@ namespace BlackMisc
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.get();
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.get();
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.get();
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.get();
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.getCopy();
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.getCopy();
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.getCopy();
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.getCopy();
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
return CAircraftModelList();

View File

@@ -72,6 +72,9 @@ namespace BlackMisc
//! Last selection
struct ModelCacheLastSelection : public BlackMisc::CDataTrait<BlackMisc::Simulation::CSimulatorInfo>
{
//! First load is synchronous
static constexpr bool isPinned() { return true; }
//! Key
static const char *key() { return "modelcachelastselection"; }
};
@@ -111,6 +114,9 @@ namespace BlackMisc
//! Last selection
struct ModelSetLastSelection : public BlackMisc::CDataTrait<BlackMisc::Simulation::CSimulatorInfo>
{
//! First load is synchronous
static constexpr bool isPinned() { return true; }
//! Key
static const char *key() { return "modelsetlastselection"; }
};
@@ -231,7 +237,6 @@ namespace BlackMisc
//! @}
private:
//! \todo Why can`t I keep the changed functions in IMultiSimulatorModelCaches -> C2039 not a member
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFsx> m_modelCacheFsx {this, &CModelSetCaches::changedFsx }; //!< FSX cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheFs9> m_modelCacheFs9 {this, &CModelSetCaches::changedFs9}; //!< FS9 cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D cache