mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 23:25:53 +08:00
Ref T264, component to copy model cache/set from other version
This commit is contained in:
@@ -8,8 +8,12 @@
|
||||
*/
|
||||
|
||||
#include "configurationwizard.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "ui_configurationwizard.h"
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackmisc/directoryutils.h"
|
||||
#include <QPointer>
|
||||
|
||||
using namespace BlackMisc;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -20,6 +24,7 @@ namespace BlackGui
|
||||
ui(new Ui::CConfigurationWizard)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->wp_CopyModels->setConfigComponent(ui->comp_CopyModels);
|
||||
ui->wp_CopyCaches->setConfigComponent(ui->comp_CopyCaches);
|
||||
ui->wp_CopySettings->setConfigComponent(ui->comp_CopySettings);
|
||||
ui->wp_Simulator->setConfigComponent(ui->comp_Simulator);
|
||||
@@ -30,7 +35,7 @@ namespace BlackGui
|
||||
this->setButtonText(CustomButton1, "skip");
|
||||
|
||||
// no other versions, skip copy pages
|
||||
if (!ui->comp_CopySettings->hasOtherVersionData())
|
||||
if (!CDirectoryUtils::hasOtherSwiftDataDirectories())
|
||||
{
|
||||
this->setStartId(ConfigSimulator);
|
||||
}
|
||||
@@ -46,8 +51,11 @@ namespace BlackGui
|
||||
connect(this, &QWizard::accepted, this, &CConfigurationWizard::ended);
|
||||
|
||||
Q_ASSERT_X(sGui, Q_FUNC_INFO, "missing sGui");
|
||||
const QPointer<CConfigurationWizard> myself(this);
|
||||
connect(this, &QWizard::helpRequested, sGui, [ = ]
|
||||
{
|
||||
if (!myself) { return; }
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
sGui->showHelp(this);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace BlackGui
|
||||
//! Page ids
|
||||
enum Pages
|
||||
{
|
||||
CopyModels,
|
||||
CopySettings,
|
||||
CopyCaches,
|
||||
ConfigSimulator,
|
||||
|
||||
@@ -28,6 +28,31 @@
|
||||
<property name="options">
|
||||
<set>QWizard::HaveCustomButton1</set>
|
||||
</property>
|
||||
<widget class="BlackGui::Components::CCopyModelsFromOtherSwiftVersionsWizardPage" name="wp_CopyModels">
|
||||
<property name="title">
|
||||
<string>Copy models</string>
|
||||
</property>
|
||||
<property name="subTitle">
|
||||
<string>Copy model data from other swift versions. Here you can copy your model set or model cache from another swift version.</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_CopyModels">
|
||||
<property name="leftMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CCopyModelsFromOtherSwiftVersionsComponent" name="comp_CopyModels"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="BlackGui::Components::CCopyConfigurationWizardPage" name="wp_CopySettings">
|
||||
<property name="title">
|
||||
<string>Copy configuration from another installation</string>
|
||||
@@ -339,6 +364,18 @@
|
||||
<header>blackgui/components/firstmodelsetcomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CCopyModelsFromOtherSwiftVersionsWizardPage</class>
|
||||
<extends>QWizardPage</extends>
|
||||
<header>blackgui/components/copymodelsfromotherswiftversionscomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CCopyModelsFromOtherSwiftVersionsComponent</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/copymodelsfromotherswiftversionscomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
/* Copyright (C) 2018
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "copymodelsfromotherswiftversionscomponent.h"
|
||||
#include "ui_copymodelsfromotherswiftversionscomponent.h"
|
||||
#include "blackgui/models/aircraftmodellistmodel.h"
|
||||
#include "blackcore/application.h"
|
||||
#include "blackmisc/stringutils.h"
|
||||
#include "blackmisc/fileutils.h"
|
||||
#include "blackmisc/directoryutils.h"
|
||||
|
||||
#include <QSet>
|
||||
#include <QFileInfo>
|
||||
#include <QMessageBox>
|
||||
|
||||
using namespace BlackCore;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackGui::Models;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CCopyModelsFromOtherSwiftVersionsComponent::CCopyModelsFromOtherSwiftVersionsComponent(QWidget *parent) :
|
||||
COverlayMessagesFrame(parent),
|
||||
ui(new Ui::CCopyModelsFromOtherSwiftVersionsComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->comp_SimulatorSelector->setMode(CSimulatorSelector::CheckBoxes);
|
||||
ui->tvp_AircraftModels->setAircraftModelMode(CAircraftModelListModel::OwnModelSet);
|
||||
connect(ui->pb_StartCopying, &QPushButton::clicked, this, &CCopyModelsFromOtherSwiftVersionsComponent::copy);
|
||||
}
|
||||
|
||||
CCopyModelsFromOtherSwiftVersionsComponent::~CCopyModelsFromOtherSwiftVersionsComponent()
|
||||
{ }
|
||||
|
||||
void CCopyModelsFromOtherSwiftVersionsComponent::copy()
|
||||
{
|
||||
const QSet<CSimulatorInfo> sims = ui->comp_SimulatorSelector->getValue().asSingleSimulatorSet();
|
||||
if (sims.isEmpty())
|
||||
{
|
||||
static const CStatusMessage m = CStatusMessage(this).validationError("No simulators selected");
|
||||
this->showOverlayMessage(m);
|
||||
return;
|
||||
}
|
||||
|
||||
const bool set = ui->cb_ModelSet->isChecked();
|
||||
const bool cache = ui->cb_ModelCache->isChecked();
|
||||
if (!cache && !set)
|
||||
{
|
||||
static const CStatusMessage m = CStatusMessage(this).validationError("No simulators selected");
|
||||
this->showOverlayMessage(m);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ui->comp_OtherSwiftVersions->hasSelection())
|
||||
{
|
||||
static const CStatusMessage m = CStatusMessage(this).validationError("No other version selected");
|
||||
this->showOverlayMessage(m);
|
||||
return;
|
||||
}
|
||||
|
||||
const CApplicationInfo otherVersion = ui->comp_OtherSwiftVersions->selectedOtherVersion();
|
||||
for (const CSimulatorInfo &sim : sims)
|
||||
{
|
||||
if (set)
|
||||
{
|
||||
// inits current version cache
|
||||
m_modelSetCaches.setCurrentSimulator(sim);
|
||||
m_modelSetCaches.synchronizeCurrentCache();
|
||||
|
||||
// get file name
|
||||
CAircraftModelList otherSet;
|
||||
const QString thisVersionModelSetFile = m_modelSetCaches.getFilename(sim);
|
||||
if (this->readDataFile(thisVersionModelSetFile, otherSet, otherVersion, sim) && !otherSet.isEmpty())
|
||||
{
|
||||
CApplication::processEventsFor(250);
|
||||
if (this->confirmOverride(QString("Override model set for '%1'").arg(sim.toQString())))
|
||||
{
|
||||
m_modelSetCaches.setModels(otherSet, sim);
|
||||
}
|
||||
}
|
||||
} // set
|
||||
|
||||
if (cache)
|
||||
{
|
||||
// inits current version cache
|
||||
m_modelCaches.setCurrentSimulator(sim);
|
||||
m_modelCaches.synchronizeCurrentCache();
|
||||
|
||||
// get file name
|
||||
CAircraftModelList otherCache;
|
||||
const QString thisVersionModelCacheFile = m_modelCaches.getFilename(sim);
|
||||
if (this->readDataFile(thisVersionModelCacheFile, otherCache, otherVersion, sim) && !otherCache.isEmpty())
|
||||
{
|
||||
CApplication::processEventsFor(250);
|
||||
if (this->confirmOverride(QString("Override model cache for '%1'").arg(sim.toQString())))
|
||||
{
|
||||
m_modelCaches.setModels(otherCache, sim);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // all sims
|
||||
}
|
||||
|
||||
bool CCopyModelsFromOtherSwiftVersionsComponent::readDataFile(const QString &thisVersionModelFile, CAircraftModelList &models, const CApplicationInfo &otherVersion, const CSimulatorInfo &sim)
|
||||
{
|
||||
// init
|
||||
models.clear();
|
||||
|
||||
// create relative file name
|
||||
QString relativeModelFile = thisVersionModelFile;
|
||||
relativeModelFile = relativeModelFile.replace(CDirectoryUtils::applicationDataDirectory(), "", Qt::CaseInsensitive);
|
||||
if (relativeModelFile.length() < 2) { return false; }
|
||||
relativeModelFile = relativeModelFile.mid(relativeModelFile.indexOf('/', 1));
|
||||
|
||||
const QString otherModelFile = CFileUtils::appendFilePathsAndFixUnc(otherVersion.getApplicationDataDirectory(), relativeModelFile);
|
||||
const QFileInfo fiOtherModelFile(otherModelFile);
|
||||
if (!fiOtherModelFile.exists())
|
||||
{
|
||||
static const QString noSet("No models here: '%1'");
|
||||
ui->le_Status->setText(noSet.arg(fiOtherModelFile.absoluteFilePath()));
|
||||
return false;
|
||||
}
|
||||
|
||||
// read other file
|
||||
const QString jsonString = CFileUtils::readFileToString(fiOtherModelFile.absoluteFilePath());
|
||||
if (jsonString.isEmpty()) { return false; }
|
||||
try
|
||||
{
|
||||
models = CAircraftModelList::fromMultipleJsonFormats(jsonString);
|
||||
ui->tvp_AircraftModels->updateContainerAsync(models);
|
||||
static const QString importSet("Imported models: '%1'");
|
||||
ui->le_Status->setText(importSet.arg(fiOtherModelFile.absoluteFilePath()));
|
||||
}
|
||||
catch (const CJsonException &ex)
|
||||
{
|
||||
static const QString m("JSON format error. '%1'");
|
||||
this->showOverlayMessage(ex.toStatusMessage(this, m.arg(fiOtherModelFile.absoluteFilePath())));
|
||||
return false;
|
||||
}
|
||||
|
||||
static const QString importSet("Imported %1 models '%2' for %3");
|
||||
ui->le_Status->setText(importSet.arg(models.size()).arg(fiOtherModelFile.fileName(), sim.toQString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CCopyModelsFromOtherSwiftVersionsComponent::confirmOverride(const QString &msg)
|
||||
{
|
||||
if (ui->cb_Silent->isChecked()) { return true; }
|
||||
const QMessageBox::StandardButton reply = QMessageBox::question(this, QStringLiteral("Confirm override"), withQUestionMark(msg), QMessageBox::Yes | QMessageBox::No);
|
||||
return reply == QMessageBox::Yes;
|
||||
}
|
||||
|
||||
bool CCopyModelsFromOtherSwiftVersionsWizardPage::validatePage()
|
||||
{
|
||||
Q_ASSERT_X(m_copyModels, Q_FUNC_INFO, "Missing widget");
|
||||
return true;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
@@ -0,0 +1,79 @@
|
||||
/* Copyright (C) 2018
|
||||
* swift project Community / Contributors
|
||||
*
|
||||
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
|
||||
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
|
||||
* including this file, may be copied, modified, propagated, or distributed except according to the terms
|
||||
* contained in the LICENSE file.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKGUI_COMPONENTS_COPYMODELSFROMOTHERSWIFTVERSIONS_H
|
||||
#define BLACKGUI_COMPONENTS_COPYMODELSFROMOTHERSWIFTVERSIONS_H
|
||||
|
||||
#include "blackgui/overlaymessagesframe.h"
|
||||
#include "blackmisc/simulation/data/modelcaches.h"
|
||||
#include "blackmisc/applicationinfo.h"
|
||||
#include <QFrame>
|
||||
#include <QWizardPage>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace Ui { class CCopyModelsFromOtherSwiftVersionsComponent; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
/**
|
||||
* Copy models from another swift version
|
||||
*/
|
||||
class CCopyModelsFromOtherSwiftVersionsComponent : public COverlayMessagesFrame
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
explicit CCopyModelsFromOtherSwiftVersionsComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Dtor
|
||||
virtual ~CCopyModelsFromOtherSwiftVersionsComponent();
|
||||
|
||||
private:
|
||||
//! Copy as per UI settings
|
||||
void copy();
|
||||
|
||||
//! Read data file
|
||||
bool readDataFile(const QString &modelFile, BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::CApplicationInfo &otherVersion, const BlackMisc::Simulation::CSimulatorInfo &sim);
|
||||
|
||||
//! Confirm override
|
||||
bool confirmOverride(const QString &msg);
|
||||
|
||||
QScopedPointer<Ui::CCopyModelsFromOtherSwiftVersionsComponent> ui;
|
||||
|
||||
// caches will be explicitly initialized in copy
|
||||
BlackMisc::Simulation::Data::CModelCaches m_modelCaches { false, this };
|
||||
BlackMisc::Simulation::Data::CModelSetCaches m_modelSetCaches { false, this };
|
||||
};
|
||||
|
||||
/**
|
||||
* Wizard page for CCopyModelsFromOtherSwiftVersionsComponent
|
||||
*/
|
||||
class CCopyModelsFromOtherSwiftVersionsWizardPage : public QWizardPage
|
||||
{
|
||||
public:
|
||||
//! Constructors
|
||||
using QWizardPage::QWizardPage;
|
||||
|
||||
//! Set config
|
||||
void setConfigComponent(CCopyModelsFromOtherSwiftVersionsComponent *config) { m_copyModels = config; }
|
||||
|
||||
//! \copydoc QWizardPage::validatePage
|
||||
virtual bool validatePage() override;
|
||||
|
||||
private:
|
||||
CCopyModelsFromOtherSwiftVersionsComponent *m_copyModels = nullptr;
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
@@ -0,0 +1,191 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CCopyModelsFromOtherSwiftVersionsComponent</class>
|
||||
<widget class="QFrame" name="CCopyModelsFromOtherSwiftVersionsComponent">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>508</width>
|
||||
<height>420</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Copy models from other swift versions</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_CopyModelsFromOtherSwiftVersions" stretch="2,1,4">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_OtherSwiftVersions">
|
||||
<property name="title">
|
||||
<string>Select the version to copy from</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_OtherSwiftVersions">
|
||||
<item>
|
||||
<widget class="BlackGui::Components::COtherSwiftVersionsComponent" name="comp_OtherSwiftVersions">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>50</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_WhatToCopy">
|
||||
<property name="title">
|
||||
<string>Select what to copy</string>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="hl_WhatToCopy">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cb_ModelSet">
|
||||
<property name="text">
|
||||
<string>Model set</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cb_ModelCache">
|
||||
<property name="text">
|
||||
<string>Model cache</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lbl_Of">
|
||||
<property name="text">
|
||||
<string>of simulator:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlackGui::Components::CSimulatorSelector" name="comp_SimulatorSelector">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>100</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="hs_SelectWhatToCopy">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="cb_Silent">
|
||||
<property name="text">
|
||||
<string>silent</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_StartCopying">
|
||||
<property name="text">
|
||||
<string>start</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Progress">
|
||||
<property name="title">
|
||||
<string>Progress</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_Progress">
|
||||
<item>
|
||||
<widget class="QFrame" name="fr_Status">
|
||||
<layout class="QFormLayout" name="fl_Status">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_Status">
|
||||
<property name="text">
|
||||
<string>Status:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_Status">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="BlackGui::Views::CAircraftModelView" name="tvp_AircraftModels">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::SingleSelection</enum>
|
||||
</property>
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::COtherSwiftVersionsComponent</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/otherswiftversionscomponent.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Components::CSimulatorSelector</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/components/simulatorselector.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::Views::CAircraftModelView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>blackgui/views/aircraftmodelview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>cb_ModelSet</tabstop>
|
||||
<tabstop>cb_ModelCache</tabstop>
|
||||
<tabstop>cb_Silent</tabstop>
|
||||
<tabstop>pb_StartCopying</tabstop>
|
||||
<tabstop>le_Status</tabstop>
|
||||
<tabstop>tvp_AircraftModels</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user