7 #include <QDialogButtonBox>
9 #include <QIntValidator>
11 #include <QProgressBar>
12 #include <QRadioButton>
14 #include <QStringBuilder>
19 #include "ui_dbautostashingcomponent.h"
37 using namespace swift::misc::aviation;
38 using namespace swift::misc::network;
39 using namespace swift::misc::simulation;
44 const QStringList &CDbAutoStashingComponent::getLogCategories()
50 CDbAutoStashingComponent::CDbAutoStashingComponent(
QWidget *parent)
51 :
QDialog(parent,
Qt::WindowSystemMenuHint |
Qt::WindowTitleHint),
55 ui->tvp_StatusMessages->setResizeMode(CAircraftModelView::ResizingAuto);
56 ui->tvp_StatusMessages->menuAddItems(CAircraftModelView::MenuSave);
62 this->resetDescription();
78 if (ui->cb_RemovedChecked->isChecked())
82 const CStatusMessage stashedMsg(
this, CStatusMessage::SeverityInfo,
83 QStringLiteral(
"Auto stashed %1 models").arg(m_modelsToStash.
size()));
84 this->addStatusMessage(stashedMsg);
85 m_modelsToStash.
clear();
92 if (this->getSelectedOrAllCount() < 1)
94 const CStatusMessage m(
this, CStatusMessage::SeverityError, u
"No data, nothing to do");
95 this->addStatusMessage(m);
98 this->tryToStashModels();
115 void CDbAutoStashingComponent::resetDescription()
117 ui->rb_DescriptionEmptyOnly->setChecked(
true);
118 ui->le_Description->setText(CAircraftModel::autoGenerated());
121 void CDbAutoStashingComponent::initGui()
125 ui->tvp_StatusMessages->clear();
127 m_noValidationFailed = 0;
131 if (!this->currentModelView())
133 const CStatusMessage m(
this, CStatusMessage::SeverityError, u
"No data for auto stashing");
134 this->addStatusMessage(m);
139 int all = this->currentModelView()->
rowCount();
146 ui->le_All->setText(allStr);
147 if (ui->le_MaxModelsStashed->text().isEmpty())
149 ui->le_MaxModelsStashed->setText(all > 100 ? QStringLiteral(
"100") :
QString());
153 ui->rb_Selected->setChecked(
true);
154 ui->rb_Selected->setEnabled(
true);
158 ui->rb_All->setChecked(
true);
159 ui->rb_Selected->setEnabled(
false);
166 percent = std::clamp(percent, 0, 100);
167 ui->pb_StashingProgress->setValue(percent);
170 ui->le_ValidationFailed->setText(
QString::number(m_noValidationFailed));
173 int CDbAutoStashingComponent::getSelectedOrAllCount()
const
175 if (!this->currentModelView()) {
return 0; }
176 if (ui->rb_Selected->isChecked()) {
return this->currentModelView()->
selectedRowCount(); }
177 else {
return this->currentModelView()->
rowCount(); }
185 void CDbAutoStashingComponent::addStatusMessage(
const CStatusMessage &msg)
188 ui->tvp_StatusMessages->insert(msg);
198 ui->tvp_StatusMessages->insert(prefixMessage);
200 else { ui->tvp_StatusMessages->insert(msg); }
203 void CDbAutoStashingComponent::tryToStashModels()
205 Q_ASSERT_X(this->currentModelView(), Q_FUNC_INFO,
"No view");
207 this->currentModelView()->selectedObjects() :
208 this->currentModelView()->containerOrFilteredContainer());
209 if (models.isEmpty()) {
return; }
214 const int all = models.size();
218 const QString maxStr(ui->le_MaxModelsStashed->text());
219 bool okMaxStr =
true;
220 if (!maxStr.isEmpty()) { max = maxStr.toInt(&okMaxStr); }
221 if (!okMaxStr || max > all) { max = all; }
224 const QString description(ui->le_Description->text().trimmed());
227 const CLivery tempLivery(ui->cb_UseTempLivery->isChecked() ? getTempLivery() :
CLivery());
234 const bool stashed = this->tryToStashModel(stashModel, tempLivery);
237 if (!description.isEmpty()) { this->setModelDescription(stashModel, description); }
244 Q_ASSERT_X(c <= all, Q_FUNC_INFO,
"illegal numbers");
247 int percent = c * 100 / all;
250 int maxPercent = autoStashed.
size() * 100 / max;
251 percent = std::max(maxPercent, percent);
255 if (autoStashed.
size() >= max) {
break; }
261 const CStatusMessage stashedMsg(
this, CStatusMessage::SeverityInfo,
262 QStringLiteral(
"Ready to auto stash %1 models").arg(autoStashed.
size()));
263 this->addStatusMessage(stashedMsg);
264 m_modelsToStash = autoStashed;
281 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityError, u
"No model string"));
288 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityError, u
"No aircraft designator"),
299 bool fallback =
false;
300 if (liveryCombinedCode.
length() == 3 || liveryCombinedCode.
length() == 4)
303 if (CAirlineIcaoCode::isValidAirlineDesignator(liveryCombinedCode))
313 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityError, u
"No airline designator"),
321 bool stashed =
false;
324 validationMsgs.removeWarningsAndBelow();
326 if (msg.
getSeverity() == CStatusMessage::SeverityError) { m_noValidationFailed++; }
329 msg =
CStatusMessage(
this, CStatusMessage::SeverityInfo, u
"Stashed succesfully");
334 this->addStatusMessage(msg, stashModel);
338 void CDbAutoStashingComponent::setModelDescription(
CAircraftModel &model,
const QString &description)
const
340 if (description.
isEmpty()) {
return; }
341 if (ui->rb_All->isChecked()) { model.
setDescription(description); }
bool hasWebDataServices() const
Web data services available?
bool isShuttingDown() const
Is application shutting down?
CWebDataServices * getWebDataServices() const
Get the web data services.
swift::misc::aviation::CLivery getTempLiveryOrDefault() const
The temp. livery if available.
void processEventsToRefreshGui() const
Allow the GUI to refresh by processing events, call the event loop.
void updateProgressIndicator(int percent)
Update the progress indicator 0..100.
void showLastResults()
Show last result.
~CDbAutoStashingComponent()
Destructor.
Allows subcomponents to gain access to model component.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
void replaceStashedModelsUnvalidated(const swift::misc::simulation::CAircraftModelList &models) const
Replace models, no validation.
views::CAircraftModelView * currentModelView() const
Current model view.
static constexpr int MaxModelPublished
Number of models which can be published at once.
int removeModelsWithModelString(const QStringList &modelStrings, Qt::CaseSensitivity sensitivity=Qt::CaseInsensitive)
Remove models with model strings.
int rowCount() const
Elements in container.
int selectedRowCount() const
Number of selected rows.
static const QString & guiComponent()
GUI components.
static const QString & mapping()
Mapping.
bool isEmpty() const
Message empty.
size_type size() const
Returns number of elements in the sequence.
void push_back(const T &value)
Appends an element at the end of the sequence.
void clear()
Removes all elements in the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
StatusSeverity getSeverity() const
Message severity.
Status messages, e.g. from Core -> GUI.
Value object encapsulating information about an airpot.
const QString & getCombinedCode() const
Combined code.
bool isLoadedFromDb() const
Loaded from DB.
bool hasValidDbKey() const
Has valid DB key.
Aircraft model (used by another pilot, my models on disk)
bool hasAirlineDesignator() const
Airline designator?
const aviation::CLivery & getLivery() const
Get livery.
QString getMembersDbStatus() const
Info, which members (Livery, Aircraft ICAO, ...) are already based on DB data.
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
bool hasAircraftDesignator() const
Has aircraft designator?
void setDescription(const QString &description)
Descriptive text.
bool hasDescription(bool ignoreAutoGenerated=false) const
Description.
bool setAirlineIcaoDesignator(const QString &designator)
Set airline ICAO code designator.
bool hasModelString() const
Non empty model string?
void setLivery(const aviation::CLivery &livery)
Livery.
Value object encapsulating a list of aircraft models.
SWIFT_GUI_EXPORT swift::gui::CGuiApplication * sGui
Single instance of GUI application object.
Backend services of the swift project, like dealing with the network or the simulators.
High level reusable GUI components.
Views, mainly QTableView.
Free functions in swift::misc.
virtual void setVisible(bool visible) override
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
qsizetype length() const const
QString number(double n, char format, int precision)