Initial commit

This commit is contained in:
torsten committed 2026-08-13 18:33:10 +02:00
commit b7d90b9afe
16245 files changed
+3396666

No files matched your search

@@ -0,0 +1,107 @@
/**
* @RDE_HEADER@
* HMI Plugin for ExerciseManangement - Exercise Overview Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2018-03-17
*/
#include "obd_ex_model.h"
#include <ngltools/ngltools_dtg.h>
#include <QJsonObject>
namespace OcBaseDownload
{
//---------------------------------
// ExModel
//---------------------------------
ExModel::ExModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<ExerciseManagement::Exercise>({tr("Name"),
tr("Begin"),
tr("End"),
tr("Description"),
QStringLiteral("Id")},
parent)
, m_logger(getLogger("ExModel"))
{}
void ExModel::addExercise(const QJsonObject &exercise)
{
// ERROR_LOG(m_logger) << "Got Exercise" << exercise;
ExerciseManagement::Exercise ex;
ex.name(exercise.value(QLatin1String("name")).toString().toStdString());
ex.beginTime(exercise.value(QLatin1String("beginTime")).toDouble());
ex.endTime(exercise.value(QLatin1String("endTime")).toDouble());
ex.defaultTimeZone(exercise.value(QLatin1String("timeZone")).toString().toStdString().c_str()[0]);
ex.startTime(exercise.value(QLatin1String("startTime")).toDouble());
ex.stopTime(exercise.value(QLatin1String("stopTime")).toDouble());
ex.state(static_cast<ExerciseManagement::ExerciseState::inner_enum>(exercise.value(QLatin1String("status")).toInt()));
ex.description(exercise.value(QLatin1String("description")).toString().toStdString());
ex.id(exercise.value(QLatin1String("id")).toInt());
ex.trainingAreaId(exercise.value(QLatin1String("trainingAreaId")).toInt());
//add to model
if (ex.id() > 0 && (ex.state() == ExerciseManagement::ExerciseState::Started || ex.state() == ExerciseManagement::ExerciseState::Paused ) )
insertRow(ex);
}
QVariant ExModel::data(const QModelIndex &index, int role) const
{
if (role != Qt::DisplayRole || !indexIsValid(index))
return QVariant();
const ExerciseManagement::Exercise &ex = m_vecData.at(index.row());
switch (index.column())
{
case ExModel::Columns::Name:
return QString::fromStdString(ex.name());
case ExModel::Columns::Begin:
return QDateTime::fromMSecsSinceEpoch(ex.beginTime());
case ExModel::Columns::End:
return QDateTime::fromMSecsSinceEpoch(ex.endTime());
case ExModel::Columns::Description:
return QString::fromStdString(ex.description());
case ExModel::Columns::Id:
return ex.id();
}
return QVariant();
}
void ExProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
m_sourceModel = qobject_cast<ExModel*>(sourceModel);
LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel);
}
bool ExProxyModel::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 ExModel::Begin:
return dataLeft.beginTime() < dataRight.beginTime();
case ExModel::End:
return dataLeft.endTime() < dataRight.endTime();
case ExModel::Name:
case ExModel::Description:
case ExModel::Id:
break;
}
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
}
} // namespace ExerciseManagement