refs #641, moved last simulator selection to caches

* removed from component cache
* kept renamed component caches as stubs for later usage

refs #646, removed gui state cache as it causes build issues on Jenkins
(idea was to keep the classes as stubs for later usage)
This commit is contained in:
Klaus Basan
2016-04-25 01:08:10 +02:00
parent 48bcb105cd
commit 43f9515eaa
20 changed files with 320 additions and 392 deletions

View File

@@ -31,9 +31,9 @@ HEADERS += $$PWD/views/*.h
SOURCES += $$PWD/views/*.cpp
HEADERS += $$PWD/components/*.h
HEADERS += $$PWD/components/data/*.h
# HEADERS += $$PWD/components/data/*.h
SOURCES += $$PWD/components/*.cpp
SOURCES += $$PWD/components/data/*.cpp
# SOURCES += $$PWD/components/data/*.cpp
FORMS += $$PWD/components/*.ui
HEADERS += $$PWD/filters/*.h

View File

@@ -1,71 +0,0 @@
/* Copyright (C) 2016
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "lastselections.h"
using namespace BlackMisc;
namespace BlackGui
{
namespace Components
{
namespace Data
{
QString CDbOwnModelsComponent::convertToQString(bool i18n) const
{
QString s(this->m_simulator.toQString(i18n));
return s;
}
CVariant CDbOwnModelsComponent::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexLastSimulator:
return this->m_simulator.propertyByIndex(index.copyFrontRemoved());
default:
return CValueObject::propertyByIndex(index);
}
}
void CDbOwnModelsComponent::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself()) { (*this) = variant.to<CDbOwnModelsComponent>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexLastSimulator:
this->m_simulator.setPropertyByIndex(variant, index.copyFrontRemoved());
break;
default:
CValueObject::setPropertyByIndex(variant, index);
break;
}
}
int CDbOwnModelsComponent::comparePropertyByIndex(const CDbOwnModelsComponent &compareValue, const CPropertyIndex &index) const
{
if (index.isMyself()) { return this->toQString().compare(compareValue.toQString()); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexLastSimulator:
return this->m_simulator.comparePropertyByIndex(compareValue.getLastSimulatorSelection(), index.copyFrontRemoved());
default:
break;
}
Q_ASSERT_X(false, Q_FUNC_INFO, "No comparison");
return 0;
}
} // ns
} // ns
} // ns

View File

@@ -1,91 +0,0 @@
/* Copyright (C) 2016
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_COMPONENTS_DATA_LASTSELECTIONS_H
#define BLACKGUI_COMPONENTS_DATA_LASTSELECTIONS_H
#include "blackgui/blackguiexport.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/datacache.h"
#include "blackmisc/simulation/simulatorinfo.h"
namespace BlackGui
{
namespace Components
{
namespace Data
{
/*!
* Store last selections/interactions with this component
*/
class BLACKGUI_EXPORT CDbOwnModelsComponent : public BlackMisc::CValueObject<CDbOwnModelsComponent>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexLastSimulator = BlackMisc::CPropertyIndex::GlobalIndexCDbOwnModelsComponent
};
//! Constructor
CDbOwnModelsComponent() {}
//! Simulator last selected
const BlackMisc::Simulation::CSimulatorInfo &getLastSimulatorSelection() const { return m_simulator; }
//! Simulator last selected
void setLastSimulatorSelection(const BlackMisc::Simulation::CSimulatorInfo &simulator) { m_simulator = simulator; }
//! \copydoc BlackMisc::Mixin::String::toQString
QString convertToQString(bool i18n = false) const;
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
void setPropertyByIndex(const BlackMisc::CVariant &variant, const BlackMisc::CPropertyIndex &index);
//! Compare by index
int comparePropertyByIndex(const CDbOwnModelsComponent &compareValue, const BlackMisc::CPropertyIndex &index) const;
private:
BlackMisc::Simulation::CSimulatorInfo m_simulator; //!< Last simulator selection
BLACK_METACLASS(
CDbOwnModelsComponent,
BLACK_METAMEMBER(simulator)
);
};
//! Trait for model cache
struct DbOwnModelsComponent : public BlackMisc::CDataTrait<CDbOwnModelsComponent>
{
//! Default value
static const CDbOwnModelsComponent &defaultValue()
{
static const CDbOwnModelsComponent ls;
return ls;
}
//! First load is synchronous
static bool isPinned() { return true; }
//! Key in data cache
static const char *key() { return "dbownmodelscomponent"; }
};
} // ns
} // ns
} // ns
Q_DECLARE_METATYPE(BlackGui::Components::Data::CDbOwnModelsComponent)
#endif // guard

View File

@@ -699,7 +699,7 @@ namespace BlackGui
return this->ui->comp_OwnAircraftModels->getOwnModelForModelString(modelString);
}
const CSimulatorInfo &CDbMappingComponent::getOwnModelsSimulator() const
const CSimulatorInfo CDbMappingComponent::getOwnModelsSimulator() const
{
return this->ui->comp_OwnAircraftModels->getOwnModelsSimulator();
}

View File

@@ -18,7 +18,6 @@
#include "blackgui/menus/menudelegate.h"
#include "blackgui/enableforviewbasedindicator.h"
#include "blackgui/components/enablefordockwidgetinfoarea.h"
#include "blackgui/components/data/lastselections.h"
#include "blackgui/views/aircraftmodelview.h"
#include "blackmisc/simulation/aircraftmodelloader.h"
#include "blackmisc/simulation/fscommon/vpilotrulesreader.h"
@@ -112,7 +111,7 @@ namespace BlackGui
BlackMisc::Simulation::CAircraftModel getOwnModelForModelString(const QString &modelString) const;
//! Own models for simulator
const BlackMisc::Simulation::CSimulatorInfo &getOwnModelsSimulator() const;
const Simulation::CSimulatorInfo getOwnModelsSimulator() const;
//! Number of own models
int getOwnModelsCount() const;

View File

