mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 23:05:36 +08:00
Ref T441, 1st version for "reduction" dialog
This commit is contained in:
118
src/blackgui/components/dbreducemodelduplicates.cpp
Normal file
118
src/blackgui/components/dbreducemodelduplicates.cpp
Normal file
@@ -0,0 +1,118 @@
|
||||
/* 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 "dbreducemodelduplicates.h"
|
||||
#include "ui_dbreducemodelduplicates.h"
|
||||
|
||||
#include "blackgui/guiapplication.h"
|
||||
#include "blackgui/uppercasevalidator.h"
|
||||
#include "blackcore/webdataservices.h"
|
||||
#include "blackmisc/statusmessage.h"
|
||||
|
||||
#include <QCompleter>
|
||||
#include <QPushButton>
|
||||
|
||||
using namespace BlackMisc;
|
||||
using namespace BlackMisc::Simulation;
|
||||
using namespace BlackGui::Views;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
CDbReduceModelDuplicates::CDbReduceModelDuplicates(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::CDbReduceModelDuplicates)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
ui->tvp_RemoveModels->menuAddItems(CAircraftModelView::MenuRemoveSelectedRows);
|
||||
ui->le_Distributor->setValidator(new CUpperCaseValidator(ui->le_Distributor));
|
||||
|
||||
connect(ui->pb_Run, &QPushButton::clicked, this, &CDbReduceModelDuplicates::process);
|
||||
}
|
||||
|
||||
CDbReduceModelDuplicates::~CDbReduceModelDuplicates()
|
||||
{ }
|
||||
|
||||
void CDbReduceModelDuplicates::setModels(const CAircraftModelList &models, const CSimulatorInfo &simulator)
|
||||
{
|
||||
m_models = models;
|
||||
m_simulator = simulator;
|
||||
|
||||
const QStringList distributors = models.getDistributors().getDbKeysAndAliases(true);
|
||||
QCompleter *c = new QCompleter(distributors, this);
|
||||
c->setCaseSensitivity(Qt::CaseInsensitive);
|
||||
ui->le_Distributor->setCompleter(c);
|
||||
ui->le_Models->setText(QStringLiteral("%1 models for simulator '%2', distributors: %3").arg(models.size()).arg(simulator.toQString(true)).arg(distributors.size()));
|
||||
}
|
||||
|
||||
void CDbReduceModelDuplicates::process()
|
||||
{
|
||||
if (!sGui || sGui->isShuttingDown()) { return; }
|
||||
if (m_models.isEmpty())
|
||||
{
|
||||
const CStatusMessage m = CStatusMessage(this).validationError("No models");
|
||||
ui->fr_Overlay->showOverlayHTMLMessage(m, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
const CAircraftModelList keyDuplicates = m_models.findDuplicateModelStrings();
|
||||
if (!keyDuplicates.isEmpty())
|
||||
{
|
||||
const CStatusMessage m = CStatusMessage(this).validationError("Found %1 key duplicates") << keyDuplicates.size();
|
||||
ui->fr_Overlay->showOverlayHTMLMessage(m, 5000);
|
||||
}
|
||||
|
||||
if (ui->le_Distributor->text().isEmpty())
|
||||
{
|
||||
const CStatusMessage m = CStatusMessage(this).validationError("No distributor");
|
||||
ui->fr_Overlay->showOverlayHTMLMessage(m, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
const CDistributorList distributors = m_models.getDistributors();
|
||||
const CDistributor distributor = distributors.findByKeyOrAlias(ui->le_Distributor->text().trimmed().toUpper());
|
||||
if (!distributor.hasValidDbKey())
|
||||
{
|
||||
const CStatusMessage m = CStatusMessage(this).validationError("Invalid distributor");
|
||||
ui->fr_Overlay->showOverlayHTMLMessage(m, 5000);
|
||||
return;
|
||||
}
|
||||
|
||||
const CAircraftModelList distributorModels = m_models.findByDistributor(distributor);
|
||||
CAircraftModelList nonDistributorModels = m_models;
|
||||
nonDistributorModels.removeByDistributor(distributor); // all models of other distrbutors
|
||||
CAircraftModelList removeModels;
|
||||
|
||||
for (const CAircraftModel &distributorModel : distributorModels)
|
||||
{
|
||||
if (!distributorModel.getLivery().isAirlineLivery()) { continue; }
|
||||
if (!distributorModel.getAircraftIcaoCode().hasValidDbKey()) { continue; }
|
||||
if (ui->rb_SameLiveryAndAircraft->isChecked())
|
||||
{
|
||||
removeModels.replaceOrAddModelsWithString(nonDistributorModels.findByAircraftAndLivery(distributorModel.getAircraftIcaoCode(), distributorModel.getLivery()), Qt::CaseInsensitive);
|
||||
}
|
||||
else if (ui->rb_SameAirlineAndAircraft->isChecked())
|
||||
{
|
||||
removeModels.replaceOrAddModelsWithString(nonDistributorModels.findByAircraftAndAirline(distributorModel.getAircraftIcaoCode(), distributorModel.getAirlineIcaoCode()), Qt::CaseInsensitive);
|
||||
}
|
||||
}
|
||||
|
||||
ui->tvp_RemoveModels->updateContainerMaybeAsync(removeModels);
|
||||
m_removeCandidates = removeModels;
|
||||
|
||||
const QString distKeys = removeModels.getDistributors().dbKeysAsString(", ");
|
||||
const CStatusMessage m = removeModels.isEmpty() ?
|
||||
CStatusMessage(this).info("No duplicates to be removed!") :
|
||||
CStatusMessage(this).info("You can remove %1 models of the following distributors: '%2'.") << removeModels.size() << distKeys;
|
||||
ui->fr_Overlay->showOverlayHTMLMessage(m, 5000);
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
58
src/blackgui/components/dbreducemodelduplicates.h
Normal file
58
src/blackgui/components/dbreducemodelduplicates.h
Normal file
@@ -0,0 +1,58 @@
|
||||
/* 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_DBREDUCEMODELDUPLICATES_H
|
||||
#define BLACKGUI_COMPONENTS_DBREDUCEMODELDUPLICATES_H
|
||||
|
||||
#include "blackmisc/simulation/aircraftmodellist.h"
|
||||
|
||||
#include <QDialog>
|
||||
#include <QScopedPointer>
|
||||
|
||||
namespace Ui { class CDbReduceModelDuplicates; }
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Components
|
||||
{
|
||||
//! Reduce modelss
|
||||
class CDbReduceModelDuplicates : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
//! Ctor
|
||||
explicit CDbReduceModelDuplicates(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
virtual ~CDbReduceModelDuplicates();
|
||||
|
||||
//! Set the models
|
||||
void setModels(const BlackMisc::Simulation::CAircraftModelList &models, const BlackMisc::Simulation::CSimulatorInfo &simulator);
|
||||
|
||||
//! Process models
|
||||
void process();
|
||||
|
||||
//! The models to be removed
|
||||
const BlackMisc::Simulation::CAircraftModelList &getRemoveCandidates() const { return m_removeCandidates; }
|
||||
|
||||
//! Simulator
|
||||
const BlackMisc::Simulation::CSimulatorInfo &getSimulator() const { return m_simulator; }
|
||||
|
||||
private:
|
||||
QScopedPointer<Ui::CDbReduceModelDuplicates> ui;
|
||||
BlackMisc::Simulation::CSimulatorInfo m_simulator;
|
||||
BlackMisc::Simulation::CAircraftModelList m_models;
|
||||
BlackMisc::Simulation::CAircraftModelList m_removeCandidates;
|
||||
};
|
||||
} //ns
|
||||
} //ns
|
||||
|
||||
#endif // guard
|
||||
236
src/blackgui/components/dbreducemodelduplicates.ui
Normal file
236
src/blackgui/components/dbreducemodelduplicates.ui
Normal file
@@ -0,0 +1,236 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CDbReduceModelDuplicates</class>
|
||||
<widget class="QDialog" name="CDbReduceModelDuplicates">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>640</width>
|
||||
<height>480</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Reduce models</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_ReduceModelDuplicate" stretch="1,0">
|
||||
<item>
|
||||
<widget class="BlackGui::COverlayMessagesFrame" name="fr_Overlay">
|
||||
<layout class="QVBoxLayout" name="vl_OverlayFrame" stretch="0,1">
|
||||
<property name="leftMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_Selection">
|
||||
<property name="title">
|
||||
<string>Selection</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="fl_Selection">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="lbl_Models">
|
||||
<property name="text">
|
||||
<string>Models:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="le_Models">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="lbl_Distributor">
|
||||
<property name="text">
|
||||
<string>Preferred distributor:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="le_Distributor"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="lnl_Mode">
|
||||
<property name="text">
|
||||
<string>Reduction mode:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QFrame" name="fr_Mode">
|
||||
<layout class="QHBoxLayout" name="hl_Mode">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item alignment="Qt::AlignLeft">
|
||||
<widget class="QRadioButton" name="rb_SameLiveryAndAircraft">
|
||||
<property name="text">
|
||||
<string>with exactly same livery and aircraft</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRadioButton" name="rb_SameAirlineAndAircraft">
|
||||
<property name="text">
|
||||
<string>with same airline and aircraft</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="hs_Mode">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QFrame" name="fr_Button">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<spacer name="hs_Button">
|
||||
<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="QPushButton" name="pb_Run">
|
||||
<property name="text">
|
||||
<string>run</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="gb_RemoveModels">
|
||||
<property name="title">
|
||||
<string>Remove models</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="vl_RemoveModels">
|
||||
<item>
|
||||
<widget class="BlackGui::Views::CAircraftModelView" name="tvp_RemoveModels">
|
||||
<property name="selectionBehavior">
|
||||
<enum>QAbstractItemView::SelectRows</enum>
|
||||
</property>
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="bb_ReduceModelDuplicates">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>BlackGui::Views::CAircraftModelView</class>
|
||||
<extends>QTableView</extends>
|
||||
<header>blackgui/views/aircraftmodelview.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>BlackGui::COverlayMessagesFrame</class>
|
||||
<extends>QFrame</extends>
|
||||
<header>blackgui/overlaymessagesframe.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>le_Models</tabstop>
|
||||
<tabstop>le_Distributor</tabstop>
|
||||
<tabstop>rb_SameLiveryAndAircraft</tabstop>
|
||||
<tabstop>rb_SameAirlineAndAircraft</tabstop>
|
||||
<tabstop>tvp_RemoveModels</tabstop>
|
||||
<tabstop>pb_Run</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>bb_ReduceModelDuplicates</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>CDbReduceModelDuplicates</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_ReduceModelDuplicates</sender>
|
||||
<signal>rejected()</signal>
|
||||
<receiver>CDbReduceModelDuplicates</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>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user