6 #include <QIntValidator>
8 #include "ui_dbautosimulatorstashingcomponent.h"
16 using namespace swift::misc::simulation;
20 CDbAutoSimulatorStashingComponent::CDbAutoSimulatorStashingComponent(QWidget *parent)
21 : QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint),
26 ui->le_MaxModelsStashed->setValidator(
new QIntValidator(
this));
27 ui->tvp_StatusMessages->setMode(swift::gui::models::CStatusMessageListModel::Simplified);
28 ui->le_MaxModelsStashed->setText(
"100");
34 return QDialog::exec();
48 const CStatusMessage stashedMsg(
this, CStatusMessage::SeverityInfo,
49 QStringLiteral(
"Stashed %1 models").arg(m_modelsToStash.
size()));
50 this->addStatusMessage(stashedMsg);
51 m_modelsToStash.
clear();
68 if (percent > 100) { percent = 100; }
69 if (percent < 0) { percent = 0; }
70 ui->pb_StashingProgress->setValue(percent);
78 void CDbAutoSimulatorStashingComponent::initGui()
80 ui->bb_OkCancel->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
81 ui->tvp_StatusMessages->clear();
86 ui->le_AllSets->setText(infoAll);
88 if (!this->currentModelView())
90 const CStatusMessage m(
this, CStatusMessage::SeverityError, u
"No data for simulator updating");
91 this->addStatusMessage(m);
96 ui->le_Selected->setText(QString::number(selected));
100 void CDbAutoSimulatorStashingComponent::addStatusMessage(
const CStatusMessage &msg)
103 ui->tvp_StatusMessages->insert(msg);
106 void CDbAutoSimulatorStashingComponent::addStatusMessages(
const CStatusMessageList &msgs)
108 if (msgs.
isEmpty()) {
return; }
109 for (
const CStatusMessage &msg : msgs) { this->addStatusMessage(msg); }
119 ui->tvp_StatusMessages->insert(prefixMessage);
121 else { ui->tvp_StatusMessages->insert(msg); }
124 void CDbAutoSimulatorStashingComponent::tryToStash()
128 if (!this->currentModelView()) {
return; }
130 int maxObjectsStashed = -1;
131 if (!ui->le_MaxModelsStashed->text().isEmpty())
134 ui->le_MaxModelsStashed->text().toInt(&ok);
135 if (!ok) { maxObjectsStashed = 100; }
138 const bool selected = ui->rb_SelectedOnly->isChecked();
139 int ownModelsCount = 0;
143 static const QString intro(
"Checking %1 selected models");
145 ownModelsCount = selectedModels.size();
146 this->addStatusMessage(
CStatusMessage(
this, CStatusMessage::SeverityInfo, intro.arg(ownModelsCount)));
148 CDatabaseUtils::updateSimulatorForFsFamily(selectedModels, &info, maxObjectsStashed,
this,
true);
153 const QSet<CSimulatorInfo> fsFamilySims(CSimulatorInfo::allFsFamilySimulators().asSingleSimulatorSet());
154 static const QString intro(
"Checking %1 models for %2");
160 const QString sim = simulator.
toQString();
161 ownModelsCount += ownModels.
size();
162 this->addStatusMessage(
163 CStatusMessage(
this, CStatusMessage::SeverityInfo, intro.arg(ownModels.
size()).arg(sim)));
165 CDatabaseUtils::updateSimulatorForFsFamily(ownModels, &info, maxObjectsStashed,
this,
true));
169 const QString result(
"Tested %1 own models, %2 models should be updated in DB");
170 this->addStatusMessages(info);
171 this->addStatusMessage(
172 CStatusMessage(
this, CStatusMessage::SeverityInfo, result.arg(ownModelsCount).arg(m_modelsToStash.
size())));
Allows to automatically update models if found in own model set, but already existing for a sibling s...
virtual ~CDbAutoSimulatorStashingComponent()
Destructor.
virtual void updateProgressIndicator(int percent)
Update the progress indicator 0..100.
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.
QString getOwnModelsInfoStringFsFamily() const
Info string without XPlane (FSX,P3D, FS9)
int selectedRowCount() const
Number of selected rows.
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.
Status messages, e.g. from Core -> GUI.
QString toQString(bool i18n=false) const
Cast as QString.
Aircraft model (used by another pilot, my models on disk)
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 hasModelString() const
Non empty model string?
Value object encapsulating a list of aircraft models.
Simple hardcoded info about the corresponding simulator.
Classes interacting with the swift database (aka "datastore").
High level reusable GUI components.
Free functions in swift::misc.