11 #include "ui_copymodelsfromotherswiftversionscomponent.h"
22 using namespace swift::misc::simulation;
27 CCopyModelsFromOtherSwiftVersionsComponent::CCopyModelsFromOtherSwiftVersionsComponent(QWidget *parent)
32 ui->comp_SimulatorSelector->clear();
33 ui->tvp_AircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnModelSet);
34 connect(ui->pb_StartCopying, &QPushButton::clicked,
this, &CCopyModelsFromOtherSwiftVersionsComponent::copy);
36 &CCopyModelsFromOtherSwiftVersionsComponent::onVersionChanged);
41 void CCopyModelsFromOtherSwiftVersionsComponent::copy()
43 using namespace std::chrono_literals;
45 const CSimulatorInfo selectedSimulators = ui->comp_SimulatorSelector->getValue();
47 if (simulators.isEmpty())
54 const bool set = ui->cb_ModelSet->isChecked();
55 const bool cache = ui->cb_ModelCache->isChecked();
64 if (!ui->comp_OtherSwiftVersions->hasSelection())
73 const CApplicationInfo otherVersion = ui->comp_OtherSwiftVersions->selectedOtherVersion();
79 m_modelSetCaches.synchronizeCache(simulator);
83 const QString thisVersionModelSetFile = m_modelSetCaches.getFilename(simulator);
84 if (this->readDataFile(thisVersionModelSetFile, otherSet, otherVersion, simulator) &&
87 CApplication::processEventsFor(250);
88 if (this->confirmOverride(QStringLiteral(
"Override model set for '%1'").arg(simulator.toQString())))
90 m_modelSetCaches.setModelsForSimulator(otherSet, simulator);
99 m_modelCaches.synchronizeCache(simulator);
103 const QString thisVersionModelCacheFile = m_modelCaches.getFilename(simulator);
104 if (this->readDataFile(thisVersionModelCacheFile, otherCache, otherVersion, simulator) &&
107 CApplication::processEventsFor(250);
108 if (this->confirmOverride(
109 QStringLiteral(
"Override model cache for '%1'").arg(simulator.toQString())))
111 m_modelCaches.setModelsForSimulator(otherCache, simulator);
118 if (sets > 0 || caches > 0)
121 << sets << caches << selectedSimulators.
toQString(
true);
126 bool CCopyModelsFromOtherSwiftVersionsComponent::readDataFile(
const QString &thisVersionModelFile,
135 QString relativeModelFile = thisVersionModelFile;
137 relativeModelFile.replace(CSwiftDirectories::applicationDataDirectory(),
"", Qt::CaseInsensitive);
138 if (relativeModelFile.length() < 2) {
return false; }
139 relativeModelFile = relativeModelFile.mid(relativeModelFile.indexOf(
'/', 1));
141 const QString otherModelFile =
143 const QFileInfo fiOtherModelFile(otherModelFile);
144 if (!fiOtherModelFile.exists())
146 ui->le_Status->setText(QStringLiteral(
"No models here: '%1'").arg(fiOtherModelFile.absoluteFilePath()));
151 const QString jsonString = CFileUtils::readFileToString(fiOtherModelFile.absoluteFilePath());
152 if (jsonString.isEmpty()) {
return false; }
155 models = CAircraftModelList::fromMultipleJsonFormats(jsonString);
156 ui->tvp_AircraftModels->updateContainerAsync(models);
157 ui->le_Status->setText(QStringLiteral(
"Imported models: '%1'").arg(fiOtherModelFile.absoluteFilePath()));
162 ex,
this, QStringLiteral(
"JSON format error. '%1'").arg(fiOtherModelFile.absoluteFilePath())));
166 ui->le_Status->setText(QStringLiteral(
"Imported %1 models '%2' for %3")
168 .arg(fiOtherModelFile.fileName(), sim.
toQString()));
172 bool CCopyModelsFromOtherSwiftVersionsComponent::confirmOverride(
const QString &msg)
175 if (ui->cb_Silent->isChecked())
181 const QMessageBox::StandardButton reply = QMessageBox::question(
182 this, QStringLiteral(
"Confirm override"),
withQuestionMark(msg), QMessageBox::Yes | QMessageBox::No);
183 return reply == QMessageBox::Yes;
186 void CCopyModelsFromOtherSwiftVersionsComponent::onVersionChanged(
const CApplicationInfo &otherVersion)
193 ui->comp_SimulatorSelector->setValue(setSims);
198 ui->comp_OtherSwiftVersions->reloadOtherVersionsDeferred(deferMs);
204 if (m_copyModels) { m_copyModels->reloadOtherVersions(1000); }
209 Q_ASSERT_X(m_copyModels, Q_FUNC_INFO,
"Missing widget");
SWIFT_CORE_EXPORT swift::core::CApplication * sApp
Single instance of application object.
static void processEventsFor(int milliseconds)
Process all events for some time.
bool isShuttingDown() const
Is application shutting down?
bool showOverlayHTMLMessage(const QString &htmlMessage, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
HTML message.
bool showOverlayMessage(const swift::misc::CStatusMessage &message, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
Show single message.
Using this class provides a QFrame with the overlay functionality already integrated.
Copy models from another swift version.
void reloadOtherVersions(int deferMs=-1)
Reload other versions.
virtual ~CCopyModelsFromOtherSwiftVersionsComponent()
Dtor.
virtual bool validatePage()
virtual void initializePage()
void versionChanged(const swift::misc::CApplicationInfo &info)
Selection changed.
@ CheckBoxes
multiple selections
Description of a swift application.
const QString & getApplicationDataDirectory() const
Set application data dir.
Thrown when a convertFromJson method encounters an unrecoverable error in JSON data.
Derived & validationError(const char16_t(&format)[N])
Set the severity to error, providing a format string, and adding the validation category.
Derived & validationInfo(const char16_t(&format)[N])
Set the severity to info, providing a format string, and adding the validation category.
size_type size() const
Returns number of elements in the sequence.
void clear()
Removes all elements in the sequence.
bool isEmpty() const
Synonym for empty.
Streamable status message, e.g.
QString toQString(bool i18n=false) const
Cast as QString.
Value object encapsulating a list of aircraft models.
Simple hardcoded info about the corresponding simulator.
QSet< CSimulatorInfo > asSingleSimulatorSet() const
As a set of single simulator info objects.
bool isAnySimulator() const
Any simulator?
CSimulatorInfo otherVersionSimulatorsWithFile(const swift::misc::CApplicationInfo &info) const
Simulators of given other versionwhich have a cache file.
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.
Free functions in swift::misc.
SWIFT_MISC_EXPORT QString withQuestionMark(const QString &question)
Add a question mark at the end if not existing.