213 lines
6.2 KiB
C++
Executable File
213 lines
6.2 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* ExerciseChooser Payload UI
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Mike Wille, SLSE, 2016-08-12
|
|
*/
|
|
|
|
#include "exm_chooser.h"
|
|
#include "ui_exm_chooser.h"
|
|
|
|
#include "exm_dialog_model.h"
|
|
#include "CustomViews/exm_exercise.h"
|
|
|
|
#include <LtsWidgets/lts_global_wait_dialog.h>
|
|
#include <LtsSession/lts_session.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <Plugins/ExerciseManagement/exm_data_plugin_interface.h>
|
|
#include <Plugins/OperatorManagement/opm_data_plugin_interface.h>
|
|
#include <Plugins/AssetManagement/asm_data_plugin_interface.h>
|
|
#include <Plugins/ProjectDataManagement/pdm_data_plugin_interface.h>
|
|
#include <OperatorManagement/opm_operator_rights.h>
|
|
#include <LtsUtilsCore/dds_vector.h>
|
|
|
|
#include <QCloseEvent>
|
|
|
|
|
|
namespace ExerciseManagement
|
|
{
|
|
|
|
ExerciseChooser::ExerciseChooser(QWidget *parent)
|
|
: QDialog(parent)
|
|
, m_ui(new Ui::ExerciseChooser)
|
|
{
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(false);
|
|
|
|
m_ui->setupUi(this);
|
|
|
|
setWindowTitle(tr("Select Exercise"));
|
|
setWindowFlags(windowFlags() | /*Qt::WindowStaysOnTopHint | */Qt::FramelessWindowHint); // hints..
|
|
|
|
m_ui->widget->seamless();
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::selectionChanged,
|
|
this, &ExerciseChooser::enaDisa);
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::doubleClicked,
|
|
this, &ExerciseChooser::slotExerciseSelected, Qt::QueuedConnection);
|
|
|
|
connect(m_ui->pbSelect, &QPushButton::clicked,
|
|
this, &ExerciseChooser::slotExerciseSelected, Qt::QueuedConnection);
|
|
|
|
connect(m_ui->pbQuit, &QPushButton::clicked,
|
|
this, &ExerciseChooser::signalQuit, Qt::QueuedConnection);
|
|
connect(m_ui->pbQuit, &QPushButton::clicked,
|
|
this, [this]()
|
|
{
|
|
//LtsWidgets::LtsGlobalWaitDialog::getInstance()->wait(); // resume plugin manager's loading screen after this ui
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
m_close = true;
|
|
close();
|
|
});
|
|
|
|
//LtsWidgets::LtsGlobalWaitDialog::getInstance()->done(); // interrupt plugin manager's loading screen for this ui
|
|
}
|
|
|
|
|
|
ExerciseChooser::~ExerciseChooser()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
bool ExerciseChooser::init(LtsSession::LtsSession *session)
|
|
{
|
|
m_session = session;
|
|
std::shared_ptr<ExerciseManagement::Interface::Dtc> dtc;
|
|
if (!session->getDtc<ExerciseManagement::DataInterface>(dtc))
|
|
return false;
|
|
std::shared_ptr<ExerciseManagement::Interface::Ftc> ftc;
|
|
if (!session->getFtc<ExerciseManagement::DataInterface>(ftc))
|
|
return false;
|
|
|
|
if (!session->getDtc<OperatorManagement::DataInterface>(m_opmDtc))
|
|
return false;
|
|
|
|
std::shared_ptr<ProjectDataManagement::Interface::Dtc> pdmDtc;
|
|
if (!session->getDtc<ProjectDataManagement::DataInterface>(pdmDtc))
|
|
return false;
|
|
std::shared_ptr<AssetManagement::Interface::Dtc> asmDtc;
|
|
if (!session->getDtc<AssetManagement::DataInterface>(asmDtc))
|
|
return false;
|
|
|
|
|
|
delete m_model;
|
|
delete m_proxyModel;
|
|
|
|
m_model = new ExerciseManagementDialogModel(this);
|
|
m_model->initModel(dtc, ftc, asmDtc, pdmDtc, true, true);
|
|
|
|
m_proxyModel = new ExerciseManagementProxyModel(this);
|
|
m_proxyModel->setAdminExerciseVisible(true);
|
|
m_proxyModel->setVisibleExerciseStates({ExerciseState::Created, ExerciseState::Started, ExerciseState::Paused, ExerciseState::Stopped});
|
|
m_proxyModel->setSourceModel(m_model);
|
|
m_proxyModel->setSortRole(Qt::UserRole);
|
|
m_proxyModel->sort(0);
|
|
|
|
|
|
CustomViewExercise *customViewExerciseDummy = new CustomViewExercise();
|
|
m_model->setImageSizeConstraints(customViewExerciseDummy->imageSize());
|
|
delete customViewExerciseDummy;
|
|
|
|
|
|
connect(m_opmDtc.get(), &OperatorManagement::Interface::Dtc::userChanged,
|
|
this, &ExerciseChooser::onUserChanged);
|
|
const int opId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
|
onUserChanged(m_opmDtc->user(opId), DataModification::eAdded);
|
|
|
|
m_ui->widget->selectCustomView();
|
|
m_ui->widget->setSelectionMode(QAbstractItemView::SelectionMode::SingleSelection);
|
|
m_ui->widget->setModel(m_proxyModel, [this]() { return new CustomViewExercise(this); });
|
|
for (int i = 0; i < m_proxyModel->columnCount(); ++i)
|
|
m_ui->widget->hideColumn(i);
|
|
m_ui->widget->showColumn(ExerciseManagement::ExerciseManagementDialogModel::Name);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
void ExerciseChooser::enaDisa()
|
|
{
|
|
m_ui->pbSelect->setEnabled(m_ui->widget->selectedRows().length() == 1);
|
|
}
|
|
|
|
|
|
void ExerciseChooser::reject()
|
|
{
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
|
|
if (!m_selected)
|
|
emit signalQuit();
|
|
|
|
QDialog::reject();
|
|
}
|
|
|
|
|
|
void ExerciseChooser::closeEvent(QCloseEvent *event) // TODO: override reject() TODO: renew this method
|
|
{
|
|
if (!m_close)
|
|
{
|
|
event->ignore();
|
|
return;
|
|
}
|
|
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
|
|
if (!m_selected)
|
|
emit signalQuit();
|
|
}
|
|
|
|
|
|
void ExerciseChooser::slotExerciseSelected()
|
|
{
|
|
if (m_selected)
|
|
return;
|
|
|
|
m_selected = true;
|
|
|
|
const QModelIndex idx = m_ui->widget->currentIndex();
|
|
const Exercise ex = m_model->getRowData(idx.row());
|
|
|
|
if (ex.id() < 0)
|
|
return;
|
|
|
|
setEnabled(false);
|
|
//hide();
|
|
//QCoreApplication::processEvents();
|
|
|
|
LtsWidgets::LtsGlobalWaitDialog::getInstance()->setVisible(true);
|
|
emit signalSelectExercise(ex.id());
|
|
m_close = true;
|
|
close();
|
|
}
|
|
|
|
|
|
void ExerciseChooser::onUserChanged(const OperatorManagement::User &user, DataModification mod)
|
|
{
|
|
if (!m_session || !m_proxyModel)
|
|
return;
|
|
const int opId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
|
|
if (user.id() != opId)
|
|
return;
|
|
|
|
if (mod == DataModification::eRemoved)
|
|
{
|
|
m_proxyModel->setVisibleExerciseIds({});
|
|
return;
|
|
}
|
|
|
|
const bool hasAdminRights = std::any_of(user.effectiveAcls().begin(), user.effectiveAcls().end(),
|
|
[](int val) { return val == OperatorRights::Administrator; });
|
|
if (m_session->app() == LtsAppDescriptor::App::OC ||
|
|
(hasAdminRights && (m_session->app() == LtsAppDescriptor::App::Situation ||
|
|
m_session->app() == LtsAppDescriptor::App::PlanEditor)))
|
|
m_proxyModel->setAdminExerciseVisible(true);
|
|
else
|
|
m_proxyModel->setAdminExerciseVisible(false);
|
|
m_proxyModel->setVisibleExerciseIds(LtsUtils::convert<QVector<int>>(user.exerciseIds()));
|
|
}
|
|
|
|
}
|