102 lines
2.9 KiB
C++
Executable File
102 lines
2.9 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Enhanced Participant Edit Model - show participant structure at specific time point
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2018-02-15
|
|
*/
|
|
|
|
#include "participant_time_point_model.h"
|
|
|
|
#include <QDateTime>
|
|
#include <QTimer>
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
|
|
//----------------------------------------------------------------------------
|
|
ParticipantTimePointModel::ParticipantTimePointModel(QObject *parent,
|
|
const std::shared_ptr<Interface::Dtc> &ppmDtc,
|
|
const std::shared_ptr<Interface::Ftc> &ppmFtc,
|
|
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
|
|
: ParticipantEditModel(parent, ppmDtc, asbIfc)
|
|
, m_requestTimer(new QTimer(this))
|
|
, m_currentTimePoint(0)
|
|
, m_csTimePointModel(Qt::Unchecked)
|
|
, m_ppmFtc(ppmFtc)
|
|
{
|
|
m_requestTimer->setSingleShot(true);
|
|
m_requestTimer->setInterval(50);
|
|
connect(m_requestTimer, &QTimer::timeout, this, &ParticipantTimePointModel::startRequest);
|
|
m_requestHelper.setQuiet(true);
|
|
}
|
|
|
|
void ParticipantTimePointModel::setTimePoint(qint64 tp)
|
|
{
|
|
if (m_currentTimePoint == tp)
|
|
return;
|
|
m_currentTimePoint = tp;
|
|
m_requestTimer->start();
|
|
}
|
|
|
|
bool ParticipantTimePointModel::onReinitModel(int partyId, const QSet<int> &checkedParticipants, Qt::CheckState cs)
|
|
{
|
|
if (m_partyId == partyId)
|
|
return true;
|
|
|
|
m_partyId = partyId;
|
|
m_partyColor = QColor::fromRgb(QRgb(m_dtc->party(m_partyId).color()));
|
|
|
|
m_checkedParticipantsTimepointModel = checkedParticipants;
|
|
m_csTimePointModel = cs;
|
|
|
|
m_requestTimer->start();
|
|
return true;
|
|
}
|
|
|
|
void ParticipantTimePointModel::startRequest()
|
|
{
|
|
ParticipantManagement::GetParticipantsRequest req;
|
|
req.partyId(partyId());
|
|
req.timeStamp(m_currentTimePoint);
|
|
|
|
m_requestHelper.startSingleRequest([this, req]() { return m_ppmFtc->getParticipantsRequest(req, this); });
|
|
}
|
|
|
|
void ParticipantTimePointModel::onGetParticipantsReply(const GetParticipantsReply &reply)
|
|
{
|
|
m_requestHelper.requestReply(reply);
|
|
|
|
NGLTreeModel::resetModel();
|
|
|
|
QHash<int, ParticipantData> tmap;
|
|
QHash<int, QSet<int>> parentId2id;
|
|
tmap.reserve(reply.participants().size());
|
|
parentId2id.reserve(reply.participants().size());
|
|
|
|
for (const auto &part : reply.participants())
|
|
{
|
|
if (part.isDeleted())
|
|
continue;
|
|
|
|
if (part.partyId() != m_partyId)
|
|
continue;
|
|
|
|
// parentId -> id for lookup
|
|
parentId2id[part.superiorId()] += part.id();
|
|
|
|
tmap.insert(part.id(), m_dtc->convertParticipantToParticipantData(part));
|
|
};
|
|
|
|
// insert recursivly
|
|
insertChildrenOf(0, m_rootItem, QModelIndex(), parentId2id, tmap, m_checkedParticipantsTimepointModel, m_csTimePointModel);
|
|
|
|
// unset modifed flag
|
|
resetModifedFlag(m_rootItem);
|
|
|
|
emit participantDataChanged();
|
|
}
|
|
|
|
} //namespace ParticipantManagement
|