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,55 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Patric Karwat, SLSE, 2016-10-05
#
SET(ppm_party_edit_gui_SRCS
ppm_party_edit_gui_plugin.cpp
ppm_party_edit_gui_plugin.h
ppm_party_view.cpp
ppm_party_view.h
ppm_party_model.cpp
ppm_party_model.h
ppm_party_edit.cpp
ppm_party_edit.h
CustomView/ppm_party.cpp
CustomView/ppm_party.h
operator_party_assignment.cpp
operator_party_assignment.h
operator_party_assignment_model.cpp
operator_party_assignment_model.h
)
NGL_WRAP_UI(ppm_party_edit_gui_SRCS
operator_party_assignment.ui
ppm_party_view.ui
ppm_party_edit.ui
CustomView/ppm_party.ui
)
NGL_ADD_LIBRARY2(WS PpmPartyEditGuiPlugin MODULE ${ppm_party_edit_gui_SRCS})
NGL_TARGET_LINK_LIBRARIES(PpmPartyEditGuiPlugin
NGLLogger
LtsPrinting
LtsSession
LtsSessionData
PpmGuiPartyPluginInterface
PpmDataPluginInterface
PpmGuiComboboxPluginInterface
Qt5::Widgets
LtsWidgets
LtsDataView
nglwidgets
LtsUtilsGuiDds
LtsUtilsSettings
OpmDataPluginInterface
OpmGuiPluginInterface
OpmChangePasswordGui
)
IF(WIN32)
add_dependencies(PpmPartyEditGuiPlugin svcAesCommon)
ENDIF()
NGL_INSTALL_TARGET(PpmPartyEditGuiPlugin)
@@ -0,0 +1,41 @@
/**
* @RDE_HEADER@
* CustomView for Parties
* $Id: ppm_party.cpp 30352 2016-11-16 13:54:20Z karwat $
* $HeadURL: svn://slssvn/TDS/branches/product/devel/trunk/Lts/Plugins/ParticipantManagement/Gui/PartyEdit/CustomView/ppm_party.cpp $
* $Author: karwat $
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#include "ppm_party.h"
#include "ui_ppm_party.h"
#include "ppm_party_model.h"
CustomViewParty::CustomViewParty(QWidget *parent)
: AbstractDisplayWidget(parent)
, m_ui(new Ui::CustomViewParty)
{
m_ui->setupUi(this);
}
CustomViewParty::~CustomViewParty()
{
delete m_ui;
}
bool CustomViewParty::init(const QModelIndex &idx)
{
if (!idx.isValid())
return false;
QString caption = tr("Name:") + QLatin1Char(' ') + rowData(idx, ParticipantManagement::PartyModel::Name).toString();
#ifdef LTS_DEBUG
caption.append(QLatin1String(" (Id: ") + rowData(idx, ParticipantManagement::PartyModel::Id).toString() + QLatin1Char(')'));
#endif
m_ui->lblParty->setText(caption);
QColor color = rowData(idx, ParticipantManagement::PartyModel::Color, Qt::BackgroundRole).value<QColor>();
m_ui->wColor->setStyleSheet(QStringLiteral("QWidget{ background: %1; }").arg(color.name()));
return true;
}
@@ -0,0 +1,28 @@
/**
* @RDE_HEADER@
* CustomView for Parties
* $Id: ppm_party.h 38595 2018-02-01 12:23:01Z wille_m $
* $HeadURL: svn://slssvn/TDS/branches/product/devel/trunk/Lts/Plugins/ParticipantManagement/Gui/PartyEdit/CustomView/ppm_party.h $
* $Author: wille_m $
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#pragma once
#include <Viewer/LtsDataView/abstract_display_widget.h>
namespace Ui
{
class CustomViewParty;
}
class CustomViewParty final : public LtsDataView::AbstractDisplayWidget
{
Q_OBJECT
public:
explicit CustomViewParty(QWidget *parent = nullptr);
~CustomViewParty();
bool init(const QModelIndex &idx) override;
private:
Ui::CustomViewParty *m_ui;
};
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CustomViewParty</class>
<widget class="QWidget" name="CustomViewParty">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>238</width>
<height>138</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lblParty">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Party</string>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="wColor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,273 @@
/**
* @RDE_HEADER@
* HMI Plugin for OperatorPartyAssignment
* $Id$
* $HeadURL$
* $Author$
* Created by Steve Kemayou, ESZS, 2025-07-22
*/
#include "operator_party_assignment.h"
#include "ui_operator_party_assignment.h"
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/OperatorManagement/opm_data_plugin_interface.h>
#include <LtsSession/lts_session_data.h>
#include <QHeaderView>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
QString s_partyOpAssignStr = QStringLiteral("PartyIdsAssignedOperator");
namespace ParticipantManagement
{
OperatorPartyAssignment::OperatorPartyAssignment(const QString &menuGroup, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_menuGroup(menuGroup)
, m_ppmDtc(nullptr)
, m_ppmFtc(nullptr)
, m_opmDtc(nullptr)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_operatorId(-1)
, m_model(nullptr)
, m_logger(getLogger("OperatorPartyAssignment"))
, m_ui(new Ui::OperatorPartyAssignment)
{
m_ui->setupUi(this);
connect(m_ui->dataView, &LtsDataView::LtsDataView::clicked,
this, &OperatorPartyAssignment::enaDisa);
}
OperatorPartyAssignment::~OperatorPartyAssignment()
{
delete m_ui;
}
void OperatorPartyAssignment::retranslate()
{
translate(m_ui, tr("Operator Party Assignment"));
}
bool OperatorPartyAssignment::init(LtsSession::LtsSession *session)
{
m_session = session;
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->setVisible(false);
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger)<<" -- Couldn't init ppmDtc";
return false;
}
if (!m_session->getDtc<OperatorManagement::DataInterface>(m_opmDtc))
{
ERROR_LOG(m_logger)<<" -- Couldn't init opmDtc";
return false;
}
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ppmFtc))
{
ERROR_LOG(m_logger)<<" -- Couldn't init ppmFtc";
return false;
}
setUnchangeable(true);
m_operatorId= LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
m_model = new OPeratorPartyAssignmentModel(this);
m_model->setPartyCheckStatesData(getPartyStatesForOpertator());
if (!m_model->initModel(m_ppmDtc))
return false;
m_ui->dataView->setModel(m_model);
m_ui->dataView->hideColumn(OPeratorPartyAssignmentModel::Columns::Id);
connect(m_opmDtc.get(), &OperatorManagement::Interface::Dtc::userChanged, this, &OperatorPartyAssignment::onOperatorChanged);
auto cbOperator = [this](const OperatorManagement::User & u){
onOperatorChanged(u, DataModification::eAdded);
};
m_opmDtc->users(cbOperator);
connect(m_ui->operatorComboBox, QOverload<int>::of(&QComboBox::currentIndexChanged),
this, &OperatorPartyAssignment::onSelectionOperatorChanged);
if (m_ui->operatorComboBox->currentIndex() != m_ui->operatorComboBox->findData(m_operatorId))
m_ui->operatorComboBox->setCurrentIndex(m_ui->operatorComboBox->findData(m_operatorId));
else
onSelectionOperatorChanged(0); //param is unused
setUnchangeable(false);
return true;
}
QMap<int, bool> OperatorPartyAssignment::getPartyStatesForOpertator() const
{
// get Party List and properties
// iterarate over partyId in the properties, find the operatorId
// if no operatorId found checked=false else true;
DEBUG_LOG(m_logger)<<" -- [getPartyStatesForOpertator] -> ";
const auto &partys = m_ppmDtc->partys();
QMap<int,bool> mapPartyCheckStates;
for (auto p : partys)
{
const QString partyId = QString::number(p.id());
QJsonObject mainObj = QJsonDocument::fromJson(QByteArray::fromStdString(p.properties())).object();
QJsonObject subObj = mainObj.value(s_partyOpAssignStr).toObject();
QJsonArray opIdJsArry = subObj.value(QString::number(p.id())).toArray();
if (opIdJsArry.contains(QJsonValue::fromVariant(m_operatorId)))
mapPartyCheckStates.insert(p.id(), true);
else
mapPartyCheckStates.insert(p.id(), false);
}
return mapPartyCheckStates;
}
void OperatorPartyAssignment::onOperatorChanged(const OperatorManagement::User &data, DataModification modType)
{
switch (modType)
{
case DataModification::eRemoved:
{
Q_ASSERT(m_operatorMap.contains(data.id()));
// Check, if Operator is currently open, if yes, reset any changes
if (m_ui->operatorComboBox->currentData().toInt() == data.id())
{
__unchange__();
}
m_operatorMap.remove(data.id());
m_ui->operatorComboBox->removeItem(m_ui->operatorComboBox->findData(data.id()));
break;
}
case DataModification::eAdded:
{
Q_ASSERT(!m_operatorMap.contains(data.id()));
const QString operatorName = QString::fromStdString(data.name());
m_operatorMap.insert(data.id(), operatorName);
m_ui->operatorComboBox->addItem(operatorName, data.id());
m_ui->operatorComboBox->model()->sort(0);
break;
}
case DataModification::eModified:
{
Q_ASSERT(m_operatorMap.contains(data.id()));
const QString operatorName = QString::fromStdString(data.name());
m_operatorMap.insert(data.id(), operatorName);
int i = m_ui->operatorComboBox->findData(data.id());
Q_ASSERT(i != -1);
m_ui->operatorComboBox->setItemText(i, operatorName);
m_ui->operatorComboBox->model()->sort(0);
break;
}
}
}
void OperatorPartyAssignment::onSelectionOperatorChanged(const int index)
{
Q_UNUSED(index);
if (hasUnsavedChanges() /*|| m_model->getChangeState() */)
{
switch (askApplyDiscardCancel())
{
case LtsWidgets::Button::Apply:
if (!apply())
return;
break;
case LtsWidgets::Button::Cancel:
{
// cfroebel 2019-06-26:
// Setting back the operator would cause this slot to be called again.
// Thus we avoid this by blocking signals.
{
QSignalBlocker blockSignals(m_ui->operatorComboBox);
m_ui->operatorComboBox->setCurrentIndex(m_ui->operatorComboBox->findData(m_operatorId)); // reset position
}
return;
}
case LtsWidgets::Button::Discard:
__unchange__(); // can't call resetChanges() by myself :(
break;
default:
break;
}
}
m_operatorId = m_ui->operatorComboBox->currentData().toInt();
m_model->updateView(getPartyStatesForOpertator());
}
bool OperatorPartyAssignment::apply()
{
const auto statesData = m_model->modelData();
const auto &partys = m_ppmDtc->partys();
for (auto party : partys)
{
const QString partyId = QString::number(party.id());
QJsonObject propertiesObj = QJsonDocument::fromJson(QByteArray::fromStdString(party.properties())).object();
QJsonObject subObj = propertiesObj.value(s_partyOpAssignStr).toObject();
QJsonArray jsArry = subObj.value(QString::number(party.id())).toArray();
const bool containsOpId = jsArry.contains(QJsonValue::fromVariant(m_operatorId));
const bool isPartyChecked = statesData.value(party.id(), false);
if (!containsOpId && !isPartyChecked)
continue;
if (containsOpId && isPartyChecked)
continue;
if (containsOpId) // this condition is for: OpId available but party is unchecked
{
//remove opId from jsObject because party is not longed checked -> remove opId from propertiesObject
for (int idx = 0; idx < jsArry.count(); ++idx)
{
if (jsArry.at(idx).toInt() == m_operatorId)
{
jsArry.removeAt(idx);
subObj.insert(QString::number(party.id()), jsArry); // if already exist item will be replaced
}
break;
}
}
else if (isPartyChecked)
{
jsArry.append(QJsonValue::fromVariant(m_operatorId));
subObj.insert(QString::number(party.id()), jsArry); // if already exist item will be replaced
}
// update properties jsObj
propertiesObj.insert(s_partyOpAssignStr, subObj); // if already exist item will be replaced
// set request;
// request
Party req = party;
req.id(party.id());
req.name(party.name());
req.color(party.color());
req.fadingColor(party.fadingColor());
req.hlaForceIdentifier(party.hlaForceIdentifier());
req.isUsedBy(party.isUsedBy());
req.role(party.role());
QString props = QString::fromUtf8(QJsonDocument(propertiesObj).toJson());
req.properties(props.toStdString());
m_requestHelper->addRequest([this, req]
{
return m_ppmFtc->modifyPartyDataRequest(req, this);
});
}
return m_requestHelper->startRequests();
}
void OperatorPartyAssignment::enaDisa()
{
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->setEnabled(true);
}
}// namespace ParticipantManagement
@@ -0,0 +1,71 @@
/**
* @RDE_HEADER@
* HMI Plugin for OperatorPartyAssignment
* $Id$
* $HeadURL$
* $Author$
* Created by Steve Kemayou, ESZS, 2025-07-22
*/
#pragma once
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <OperatorManagement/opm_dtc.h>
#include <ParticipantManagement/logger.h>
#include <LtsSession/lts_session.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsUtilsGuiDds/request_helper.h>
#include "operator_party_assignment_model.h"
#include <QWidget>
namespace Ui
{
class OperatorPartyAssignment;
}
namespace ParticipantManagement
{
class OperatorPartyAssignment : public LtsWidgets::LtsDialog
, protected ParticipantManagement::Interface::Ftc::ModifyPartyDataReplyHandler
{
Q_OBJECT
public:
explicit OperatorPartyAssignment(const QString &menuGroup, QWidget *parent = nullptr);
~OperatorPartyAssignment();
bool init(LtsSession::LtsSession *session);
QMap<int, bool> getPartyStatesForOpertator() const;
private slots:
void onOperatorChanged(const OperatorManagement::User &data, DataModification modType);
void onSelectionOperatorChanged(const int index);
private:
void retranslate() override;
bool apply() override;
void onModifyPartyDataReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void enaDisa();
private:
QString m_menuGroup;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
std::shared_ptr<OperatorManagement::Interface::Dtc> m_opmDtc;
LtsSession::LtsSession *m_session;
LtsUtils::RequestHelper *m_requestHelper;
int m_operatorId; //!< currently displayed operator
QMap<int, QString> m_operatorMap;
OPeratorPartyAssignmentModel *m_model;
LOGGER_T m_logger;
Ui::OperatorPartyAssignment *m_ui;
};
}// namespace ParticipantManagement
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>OperatorPartyAssignment</class>
<widget class="QWidget" name="OperatorPartyAssignment">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>738</width>
<height>364</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout" rowstretch="0,1">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lbxOperator">
<property name="text">
<string>Operator:</string>
</property>
</widget>
</item>
<item>
<widget class="LtsWidgets::LtsComboBox" name="operatorComboBox">
<property name="const" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>278</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="LtsDataView::LtsDataView" name="dataView" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,130 @@
#include "operator_party_assignment_model.h"
#include <ParticipantManagement/ppm_translation.h>
#include <QColor>
#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
namespace ParticipantManagement
{
OPeratorPartyAssignmentModel::OPeratorPartyAssignmentModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>({tr("Id"),
tr("Name"),
tr("Color"),
tr("Faded Color"),
tr("Role")},
parent)
, m_dtc(nullptr)
, m_logger(getLogger("OPeratorPartyAssignmentModel"))
{
}
bool OPeratorPartyAssignmentModel::initModel(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc)
{
if (!dtc)
return false;
m_dtc = dtc;
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::partyChanged ,
this, &OPeratorPartyAssignmentModel::onDataChanged);
auto cb = [this](const ParticipantManagement::Party &party)
{
insertRow(party);
};
m_dtc->partys(cb);
return true;
}
void OPeratorPartyAssignmentModel::setPartyCheckStatesData(const QMap<int, bool> partyCheckStates)
{
m_mapPartyCheckStates.clear();
m_mapPartyCheckStates = partyCheckStates;
}
QMap<int, bool> OPeratorPartyAssignmentModel::modelData() const
{
return m_mapPartyCheckStates;
}
void OPeratorPartyAssignmentModel::updateView(const QMap<int, bool> partyCheckStates)
{
if (partyCheckStates.isEmpty())
return;
m_mapPartyCheckStates.clear();
m_mapPartyCheckStates = partyCheckStates;
beginResetModel();
endResetModel();
}
QVariant OPeratorPartyAssignmentModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index))
return QVariant();
const ParticipantManagement::Party &party = m_vecData.at(index.row());
if (role == Qt::BackgroundRole)
{
switch(index.column())
{
case Color:
return QColor::fromRgb(QRgb(party.color()));
case FadedColor:
return QColor::fromRgb(QRgb(party.fadingColor()));
}
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case Id:
return party.id();
case Name:
return ParticipantManagement::trPartyName(party.name());
case Color:
return QVariant();
case FadedColor:
return QVariant();
case Role:
return ParticipantManagement::toString(party.role());
}
}
if (role == Qt::CheckStateRole && index.column() == Name)
{
Qt::CheckState checkState = m_mapPartyCheckStates.value(party.id(),false) ? Qt::Checked : Qt::Unchecked;
return checkState;
}
return QVariant();
}
Qt::ItemFlags OPeratorPartyAssignmentModel::flags(const QModelIndex &index) const
{
auto f = QAbstractTableModel::flags(index);
if (!index.isValid() || index.row() >= m_vecData.size())
return f;
if (index.column() == Columns::Name)
f.setFlag(Qt::ItemIsUserCheckable);
f.setFlag(Qt::ItemIsEditable, false);
f.setFlag(Qt::ItemIsSelectable, true);
return f;
}
bool OPeratorPartyAssignmentModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!index.isValid() || role != Qt::CheckStateRole || !value.canConvert<Qt::CheckState>())
return QAbstractTableModel::setData(index, value, role);
const ParticipantManagement::Party &party = m_vecData.at(index.row());
bool &state = m_mapPartyCheckStates[party.id()];
state = state ? false : true;
emit dataChanged(index, index, {role});
return true;
}
}
@@ -0,0 +1,62 @@
/**
* @RDE_HEADER@
* OperatorPartyAssignmentModel
* $Id$
* $HeadURL$
* $Author$
* Created by Steve Kemayou, ESZS, 2025-07-22
*/
#pragma once
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/logger.h>
#include <QSortFilterProxyModel>
#include <QSet>
#include <LtsWidgets/lts_abstract_table_model.h>
namespace ParticipantManagement
{
class OPeratorPartyAssignmentModel final : public LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>
{
Q_OBJECT
public:
enum Columns
{
Id,
Name,
Color,
FadedColor,
Role
};
explicit OPeratorPartyAssignmentModel(QObject *parent = nullptr);
bool initModel(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc);
void setPartyCheckStatesData(const QMap<int, bool> partyCheckStates);
QMap<int, bool> modelData() const;
public slots:
void updateView(const QMap<int, bool> partyCheckStates);
protected:
QVariant data(const QModelIndex &, int) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override final;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool isFiltered(const Party &data, DataModification modType) const override
{
//no pool and support
if (data.id() <= 1)
return true;
return LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>::isFiltered(data, modType);
}
private:
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
LOGGER_T m_logger;
QMap<int/*id*/, bool> m_mapPartyCheckStates;
};
} //namespace ParticipantManagement
@@ -0,0 +1,448 @@
/**
* @RDE_HEADER@
* ParticipantManagement - Party Edit Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#include "ppm_party_edit.h"
#include "NGLLogger/INGLLogger.h"
#include "ui_ppm_party_edit.h"
#include <QColorDialog>
#include <QJsonDocument>
#include <QJsonArray>
#include <QMessageBox>
#include <ParticipantManagement/ppm_translation.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <LtsUtilsSettings/settings.h>
#include <LtsSession/lts_session_data.h>
#include <Services/AreaEffectSimulation/aes_operator_rights.h>
namespace ParticipantManagement
{
PartyEdit::PartyEdit(QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_partyId(-1)
, m_color(Qt::white)
, m_fadedColor(Qt::white)
, m_isUsed(false)
, m_partiallyUnchangeable(false)
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_dtcOpm(nullptr)
, m_ftcOpm(nullptr)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_session(nullptr)
, m_ui(new Ui::PartyEdit)
, m_logger(getLogger("PartyEdit"))
{
m_ui->setupUi(this);
} // end of ctor()
//-----------------------------------------------------------------------------
PartyEdit::~PartyEdit()
{
delete m_ui;
} // end of dtor()
//-----------------------------------------------------------------------------
void PartyEdit::retranslate()
{
translate(m_ui, m_dtc->party(m_partyId), tr("Party"));
m_ppmGuiCbxIfc->fillRoleComboBox(m_ui->cbRole);
m_ppmGuiCbxIfc->fillHlaForceIdentifierComboBox(m_ui->cbHlaForceIdentifier);
}
void PartyEdit::lock()
{
LtsWidgets::LtsDialog::lock();
if (unchangeable())
{
m_partiallyUnchangeable = true;
setUnchangeable(false);
m_ui->tbColor->setEnabled(false);
m_ui->tbFadedColor->setEnabled(false);
}
m_ui->cbAdlerNotification->setEnabled(true);
m_ui->cbCombatOrder->setEnabled(true);
}
bool PartyEdit::init(int partyId, LtsSession::LtsSession *session)
{
DEBUG_LOG(m_logger) << "PartyEdit::init()";
m_session = session;
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_dtc))
return false;
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ftc))
return false;
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc))
return false;
if (!m_session->getDtc<OperatorManagement::DataInterface>(m_dtcOpm))
return false;
if (!m_session->getFtc<OperatorManagement::DataInterface>(m_ftcOpm))
return false;
m_partyId = partyId;
m_ppmGuiCbxIfc->fillRoleComboBox(m_ui->cbRole);
m_ppmGuiCbxIfc->fillHlaForceIdentifierComboBox(m_ui->cbHlaForceIdentifier);
if (m_partyId >= 0) // pool has id 0 so is a valid party
{
const Party &party = m_dtc->party(m_partyId);
if(party.id() >= 0)
{
setData(party);
}
}
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
const bool enableHlaForceIdentifier = ps->value(QStringLiteral("ppm"),
QStringLiteral("enableHlaForceIdentifier")).toBool();
if (!enableHlaForceIdentifier)
{
m_ui->lblHlaIdentifier->hide();
m_ui->cbHlaForceIdentifier->hide();
}
// Could be filled programmatically later
m_ui->cbAdlerNotification->setProperty("Notification", NotificationManagement::NotificationType::AdlerNotification);
m_ui->cbCombatOrder->setProperty("Notification", NotificationManagement::NotificationType::CombatOrder);
bool enableNotification = (LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::NotificationShow) );
if (!enableNotification)
{
m_ui->cbAdlerNotification->hide();
m_ui->cbCombatOrder->hide();
}
const ParticipantManagement::ConnectState status = m_dtc->saaConnectedState(m_partyId);
const bool enableReset = (LtsSessionData::LtsSessionData::getInstance()->hasOperatorRight(OperatorRights::ChargeAdministrationShow)) &&
(status.underlying() == ParticipantManagement::ConnectState::NoHeartbeat);
if (!enableReset)
{
m_ui->lblReset->hide();
m_ui->tbResetAdlerConnection->hide();
}
connect(m_ui->tbColor, &QToolButton::clicked, this, &PartyEdit::onColorClicked);
connect(m_ui->tbFadedColor, &QToolButton::clicked, this, &PartyEdit::onFadedColorClicked);
connect(m_ui->tbResetAdlerConnection, &QToolButton::clicked, this, &PartyEdit::onResetAdlerConnectionClicked);
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::partyChanged, this, &PartyEdit::onPartyChanged);
// check Notifications
notificationCheck();
setOnlineHelpFilename(QStringLiteral("Situation-Parties"));
return true;
}
//slots
bool PartyEdit::apply()
{
if (!m_partiallyUnchangeable)
{
ParticipantManagement::Role role = static_cast<ParticipantManagement::Role_def::type>(m_ui->cbRole->currentData().toInt());
ParticipantManagement::HlaForceIdentifierEnum hlaIdentfier = static_cast<ParticipantManagement::HlaForceIdentifierEnum_def::type>(m_ui->cbHlaForceIdentifier->currentData().toInt());
Party req;
req.id(m_partyId);
req.name(m_ui->leName->text().toStdString());
req.color(m_color.rgb());
req.fadingColor(m_fadedColor.rgb());
req.role(role);
req.hlaForceIdentifier(hlaIdentfier);
req.isUsedBy(m_isUsed);
m_requestHelper->addRequest([req, this]()
{
return m_ftc->modifyPartyDataRequest(req, this);
});
}
OperatorManagement::User user = m_dtcOpm->user(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
QJsonObject opmProperties(QJsonDocument::fromJson(QByteArray::fromStdString(user.properties())).object());
fillOpmProperties(opmProperties);
OperatorManagement::OperatorCreateModifyRequest reqOpm;
reqOpm.id(user.id());
reqOpm.name(user.name());
reqOpm.description(user.description());
reqOpm.audioChannelPriority(user.audioChannelPriority());
reqOpm.projectionPriority(user.projectionPriority());
reqOpm.image(user.image());
reqOpm.visiblePartiesByExercise(user.visiblePartiesByExercise());
reqOpm.rolePresetId(user.rolePresetId());
QString properties = QString::fromUtf8(QJsonDocument(opmProperties).toJson());
DEBUG_LOG(m_logger) << "properties: " << properties;
reqOpm.properties(properties.toStdString());
m_requestHelper->addRequest([reqOpm, this]()
{
return m_ftcOpm->operatorCreateModifyRequest(reqOpm, this);
});
return m_requestHelper->startRequests();
}
void ParticipantManagement::PartyEdit::onColorClicked()
{
QColorDialog diag;
diag.setOption(QColorDialog::DontUseNativeDialog);
diag.setCurrentColor(m_color);
if( diag.exec() == QColorDialog::Accepted)
{
m_color = diag.currentColor();
setColorToButton(m_ui->tbColor, m_color);
slotChangesMade();
}
}
void ParticipantManagement::PartyEdit::onFadedColorClicked()
{
QColorDialog diag;
diag.setOption(QColorDialog::DontUseNativeDialog);
diag.setCurrentColor(m_fadedColor);
if(diag.exec() == QColorDialog::Accepted)
{
m_fadedColor = diag.currentColor();
setColorToButton(m_ui->tbFadedColor, m_fadedColor);
slotChangesMade();
}
}
void PartyEdit::onResetAdlerConnectionClicked()
{
const int ret = QMessageBox::question(this, tr("Reset ADLER system"),
tr("Are you sure you want to do that?\n"
"If any ADLER objects exist, they will all be deleted and force the disconnection.\n\n"
"Please note:\nAll open ADLER Effect Cluster Dialog boxes must be closed first.\n"
),
QMessageBox::Yes | QMessageBox::Cancel);
if(ret == QMessageBox::Yes)
modifyPartyProperties();
}
void PartyEdit::onPartyChanged(const Party &data, DataModification modType)
{
if (modType == DataModification::eRemoved || data.id() != m_partyId)
return;
const ConnectState connectState = m_dtc->saaConnectedState(m_partyId);
switch (connectState.underlying())
{
case ParticipantManagement::ConnectState::NoHeartbeat:
{
m_ui->lblReset->show();
m_ui->tbResetAdlerConnection->show();
break;
}
default:
{
m_ui->lblReset->hide();
m_ui->tbResetAdlerConnection->hide();
break;
}
}
}
//private
void PartyEdit::setData(const Party &party)
{
m_ui->leName->setText(ParticipantManagement::trPartyName(party.name()));
m_color = QColor::fromRgb(QRgb(party.color()));
m_fadedColor = QColor::fromRgb(QRgb(party.fadingColor()));
m_isUsed = party.isUsedBy();
setColorToButton(m_ui->tbColor, m_color);
setColorToButton(m_ui->tbFadedColor, m_fadedColor);
m_ui->cbRole->setCurrentIndex(m_ui->cbRole->findData(party.role().underlying()));
m_ui->cbHlaForceIdentifier->setCurrentIndex(m_ui->cbHlaForceIdentifier->findData(party.hlaForceIdentifier().underlying()));
}
void PartyEdit::setColorToButton(QToolButton *button, const QColor &color)
{
button->setStyleSheet(QStringLiteral("QToolButton{ background: %1; }").arg(color.name())); // TODO: muss das sein?
}
void PartyEdit::fillJsonSuppressNotifications( QJsonArray &notif, NotificationManagement::NotificationType notifType)
{
QJsonObject suppNotif;
suppNotif[QStringLiteral("partyId")] = m_partyId;
suppNotif[QStringLiteral("AddressType")] = NotificationManagement::AddressType_def::Service;
suppNotif[QStringLiteral("Address")] = AreaEffectSimulation::Offset;
QCheckBox *cbNotif = findCheckBoxByNotificationType(notifType);
if (!cbNotif)
return;
int index = findSuppressNotification(m_partyId, notifType, notif);
if (!cbNotif->isChecked())
{
suppNotif[QStringLiteral("NotificationType")] = notifType.underlying();
if (index >= 0)
notif.replace(index, suppNotif);
else
notif.append(suppNotif);
}
else
{
if (index >= 0)
notif.removeAt(index);
}
}
QCheckBox* PartyEdit::findCheckBoxByNotificationType(const NotificationManagement::NotificationType &notif)
{
for(QCheckBox* cb : findChildren<QCheckBox*>())
{
if (cb->property("Notification").toInt() == notif.underlying())
return cb;
}
return nullptr;
}
int PartyEdit::findSuppressNotification( int partyId, NotificationManagement::NotificationType notifType, QJsonArray suppNotif)
{
for (int i=0; i < suppNotif.size(); ++i)
{
QJsonObject obj = suppNotif.at(i).toObject();
if (obj[QStringLiteral("partyId")] == partyId &&
obj[QStringLiteral("NotificationType")] == notifType.underlying())
return i;
}
return -1;
}
void PartyEdit::fillOpmProperties( QJsonObject &opmProperties)
{
QJsonArray arrExercises = opmProperties[QStringLiteral("Exercises")].toArray();
QJsonObject objExe;
QJsonArray notif;
int indexToReplace = -1;
if (arrExercises.isEmpty())
{
fillJsonSuppressNotifications(notif, NotificationManagement::NotificationType_def::AdlerNotification);
fillJsonSuppressNotifications(notif, NotificationManagement::NotificationType_def::CombatOrder);
}
else
{
for (int i=0; i < arrExercises.size(); ++i)
{
objExe = arrExercises.at(i).toObject();
if (objExe[QStringLiteral("exerciseId")] == m_session->exerciseId())
{
notif = objExe[QStringLiteral("suppressNotifications")].toArray();
fillJsonSuppressNotifications(notif, NotificationManagement::NotificationType_def::AdlerNotification);
fillJsonSuppressNotifications(notif, NotificationManagement::NotificationType_def::CombatOrder);
indexToReplace = i;
break;
}
}
}
objExe[QStringLiteral("suppressNotifications")] = notif;
objExe[QStringLiteral("exerciseId")] = m_session->exerciseId();
if (indexToReplace >= 0)
arrExercises.replace(indexToReplace, objExe);
else
arrExercises.append(objExe);
opmProperties[QStringLiteral("Exercises")] = arrExercises;
}
void PartyEdit::notificationCheck()
{
if (!m_dtcOpm->isAdlerAllowedParty(m_session->exerciseId(), m_partyId, LtsSessionData::LtsSessionData::getInstance()->getOperatorId()))
{
WARNING_LOG(m_logger) << "Party " << m_partyId << " not allowed for this user";
m_ui->lblNotifications->hide();
m_ui->cbAdlerNotification->hide();
m_ui->cbCombatOrder->hide();
return;
}
DEBUG_LOG(m_logger) << "Party allowed for ADLER notifications";
const std::string properties = m_dtcOpm->user(LtsSessionData::LtsSessionData::getInstance()->getOperatorId()).properties();
QJsonObject opmProperties(QJsonDocument::fromJson(QByteArray::fromStdString(properties)).object());
QJsonArray arrExercises = opmProperties[QStringLiteral("Exercises")].toArray();
m_ui->cbAdlerNotification->setCheckState(Qt::Checked);
m_ui->cbCombatOrder->setCheckState(Qt::Checked);
// Here add another NotificationType, everything else will happen automatically
// CheckBox insert in Ui
const QList<NotificationManagement::NotificationType> notifTypes { NotificationManagement::NotificationType_def::AdlerNotification,
NotificationManagement::NotificationType_def::CombatOrder};
for (int i=0; i < arrExercises.size(); ++i)
{
const QJsonObject objExe = arrExercises.at(i).toObject();
if (objExe[QStringLiteral("exerciseId")] != m_session->exerciseId())
continue;
const QJsonArray notif = objExe[QStringLiteral("suppressNotifications")].toArray();
for (const auto elem : notifTypes)
{
auto cb = findCheckBoxByNotificationType(elem);
if (!cb)
continue;
int index = findSuppressNotification(m_partyId, elem, notif);
cb->setCheckState( index>= 0 ? Qt::Unchecked : Qt::Checked);
}
}
}
void PartyEdit::modifyPartyProperties()
{
DEBUG_LOG(m_logger) << LOGFUNCTION;
ParticipantManagement::Party requestParty;
requestParty = m_dtc->party(m_partyId);
// Get properties and then update them
const QJsonObject &origObj = QJsonDocument::fromJson(requestParty.properties().c_str()).object();
QJsonObject adlerPropertiesObj = origObj[QStringLiteral("Adler")].toObject();
adlerPropertiesObj[QStringLiteral("saaConnectedState")] = ParticipantManagement::ConnectState::Disconnecting;
const QByteArray &propertiesBa = requestParty.properties().c_str();
QJsonParseError parserError;
QJsonDocument doc(QJsonDocument::fromJson(propertiesBa, &parserError));
if (parserError.error != QJsonParseError::NoError)
{
ERROR_LOG(m_logger) << "Error parsing json document: " << parserError.errorString() << " '" << propertiesBa << "'";
doc = QJsonDocument();
}
DEBUG_LOG(m_logger) << "json to parse: " << doc.toJson();
QJsonObject obj(doc.object());
obj[QStringLiteral("Adler")] = adlerPropertiesObj;
const QByteArray propertiesStr = QJsonDocument(obj).toJson(QJsonDocument::Compact);
requestParty.properties() = propertiesStr.data();
m_ftc->modifyPartyDataRequest(requestParty);
}
}
@@ -0,0 +1,97 @@
/**
* @RDE_HEADER@
* ParticipantManagement - Party Edit Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#pragma once
#include <LtsWidgets/lts_dialog.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <Services/OperatorManagement/opm_dtc.h>
#include <Services/OperatorManagement/opm_ftc.h>
#include <NotificationManagement/nom.hpp>
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/OperatorManagement/opm_data_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_party_gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <ParticipantManagement/logger.h>
#include <LtsUtilsGuiDds/request_helper.h>
#include <LtsSession/lts_session.h>
class QToolButton;
namespace Ui
{
class PartyEdit;
}
namespace ParticipantManagement
{
class PartyEdit : public LtsWidgets::LtsDialog,
protected ParticipantManagement::Interface::Ftc::ModifyPartyDataReplyHandler
,protected OperatorManagement::Interface::Ftc::OperatorCreateModifyReplyHandler
{
Q_OBJECT
public:
explicit PartyEdit(QWidget *parent = nullptr);
~PartyEdit();
bool init(int partyId,
LtsSession::LtsSession *session);
//virtual functions from ParticipantManagement::Interface::Ftc::StaticMeteoDataModifyReplyHandler
void onModifyPartyDataReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void onOperatorCreateModifyReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void lock() override;
public slots:
void onColorClicked();
void onFadedColorClicked();
void onResetAdlerConnectionClicked();
void onPartyChanged(const ParticipantManagement::Party &data, DataModification modType);
private:
void setData(const Party &party);
void setColorToButton(QToolButton *button, const QColor &color);
bool apply() override;
void fillJsonSuppressNotifications( QJsonArray &arr, NotificationManagement::NotificationType notifType);
void fillOpmProperties( QJsonObject &opmProperties);
int findSuppressNotification( int partyId, NotificationManagement::NotificationType notifType, QJsonArray suppNotif);
QCheckBox* findCheckBoxByNotificationType(const NotificationManagement::NotificationType &notif);
void notificationCheck();
void modifyPartyProperties();
private:
void retranslate() override;
int m_partyId;
QColor m_color;
QColor m_fadedColor;
bool m_isUsed;
// if true, only the notifications can be changed -> they depend on the operator
bool m_partiallyUnchangeable;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
std::shared_ptr<OperatorManagement::Interface::Dtc> m_dtcOpm;
std::shared_ptr<OperatorManagement::Interface::Ftc> m_ftcOpm;
LtsUtils::RequestHelper *m_requestHelper;
LtsSession::LtsSession *m_session;
Ui::PartyEdit *m_ui;
LOGGER_T m_logger;
};
} //namespace ParticipantManagement
@@ -0,0 +1,172 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartyEdit</class>
<widget class="QWidget" name="PartyEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>376</width>
<height>385</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<widget class="QLineEdit" name="leName"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Name:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Color:</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="LtsWidgets::LtsComboBox" name="cbHlaForceIdentifier"/>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Faded Color:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="2">
<widget class="LtsWidgets::LtsComboBox" name="cbRole"/>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="tbColor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLabel" name="lblHlaIdentifier">
<property name="text">
<string>HLA ForceIdentifier:</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Role:</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="tbFadedColor">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="QLabel" name="lblNotifications">
<property name="text">
<string>Notifications:</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
</widget>
</item>
<item row="5" column="2">
<layout class="QVBoxLayout" name="layoutNotifications">
<item>
<widget class="QCheckBox" name="cbAdlerNotification">
<property name="text">
<string>Adler Notification</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbCombatOrder">
<property name="text">
<string>Combat Order</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="6" column="2">
<widget class="QToolButton" name="tbResetAdlerConnection">
<property name="text">
<string>Reset ADLER Connection</string>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="lblReset">
<property name="text">
<string>Reset:</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>leName</tabstop>
<tabstop>tbColor</tabstop>
<tabstop>tbFadedColor</tabstop>
<tabstop>cbRole</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,97 @@
/**
* @RDE_HEADER@
* Gui Plugin for ParticipantManagement - Party
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#include "ppm_party_edit_gui_plugin.h"
#include "ppm_party_view.h"
#include "ppm_party_edit.h"
#include "operator_party_assignment.h"
#include <LtsSession/lts_session.h>
#include <Services/ParticipantManagement/ppm_operator_rights.h>
namespace ParticipantManagement
{
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
{
return std::make_shared<InterfaceImpl>(session);
}
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
: GuiPluginBase::Interface(session, getLogger("Plugins.Gui.Ppm.PartyEdit"))
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
{}
bool InterfaceImpl::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_dtc))
return false;
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ftc))
return false;
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc))
return false;
return true;
}
void InterfaceImpl::clearInterfaces()
{
m_dtc = nullptr;
m_ftc = nullptr;
m_ppmGuiCbxIfc = nullptr;
}
QString InterfaceImpl::menuGroup() const
{
return tr("Participants");
}
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
{
QVector<LtsWidgets::PluginData> ret;
{
LtsWidgets::PluginData plData;
plData.menuGroup = menuGroup();
plData.menuText = tr("Parties");
plData.identifier = QLatin1String("ppmPartyView");
plData.menuIcon = QIcon(QLatin1String("icon:party_edit.svg"));
plData.operatorRight = OperatorRights::PartyEdit::PartiesShow;
plData.exercisePart = LtsWidgets::ExercisePart::ePlanning;
plData.createWidgetFunc = [this](QWidget *parent)
{
return onShowParties(parent);
};
ret.append(plData);
}
return ret;
}
LtsWidgets::LtsDialog *InterfaceImpl::onShowParties(QWidget *parent)
{
return LtsWidgets::initDialog(new PartyView(menuGroup(), parent),
m_session);
}
LtsWidgets::LtsDialog *InterfaceImpl::onShowOperatorParyAssignment(QWidget *parent)
{
return LtsWidgets::initDialog(new OperatorPartyAssignment(menuGroup(), parent),
m_session);
}
} // namespace ParticipantManagement
@@ -0,0 +1,68 @@
/**
* @RDE_HEADER@
* Gui Plugin for ParticipantManagement - Party
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_party_gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
namespace ParticipantManagement
{
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
{
Q_PLUGIN_METADATA(IID "gui:3:ppm.partyedit")
Q_INTERFACES(GuiPluginBase::Plugin)
Q_OBJECT
public:
GuiPlugin() = default;
~GuiPlugin() = default;
QString pluginName() override { return QStringLiteral("ParticipantManagement.GuiPlugin.PartyEdit"); }
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
bool availableInPartition(IDL::PartitionType partition) const override
{
return (partition == IDL::PartitionType::Global ||
partition == IDL::PartitionType::Exercise);
}
};
class InterfaceImpl final : public QObject, public GuiPluginBase::Interface
{
Q_OBJECT
public:
explicit InterfaceImpl(LtsSession::LtsSession *session);
bool fetchInterfaces() override;
void clearInterfaces() override;
QString menuGroup() const override;
QVector<LtsWidgets::PluginData> getActions() override;
bool availableInPartition(IDL::PartitionType partition) const override { return partition == IDL::PartitionType::Global || partition == IDL::PartitionType::Exercise; }
private:
LtsWidgets::LtsDialog *onShowParties(QWidget *parent);
LtsWidgets::LtsDialog *onShowOperatorParyAssignment(QWidget *parent);
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
};
} // namespace ParticipantManagement
@@ -0,0 +1,186 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Party Overview Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#include "ppm_party_model.h"
#include <OperatorManagement/opm_data_plugin_interface.h>
#include <ParticipantManagement/ppm_data_plugin_interface.h>
#include <LtsSession/lts_session_data.h>
#include <ParticipantManagement/ppm_translation.h>
#include <QColor>
#include <QJsonDocument>
#include <QJsonObject>
namespace ParticipantManagement
{
//---------------------------------
// PartyModel
//---------------------------------
PartyModel::PartyModel(QObject *parent)
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>({tr("Id"),
tr("Name"),
tr("Color"),
tr("Faded Color"),
tr("Role"),
tr("Is Used"),
tr("Is SAA connected"),
tr("SAA Name"),
tr("Szenar Name")},
parent)
, m_ppmDtc(nullptr)
, m_logger(getLogger("PartyModel"))
{}
bool PartyModel::initModel(LtsSession::LtsSession *session)
{
m_session = session;
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger)<<" Couldn't load ppmDtc!!! ";
return false;
}
if (!m_session->getDtc<OperatorManagement::DataInterface>(m_opmDtc))
{
ERROR_LOG(m_logger)<<" Couldn't load opmDtc!!! ";
return false;
}
connect(m_ppmDtc.get(), &ParticipantManagement::Interface::Dtc::partyChanged ,
this, &PartyModel::onDataChanged);
m_operatorId = LtsSessionData::LtsSessionData::getInstance()->getOperatorId();
m_ppmDtc->partys([this](const ParticipantManagement::Party &party)
{
if (hasParty(party)) // opm_operator_exercise -> visible_parties
insertRow(party);
});
return true;
}
QVariant PartyModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index))
return QVariant();
const ParticipantManagement::Party &party = m_vecData.at(index.row());
if (role == Qt::BackgroundRole)
{
switch(index.column())
{
case Color:
return QColor::fromRgb(QRgb(party.color()));
case FadedColor:
return QColor::fromRgb(QRgb(party.fadingColor()));
}
}
if (role == Qt::DisplayRole)
{
switch (index.column())
{
case Id:
return party.id();
case Name:
return ParticipantManagement::trPartyName(party.name());
case Color:
return QVariant();
case FadedColor:
return QVariant();
case Role:
return ParticipantManagement::toString(party.role());
case IsUsedBy:
return party.isUsedBy() ? tr("Yes") : tr("No");
case IsSaaConnected:
{
if ( party.properties().empty())
return false;
ParticipantManagement::ConnectState status = m_ppmDtc->saaConnectedState(party.id());
QString connectState;
switch (status.underlying())
{
case ParticipantManagement::ConnectState::Connected:
connectState = tr("Connected");
break;
case ParticipantManagement::ConnectState::NoHeartbeat:
connectState = tr("No Heartbeat");
break;
default:
connectState = QStringLiteral("");
break;
}
return connectState;
}
case SaaName:
{
if ( party.properties().empty())
return QString{};
const QJsonObject properties(QJsonDocument::fromJson(QByteArray::fromStdString(party.properties())).object());
if (!properties.contains(QStringLiteral("Adler")) )
return QString{};
const QJsonObject adlerObj = properties[QStringLiteral("Adler")].toObject();
QString saaName;
if (adlerObj.contains(QStringLiteral("saaName")) )
saaName.append(adlerObj[QStringLiteral("saaName")].toString());
if (adlerObj.contains(QStringLiteral("isVerbund")) && !saaName.isEmpty())
saaName.append(QStringLiteral(" (") + (adlerObj[QStringLiteral("isVerbund")].toBool() ? tr("Verbund") : tr("Standalone")) + QStringLiteral(")"));
return saaName;
}
case SzenarName:
{
if ( party.properties().empty())
return QString{};
const QJsonObject properties(QJsonDocument::fromJson(QByteArray::fromStdString(party.properties())).object());
if (!properties.contains(QStringLiteral("Adler")) )
return QString{};
const QJsonObject adlerObj = properties[QStringLiteral("Adler")].toObject();
if (adlerObj.contains(QStringLiteral("szenarName")) )
return adlerObj[QStringLiteral("szenarName")].toString();
return QString{};
}
}
}
return QVariant();
}
bool PartyModel::hasParty(const Party &party) const
{
const auto visiblePartiesByExercise = m_opmDtc->user(m_operatorId).visiblePartiesByExercise();
for (const auto &exerciseParties : visiblePartiesByExercise)
{
if (exerciseParties.exerciseId() != m_session->exerciseId())
continue;
if (!exerciseParties.visibleParties().is_set()) //has_value not support on windows yet so we need depricated is_set
return false;
for (const auto &partyId : exerciseParties.visibleParties().get())
if (partyId == party.id())
return true;
return false;
}
return false;
}
bool PartyModel::isPartyHidden(const Party &party) const
{ const auto visiblePartiesByExercise = m_opmDtc->user(m_operatorId).visiblePartiesByExercise();
for (const auto &exerciseParties : visiblePartiesByExercise)
{
if (exerciseParties.exerciseId() != m_session->exerciseId())
continue;
if (!exerciseParties.hiddenParties().is_set()) //has_value not support on windows yet so we need depricated is_set
return false;
for (const auto &partyId : exerciseParties.hiddenParties().get())
if (partyId == party.id())
return true;
return false;
}
return false;
}
} // namespace ParticipantManagement
@@ -0,0 +1,68 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Party Overview Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#pragma once
#include <OperatorManagement/opm_dtc.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/logger.h>
#include <LtsSession/lts_session.h>
#include <LtsWidgets/lts_abstract_table_model.h>
namespace ParticipantManagement
{
// --------------------------------------------------------
// PartyModel
// --------------------------------------------------------
class PartyModel final : public LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>
{
Q_OBJECT
public:
enum Columns
{
Id,
Name,
Color,
FadedColor,
Role,
IsUsedBy,
IsSaaConnected,
SaaName,
SzenarName
};
explicit PartyModel(QObject *parent = nullptr);
bool initModel(LtsSession::LtsSession *session);
QVariant data(const QModelIndex &, int) const override;
protected:
bool isFiltered(const Party &data, DataModification modType) const override
{
//no pool and support
if (data.id() <= 1)
return true;
return LtsWidgets::LtsAbstractTableModel<ParticipantManagement::Party>::isFiltered(data, modType);
}
private:
bool hasParty(const ParticipantManagement::Party &party) const;
bool isPartyHidden(const ParticipantManagement::Party &party) const;
private:
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<OperatorManagement::Interface::Dtc> m_opmDtc;
int m_operatorId;
int m_exerciseId;
LtsSession::LtsSession *m_session;
LOGGER_T m_logger;
};
} //namespace ParticipantManagement
@@ -0,0 +1,220 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Party View
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#include "ppm_party_view.h"
#include "ui_ppm_party_view.h"
#include "CustomView/ppm_party.h"
#include "ppm_party_edit.h"
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <LtsPrinting/printing.h>
#include <QTreeView>
namespace ParticipantManagement
{
PartyView::PartyView(const QString &menuGroup, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
, m_menuGroup(menuGroup)
, m_model(nullptr)
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_session(nullptr)
, m_ui(new Ui::PartyView)
, m_logger(getLogger("PartyView"))
{
m_ui->setupUi(this);
m_ui->widget->setSelectionMode(QAbstractItemView::SingleSelection);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
this, &PartyView::enaDisa);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked, this, &PartyView::onEditParty);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalEnterPressed, this, &PartyView::onEditParty);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &PartyView::onEditParty);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &PartyView::onAddParty);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &PartyView::onRemoveParty);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &PartyView::onPrint);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Load, this, &PartyView::onSyncParties);
m_buttonBox->setText(LtsWidgets::DialogButton::Load, tr("Synchronize Parties"));
setOnlineHelpFilename(QStringLiteral("Situation-Parties"));
}
PartyView::~PartyView()
{
delete m_ui;
}
void PartyView::retranslate()
{
translate(m_ui, tr("Parties"));
}
bool PartyView::init(LtsSession::LtsSession *session)
{
m_session = session;
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_dtc))
return false;
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ftc))
return false;
m_model = new PartyModel(this);
if (!m_model->initModel(m_session))
return false;
m_ui->widget->setModel(m_model, [this]() { return new CustomViewParty(this); });
#ifndef LTS_DEBUG
m_ui->widget->hideColumn(PartyModel::Id);
#endif
m_ui->widget->setSortingEnabled(false);
connect(m_model, &PartyModel::rowsInserted, this, &PartyView::enaDisa);
connect(m_model, &PartyModel::rowsRemoved, this, &PartyView::enaDisa);
enaDisa();
return true;
}
void PartyView::enaDisa()
{
const QModelIndex idx = m_ui->widget->currentIndex();
bool bAddVisible = m_model->rowCount() < 12; // 12 parties, OC and pool are not shown
bool bEditEnabled = true;
bool bRemoveEnabled = true;
bool bRemoveVisible = (m_session->exerciseId() > 0);
bool bLoadEnabled = true;
bool bLoadVisible = (m_session->exerciseId() > 0);
const int row = idx.row();
if (m_ui->widget->selectedRows().size() == 0 || row < 0)
{
bEditEnabled = false;
bRemoveEnabled = false;
}
else
{
const ParticipantManagement::Party party = m_model->getRowData(row);
bEditEnabled = party.id() > 0; // all but not pool
bRemoveEnabled = !party.isUsedBy();
}
if (m_session->exerciseId() > 0)
{
// no add parties in ex_N, they need to be added in ex_0 and synchronized. Last updated: 2018.04.12
bAddVisible = false;
// sync possible only in preparing exercise
const bool bInPreparation = (m_session->exerciseState() == LtsWidgets::ExerciseState::eCreated);
if (bInPreparation)
{
// sync possible only in preparing exercise
bLoadEnabled = true;
bLoadVisible = true;
bRemoveVisible = true;
}
else
{
// sync and delete not possible after starting exercise
bLoadEnabled = false;
bLoadVisible = false;
bRemoveVisible = false;
bRemoveEnabled = false;
}
}
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Add, bAddVisible);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bEditEnabled);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, bRemoveEnabled);
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Remove, bRemoveVisible);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, bLoadEnabled);
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Load, bLoadVisible);
}
void PartyView::onEditParty()
{
const QModelIndex idx = m_ui->widget->currentIndex();
int row = idx.row();
if (row < 0)
return;
ParticipantManagement::Party party = m_model->getRowData(row);
PartyEdit *dialog = new PartyEdit(this);
dialog->init(party.id(), m_session);
addDialog(dialog, m_menuGroup, QLatin1String("ppmEditParty")+QString::number(party.id()), LtsWidgets::LayoutArea::eDialogTab);
}
void PartyView::onAddParty()
{
PartyEdit *dialog = new PartyEdit(this);
dialog->init(-1 , m_session);
addDialog(dialog, m_menuGroup, QLatin1String("ppmAddParty"), LtsWidgets::LayoutArea::eDialogTab);
}
void PartyView::onRemoveParty()
{
const QModelIndex curIdx = m_ui->widget->currentIndex();
if (!curIdx.isValid())
return;
const Party party = m_model->getRowData(curIdx.row());
if (party.id() < 0)
return;
RemovePartyRequest req;
req.partyId(party.id());
m_requestHelper->startSingleRequest([req, this]()
{
return m_ftc->removePartyRequest(req, this);
});
enaDisa();
}
void PartyView::onPrint()
{
LtsPrinting::printView(m_session, this, m_ui->widget->treeView() );
}
void PartyView::onSyncParties()
{
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this,tr("Changes in this exercise will be lost. Do you wish to continue?"), tr("Warning"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
if (button == LtsWidgets::Button::Yes)
{
m_requestHelper->startSingleRequest([this]()
{
SyncPartiesRequest req;
req.exerciseId(m_session->exerciseId());
DEBUG_LOG(m_logger) << "Sync parties for exercise " << req.exerciseId();
return m_ftc->syncPartiesRequest(req, this);
});
}
enaDisa();
}
void PartyView::tableColumnOrganiserSetting()
{
//LtsColumnOrganiser
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
}
} // namespace ParticipantManagement
@@ -0,0 +1,77 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Party View
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-11
*/
#pragma once
#include "ppm_party_model.h"
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <Services/OperatorManagement/opm_ftc.h>
//#include <Services/ExerciseManagement/exm_dtc.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <LtsUtilsGuiDds/request_helper.h>
namespace Ui
{
class PartyView;
}
namespace ParticipantManagement
{
class PartyView : public LtsWidgets::LtsDialog
, protected ParticipantManagement::Interface::Ftc::ModifyPartyDataReplyHandler
, protected ParticipantManagement::Interface::Ftc::RemovePartyReplyHandler
, protected ParticipantManagement::Interface::Ftc::SyncPartiesReplyHandler
, protected OperatorManagement::Interface::Ftc::OperatorCreateModifyReplyHandler
{
Q_OBJECT
public:
explicit PartyView(const QString &menuGroup, QWidget *parent = nullptr);
~PartyView();
bool init(LtsSession::LtsSession *session);
//const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
// const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
// const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc);
private:
void retranslate() override;
void onModifyPartyDataReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void onRemovePartyReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void onSyncPartiesReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void onOperatorCreateModifyReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void enaDisa();
void onEditParty();
void onAddParty();
void onRemoveParty();
void onPrint();
void onSyncParties();
void tableColumnOrganiserSetting() override;
private:
QString m_menuGroup;
PartyModel *m_model;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
LtsUtils::RequestHelper *m_requestHelper;
LtsSession::LtsSession *m_session;
Ui::PartyView *m_ui;
LOGGER_T m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>PartyView</class>
<widget class="QWidget" name="PartyView">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>455</width>
<height>341</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="LtsDataView::LtsDataView" name="widget">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>250</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>