Simulator update returns info what was updated

This commit is contained in:
Klaus Basan
2018-11-27 02:32:13 +01:00
parent 9c46cab133
commit d704a8aeab
4 changed files with 38 additions and 13 deletions

View File

@@ -292,14 +292,14 @@ namespace BlackCore
return c; return c;
} }
CAircraftModelList CDatabaseUtils::updateSimulatorForFsFamily(const CAircraftModelList &ownModels, int maxToStash, IProgressIndicator *progressIndicator, bool processEvents) CAircraftModelList CDatabaseUtils::updateSimulatorForFsFamily(const CAircraftModelList &ownModels, CStatusMessageList *updateInfo, int maxToStash, IProgressIndicator *progressIndicator, bool processEvents)
{ {
if (!sApp || !sApp->getWebDataServices()) { return CAircraftModelList(); } if (!sApp || !sApp->getWebDataServices() || sApp->isShuttingDown()) { return CAircraftModelList(); }
CAircraftModelList dbFsFamilyModels(sApp->getWebDataServices()->getModels().getAllFsFamilyModels()); const CAircraftModelList dbFsFamilyModels(sApp->getWebDataServices()->getModels().getAllFsFamilyModels());
CAircraftModelList stashModels; CAircraftModelList stashModels;
if (dbFsFamilyModels.isEmpty() || ownModels.isEmpty()) { return stashModels; } if (dbFsFamilyModels.isEmpty() || ownModels.isEmpty()) { return stashModels; }
const QSet<QString> dbKeys = dbFsFamilyModels.getModelStringSet(); const QSet<QString> dbKeys = dbFsFamilyModels.getModelStringSet();
const int maxModelsCount = maxToStash >= 0 ? maxToStash : ownModels.size(); const int maxModelsCount = (maxToStash >= 0) ? maxToStash : ownModels.size();
if (maxModelsCount < 1) { return stashModels; } if (maxModelsCount < 1) { return stashModels; }
int c = 0; // counter int c = 0; // counter
@@ -322,21 +322,31 @@ namespace BlackCore
} }
// values to be skipped // values to be skipped
if (maxToStash >= 0 && maxToStash == stashModels.size()) { break; } if (maxToStash >= 0 && stashModels.size() > maxToStash) { break; }
if (!dbKeys.contains(ownModel.getModelString())) { continue; } if (!dbKeys.contains(ownModel.getModelString())) { continue; }
if (ownModel.matchesSimulatorFlag(CSimulatorInfo::XPLANE)) { continue; } if (ownModel.matchesSimulatorFlag(CSimulatorInfo::XPLANE)) { continue; }
// in DB // in DB
CAircraftModel dbModel = dbFsFamilyModels.findFirstByModelStringOrDefault(ownModel.getModelString()); CAircraftModel dbModel = dbFsFamilyModels.findFirstByModelStringOrDefault(ownModel.getModelString());
if (!dbModel.isLoadedFromDb()) {continue; } if (!dbModel.isLoadedFromDb()) { continue; }
if (dbModel.getSimulator() == ownModel.getSimulator()) { continue; }
// update simulator and add // update simulator and add
CSimulatorInfo simulator(dbModel.getSimulator()); CSimulatorInfo simulator(dbModel.getSimulator());
simulator.add(ownModel.getSimulator()); const CSimulatorInfo dbModelSimulator(simulator);
const CSimulatorInfo delta = simulator.add(ownModel.getSimulator());
if (delta.getSimulator() == CSimulatorInfo::None) { continue; }
dbModel.setSimulator(simulator); dbModel.setSimulator(simulator);
stashModels.push_back(dbModel); stashModels.push_back(dbModel); // changed DB model
if (updateInfo)
{
const CStatusMessage m = CStatusMessage(getLogCategories()).info("%1 -> %2 (%3) for '%4'")
<< dbModelSimulator.toQString(true) << simulator.toQString(true)
<< delta.toQString(true) << dbModel.getModelStringAndDbKey();
updateInfo->push_back(m);
} }
}
progressIndicator->updateProgressIndicatorAndProcessEvents(100);
return stashModels; return stashModels;
} }

View File

