Files
qt5-legatus-legacy/Lts/Plugins/InfrastructureManagement/Gui/ResourceManagement/ism_plan_dialog_model.cpp
T
2026-08-13 18:33:10 +02:00

113 lines
3.2 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Plans Overview Dialog Model
* $Id$
* $HeadURL$
* $Author$
*
* Created by Mike Wille, SLSE, 2016-11-02
*/
#include <InfrastructureManagement/ism_translation.h>
#include <ngltools/ngltools_dtg.h>
#include "ism_plan_dialog_model.h"
namespace InfrastructureManagement
{
PlanDialogModel::PlanDialogModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<MainSchedule>({tr("Plan Id"),
tr("Name"),
tr("Status"),
tr("Created"),
tr("Begin"),
tr("End"),
tr("Complete")},
parent)
, m_dtc(nullptr)
, m_logger(getLogger("PlanDialogModel"))
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
}
PlanDialogModel::~PlanDialogModel()
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
}
bool PlanDialogModel::initModel(const std::shared_ptr<Interface::Dtc> &dtc)
{
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
m_dtc = dtc;
connect(m_dtc.get(), &Interface::Dtc::mainScheduleChanged, this, &PlanDialogModel::onDataChanged);
m_dtc->mainSchedules([this](const MainSchedule &ms){ onDataChanged(ms, DataModification::eAdded); });
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
return true;
}
QVariant PlanDialogModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index)) //role != Qt::DisplayRole ||
return QVariant();
const MainSchedule &ms = m_vecData.at(index.row());
if (role == Qt::DecorationRole)
{
static const QIcon green(QLatin1String("icon:green_light.svg"));
static const QIcon red(QLatin1String("icon:red_light.svg"));
if (index.column() == PlanDialogModel::Columns::COMPLETE)
{
// since checkSchedule could be timeconsuming, perform only if needed:
bool isComplete = m_dtc->checkSchedule(ms.id());
return (isComplete ? green : red);
}
}
else if (role == Qt::TextColorRole)
{
if (index.column() == PlanDialogModel::Columns::STATUS)
{
switch (ms.statusId().underlying())
{
case ScheduleStatus::Active:
return QColor(Qt::darkGreen);
case ScheduleStatus::Inactive:
return QColor(Qt::red);
}
}
}
else if (role == Qt::DisplayRole)
{
switch (index.column())
{
case ID:
return ms.id();
case NAME:
return QString::fromStdString(ms.name());
case STATUS:
return toString(ms.statusId());
case CREATED:
return DTG::toStringMSec(ms.timeCreated());
case START:
return (ms.timeStart().is_set() ? DTG::toStringMSec(ms.timeStart().get()) : QVariant()) ;
case END:
return (ms.timeEnd().is_set() ? DTG::toStringMSec(ms.timeEnd().get()) : QVariant());
case COMPLETE:
{
// since checkSchedule could be timeconsuming, perform only if needed:
bool isComplete = m_dtc->checkSchedule(ms.id());
return (isComplete ? tr("Yes") : tr("No"));
}
}
}
return QVariant();
}
}