10 #include <QPushButton>
11 #include <QStringBuilder>
16 #include "ui_dbstashcomponent.h"
38 using namespace swift::misc::simulation;
39 using namespace swift::misc::aviation;
40 using namespace swift::misc::network;
47 CDbStashComponent::CDbStashComponent(QWidget *parent)
52 connect(ui->pb_Unstash, &QPushButton::pressed,
this, &CDbStashComponent::onUnstashPressed);
53 connect(ui->pb_Validate, &QPushButton::pressed,
this, &CDbStashComponent::onValidatePressed);
54 connect(ui->pb_RemoveInvalid, &QPushButton::pressed,
this, &CDbStashComponent::onRemoveInvalidPressed);
55 connect(ui->pb_Publish, &QPushButton::pressed,
this, &CDbStashComponent::onPublishPressed);
56 connect(ui->tvp_StashAircraftModels, &CAircraftModelView::modelChanged,
this,
58 connect(ui->tvp_StashAircraftModels, &CAircraftModelView::modelDataChanged,
this,
59 &CDbStashComponent::onRowCountChanged);
62 connect(ui->pb_AircraftIcao, &QPushButton::pressed,
this, &CDbStashComponent::copyOverValuesToSelectedModels);
63 connect(ui->pb_AirlineIcao, &QPushButton::pressed,
this, &CDbStashComponent::copyOverValuesToSelectedModels);
64 connect(ui->pb_Livery, &QPushButton::pressed,
this, &CDbStashComponent::copyOverValuesToSelectedModels);
65 connect(ui->pb_Distributor, &QPushButton::pressed,
this, &CDbStashComponent::copyOverValuesToSelectedModels);
66 connect(ui->pb_Model, &QPushButton::pressed,
this, &CDbStashComponent::modifyModelDialog);
68 ui->tvp_StashAircraftModels->setAircraftModelMode(CAircraftModelListModel::StashModel);
69 ui->tvp_StashAircraftModels->allowDragDrop(
false,
true,
true);
70 ui->tvp_StashAircraftModels->setAcceptedMetaTypeIds();
71 ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuLoadAndSave);
72 ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows);
73 ui->tvp_StashAircraftModels->setHighlight(
true);
74 ui->tvp_StashAircraftModels->setHighlightColor(Qt::red);
75 ui->tvp_StashAircraftModels->setSettingsDirectoryIndex(CDirectories::IndexDirLastModelStashJsonOrDefault);
76 this->enableButtonRow();
79 &CDbStashComponent::onPublishedModelsResponse, Qt::QueuedConnection);
80 this->onUserChanged();
87 if (!allowReplace && ui->tvp_StashAircraftModels->container().containsModelStringOrDbKey(model))
89 const QString msg(
"Model '%1' already stashed");
90 return CStatusMessage(validationCategories(), CStatusMessage::SeverityError,
97 bool clearHighlighting)
106 ui->tvp_StashAircraftModels->replaceOrAdd(&CAircraftModel::getModelString,
stashModel.getModelString(),
109 else { ui->tvp_StashAircraftModels->insert(
stashModel); }
115 bool consolidateWithDbData,
bool clearHighlighting)
119 int successfullyAdded = 0;
124 else { successfullyAdded++; }
132 ui->tvp_StashAircraftModels->updateContainerMaybeAsync(models);
137 if (keys.isEmpty()) {
return 0; }
138 return ui->tvp_StashAircraftModels->removeDbKeys(keys);
143 if (modelStrings.isEmpty()) {
return 0; }
144 return ui->tvp_StashAircraftModels->removeModelsWithModelString(modelStrings);
149 if (models.
isEmpty()) {
return 0; }
150 return ui->tvp_StashAircraftModels->removeModelsWithModelString(models);
161 return ui->tvp_StashAircraftModels->derivedModel()->getModelStrings(
false);
166 return ui->tvp_StashAircraftModels->derivedModel()->container();
171 if (modelString.isEmpty() || ui->tvp_StashAircraftModels->isEmpty()) {
return CAircraftModel(); }
172 return ui->tvp_StashAircraftModels->container().findFirstByModelStringOrDefault(modelString);
177 if (!ui->tvp_StashAircraftModels->hasSelection()) {
return; }
179 if (this->showOverlayMessages(msgs, acceptWarnings)) {
return; }
180 ui->tvp_StashAircraftModels->applyToSelected(livery);
185 if (!ui->tvp_StashAircraftModels->hasSelection()) {
return; }
187 if (this->showOverlayMessages(msgs, acceptWarnings)) {
return; }
188 ui->tvp_StashAircraftModels->applyToSelected(icao);
195 static const CStatusMessage msg(CStatusMessage::SeverityError, u
"No valid designator");
196 this->showOverlayMessage(msg);
206 this->showOverlayMessage(msg);
215 if (!ui->tvp_StashAircraftModels->hasSelection()) {
return; }
217 if (this->showOverlayMessages(msgs, acceptWarnings)) {
return; }
218 ui->tvp_StashAircraftModels->applyToSelected(distributor);
224 if (!ui->tvp_StashAircraftModels->hasSelection()) {
return; }
225 ui->tvp_StashAircraftModels->applyToSelected(vm);
228 void CDbStashComponent::onUnstashPressed() { ui->tvp_StashAircraftModels->removeSelectedRows(); }
230 void CDbStashComponent::onValidatePressed()
232 if (ui->tvp_StashAircraftModels->isEmpty()) {
return; }
235 this->validateAndDisplay(validModels, invalidModels,
true);
238 void CDbStashComponent::onRemoveInvalidPressed()
240 if (ui->tvp_StashAircraftModels->isEmpty()) {
return; }
243 this->validate(validModels, invalidModels);
247 void CDbStashComponent::onPublishPressed()
250 if (ui->tvp_StashAircraftModels->isEmpty()) {
return; }
255 if (models.isEmpty()) {
return; }
260 if (!this->validateAndDisplay(validModels, invalidModels)) {
return; }
266 u
"More than %1 values, values skipped")
272 else { ui->tvp_StashAircraftModels->showLoadIndicator(); }
275 void CDbStashComponent::onPublishedModelsResponse(
const CAircraftModelList &publishedModels,
280 Q_UNUSED(skippedModels);
281 ui->tvp_StashAircraftModels->hideLoadIndicator();
282 if (!publishedModels.
isEmpty() && sendingSuccesful)
289 if (publishedModels.
isEmpty()) { this->showOverlayMessages(msgs,
false,
false); }
292 QPointer<CDbStashComponent> myself(
this);
293 const QString confirm(
"Remove %1 published models from stash?");
294 auto lambda = [=]() {
295 if (!myself) {
return; }
298 this->showOverlayMessagesWithConfirmation(msgs,
false, confirm.arg(publishedModels.
size()), lambda,
311 const bool ignoreEqual = ui->cb_ChangedOnly->isChecked();
319 {
CStatusMessage(validationCategories(), CStatusMessage::SeverityInfo, u
"No errors in %1 model(s)")
322 else {
return msgs; }
331 this->showOverlayMessages(msgs);
332 ui->tvp_StashAircraftModels->setHighlightModelStrings(invalidModels.
getModelStringList(
false));
337 ui->tvp_StashAircraftModels->clearHighlighting();
341 const CStatusMessage msg(validationCategories(), CStatusMessage::SeverityInfo,
342 "Validation passed for " + no +
" models");
343 this->showOverlayMessage(msg);
349 void CDbStashComponent::enableButtonRow()
351 const bool e = !ui->tvp_StashAircraftModels->isEmpty();
352 ui->pb_AircraftIcao->setEnabled(e);
353 ui->pb_AirlineIcao->setEnabled(e);
354 ui->pb_Distributor->setEnabled(e);
355 ui->pb_Livery->setEnabled(e);
356 ui->pb_Unstash->setEnabled(e);
357 ui->pb_Validate->setEnabled(e);
358 ui->pb_RemoveInvalid->setEnabled(e);
359 ui->pb_Model->setEnabled(e);
360 ui->pb_Publish->setEnabled(e);
361 this->onUserChanged();
372 const bool selectedOnly = ui->cb_SelectedOnly->isChecked();
373 const CAircraftModelList models(selectedOnly ? ui->tvp_StashAircraftModels->selectedObjects() :
374 ui->tvp_StashAircraftModels->containerOrFilteredContainer());
380 const CAircraftModel consolidatedModel = CDatabaseUtils::consolidateModelWithDbData(model, forced);
381 return consolidatedModel;
387 if (model.
getModelType() == CAircraftModel::TypeOwnSimulatorModel) {
return model; }
389 if (!ownModel.hasModelString()) {
return model; }
399 const bool ownModel =
stashModel.getModelType() == CAircraftModel::TypeOwnSimulatorModel;
416 if (models.
isEmpty()) {
return; }
430 this->showOverlayMessages(msgs);
435 void CDbStashComponent::copyOverValuesToSelectedModels()
437 const QObject *sender = QObject::sender();
440 if (!ui->tvp_StashAircraftModels->hasSelection()) {
return; }
449 void CDbStashComponent::modifyModelDialog()
454 void CDbStashComponent::onRowCountChanged(
int number,
bool filter)
458 this->enableButtonRow();
461 void CDbStashComponent::onUserChanged()
464 if (!user.isAuthenticated())
466 ui->pb_Publish->setText(
" Publish (login) ");
467 ui->pb_Publish->setToolTip(
"Login first");
468 ui->pb_Publish->setEnabled(
false);
470 else if (user.canDirectlyWriteModels())
472 ui->pb_Publish->setText(
" Publish (dir.) ");
473 ui->pb_Publish->setToolTip(
"Models directly released");
474 ui->pb_Publish->setEnabled(
true);
478 ui->pb_Publish->setText(
" Publish (CR) ");
479 ui->pb_Publish->setToolTip(
"Models published as change request");
480 ui->pb_Publish->setEnabled(
true);
484 bool CDbStashComponent::showOverlayMessages(
const CStatusMessageList &msgs,
bool onlyErrors,
bool appendOldMessages,
485 std::chrono::milliseconds timeout)
487 if (msgs.
isEmpty()) {
return false; }
496 bool CDbStashComponent::showOverlayMessagesWithConfirmation(
const CStatusMessageList &msgs,
bool appendOldMessages,
497 const QString &confirmation,
498 std::function<
void()> okLambda,
499 QMessageBox::StandardButton defaultButton,
500 bool onlyErrors, std::chrono::milliseconds timeout)
502 if (msgs.
isEmpty()) {
return false; }
507 okLambda, defaultButton, timeout);
511 bool CDbStashComponent::showOverlayMessage(
const CStatusMessage &msg, std::chrono::milliseconds timeout)
513 if (msg.
isEmpty()) {
return false; }
520 void CDbStashComponent::clearOverlayMessages()
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::CStatusMessageList asyncPublishModels(const swift::misc::simulation::CAircraftModelList &modelsToBePublished) const
Publish models to database.
db::CDatabaseWriter * getDatabaseWriter() const
DB writer class.
swift::misc::aviation::CLivery getStdLiveryForAirlineCode(const swift::misc::aviation::CAirlineIcaoCode &icao) const
Standard livery for airline code.
bool isDbModelEqualForPublishing(const swift::misc::simulation::CAircraftModel &modelToBeChecked, swift::misc::CStatusMessageList *details=nullptr) const
Considered equal for publishing, compares if livery etc. are the same DB values.
swift::misc::CStatusMessageList validateForPublishing(const swift::misc::simulation::CAircraftModelList &modelsToBePublished, bool ignoreEqual, swift::misc::simulation::CAircraftModelList &validModels, swift::misc::simulation::CAircraftModelList &invalidModels) const
Validate for publishing.
bool hasMinimumMappingVersion() const
Minimum mapping version check.
void clearOverlayMessages()
Clear the overlay messages.
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show single message.
void showOverlayMessages(const swift::misc::CStatusMessageList &messages, bool appendOldMessages=false, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show multiple messages.
void showOverlayMessagesWithConfirmation(const swift::misc::CStatusMessageList &messages, bool appendOldMessages, const QString &confirmationMessage, std::function< void()> okLambda, QMessageBox::StandardButton defaultButton=QMessageBox::Cancel, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show multiple messages with confirmation bar.
Allows subcomponents to gain access to model component.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
void modifyModelDialog()
Open model modify dialog.
static constexpr int MaxModelPublished
Number of models which can be published at once.
void stashedModelsChanged()
Stashed models have been changed.
void showChangedAttributes()
Show changed attributes of selected models.
int unstashModels(const QSet< int > &keys)
Unstash given models with keys.
int getStashedModelsCount() const
Number of models.
swift::misc::simulation::CAircraftModel getStashedModel(const QString &modelString) const
Model for model string.
virtual ~CDbStashComponent()
Destructor.
swift::gui::views::CAircraftModelView * view() const
The embedded view.
void applyToSelected(const swift::misc::aviation::CLivery &livery, bool acceptWarnings=true)
Apply livery to selected objects.
bool hasStashedModels() const
Has stashed models.
swift::misc::CStatusMessage stashModel(const swift::misc::simulation::CAircraftModel &model, bool replace=false, bool consolidateWithDbData=true, bool clearHighlighting=true)
Stash given model (includes validation and consolidation with DB data)
swift::misc::CStatusMessage validateStashModel(const swift::misc::simulation::CAircraftModel &model, bool allowReplace) const
Test the given model if it can be stashed.
swift::misc::simulation::CAircraftModel consolidateModel(const swift::misc::simulation::CAircraftModel &model) const
Consolidate with other available data.
const swift::misc::simulation::CAircraftModelList & getStashedModels() const
The stashed models.
void modelsSuccessfullyPublished(const swift::misc::simulation::CAircraftModelList &publishedModels, bool directWrite)
Models succesfully published.
swift::misc::CStatusMessageList stashModels(const swift::misc::simulation::CAircraftModelList &models, bool replace=false, bool consolidateWithDbData=true, bool clearHighlighting=true)
Stash given models (includes validation and consolidation with DB data)
void clearValidationHighlighting()
Clear highlighting set by validations.
void replaceModelsUnvalidated(const swift::misc::simulation::CAircraftModelList &models)
Replace models, no validation.
QStringList getStashedModelStrings() const
Stashed model strings.
T get() const
Get a copy of the current value.
A sequence of log categories.
bool isEmpty() const
Message empty.
Specialized value object compliant map for variants, based on indexes.
bool isEmpty() const
Is empty?
size_type size() const
Returns number of elements in the sequence.
void truncate(size_type maxSize)
Changes the size of the sequence, if it is bigger than the given size.
void push_back(const T &value)
Appends an element at the end of the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
bool isWarningOrAbove() const
Warning or above.
Status messages, e.g. from Core -> GUI.
bool hasWarningOrErrorMessages() const
Warning or error messages.
bool hasErrorMessages() const
Error messages.
Value object for ICAO classification.
CStatusMessageList validate() const
Validate data.
Value object for ICAO classification.
const QString & getDesignator() const
Get airline, e.g. "DLH".
bool hasValidDesignator() const
Airline designator available?
Value object encapsulating information about an airpot.
CStatusMessageList validate() const
Validate data.
bool hasValidDbKey() const
Has valid DB key.
Value object encapsulating information of an authentiated user.
Aircraft model (used by another pilot, my models on disk)
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code.
const aviation::CLivery & getLivery() const
Get livery.
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
const CDistributor & getDistributor() const
Get distributor.
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Aircraft ICAO code.
ModelType getModelType() const
Model type.
QString getModelStringAndDbKey() const
Model string and DB key (if available)
bool hasModelString() const
Non empty model string?
void updateMissingParts(const CAircraftModel &otherModel, bool dbModelPriority=true)
Update missing parts from another model.
Value object encapsulating a list of aircraft models.
QStringList getModelStringList(bool sort=true) const
Model strings.
Value object encapsulating information of software distributor.
swift::misc::CStatusMessageList validate() const
Validate data.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Classes interacting with the swift database (aka "datastore").
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Models to be used with views, mainly QTableView.
Views, mainly QTableView.
Free functions in swift::misc.
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.