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