Files
qt5-legatus-legacy/Lts/Plugins/AlarmManagement/Gui/ConfigParticipantAlarm/alm_participant_model.cpp
T
2026-08-13 18:33:10 +02:00

80 lines
2.6 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Model for ParticipantsMoveDialog
* $Id$
* $HeadURL$
* $Author$
* Created by Gerlinde Rudolphus, SLSE, 2018-01-02
*/
#include "alm_participant_model.h"
#include <AlarmManagement/logger.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
namespace ParticipantAlarms
{
//----------------------------------------------------------------------------
ParticipantAlarmModel::ParticipantAlarmModel(QObject *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
: ParticipantManagement::ParticipantEditModel(parent, ppmDtc, asbIfc)
, m_logger(AlarmManagement::getLogger("ParticipantAlarmModel"))
{
m_titles += tr("Alarm Assignable");
DEBUG_LOG(m_logger) << "ParticipantAlarmModel::ParticipantAlarmModel";
}
QVariant ParticipantAlarmModel::data(const QModelIndex &index, int role) const
{
// ColSimulated is the last column
if (role == Qt::DisplayRole && index.column() == columnCount() - 1)
{
bool bIsSimulated = false;
if (!isSelectableByAlarm(index, &bIsSimulated))
return QVariant();
return !bIsSimulated ? tr("Yes") : tr("No");
}
return ParticipantManagement::ParticipantEditModel::data(index, role);
}
void ParticipantAlarmModel::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
{
Q_UNUSED(modType);
if (data.partyId() != partyId())
return;
INFO_LOG(m_logger) << "onParticipantChanged isSimulated=" << data.isSimulated();
onReinitModel(partyId());
emit newData();
}
bool ParticipantAlarmModel::isSelectableByAlarm(const QModelIndex &index, bool *bIsSimulated) const
{
bool isSimulatable = false;
const ParticipantManagement::ParticipantData data(getParticipantData(index));
if ((data.equipmentNumber().is_set() && data.equipmentNumber().get() > 0) ||
m_dtc->type(data.typeId()).typeClass() == ParticipantManagement::TypeClass_def::Unit)
isSimulatable = true;
DEBUG_LOG(m_logger) << "ParticipantId: " << data.id()
<< " isSimulated:" << data.isSimulated()
<< " equipmentNo:" << data.equipmentNumber()
<< " typeId=" << data.typeId()
<< " modId=" << data.modId()
<< " typeClass=" << m_dtc->type(data.typeId()).typeClass()
<< " isSimulatable=" << isSimulatable;
if (bIsSimulated)
*bIsSimulated = data.isSimulated();
return isSimulatable;
}
} // namespace ParticipantAlarms