refs #562, allow to validate models

* GUI part
* allow to merge a list of messages into one
* validation function
This commit is contained in:
Klaus Basan
2015-12-20 16:29:32 +01:00
parent 459b935e3b
commit 3387caabdc
9 changed files with 142 additions and 1 deletions

View File

@@ -39,6 +39,7 @@ namespace BlackGui
connect(this->ui->pb_Unstash, &QPushButton::pressed, this, &CDbStashComponent::ps_onUnstashPressed);
connect(this->ui->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::ps_onValidatePressed);
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::modelChanged, this, &CDbStashComponent::stashedModelsChanged);
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbStashComponent::ps_onRowCountChanged);
// copy over buttons
connect(this->ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
@@ -47,6 +48,7 @@ namespace BlackGui
connect(this->ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true));
this->enableButtonRow();
}
CDbStashComponent::~CDbStashComponent()
@@ -167,7 +169,36 @@ namespace BlackGui
void CDbStashComponent::ps_onValidatePressed()
{
if (this->ui->tvp_StashAircraftModels->isEmpty()) { return; }
if (this->ui->tvp_StashAircraftModels->isEmpty()) {return; }
const CStatusMessageList msgs(this->validate());
this->showMessages(msgs);
}
CStatusMessageList CDbStashComponent::validate() const
{
if (this->ui->tvp_StashAircraftModels->isEmpty()) {return CStatusMessageList(); }
bool selectedOnly = ui->cb_SelectedOnly->isChecked();
const CAircraftModelList models(selectedOnly ? this->ui->tvp_StashAircraftModels->selectedObjects() : this->ui->tvp_StashAircraftModels->container());
if (models.isEmpty()) { return CStatusMessageList(); }
const CStatusMessageList msgs(models.validateForPublishing());
if (!msgs.isEmpty()) { return msgs; }
return CStatusMessageList(
{
CStatusMessage(CStatusMessage::SeverityInfo, QString("No errors in %1 model(s)").arg(models.size()))
});
}
void CDbStashComponent::enableButtonRow()
{
bool e = !this->ui->tvp_StashAircraftModels->isEmpty();
this->ui->pb_AircraftIcao->setEnabled(e);
this->ui->pb_AirlineIcao->setEnabled(e);
this->ui->pb_Distributor->setEnabled(e);
this->ui->pb_Livery->setEnabled(e);
this->ui->pb_Publish->setEnabled(e);
this->ui->pb_Unstash->setEnabled(e);
this->ui->pb_Validate->setEnabled(e);
}
void CDbStashComponent::ps_copyOverValues()
@@ -196,6 +227,13 @@ namespace BlackGui
}
}
void CDbStashComponent::ps_onRowCountChanged(int number, bool filter)
{
Q_UNUSED(number);
Q_UNUSED(filter);
this->enableButtonRow();
}
bool CDbStashComponent::showMessages(const CStatusMessageList &msgs, bool onlyErrors)
{
if (msgs.isEmpty()) { return false; }

View File

@@ -101,6 +101,9 @@ namespace BlackGui
//! Copy over values
void ps_copyOverValues();
//! Row count changed
void ps_onRowCountChanged(int number, bool filter);
private:
QScopedPointer<Ui::CDbStashComponent> ui;
@@ -110,6 +113,12 @@ namespace BlackGui
//! Display message
bool showMessage(const BlackMisc::CStatusMessage &msg);
//! Validate
BlackMisc::CStatusMessageList validate() const;
//! Set the button row
void enableButtonRow();
//! Custom menu for the stashed models
class CStashModelsMenu : public BlackGui::IMenuDelegate
{

View File

@@ -97,6 +97,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cb_SelectedOnly">
<property name="toolTip">
<string>selected models only</string>
</property>
<property name="text">
<string>selected</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_Sep2">
<property name="orientation">

View File

@@ -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

View File

@@ -86,6 +86,9 @@ namespace BlackMisc
//! Update livery
void updateLivery(const BlackMisc::Aviation::CLivery &livery);
//! Validate for publishing
CStatusMessageList validateForPublishing() const;
};
} //namespace

View File

@@ -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));

View File

@@ -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(); }

View File

@@ -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)

View File

@@ -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);
};