mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-09 21:45:34 +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:
@@ -39,6 +39,7 @@ namespace BlackGui
|
|||||||
connect(this->ui->pb_Unstash, &QPushButton::pressed, this, &CDbStashComponent::ps_onUnstashPressed);
|
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->pb_Validate, &QPushButton::pressed, this, &CDbStashComponent::ps_onValidatePressed);
|
||||||
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::modelChanged, this, &CDbStashComponent::stashedModelsChanged);
|
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::modelChanged, this, &CDbStashComponent::stashedModelsChanged);
|
||||||
|
connect(this->ui->tvp_StashAircraftModels, &CAircraftModelView::rowCountChanged, this, &CDbStashComponent::ps_onRowCountChanged);
|
||||||
|
|
||||||
// copy over buttons
|
// copy over buttons
|
||||||
connect(this->ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
|
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);
|
connect(this->ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
|
||||||
|
|
||||||
ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true));
|
ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true));
|
||||||
|
this->enableButtonRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
CDbStashComponent::~CDbStashComponent()
|
CDbStashComponent::~CDbStashComponent()
|
||||||
@@ -167,7 +169,36 @@ namespace BlackGui
|
|||||||
|
|
||||||
void CDbStashComponent::ps_onValidatePressed()
|
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()
|
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)
|
bool CDbStashComponent::showMessages(const CStatusMessageList &msgs, bool onlyErrors)
|
||||||
{
|
{
|
||||||
if (msgs.isEmpty()) { return false; }
|
if (msgs.isEmpty()) { return false; }
|
||||||
|
|||||||
@@ -101,6 +101,9 @@ namespace BlackGui
|
|||||||
//! Copy over values
|
//! Copy over values
|
||||||
void ps_copyOverValues();
|
void ps_copyOverValues();
|
||||||
|
|
||||||
|
//! Row count changed
|
||||||
|
void ps_onRowCountChanged(int number, bool filter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QScopedPointer<Ui::CDbStashComponent> ui;
|
QScopedPointer<Ui::CDbStashComponent> ui;
|
||||||
|
|
||||||
@@ -110,6 +113,12 @@ namespace BlackGui
|
|||||||
//! Display message
|
//! Display message
|
||||||
bool showMessage(const BlackMisc::CStatusMessage &msg);
|
bool showMessage(const BlackMisc::CStatusMessage &msg);
|
||||||
|
|
||||||
|
//! Validate
|
||||||
|
BlackMisc::CStatusMessageList validate() const;
|
||||||
|
|
||||||
|
//! Set the button row
|
||||||
|
void enableButtonRow();
|
||||||
|
|
||||||
//! Custom menu for the stashed models
|
//! Custom menu for the stashed models
|
||||||
class CStashModelsMenu : public BlackGui::IMenuDelegate
|
class CStashModelsMenu : public BlackGui::IMenuDelegate
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -97,6 +97,16 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</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>
|
<item>
|
||||||
<widget class="Line" name="line_Sep2">
|
<widget class="Line" name="line_Sep2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|||||||
@@ -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
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -86,6 +86,9 @@ namespace BlackMisc
|
|||||||
|
|
||||||
//! Update livery
|
//! Update livery
|
||||||
void updateLivery(const BlackMisc::Aviation::CLivery &livery);
|
void updateLivery(const BlackMisc::Aviation::CLivery &livery);
|
||||||
|
|
||||||
|
//! Validate for publishing
|
||||||
|
CStatusMessageList validateForPublishing() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
} //namespace
|
} //namespace
|
||||||
|
|||||||
@@ -130,6 +130,18 @@ namespace BlackMisc
|
|||||||
return patternNames;
|
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
|
void CStatusMessage::markAsHandledBy(const QObject *object) const
|
||||||
{
|
{
|
||||||
this->m_handledByObjects.push_back(quintptr(object));
|
this->m_handledByObjects.push_back(quintptr(object));
|
||||||
|
|||||||
@@ -103,6 +103,12 @@ namespace BlackMisc
|
|||||||
//! Message
|
//! Message
|
||||||
QString getMessage() const { return this->m_message; }
|
QString getMessage() const { return this->m_message; }
|
||||||
|
|
||||||
|
//! Prepend message
|
||||||
|
void prependMessage(const QString &msg);
|
||||||
|
|
||||||
|
//! Append message
|
||||||
|
void appendMessage(const QString &msg);
|
||||||
|
|
||||||
//! Message empty
|
//! Message empty
|
||||||
bool isEmpty() const { return this->m_message.isEmpty(); }
|
bool isEmpty() const { return this->m_message.isEmpty(); }
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include "statusmessagelist.h"
|
#include "statusmessagelist.h"
|
||||||
#include "statusmessage.h"
|
#include "statusmessage.h"
|
||||||
|
#include "logcategorylist.h"
|
||||||
|
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -72,6 +73,37 @@ namespace BlackMisc
|
|||||||
{
|
{
|
||||||
msg.setCategories(categories);
|
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)
|
CStatusMessageList CStatusMessageList::fromDatabaseJson(const QJsonArray &array)
|
||||||
|
|||||||
@@ -64,6 +64,12 @@ namespace BlackMisc
|
|||||||
//! Reset the categories of all messages in the list
|
//! Reset the categories of all messages in the list
|
||||||
void setCategories(const CLogCategoryList &categories);
|
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
|
//! From our database JSON format
|
||||||
static CStatusMessageList fromDatabaseJson(const QJsonArray &array);
|
static CStatusMessageList fromDatabaseJson(const QJsonArray &array);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user