@@ -71,7 +71,7 @@ namespace BlackCore
static int fillInMissingAircraftAndLiveryEntities(BlackMisc::Simulation::CAircraftModelList &models); static int fillInMissingAircraftAndLiveryEntities(BlackMisc::Simulation::CAircraftModelList &models);
//! Create stash models if the DB models miss that simulator //! Create stash models if the DB models miss that simulator
static BlackMisc::Simulation::CAircraftModelList updateSimulatorForFsFamily(const BlackMisc::Simulation::CAircraftModelList &ownModels, int maxToStash = -1, BlackCore::IProgressIndicator *progressIndicator = nullptr, bool processEvents = true); static BlackMisc::Simulation::CAircraftModelList updateSimulatorForFsFamily(const BlackMisc::Simulation::CAircraftModelList &ownModels, BlackMisc::CStatusMessageList *updateInfo, int maxToStash = -1, BlackCore::IProgressIndicator *progressIndicator = nullptr, bool processEvents = true);
//! Database JSON from content string, which can be compressed //! Database JSON from content string, which can be compressed
static QJsonDocument databaseJsonToQJsonDocument(const QString &content); static QJsonDocument databaseJsonToQJsonDocument(const QString &content);

View File

@@ -97,7 +97,7 @@ namespace BlackGui
} }
else else
{ {
int selected = this->currentModelView()->selectedRowCount(); const int selected = this->currentModelView()->selectedRowCount();
ui->le_Selected->setText(QString::number(selected)); ui->le_Selected->setText(QString::number(selected));
} }
} }
@@ -108,6 +108,15 @@ namespace BlackGui
ui->tvp_StatusMessages->insert(msg); ui->tvp_StatusMessages->insert(msg);
} }
void CDbAutoSimulatorStashingComponent::addStatusMessages(const CStatusMessageList &msgs)
{
if (msgs.isEmpty()) { return; }
for (const CStatusMessage &msg : msgs)
{
this->addStatusMessage(msg);
}
}
void CDbAutoSimulatorStashingComponent::addStatusMessage(const CStatusMessage &msg, const CAircraftModel &model) void CDbAutoSimulatorStashingComponent::addStatusMessage(const CStatusMessage &msg, const CAircraftModel &model)
{ {
if (msg.isEmpty()) { return; } if (msg.isEmpty()) { return; }
@@ -139,13 +148,14 @@ namespace BlackGui
const bool selected = ui->rb_SelectedOnly->isChecked(); const bool selected = ui->rb_SelectedOnly->isChecked();
int ownModelsCount = 0; int ownModelsCount = 0;
CStatusMessageList info;
if (selected) if (selected)
{ {
static const QString intro("Checking %1 selected models"); static const QString intro("Checking %1 selected models");
const CAircraftModelList selectedModels(this->currentModelView()->selectedObjects()); const CAircraftModelList selectedModels(this->currentModelView()->selectedObjects());
ownModelsCount = selectedModels.size(); ownModelsCount = selectedModels.size();
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModelsCount))); this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModelsCount)));
m_modelsToStash = CDatabaseUtils::updateSimulatorForFsFamily(selectedModels, maxObjectsStashed, this, true); m_modelsToStash = CDatabaseUtils::updateSimulatorForFsFamily(selectedModels, &info, maxObjectsStashed, this, true);
} }
else else
{ {
@@ -160,10 +170,12 @@ namespace BlackGui
const QString sim = simulator.toQString(); const QString sim = simulator.toQString();
ownModelsCount += ownModels.size(); ownModelsCount += ownModels.size();
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModels.size()).arg(sim))); this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModels.size()).arg(sim)));
m_modelsToStash.push_back(CDatabaseUtils::updateSimulatorForFsFamily(ownModels, maxObjectsStashed, this, true)); m_modelsToStash.push_back(CDatabaseUtils::updateSimulatorForFsFamily(ownModels, &info, maxObjectsStashed, this, true));
} }
} }
const QString result("Tested %1 own models, %2 models should be updated in DB"); const QString result("Tested %1 own models, %2 models should be updated in DB");
this->addStatusMessages(info);
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, result.arg(ownModelsCount).arg(m_modelsToStash.size()))); this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, result.arg(ownModelsCount).arg(m_modelsToStash.size())));
m_state = Completed; m_state = Completed;
} }

View File

@@ -76,6 +76,9 @@ namespace BlackGui
//! Add a status message //! Add a status message
void addStatusMessage(const BlackMisc::CStatusMessage &msg); void addStatusMessage(const BlackMisc::CStatusMessage &msg);
//! Add a status messages
void addStatusMessages(const BlackMisc::CStatusMessageList &msgs);
//! Add a status message for a given model (prefixed) //! Add a status message for a given model (prefixed)
void addStatusMessage(const BlackMisc::CStatusMessage &msg, const BlackMisc::Simulation::CAircraftModel &model); void addStatusMessage(const BlackMisc::CStatusMessage &msg, const BlackMisc::Simulation::CAircraftModel &model);