425 lines
12 KiB
C++
Executable File
425 lines
12 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* GUI Plugin for ParticipantManagement - ParticipantFollowDialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-06-13
|
|
*/
|
|
|
|
#include "participant_follow_dialog.h"
|
|
#include "ui_participant_follow_dialog.h"
|
|
#include <AdvancedSymbology/asb_data_plugin_interface.h>
|
|
#include <QTimer>
|
|
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
int ParticipantFollowDialog::s_preselectedParty = -1;
|
|
bool ParticipantFollowDialog::s_preselectedAllParticipants = true;
|
|
|
|
ParticipantFollowDialog::ParticipantFollowDialog(QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_model(nullptr)
|
|
, m_equipNo(0)
|
|
, m_dtc(nullptr)
|
|
, m_ppmCbxIfc(nullptr)
|
|
, m_ui(new Ui::ParticipantFollowDialog)
|
|
, m_followParticipantId(-1)
|
|
, m_followEquipmentNo(-1)
|
|
, m_logger(getLogger("ParticipantFollowDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->leEquipNo->setValidator(new QIntValidator(0, 100000, m_ui->leEquipNo));
|
|
setUnchangeable();
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &ParticipantFollowDialog::onStartFollowClicked);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &ParticipantFollowDialog::onStopFollowClicked);
|
|
|
|
m_updateObjectIndicator = new QTimer(this);
|
|
m_updateObjectIndicator->setSingleShot(true);
|
|
m_updateObjectIndicator->setInterval(100);
|
|
connect(m_updateObjectIndicator, &QTimer::timeout, this, &ParticipantFollowDialog::updateObjectIndicator);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Find_Participant"));
|
|
}
|
|
|
|
ParticipantFollowDialog::~ParticipantFollowDialog()
|
|
{
|
|
if (m_sitMapGuiIfc)
|
|
m_sitMapGuiIfc->removeObjectIndicator();
|
|
|
|
delete m_ui;
|
|
}
|
|
|
|
void ParticipantFollowDialog::retranslate()
|
|
{
|
|
translate(m_ui, tr("Participant Follow"));
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setText(tr("Start Follow Participant on Map"));
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setText(tr("Stop Follow Participant on Map"));
|
|
}
|
|
|
|
bool ParticipantFollowDialog::init(LtsSession::LtsSession *session,
|
|
const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<ForeignParticipantInfoGuiInterface> &ppmGuiIfc)
|
|
{
|
|
DEBUG_LOG(m_logger) << "ParticipantFollowDialog::init";
|
|
m_dtc = dtc;
|
|
m_ppmGuiIfc = ppmGuiIfc;
|
|
enadisa();
|
|
|
|
if (!m_dtc)
|
|
return false;
|
|
|
|
if (!session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmCbxIfc))
|
|
return false;
|
|
|
|
if (!session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(m_sitMapGuiIfc))
|
|
return false;
|
|
|
|
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asbIfc;
|
|
session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asbIfc);
|
|
|
|
m_ui->cbAll->setChecked(s_preselectedAllParticipants);
|
|
|
|
m_model = new ParticipantEditModel(this, m_dtc, asbIfc);
|
|
m_ui->tvParticipants->setModel(m_model);
|
|
|
|
connect(m_ui->cbParty,
|
|
static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
|
|
this, &ParticipantFollowDialog::changeParty);
|
|
|
|
QItemSelectionModel *selectionModel = m_ui->tvParticipants->selectionModel();
|
|
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
|
this, &ParticipantFollowDialog::slotLookup);
|
|
|
|
connect(m_ui->tvParticipants, &QTreeView::doubleClicked,
|
|
this, &ParticipantFollowDialog::onDoubleClicked);
|
|
|
|
connect(m_ui->slEquipmentNumber, &QSlider::valueChanged, this, &ParticipantFollowDialog::slotLookup);
|
|
connect(m_ui->pbLookup, &QPushButton::clicked, this, &ParticipantFollowDialog::slotLookup);
|
|
connect(m_ui->leEquipNo, &QLineEdit::returnPressed, this, &ParticipantFollowDialog::slotLookup);
|
|
connect(m_ui->cbAll, &QCheckBox::toggled, this, &ParticipantFollowDialog::changeParty);
|
|
|
|
m_ppmCbxIfc->fillPartyComboBox(m_ui->cbParty, ForeignGuiComboboxInterface::CbxPartyFilter::All);
|
|
const int idx = m_ui->cbParty->findData(s_preselectedParty);
|
|
if (idx >= 0)
|
|
m_ui->cbParty->setCurrentIndex(idx);
|
|
|
|
changeParty();
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(false);
|
|
|
|
enadisa();
|
|
return true;
|
|
}
|
|
|
|
void ParticipantFollowDialog::setFollower(const int equipmentNumber, const int participantId)
|
|
{
|
|
m_followEquipmentNo = equipmentNumber;
|
|
m_followParticipantId = participantId;
|
|
}
|
|
|
|
void ParticipantFollowDialog::slotLookup()
|
|
{
|
|
//block all signals here
|
|
QSignalBlocker blx2(m_ui->slEquipmentNumber);
|
|
QSignalBlocker blx3(m_ui->leEquipNo);
|
|
|
|
//set sliderposition to current value
|
|
int newEquipNo = -1;
|
|
|
|
if (qobject_cast<QSlider *>(sender()))
|
|
newEquipNo = changeLabelText(m_ui->slEquipmentNumber->value());
|
|
if (qobject_cast<QLineEdit *>(sender()) ||
|
|
qobject_cast<QPushButton *>(sender()))
|
|
{
|
|
//get Number from
|
|
newEquipNo = m_ui->leEquipNo->text().toInt();
|
|
}
|
|
if (qobject_cast<QItemSelectionModel *>(sender()))
|
|
{
|
|
newEquipNo = onSelectionChanged();
|
|
//selection cleared (do we allow a deselct?)
|
|
// if (newEquipNo < 0 )
|
|
// {
|
|
// m_equipNo = newEquipNo;
|
|
// return;
|
|
// }
|
|
}
|
|
|
|
if (newEquipNo == m_equipNo)
|
|
return;
|
|
|
|
m_equipNo = newEquipNo;
|
|
|
|
//set Label and update lineEdit
|
|
if (m_equipNo > 0)
|
|
m_ui->leEquipNo->setText(QString::number(m_equipNo));
|
|
changeSliderPosition(m_equipNo);
|
|
|
|
//finally enable show button if found
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(m_participantMap.contains(m_equipNo));
|
|
|
|
//function for itemselection
|
|
auto cb = [this](const QModelIndex & idx)
|
|
{
|
|
m_ui->tvParticipants->setCurrentIndex(idx);
|
|
};
|
|
auto it = m_participantMap.find(m_equipNo);
|
|
if (it == m_participantMap.end() && !qobject_cast<QItemSelectionModel *>(sender()))
|
|
{
|
|
m_ui->tvParticipants->setCurrentIndex(QModelIndex());
|
|
return;
|
|
}
|
|
m_model->selectItemByParticipantId(it.value(), cb);
|
|
|
|
|
|
// update ObjectIndicator:
|
|
if (m_updateObjectIndicator)
|
|
m_updateObjectIndicator->start(); // start is restart
|
|
}
|
|
|
|
void ParticipantFollowDialog::updateObjectIndicator()
|
|
{
|
|
if (!m_sitMapGuiIfc)
|
|
return;
|
|
|
|
int participantId = m_participantMap.value(m_equipNo, -1);
|
|
|
|
if (participantId >= 0)
|
|
m_sitMapGuiIfc->objectIndicatorToParticipant(participantId);
|
|
else
|
|
m_sitMapGuiIfc->removeObjectIndicator();
|
|
enadisa();
|
|
}
|
|
|
|
void ParticipantFollowDialog::enterEvent(QEvent *e)
|
|
{
|
|
BaseClass::enterEvent(e);
|
|
updateObjectIndicator();
|
|
}
|
|
|
|
void ParticipantFollowDialog::leaveEvent(QEvent *e)
|
|
{
|
|
BaseClass::leaveEvent(e);
|
|
// to early, remove obj at dtor
|
|
// if (m_sitMapGuiIfc)
|
|
// m_sitMapGuiIfc->removeObjectIndicator();
|
|
}
|
|
|
|
|
|
//private
|
|
|
|
int ParticipantFollowDialog::onSelectionChanged()
|
|
{
|
|
QModelIndex index = m_ui->tvParticipants->currentIndex();
|
|
|
|
//finally enable show button
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(true);
|
|
|
|
ParticipantManagement::ParticipantData data;
|
|
data = m_model->getParticipantData(index);
|
|
if (!data.equipmentNumber().is_set())
|
|
return -1;
|
|
|
|
enadisa();
|
|
return data.equipmentNumber().get();
|
|
}
|
|
|
|
void ParticipantFollowDialog::onDoubleClicked()
|
|
{
|
|
QModelIndex index = m_ui->tvParticipants->currentIndex();
|
|
|
|
ParticipantManagement::ParticipantData data;
|
|
data = m_model->getParticipantData(index);
|
|
m_followParticipantId = data.id();
|
|
m_followEquipmentNo = getEquipmentNumber(m_followParticipantId);
|
|
enadisa();
|
|
DEBUG_LOG(m_logger) << "onDoubleClicked follow Participant Id =" << m_followParticipantId
|
|
<< " m_followEquipmentNo=" << m_followEquipmentNo;
|
|
}
|
|
|
|
void ParticipantFollowDialog::clearSelections()
|
|
{
|
|
changeSliderPosition(-1);
|
|
m_ui->leEquipNo->clear();
|
|
m_equipNo = 0;
|
|
m_ui->tvParticipants->setCurrentIndex(QModelIndex());
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Show)->setEnabled(false);
|
|
}
|
|
|
|
//Slots
|
|
void ParticipantFollowDialog::changeParty()
|
|
{
|
|
s_preselectedAllParticipants = m_ui->cbAll->isChecked();
|
|
if (m_ui->cbAll->isChecked())
|
|
{
|
|
m_ui->cbParty->setEnabled(false);
|
|
m_ui->tvParticipants->setEnabled(false);
|
|
m_model->resetModel();
|
|
fillMapFromDtc();
|
|
}
|
|
else
|
|
{
|
|
m_ui->cbParty->setEnabled(true);
|
|
m_ui->tvParticipants->setEnabled(true);
|
|
int partyId = m_ui->cbParty->currentData().toInt();
|
|
s_preselectedParty = partyId;
|
|
m_model->onReinitModel(partyId);
|
|
m_ui->tvParticipants->expandAll();
|
|
fillParticipantMapFromTree();
|
|
}
|
|
|
|
m_ui->slEquipmentNumber->setRange(0, m_participantMap.size() - 1);
|
|
clearSelections();
|
|
}
|
|
|
|
void ParticipantFollowDialog::fillMapFromDtc()
|
|
{
|
|
m_participantMap.clear();
|
|
auto cb = [this](const Participant & data)
|
|
{
|
|
if (data.equipmentNumber().is_set())
|
|
m_participantMap.insert(data.equipmentNumber().get(), data.id());
|
|
};
|
|
m_dtc->participants(cb);
|
|
}
|
|
|
|
int ParticipantFollowDialog::changeLabelText(int value)
|
|
{
|
|
if (value < 0 || value >= m_participantMap.size())
|
|
return -1;
|
|
|
|
auto it = m_participantMap.begin();
|
|
it += value;
|
|
int newEqNr = it.key();
|
|
|
|
m_ui->lblEquipmentNumber->setText(QString::number(newEqNr));
|
|
m_ui->leEquipNo->setText(QString::number(newEqNr));
|
|
return newEqNr;
|
|
}
|
|
|
|
void ParticipantFollowDialog::changeSliderPosition(int equipNo)
|
|
{
|
|
int i = 0;
|
|
int pos = -1;
|
|
for (auto it = m_participantMap.cbegin(); it != m_participantMap.cend(); ++it)
|
|
{
|
|
if (equipNo == it.key())
|
|
{
|
|
pos = i;
|
|
break;
|
|
}
|
|
i++;
|
|
}
|
|
|
|
if (pos >= 0)
|
|
{
|
|
m_ui->lblEquipmentNumber->setText(QString::number(equipNo));
|
|
m_ui->slEquipmentNumber->setSliderPosition(pos);
|
|
}
|
|
else
|
|
{
|
|
m_ui->slEquipmentNumber->setSliderPosition(-1);
|
|
m_ui->lblEquipmentNumber->setText(tr("Not found"));
|
|
}
|
|
}
|
|
|
|
void ParticipantFollowDialog::fillParticipantMapFromTree()
|
|
{
|
|
m_participantMap.clear();
|
|
|
|
fillParticipantMapFromTree(QModelIndex());
|
|
}
|
|
|
|
void ParticipantFollowDialog::fillParticipantMapFromTree(const QModelIndex &parent)
|
|
{
|
|
const int rc = m_model->rowCount(parent);
|
|
for (int row = 0; row < rc; ++row)
|
|
fillParticipantMapFromTree(m_model->index(row, 0, parent));
|
|
|
|
const ParticipantManagement::ParticipantData data(m_model->getParticipantData(parent));
|
|
if (data.equipmentNumber().is_set())
|
|
m_participantMap.insert(data.equipmentNumber().get(), data.id());
|
|
}
|
|
|
|
int ParticipantFollowDialog::getEquipmentNumber(const int participantId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "getEquipmentNumber(" << participantId << ")";
|
|
int equipmentNumber = 0;
|
|
|
|
QMapIterator<int, int> iter(m_participantMap);
|
|
|
|
while (iter.hasNext())
|
|
{
|
|
iter.next();
|
|
DEBUG_LOG(m_logger) << iter.key() << " : " << iter.value();
|
|
if (iter.value() == participantId)
|
|
{
|
|
DEBUG_LOG(m_logger) << "return: " << iter.key();
|
|
return (iter.key());
|
|
}
|
|
}
|
|
return equipmentNumber;
|
|
}
|
|
|
|
void ParticipantFollowDialog::onStartFollowClicked()
|
|
{
|
|
int participantId = m_participantMap.value(m_equipNo);
|
|
DEBUG_LOG(m_logger) << "Follow Participant id=" << participantId << " on Map";
|
|
|
|
if (!m_ui->cbAll->isChecked())
|
|
onDoubleClicked();
|
|
else
|
|
{
|
|
DEBUG_LOG(m_logger) << "Start Follow Participant id=" << participantId << " on Map";
|
|
m_followParticipantId = participantId;
|
|
m_followEquipmentNo = m_equipNo;
|
|
}
|
|
enadisa();
|
|
}
|
|
|
|
void ParticipantFollowDialog::onStopFollowClicked()
|
|
{
|
|
DEBUG_LOG(m_logger) << "Stop Follow Participant id=" << m_followParticipantId << " on Map";
|
|
m_followParticipantId = 0;
|
|
m_followEquipmentNo = 0;
|
|
enadisa();
|
|
}
|
|
|
|
void ParticipantFollowDialog::enadisa()
|
|
{
|
|
if (m_followParticipantId > 0)
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, true);
|
|
}
|
|
else if (m_followParticipantId == 0)
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, true);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
|
|
}
|
|
else
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
|
|
}
|
|
QString labelText = tr("Map follows");
|
|
|
|
QString equipNoStr = QString::number(m_followEquipmentNo);
|
|
labelText.append(QStringLiteral(": "));
|
|
labelText.append(m_dtc->hierarchyFromParticipant(m_followParticipantId));
|
|
if (m_followEquipmentNo > 0)
|
|
{
|
|
labelText.append(QStringLiteral(" ("));
|
|
labelText.append(equipNoStr);
|
|
labelText.append(QStringLiteral(")"));
|
|
}
|
|
m_ui->lbFollow->setText(labelText);
|
|
DEBUG_LOG(m_logger) << "labelText=" << labelText;
|
|
DEBUG_LOG(m_logger) << " m_ui->lbFollow->getText()" << m_ui->lbFollow->text();
|
|
DEBUG_LOG(m_logger) << "newFollowEquipment(" << m_followEquipmentNo << ", "
|
|
<< m_followParticipantId << ")";
|
|
emit newFollowEquipment(m_followEquipmentNo,m_followParticipantId );
|
|
}
|
|
} // namespace ParticipantManagement
|