diff --git a/src/blackgui/components/dbmappingcomponent.cpp b/src/blackgui/components/dbmappingcomponent.cpp
index 03706d20e..356c5d0a1 100644
--- a/src/blackgui/components/dbmappingcomponent.cpp
+++ b/src/blackgui/components/dbmappingcomponent.cpp
@@ -44,7 +44,6 @@ namespace BlackGui
this->ui->tvp_OwnAircraftModels->addFilterDialog();
// connects
- connect(ui->editor_Model, &CModelMappingForm::requestPublish, this, &CDbMappingComponent::ps_publishSingleModelToDb);
connect(ui->editor_Model, &CModelMappingForm::requestStash, this, &CDbMappingComponent::ps_stashCurrentModel);
connect(ui->tvp_OwnAircraftModels, &CAircraftModelView::doubleClicked, this, &CDbMappingComponent::ps_onModelRowSelected);
@@ -244,7 +243,7 @@ namespace BlackGui
return currentTabIndex() == TabStash;
}
- CStatusMessageList CDbMappingComponent::validate(bool withNestedForms) const
+ CStatusMessageList CDbMappingComponent::validateCurrentModel(bool withNestedForms) const
{
CStatusMessageList msgs(this->ui->editor_Model->validate(!withNestedForms));
if (withNestedForms)
@@ -256,24 +255,6 @@ namespace BlackGui
return msgs;
}
- void CDbMappingComponent::ps_publishSingleModelToDb()
- {
- CStatusMessageList msgs(validate(true));
- if (msgs.hasErrorMessages())
- {
- CLogMessage::preformatted(msgs);
- this->showMessages(msgs);
- return;
- }
-
- const CAircraftModel model(getAircraftModel());
- msgs = this->asyncWriteModel(model);
- if (!msgs.isEmpty())
- {
- CLogMessage(this).preformatted(msgs);
- }
- }
-
void CDbMappingComponent::ps_handleStashDropRequest(const CAirlineIcaoCode &code) const
{
CLivery stdLivery(this->getStdLiveryForAirlineCode(code));
@@ -284,13 +265,13 @@ namespace BlackGui
void CDbMappingComponent::ps_stashCurrentModel()
{
const CAircraftModel model(getAircraftModel());
- if (!model.hasModelString())
+ CStatusMessageList msgs(this->validateCurrentModel(true));
+ if (msgs.hasErrorMessages())
{
- CStatusMessage msg = CStatusMessage(CStatusMessage::SeverityError, "no model string, ignored");
- this->showMessage(msg);
+ this->showMessages(msgs);
return;
}
- this->ui->comp_StashAircraft->stashModel(model);
+ this->ui->comp_StashAircraft->stashModel(model, true);
}
void CDbMappingComponent::resizeForSelect()
diff --git a/src/blackgui/components/dbmappingcomponent.h b/src/blackgui/components/dbmappingcomponent.h
index b0e83847f..fcf5fc1f8 100644
--- a/src/blackgui/components/dbmappingcomponent.h
+++ b/src/blackgui/components/dbmappingcomponent.h
@@ -104,7 +104,7 @@ namespace BlackGui
public slots:
//! Validate, empty list means OK
- BlackMisc::CStatusMessageList validate(bool withNestedForms) const;
+ BlackMisc::CStatusMessageList validateCurrentModel(bool withNestedForms) const;
//! Resize so that selection is easy (larger table view)
void resizeForSelect();
@@ -128,9 +128,6 @@ namespace BlackGui
//! Stashed models changed
void ps_onStashedModelsChanged();
- //! Publish
- void ps_publishSingleModelToDb();
-
//! Stash drop request
void ps_handleStashDropRequest(const BlackMisc::Aviation::CAirlineIcaoCode &code) const;
diff --git a/src/blackgui/components/dbmappingcomponent.ui b/src/blackgui/components/dbmappingcomponent.ui
index bf659dd71..16d0106cd 100644
--- a/src/blackgui/components/dbmappingcomponent.ui
+++ b/src/blackgui/components/dbmappingcomponent.ui
@@ -6,10 +6,16 @@
0
0
- 262
+ 600
618
+
+
+ 600
+ 400
+
+
Frame
@@ -226,7 +232,7 @@
0
0
- 244
+ 582
425
diff --git a/src/blackgui/components/dbmodelcomponent.cpp b/src/blackgui/components/dbmodelcomponent.cpp
index 0a8ee6bb0..8ae39b78c 100644
--- a/src/blackgui/components/dbmodelcomponent.cpp
+++ b/src/blackgui/components/dbmodelcomponent.cpp
@@ -76,6 +76,5 @@ namespace BlackGui
{
// code goes here
}
-
} // ns
} // ns
diff --git a/src/blackgui/components/dbstashcomponent.cpp b/src/blackgui/components/dbstashcomponent.cpp
index 05af7e049..a45341902 100644
--- a/src/blackgui/components/dbstashcomponent.cpp
+++ b/src/blackgui/components/dbstashcomponent.cpp
@@ -38,14 +38,15 @@ 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->pb_Publish, &QPushButton::pressed, this, &CDbStashComponent::ps_onPublishPressed);
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);
- connect(this->ui->pb_AirlineIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
- connect(this->ui->pb_Livery, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
- connect(this->ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverValues);
+ connect(this->ui->pb_AircraftIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected);
+ connect(this->ui->pb_AirlineIcao, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected);
+ connect(this->ui->pb_Livery, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected);
+ connect(this->ui->pb_Distributor, &QPushButton::pressed, this, &CDbStashComponent::ps_copyOverPartsToSelected);
ui->tvp_StashAircraftModels->setCustomMenu(new CStashModelsMenu(this, true));
this->enableButtonRow();
@@ -57,6 +58,10 @@ namespace BlackGui
void CDbStashComponent::setProvider(IWebDataServicesProvider *provider)
{
CWebDataServicesAware::setProvider(provider);
+ provider->connectDataPublishSignal(
+ this,
+ std::bind(&CDbStashComponent::ps_publishResponse, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)
+ );
}
void CDbStashComponent::gracefulShutdown()
@@ -64,23 +69,33 @@ namespace BlackGui
// shutdown
}
- CStatusMessage CDbStashComponent::validateStashModel(const CAircraftModel &model) const
+ CStatusMessage CDbStashComponent::validateStashModel(const CAircraftModel &model, bool allowReplace) const
{
- static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
- if (this->ui->tvp_StashAircraftModels->container().containsModelStringOrId(model))
+ if (!allowReplace && this->ui->tvp_StashAircraftModels->container().containsModelStringOrId(model))
{
const QString msg("Model \"%1\" already stashed");
- return CStatusMessage(cats, CStatusMessage::SeverityError, msg.arg(model.getModelString()));
+ return CStatusMessage(validationCats(), CStatusMessage::SeverityError, msg.arg(model.getModelString()));
}
return CStatusMessage();
}
- CStatusMessage CDbStashComponent::stashModel(const CAircraftModel &model)
+ CStatusMessage CDbStashComponent::stashModel(const CAircraftModel &model, bool replace)
{
- CStatusMessage m(validateStashModel(model));
+ CStatusMessage m(validateStashModel(model, replace));
if (!m.isWarningOrAbove())
{
- this->ui->tvp_StashAircraftModels->insert(model);
+ if (replace)
+ {
+ this->ui->tvp_StashAircraftModels->replaceOrAdd(&CAircraftModel::getModelString, model.getModelString(), model);
+ }
+ else
+ {
+ this->ui->tvp_StashAircraftModels->insert(model);
+ }
+ }
+ else
+ {
+ this->showMessage(m);
}
return m;
}
@@ -107,6 +122,11 @@ namespace BlackGui
return !this->ui->tvp_StashAircraftModels->isEmpty();
}
+ int CDbStashComponent::getStashedModelsCount() const
+ {
+ return this->ui->tvp_StashAircraftModels->rowCount();
+ }
+
QStringList CDbStashComponent::getStashedModelStrings() const
{
return this->ui->tvp_StashAircraftModels->derivedModel()->getModelStrings(false);
@@ -170,25 +190,67 @@ namespace BlackGui
void CDbStashComponent::ps_onValidatePressed()
{
if (this->ui->tvp_StashAircraftModels->isEmpty()) {return; }
- const CStatusMessageList msgs(this->validate());
- this->showMessages(msgs);
+ this->validateAndDisplay(true);
+ }
+
+ void CDbStashComponent::ps_onPublishPressed()
+ {
+ if (this->ui->tvp_StashAircraftModels->isEmpty()) {return; }
+ if (!this->validateAndDisplay()) { return; }
+ CAircraftModelList models(getSelectedOrAllModels());
+ if (models.isEmpty()) { return; }
+ CStatusMessageList msgs = this->asyncPublishModels(models);
+ if (msgs.hasWarningOrErrorMessages())
+ {
+ this->showMessages(msgs);
+ }
+ }
+
+ void CDbStashComponent::ps_publishResponse(const CAircraftModelList &publishedModels, const CAircraftModelList &skippedModels, const CStatusMessageList &msgs)
+ {
+ if (!msgs.isEmpty())
+ {
+ this->showMessages(msgs);
+ }
+
+ Q_UNUSED(publishedModels);
+ Q_UNUSED(skippedModels);
}
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());
+ CAircraftModelList models(getSelectedOrAllModels());
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()))
+ CStatusMessage(validationCats(), CStatusMessage::SeverityInfo, QString("No errors in %1 model(s)").arg(models.size()))
});
}
+ bool CDbStashComponent::validateAndDisplay(bool displayInfo)
+ {
+ const CStatusMessageList msgs(this->validate());
+ if (msgs.hasWarningOrErrorMessages())
+ {
+ this->showMessages(msgs);
+ return false;
+ }
+ else
+ {
+ if (displayInfo)
+ {
+ QString no = QString::number(this->getStashedModelsCount());
+ CStatusMessage msg(validationCats(), CStatusMessage::SeverityInfo, "Validation passed for " + no + " models");
+ this->showMessage(msg);
+ }
+ return true; // no error
+ }
+ }
+
void CDbStashComponent::enableButtonRow()
{
bool e = !this->ui->tvp_StashAircraftModels->isEmpty();
@@ -201,7 +263,20 @@ namespace BlackGui
this->ui->pb_Validate->setEnabled(e);
}
- void CDbStashComponent::ps_copyOverValues()
+ const CLogCategoryList &CDbStashComponent::validationCats() const
+ {
+ static const CLogCategoryList cats(CLogCategoryList(this).join({ CLogCategory::validation()}));
+ return cats;
+ }
+
+ CAircraftModelList CDbStashComponent::getSelectedOrAllModels() const
+ {
+ bool selectedOnly = ui->cb_SelectedOnly->isChecked();
+ const CAircraftModelList models(selectedOnly ? this->ui->tvp_StashAircraftModels->selectedObjects() : this->ui->tvp_StashAircraftModels->container());
+ return models;
+ }
+
+ void CDbStashComponent::ps_copyOverPartsToSelected()
{
QObject *sender = QObject::sender();
BLACK_VERIFY_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
@@ -234,22 +309,22 @@ namespace BlackGui
this->enableButtonRow();
}
- bool CDbStashComponent::showMessages(const CStatusMessageList &msgs, bool onlyErrors)
+ bool CDbStashComponent::showMessages(const CStatusMessageList &msgs, bool onlyErrors, int timeoutMs)
{
if (msgs.isEmpty()) { return false; }
if (!msgs.hasErrorMessages() && onlyErrors) { return false; }
BLACK_VERIFY_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
if (!this->getMappingComponent()) { return false; }
- this->getMappingComponent()->showMessages(msgs);
+ this->getMappingComponent()->showMessages(msgs, timeoutMs);
return true;
}
- bool CDbStashComponent::showMessage(const CStatusMessage &msg)
+ bool CDbStashComponent::showMessage(const CStatusMessage &msg, int timeoutMs)
{
if (msg.isEmpty()) { return false; }
BLACK_VERIFY_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
if (!this->getMappingComponent()) { return false; }
- this->getMappingComponent()->showMessage(msg);
+ this->getMappingComponent()->showMessage(msg, timeoutMs);
return true;
}
diff --git a/src/blackgui/components/dbstashcomponent.h b/src/blackgui/components/dbstashcomponent.h
index f02159d39..4d967ccc9 100644
--- a/src/blackgui/components/dbstashcomponent.h
+++ b/src/blackgui/components/dbstashcomponent.h
@@ -52,10 +52,10 @@ namespace BlackGui
void gracefulShutdown();
//! Test the given model if it can be stashed
- BlackMisc::CStatusMessage validateStashModel(const BlackMisc::Simulation::CAircraftModel &model) const;
+ BlackMisc::CStatusMessage validateStashModel(const BlackMisc::Simulation::CAircraftModel &model, bool allowReplace) const;
//! Stash given model
- BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model);
+ BlackMisc::CStatusMessage stashModel(const BlackMisc::Simulation::CAircraftModel &model, bool replace = false);
//! Stash given models
BlackMisc::CStatusMessageList stashModels(const BlackMisc::Simulation::CAircraftModelList &models);
@@ -66,6 +66,9 @@ namespace BlackGui
//! Has stashed models
bool hasStashedModels() const;
+ //! Number of models
+ int getStashedModelsCount() const;
+
//! Stashed model strings
QStringList getStashedModelStrings() const;
@@ -98,8 +101,16 @@ namespace BlackGui
//! Validate pressed
void ps_onValidatePressed();
+ //! Publish pressed
+ void ps_onPublishPressed();
+
+ //! Publish response received
+ void ps_publishResponse(const BlackMisc::Simulation::CAircraftModelList &publishedModels,
+ const BlackMisc::Simulation::CAircraftModelList &skippedModels,
+ const BlackMisc::CStatusMessageList &msgs);
+
//! Copy over values
- void ps_copyOverValues();
+ void ps_copyOverPartsToSelected();
//! Row count changed
void ps_onRowCountChanged(int number, bool filter);
@@ -108,17 +119,26 @@ namespace BlackGui
QScopedPointer ui;
//! Display messages
- bool showMessages(const BlackMisc::CStatusMessageList &msgs, bool onlyErrors = false);
+ bool showMessages(const BlackMisc::CStatusMessageList &msgs, bool onlyErrors = false, int timeoutMs = -1);
//! Display message
- bool showMessage(const BlackMisc::CStatusMessage &msg);
+ bool showMessage(const BlackMisc::CStatusMessage &msg, int timeoutMs = -1);
//! Validate
BlackMisc::CStatusMessageList validate() const;
+ //! Validate and display info messages
+ bool validateAndDisplay(bool displayInfo = false);
+
//! Set the button row
void enableButtonRow();
+ //! Validation categories
+ const BlackMisc::CLogCategoryList &validationCats() const;
+
+ //! Get the selected only models or all models depending on checkbox
+ BlackMisc::Simulation::CAircraftModelList getSelectedOrAllModels() const;
+
//! Custom menu for the stashed models
class CStashModelsMenu : public BlackGui::IMenuDelegate
{