/** * @RDE_HEADER@ * MeteoDataManagement - Static Meteo Data Edit Dialog * $Id$ * $HeadURL$ * $Author$ * Created by hjl, SLSE, 2016-10-17 */ #include "esm_effect_show_edit.h" #include "ui_esm_effect_show_list.h" #include "ui_esm_effect_show_edit.h" #include "esm_effect_show_actor_model.h" #include #include #include #include #include namespace EffectShowManagement { EffectShowEdit::EffectShowEdit(const EffectShow &effectShow, QWidget *parent) : LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel) , m_ftc(nullptr) , m_model(nullptr) , m_requestHelper(new LtsUtils::RequestHelper(this)) , m_effectShow(effectShow) , m_ui(new Ui::EffectShowEdit) , m_logger(getLogger("EffectShowEdit")) { m_ui->setupUi(this); } EffectShowEdit::~EffectShowEdit() { delete m_ui; } void EffectShowEdit::retranslate() { translate(m_ui, tr("Edit Effect Show")); } bool EffectShowEdit::init(LtsSession::LtsSession *session, EffectShowModel *model) { m_session = session; if (!session->getFtc(m_ftc)) return false; if (!session->getDtc(m_pdmDtc)) return false; if (!session->getDtc(m_ppmDtc)) return false; if (!session->getDtc(m_aesDtc)) return false; if (!session->getForeignGuiInterface(m_esmActorCbx)) return false; DEBUG_LOG(m_logger) << "EffectShowEdit::init()"; m_model = model; AreaEffectSimulation::AesItem aesItem; bool foundItem = m_aesDtc->aesItemFromId(m_effectShow.idAreaEffectSimulation(), aesItem); DEBUG_LOG(m_logger) << ", found :" << foundItem << ", idAreaEffectSimulation :" << m_effectShow.idAreaEffectSimulation() << ", aesItem.id() :" << aesItem.id() << ", esmParticipantId: " << m_effectShow.esmParticipantId(); if (!foundItem) return false; m_isSmoke = m_pdmDtc->isSmoke(aesItem.chargeStruct().chargeTypeId(), aesItem.chargeStruct().igniterTypeId(), aesItem.chargeStruct().igniterFunctionId()); if (!m_isSmoke) { connect(m_ui->sbVolley, static_cast(&QSpinBox::valueChanged), this, [this](int val) { m_ui->sbShotsInTotal->setMinimum(val); if (m_ui->sbShotsInTotal->value() < val) m_ui->sbShotsInTotal->setValue(val); }); // initialize filter combobox m_ui->cbEffectShowActorFilter->addItem(tr(""), EffectShowActorModel::eFeature::NotSpecified); m_ui->cbEffectShowActorFilter->addItem(EffectShowActorModel::getFeatureName(EffectShowActorModel::eFeature::SmokeAndExplosion48), EffectShowActorModel::eFeature::SmokeAndExplosion48); m_ui->cbEffectShowActorFilter->addItem(EffectShowActorModel::getFeatureName(EffectShowActorModel::eFeature::Explosion24), EffectShowActorModel::eFeature::Explosion24); m_ui->cbEffectShowActorFilter->setCurrentIndex(1); // default should be SmokeAndExplosion48 == DMF-Fz onEffectShowActorFilterChanged(-1); // function argument has no effect connect(m_ui->cbEffectShowActorFilter, QOverload::of(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &EffectShowEdit::onEffectShowActorFilterChanged); } else { m_ui->lblEffectShowActorFilter->hide(); m_ui->cbEffectShowActorFilter->hide(); onEffectShowActorFilterChanged(-1); // fill combobox } connect(m_model, &EffectShowModel::effectShowVehicleStatusChanged, this, &EffectShowEdit::onEffectShowVehicleStatusChanged); showEffectShow(); m_ui->dteFire->setWithNowButton(false); return true; } bool EffectShowEdit::apply() { // Send modified data via FTC call return m_requestHelper->startSingleRequest([this]() { m_effectShow.esmParticipantId(m_ui->cbEffectShowActor->currentData().toInt()); if (!m_isSmoke) { m_effectShow.numOfVolley(m_ui->sbVolley->value()); m_effectShow.shotsPerVolley(m_ui->sbShotsInTotal->value()); } return m_ftc->effectShowModifyRequest(m_effectShow, this); }); } void EffectShowEdit::showEffectShow() { m_ui->leName->setText(QString::fromStdString(m_effectShow.nameAreaEffectSimulation())); // get the vehicleStatus to set the correct entry for the cbEffectShowActorFilter EffectShowVehicleStatus vehicleStatus; const int equipmentNumber = m_ppmDtc->equipmentNumberByParticipantId(m_effectShow.esmParticipantId()); m_model->getVehicleStatus(equipmentNumber, vehicleStatus); const int feature = m_ui->cbEffectShowActorFilter->findData(vehicleStatus.feature().underlying()); switch (feature) { case EffectShowManagement::Feature_e::Explosion24: case EffectShowManagement::Feature_e::NotSpecified: m_ui->cbEffectShowActorFilter->setCurrentIndex(feature); break; default: m_ui->cbEffectShowActorFilter->setCurrentIndex(1); // set default SmokeAndExplosion48 (DMF-Fz) break; } if (m_effectShow.esmParticipantId() > 0) m_ui->cbEffectShowActor->setCurrentIndex(m_ui->cbEffectShowActor->findData(m_effectShow.esmParticipantId())); if (m_isSmoke) //smoke { m_ui->sbVolley->hide(); m_ui->lblVolley->hide(); m_ui->sbShotsInTotal->hide(); m_ui->lblShots->hide(); } else { m_ui->lblVolley->setText(tr("Volley:")); m_ui->lblShots->setText(tr("Shots in Total:")); m_ui->sbVolley->setValue(m_effectShow.numOfVolley()); m_ui->sbShotsInTotal->setValue(m_effectShow.shotsPerVolley()); } m_ui->dteFire->setMsecsSinceEpoch(m_effectShow.startTime().is_set() ? m_effectShow.startTime().get() : 0); m_ui->leRemainingAmmunition->setText(m_model->getParticipantAmmunition(m_effectShow.esmParticipantId())); connect(m_ui->cbEffectShowActor, static_cast(&QComboBox::currentIndexChanged), this, [this]() { m_ui->leRemainingAmmunition->setText(m_model->getParticipantAmmunition(m_ui->cbEffectShowActor->currentData().toInt())); }); } void EffectShowEdit::updateActorComboBox(const Core::GeoPosition &coordGeo) { bool ok; int esmParticipantId = m_ui->cbEffectShowActor->currentData().toInt(&ok); DEBUG_LOG(m_logger) << "currentIndex: " << m_ui->cbEffectShowActor->currentIndex() << ", currentText: " << m_ui->cbEffectShowActor->currentText() << ", esmParticipantId: " << esmParticipantId << ", ok: " << ok; int featureFilter = m_ui->cbEffectShowActorFilter->currentData().toInt(); m_esmActorCbx->fillActorComboBox(m_ui->cbEffectShowActor, coordGeo, m_isSmoke, featureFilter); m_ui->cbEffectShowActor->setCurrentIndex(m_ui->cbEffectShowActor->findData(esmParticipantId)); } void EffectShowEdit::onEffectShowActorFilterChanged(const int &idx) { Q_UNUSED(idx); const Core::GeoPosition coordGeo(m_effectShow.position().lon(), m_effectShow.position().lat(), 0); updateActorComboBox(coordGeo); // int selectedParticipantId = -1; // if (m_ui->cbEffectShowActor->currentIndex() > 0) // selectedParticipantId = m_ui->cbEffectShowActor->currentData().toInt(); // m_ui->cbEffectShowActor->clear(); // m_ui->cbEffectShowActor->addItem(QLatin1String("---"), 0); // int currentIndex = 1; // value at 0 is "---" // const int filter = m_ui->cbEffectShowActorFilter->currentData().toInt(); // //const auto actors = m_model->getParticipantList(m_isSmoke); // const auto actors = m_model->getParticipantListByDistance(m_isSmoke, m_effectShow.position()); // for (auto it = actors.begin(); it != actors.end(); ++it) // { // if (!m_isSmoke) // { // auto iParticipant = m_model->getEffectShowActorModel()->getIt(it->first); // if (iParticipant == m_model->getEffectShowActorModel()->getItEnd()) // continue; // if (!iParticipant->equipmentNumber().is_set()) // continue; // if (!m_model->getEffectShowActorModel()->isMatchedByFilter(iParticipant->equipmentNumber().get(), filter)) // continue; // } // if // m_ui->cbEffectShowActor->addItem(it->second, it->first); // if (selectedParticipantId == it->first) // m_ui->cbEffectShowActor->setCurrentIndex(currentIndex); // ++currentIndex; // } // for } void EffectShowEdit::onEffectShowVehicleStatusChanged(const EffectShowVehicleStatus &data, const DataModification &modType) { Q_UNUSED(modType); int equipmentNumber = m_ppmDtc->equipmentNumberByParticipantId(data.esmParticipantId()); const int filter = m_ui->cbEffectShowActorFilter->currentData().toInt(); if (m_model->getEffectShowActorModel()->isMatchedByFilter(equipmentNumber, filter)) onEffectShowActorFilterChanged(-1); } } // namespace EffectShowManagement