@@ -33,22 +33,23 @@ namespace BlackGui
ui->tvp_OwnAircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnSimulatorModelMapping);
ui->tvp_OwnAircraftModels->addFilterDialog();
ui->tvp_OwnAircraftModels->setDisplayAutomatically(true);
ui->tvp_OwnAircraftModels->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnAircraftModels, this->modelLoader(), false));
ui->tvp_OwnAircraftModels->setCustomMenu(new CLoadModelsMenu(this, true));
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::requestUpdate, this, &CDbOwnModelsComponent::ps_requestOwnModelsUpdate);
this->m_lastInteractions.synchronize();
// should be single simulator or no simulator (default)
const CSimulatorInfo sim = this->m_lastInteractions.getCopy().getLastSimulatorSelection();
BLACK_VERIFY_X(!sim.isMultipleSimulators(), Q_FUNC_INFO, "Should be single simulator or default");
if (sim.isSingleSimulator())
this->m_simulatorSelection.synchronize();
const CSimulatorInfo simulator(this->m_simulatorSelection.get());
const bool s = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator);
if (s)
{
// if we have already use this before, use it again, but only from cache
this->initModelLoader(sim);
this->m_modelLoader->startLoading(IAircraftModelLoader::CacheOnly);
}
ui->tvp_OwnAircraftModels->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnAircraftModels, this->modelLoader(), false));
ui->tvp_OwnAircraftModels->setCustomMenu(new CLoadModelsMenu(this, true));
else
{
CLogMessage(this).error("Init of model loader failed in component");
}
}
CDbOwnModelsComponent::~CDbOwnModelsComponent()
@@ -89,7 +90,7 @@ namespace BlackGui
return ui->tvp_OwnAircraftModels->selectedObjects();
}
const CSimulatorInfo &CDbOwnModelsComponent::getOwnModelsSimulator() const
const CSimulatorInfo CDbOwnModelsComponent::getOwnModelsSimulator() const
{
static const CSimulatorInfo noSim;
if (!this->m_modelLoader) { return noSim; }
@@ -117,27 +118,28 @@ namespace BlackGui
if (this->m_modelLoader) { this->m_modelLoader->gracefulShutdown(); }
}
bool CDbOwnModelsComponent::initModelLoader(const CSimulatorInfo &simInfo)
bool CDbOwnModelsComponent::initModelLoader(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
// already loaded
Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
if (this->m_modelLoader && this->m_modelLoader->supportsSimulator(simInfo))
if (this->m_modelLoader && this->m_modelLoader->supportsSimulator(simulator))
{
this->setSaveFileName(simInfo);
this->setSaveFileName(simulator);
return true;
}
// unload old
// mismatching loader
if (this->m_modelLoader)
{
this->m_modelLoader->gracefulShutdown();
}
// create loader, also syncronizes the caches
this->m_modelLoader = IAircraftModelLoader::createModelLoader(simInfo);
if (!this->m_modelLoader || !this->m_modelLoader->supportsSimulator(simInfo))
this->m_modelLoader = IAircraftModelLoader::createModelLoader(simulator); // last selected simulator or explicit given
if (!this->m_modelLoader || !this->m_modelLoader->supportsSimulator(simulator))
{
CLogMessage(this).error("Failed to init model loader %1") << simInfo.toQString();
CLogMessage(this).error("Failed to init model loader %1") << simulator.toQString();
this->m_modelLoader.reset();
return false;
}
@@ -146,7 +148,7 @@ namespace BlackGui
bool c = connect(this->m_modelLoader.get(), &IAircraftModelLoader::loadingFinished, this, &CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished);
Q_ASSERT_X(c, Q_FUNC_INFO, "Failed connect for model loader");
Q_UNUSED(c);
this->setSaveFileName(simInfo);
this->setSaveFileName(simulator);
return true;
}
}
@@ -242,45 +244,35 @@ namespace BlackGui
);
}
void CDbOwnModelsComponent::ps_loadInstalledModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode)
void CDbOwnModelsComponent::ps_loadInstalledModels(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode)
{
if (!this->initModelLoader(simInfo))
if (!this->initModelLoader(simulator))
{
CLogMessage(this).error("Cannot load model loader for %1") << simInfo.toQString();
CLogMessage(this).error("Cannot load model loader for %1") << simulator.toQString();
return;
}
if (!this->m_modelLoader->isLoadingFinished())
{
CLogMessage(this).info("Loading for %1 already in progress") << simInfo.toQString();
CLogMessage(this).info("Loading for %1 already in progress") << simulator.toQString();
return;
}
CLogMessage(this).info("Starting loading for %1") << simInfo.toQString();
CLogMessage(this).info("Starting loading for %1") << simulator.toQString();
this->ui->tvp_OwnAircraftModels->showLoadIndicator();
Q_ASSERT_X(sGui && sGui->getWebDataServices(), Q_FUNC_INFO, "missing web data services");
this->m_modelLoader->startLoading(mode, sGui->getWebDataServices()->getModels());
}
void CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished(bool success, const CSimulatorInfo &simInfo)
void CDbOwnModelsComponent::ps_onOwnModelsLoadingFinished(bool success, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simInfo.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator");
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Expect single simulator");
if (success && this->m_modelLoader)
{
const CAircraftModelList models(this->m_modelLoader->getAircraftModels());
const int modelsLoaded = models.size();
this->ui->tvp_OwnAircraftModels->updateContainerMaybeAsync(models);
if (modelsLoaded > 0)
{
// store for later
Data::CDbOwnModelsComponent mc(this->m_lastInteractions.get());
if (simInfo.isSingleSimulator() && mc.getLastSimulatorSelection() != simInfo)
{
mc.setLastSimulatorSelection(simInfo);
this->m_lastInteractions.set(mc);
}
}
else
if (modelsLoaded < 1)
{
// loading ok, but no data
CLogMessage(this).warning("Loading completed, but no models");
@@ -288,15 +280,15 @@ namespace BlackGui
}
else
{
this->ui->tvp_OwnAircraftModels->hideLoadIndicator();
CLogMessage(this).error("Loading of models failed, simulator %1") << simInfo.toQString();
this->ui->tvp_OwnAircraftModels->clear();
CLogMessage(this).error("Loading of models failed, simulator %1") << simulator.toQString();
}
this->ui->tvp_OwnAircraftModels->hideLoadIndicator();
}
void CDbOwnModelsComponent::ps_requestSimulatorModels(const CSimulatorInfo &simInfo, IAircraftModelLoader::LoadMode mode)
void CDbOwnModelsComponent::ps_requestSimulatorModels(const CSimulatorInfo &simulator, IAircraftModelLoader::LoadMode mode)
{
this->ps_loadInstalledModels(simInfo, mode);
this->ps_loadInstalledModels(simulator, mode);
}
} // ns
} // ns

View File

