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);
60 connect(ui->tb_ResetDescription, &QToolButton::clicked,
this, &CDbAutoStashingComponent::resetDescription);
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();
106 return QDialog::exec();
111 ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Close);
112 this->setVisible(
true);
115 void CDbAutoStashingComponent::resetDescription()
117 ui->rb_DescriptionEmptyOnly->setChecked(
true);
118 ui->le_Description->setText(CAircraftModel::autoGenerated());
121 void CDbAutoStashingComponent::initGui()
124 ui->bb_AutoStashing->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
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();
140 ui->le_Selected->setText(QString::number(selected));
141 QString allStr(QString::number(all));
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 if (percent > 100) { percent = 100; }
167 if (percent < 0) { percent = 0; }
168 ui->pb_StashingProgress->setValue(percent);
169 ui->le_Stashed->setText(QString::number(m_noStashed));
170 ui->le_NoData->setText(QString::number(m_noData));
171 ui->le_ValidationFailed->setText(QString::number(m_noValidationFailed));
174 int CDbAutoStashingComponent::getSelectedOrAllCount()
const
176 if (!this->currentModelView()) {
return 0; }
177 if (ui->rb_Selected->isChecked()) {
return this->currentModelView()->
selectedRowCount(); }
178 else {
return this->currentModelView()->
rowCount(); }
186 void CDbAutoStashingComponent::addStatusMessage(
const CStatusMessage &msg)
189 ui->tvp_StatusMessages->insert(msg);
199 ui->tvp_StatusMessages->insert(prefixMessage);
201 else { ui->tvp_StatusMessages->insert(msg); }
204 void CDbAutoStashingComponent::tryToStashModels()
206 Q_ASSERT_X(this->currentModelView(), Q_FUNC_INFO,
"No view");
208 this->currentModelView()->selectedObjects() :
209 this->currentModelView()->containerOrFilteredContainer());
210 if (models.isEmpty()) {
return; }
215 const int all = models.size();
219 const QString maxStr(ui->le_MaxModelsStashed->text());
220 bool okMaxStr =
true;
221 if (!maxStr.isEmpty()) { max = maxStr.toInt(&okMaxStr); }
222 if (!okMaxStr || max > all) { max = all; }
225 const QString description(ui->le_Description->text().trimmed());
228 const CLivery tempLivery(ui->cb_UseTempLivery->isChecked() ? getTempLivery() :
CLivery());
235 const bool stashed = this->tryToStashModel(stashModel, tempLivery);
238 if (!description.isEmpty()) { this->setModelDescription(stashModel, description); }
245 Q_ASSERT_X(c <= all, Q_FUNC_INFO,
"illegal numbers");
248 int percent = c * 100 / all;
251 int maxPercent = autoStashed.
size() * 100 / max;
252 if (maxPercent > percent) { percent = maxPercent; }
256 if (autoStashed.
size() >= max) {
break; }
262 const CStatusMessage stashedMsg(
this, CStatusMessage::SeverityInfo,
263 QStringLiteral(
"Ready to auto stash %1 models").arg(autoStashed.
size()));
264 this->addStatusMessage(stashedMsg);
265 m_modelsToStash = autoStashed;
282 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityError, u
"No model string"));
289 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityError, u
"No aircraft designator"),
300 bool fallback =
false;
301 if (liveryCombinedCode.length() == 3 || liveryCombinedCode.length() == 4)
304 if (CAirlineIcaoCode::isValidAirlineDesignator(liveryCombinedCode))
314 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityError, u
"No airline designator"),
322 bool stashed =
false;
325 validationMsgs.removeWarningsAndBelow();
327 if (msg.
getSeverity() == CStatusMessage::SeverityError) { m_noValidationFailed++; }
330 msg =
CStatusMessage(
this, CStatusMessage::SeverityInfo, u
"Stashed succesfully");
335 this->addStatusMessage(msg, stashModel);
339 void CDbAutoStashingComponent::setModelDescription(
CAircraftModel &model,
const QString &description)
const
341 if (description.isEmpty()) {
return; }
342 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.
virtual void updateProgressIndicator(int percent)
Update the progress indicator 0..100.
void showLastResults()
Show last result.
virtual ~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.
virtual 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.