mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Load/save invalid models to file, originally Ref T247
This commit is contained in:
committed by
Mat Sutcliffe
parent
8344f03cf3
commit
e53e37f770
@@ -29,6 +29,7 @@ namespace BlackGui
|
||||
ui->comp_Simulator->setMode(CSimulatorSelector::ComboBox);
|
||||
ui->comp_Simulator->setRememberSelection(false);
|
||||
ui->comp_Messages->setNoSorting(); // keep order
|
||||
ui->tvp_InvalidModels->setValidationContextMenu(false);
|
||||
|
||||
const CAircraftMatcherSetup setup = m_matchingSettings.get();
|
||||
ui->cb_EnableStartupCheck->setChecked(setup.doVerificationAtStartup());
|
||||
@@ -84,6 +85,7 @@ namespace BlackGui
|
||||
if (!sGui || sGui->isShuttingDown() || !sGui->supportsContexts()) { return; }
|
||||
if (!sGui->getIContextSimulator()) { return; }
|
||||
sGui->getIContextSimulator()->disableModelsForMatching(models, true);
|
||||
this->saveInvalidModels(models);
|
||||
}
|
||||
|
||||
void CAircraftModelValidationComponent::onCheckAtStartupChanged(bool checked)
|
||||
@@ -131,8 +133,26 @@ namespace BlackGui
|
||||
void CAircraftModelValidationComponent::onButtonClicked()
|
||||
{
|
||||
const QObject *sender = QObject::sender();
|
||||
if (sender == ui->pb_TempDisableInvalid) { this->tempDisableModels(ui->tvp_InvalidModels->container()); }
|
||||
else if (sender == ui->pb_TempDisableSelected) { this->tempDisableModels(ui->tvp_InvalidModels->selectedObjects()); }
|
||||
CAircraftModelList disabledModels;
|
||||
if (sender == ui->pb_TempDisableInvalid) { disabledModels = ui->tvp_InvalidModels->container(); }
|
||||
else if (sender == ui->pb_TempDisableSelected) { disabledModels = ui->tvp_InvalidModels->selectedObjects(); }
|
||||
|
||||
this->tempDisableModels(disabledModels);
|
||||
|
||||
if (disabledModels.isEmpty())
|
||||
{
|
||||
this->showOverlayHTMLMessage("No models disabled");
|
||||
}
|
||||
else
|
||||
{
|
||||
this->showOverlayHTMLMessage(QStringLiteral("%1 models disabled").arg(disabledModels.size()));
|
||||
}
|
||||
}
|
||||
|
||||
void CAircraftModelValidationComponent::saveInvalidModels(const CAircraftModelList &models) const
|
||||
{
|
||||
const CStatusMessage m = models.saveInvalidModels();
|
||||
Q_UNUSED(m);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -70,6 +70,9 @@ namespace BlackGui
|
||||
|
||||
//! Button has been clicked
|
||||
void onButtonClicked();
|
||||
|
||||
//! Save invalid models
|
||||
void saveInvalidModels(const BlackMisc::Simulation::CAircraftModelList &models) const;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
@@ -13,6 +13,8 @@
|
||||
#include "blackmisc/compare.h"
|
||||
#include "blackmisc/iterator.h"
|
||||
#include "blackmisc/range.h"
|
||||
#include "fileutils.h"
|
||||
#include "directoryutils.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
|
||||
@@ -1560,6 +1562,23 @@ namespace BlackMisc
|
||||
return stats;
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelList::saveInvalidModels() const
|
||||
{
|
||||
if (this->isEmpty()) { return CStatusMessage(this).info(u"No models"); }
|
||||
const QString json = this->toJsonString();
|
||||
const bool s = CFileUtils::writeStringToFile(json, invalidModelFileAndPath());
|
||||
if (!s) { return CStatusMessage(this).error(u"Unable to save %1 entries to '%2'") << this->size() << invalidModelFileAndPath(); }
|
||||
return CStatusMessage(this).info(u"Saved %1 entries to '%2'") << this->size() << invalidModelFileAndPath();
|
||||
}
|
||||
|
||||
CStatusMessage CAircraftModelList::loadInvalidModels()
|
||||
{
|
||||
const QString json = CFileUtils::readFileToString(invalidModelFileAndPath());
|
||||
if (json.isEmpty()) { return CStatusMessage(this).error(u"Unable to read from '%1'") << invalidModelFileAndPath(); }
|
||||
*this = CAircraftModelList::fromJson(json, true);
|
||||
return CStatusMessage(this).info(u"Loaded %1 entries from '%2'") << this->size() << invalidModelFileAndPath();
|
||||
}
|
||||
|
||||
CAircraftModelList CAircraftModelList::fromDatabaseJsonCaching(
|
||||
const QJsonArray &array,
|
||||
const CAircraftIcaoCodeList &icaos,
|
||||
@@ -1580,5 +1599,18 @@ namespace BlackMisc
|
||||
}
|
||||
return models;
|
||||
}
|
||||
|
||||
const QString &CAircraftModelList::invalidModelFileAndPath()
|
||||
{
|
||||
static const QString f = CFileUtils::appendFilePathsAndFixUnc(CDirectoryUtils::logDirectory(), "invalidmodels.json");
|
||||
return f;
|
||||
}
|
||||
|
||||
bool CAircraftModelList::hasInvalidModelFile()
|
||||
{
|
||||
const QFileInfo fi(invalidModelFileAndPath());
|
||||
return fi.exists();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -20,12 +20,13 @@
|
||||
#include "blackmisc/aviation/liverylist.h"
|
||||
#include "blackmisc/aviation/callsignobjectlist.h"
|
||||
#include "blackmisc/db/datastoreobjectlist.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/orderablelist.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
@@ -480,6 +481,13 @@ namespace BlackMisc
|
||||
//! A HTML summary of the data in the list
|
||||
QString htmlStatistics(bool aircraftStats, bool airlineStats) const;
|
||||
|
||||
//! Save/load invalid models @{
|
||||
CStatusMessage saveInvalidModels() const;
|
||||
CStatusMessage loadInvalidModels();
|
||||
static const QString &invalidModelFileAndPath();
|
||||
static bool hasInvalidModelFile();
|
||||
//! @}
|
||||
|
||||
//! Newer version
|
||||
static CAircraftModelList fromDatabaseJsonCaching(const QJsonArray &array,
|
||||
const Aviation::CAircraftIcaoCodeList &aircraftIcaos = {},
|
||||
|
||||
Reference in New Issue
Block a user