Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,169 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* Buildings - BuildingsConfigDialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by hjl, SLSE, 2017-04-20
|
||||
*/
|
||||
|
||||
#include "bld_config_dialog.h"
|
||||
#include "ui_bld_config_dialog.h"
|
||||
|
||||
// DDS
|
||||
#include <ProjectDataManagement/pdm_to_string.h>
|
||||
|
||||
// Lts
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsUtilsSettings/settings.h>
|
||||
|
||||
// Qt
|
||||
#include <QComboBox>
|
||||
|
||||
|
||||
namespace Buildings
|
||||
{
|
||||
|
||||
BldConfigDialog::BldConfigDialog(int bldEntityId, const QString &displayName, QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
||||
, m_bldEntityId(bldEntityId)
|
||||
, m_displayName(displayName)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_ui(new Ui::BldConfigDialog)
|
||||
, m_logger(getLogger("BuildingConfigDialog"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->setText(tr("Send and Close"));
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->setText(tr("Send"));
|
||||
connect(m_ui->cmbStatus, QOverload<int>::of(&QComboBox::currentIndexChanged), this,
|
||||
&BldConfigDialog::slotCmbStatusCurrentIndexChanged);
|
||||
|
||||
} // end of ctor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
BldConfigDialog::~BldConfigDialog()
|
||||
{
|
||||
delete m_ui;
|
||||
} // end of dtor()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void BldConfigDialog::retranslate()
|
||||
{
|
||||
translate(m_ui, m_displayName, false, tr("Building Status"));
|
||||
fillCbx();
|
||||
}
|
||||
|
||||
bool BldConfigDialog::init(LtsSession::LtsSession *session)
|
||||
{
|
||||
if (!session->getFtc<Buildings::DataInterface>(m_ftc))
|
||||
return false;
|
||||
if (!session->getFtc<CentralEffectSimulation::DataInterface>(m_cesFtc))
|
||||
return false;
|
||||
|
||||
std::shared_ptr<Buildings::Interface::Dtc> dtc;
|
||||
if (!session->getDtc<Buildings::DataInterface>(dtc))
|
||||
return false;
|
||||
if ( dtc != NULL)
|
||||
m_bldState = dtc->buildingState(m_bldEntityId);
|
||||
|
||||
|
||||
// TODO: Reactivate later:
|
||||
|
||||
// if (m_bldState.id() < 1)
|
||||
// {
|
||||
// LtsWidgets::LtsMessageDialog::showMessage(this, tr("The selected Building does not exist!"), tr("Invalid Building"));
|
||||
// return false;
|
||||
// }
|
||||
|
||||
slotChangesMade();
|
||||
const bool showBuildingOwnershp = LtsUtils::ProjectSettings::isFunctionEnabled(QStringLiteral("Buildings"),
|
||||
QStringLiteral("Ownership"));
|
||||
|
||||
if ( showBuildingOwnershp == false)
|
||||
{
|
||||
m_ui->gbOwnership->setVisible(false);
|
||||
}
|
||||
|
||||
return true;
|
||||
} // end of init()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
void BldConfigDialog::fillCbx()
|
||||
{
|
||||
m_ui->cmbStatus->clear();
|
||||
m_ui->cmbStatus->addItem(toString(ProjectDataManagement::VulnerabilityState::NoChange),
|
||||
ProjectDataManagement::VulnerabilityState::NoChange);
|
||||
m_ui->cmbStatus->addItem(toString(ProjectDataManagement::VulnerabilityState::CombatReady),
|
||||
ProjectDataManagement::VulnerabilityState::CombatReady);
|
||||
m_ui->cmbStatus->addItem(toString(ProjectDataManagement::VulnerabilityState::CatastrophicKill),
|
||||
ProjectDataManagement::VulnerabilityState::CatastrophicKill);
|
||||
m_ui->cmbStatus->setCurrentIndex(m_ui->cmbStatus->findData(m_bldState.vulnerabilityState().underlying()));
|
||||
|
||||
} // end of fillCbx()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
bool BldConfigDialog::apply()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION;
|
||||
|
||||
if (m_ui->chbOwnership->isChecked())
|
||||
{
|
||||
CentralEffectSimulation::SetOwnershipRequest req(m_bldEntityId, 0);
|
||||
m_requestHelper->addRequest([req, this]()
|
||||
{
|
||||
return m_cesFtc->setOwnershipRequest(req, this);
|
||||
});
|
||||
}
|
||||
|
||||
// aktuellen state aus Cbx ermitteln und LTS-SetBuildingStates aufrufen
|
||||
m_requestHelper->addRequest([this]()
|
||||
{
|
||||
// ich habe hier mal etwas aufgeraeumt:
|
||||
|
||||
// a) prepare Building
|
||||
Buildings::Building building;
|
||||
building.buildingId(m_bldEntityId);
|
||||
|
||||
// since the 'bracket initialization', this step could be skipped :-)
|
||||
// b) prepare buildingVec
|
||||
// use simply ...ldings({building});
|
||||
// std::vector<Buildings::Building> buildingVec;
|
||||
// buildingVec.resize(1);
|
||||
// buildingVec.push_back(building);
|
||||
|
||||
// c) prepare request
|
||||
SetBuildingStatesRequest requestData;
|
||||
requestData.buildings({building}); // <- 'bracket initialization' - helpfull to skip explicit vector :-)
|
||||
|
||||
ProjectDataManagement::VulnerabilityState state = static_cast<ProjectDataManagement::VulnerabilityState_def::type>(m_ui->cmbStatus->currentData().toInt());
|
||||
requestData.vulnerabilityState(state);
|
||||
|
||||
requestData.resetContamination(m_ui->chbResetContamination->isChecked());
|
||||
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << "currentIndex: " << m_ui->cmbStatus->currentIndex();
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << "currentData: " << state;
|
||||
|
||||
return m_ftc->setBuildingStatesRequest(requestData, this);
|
||||
});
|
||||
|
||||
return m_requestHelper->startRequests();
|
||||
|
||||
} // end of apply()
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
} // namespace Buildings
|
||||
|
||||
void Buildings::BldConfigDialog::slotCmbStatusCurrentIndexChanged(int index)
|
||||
{
|
||||
Q_UNUSED(index)
|
||||
ProjectDataManagement::VulnerabilityState state = static_cast<ProjectDataManagement::VulnerabilityState_def::type>(m_ui->cmbStatus->currentData().toInt());
|
||||
if (state == ProjectDataManagement::VulnerabilityState_def::CatastrophicKill)
|
||||
{
|
||||
m_ui->chbResetContamination->setEnabled(true);
|
||||
m_ui->chbResetContamination->setChecked(false);
|
||||
}
|
||||
else
|
||||
m_ui->chbResetContamination->setEnabled(true);
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user