@@ -13,7 +13,6 @@
#define BLACKGUI_COMPONENTS_DBOWNMODELSCOMPONENT_H
#include "blackgui/models/aircraftmodellistmodel.h"
#include "blackgui/components/data/lastselections.h"
#include "blackgui/menus/menudelegate.h"
#include "blackmisc/simulation/aircraftmodelloader.h"
#include <QFrame>
@@ -49,7 +48,7 @@ namespace BlackGui
BlackMisc::Simulation::CAircraftModelList getOwnSelectedModels() const;
//! Own models for simulator
const BlackMisc::Simulation::CSimulatorInfo &getOwnModelsSimulator() const;
const BlackMisc::Simulation::CSimulatorInfo getOwnModelsSimulator() const;
//! Number of own models
int getOwnModelsCount() const;
@@ -74,21 +73,21 @@ namespace BlackGui
void ps_requestOwnModelsUpdate();
//! Load the models
void ps_loadInstalledModels(const BlackMisc::Simulation::CSimulatorInfo &simInfo, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode);
void ps_loadInstalledModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode);
//! Model loading finished
void ps_onOwnModelsLoadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simInfo);
void ps_onOwnModelsLoadingFinished(bool success, const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Request simulator models
void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simInfo, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode);
void ps_requestSimulatorModels(const BlackMisc::Simulation::CSimulatorInfo &simulator, BlackMisc::Simulation::IAircraftModelLoader::LoadMode mode);
private:
QScopedPointer<Ui::CDbOwnModelsComponent> ui;
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
BlackMisc::CData<BlackGui::Components::Data::DbOwnModelsComponent> m_lastInteractions {this}; //!< last interactions
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_simulatorSelection {this }; //!< last selection
//! Init model loader
bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
bool initModelLoader(const Simulation::CSimulatorInfo &simulator);
//! File name for savinf
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);

View File

@@ -12,6 +12,7 @@
#include "blackgui/menus/aircraftmodelmenus.h"
#include "blackmisc/simulation/aircraftmodellist.h"
#include "blackmisc/logmessage.h"
#include "blackmisc/verify.h"
#include "dbmappingcomponent.h"
#include "dbownmodelsetdialog.h"
#include "ui_dbownmodelsetcomponent.h"
@@ -36,10 +37,11 @@ namespace BlackGui
ui->tvp_OwnModelSet->menuRemoveItems(CAircraftModelView::MenuDisplayAutomaticallyAndRefresh | CAircraftModelView::MenuStashing | CAircraftModelView::MenuBackend | CAircraftModelView::MenuRefresh);
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows | CAircraftModelView::MenuClear);
ui->tvp_OwnModelSet->addFilterDialog();
ui->tvp_OwnModelSet->setCustomMenu(new CLoadModelsMenu(this));
ui->tvp_OwnModelSet->setJsonLoad(CAircraftModelView::AllowOnlySingleSimulator | CAircraftModelView::ReduceToOneSimulator);
ui->tvp_OwnModelSet->setCustomMenu(new CLoadModelsMenu(this));
ui->tvp_OwnModelSet->setCustomMenu(new CMergeWithDbDataMenu(ui->tvp_OwnModelSet, this, true));
ui->tvp_OwnModelSet->menuAddItems(CAircraftModelView::MenuOrderable);
ui->tvp_OwnModelSet->setSorting(CAircraftModel::IndexOrderString);
ui->tvp_OwnModelSet->initAsOrderable();
connect(ui->pb_CreateNewSet, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
@@ -47,9 +49,16 @@ namespace BlackGui
connect(ui->pb_SaveAsSetForSimulator, &QPushButton::clicked, this, &CDbOwnModelSetComponent::ps_buttonClicked);
connect(&this->m_modelSetLoader, &CAircraftModelSetLoader::simulatorChanged, this, &CDbOwnModelSetComponent::ps_onSimulatorChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::rowCountChanged, this, &CDbOwnModelSetComponent::ps_onRowCountChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::modelChanged, this, &CDbOwnModelSetComponent::ps_modelChanged);
connect(ui->tvp_OwnModelSet, &CAircraftModelView::jsonModelsForSimulatorLoaded, this, &CDbOwnModelSetComponent::ps_onJsonDataLoaded);
this->ps_onRowCountChanged(ui->tvp_OwnModelSet->rowCount(), ui->tvp_OwnModelSet->hasFilter());
const CSimulatorInfo sim = this->m_modelSetLoader.getSimulator();
if (sim.isSingleSimulator())
{
ui->tvp_OwnModelSet->updateContainerMaybeAsync(this->m_modelSetLoader.getAircraftModels());
}
const int c = this->m_modelSetLoader.getAircraftModelsCount();
this->ps_onRowCountChanged(c, ui->tvp_OwnModelSet->hasFilter());
}
CDbOwnModelSetComponent::~CDbOwnModelSetComponent()
@@ -103,6 +112,11 @@ namespace BlackGui
return ui->tvp_OwnModelSet->container();
}
const CSimulatorInfo CDbOwnModelSetComponent::getModelSetSimulator() const
{
return this->m_modelSetLoader.getSimulator();
}
CStatusMessage CDbOwnModelSetComponent::addToModelSet(const CAircraftModel &model, const CSimulatorInfo &simulator)
{
return this->addToModelSet(CAircraftModelList({model}), simulator);
@@ -195,16 +209,18 @@ namespace BlackGui
void CDbOwnModelSetComponent::ps_changeSimulator(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
this->m_modelSetLoader.changeSimulator(simulator);
if (this->getModelSetSimulator() == simulator) { return; } // avoid endless loops
this->setSimulator(simulator);
const CAircraftModelList models(this->m_modelSetLoader.getAircraftModels());
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
}
void CDbOwnModelSetComponent::ps_onSimulatorChanged(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
const CAircraftModelList models(this->m_modelSetLoader.getAircraftModels());
this->setSimulator(simulator);
ui->tvp_OwnModelSet->updateContainerMaybeAsync(models);
if (this->getModelSetSimulator() == simulator) { return; } // avoid endless loops
this->ps_changeSimulator(simulator);
}
void CDbOwnModelSetComponent::ps_onRowCountChanged(int count, bool withFilter)
@@ -212,12 +228,12 @@ namespace BlackGui
Q_UNUSED(count);
Q_UNUSED(withFilter);
int realUnfilteredCount = ui->tvp_OwnModelSet->container().size();
bool canSave = this->m_simulator.isSingleSimulator() && (realUnfilteredCount > 0);
bool canSave = this->getModelSetSimulator().isSingleSimulator() && (realUnfilteredCount > 0);
this->ui->pb_SaveAsSetForSimulator->setEnabled(canSave);
if (canSave)
{
this->setSaveFileName(this->m_simulator);
ui->pb_SaveAsSetForSimulator->setText("save for " + this->m_simulator.toQString(true));
this->setSaveFileName(this->getModelSetSimulator());
ui->pb_SaveAsSetForSimulator->setText("save for " + this->getModelSetSimulator().toQString(true));
}
else
{
@@ -243,6 +259,11 @@ namespace BlackGui
}
}
void CDbOwnModelSetComponent::ps_modelChanged()
{
ui->pb_SaveAsSetForSimulator->setEnabled(true);
}
void CDbOwnModelSetComponent::setSaveFileName(const CSimulatorInfo &sim)
{
Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
@@ -250,10 +271,11 @@ namespace BlackGui
this->ui->tvp_OwnModelSet->setSaveFileName(name);
}
void CDbOwnModelSetComponent::setSimulator(const CSimulatorInfo &sim)
void CDbOwnModelSetComponent::setSimulator(const CSimulatorInfo &simulator)
{
this->m_simulator = sim;
this->ui->le_Simulator->setText(sim.toQString(true));
if (this->m_modelSetLoader.getSimulator() == simulator) { return; } // avoid unnecessary signals
this->m_modelSetLoader.changeSimulator(simulator);
this->ui->le_Simulator->setText(simulator.toQString(true));
}
void CDbOwnModelSetComponent::updateDistributorOrder(const CSimulatorInfo &simulator)

