200 lines
6.5 KiB
C++
Executable File
200 lines
6.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* TargetManagement - Target Edit Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Norbert Thoden, NLE, 2020-05-29
|
|
*/
|
|
|
|
#include "tgt_shootback_target_edit.h"
|
|
#include "tgt_target_part_model.h"
|
|
#include "ui_tgt_shootback_target_edit.h"
|
|
|
|
#include <LtsUtilsSettings/settings.h>
|
|
|
|
#include <QBuffer>
|
|
|
|
namespace TargetManagement
|
|
{
|
|
|
|
ShootbackTargetEdit::ShootbackTargetEdit(QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_ui(new Ui::ShootbackTargetEdit)
|
|
, m_logger(getLogger("ShootbackTargetEdit"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
|
|
ShootbackTargetEdit::~ShootbackTargetEdit()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void ShootbackTargetEdit::retranslate()
|
|
{
|
|
translate(m_ui, m_target, tr("ShootbackTarget"));
|
|
}
|
|
|
|
bool ShootbackTargetEdit::init(const std::shared_ptr<TargetManagement::Interface::Dtc> &dtc,
|
|
const std::shared_ptr<TargetManagement::Interface::Ftc> &ftc,
|
|
TargetParticipantModel *targetParticipantModel,
|
|
const TargetManagement::ShootbackTarget &target)
|
|
{
|
|
DEBUG_LOG(m_logger) << "ShootbackTargetEdit::init()";
|
|
|
|
if (!dtc || !ftc)
|
|
{
|
|
ERROR_LOG(m_logger) << "ShootbackTargetEdit::init() Invalid shared_ptr!";
|
|
return false;
|
|
}
|
|
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
m_targetParticipantModel = targetParticipantModel;
|
|
setData(target);
|
|
|
|
initCmbParticipants();
|
|
connect(m_targetParticipantModel, &TargetParticipantModel::signalParticipantNamesChanged,
|
|
this, &ShootbackTargetEdit::initCmbParticipants);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Targets"));
|
|
// if (m_target.id() <= 0)
|
|
// slotChangesMade();
|
|
|
|
return true;
|
|
}
|
|
|
|
void ShootbackTargetEdit::initCmbParticipants()
|
|
{
|
|
m_ui->cmbParticipants->clear();
|
|
|
|
if (!m_targetParticipantModel)
|
|
return;
|
|
|
|
QSignalBlocker sb(m_ui->cmbParticipants); // pause tooltip update
|
|
|
|
m_ui->cmbParticipants->addItem(QStringLiteral("-"), 0); // to remove association
|
|
|
|
const auto hierarchies(m_targetParticipantModel->getParticipantHierarchies());
|
|
const auto decorations(m_targetParticipantModel->getParticipantDecorations());
|
|
for (auto it = hierarchies.begin(); it != hierarchies.end(); ++it)
|
|
{
|
|
const int participantId = it.key();
|
|
const QString hierarchy(it.value());
|
|
|
|
if (!m_targetParticipantModel->getAssociatedParticipantIds().contains(participantId) || m_target.targetParticipantId() == participantId)
|
|
{
|
|
const QPixmap &pm = decorations.value(participantId);
|
|
|
|
m_ui->cmbParticipants->addItem(QIcon(pm), hierarchy, participantId);
|
|
|
|
// Tooltip:
|
|
int idx = m_ui->cmbParticipants->findData(participantId);
|
|
QString tooltip(QStringLiteral("<html>"));
|
|
// without a temporary file:
|
|
QByteArray baData;
|
|
QBuffer buffer(&baData);
|
|
pm.save(&buffer, "PNG", 100);
|
|
tooltip.append(QStringLiteral("<center><img src='data:image/png;base64,%1'></center>").arg(QString::fromLatin1(baData.toBase64()))); // how can i center the image?
|
|
|
|
#ifndef LTS_DEBUG
|
|
if (QGuiApplication::keyboardModifiers().testFlag(Qt::KeyboardModifier::ShiftModifier))
|
|
#endif
|
|
tooltip.append(QStringLiteral("<center>id=%1</center>").arg(participantId));
|
|
|
|
tooltip.append(QStringLiteral("</html>"));
|
|
m_ui->cmbParticipants->setItemData(idx, tooltip, Qt::ToolTipRole);
|
|
}
|
|
}
|
|
|
|
int newIdx = m_ui->cmbParticipants->findData(m_target.targetParticipantId());
|
|
if (newIdx >= 0)
|
|
m_ui->cmbParticipants->setCurrentIndex(newIdx);
|
|
m_ui->cmbParticipants->model()->sort(0);
|
|
|
|
m_ui->cmbParticipants->setIconSize(QSize(50, 50));
|
|
connect(m_ui->cmbParticipants, QOverload<int>::of(&LtsWidgets::LtsComboBox::currentIndexChanged),
|
|
this, &ShootbackTargetEdit::onCmbParticipantsChanged, Qt::UniqueConnection);
|
|
onCmbParticipantsChanged();
|
|
}
|
|
|
|
//slots
|
|
void ShootbackTargetEdit::onCmbParticipantsChanged()
|
|
{
|
|
const auto decorations(m_targetParticipantModel->getParticipantDecorations());
|
|
int participantId = m_ui->cmbParticipants->currentData().toInt();
|
|
const auto it = decorations.find(participantId);
|
|
if (it != decorations.constEnd())
|
|
{
|
|
const QPixmap &pm = decorations.value(it.key());
|
|
{
|
|
QString tooltip(QStringLiteral("<html>"));
|
|
QByteArray data;
|
|
QBuffer buffer(&data);
|
|
// XML-Symbol with scale = 4 will produce huge images. Limit the size:
|
|
pm.save(&buffer, "PNG", 100);
|
|
|
|
tooltip += QStringLiteral("<center>");
|
|
tooltip += QStringLiteral("<img src='data:image/png;base64,%1'>").arg(QString::fromLatin1(data.toBase64()));
|
|
tooltip += QStringLiteral("</center>");
|
|
|
|
#ifndef LTS_DEBUG
|
|
if (QGuiApplication::keyboardModifiers().testFlag(Qt::KeyboardModifier::ShiftModifier))
|
|
#endif
|
|
tooltip.append(QStringLiteral("<center>id=%1</center>").arg(participantId));
|
|
|
|
tooltip += QStringLiteral("</html>");
|
|
m_ui->cmbParticipants->setToolTip(tooltip);
|
|
}
|
|
}
|
|
}
|
|
|
|
bool ShootbackTargetEdit::apply()
|
|
{
|
|
m_target.name(m_ui->leName->text().toStdString());
|
|
|
|
m_target.activateLaserDesignation(m_ui->cb_activateLaserDetection->isChecked());
|
|
m_target.activateLights(m_ui->cb_activateLights->isChecked());
|
|
m_target.activatePopupAutomatic(m_ui->cb_activatePopupAutomatic->isChecked());
|
|
m_target.permanentInstalledTarget(m_ui->cb_permanentInstalledTarget->isChecked());
|
|
m_target.hitsToKill(m_ui->sp_hitsToKill->value());
|
|
|
|
// selected participant:
|
|
int32_t participantId = m_ui->cmbParticipants->currentData().toInt();
|
|
m_target.targetParticipantId(participantId);
|
|
|
|
m_requestHelper->addRequest([this]()
|
|
{
|
|
return m_ftc->shootbackTargetModifyRequest(m_target, this);
|
|
});
|
|
|
|
return m_requestHelper->startRequests();
|
|
}
|
|
|
|
|
|
//private
|
|
|
|
void ShootbackTargetEdit::setData(const ShootbackTarget &target)
|
|
{
|
|
m_target = target;
|
|
|
|
m_ui->leName->setText(QString::fromStdString(m_target.name()));
|
|
|
|
m_ui->cb_activateLaserDetection->setChecked(m_target.activateLaserDesignation());
|
|
m_ui->cb_activateLights->setChecked(m_target.activateLights());
|
|
m_ui->cb_activatePopupAutomatic->setChecked(m_target.activatePopupAutomatic());
|
|
m_ui->cb_permanentInstalledTarget->setChecked(m_target.permanentInstalledTarget());
|
|
m_ui->sp_hitsToKill->setValue(m_target.hitsToKill());
|
|
|
|
// update combo box:
|
|
int newIdx = m_ui->cmbParticipants->findData(m_target.targetParticipantId());
|
|
if (newIdx >= 0)
|
|
m_ui->cmbParticipants->setCurrentIndex(newIdx);
|
|
}
|
|
|
|
}
|