mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 04:25:35 +08:00
Ref T117, utility functions
* detect equal models (equal in sense of "equal for publishing", not ==) * severity functions for message list
This commit is contained in:
committed by
Mathew Sutcliffe
parent
202c37beca
commit
9903d518b0
@@ -648,6 +648,71 @@ namespace BlackMisc
|
||||
return msgs;
|
||||
}
|
||||
|
||||
//! Create an appropriate status message for an attribute comparison
|
||||
CStatusMessage equalMessage(bool same, const CAircraftModel &model, const QString &description, const QString &oldValue, const QString &newValue)
|
||||
{
|
||||
if (same)
|
||||
{
|
||||
static const CStatusMessage msgSame({ CLogCategory::validation() }, CStatusMessage::SeverityWarning, "Model '%1' same %2 '%3'");
|
||||
return CStatusMessage(msgSame) << model.getModelStringAndDbKey() << description << newValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
static const CStatusMessage msgDiff({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "Model '%1' changed %2 '%3'->'%4'");
|
||||
return CStatusMessage(msgDiff) << model.getModelStringAndDbKey() << description << oldValue << newValue;
|
||||
}
|
||||
}
|
||||
|
||||
bool CAircraftModel::isEqualForPublishing(const CAircraftModel &dbModel, CStatusMessageList *details) const
|
||||
{
|
||||
if (!dbModel.isLoadedFromDb())
|
||||
{
|
||||
static const CStatusMessage msgNoDbModel({ CLogCategory::validation() }, CStatusMessage::SeverityInfo, "No DB model yet");
|
||||
if (details) { details->push_back(msgNoDbModel); }
|
||||
return false;
|
||||
}
|
||||
|
||||
CStatusMessageList validationMsgs;
|
||||
bool changed = false;
|
||||
bool equal = dbModel.getLivery().isLoadedFromDb() && dbModel.getLivery().isDbEqual(this->getLivery());
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("livery"), dbModel.getLivery().getCombinedCodePlusInfoAndId(), this->getLivery().getCombinedCodePlusInfoAndId())); }
|
||||
changed |= !equal;
|
||||
|
||||
equal = dbModel.getAircraftIcaoCode().isLoadedFromDb() && dbModel.getAircraftIcaoCode().isDbEqual(this->getAircraftIcaoCode());
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("aircraft ICAO"), dbModel.getAircraftIcaoCode().getDesignatorDbKey(), this->getAircraftIcaoCode().getDesignatorDbKey())); }
|
||||
changed |= !equal;
|
||||
|
||||
equal = dbModel.getDistributor().isLoadedFromDb() && dbModel.getDistributor().isDbEqual(this->getDistributor());
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("distributor"), dbModel.getDistributor().getDescription(), this->getDistributor().getDescription())); }
|
||||
changed |= !equal;
|
||||
|
||||
equal = dbModel.getSimulator() == this->getSimulator();
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("simulator"), dbModel.getSimulator().toQString(), this->getSimulator().toQString())); }
|
||||
changed |= !equal;
|
||||
|
||||
equal = dbModel.getDescription() == this->getDescription();
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("description"), dbModel.getDescription(), this->getDescription())); }
|
||||
changed |= !equal;
|
||||
|
||||
equal = dbModel.getName() == this->getName();
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("name"), dbModel.getName(), this->getName())); }
|
||||
changed |= !equal;
|
||||
|
||||
equal = dbModel.getModelMode() == this->getModelMode();
|
||||
if (details) { validationMsgs.push_back(equalMessage(equal, *this, QStringLiteral("mode"), dbModel.getModelModeAsString(), this->getModelModeAsString())); }
|
||||
changed |= !equal;
|
||||
|
||||
// clean messages
|
||||
if (changed && details)
|
||||
{
|
||||
// we have a changed entity, remove the warnings as they are just noise
|
||||
validationMsgs.removeSeverity(CStatusMessage::SeverityWarning);
|
||||
}
|
||||
|
||||
if (details) { details->push_back(validationMsgs); }
|
||||
return !changed;
|
||||
}
|
||||
|
||||
QString CAircraftModel::modelTypeToString(CAircraftModel::ModelType type)
|
||||
{
|
||||
switch (type)
|
||||
|
||||
@@ -368,6 +368,9 @@ namespace BlackMisc
|
||||
//! Validate
|
||||
BlackMisc::CStatusMessageList validate(bool withNestedObjects) const;
|
||||
|
||||
//! Considered equal for publishing, compares if livery etc. are the same DB values
|
||||
bool isEqualForPublishing(const CAircraftModel &dbModel, BlackMisc::CStatusMessageList *details = nullptr) const;
|
||||
|
||||
//! Helper class used by implementation.
|
||||
using MemoHelper = CMemoHelper<Aviation::CAircraftIcaoCode, Aviation::CLivery, CDistributor>;
|
||||
|
||||
|
||||
@@ -120,6 +120,15 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
void CStatusMessageList::warningToError()
|
||||
{
|
||||
for (CStatusMessage &msg : *this)
|
||||
{
|
||||
if (msg.getSeverity() != CStatusMessage::SeverityWarning) { continue; }
|
||||
msg.setSeverity(CStatusMessage::SeverityError);
|
||||
}
|
||||
}
|
||||
|
||||
void CStatusMessageList::sortBySeverity()
|
||||
{
|
||||
this->sortBy(&CStatusMessage::getSeverity);
|
||||
@@ -132,6 +141,12 @@ namespace BlackMisc
|
||||
this->removeInfoAndBelow();
|
||||
}
|
||||
|
||||
void CStatusMessageList::removeSeverity(CStatusMessage::StatusSeverity severity)
|
||||
{
|
||||
if (this->isEmpty()) { return; }
|
||||
this->removeIf(&CStatusMessage::getSeverity, severity);
|
||||
}
|
||||
|
||||
void CStatusMessageList::removeInfoAndBelow()
|
||||
{
|
||||
if (this->isEmpty()) { return; }
|
||||
|
||||
@@ -88,12 +88,18 @@ namespace BlackMisc
|
||||
//! And higher (more critical) severity will be clipped to given severity
|
||||
void clampSeverity(CStatusMessage::StatusSeverity severity);
|
||||
|
||||
//! Turn warnings into errors
|
||||
void warningToError();
|
||||
|
||||
//! Sort by severity, lowest first
|
||||
void sortBySeverity();
|
||||
|
||||
//! Remove warnings and below
|
||||
void removeWarningsAndBelow();
|
||||
|
||||
//! Remove given severity
|
||||
void removeSeverity(CStatusMessage::StatusSeverity severity);
|
||||
|
||||
//! Remove info and below
|
||||
void removeInfoAndBelow();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user