View File

@@ -67,15 +67,15 @@ namespace BlackGui
const BlackMisc::Simulation::CAircraftModelList &getModelSet() const;
//! Model set is for simulator
const BlackMisc::Simulation::CSimulatorInfo &getModelSetSimulator() const { return m_simulator; }
const Simulation::CSimulatorInfo getModelSetSimulator() const;
//! \copydoc CDbMappingComponentAware::setMappingComponent
virtual void setMappingComponent(CDbMappingComponent *component) override;
//! \name Implementations of the models interfaces
//! @{
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setModelSet(models, this->m_simulator); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddModelSet(models, this->m_simulator); }
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setModelSet(models, this->getModelSetSimulator()); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddModelSet(models, this->getModelSetSimulator()); }
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setModelSet(models, simulator); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddModelSet(models, simulator); }
//! @}
@@ -109,19 +109,21 @@ namespace BlackGui
//! Preferences changed
void ps_preferencesChanged();
//! Model has been changed
void ps_modelChanged();
private:
//! Default file name
void setSaveFileName(const BlackMisc::Simulation::CSimulatorInfo &sim);
//! Simulator
void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &sim);
void setSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator);
//! Update distributor order
void updateDistributorOrder(const BlackMisc::Simulation::CSimulatorInfo &simulator);
QScopedPointer<Ui::CDbOwnModelSetComponent> ui;
QScopedPointer<CDbOwnModelSetDialog> m_modelSetDialog;
BlackMisc::Simulation::CSimulatorInfo m_simulator;
BlackMisc::Simulation::CAircraftModelSetLoader m_modelSetLoader { BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX), this };
BlackMisc::CSetting<BlackCore::Settings::Simulation::DistributorListPreferences> m_distributorPreferences { this, &CDbOwnModelSetComponent::ps_preferencesChanged };

View File

@@ -8,7 +8,6 @@
*/
#include "registermetadatacomponents.h"
#include "blackgui/components/data/lastselections.h"
namespace BlackGui
{
@@ -16,8 +15,7 @@ namespace BlackGui
{
void registerMetadata()
{
Data::CDbOwnModelsComponent::registerMetadata();
}
}
} // ns
} // ns

View File

