7#include <QDialogButtonBox>
9#include <QIntValidator>
11#include <QProgressBar>
12#include <QRadioButton>
14#include <QStringBuilder>
19#include "ui_dbautostashingcomponent.h"
37using namespace swift::misc::aviation;
38using namespace swift::misc::network;
39using namespace swift::misc::simulation;
62 this->resetDescription();
74 if (!m_modelsToStash.isEmpty())
78 if (ui->cb_RemovedChecked->isChecked())
80 this->currentModelView()->removeModelsWithModelString(m_modelsToStash);
83 QStringLiteral(
"Auto stashed %1 models").arg(m_modelsToStash.size()));
84 this->addStatusMessage(stashedMsg);
85 m_modelsToStash.clear();
92 if (this->getSelectedOrAllCount() < 1)
95 this->addStatusMessage(m);
98 this->tryToStashModels();
115 void CDbAutoStashingComponent::resetDescription()
117 ui->rb_DescriptionEmptyOnly->setChecked(
true);
121 void CDbAutoStashingComponent::initGui()
125 ui->tvp_StatusMessages->clear();
127 m_noValidationFailed = 0;
131 if (!this->currentModelView())
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())
179 if (ui->rb_Selected->isChecked())
185 return this->currentModelView()->
rowCount();
189 CAircraftModelView *CDbAutoStashingComponent::currentModelView()
const
194 void CDbAutoStashingComponent::addStatusMessage(
const CStatusMessage &msg)
200 ui->tvp_StatusMessages->
insert(msg);
203 void CDbAutoStashingComponent::addStatusMessage(
const CStatusMessage &msg,
const CAircraftModel &model)
211 CStatusMessage prefixMessage(msg);
213 ui->tvp_StatusMessages->insert(prefixMessage);
217 ui->tvp_StatusMessages->insert(msg);
221 void CDbAutoStashingComponent::tryToStashModels()
223 Q_ASSERT_X(this->currentModelView(), Q_FUNC_INFO,
"No view");
224 const CAircraftModelList models(ui->rb_Selected->isChecked() ?
225 this->currentModelView()->selectedObjects() :
226 this->currentModelView()->containerOrFilteredContainer());
227 if (models.isEmpty())
238 const int all = models.size();
242 const QString maxStr(ui->le_MaxModelsStashed->text());
243 bool okMaxStr =
true;
244 if (!maxStr.isEmpty())
246 max = maxStr.toInt(&okMaxStr);
248 if (!okMaxStr || max > all)
254 const QString description(ui->le_Description->text().trimmed());
257 const CLivery tempLivery(ui->cb_UseTempLivery->isChecked() ? getTempLivery() : CLivery());
260 CAircraftModelList autoStashed;
261 for (
const CAircraftModel &model : models)
263 CAircraftModel stashModel(model);
264 const bool stashed = this->tryToStashModel(stashModel, tempLivery);
267 if (!description.isEmpty())
269 this->setModelDescription(stashModel, description);
277 Q_ASSERT_X(c <= all, Q_FUNC_INFO,
"illegal numbers");
280 int percent = c * 100 / all;
283 int maxPercent = autoStashed.
size() * 100 / max;
284 percent = std::max(maxPercent, percent);
288 if (autoStashed.
size() >= max)
298 QStringLiteral(
"Ready to auto stash %1 models").arg(autoStashed.
size()));
299 this->addStatusMessage(stashedMsg);
300 m_modelsToStash = autoStashed;
304 bool CDbAutoStashingComponent::tryToStashModel(CAircraftModel &model,
const CLivery &tempLivery)
335 bool fallback =
false;
336 if (liveryCombinedCode.
length() == 3 || liveryCombinedCode.
length() == 4)
357 bool stashed =
false;
359 CStatusMessageList validationMsgs(stashModel.validate(
true));
360 validationMsgs.removeWarningsAndBelow();
361 CStatusMessage msg = validationMsgs.toSingleMessage();
364 m_noValidationFailed++;
373 this->addStatusMessage(msg, stashModel);
377 void CDbAutoStashingComponent::setModelDescription(CAircraftModel &model,
const QString &description)
const
383 if (ui->rb_All->isChecked())
398 swift::misc::aviation::CLivery CDbAutoStashingComponent::getTempLivery()
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.
static const QStringList & getLogCategories()
Log categories.
void showLastResults()
Show last result.
~CDbAutoStashingComponent()
Destructor.
CDbAutoStashingComponent(QWidget *parent=nullptr)
Constructor.
CDbMappingComponent * getMappingComponent() const
Get the mapping component.
CDbMappingComponentAware(QObject *parent)
Constructor.
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.
void insert(const ObjectType &value, bool resize=true)
Insert.
int rowCount() const
Elements in container.
@ ResizingAuto
resizing when below threshold,
int selectedRowCount() const
Number of selected rows.
static const QString & mapping()
Mapping.
static const QString & guiComponent()
GUI components.
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.
Streamable status message, e.g.
static constexpr auto SeverityInfo
Status severities.
static constexpr auto SeverityError
Status severities.
StatusSeverity getSeverity() const
Message severity.
static bool isValidAirlineDesignator(const QString &airline)
Valid designator?
const QString & getCombinedCode() const
Combined code.
bool isLoadedFromDb() const
Loaded from DB.
bool hasValidDbKey() const
Has valid DB key.
bool hasAirlineDesignator() const
Airline designator?
QString getMembersDbStatus() const
Info, which members (Livery, Aircraft ICAO, ...) are already based on DB data.
const aviation::CLivery & getLivery() const
Get livery.
bool hasAircraftDesignator() const
Has aircraft designator?
void setDescription(const QString &description)
Descriptive text.
const QString & getModelString() const
Model key, either queried or loaded from simulator model.
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.
static const QString & autoGenerated()
Hint, that model was automatically generated (e.g. by auto stashing).
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.
QDialog(QWidget *parent, Qt::WindowFlags f)
virtual void setVisible(bool visible) override
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
T qobject_cast(QObject *object)
bool isEmpty() const const
qsizetype length() const const
QString number(double n, char format, int precision)