169 lines
4.9 KiB
C++
Executable File
169 lines
4.9 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* PresentationManangement - Script Overview Dialog Model
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2017-03-15
|
|
*/
|
|
|
|
#include "evl_element_model.h"
|
|
|
|
#include <ngltools/ngltools_dtg.h>
|
|
#include <QDateTime>
|
|
#include <LtsUtilsCore/json_object.h>
|
|
#include <AudioVideoManagement/stream_name_mapping.h>
|
|
|
|
namespace Evaluations
|
|
{
|
|
|
|
ElementDialogModel::ElementDialogModel(QObject *parent)
|
|
: LtsWidgets::LtsAbstractTableModel<EvaluationElement>(
|
|
{
|
|
tr("Id"),
|
|
tr("Situation"),
|
|
tr("Video"),
|
|
tr("Audio"),
|
|
tr("Start Time"),
|
|
tr("Duration"),
|
|
tr("Rating"),
|
|
tr("Radio Circuit"),
|
|
tr("Video Channel"),
|
|
tr("Note"),
|
|
tr("Phase")
|
|
},
|
|
parent)
|
|
, m_logger(getLogger("ElementDialogModel"))
|
|
{}
|
|
|
|
bool ElementDialogModel::initModel(const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<ExerciseManagement::Interface::Dtc> &exmDtc,
|
|
const std::shared_ptr<AudioVideoManagement::ForeignDataInterface> &avmDataIfc,
|
|
int criteriumId)
|
|
{
|
|
m_exmDtc = exmDtc;
|
|
m_avmDataIfc = avmDataIfc;
|
|
|
|
connect(dtc.get(), &Interface::Dtc::evaluationElementChanged,
|
|
this, &ElementDialogModel::onDataChanged);
|
|
|
|
auto cb = [this, criteriumId](const EvaluationElement &e)
|
|
{
|
|
if (e.criteriumId() == criteriumId)
|
|
insertRow(e);
|
|
};
|
|
dtc->evaluationElements(cb);
|
|
|
|
INFO_LOG(m_logger) << "initModel - #EvalElements: " << m_vecData.size();
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
QVariant ElementDialogModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if ((role != Qt::DisplayRole) || !indexIsValid(index))
|
|
return QVariant();
|
|
|
|
const Evaluations::EvaluationElement &eval = m_vecData.at(index.row());
|
|
|
|
switch (index.column())
|
|
{
|
|
case Id:
|
|
return eval.id();
|
|
case Situation:
|
|
return eval.situation() ? tr("Yes") : tr("No");
|
|
case Video:
|
|
return eval.video() ? tr("Yes") : tr("No");
|
|
case Audio:
|
|
return eval.audio() ? tr("Yes") : tr("No");
|
|
case Timestamp:
|
|
return QDateTime::fromMSecsSinceEpoch(eval.timestamp());
|
|
case Duration:
|
|
return eval.duration();
|
|
case Rating:
|
|
return eval.rating();
|
|
case RadioCircuit:
|
|
if (eval.audioContent().is_set())
|
|
{
|
|
LtsUtils::JsonObject jsonObj = LtsUtils::JsonObject::fromJson(eval.audioContent().get());
|
|
return jsonObj.value<QString>("actualStream");
|
|
}
|
|
else
|
|
return QString();
|
|
case VideoChannel:
|
|
if (eval.videoContent().is_set())
|
|
{
|
|
LtsUtils::JsonObject jsonObj = LtsUtils::JsonObject::fromJson(eval.videoContent().get());
|
|
QString streamName = jsonObj.value<QString>("actualStream");
|
|
QString displayName = m_avmDataIfc->streamNameMapping()->displayName(streamName);
|
|
return displayName;
|
|
}
|
|
else
|
|
return QString();
|
|
case Note:
|
|
return QString::fromStdString(eval.note());
|
|
case Phase:
|
|
return QString::fromStdString(m_exmDtc->exercisePhase(eval.phaseId()).name());
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
void ElementDialogProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
|
{
|
|
m_sourceModel = qobject_cast<ElementDialogModel*>(sourceModel);
|
|
LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel);
|
|
}
|
|
|
|
bool ElementDialogProxyModel::lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const
|
|
{
|
|
if (!m_sourceModel ||
|
|
source_left.column() != source_right.column() ||
|
|
!source_left.isValid() ||
|
|
!source_right.isValid())
|
|
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
|
const auto &dataLeft = m_sourceModel->m_vecData.at(source_left.row());
|
|
const auto dataRight = m_sourceModel->m_vecData.at(source_right.row());
|
|
switch (source_left.column())
|
|
{
|
|
case ElementDialogModel::Timestamp:
|
|
return dataLeft.timestamp() < dataRight.timestamp();
|
|
case ElementDialogModel::Id:
|
|
case ElementDialogModel::Situation:
|
|
case ElementDialogModel::Video:
|
|
case ElementDialogModel::Audio:
|
|
|
|
case ElementDialogModel::Duration:
|
|
case ElementDialogModel::Rating:
|
|
case ElementDialogModel::RadioCircuit:
|
|
case ElementDialogModel::VideoChannel:
|
|
case ElementDialogModel::Note:
|
|
case ElementDialogModel::Phase:
|
|
break;
|
|
}
|
|
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
|
}
|
|
|
|
void ElementDialogProxyModel::setCriteriumId(int criteriumId)
|
|
{
|
|
if (m_criteriumId == criteriumId)
|
|
return;
|
|
m_criteriumId = criteriumId;
|
|
invalidateFilter();
|
|
}
|
|
|
|
bool ElementDialogProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
|
|
{
|
|
if (m_criteriumId < 0 || !m_sourceModel || source_parent.isValid() || source_row < 0 || source_row >= m_sourceModel->m_vecData.size())
|
|
return LtsWidgets::LtsColumnFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
|
|
|
const auto &data = m_sourceModel->m_vecData.at(source_row);
|
|
if (data.criteriumId() != m_criteriumId)
|
|
return false;
|
|
return LtsWidgets::LtsColumnFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
|
}
|
|
|
|
} // namespace Evaluations
|