@@ -37,7 +37,7 @@ namespace BlackMisc
{
Q_ASSERT_X(!this->isEmpty(), Q_FUNC_INFO, "Empty index");
if (this->isEmpty()) { return CPropertyIndex(); }
int p = this->m_indexString.indexOf(';');
const int p = this->m_indexString.indexOf(';');
if (p < 0) { return CPropertyIndex(); }
return CPropertyIndex(this->m_indexString.mid(p + 1));
}
@@ -129,7 +129,7 @@ namespace BlackMisc
Q_ASSERT_X(!this->isEmpty(), Q_FUNC_INFO, "No index");
int f = -1;
bool ok;
int p = this->m_indexString.indexOf(';');
const int p = this->m_indexString.indexOf(';');
if (p < 0)
{
f = this->m_indexString.toInt(&ok);

View File

@@ -37,67 +37,67 @@ namespace BlackMisc
public Mixin::CompareByMetaClass<CPropertyIndex>,
public Mixin::String<CPropertyIndex>
{
// In the first trial I have used CSequence<int> as base class
// This has created too much circular dependencies of the headers
// In the first trial I have used CSequence<int> as base class. This has created too much circular dependencies of the headers
// CIndexVariantMap is used in CValueObject, CPropertyIndex in CIndexVariantMap
public:
//! Global index, make sure the indexes are unqiue (for using them in class hierarchy)
enum GlobalIndex
{
GlobalIndexCValueObject = 10, // avoid circular dependencies, GlobalIndexCValueObject needs to be set manually in CValueObject
GlobalIndexCPhysicalQuantity = 100,
GlobalIndexCStatusMessage = 200,
GlobalIndexCNameVariantPair = 300,
GlobalIndexITimestampBased = 400,
GlobalIndexIOrderable = 500,
GlobalIndexCIdentifier = 600,
GlobalIndexCRgbColor = 700,
GlobalIndexCCountry = 800,
GlobalIndexCCallsign = 1000,
GlobalIndexCAircraftSituation = 1100,
GlobalIndexCAtcStation = 1200,
GlobalIndexCAirport = 1300,
GlobalIndexCAircraftParts = 1400,
GlobalIndexCAircraftLights = 1500,
GlobalIndexCLivery = 1600,
GlobalIndexCModulator = 2000,
GlobalIndexCTransponder = 2100,
GlobalIndexCAircraftIcaoData = 2500,
GlobalIndexCAircraftIcaoCode = 2600,
GlobalIndexCAirlineIcaoCode = 2700,
GlobalIndexCAirportIcaoCode = 2800,
GlobalIndexCMetar = 4000,
GlobalIndexCCloudLayer = 4100,
GlobalIndexCPresentWeather = 4200,
GlobalIndexCWindLayer = 4300,
GlobalIndexCTemperatureLayer = 4400,
GlobalIndexCGridPoint = 4500,
GlobalIndexCVisibilityLayer = 4600,
GlobalIndexICoordinateGeodetic = 5000,
GlobalIndexCCoordinateGeodetic = 5100,
GlobalIndexCClient = 6000,
GlobalIndexCUser = 6100,
GlobalIndexCAuthenticatedUser = 6200,
GlobalIndexCRole = 6300,
GlobalIndexCServer = 6400,
GlobalIndexCUrl = 6500,
GlobalIndexCAircraftModel = 6600,
GlobalIndexCSimulatedAircraft = 6700,
GlobalIndexCTextMessage = 6800,
GlobalIndexCSimulatorSetup = 6900,
GlobalIndexCAircraftCfgEntries = 7000,
GlobalIndexCDistributor = 7100,
GlobalIndexCVPilotModelRule = 8000,
GlobalIndexCVoiceRoom = 9000,
GlobalIndexCSettingKeyboardHotkey = 10000,
GlobalIndexIDatastoreInteger = 11000,
GlobalIndexIDatastoreString = 11100,
GlobalIndexCGlobalSetup = 12000,
GlobalIndexCUpdateInfo = 12100,
GlobalIndexCVatsimSetup = 12200,
GlobalIndexCDbOwnModelsComponent = 14000,
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed
GlobalIndexCValueObject = 10,
GlobalIndexCPhysicalQuantity = 100,
GlobalIndexCStatusMessage = 200,
GlobalIndexCNameVariantPair = 300,
GlobalIndexITimestampBased = 400,
GlobalIndexIOrderable = 500,
GlobalIndexCIdentifier = 600,
GlobalIndexCRgbColor = 700,
GlobalIndexCCountry = 800,
GlobalIndexCCallsign = 1000,
GlobalIndexCAircraftSituation = 1100,
GlobalIndexCAtcStation = 1200,
GlobalIndexCAirport = 1300,
GlobalIndexCAircraftParts = 1400,
GlobalIndexCAircraftLights = 1500,
GlobalIndexCLivery = 1600,
GlobalIndexCModulator = 2000,
GlobalIndexCTransponder = 2100,
GlobalIndexCAircraftIcaoData = 2500,
GlobalIndexCAircraftIcaoCode = 2600,
GlobalIndexCAirlineIcaoCode = 2700,
GlobalIndexCAirportIcaoCode = 2800,
GlobalIndexCMetar = 4000,
GlobalIndexCCloudLayer = 4100,
GlobalIndexCPresentWeather = 4200,
GlobalIndexCWindLayer = 4300,
GlobalIndexCTemperatureLayer = 4400,
GlobalIndexCGridPoint = 4500,
GlobalIndexCVisibilityLayer = 4600,
GlobalIndexICoordinateGeodetic = 5000,
GlobalIndexCCoordinateGeodetic = 5100,
GlobalIndexCClient = 6000,
GlobalIndexCUser = 6100,
GlobalIndexCAuthenticatedUser = 6200,
GlobalIndexCRole = 6300,
GlobalIndexCServer = 6400,
GlobalIndexCUrl = 6500,
GlobalIndexCAircraftModel = 6600,
GlobalIndexCSimulatedAircraft = 6700,
GlobalIndexCTextMessage = 6800,
GlobalIndexCSimulatorSetup = 6900,
GlobalIndexCAircraftCfgEntries = 7000,
GlobalIndexCDistributor = 7100,
GlobalIndexCVPilotModelRule = 8000,
GlobalIndexCVoiceRoom = 9000,
GlobalIndexCSettingKeyboardHotkey = 10000,
GlobalIndexIDatastoreInteger = 11000,
GlobalIndexIDatastoreString = 11100,
GlobalIndexCGlobalSetup = 12000,
GlobalIndexCUpdateInfo = 12100,
GlobalIndexCVatsimSetup = 12200,
GlobalIndexCGuiStateDbOwnModelsComponent = 14000,
GlobalIndexCGuiStateDbOwnModelSetComponent = 14100,
GlobalIndexAbuseMode = 20000 // property index abused as map key or otherwise, to be removed if no longer needed
};
//! Default constructor.

View File

@@ -12,6 +12,7 @@
#include "blackmisc/simulation/xplane/aircraftmodelloaderxplane.h"
#include "blackmisc/simulation/xplane/xplaneutil.h"
using namespace BlackMisc::Simulation::Data;
using namespace BlackMisc::Simulation::FsCommon;
using namespace BlackMisc::Simulation::XPlane;
@@ -19,10 +20,11 @@ namespace BlackMisc
{
namespace Simulation
{
IAircraftModelLoader::IAircraftModelLoader(const CSimulatorInfo &info, const QString &rootDirectory, const QStringList &excludeDirs) :
m_simulatorInfo(info), m_rootDirectory(rootDirectory), m_excludedDirectories(excludeDirs)
IAircraftModelLoader::IAircraftModelLoader(const CSimulatorInfo &simulator, const QString &rootDirectory, const QStringList &excludeDirs) :
m_rootDirectory(rootDirectory), m_excludedDirectories(excludeDirs)
{
Q_ASSERT_X(info.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->m_caches.setCurrentSimulator(simulator);
connect(this, &IAircraftModelLoader::loadingFinished, this, &IAircraftModelLoader::ps_loadFinished);
}
@@ -41,7 +43,7 @@ namespace BlackMisc
CStatusMessage IAircraftModelLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator();
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
return this->m_caches.setCachedModels(models, sim);
}
@@ -49,7 +51,7 @@ namespace BlackMisc
CStatusMessage IAircraftModelLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); }
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->getSimulator();
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
CAircraftModelList allModels(this->m_caches.getCachedModels(sim));
int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
@@ -80,22 +82,22 @@ namespace BlackMisc
CAircraftModelList IAircraftModelLoader::getAircraftModels() const
{
return this->m_caches.getCachedModels(this->m_simulatorInfo);
return this->m_caches.getCurrentCachedModels();
}
QDateTime IAircraftModelLoader::getCacheTimestamp() const
{
return this->m_caches.getCacheTimestamp(this->m_simulatorInfo);
return this->m_caches.getCurrentCacheTimestamp();
}
void IAircraftModelLoader::syncronizeCache()
bool IAircraftModelLoader::syncronizeCache()
{
return this->m_caches.syncronizeCache(this->m_simulatorInfo);
return this->m_caches.syncronizeCurrentCache();
}
bool IAircraftModelLoader::hasCachedData() const
{
return !this->m_caches.getCachedModels(this->m_simulatorInfo).isEmpty();
return !this->m_caches.getCurrentCachedModels().isEmpty();
}
CStatusMessage IAircraftModelLoader::clearCache()
@@ -110,7 +112,7 @@ namespace BlackMisc
const bool useCachedData = !mode.testFlag(CacheSkipped) && this->hasCachedData();
if (useCachedData && (mode.testFlag(CacheFirst) || mode.testFlag(CacheOnly)))
{
emit loadingFinished(true, this->m_simulatorInfo);
emit loadingFinished(true, this->getSimulator());
return;
}
else if (useCachedData && mode.testFlag(CacheUntilNewer))
@@ -118,27 +120,27 @@ namespace BlackMisc
//! \todo currently too slow, does not make sense with that overhead
if (!this->areModelFilesUpdated())
{
emit loadingFinished(true, this->m_simulatorInfo);
emit loadingFinished(true, this->getSimulator());
return;
}
}
if (mode.testFlag(CacheOnly))
{
// only cache, but we did not find any data
emit loadingFinished(false, this->m_simulatorInfo);
emit loadingFinished(false, this->getSimulator());
return;
}
this->startLoadingFromDisk(mode, dbModels);
}
const CSimulatorInfo &IAircraftModelLoader::getSimulator() const
const CSimulatorInfo IAircraftModelLoader::getSimulator() const
{
return m_simulatorInfo;
return this->m_caches.getCurrentSimulator();
}
QString IAircraftModelLoader::getSimulatorAsString() const
{
return m_simulatorInfo.toQString();
return this->getSimulator().toQString();
}
bool IAircraftModelLoader::supportsSimulator(const CSimulatorInfo &info)
@@ -157,10 +159,11 @@ namespace BlackMisc
this->cancelLoading();
}
std::unique_ptr<IAircraftModelLoader> IAircraftModelLoader::createModelLoader(const CSimulatorInfo &simInfo)
std::unique_ptr<IAircraftModelLoader> IAircraftModelLoader::createModelLoader(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Single simulator");
std::unique_ptr<IAircraftModelLoader> loader;
if (simInfo.xplane())
if (simulator.xplane())
{
loader = std::make_unique<CAircraftModelLoaderXPlane>(
CSimulatorInfo(CSimulatorInfo::XPLANE),
@@ -168,10 +171,16 @@ namespace BlackMisc
}
else
{
loader = CAircraftCfgParser::createModelLoader(simInfo);
loader = CAircraftCfgParser::createModelLoader(simulator);
}
if (!loader) { return loader; }
// make sure the cache is really available, normally this happens in the constructor
if (loader->getSimulator() != simulator)
{
loader->m_caches.setCurrentSimulator(simulator); // mark current simulator and sync caches
}
// make sure the cache is really available
loader->syncronizeCache();
return loader;
}
} // ns

