mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
refs #562, allow to validate models
* GUI part * allow to merge a list of messages into one * validation function
This commit is contained in:
@@ -173,5 +173,30 @@ namespace BlackMisc
|
||||
}
|
||||
}
|
||||
|
||||
CStatusMessageList CAircraftModelList::validateForPublishing() const
|
||||
{
|
||||
if (this->isEmpty()) { return CStatusMessageList(); }
|
||||
CStatusMessageList msgs;
|
||||
for (const CAircraftModel &model : *this)
|
||||
{
|
||||
const CStatusMessageList msgsModel(model.validate(false));
|
||||
CStatusMessage msgModel(msgsModel.toSingleMessage());
|
||||
|
||||
QStringList subMsgs;
|
||||
if (!model.getDistributor().hasValidDbKey()) { subMsgs << "No distributor from DB"; }
|
||||
if (!model.getAircraftIcaoCode().hasValidDbKey()) { subMsgs << "No aircraft ICAO from DB"; }
|
||||
if (!model.getLivery().hasValidDbKey()) { subMsgs << "No livery from DB"; }
|
||||
if (!model.getLivery().getAirlineIcaoCode().hasValidDbKey()) { subMsgs << "No airline ICAO from DB"; }
|
||||
CStatusMessage msgDb(CStatusMessage::SeverityError, subMsgs.join(", "));
|
||||
|
||||
CStatusMessage singleMsg(CStatusMessageList({msgModel, msgDb}).toSingleMessage());
|
||||
if (model.hasModelString())
|
||||
{
|
||||
singleMsg.prependMessage(model.getModelString() + ": ");
|
||||
}
|
||||
msgs.push_back(singleMsg);
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
} // namespace
|
||||
} // namespace
|
||||
|
||||
@@ -86,6 +86,9 @@ namespace BlackMisc
|
||||
|
||||
//! Update livery
|
||||
void updateLivery(const BlackMisc::Aviation::CLivery &livery);
|
||||
|
||||
//! Validate for publishing
|
||||
CStatusMessageList validateForPublishing() const;
|
||||
};
|
||||
|
||||
} //namespace
|
||||
|
||||
@@ -130,6 +130,18 @@ namespace BlackMisc
|
||||
return patternNames;
|
||||
}
|
||||
|
||||
void CStatusMessage::prependMessage(const QString &msg)
|
||||
{
|
||||
if (msg.isEmpty()) { return; }
|
||||
this->m_message = msg + this->m_message;
|
||||
}
|
||||
|
||||
void CStatusMessage::appendMessage(const QString &msg)
|
||||
{
|
||||
if (msg.isEmpty()) { return; }
|
||||
this->m_message += msg;
|
||||
}
|
||||
|
||||
void CStatusMessage::markAsHandledBy(const QObject *object) const
|
||||
{
|
||||
this->m_handledByObjects.push_back(quintptr(object));
|
||||
|
||||
@@ -103,6 +103,12 @@ namespace BlackMisc
|
||||
//! Message
|
||||
QString getMessage() const { return this->m_message; }
|
||||
|
||||
//! Prepend message
|
||||
void prependMessage(const QString &msg);
|
||||
|
||||
//! Append message
|
||||
void appendMessage(const QString &msg);
|
||||
|
||||
//! Message empty
|
||||
bool isEmpty() const { return this->m_message.isEmpty(); }
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "statusmessagelist.h"
|
||||
#include "statusmessage.h"
|
||||
#include "logcategorylist.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -72,6 +73,37 @@ namespace BlackMisc
|
||||
{
|
||||
msg.setCategories(categories);
|
||||
}
|
||||
|
||||
CStatusMessage::StatusSeverity CStatusMessageList::worstSeverity() const
|
||||
{
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityDebug;
|
||||
for (const CStatusMessage &msg : *this)
|
||||
{
|
||||
CStatusMessage::StatusSeverity ms = msg.getSeverity();
|
||||
if (ms == CStatusMessage::SeverityError) { return CStatusMessage::SeverityError; }
|
||||
if (ms <= s) { continue; }
|
||||
s = ms;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
CStatusMessage CStatusMessageList::toSingleMessage() const
|
||||
{
|
||||
if (this->isEmpty()) { return CStatusMessage(); }
|
||||
if (this->size() == 1) { return this->front(); }
|
||||
QStringList newMsgs;
|
||||
CStatusMessage::StatusSeverity s = CStatusMessage::SeverityDebug;
|
||||
CLogCategoryList cats;
|
||||
for (const CStatusMessage &msg : *this)
|
||||
{
|
||||
if (msg.isEmpty()) { continue; }
|
||||
newMsgs.append(msg.getMessage());
|
||||
CStatusMessage::StatusSeverity ms = msg.getSeverity();
|
||||
if (s < ms) { s = ms; }
|
||||
cats.join(msg.getCategories());
|
||||
}
|
||||
const CStatusMessage newMsg(cats, s, newMsgs.join(", "));
|
||||
return newMsg;
|
||||
}
|
||||
|
||||
CStatusMessageList CStatusMessageList::fromDatabaseJson(const QJsonArray &array)
|
||||
|
||||
@@ -64,6 +64,12 @@ namespace BlackMisc
|
||||
//! Reset the categories of all messages in the list
|
||||
void setCategories(const CLogCategoryList &categories);
|
||||
|
||||
//! Find worst severity
|
||||
CStatusMessage::StatusSeverity worstSeverity() const;
|
||||
|
||||
//! Merge into a single message
|
||||
CStatusMessage toSingleMessage() const;
|
||||
|
||||
//! From our database JSON format
|
||||
static CStatusMessageList fromDatabaseJson(const QJsonArray &array);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user