Files
qt5-legatus-legacy/Lts/Plugins/ParticipantManagement/Gui/PartyEdit/ppm_party_model.cpp
T
torstenandCopilot 3028302f7b Qt6 Migration: Merge latest Qt5 devel content and apply migration fixes
- Merged 292 changed files from dlbo snapshot
- Fixed IDL enum collisions (PortType, PdmEventType)
- Fixed Grantlee template for C++11 scoped enums
- Fixed CMake VERSION_GREATER syntax
- Added missing directories (THP, LtsRestClient, etc.)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-09-15 18:20:51 +00:00

184 lines
6.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Party Overview Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#include "ppm_party_model.h"
#include <OperatorManagement/opm_data_plugin_interface.h>
#include <ParticipantManagement/ppm_data_plugin_interface.h>
#include <LtsSession/lts_session_data.h>
#include <ParticipantManagement/ppm_translation.h>
#include <QColor>
#include <QJsonDocument>
#include <QJsonObject>
namespace ParticipantManagement
{
//---------------------------------
// PartyModel
//---------------------------------
PartyModel::PartyModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>({tr("Id"),
tr("Name"),
tr("Color"),
tr("Faded Color"),
tr("Role"),
tr("Is Used"),
tr("Is SAA connected"),
tr("SAA Name"),
tr("Szenar Name")},
parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("PartyModel"))
{}
bool PartyModel::initModel(LtsSession::LtsSession *session)
{
m_session = session;
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger)<<" Couldn't load ppmDtc!!! ";
return false;
}
if (!m_session->getDtc<OperatorManagement::DataInterface>(m_opmDtc))
{
ERROR_LOG(m_logger)<<" Couldn't load opmDtc!!! ";
return false;
}
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::partyChanged ,
this, &PartyModel::onDataChanged);
m_operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
m_ppmDtc->partys([this](const ParticipantManagement::Party &party)
{
if (hasParty(party)) // opm_operator_exercise -> visible_parties
insertRow(party);
});
return true;
}
QVariant PartyModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index))
return QVariant();
const ParticipantManagement::Party &party = m_vecData.at(index.row());
if (role == Qt::BackgroundRole)
{
switch(index.column())
{
case Color:
return QColor::fromRgb(QRgb(party.color()));
case FadedColor:
return QColor::fromRgb(QRgb(party.fadingColor()));
}
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case Id:
return party.id();
case Name:
return ParticipantManagement::trPartyName(party.name());
case Color:
return QVariant();
case FadedColor:
return QVariant();
case Role:
return ParticipantManagement::toString(party.role());
case IsUsedBy:
return party.isUsedBy() ? tr("Yes") : tr("No");
case IsSaaConnected:
{
if ( party.properties().empty())
return false;
ParticipantManagement::ConnectState status = m_ppmDtc->saaConnectedState(party.id());
QString connectState;
switch (status.underlying())
{
case ParticipantManagement::ConnectState::Undefined:
connectState = QStringLiteral("");
break;
default:
connectState = ParticipantManagement::toString(status);
break;
}
return connectState;
}
case SaaName:
{
if ( party.properties().empty())
return QString{};
const QJsonObject properties(QJsonDocument::fromJson(QByteArray::fromStdString(party.properties())).object());
if (!properties.contains(QStringLiteral("Adler")) )
return QString{};
const QJsonObject adlerObj = properties[QStringLiteral("Adler")].toObject();
QString saaName;
if (adlerObj.contains(QStringLiteral("saaName")) )
saaName.append(adlerObj[QStringLiteral("saaName")].toString());
if (adlerObj.contains(QStringLiteral("isVerbund")) && !saaName.isEmpty())
saaName.append(QStringLiteral(" (") + (adlerObj[QStringLiteral("isVerbund")].toBool() ? tr("Verbund") : tr("Standalone")) + QStringLiteral(")"));
return saaName;
}
case SzenarName:
{
if ( party.properties().empty())
return QString{};
const QJsonObject properties(QJsonDocument::fromJson(QByteArray::fromStdString(party.properties())).object());
if (!properties.contains(QStringLiteral("Adler")) )
return QString{};
const QJsonObject adlerObj = properties[QStringLiteral("Adler")].toObject();
if (adlerObj.contains(QStringLiteral("szenarName")) )
return adlerObj[QStringLiteral("szenarName")].toString();
return QString{};
}
}
}
return QVariant();
}
bool PartyModel::hasParty(const Party &party) const
{
const auto visiblePartiesByExercise = m_opmDtc->user(m_operatorId).visiblePartiesByExercise();
for (const auto &exerciseParties : visiblePartiesByExercise)
{
if (exerciseParties.exerciseId() != m_session->exerciseId())
continue;
if (!exerciseParties.visibleParties().is_set()) //has_value not support on windows yet so we need depricated is_set
return false;
for (const auto &partyId : exerciseParties.visibleParties().get())
if (partyId == party.id())
return true;
return false;
}
return false;
}
bool PartyModel::isPartyHidden(const Party &party) const
{ const auto visiblePartiesByExercise = m_opmDtc->user(m_operatorId).visiblePartiesByExercise();
for (const auto &exerciseParties : visiblePartiesByExercise)
{
if (exerciseParties.exerciseId() != m_session->exerciseId())
continue;
if (!exerciseParties.hiddenParties().is_set()) //has_value not support on windows yet so we need depricated is_set
return false;
for (const auto &partyId : exerciseParties.hiddenParties().get())
if (partyId == party.id())
return true;
return false;
}
return false;
}
} // namespace ParticipantManagement