View File

@@ -84,7 +84,7 @@ namespace BlackMisc
virtual bool areModelFilesUpdated() const = 0;
//! Which simulator is supported by that very loader
const BlackMisc::Simulation::CSimulatorInfo &getSimulator() const;
const CSimulatorInfo getSimulator() const;
//! Supported simulators as string
QString getSimulatorAsString() const;
@@ -100,14 +100,14 @@ namespace BlackMisc
//! \name Implementations of the model interfaces (allows to set models modified in utility functions)
//! @{
virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->m_simulatorInfo); }
virtual void updateModels(const CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->m_simulatorInfo); }
virtual void setModels(const CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
virtual void updateModels(const CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->getSimulator()); }
virtual void setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
virtual void updateModels(const CAircraftModelList &models, const CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); }
//! @}
//! Create a loader and syncronize caches
static std::unique_ptr<IAircraftModelLoader> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simInfo);
static std::unique_ptr<IAircraftModelLoader> createModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator);
public slots:
//! Set cache from outside, this should only be used in special cases.
@@ -124,13 +124,13 @@ namespace BlackMisc
protected:
//! Constructor
IAircraftModelLoader(const CSimulatorInfo &info, const QString &rootDirectory, const QStringList &excludeDirs = {});
IAircraftModelLoader(const CSimulatorInfo &simulator, const QString &rootDirectory, const QStringList &excludeDirs = {});
//! Cache timestamp
QDateTime getCacheTimestamp() const;
//! Make sure cache is syncronized
void syncronizeCache();
bool syncronizeCache();
//! Any cached data?
bool hasCachedData() const;
@@ -144,7 +144,6 @@ namespace BlackMisc
//! Start the loading process from disk
virtual void startLoadingFromDisk(LoadMode mode, const BlackMisc::Simulation::CAircraftModelList &dbModels) = 0;
BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; //!< Corresponding simulator
std::atomic<bool> m_cancelLoading { false }; //!< flag
std::atomic<bool> m_loadingInProgress { false }; //!< Loading in progress
QString m_rootDirectory; //!< root directory parsing aircraft.cfg files

View File

@@ -15,11 +15,11 @@ namespace BlackMisc
{
namespace Simulation
{
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &info, QObject *parent) :
QObject(parent),
m_simulatorInfo(info)
CAircraftModelSetLoader::CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent) :
QObject(parent)
{
Q_ASSERT_X(info.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->syncronizeCache();
connect(&this->m_caches, &CModelSetCaches::cacheChanged, this, &CAircraftModelSetLoader::cacheChanged);
}
@@ -30,7 +30,7 @@ namespace BlackMisc
CStatusMessage CAircraftModelSetLoader::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_caches.getCurrentSimulator();
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simulator"); }
const CStatusMessage m(this->m_caches.setCachedModels(models, sim));
return m;
@@ -39,7 +39,7 @@ namespace BlackMisc
CStatusMessage CAircraftModelSetLoader::replaceOrAddCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
if (models.isEmpty()) { return CStatusMessage(this, CStatusMessage::SeverityInfo, "No data"); }
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_simulatorInfo;
const CSimulatorInfo sim = simulator.isSingleSimulator() ? simulator : this->m_caches.getCurrentSimulator();
if (!sim.isSingleSimulator()) { return CStatusMessage(this, CStatusMessage::SeverityError, "Invalid simuataor"); }
CAircraftModelList allModels(this->m_caches.getCachedModels(sim));
int c = allModels.replaceOrAddModelsWithString(models, Qt::CaseInsensitive);
@@ -56,14 +56,13 @@ namespace BlackMisc
void CAircraftModelSetLoader::changeSimulator(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
this->m_simulatorInfo = simulator;
this->m_caches.syncronizeCache(simulator);
emit simulatorChanged(simulator);
}
CAircraftModelList CAircraftModelSetLoader::getAircraftModels() const
{
return this->m_caches.getCachedModels(this->m_simulatorInfo);
return this->m_caches.getCurrentCachedModels();
}
CAircraftModelList CAircraftModelSetLoader::getAircraftModels(const CSimulatorInfo &simulator) const
@@ -80,17 +79,17 @@ namespace BlackMisc
QDateTime CAircraftModelSetLoader::getCacheTimestamp() const
{
return this->m_caches.getCacheTimestamp(this->m_simulatorInfo);
return this->m_caches.getCurrentCacheTimestamp();
}
void CAircraftModelSetLoader::syncronizeCache()
bool CAircraftModelSetLoader::syncronizeCache()
{
return this->m_caches.syncronizeCache(this->m_simulatorInfo);
return this->m_caches.syncronizeCurrentCache();
}
bool CAircraftModelSetLoader::hasCachedData() const
{
return !this->m_caches.getCachedModels(this->m_simulatorInfo).isEmpty();
return !this->m_caches.getCurrentCachedModels().isEmpty();
}
CStatusMessage CAircraftModelSetLoader::clearCache()
@@ -98,14 +97,14 @@ namespace BlackMisc
return this->setCachedModels(CAircraftModelList());
}
const CSimulatorInfo &CAircraftModelSetLoader::getSimulator() const
CSimulatorInfo CAircraftModelSetLoader::getSimulator() const
{
return m_simulatorInfo;
return this->m_caches.getCurrentSimulator();
}
QString CAircraftModelSetLoader::getSimulatorAsString() const
{
return m_simulatorInfo.toQString();
return this->getSimulator().toQString();
}
bool CAircraftModelSetLoader::supportsSimulator(const CSimulatorInfo &info)

