101 lines
2.5 KiB
C++
Executable File
101 lines
2.5 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* OperatorManagement - Operator Change Password (Frameless) Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Malte Diers, SLSE, 2017-10-11
|
|
*/
|
|
|
|
#include "participant_search_modal.h"
|
|
#include "ui_participant_search_modal.h"
|
|
#include <LtsSession/lts_session_data_dds.h>
|
|
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
|
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
|
|
ParticipantSearchModal::ParticipantSearchModal(QWidget *parent)
|
|
: LtsWidgets::LtsFramelessDialog(parent)
|
|
, m_ui(new Ui::ParticipantSearchModal)
|
|
{
|
|
m_ui->setupUi(this);
|
|
connect(m_ui->pbCancel, &QPushButton::clicked, this, &ParticipantSearchModal::reject);
|
|
connect(m_ui->pbOk, &QPushButton::clicked, this, &ParticipantSearchModal::onOkay);
|
|
}
|
|
|
|
ParticipantSearchModal::~ParticipantSearchModal()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
bool ParticipantSearchModal::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc)
|
|
{
|
|
if (!dtc)
|
|
return false;
|
|
|
|
auto cb = [this](const Participant &data)
|
|
{
|
|
if (!data.equipmentNumber().is_set())
|
|
return;
|
|
const int newEqId = data.equipmentNumber().get();
|
|
m_partId2EqId[data.id()] = newEqId;
|
|
m_eqId2PartId[newEqId] = data.id();
|
|
};
|
|
dtc->participants(cb);
|
|
connect(dtc.get(), &Interface::Dtc::participantChanged,
|
|
this, &ParticipantSearchModal::onParticipantChanged);
|
|
|
|
return true;
|
|
}
|
|
|
|
void ParticipantSearchModal::showEvent(QShowEvent *e)
|
|
{
|
|
LtsWidgets::LtsFramelessDialog::showEvent(e);
|
|
m_ui->leEquipmentNo->clear();
|
|
m_ui->leEquipmentNo->setFocus();
|
|
}
|
|
|
|
void ParticipantSearchModal::onOkay()
|
|
{
|
|
int participantId = m_eqId2PartId.value(m_ui->leEquipmentNo->text().toInt());
|
|
if (participantId > 0)
|
|
emit participantSelected(participantId);
|
|
|
|
close();
|
|
}
|
|
|
|
void ParticipantSearchModal::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
|
|
{
|
|
const int newEqId = data.equipmentNumber().is_set() ? data.equipmentNumber().get() : 0;
|
|
switch (modType)
|
|
{
|
|
case DataModification::eAdded:
|
|
case DataModification::eModified:
|
|
{
|
|
const int oldEqId = m_partId2EqId.value(data.id());
|
|
if (oldEqId == newEqId)
|
|
return;
|
|
if (oldEqId != 0)
|
|
m_eqId2PartId.remove(oldEqId);
|
|
if (newEqId == 0)
|
|
return;
|
|
m_partId2EqId[data.id()] = newEqId;
|
|
m_eqId2PartId[newEqId] = data.id();
|
|
break;
|
|
}
|
|
case DataModification::eRemoved:
|
|
{
|
|
const int oldEqId = m_partId2EqId.value(data.id());
|
|
m_partId2EqId.remove(data.id());
|
|
if (oldEqId != 0)
|
|
m_eqId2PartId.remove(oldEqId);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
} // namespace
|