mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-20 20:40:29 +08:00
refs #649, further fixes and improvements
* call of non-virtual function in ctor * use getCopy * return number of merged models * change current simulator in model set loader (fixes infinite loop: change data -> signal -> change data).
This commit is contained in:
@@ -48,7 +48,7 @@ namespace BlackGui
|
|||||||
|
|
||||||
// should be single simulator or no simulator (default)
|
// should be single simulator or no simulator (default)
|
||||||
this->m_simulatorSelection.synchronize();
|
this->m_simulatorSelection.synchronize();
|
||||||
const CSimulatorInfo simulator(this->m_simulatorSelection.get());
|
const CSimulatorInfo simulator(this->m_simulatorSelection.getCopy());
|
||||||
const bool s = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator);
|
const bool s = this->initModelLoader(!simulator.isSingleSimulator() ? CSimulatorInfo(CSimulatorInfo::FSX) : simulator);
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ namespace BlackGui
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CDbOwnModelsComponent> ui;
|
QScopedPointer<Ui::CDbOwnModelsComponent> ui;
|
||||||
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
|
std::unique_ptr<BlackMisc::Simulation::IAircraftModelLoader> m_modelLoader; //!< read own aircraft models
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_simulatorSelection {this }; //!< last selection
|
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_simulatorSelection {this }; //!< last selection
|
||||||
|
|
||||||
//! Init or change model loader
|
//! Init or change model loader
|
||||||
bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
bool initModelLoader(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
@@ -126,8 +126,8 @@ namespace BlackGui
|
|||||||
virtual void customMenu(BlackGui::Menus::CMenuActions &menuActions) override;
|
virtual void customMenu(BlackGui::Menus::CMenuActions &menuActions) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<QAction *> m_loadActions; //!< load actions
|
QList<QAction *> m_loadActions; //!< load actions
|
||||||
QList<QAction *> m_reloadActions; //!< reload actions
|
QList<QAction *> m_reloadActions; //!< reload actions
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "aircraftmodelmenus.h"
|
#include "aircraftmodelmenus.h"
|
||||||
#include "blackgui/guiapplication.h"
|
#include "blackgui/guiapplication.h"
|
||||||
#include "blackcore/webdataservices.h"
|
#include "blackcore/webdataservices.h"
|
||||||
|
#include "blackmisc/verify.h"
|
||||||
#include "blackmisc/icons.h"
|
#include "blackmisc/icons.h"
|
||||||
#include "blackmisc/logmessage.h"
|
#include "blackmisc/logmessage.h"
|
||||||
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
|
#include "blackmisc/simulation/aircraftmodelinterfaces.h"
|
||||||
@@ -139,15 +140,27 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CMergeWithDbDataMenu::ps_mergeData()
|
void CMergeWithDbDataMenu::ps_mergeData()
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(sGui, Q_FUNC_INFO, "Missing sGui");
|
BLACK_VERIFY_X(sGui, Q_FUNC_INFO, "Missing sGui");
|
||||||
if (!sGui->hasWebDataServices()) { return; }
|
if (!sGui->hasWebDataServices()) { return; }
|
||||||
|
|
||||||
const CAircraftModelList dbModels(sGui->getWebDataServices()->getModels());
|
const CAircraftModelList dbModels(sGui->getWebDataServices()->getModels());
|
||||||
|
if (dbModels.isEmpty())
|
||||||
|
{
|
||||||
|
CLogMessage().warning("No DB models to merge with");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->modelView()->showLoadIndicator();
|
||||||
CAircraftModelList models(this->getAircraftModels());
|
CAircraftModelList models(this->getAircraftModels());
|
||||||
CAircraftModelUtilities::mergeWithDbData(models, dbModels, true);
|
int c = CAircraftModelUtilities::mergeWithDbData(models, dbModels, true);
|
||||||
if (this->modelsTargetSetable())
|
if (c > 0 && this->modelsTargetSetable())
|
||||||
{
|
{
|
||||||
this->modelsTargetSetable()->setModels(models);
|
this->modelsTargetSetable()->setModels(models);
|
||||||
|
CLogMessage().info("Merged %1/%2 models with DB") << c << models.size();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
CLogMessage().info("No data merged with DB");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -95,11 +95,6 @@ namespace BlackMisc
|
|||||||
return this->m_caches.getCurrentCacheTimestamp();
|
return this->m_caches.getCurrentCacheTimestamp();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IAircraftModelLoader::syncronizeCache()
|
|
||||||
{
|
|
||||||
return this->m_caches.syncronizeCurrentCache();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IAircraftModelLoader::hasCachedData() const
|
bool IAircraftModelLoader::hasCachedData() const
|
||||||
{
|
{
|
||||||
return !this->m_caches.getCurrentCachedModels().isEmpty();
|
return !this->m_caches.getCurrentCachedModels().isEmpty();
|
||||||
|
|||||||
@@ -136,9 +136,6 @@ namespace BlackMisc
|
|||||||
//! Cache timestamp
|
//! Cache timestamp
|
||||||
QDateTime getCacheTimestamp() const;
|
QDateTime getCacheTimestamp() const;
|
||||||
|
|
||||||
//! Make sure cache is syncronized
|
|
||||||
bool syncronizeCache();
|
|
||||||
|
|
||||||
//! Any cached data?
|
//! Any cached data?
|
||||||
bool hasCachedData() const;
|
bool hasCachedData() const;
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,8 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "Only one simulator per loader");
|
||||||
if (this->getSimulator() == simulator) { return; }
|
if (this->getSimulator() == simulator) { return; }
|
||||||
this->m_caches.syncronizeCache(simulator); // also changes current simulator of caches
|
this->m_caches.setCurrentSimulator(simulator);
|
||||||
|
this->m_caches.syncronizeCurrentCache();
|
||||||
emit simulatorChanged(simulator);
|
emit simulatorChanged(simulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,10 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
namespace Simulation
|
namespace Simulation
|
||||||
{
|
{
|
||||||
bool CAircraftModelUtilities::mergeWithDbData(CAircraftModelList &modelToBeModified, const CAircraftModelList &dbModels, bool force)
|
int CAircraftModelUtilities::mergeWithDbData(CAircraftModelList &modelToBeModified, const CAircraftModelList &dbModels, bool force)
|
||||||
{
|
{
|
||||||
if (dbModels.isEmpty() || modelToBeModified.isEmpty()) { return false; }
|
if (dbModels.isEmpty() || modelToBeModified.isEmpty()) { return 0; }
|
||||||
|
int c = 0;
|
||||||
for (CAircraftModel &simModel : modelToBeModified)
|
for (CAircraftModel &simModel : modelToBeModified)
|
||||||
{
|
{
|
||||||
if (!force && simModel.hasValidDbKey()) { continue; } // already done
|
if (!force && simModel.hasValidDbKey()) { continue; } // already done
|
||||||
@@ -27,8 +28,9 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
dbModel.updateMissingParts(simModel, false);
|
dbModel.updateMissingParts(simModel, false);
|
||||||
simModel = dbModel;
|
simModel = dbModel;
|
||||||
|
c++;
|
||||||
}
|
}
|
||||||
return true;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CAircraftModelUtilities::mergeWithVPilotData(CAircraftModelList &modelToBeModified, const CAircraftModelList &vPilotModels, bool force)
|
bool CAircraftModelUtilities::mergeWithVPilotData(CAircraftModelList &modelToBeModified, const CAircraftModelList &vPilotModels, bool force)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace BlackMisc
|
|||||||
CAircraftModelUtilities() = delete;
|
CAircraftModelUtilities() = delete;
|
||||||
|
|
||||||
//! Merge with DB data if possible
|
//! Merge with DB data if possible
|
||||||
static bool mergeWithDbData(BlackMisc::Simulation::CAircraftModelList &modelToBeModified, const BlackMisc::Simulation::CAircraftModelList &dbModels, bool force = false);
|
static int mergeWithDbData(BlackMisc::Simulation::CAircraftModelList &modelToBeModified, const BlackMisc::Simulation::CAircraftModelList &dbModels, bool force = false);
|
||||||
|
|
||||||
//! Merge with vPilot data if possible
|
//! Merge with vPilot data if possible
|
||||||
static bool mergeWithVPilotData(BlackMisc::Simulation::CAircraftModelList &modelToBeModified, const BlackMisc::Simulation::CAircraftModelList &vPilotModels, bool force = false);
|
static bool mergeWithVPilotData(BlackMisc::Simulation::CAircraftModelList &modelToBeModified, const BlackMisc::Simulation::CAircraftModelList &vPilotModels, bool force = false);
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
this->m_currentSimulator.synchronize();
|
this->m_currentSimulator.synchronize();
|
||||||
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
|
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
|
||||||
this->syncronizeCache(sim);
|
this->syncronizeCacheImpl(sim);
|
||||||
const QString simStr(sim.toQString(true));
|
const QString simStr(sim.toQString(true));
|
||||||
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
CLogMessage(this).info("Initialized model caches to %1") << simStr;
|
||||||
}
|
}
|
||||||
@@ -125,6 +125,21 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
void CModelCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
this->syncronizeCacheImpl(simulator);
|
||||||
|
}
|
||||||
|
|
||||||
|
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
||||||
|
const CSimulatorInfo s = this->m_currentSimulator.getCopy();
|
||||||
|
if (s == simulator) { return sameSimMsg; }
|
||||||
|
const BlackMisc::CStatusMessage m = this->m_currentSimulator.set(simulator);
|
||||||
|
this->syncronizeCache(simulator);
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CModelCaches::syncronizeCacheImpl(const CSimulatorInfo &simulator)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
switch (simulator.getSimulator())
|
switch (simulator.getSimulator())
|
||||||
@@ -139,21 +154,11 @@ namespace BlackMisc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CStatusMessage CModelCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
|
||||||
{
|
|
||||||
static const CStatusMessage sameSimMsg = CStatusMessage(this).info("Same simulator");
|
|
||||||
const CSimulatorInfo s = this->m_currentSimulator.getCopy();
|
|
||||||
if (s == simulator) { return sameSimMsg; }
|
|
||||||
const BlackMisc::CStatusMessage m = this->m_currentSimulator.set(simulator);
|
|
||||||
this->syncronizeCache(simulator);
|
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
CModelSetCaches::CModelSetCaches(QObject *parent) : IMultiSimulatorModelCaches(parent)
|
||||||
{
|
{
|
||||||
this->m_currentSimulator.synchronize();
|
this->m_currentSimulator.synchronize();
|
||||||
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
|
const CSimulatorInfo sim(this->m_currentSimulator.getCopy());
|
||||||
this->syncronizeCache(sim);
|
this->syncronizeCacheImpl(sim);
|
||||||
const QString simStr(sim.toQString(true));
|
const QString simStr(sim.toQString(true));
|
||||||
CLogMessage(this).info("Initialized model set caches to %1") << simStr;
|
CLogMessage(this).info("Initialized model set caches to %1") << simStr;
|
||||||
}
|
}
|
||||||
@@ -215,16 +220,7 @@ namespace BlackMisc
|
|||||||
|
|
||||||
void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
void CModelSetCaches::syncronizeCache(const CSimulatorInfo &simulator)
|
||||||
{
|
{
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
this->syncronizeCacheImpl(simulator);
|
||||||
switch (simulator.getSimulator())
|
|
||||||
{
|
|
||||||
case CSimulatorInfo::FS9: this->m_modelCacheFs9.synchronize(); break;
|
|
||||||
case CSimulatorInfo::FSX: this->m_modelCacheFsx.synchronize(); break;
|
|
||||||
case CSimulatorInfo::P3D: this->m_modelCacheP3D.synchronize(); break;
|
|
||||||
case CSimulatorInfo::XPLANE: this->m_modelCacheXP.synchronize(); break;
|
|
||||||
default:
|
|
||||||
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
CStatusMessage CModelSetCaches::setCurrentSimulator(const CSimulatorInfo &simulator)
|
||||||
@@ -236,6 +232,20 @@ namespace BlackMisc
|
|||||||
this->syncronizeCache(simulator);
|
this->syncronizeCache(simulator);
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CModelSetCaches::syncronizeCacheImpl(const CSimulatorInfo &simulator)
|
||||||
|
{
|
||||||
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
|
switch (simulator.getSimulator())
|
||||||
|
{
|
||||||
|
case CSimulatorInfo::FS9: this->m_modelCacheFs9.synchronize(); break;
|
||||||
|
case CSimulatorInfo::FSX: this->m_modelCacheFsx.synchronize(); break;
|
||||||
|
case CSimulatorInfo::P3D: this->m_modelCacheP3D.synchronize(); break;
|
||||||
|
case CSimulatorInfo::XPLANE: this->m_modelCacheXP.synchronize(); break;
|
||||||
|
default:
|
||||||
|
Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "No single simulator");
|
||||||
|
}
|
||||||
|
}
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
@@ -246,6 +246,9 @@ namespace BlackMisc
|
|||||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheP3D> m_modelCacheP3D {this, &CModelCaches::changedP3D }; //!< P3D 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
|
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheXP> m_modelCacheXP {this, &CModelCaches::changedXP }; //!< XP cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_currentSimulator { this }; //!< current simulator
|
BlackMisc::CData<BlackMisc::Simulation::Data::ModelCacheLastSelection> m_currentSimulator { this }; //!< current simulator
|
||||||
|
|
||||||
|
//! Non virtaul version (used in ctor)
|
||||||
|
void syncronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Bundle of caches for model sets of all simulators
|
//! Bundle of caches for model sets of all simulators
|
||||||
@@ -274,6 +277,9 @@ namespace BlackMisc
|
|||||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheP3D> m_modelCacheP3D {this, &CModelSetCaches::changedP3D }; //!< P3D 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
|
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetCacheXP> m_modelCacheXP {this, &CModelSetCaches::changedXP }; //!< XP cache
|
||||||
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
BlackMisc::CData<BlackMisc::Simulation::Data::ModelSetLastSelection> m_currentSimulator { this }; //!< current simulator
|
||||||
|
|
||||||
|
//! Non virtaul version (used in ctor)
|
||||||
|
void syncronizeCacheImpl(const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||||
};
|
};
|
||||||
} // ns
|
} // ns
|
||||||
} // ns
|
} // ns
|
||||||
|
|||||||
Reference in New Issue
Block a user