View File

@@ -40,7 +40,7 @@ namespace BlackMisc
public:
//! Constructor
CAircraftModelSetLoader(const CSimulatorInfo &info, QObject *parent = nullptr);
CAircraftModelSetLoader(const CSimulatorInfo &simulator, QObject *parent = nullptr);
//! Destructor
virtual ~CAircraftModelSetLoader();
@@ -62,7 +62,7 @@ namespace BlackMisc
BlackMisc::Simulation::CAircraftModel getModelForModelString(const QString &modelString) const;
//! Which simulator is supported by that very loader
const BlackMisc::Simulation::CSimulatorInfo &getSimulator() const;
CSimulatorInfo getSimulator() const;
//! Supported simulators as string
QString getSimulatorAsString() const;
@@ -75,8 +75,8 @@ namespace BlackMisc
//! \name Implementations of the models interfaces
//! @{
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setCachedModels(models, this->m_simulatorInfo); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->m_simulatorInfo); }
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->setCachedModels(models, this->getSimulator()); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models) override { this->replaceOrAddCachedModels(models, this->getSimulator()); }
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->setCachedModels(models, simulator); }
virtual void updateModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override { this->replaceOrAddCachedModels(models, simulator); }
//! @}
@@ -105,7 +105,7 @@ namespace BlackMisc
QDateTime getCacheTimestamp() const;
//! Make sure cache is syncronized
void syncronizeCache();
bool syncronizeCache();
//! Any cached data?
bool hasCachedData() const;
@@ -113,7 +113,6 @@ namespace BlackMisc
//! Clear cache
BlackMisc::CStatusMessage clearCache();
BlackMisc::Simulation::CSimulatorInfo m_simulatorInfo; //!< Corresponding simulator
BlackMisc::Simulation::Data::CModelSetCaches m_caches { this }; //!< caches
};
} // namespace

View File

@@ -8,6 +8,9 @@
*/
#include "modelcaches.h"
#include "blackmisc/logmessage.h"
using namespace BlackMisc;
namespace BlackMisc
{
@@ -15,8 +18,30 @@ namespace BlackMisc
{
namespace Data
{
void IMultiSimulatorModelCaches::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
this->setCachedModels(models, simulator);
}
CAircraftModelList IMultiSimulatorModelCaches::getCurrentCachedModels() const
{
const CSimulatorInfo sim(this->getCurrentSimulator());
if (!sim.isSingleSimulator()) { return CAircraftModelList(); }
return this->getCachedModels(sim);
}
bool IMultiSimulatorModelCaches::syncronizeCurrentCache()
{
const CSimulatorInfo sim(this->getCurrentSimulator());
if (!sim.isSingleSimulator()) { return false; }
this->syncronizeCache(sim);
return true;
}
CModelCaches::CModelCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
{ }
{
this->m_currentSimulator.synchronize();
}
CAircraftModelList CModelCaches::getCachedModels(const CSimulatorInfo &simulator) const
{
@@ -36,6 +61,8 @@ namespace BlackMisc
CStatusMessage CModelCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { return m; }
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(models);
@@ -48,6 +75,13 @@ namespace BlackMisc
}
}
QDateTime IMultiSimulatorModelCaches::getCurrentCacheTimestamp() const
{
const CSimulatorInfo sim(this->getCurrentSimulator());
if (!sim.isSingleSimulator()) { return QDateTime(); }
return this->getCacheTimestamp(sim);
}
QDateTime CModelCaches::getCacheTimestamp(const CSimulatorInfo &simulator) const
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
@@ -66,6 +100,8 @@ namespace BlackMisc
void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { CLogMessage::preformatted(m); }
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.synchronize(); break;
@@ -77,8 +113,15 @@ namespace BlackMisc
}
}
void CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
{
this->syncronizeCache(simulator);
}
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
{ }
{
this->m_currentSimulator.synchronize();
}
CAircraftModelList CModelSetCaches::getCachedModels(const CSimulatorInfo &simulator) const
{
@@ -98,24 +141,24 @@ namespace BlackMisc
CStatusMessage CModelSetCaches::setCachedModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
CAircraftModelList m(models);
// make sure we have a proper order
if (m.needsOrder())
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { return m; }
CAircraftModelList orderedModels(models);
if (orderedModels.needsOrder())
{
m.resetOrder();
orderedModels.resetOrder();
}
else
{
m.sortAscendingByOrder();
orderedModels.sortAscendingByOrder();
}
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(m);
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(m);
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(m);
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(m);
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.set(orderedModels);
case CSimulatorInfo::FSX: return this->m_modelCacheFsx.set(orderedModels);
case CSimulatorInfo::P3D: return this->m_modelCacheP3D.set(orderedModels);
case CSimulatorInfo::XPLANE: return this->m_modelCacheXP.set(orderedModels);
default:
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
return CStatusMessage();
@@ -140,6 +183,8 @@ namespace BlackMisc
void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
const CStatusMessage m = this->m_currentSimulator.set(simulator);
if (m.isFailure()) { CLogMessage::preformatted(m); }
switch (simulator.getSimulator())
{
case CSimulatorInfo::FS9: return this->m_modelCacheFs9.synchronize(); break;
@@ -151,6 +196,11 @@ namespace BlackMisc
}
}
void CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
{
this->syncronizeCache(simulator);
}
} // ns
} // ns
} // ns

View File

