mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-04 00:16:51 +08:00
refs #743, dialog for cross simulator updates FSX-P3D-FS9
This commit is contained in:
committed by
Mathew Sutcliffe
parent
35f010e516
commit
260996b38c
169
src/blackgui/components/dbautosimulatorstashingcomponent.cpp
Normal file
169
src/blackgui/components/dbautosimulatorstashingcomponent.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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 "blackcore/db/databaseutils.h"
|
||||
#include "dbautosimulatorstashingcomponent.h"
|
||||
#include "dbmappingcomponent.h"
|
||||
#include "ui_dbautosimulatorstashingcomponent.h"
|
||||
#include <QIntValidator>
|
||||
|
||||
using namespace BlackGui;
|
||||
using namespace BlackCore::Db;
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CDbAutoSimulatorStashingComponent::CDbAutoSimulatorStashingComponent(QWidget *parent) :
|
||||
QDialog(parent, Qt::WindowSystemMenuHint | Qt::WindowTitleHint),
|
||||
CDbMappingComponentAware(qobject_cast<CDbMappingComponent * >(parent)),
|
||||
ui(new Ui::CDbAutoSimulatorStashingComponent)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->le_MaxModelsStashed->setValidator(new QIntValidator(this));
|
||||
ui->tvp_StatusMessages->setMode(BlackGui::Models::CStatusMessageListModel::Simplified);
|
||||
ui->le_MaxModelsStashed->setText("100");
|
||||
}
|
||||
|
||||
int CDbAutoSimulatorStashingComponent::exec()
|
||||
{
|
||||
this->initGui();
|
||||
return QDialog::exec();
|
||||
}
|
||||
|
||||
void CDbAutoSimulatorStashingComponent::accept()
|
||||
{
|
||||
switch (this->m_state)
|
||||
{
|
||||
case Running: return;
|
||||
case Completed:
|
||||
{
|
||||
if (!this->m_modelsToStash.isEmpty())
|
||||
{
|
||||
// this removes previously stashed models
|
||||
this->getMappingComponent()->replaceStashedModelsUnvalidated(this->m_modelsToStash);
|
||||
const CStatusMessage stashedMsg(this, CStatusMessage::SeverityInfo, QString("Stashed %1 models").arg(this->m_modelsToStash.size()));
|
||||
this->addStatusMessage(stashedMsg);
|
||||
this->m_modelsToStash.clear();
|
||||
}
|
||||
QDialog::accept();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
this->tryToStash();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CDbAutoSimulatorStashingComponent::~CDbAutoSimulatorStashingComponent()
|
||||
{ }
|
||||
|
||||
void CDbAutoSimulatorStashingComponent::updateProgressIndicator(int percent)
|
||||
{
|
||||
if (percent > 100) { percent = 100; }
|
||||
if (percent < 0) { percent = 0; }
|
||||
ui->pb_StashingProgress->setValue(percent);
|
||||
}
|
||||
|
||||
Views::CAircraftModelView *CDbAutoSimulatorStashingComponent::currentModelView() const
|
||||
{
|
||||
return this->getMappingComponent()->currentModelView();
|
||||
}
|
||||
|
||||
void CDbAutoSimulatorStashingComponent::initGui()
|
||||
{
|
||||
ui->bb_OkCancel->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
|
||||
ui->tvp_StatusMessages->clear();
|
||||
this->m_state = Idle;
|
||||
this->updateProgressIndicator(0);
|
||||
|
||||
const QString infoAll = this->getMappingComponent()->getOwnModelsInfoStringFsFamily();
|
||||
ui->le_AllSets->setText(infoAll);
|
||||
|
||||
if (!this->currentModelView())
|
||||
{
|
||||
const CStatusMessage m(this, CStatusMessage::SeverityError, "No data for simulator updating");
|
||||
this->addStatusMessage(m);
|
||||
}
|
||||
else
|
||||
{
|
||||
int selected = this->currentModelView()->selectedRowCount();
|
||||
ui->le_Selected->setText(QString::number(selected));
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAutoSimulatorStashingComponent::addStatusMessage(const CStatusMessage &msg)
|
||||
{
|
||||
if (msg.isEmpty()) { return; }
|
||||
ui->tvp_StatusMessages->insert(msg);
|
||||
}
|
||||
|
||||
void CDbAutoSimulatorStashingComponent::addStatusMessage(const CStatusMessage &msg, const CAircraftModel &model)
|
||||
{
|
||||
if (msg.isEmpty()) { return; }
|
||||
if (model.hasModelString())
|
||||
{
|
||||
CStatusMessage prefixMessage(msg);
|
||||
prefixMessage.prependMessage(QString(model.getModelString() + ", " + model.getMembersDbStatus() + ": "));
|
||||
ui->tvp_StatusMessages->insert(prefixMessage);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->tvp_StatusMessages->insert(msg);
|
||||
}
|
||||
}
|
||||
|
||||
void CDbAutoSimulatorStashingComponent::tryToStash()
|
||||
{
|
||||
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "Missing mapping component");
|
||||
|
||||
if (!this->currentModelView()) { return; }
|
||||
this->m_state = Running;
|
||||
int maxObjectsStashed = -1;
|
||||
if (!ui->le_MaxModelsStashed->text().isEmpty())
|
||||
{
|
||||
bool ok;
|
||||
ui->le_MaxModelsStashed->text().toInt(&ok);
|
||||
if (!ok) { maxObjectsStashed = 100; }
|
||||
}
|
||||
|
||||
const bool selected = ui->rb_SelectedOnly->isChecked();
|
||||
int ownModelsCount = 0;
|
||||
if (selected)
|
||||
{
|
||||
const QString intro("Checking %1 selected models");
|
||||
const CAircraftModelList selectedModels(this->currentModelView()->selectedObjects());
|
||||
ownModelsCount = selectedModels.size();
|
||||
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModelsCount)));
|
||||
this->m_modelsToStash = CDatabaseUtils::updateSimulatorForFsFamily(selectedModels, maxObjectsStashed, this, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
const CDbMappingComponent *mappincComponent = this->getMappingComponent();
|
||||
const QSet<CSimulatorInfo> fsFamilySims(CSimulatorInfo::allFsFamilySimulators().asSingleSimulatorSet());
|
||||
const QString intro("Checking %1 models for %2");
|
||||
for (const CSimulatorInfo &simulator : fsFamilySims)
|
||||
{
|
||||
const CAircraftModelList ownModels = mappincComponent->getOwnCachedModels(simulator);
|
||||
const QString sim = simulator.toQString();
|
||||
ownModelsCount += ownModels.size();
|
||||
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, intro.arg(ownModels.size()).arg(sim)));
|
||||
this->m_modelsToStash.push_back(CDatabaseUtils::updateSimulatorForFsFamily(ownModels, maxObjectsStashed, this, true));
|
||||
}
|
||||
}
|
||||
const QString result("Tested %1 own models, %2 models should be updated in DB");
|
||||
this->addStatusMessage(CStatusMessage(this, CStatusMessage::SeverityInfo, result.arg(ownModelsCount).arg(this->m_modelsToStash.size())));
|
||||
this->m_state = Completed;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
91
src/blackgui/components/dbautosimulatorstashingcomponent.h
Normal file
91
src/blackgui/components/dbautosimulatorstashingcomponent.h
Normal file
@@ -0,0 +1,91 @@
|
||||
/* Copyright (C) 2016
|
||||
* 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_DBAUTOSIMULATORSTASHINGCOMPONENT_H
|
||||
#define BLACKGUI_COMPONENTS_DBAUTOSIMULATORSTASHINGCOMPONENT_H
|
||||
|
||||
#include "blackgui/blackguiexport.h"
|
||||
#include "blackgui/components/dbmappingcomponentaware.h"
|
||||
#include "blackgui/views/aircraftmodelview.h"
|
||||
#include "blackcore/progress.h"
|
||||
#include "blackmisc/simulation/aircraftmodel.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
#include <QDialog>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace Ui { class CDbAutoSimulatorStashingComponent; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
/**
|
||||
* Allows to automatically updated models if found in own model set, but already existing
|
||||
* for a sibling simulator (ie. FSX/P3D/FS9)
|
||||
*/
|
||||
class BLACKGUI_EXPORT CDbAutoSimulatorStashingComponent :
|
||||
public QDialog,
|
||||
public BlackGui::Components::CDbMappingComponentAware,
|
||||
public BlackCore::IProgressIndicator
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Current state of this component
|
||||
enum State
|
||||
{
|
||||
Idle,
|
||||
Running,
|
||||
Completed
|
||||
};
|
||||
|
||||
//! Constructor
|
||||
explicit CDbAutoSimulatorStashingComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CDbAutoSimulatorStashingComponent();
|
||||
|
||||
//! At least run once and completed
|
||||
bool isCompleted() const { return m_state == Completed; }
|
||||
|
||||
//! \copydoc BlackCore::IProgressIndicator::updateProgressIndicator
|
||||
virtual void updateProgressIndicator(int percent) override;
|
||||
|
||||
public slots:
|
||||
//! \copydoc QDialog::accept
|
||||
virtual void accept() override;
|
||||
|
||||
//! \copydoc QDialog::exec
|
||||
virtual int exec() override;
|
||||
|
||||
private:
|
||||
//! Init the GUI
|
||||
void initGui();
|
||||
|
||||
//! Model view to take models from
|
||||
BlackGui::Views::CAircraftModelView *currentModelView() const;
|
||||
|
||||
//! Add a status message
|
||||
void addStatusMessage(const BlackMisc::CStatusMessage &msg);
|
||||
|
||||
//! Add a status message for a given model (prefixed)
|
||||
void addStatusMessage(const BlackMisc::CStatusMessage &msg, const BlackMisc::Simulation::CAircraftModel &model);
|
||||
|
||||
//! Try to stash updated models
|
||||
void tryToStash();
|
||||
|
||||
QScopedPointer<Ui::CDbAutoSimulatorStashingComponent> ui;
|
||||
State m_state = Idle; //!< modus
|
||||
BlackMisc::Simulation::CAircraftModelList m_modelsToStash; //!< Models about to be stashed
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
148
src/blackgui/components/dbautosimulatorstashingcomponent.ui
Normal file
148
src/blackgui/components/dbautosimulatorstashingcomponent.ui
Normal file
@@ -0,0 +1,148 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDbAutoSimulatorStashingComponent</class>
|
||||
<widget class="QDialog" name="CDbAutoSimulatorStashingComponent">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<height>400</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Cross simulator updating (FSX-P3D-FS9)</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="4" column="0" colspan="4">
|
||||
<widget class="QProgressBar" name="pb_StashingProgress">
|
||||
<property name="value">
|
||||
<number>24</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0" colspan="4">
|
||||
<widget class="BlackGui::Views::CStatusMessageView" name="tvp_StatusMessages">
|
||||
<property name="selectionMode">
|
||||
<enum>QAbstractItemView::NoSelection</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="3">
|
||||
<widget class="QLineEdit" name="le_AllSets">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QRadioButton" name="rb_SelectedOnly">
|
||||
<property name="text">
|
||||
<string>selected</string>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">bg_ScanAllOrSelected</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0" colspan="4">
|
||||
<widget class="QDialogButtonBox" name="bb_OkCancel">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="QRadioButton" name="rb_ScanAllModels">
|
||||
<property name="text">
|
||||
<string>scan all models</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<attribute name="buttonGroup">
|
||||
<string notr="true">bg_ScanAllOrSelected</string>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_Selected">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="lbl_MaxModelsStashed">
|
||||
<property name="text">
|
||||
<string>Max.stashed:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="le_MaxModelsStashed">
|
||||
<property name="placeholderText">
|
||||
<string>max.models to be stashed</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::Views::CStatusMessageView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>blackgui/views/statusmessageview.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>bb_OkCancel</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CDbAutoSimulatorStashingComponent</receiver>
|
||||
<slot>accept()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>248</x>
|
||||
<y>254</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>157</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
<connection>
|
||||
<sender>bb_OkCancel</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CDbAutoSimulatorStashingComponent</receiver>
|
||||
<slot>reject()</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>316</x>
|
||||
<y>260</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>286</x>
|
||||
<y>274</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
<buttongroups>
|
||||
<buttongroup name="bg_ScanAllOrSelected"/>
|
||||
</buttongroups>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user