Ref T246, renamed dialog to CDbOwnModelSetFormDialog

This commit is contained in:
Klaus Basan
2018-02-08 03:15:23 +01:00
parent 887d1ec401
commit bd7ffb5ea2
3 changed files with 43 additions and 45 deletions

View File

@@ -0,0 +1,149 @@
/* 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/modelsetbuilder.h"
#include "blackgui/components/dbmappingcomponent.h"
#include "blackgui/components/dbownmodelsetformdialog.h"
#include "blackgui/editors/ownmodelsetform.h"
#include "blackmisc/logcategory.h"
#include "blackmisc/logcategorylist.h"
#include "blackmisc/simulation/distributorlist.h"
#include "ui_dbownmodelsetformdialog.h"
#include <QPushButton>
#include <QString>
#include <QWidget>
#include <QtGlobal>
using namespace BlackMisc;
using namespace BlackMisc::Simulation;
using namespace BlackCore;
using namespace BlackGui::Editors;
namespace BlackGui
{
namespace Components
{
const CLogCategoryList &CDbOwnModelSetFormDialog::getLogCategories()
{
static const CLogCategoryList cats({ CLogCategory("swift.ownmodelset"), CLogCategory::guiComponent()});
return cats;
}
CDbOwnModelSetFormDialog::CDbOwnModelSetFormDialog(QWidget *parent) :
QDialog(parent),
CDbMappingComponentAware(parent),
ui(new Ui::CDbOwnModelSetFormDialog)
{
ui->setupUi(this);
connect(ui->pb_Cancel, &QPushButton::clicked, this, &CDbOwnModelSetFormDialog::buttonClicked);
connect(ui->pb_Ok, &QPushButton::clicked, this, &CDbOwnModelSetFormDialog::buttonClicked);
connect(ui->form_OwnModelSet, &COwnModelSetForm::simulatorChanged, this, &CDbOwnModelSetFormDialog::simulatorChanged);
}
CDbOwnModelSetFormDialog::~CDbOwnModelSetFormDialog()
{
// void
}
void CDbOwnModelSetFormDialog::reloadData()
{
m_simulatorInfo = this->getMappingComponent()->getOwnModelsSimulator();
Q_ASSERT_X(m_simulatorInfo.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
ui->form_OwnModelSet->setSimulator(m_simulatorInfo);
ui->form_OwnModelSet->reloadData();
m_modelSet = this->getMappingComponent()->getOwnModelSet();
}
int CDbOwnModelSetFormDialog::exec()
{
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
const CSimulatorInfo sim(this->getMappingComponent()->getOwnModelsSimulator());
Q_ASSERT_X(sim.isSingleSimulator(), Q_FUNC_INFO, "need single simulator");
this->setSimulator(sim);
this->checkData();
return QDialog::exec();
}
void CDbOwnModelSetFormDialog::buttonClicked()
{
const QObject *sender = QObject::sender();
if (sender == ui->pb_Cancel)
{
this->reject();
}
else if (sender == ui->pb_Ok)
{
m_modelSet = this->buildSet(m_simulatorInfo, m_modelSet);
this->accept();
}
}
void CDbOwnModelSetFormDialog::simulatorChanged(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
this->setSimulator(simulator);
this->getMappingComponent()->setOwnModelsSimulator(simulator);
this->getMappingComponent()->setOwnModelSetSimulator(simulator);
this->checkData();
}
bool CDbOwnModelSetFormDialog::checkData()
{
// models
Q_ASSERT_X(m_simulatorInfo.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
const int c = this->getMappingComponent()->getOwnModelsCount();
if (c < 1)
{
const CStatusMessage m = CStatusMessage(this).error("No models for %1") << m_simulatorInfo.toQString(true);
ui->form_OwnModelSet->showOverlayMessage(m);
return false;
}
return true;
}
void CDbOwnModelSetFormDialog::setSimulator(const CSimulatorInfo &simulator)
{
Q_ASSERT_X(m_simulatorInfo.isSingleSimulator(), Q_FUNC_INFO, "Need single simulator");
m_simulatorInfo = simulator;
ui->form_OwnModelSet->setSimulator(m_simulatorInfo);
this->setWindowTitle("Create model set for " + m_simulatorInfo.toQString(true));
}
CAircraftModelList CDbOwnModelSetFormDialog::buildSet(const CSimulatorInfo &simulator, const CAircraftModelList &currentSet)
{
Q_ASSERT_X(this->getMappingComponent(), Q_FUNC_INFO, "missing mapping component");
const bool givenDistributorsOnly = !ui->form_OwnModelSet->optionUseAllDistributors();
const bool dbDataOnly = ui->form_OwnModelSet->optionDbDataOnly();
const bool dbIcaoOnly = ui->form_OwnModelSet->optionDbIcaoCodesOnly();
const bool incremnental = ui->form_OwnModelSet->optionIncrementalBuild();
const bool sortByDistributor = ui->form_OwnModelSet->optionSortByDistributorPreferences();
const bool consolidateWithDb = ui->form_OwnModelSet->optionConsolidateModelSetWithDbData();
m_simulatorInfo = this->getMappingComponent()->getOwnModelsSimulator();
const CAircraftModelList models = this->getMappingComponent()->getOwnModels();
const CDistributorList distributors = ui->form_OwnModelSet->getDistributorsBasedOnOptions();
if (givenDistributorsOnly && distributors.isEmpty())
{
// nothing to do, keep current set
return currentSet;
}
const CModelSetBuilder builder(this);
CModelSetBuilder::Builder options = givenDistributorsOnly ? CModelSetBuilder::GivenDistributorsOnly : CModelSetBuilder::NoOptions;
if (dbDataOnly) { options |= CModelSetBuilder::OnlyDbData; }
if (dbIcaoOnly) { options |= CModelSetBuilder::OnlyDbIcaoCodes; }
if (incremnental) { options |= CModelSetBuilder::Incremental; }
if (sortByDistributor) { options |= CModelSetBuilder::SortByDistributors; }
if (consolidateWithDb) { options |= CModelSetBuilder::ConsolidateWithDb; }
return builder.buildModelSet(simulator, models, currentSet, options, distributors);
}
} // ns
} // ns