11#include <QStringBuilder>
16#include "ui_dbstashcomponent.h"
38using namespace swift::misc::simulation;
39using namespace swift::misc::aviation;
40using namespace swift::misc::network;
59 &CDbStashComponent::onRowCountChanged);
69 ui->tvp_StashAircraftModels->allowDragDrop(
false,
true,
true);
70 ui->tvp_StashAircraftModels->setAcceptedMetaTypeIds();
71 ui->tvp_StashAircraftModels->menuAddItems(CAircraftModelView::MenuLoadAndSave);
73 ui->tvp_StashAircraftModels->setHighlight(
true);
74 ui->tvp_StashAircraftModels->setHighlightColor(
Qt::red);
75 ui->tvp_StashAircraftModels->setSettingsDirectoryIndex(CDirectories::IndexDirLastModelStashJsonOrDefault);
76 this->enableButtonRow();
80 this->onUserChanged();
87 if (!allowReplace && ui->tvp_StashAircraftModels->container().containsModelStringOrDbKey(model))
89 const QString msg(
"Model '%1' already stashed");
96 bool clearHighlighting)
102 if (clearHighlighting)
113 ui->tvp_StashAircraftModels->insert(
stashModel);
120 bool consolidateWithDbData,
bool clearHighlighting)
127 int successfullyAdded = 0;
140 if (successfullyAdded > 0 && clearHighlighting)
149 ui->tvp_StashAircraftModels->updateContainerMaybeAsync(
models);
158 return ui->tvp_StashAircraftModels->removeDbKeys(keys);
167 return ui->tvp_StashAircraftModels->removeModelsWithModelString(modelStrings);
176 return ui->tvp_StashAircraftModels->removeModelsWithModelString(
models);
187 return ui->tvp_StashAircraftModels->derivedModel()->getModelStrings(
false);
192 return ui->tvp_StashAircraftModels->derivedModel()->
container();
197 if (modelString.
isEmpty() || ui->tvp_StashAircraftModels->isEmpty())
201 return ui->tvp_StashAircraftModels->container().findFirstByModelStringOrDefault(modelString);
206 if (!ui->tvp_StashAircraftModels->hasSelection())
211 if (this->showOverlayMessages(msgs, acceptWarnings))
215 ui->tvp_StashAircraftModels->applyToSelected(livery);
220 if (!ui->tvp_StashAircraftModels->hasSelection())
225 if (this->showOverlayMessages(msgs, acceptWarnings))
229 ui->tvp_StashAircraftModels->applyToSelected(icao);
237 this->showOverlayMessage(msg);
242 const CLivery stdLivery(sApp->getWebDataServices()->getStdLiveryForAirlineCode(icao));
247 this->showOverlayMessage(msg);
256 if (!ui->tvp_StashAircraftModels->hasSelection())
261 if (this->showOverlayMessages(msgs, acceptWarnings))
265 ui->tvp_StashAircraftModels->applyToSelected(distributor);
274 if (!ui->tvp_StashAircraftModels->hasSelection())
278 ui->tvp_StashAircraftModels->applyToSelected(vm);
281 void CDbStashComponent::onUnstashPressed() { ui->tvp_StashAircraftModels->removeSelectedRows(); }
283 void CDbStashComponent::onValidatePressed()
285 if (ui->tvp_StashAircraftModels->isEmpty())
291 this->validateAndDisplay(validModels, invalidModels,
true);
294 void CDbStashComponent::onRemoveInvalidPressed()
296 if (ui->tvp_StashAircraftModels->isEmpty())
300 CAircraftModelList validModels;
301 CAircraftModelList invalidModels;
302 this->validate(validModels, invalidModels);
306 void CDbStashComponent::onPublishPressed()
312 if (ui->tvp_StashAircraftModels->isEmpty())
322 const CAircraftModelList models(getSelectedOrAllModels());
323 if (models.isEmpty())
329 CAircraftModelList validModels;
330 CAircraftModelList invalidModels;
331 if (!this->validateAndDisplay(validModels, invalidModels))
335 CStatusMessageList msgs;
340 u
"More than %1 values, values skipped")
347 this->showOverlayMessages(msgs);
351 ui->tvp_StashAircraftModels->showLoadIndicator();
355 void CDbStashComponent::onPublishedModelsResponse(
const CAircraftModelList &publishedModels,
356 const CAircraftModelList &skippedModels,
357 const CStatusMessageList &msgs,
bool sendingSuccesful,
360 Q_UNUSED(skippedModels);
361 ui->tvp_StashAircraftModels->hideLoadIndicator();
362 if (!publishedModels.
isEmpty() && sendingSuccesful)
371 this->showOverlayMessages(msgs,
false,
false);
375 QPointer<CDbStashComponent> myself(
this);
376 const QString confirm(
"Remove %1 published models from stash?");
377 auto lambda = [=]() {
384 this->showOverlayMessagesWithConfirmation(msgs,
false, confirm.arg(publishedModels.
size()), lambda,
390 CStatusMessageList CDbStashComponent::validate(CAircraftModelList &validModels,
391 CAircraftModelList &invalidModels)
const
393 if (ui->tvp_StashAircraftModels->isEmpty())
398 const CAircraftModelList models(getSelectedOrAllModels());
399 if (models.isEmpty())
403 const bool ignoreEqual = ui->cb_ChangedOnly->isChecked();
404 const CStatusMessageList msgs(
410 return CStatusMessageList(
420 bool CDbStashComponent::validateAndDisplay(CAircraftModelList &validModels, CAircraftModelList &invalidModels,
423 const CStatusMessageList msgs(this->validate(validModels, invalidModels));
426 this->showOverlayMessages(msgs);
427 ui->tvp_StashAircraftModels->setHighlightModelStrings(invalidModels.
getModelStringList(
false));
432 ui->tvp_StashAircraftModels->clearHighlighting();
437 "Validation passed for " + no +
" models");
438 this->showOverlayMessage(msg);
444 void CDbStashComponent::enableButtonRow()
446 const bool e = !ui->tvp_StashAircraftModels->isEmpty();
447 ui->pb_AircraftIcao->setEnabled(e);
448 ui->pb_AirlineIcao->setEnabled(e);
449 ui->pb_Distributor->setEnabled(e);
450 ui->pb_Livery->setEnabled(e);
451 ui->pb_Unstash->setEnabled(e);
452 ui->pb_Validate->setEnabled(e);
453 ui->pb_RemoveInvalid->setEnabled(e);
454 ui->pb_Model->setEnabled(e);
455 ui->pb_Publish->setEnabled(e);
456 this->onUserChanged();
459 const CLogCategoryList &CDbStashComponent::validationCategories()
const
461 static const CLogCategoryList cats(CLogCategoryList(
this).withValidation());
465 CAircraftModelList CDbStashComponent::getSelectedOrAllModels()
const
467 const bool selectedOnly = ui->cb_SelectedOnly->isChecked();
468 const CAircraftModelList models(selectedOnly ? ui->tvp_StashAircraftModels->selectedObjects() :
469 ui->tvp_StashAircraftModels->containerOrFilteredContainer());
473 CAircraftModel CDbStashComponent::consolidateWithDbData(
const CAircraftModel &model,
bool forced)
const
476 return consolidatedModel;
479 CAircraftModel CDbStashComponent::consolidateWithOwnModels(
const CAircraftModel &model)
const
490 if (!ownModel.hasModelString())
494 ownModel.updateMissingParts(model);
498 CAuthenticatedUser CDbStashComponent::getSwiftDbUser()
const {
return m_swiftDbUser.get(); }
520 if (!sGui || !sGui->hasWebDataServices())
524 if (sGui->isShuttingDown())
538 const bool equal = sGui->getWebDataServices()->isDbModelEqualForPublishing(model, &modelMsgs);
549 this->showOverlayMessages(msgs);
554 void CDbStashComponent::copyOverValuesToSelectedModels()
562 if (!ui->tvp_StashAircraftModels->hasSelection())
568 if (
sender == ui->pb_AircraftIcao)
572 else if (
sender == ui->pb_AirlineIcao)
576 else if (
sender == ui->pb_Distributor)
580 else if (
sender == ui->pb_Livery)
586 void CDbStashComponent::modifyModelDialog()
594 void CDbStashComponent::onRowCountChanged(
int number,
bool filter)
598 this->enableButtonRow();
601 void CDbStashComponent::onUserChanged()
603 const CAuthenticatedUser user(this->getSwiftDbUser());
604 if (!user.isAuthenticated())
606 ui->pb_Publish->setText(
" Publish (login) ");
607 ui->pb_Publish->setToolTip(
"Login first");
608 ui->pb_Publish->setEnabled(
false);
610 else if (user.canDirectlyWriteModels())
612 ui->pb_Publish->setText(
" Publish (dir.) ");
613 ui->pb_Publish->setToolTip(
"Models directly released");
614 ui->pb_Publish->setEnabled(
true);
618 ui->pb_Publish->setText(
" Publish (CR) ");
619 ui->pb_Publish->setToolTip(
"Models published as change request");
620 ui->pb_Publish->setEnabled(
true);
624 bool CDbStashComponent::showOverlayMessages(
const CStatusMessageList &msgs,
bool onlyErrors,
bool appendOldMessages,
625 std::chrono::milliseconds timeout)
645 bool CDbStashComponent::showOverlayMessagesWithConfirmation(
const CStatusMessageList &msgs,
bool appendOldMessages,
646 const QString &confirmation,
647 std::function<
void()> okLambda,
649 bool onlyErrors, std::chrono::milliseconds timeout)
665 okLambda, defaultButton, timeout);
669 bool CDbStashComponent::showOverlayMessage(
const CStatusMessage &msg, std::chrono::milliseconds timeout)
684 void CDbStashComponent::clearOverlayMessages()
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.
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.
static swift::misc::simulation::CAircraftModel consolidateModelWithDbData(const swift::misc::simulation::CAircraftModel &model, bool force, bool *modified=nullptr)
Consolidate model data with DB data.
void publishedModels(const swift::misc::simulation::CAircraftModelList &modelsPublished, const swift::misc::simulation::CAircraftModelList &modelsSkipped, const swift::misc::CStatusMessageList &messages, bool sendingSuccessful, bool directWrite)
Published models, the response to.
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.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
CDbMappingComponentAware(QObject *parent)
Constructor.
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.
~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.
CDbStashComponent(QWidget *parent=nullptr)
Constructor.
QStringList getStashedModelStrings() const
Stashed model strings.
@ StashModel
stashed models
bool isEmpty() const
Empty?
void modelChanged()
Model bas been changed (means data in view have been changed).
void modelDataChanged(int count, bool withFilter)
Model data changed.
@ MenuRemoveSelectedRows
allow to remove selected rows
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.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
static constexpr auto SeverityWarning
Status severities.
Status messages, e.g. from Core -> GUI.
bool hasWarningOrErrorMessages() const
Warning or error messages.
bool hasErrorMessages() const
Error messages.
const CONTAINER & container() const
Container.
Value object for ICAO classification.
CStatusMessageList validate() const
Validate data.
Value object for ICAO classification.
bool hasValidDesignator() const
Airline designator available?
const QString & getDesignator() const
Get airline, e.g. "DLH".
Value object encapsulating information about an airpot.
CStatusMessageList validate() const
Validate data.
bool hasValidDbKey() const
Has valid DB key.
Aircraft model (used by another pilot, my models on disk).
@ TypeOwnSimulatorModel
represents own simulator model (AI model, model on disk)
const CDistributor & getDistributor() const
Get distributor.
const aviation::CLivery & getLivery() const
Get livery.
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
ModelType getModelType() const
Model type.
QString getModelStringAndDbKey() const
Model string and DB key (if available).
const aviation::CAirlineIcaoCode & getAirlineIcaoCode() const
Airline ICAO code.
bool hasModelString() const
Non empty model string?
const aviation::CAircraftIcaoCode & getAircraftIcaoCode() const
Aircraft ICAO code.
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.
QFrame(QWidget *parent, Qt::WindowFlags f)
bool isEmpty() const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QObject * sender() const const
bool isEmpty() const const
QString arg(Args &&... args) const const
bool isEmpty() const const
QString number(double n, char format, int precision)
#define SWIFT_VERIFY_X(COND, WHERE, WHAT)
A weaker kind of assert.