@@ -63,8 +63,14 @@ namespace BlackMisc
//! Key in data cache
static const char *key() { return "modelcachep3d"; }
};
//! @}
//! Last selection
struct ModelCacheLastSelection : public BlackMisc::CDataTrait<BlackMisc::Simulation::CSimulatorInfo>
{
//! Key
static const char *key() { return "modelcachelastselection"; }
};
//! @}
//! \name Caches for choosen model sets
//! @{
@@ -96,8 +102,14 @@ namespace BlackMisc
//! Key in data cache
static const char *key() { return "modelsetp3d"; }
};
//! @}
//! Last selection
struct ModelSetLastSelection : public BlackMisc::CDataTrait<BlackMisc::Simulation::CSimulatorInfo>
{
//! Key
static const char *key() { return "modelsetlastselection"; }
};
//! @}
//! Trait for vPilot derived models
struct VPilotAircraftModels : public ModelCache
@@ -122,30 +134,51 @@ namespace BlackMisc
//! \threadsafe
virtual CAircraftModelList getCachedModels(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
//! Models
//! \threadsafe
CAircraftModelList getCurrentCachedModels() const;
//! Cache timestamp
//! \threadsafe
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const = 0;
//! Last selection`s timestamp
QDateTime getCurrentCacheTimestamp() const;
//! Set cache
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
//! Syncronize
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
//! Last cache
bool syncronizeCurrentCache();
//! Selected simulator
//! \threadsafe
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const = 0;
//!Selected simulator
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) = 0;
//! \copydoc IModelsPerSimulatorSetable::setModels
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override
{
this->setCachedModels(models, simulator);
}
virtual void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
protected:
//! \name Cache has been changed
//! @{
void changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); }
void changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); }
void changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); }
void changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); }
//! @}
signals:
//! Cache has been changed
void cacheChanged(const BlackMisc::Simulation::CSimulatorInfo &simulator);
};
//! Bundle of caches for all simulators
//! \remark Temp. workaround
class CModelCaches : public IMultiSimulatorModelCaches
{
Q_OBJECT
@@ -160,22 +193,16 @@ namespace BlackMisc
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
//! @}
private:
//! \todo Why can`t I keep the changed functions in IMultiSimulatorModelCaches -> C2039 not a member
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFsx> m_modelCacheFsx {this, &CModelCaches::changedFsx }; //!< FSX cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheFs9> m_modelCacheFs9 {this, &CModelCaches::changedFs9 }; //!< FS9 cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D cache
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
//! \name Cache has been changed
//! @{
void changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); }
void changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); }
void changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); }
void changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); }
//! @}
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_currentSimulator {this }; //!< surrent simulator
};
//! Bundle of caches for model sets of all simulators
@@ -194,6 +221,8 @@ namespace BlackMisc
virtual BlackMisc::CStatusMessage setCachedModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual QDateTime getCacheTimestamp(const BlackMisc::Simulation::CSimulatorInfo &simulator) const override;
virtual void syncronizeCache(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
virtual BlackMisc::Simulation::CSimulatorInfo getCurrentSimulator() const override { return this->m_currentSimulator.getCopy(); }
virtual void setCurrentSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator) override;
//! @}
private:
@@ -202,14 +231,7 @@ namespace BlackMisc
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
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
//! \name Cache has been changed
//! @{
void changedFsx() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FSX)); }
void changedFs9() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::FS9)); }
void changedP3D() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::P3D)); }
void changedXP() { emit cacheChanged(BlackMisc::Simulation::CSimulatorInfo(BlackMisc::Simulation::CSimulatorInfo::XPLANE)); }
//! @}
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
};
} // ns
} // ns

View File

@@ -100,11 +100,11 @@ namespace BlackMisc
this->setCachedModels(models); // not thread safe
}
// currently I treat no data as error
emit this->loadingFinished(hasData, this->m_simulatorInfo);
emit this->loadingFinished(hasData, this->getSimulator());
}
else
{
emit this->loadingFinished(false, this->m_simulatorInfo);
emit this->loadingFinished(false, this->getSimulator());
}
});
}
@@ -120,7 +120,7 @@ namespace BlackMisc
this->setCachedModels(models); // not thread safe
}
// currently I treat no data as error
emit this->loadingFinished(hasData, this->m_simulatorInfo);
emit this->loadingFinished(hasData, this->getSimulator());
}
}
@@ -128,7 +128,7 @@ namespace BlackMisc
{
if (this->hasCachedData())
{
emit this->loadingFinished(true, this->m_simulatorInfo);
emit this->loadingFinished(true, this->getSimulator());
}
}

View File

@@ -60,7 +60,7 @@ namespace BlackMisc
if (m_rootDirectory.isEmpty())
{
this->clearCache();
emit loadingFinished(false, this->m_simulatorInfo);
emit loadingFinished(false, this->getSimulator());
return;
}
@@ -105,7 +105,7 @@ namespace BlackMisc
void CAircraftModelLoaderXPlane::updateInstalledModels(const CAircraftModelList &models)
{
this->setCachedModels(models);
emit loadingFinished(true, this->m_simulatorInfo);
emit loadingFinished(true, this->getSimulator());
}
QString CAircraftModelLoaderXPlane::CSLPlane::getModelName() const
@@ -155,7 +155,7 @@ namespace BlackMisc
CAircraftModel model;
model.setModelType(CAircraftModel::TypeOwnSimulatorModel);
model.setSimulator(m_simulatorInfo);
model.setSimulator(this->getSimulator());
model.setFileName(aircraftIt.filePath());
model.setModelString(modelString);
@@ -208,9 +208,9 @@ namespace BlackMisc
while (it.hasNext())
{
QString packageFile = it.next();
//! \todo KB I would consider exclude dirs here CFileUtils::matchesExcludeDirectory()
if (CFileUtils::isExcludedDirectory(it.filePath(), excludeDirectories)) { continue; }
QString packageFilePath = it.fileInfo().absolutePath();
const QString packageFilePath = it.fileInfo().absolutePath();
QFile file(packageFile);
file.open(QIODevice::ReadOnly);
QString content;
@@ -219,7 +219,7 @@ namespace BlackMisc
content.append(ts.readAll());
file.close();
auto package = parsePackageHeader(packageFilePath, content);
const auto package = parsePackageHeader(packageFilePath, content);
if (package.hasValidHeader()) m_cslPackages.push_back(package);
}
@@ -262,7 +262,7 @@ namespace BlackMisc
CDistributor distributor(package.name);
model.setDistributor(distributor);
model.setSimulator(m_simulatorInfo);
model.setSimulator(this->getSimulator());
installedModels.push_back(model);
}
}