166 lines
5.4 KiB
C++
Executable File
166 lines
5.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* PresentationManangement - Script Overview Dialog Model
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*
|
|
* Created by Mike Wille, SLSE, 2017-03-15
|
|
*/
|
|
|
|
#include "pre_model.h"
|
|
|
|
#include <ngltools/ngltools_dtg.h>
|
|
#include <PresentationManagement/pre_translation.h>
|
|
|
|
#include <QGuiApplication>
|
|
#include <QPalette>
|
|
|
|
namespace PresentationManagement
|
|
{
|
|
PresentationManagementDialogModel::PresentationManagementDialogModel(QObject *parent)
|
|
: LtsWidgets::LtsAbstractTableModel<Presentation>({tr("Id"),
|
|
tr("Name"),
|
|
tr("Description"),
|
|
tr("Operator"),
|
|
tr("LastModified"),
|
|
tr("Status")},
|
|
parent)
|
|
, m_logger(getLogger("PresentationManagementDialogModel"))
|
|
{
|
|
}
|
|
|
|
|
|
PresentationManagementDialogModel::~PresentationManagementDialogModel()
|
|
{}
|
|
|
|
|
|
bool PresentationManagementDialogModel::initModel(const std::shared_ptr<Interface::Dtc> &dtc,
|
|
const std::shared_ptr<OperatorManagement::Interface::Dtc> &opmDtc,
|
|
const std::function<bool(const Presentation &)> &predicate)
|
|
{
|
|
m_opmDtc = opmDtc;
|
|
m_predicate = predicate;
|
|
connect(dtc.get(), &Interface::Dtc::presentationChanged,
|
|
this, &PresentationManagementDialogModel::onDataChanged);
|
|
dtc->presentations([this](const Presentation &p) { insertRow(p); m_scriptUsers.append(p.operatorId()); });
|
|
|
|
|
|
QMap<qint32, OperatorManagement::User> users = opmDtc->users();
|
|
m_users.clear();
|
|
for (auto it = users.constBegin(); it != users.constEnd(); ++it)
|
|
{
|
|
if (m_scriptUsers.contains(it->id()))
|
|
m_users.insert(static_cast<int>(it.value().id()), QString::fromStdString(it.value().name()));
|
|
}
|
|
|
|
INFO_LOG(m_logger) << "initModel - #presentations: " << m_vecData.size();
|
|
return true;
|
|
}
|
|
|
|
|
|
QVariant PresentationManagementDialogModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
{
|
|
if (role == LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole &&
|
|
orientation == Qt::Horizontal &&
|
|
section == Columns::Operator)
|
|
{
|
|
LtsWidgets::ComboboxFilterContent cfc;
|
|
cfc.data.reserve(m_users.size());
|
|
LtsWidgets::ComboboxFilterData cfd;
|
|
for (auto it = m_users.constBegin(); it != m_users.constEnd(); ++it)
|
|
{
|
|
cfd.data = it.key();
|
|
cfd.text = it.value();
|
|
cfc.data.push_back(cfd);
|
|
}
|
|
cfc.sortItems = true;
|
|
return cfc.toVariant();
|
|
}
|
|
else
|
|
return LtsAbstractTableModel::headerData(section, orientation, role);
|
|
}
|
|
|
|
QVariant PresentationManagementDialogModel::data(const QModelIndex &index, int role) const
|
|
{
|
|
if ((role != Qt::DisplayRole && role != Qt::BackgroundRole && role != LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole) ||
|
|
!indexIsValid(index))
|
|
return QVariant();
|
|
|
|
const PresentationManagement::Presentation &pre = m_vecData.at(index.row());
|
|
|
|
if (role == Qt::BackgroundRole)
|
|
{
|
|
if (pre.fileStatus() == PresentationManagement::FileStatus::Deleted)
|
|
return QGuiApplication::palette().color(QPalette::Disabled, QPalette::AlternateBase);
|
|
return QGuiApplication::palette().color(QPalette::Active, QPalette::Base);
|
|
}
|
|
|
|
if (role == Qt::DisplayRole)
|
|
{
|
|
switch (index.column())
|
|
{
|
|
case Id:
|
|
return pre.id();
|
|
case Name:
|
|
return QString::fromStdString(pre.name());
|
|
case Description:
|
|
return QString::fromStdString(pre.description());
|
|
case Operator:
|
|
return QString::fromStdString(m_opmDtc->user(pre.operatorId()).name());
|
|
case LastModified:
|
|
return QDateTime::fromMSecsSinceEpoch(pre.lastModified());
|
|
case Status:
|
|
return PresentationManagement::toString(pre.fileStatus());
|
|
}
|
|
}
|
|
|
|
if (role == LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole)
|
|
{
|
|
switch (index.column())
|
|
{
|
|
case Columns::Operator:
|
|
return pre.operatorId();
|
|
|
|
default:
|
|
return {};
|
|
}
|
|
Q_UNREACHABLE();
|
|
}
|
|
|
|
return QVariant();
|
|
}
|
|
|
|
void PresentationManagementDialogProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
|
|
{
|
|
m_sourceModel = qobject_cast< PresentationManagementDialogModel*>(sourceModel);
|
|
LtsWidgets::LtsColumnFilterProxyModel::setSourceModel(sourceModel);
|
|
}
|
|
|
|
bool PresentationManagementDialogProxyModel::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 PresentationManagementDialogModel::LastModified:
|
|
return dataLeft.lastModified() < dataRight.lastModified();
|
|
case PresentationManagementDialogModel::Id:
|
|
case PresentationManagementDialogModel::Name:
|
|
case PresentationManagementDialogModel::Description:
|
|
case PresentationManagementDialogModel::Operator:
|
|
|
|
case PresentationManagementDialogModel::Status:
|
|
|
|
break;
|
|
}
|
|
return LtsWidgets::LtsColumnFilterProxyModel::lessThan(source_left, source_right);
|
|
}
|
|
|
|
} // namespace PresentationManagement
|