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 Mike Wille, SLSE, 2016-05-05
#
SET(participant_templates_gui_SRCS
participant_templates_gui_plugin.h
participant_templates_gui_plugin.cpp
participant_template_chooser_model.cpp
participant_template_chooser_model.h
participant_template_chooser.cpp
participant_template_chooser.h
participant_template_chooser_frameless.cpp
participant_template_chooser_frameless.h
participant_template_edit.cpp
participant_template_edit.h
template_unit_namer.cpp
template_unit_namer.h
CustomView/template.cpp
CustomView/template.h
)
NGL_WRAP_UI(participant_templates_gui_SRCS
participant_template_chooser.ui
participant_template_chooser_frameless.ui
participant_template_edit.ui
template_unit_namer.ui
CustomView/template.ui
)
NGL_ADD_LIBRARY(WS PpmParticipantTemplatesGuiPlugin MODULE ${participant_templates_gui_SRCS})
NGL_TARGET_LINK_LIBRARIES(PpmParticipantTemplatesGuiPlugin
AsbDataPluginInterface
advancedSymbology
advancedSymbologyGui
AsbHelper
nglwidgets
NGLLogger
LtsPrinting
LtsDataView
LtsAppManager
LtsPluginManager
LtsSessionData
PpmGuiTemplatesPluginInterface
PpmGuiComboboxPluginInterface
PpmDataPluginInterface
PpmCommon
Qt5::Widgets
LtsWidgets
LtsSession
LtsUtilsGuiDds
)
NGL_INSTALL_TARGET(PpmParticipantTemplatesGuiPlugin)
@@ -0,0 +1,39 @@
/**
* @RDE_HEADER@
* CustomView for MDM Station
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "template.h"
#include "ui_template.h"
#include "participant_template_chooser_model.h"
namespace ParticipantManagement
{
CustomViewTemplate::CustomViewTemplate(QWidget *parent) // TODO: Class Name passt irgendwie nicht zum Programm?
: AbstractDisplayWidget(parent)
, m_ui(new Ui::CustomViewTemplate)
{
m_ui->setupUi(this);
}
CustomViewTemplate::~CustomViewTemplate()
{
delete m_ui;
}
bool CustomViewTemplate::init(const QModelIndex &idx)
{
if (!idx.isValid())
return false;
m_ui->lbNote->setText(rowData(idx, ParticipantManagement::ParticipantTemplateChooserModel::ColDesignatorIdentifier).toString());
m_ui->lbType->setText(rowData(idx, ParticipantManagement::ParticipantTemplateChooserModel::ColType).toString());
return true;
}
} // namespace ParticipantManagement
@@ -0,0 +1,32 @@
/**
* @RDE_HEADER@
* CustomView for MRK Marker
* $Id$
* $HeadURL$
* $Author$
* Created by Mike Wille, SLSE, 2016-04-08
*/
#pragma once
#include <Viewer/LtsDataView/abstract_display_widget.h>
namespace Ui
{
class CustomViewTemplate;
}
namespace ParticipantManagement
{
class CustomViewTemplate final : public LtsDataView::AbstractDisplayWidget
{
Q_OBJECT
public:
explicit CustomViewTemplate(QWidget *parent = nullptr);
~CustomViewTemplate();
bool init(const QModelIndex &idx) override;
private:
Ui::CustomViewTemplate* m_ui;
};
} // namespace ParticipantManagement
@@ -0,0 +1,113 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CustomViewTemplate</class>
<widget class="QWidget" name="CustomViewTemplate">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>230</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lbType">
<property name="font">
<font>
<italic>true</italic>
</font>
</property>
<property name="text">
<string notr="true">Type</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbNote">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string notr="true">Note</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<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>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="lbTime">
<property name="text">
<string notr="true">Time</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string notr="true">with</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lbOffset">
<property name="text">
<string notr="true">Offset</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_6">
<property name="text">
<string notr="true">seconds Offset</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,233 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Overview Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "participant_template_chooser.h"
#include "ui_participant_template_chooser.h"
#include "CustomView/template.h"
#include "participant_template_edit.h"
#include "template_unit_namer.h"
#include <LtsSession/lts_session_manager.h>
#include <LtsSession/lts_session_data.h>
#include <LtsAppManager/lts_app_manager.h>
#include <PluginInterfaces/gui_plugin_interface.h>
#include <LtsPluginManager/lts_plugin_manager.h>
#include <LtsAppDescriptor/lts_app_descriptor.h>
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
#include <LtsPrinting/printing.h>
#include <QTreeView>
namespace ParticipantManagement
{
ParticipantTemplateChooser::ParticipantTemplateChooser(const QString &menuGroup,
bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_menuGroup(menuGroup)
, m_asSupportService(asSupportService)
, m_model(nullptr)
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_ppmGuiOrgChartIfc(nullptr)
, m_session(session)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_ui(new Ui::ParticipantTemplateChooser)
, m_logger(getLogger("ParticipantTemplateChooser"))
{
m_ui->setupUi(this);
m_ui->widget->setSelectionMode(QAbstractItemView::SingleSelection);
if (m_asSupportService)
setOnlineHelpFilename(QStringLiteral("Administrator-Support_Templates"));
else
setOnlineHelpFilename(QStringLiteral("Administrator-Participant_Templates"));
}
ParticipantTemplateChooser::~ParticipantTemplateChooser()
{
delete m_ui;
}
void ParticipantTemplateChooser::retranslate()
{
translate(m_ui, m_asSupportService ? tr("Support Templates") : tr("Participant Templates"));
}
void ParticipantTemplateChooser::tableColumnOrganiserSetting()
{
//LtsColumnOrganiser
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
}
bool ParticipantTemplateChooser::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<ForeignGuiOrgChartInterface> &ppmGuiOrgChartIfc)
{
if (!dtc || !ftc || !ppmGuiCbxIfc)
return false;
m_dtc = dtc;
m_ftc = ftc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
m_ppmGuiOrgChartIfc = ppmGuiOrgChartIfc;
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(m_asbIfc);
m_model = new ParticipantTemplateChooserModel(m_asSupportService, this);
m_model->initModel(m_session, m_dtc);
m_ui->widget->setModel(m_model, [this]() { return new CustomViewTemplate(this); });
//m_ui->widget->treeView()->header()->setSectionResizeMode(QHeaderView::ResizeToContents); // schön wäre es ...
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &ParticipantTemplateChooser::onAddTemplate);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked,
this, &ParticipantTemplateChooser::onEditTemplate);
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
this, [this]
{
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, m_ui->widget->selectedRows().size());
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, m_ui->widget->selectedRows().size());
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, m_ui->widget->selectedRows().size());
});
const LtsAppDescriptor::AppDescriptionVector &vec = LtsAppManager::LtsAppManager::getInstance()->getAvailableApps();
for (const LtsAppDescriptor::AppDescription &descr : vec)
{
if (descr.id == LtsAppDescriptor::App::OrgChart && descr.active && m_ppmGuiOrgChartIfc)
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &ParticipantTemplateChooser::onEditTemplateOrgChart);
}
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &ParticipantTemplateChooser::onEditTemplate);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &ParticipantTemplateChooser::onRemoveTemplate);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &ParticipantTemplateChooser::onPrint);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Print);
return true;
}
//SLOTS
void ParticipantTemplateChooser::onAddTemplate()
{
TemplateUnitNamer *namer = new TemplateUnitNamer(m_asSupportService, m_dtc, m_ppmGuiCbxIfc, this);
QObject::connect(namer, &TemplateUnitNamer::rejected, namer, &TemplateUnitNamer::deleteLater);
QObject::connect(namer, &TemplateUnitNamer::newUnitTemplateRoot, this, [this](const ParticipantManagement::TemplateData &tempData)
{
ModifyTemplateDataRequest req;
req.data({tempData});
m_requestHelper->addRequest([this,req]()
{
return m_ftc->modifyTemplateDataRequest(req, this);
});
m_requestHelper->startRequests();
});
namer->show();
}
void ParticipantTemplateChooser::onEditTemplate()
{
QModelIndex idx = m_ui->widget->currentIndex();
if (!idx.isValid())
return;
TemplateParticipant data = m_model->getRowData(m_ui->widget->currentIndex().row());
ParticipantTemplateEdit *edit = new ParticipantTemplateEdit(m_session, data.templateId(), m_asSupportService, this);
if (!edit->init(m_dtc, m_ftc, m_ppmGuiCbxIfc, m_asbIfc))
{
delete edit;
return;
}
addDialog(edit, m_menuGroup, QLatin1String("editTemplate") + QString::number(data.templateId()), LtsWidgets::LayoutArea::eDialogTab);
}
void ParticipantTemplateChooser::onEditTemplateOrgChart()
{
if(!m_ppmGuiOrgChartIfc)
return;
QModelIndex idx = m_ui->widget->currentIndex();
if (!idx.isValid())
return;
TemplateParticipant data = m_model->getRowData(idx.row());
// Was genau passiert hier??
//maybe add skip payload to create app'?
LtsSession::DdsConnectionParams connParams(m_session->connParams());
LtsSessionData::LtsSessionData::getInstance()->setPartitionPreset(connParams.partitionId, connParams.partitionType); // skip exc chooser
LtsPluginManager::LtsPluginManager *app = LtsAppManager::LtsAppManager::getInstance()->createApp(LtsAppDescriptor::App::OrgChart, connParams);
connect(app, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
this, [this, app, data, connParams]()
{
disconnect(app, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
this, nullptr);
LtsSession::LtsSession *session = app->getSession(connParams.partitionType, connParams.partitionId);
if (session == nullptr)
{
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Could not start Organisation Application properly."));
return;
}
if (!session->getForeignGuiInterface(m_ppmGuiOrgChartIfc))
{
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Unable to start Organisation Application properly."));
return;
}
m_ppmGuiOrgChartIfc->loadTemplate(data.templateId(), m_asSupportService);
});
//LtsSessionData::LtsSessionData::getInstance()->clear();
}
void ParticipantTemplateChooser::onRemoveTemplate()
{
QModelIndex idx = m_ui->widget->currentIndex();
if (!idx.isValid())
return;
const TemplateParticipant tmplParticipant = m_model->getRowData(idx.row());
auto tmplData = m_dtc->convertFromParticipantTemplateToTemplateData(tmplParticipant);
tmplData.isDeleted(true);
ModifyTemplateDataRequest req;
req.data({tmplData});
m_requestHelper->startSingleRequest([this, req]()
{
return m_ftc->modifyTemplateDataRequest(req, this);
});
}
void ParticipantTemplateChooser::onPrint()
{
LtsPrinting::printView(m_session, this, m_ui->widget->treeView() );
}
} //namespace ParticipantManagement
@@ -0,0 +1,76 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Overview Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include "participant_template_chooser_model.h"
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_org_chart_gui_plugin.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <LtsUtilsGuiDds/request_helper.h>
namespace AdvancedSymbology
{
class ForeignDataInterface;
}
namespace Ui
{
class ParticipantTemplateChooser;
}
namespace ParticipantManagement
{
class ParticipantTemplateChooser : public LtsWidgets::LtsDialog
, protected ParticipantManagement::Interface::Ftc::ModifyTemplateDataReplyHandler
{
Q_OBJECT
public:
explicit ParticipantTemplateChooser(const QString &menuGroup, bool asSupportService, LtsSession::LtsSession *session, QWidget *parent = nullptr);
~ParticipantTemplateChooser();
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<ForeignGuiOrgChartInterface> &ppmGuiOrgChartIfc);
private slots:
void onAddTemplate();
void onEditTemplate();
void onEditTemplateOrgChart();
void onRemoveTemplate();
void onPrint();
private:
void retranslate() override;
void onModifyTemplateDataReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
void tableColumnOrganiserSetting() override;
QString m_menuGroup;
bool m_asSupportService;
ParticipantTemplateChooserModel *m_model;
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<ParticipantManagement::ForeignGuiOrgChartInterface> m_ppmGuiOrgChartIfc;
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbIfc;
LtsSession::LtsSession *m_session;
LtsUtils::RequestHelper *m_requestHelper;
Ui::ParticipantTemplateChooser *m_ui;
LOGGER_T m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantTemplateChooser</class>
<widget class="QWidget" name="ParticipantTemplateChooser">
<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>
@@ -0,0 +1,69 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Insert Template Frameless Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "participant_template_chooser_frameless.h"
#include "ui_participant_template_chooser_frameless.h"
#include "CustomView/template.h"
#include "participant_template_edit.h"
namespace ParticipantManagement
{
ParticipantTemplateChooserFrameless::ParticipantTemplateChooserFrameless(LtsSession::LtsSession *session, QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_model(nullptr)
, m_dtc(nullptr)
, m_session(session)
, m_ui(new Ui::ParticipantTemplateChooserFrameless)
, m_logger(getLogger("ParticipantTemplateChooser"))
{
m_ui->setupUi(this);
m_ui->widget->setSelectionMode(QAbstractItemView::SingleSelection);
}
ParticipantTemplateChooserFrameless::~ParticipantTemplateChooserFrameless()
{
delete m_ui;
}
bool ParticipantTemplateChooserFrameless::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc)
{
if (!dtc)
return false;
m_dtc = dtc;
m_model = new ParticipantTemplateChooserModel(m_session->partitionId(), this);
m_model->initModel(m_session, m_dtc);
m_ui->widget->setModel(m_model, [this]() { return new CustomViewTemplate(this); });
m_ui->ltsDialogButtonBox->connectButton(LtsWidgets::DialogButton::Add, this, &ParticipantTemplateChooserFrameless::onAddTemplate);
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
//HACK as close is not allowed directly
connect(m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &ParticipantTemplateChooserFrameless::close);
return true;
}
//SLOTS
void ParticipantTemplateChooserFrameless::onAddTemplate()
{
QModelIndex idx = m_ui->widget->currentIndex();
if (!idx.isValid())
return;
TemplateParticipant data = m_model->getRowData(m_ui->widget->currentIndex().row());
emit selectedTemplate(data.templateId());
close();
}
} //namespace ParticipantManagement
@@ -0,0 +1,51 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Insert Template Frameless Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include "participant_template_chooser_model.h"
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <LtsWidgets/lts_frameless_dialog.h>
#include <LtsSession/lts_session.h>
namespace Ui
{
class ParticipantTemplateChooserFrameless;
}
namespace ParticipantManagement
{
class ParticipantTemplateChooserFrameless : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
explicit ParticipantTemplateChooserFrameless(LtsSession::LtsSession *session, QWidget *parent = nullptr);
~ParticipantTemplateChooserFrameless();
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc);
private Q_SLOTS:
void onAddTemplate();
Q_SIGNALS:
void selectedTemplate(int);
private:
ParticipantTemplateChooserModel *m_model;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
LtsSession::LtsSession *m_session;
Ui::ParticipantTemplateChooserFrameless *m_ui;
LOGGER_T m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantTemplateChooserFrameless</class>
<widget class="QWidget" name="ParticipantTemplateChooserFrameless">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>593</width>
<height>607</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>
<item>
<widget class="LtsWidgets::LtsDialogButtonBox" name="ltsDialogButtonBox"/>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsDialogButtonBox</class>
<extends>QWidget</extends>
<header>LtsWidgets/lts_dialog_button_box.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,146 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "participant_template_chooser_model.h"
#include <Plugins/ParticipantManagement/ppm_mime_datas.h>
#include <ParticipantManagement/ppm_translation.h>
#include <LtsSession/lts_session_data_dds.h>
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
#include <QMimeData>
namespace ParticipantManagement
{
//---------------------------------
// ParticipantTemplateChooserModel
//---------------------------------
ParticipantTemplateChooserModel::ParticipantTemplateChooserModel(bool asSupportService, QObject *parent)
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::TemplateParticipant>({tr("Designator/Identifier"),
tr("Type Class"),
tr("Type")},
parent)
, AdvancedSymbology::TableModelSymbolRenderer<ParticipantTemplateChooserModel>(ColDesignatorIdentifier)
, m_asSupportService(asSupportService)
, m_dtc(nullptr)
, m_logger(getLogger("ParticipantTemplateChooserModel"))
{}
ParticipantTemplateChooserModel::~ParticipantTemplateChooserModel()
{}
bool ParticipantTemplateChooserModel::initModel(LtsSession::LtsSessionDataDds *session,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc)
{
if (!dtc)
return false;
// optional
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
AdvancedSymbology::TableModelSymbolRenderer<ParticipantTemplateChooserModel>::init(asb, this);
m_dtc = dtc;
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::templateParticipantChanged ,
this, &ParticipantTemplateChooserModel::onTemplateChanged);
// insert Model
auto cb = [this](const ParticipantManagement::TemplateParticipant &templateData)
{
if (insertRow(templateData))
tryRenderSymbol(QString::fromStdString(templateData.symbol()), templateData.templateId());
};
m_dtc->templateParticipants(cb);
return true;
}
QVariant ParticipantTemplateChooserModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index) || (role != Qt::DisplayRole && role != Qt::DecorationRole))
return QVariant();
const ParticipantManagement::TemplateParticipant &templateData = m_vecData.at(index.row());
if (role == Qt::DecorationRole)
return decorationData(index, templateData.templateId());
switch (index.column())
{
case ColDesignatorIdentifier:
{
if (templateData.designator().size() == 0)
return QString::fromStdString(templateData.tacticalIdentifier());
return QString(QString::fromStdString(templateData.designator()) + QLatin1Char('/') +
QString::fromStdString(templateData.tacticalIdentifier()));
}
case ColTypeClass:
return ParticipantManagement::toString(m_dtc->type(templateData.typeId()).typeClass());
case ColType:
return ParticipantManagement::trTypeName(m_dtc->type(templateData.typeId()).name());
}
return QVariant();
}
Qt::ItemFlags ParticipantTemplateChooserModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags retFlags = QAbstractTableModel::flags(index);
retFlags |= Qt::ItemIsDragEnabled;
return retFlags;
}
QMimeData *ParticipantTemplateChooserModel::mimeData(const QModelIndexList &indexes) const
{
QMimeData *mimeData = new QMimeData();
for (const QModelIndex &index : indexes)
{
if (index.isValid())
{
QByteArray encodedData = QByteArray::number(getRowData(index.row()).templateId());
mimeData->setData(ParticipantManagement::ParticipantTemplateRoot, encodedData);
return mimeData;
}
}
return mimeData;
}
QStringList ParticipantManagement::ParticipantTemplateChooserModel::mimeTypes() const
{
return { ParticipantManagement::ParticipantTemplateRoot };
}
void ParticipantTemplateChooserModel::onTemplateChanged(const ParticipantManagement::TemplateParticipant &data,
DataModification modType)
{
if (onDataChanged(data, modType) && modType != DataModification::eRemoved)
tryRenderSymbol(QString::fromStdString(data.symbol()), data.templateId());
}
bool ParticipantTemplateChooserModel::isFiltered(const TemplateParticipant &data, DataModification modType) const
{
Q_UNUSED(modType);
if (data.superiorTemplateId() != 0)
return true;
const TypeClass &tc = m_dtc->type(data.typeId()).typeClass();
if (m_asSupportService)
return (tc != TypeClass::SupportEntity && tc != TypeClass::SupportUnit);
return (tc == TypeClass::SupportEntity || tc == TypeClass::SupportUnit);
}
} // namespace ParticipantManagement
@@ -0,0 +1,72 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10.05
*/
#pragma once
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/logger.h>
#include <LtsWidgets/lts_abstract_table_model.h>
#include <Plugins/AdvancedSymbology/Helper/table_model_symbol_renderer.h>
namespace LtsSession
{
class LtsSessionDataDds;
}
namespace ParticipantManagement
{
// --------------------------------------------------------
// ParticipantTemplateChooserModel
// --------------------------------------------------------
class ParticipantTemplateChooserModel final : public LtsWidgets::LtsAbstractTableModel<ParticipantManagement::TemplateParticipant>
, public AdvancedSymbology::TableModelSymbolRenderer<ParticipantTemplateChooserModel>
{
Q_OBJECT
friend class AdvancedSymbology::TableModelSymbolRenderer<ParticipantTemplateChooserModel>;
public:
enum Columns
{
ColDesignatorIdentifier,
ColTypeClass,
ColType
};
explicit ParticipantTemplateChooserModel(bool asSupportService, QObject *parent = nullptr);
~ParticipantTemplateChooserModel();
bool initModel(LtsSession::LtsSessionDataDds *session,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc);
QVariant data(const QModelIndex &, int) const override final;
Qt::ItemFlags flags(const QModelIndex &index) const override;
QMimeData *mimeData(const QModelIndexList &indexes) const override;
QStringList mimeTypes() const override;
Qt::DropActions supportedDragActions() const override { return Qt::CopyAction; }
protected:
int getId(const TemplateParticipant &data) const override
{
return data.templateId();
}
private slots:
void onTemplateChanged(const ParticipantManagement::TemplateParticipant &data,
DataModification modType);
private:
bool isFiltered(const TemplateParticipant &data, DataModification modType) const override;
bool m_asSupportService;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
LOGGER_T m_logger;
};
} //namespace ParticipantManagement
@@ -0,0 +1,448 @@
/**
* @RDE_HEADER@
* template-Editor
* $Id$
* $HeadURL$
* $Author$
*/
#include "participant_template_edit.h"
#include "ui_participant_template_edit.h"
#include <Plugins/ParticipantManagement/Gui/Common/participant_template_edit_item.h>
#include <Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h>
#include "participant_template_chooser_frameless.h"
#include <ParticipantManagement/Gui/Common/participant_firing_unit_validator.h>
#include <QMenu>
#include <nglwidgets/ngltreeitem.h>
#include <LtsPrinting/printing.h>
#include <QTreeView>
namespace ParticipantManagement
{
ParticipantTemplateEdit::ParticipantTemplateEdit(LtsSession::LtsSession *session,
int rootId,
bool asSupportService,
QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_rootId(rootId)
, m_asSupportService(asSupportService)
, m_bNeedCommitModifedData(true)
, m_model(nullptr)
, m_actionInsertTemplate(nullptr)
, m_actionSaveAsNewTemplate(nullptr)
, m_actionRemove(nullptr)
, m_actionEdit(nullptr)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_session(session)
, m_ui(new Ui::ParticipantTemplateEdit)
, m_logger(getLogger("ParticipantTemplateEdit"))
{
m_ui->setupUi(this);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &ParticipantTemplateEdit::onAddItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &ParticipantTemplateEdit::onEditItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &ParticipantTemplateEdit::onRemoveItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &ParticipantTemplateEdit::onPrint);
// ein Apply führt zu aufwendigen Update im Template-Baum - erst einmal hide da Ok ausreichen sollte
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->hide();
if (m_asSupportService)
setOnlineHelpFilename(QStringLiteral("Administrator-Support_Templates"));
else
setOnlineHelpFilename(QStringLiteral("Administrator-Participant_Templates"));
}
//----------------------------------------------------------------------------
ParticipantTemplateEdit::~ParticipantTemplateEdit()
{
delete m_ui;
}
void ParticipantTemplateEdit::retranslate()
{
translate(m_ui, m_asSupportService ? tr("Support Template Editor") : tr("Participant Template Editor"));
}
bool ParticipantTemplateEdit::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
{
if (!dtc || !ftc || !ppmGuiCbxIfc)
return false;
m_dtc = dtc;
m_ftc = ftc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
m_asbIfc = asbIfc;
m_model = new ParticipantTemplateEditModel(this, m_dtc, asbIfc, m_rootId);
// View treeView :
m_ui->treeViewEdit->setModel(m_model);
m_ui->treeViewEdit->hideColumn(ParticipantTemplateEditModel::ColTypeClass);
m_ui->treeViewEdit->expandAll();
for (int i = 0; i < m_model->columnCount(QModelIndex()); ++i)
m_ui->treeViewEdit->resizeColumnToContents(i);
m_ui->treeViewEdit->header()->resizeSection(0, m_ui->treeViewEdit->columnWidth(0) + m_ui->treeViewEdit->iconSize().width() + 10);
QPushButton *pbInsert = m_buttonBox->getButton(LtsWidgets::DialogButton::Import);
pbInsert->setText(tr("Insert Template"));
pbInsert->setVisible(true);
connect(pbInsert, &QPushButton::clicked,
this, &ParticipantTemplateEdit::onInsertTemplate);
QPushButton *pbSaveAs = m_buttonBox->getButton(LtsWidgets::DialogButton::Export);
pbSaveAs->setText(tr("Save as Template"));
pbSaveAs->setVisible(true);
connect(pbSaveAs, &QPushButton::clicked,
this, &ParticipantTemplateEdit::onSaveAsNewTemplate);
// ContextMenu :
m_ui->treeViewEdit->setContextMenuPolicy(Qt::CustomContextMenu);
connect(m_ui->treeViewEdit, &QTreeView::customContextMenuRequested,
this, &ParticipantTemplateEdit::slotCustomContextMenuRequested);
connect(m_ui->treeViewEdit, &QTreeView::doubleClicked,
this, &ParticipantTemplateEdit::onDoubleClicked);
// ContextMenu actions :
m_actionInsertTemplate = new QAction(pbInsert->icon(), pbInsert->text(), this);
connect(m_actionInsertTemplate, &QAction::triggered,
this, &ParticipantTemplateEdit::onInsertTemplate);
m_actionSaveAsNewTemplate = new QAction(pbSaveAs->icon(), pbSaveAs->text(), this);
connect(m_actionSaveAsNewTemplate, &QAction::triggered,
this, &ParticipantTemplateEdit::onSaveAsNewTemplate);
QPushButton *pbRemove = m_buttonBox->getButton(LtsWidgets::DialogButton::Remove);
m_actionRemove = new QAction(pbRemove->icon(), pbRemove->text(), this);
connect(m_actionRemove, &QAction::triggered,
this, &ParticipantTemplateEdit::onRemoveItem);
QPushButton *pbEdit = m_buttonBox->getButton(LtsWidgets::DialogButton::Edit);
m_actionEdit = new QAction(pbEdit->icon(), pbEdit->text(), this);
connect(m_actionEdit, &QAction::triggered, this,
&ParticipantTemplateEdit::onEditItem);
// SelectionModel :
QItemSelectionModel *selectionModel = m_ui->treeViewEdit->selectionModel();
connect(selectionModel, &QItemSelectionModel::selectionChanged,
this, &ParticipantTemplateEdit::onSelectionChanged);
selectionModel->clearSelection();
enaDisa();
connect(m_model, &ParticipantTemplateEditModel::internalDataChanged, this, &ParticipantTemplateEdit::slotChangesMade);
if (m_firingUnitValidator)
delete m_firingUnitValidator;
m_firingUnitValidator = new FiringUnitValidator(m_dtc, this);
return true;
}
void ParticipantTemplateEdit::onModifyTemplateDataReply(const Core::FunctionReplyObject &replyObject)
{
enaDisa();
if (m_bNeedCommitModifedData && !replyObject.error())
m_model->dataCommitted();
m_requestHelper->requestReply(replyObject);
}
QModelIndex ParticipantTemplateEdit::selectedIndexView() const
{
QItemSelectionModel *selectionModel = m_ui->treeViewEdit->selectionModel();
QModelIndexList indexL = selectionModel->selectedRows(0);
if (indexL.size() == 0)
return QModelIndex();
return indexL.at(0);
}
bool ParticipantTemplateEdit::isContainer(const QModelIndex &index)
{
Q_UNUSED(index);
if (!selectedIndexView().isValid())
return false;
int typeId = m_model->privateData(selectedIndexView())->data().value<ParticipantManagement::TemplateData>().typeId();
if (typeId <= 0)
return false;
if (m_asSupportService)
return m_dtc->type(typeId).typeClass() == ParticipantManagement::TypeClass_def::SupportUnit;
else
return m_dtc->type(typeId).typeClass() == ParticipantManagement::TypeClass_def::Unit;
}
void ParticipantTemplateEdit::enaDisa()
{
QModelIndex selIndex = selectedIndexView();
bool enableAdd = false;
bool enableEdit = false;
bool enableRemove = false;
bool enableSaveAsTemplate = false;
if (selIndex.isValid())
{
if (isContainer(selIndex)) //only add to units
{
enableSaveAsTemplate = true;
enableAdd = true;
if (m_firingUnitValidator)
enableAdd &= m_firingUnitValidator->hasUnitCapacities(m_model, selIndex);
}
enableEdit = true;
enableRemove = selIndex.parent().isValid();
}
m_actionInsertTemplate->setEnabled(enableAdd);
m_actionSaveAsNewTemplate->setEnabled(enableSaveAsTemplate);
m_actionRemove->setEnabled(enableRemove);
m_actionEdit->setEnabled(enableEdit);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, enableAdd);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, m_actionEdit->isEnabled());
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, m_actionRemove->isEnabled());
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Import, m_actionInsertTemplate->isEnabled());
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Export, m_actionSaveAsNewTemplate->isEnabled());
}
void ParticipantTemplateEdit::removeCurrentRow()
{
QModelIndex selIndex = selectedIndexView();
NGLTreeItem *item = m_model->privateData(selIndex);
ParticipantManagement::TemplateData tmpl = item->data().value<ParticipantManagement::TemplateData>();
const bool isRootTemplate = (tmpl.templateId() == m_rootId);
if (!selIndex.isValid() || isRootTemplate)
return;
/** with or without question :
if(m_model->hasChildren(selIndex)) {
if(QMessageBox::No == QMessageBox::question(this,
tr ("Einheit loeschen"),
tr("Moechten Sie das Element mit allen Untereinheiten wirklich loeschen?"),
QMessageBox::Yes|QMessageBox::No)) {
return;
}
} else { // no childs :
if(QMessageBox::No == QMessageBox::question(this,
tr("Einheit loeschen"),
tr("Moechten Sie das Element wirklich loeschen?"),
QMessageBox::Yes|QMessageBox::No)) {
return;
}
}
*/
m_model->onDeleteRow(selIndex, true);
}
//slots
void ParticipantTemplateEdit::onAddItem()
{
ParticipantTemplateEditItem *newItemDlg = new ParticipantTemplateEditItem(m_asSupportService,
m_session,
this);
const bool addItem = true;
ParticipantManagement::TemplateData data = ParticipantManagement::TemplateData();
QModelIndex selIndex = selectedIndexView();
if (selIndex.isValid())
{
ParticipantManagement::TemplateData dataAll = m_model->privateData(selIndex)->data().value<ParticipantManagement::TemplateData>();
data.designator(dataAll.designator());
data.tacticalIdentifier(dataAll.tacticalIdentifier());
}
if (!newItemDlg->init(selIndex, m_dtc, m_ppmGuiCbxIfc, m_asbIfc, data, addItem))
{
delete newItemDlg;
return;
}
newItemDlg->setUsedEquipmentNumbers(m_model->usedEquipmentNumbers());
newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
connect(newItemDlg, &ParticipantTemplateEditItem::rejected, newItemDlg, &ParticipantTemplateEditItem::deleteLater);
connect(newItemDlg, &ParticipantTemplateEditItem::addItem, this, &ParticipantTemplateEdit::onAddItemToModel);
connect(this, &ParticipantTemplateEdit::usedEquipmentNumbersChanged, newItemDlg, &ParticipantTemplateEditItem::setUsedEquipmentNumbers);
if (m_firingUnitValidator)
{
newItemDlg->setIsAdler(m_firingUnitValidator->isAdler(m_model, selIndex));
const int unitGearClassType = m_firingUnitValidator->getGearClassType(m_model, selIndex);
newItemDlg->setFiringUnitRestrictions(m_model, false, m_firingUnitValidator->getRestrictions(m_model, selIndex), m_firingUnitValidator, unitGearClassType);
connect(newItemDlg, &ParticipantTemplateEditItem::addItem, this, [this, newItemDlg, unitGearClassType] (const QModelIndex &parent, const TemplateData &newData)
{
Q_UNUSED(newData)
if (!newItemDlg || !m_firingUnitValidator)
return;
newItemDlg->setFiringUnitRestrictions(m_model, false, m_firingUnitValidator->getRestrictions(m_model, parent), m_firingUnitValidator, unitGearClassType);
});
}
newItemDlg->show();
}
void ParticipantTemplateEdit::onEditItem()
{
QModelIndex selIndex = selectedIndexView();
if (!selIndex.isValid())
return;
ParticipantManagement::TemplateData data = m_model->privateData(selIndex)->data().value<ParticipantManagement::TemplateData>();
ParticipantTemplateEditItem *newItemDlg = new ParticipantTemplateEditItem(m_asSupportService,
m_session,
this);
if (!newItemDlg->init(selIndex, m_dtc, m_ppmGuiCbxIfc, m_asbIfc, data))
{
delete newItemDlg;
return;
}
newItemDlg->setUsedEquipmentNumbers(m_model->usedEquipmentNumbers());
newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
connect(newItemDlg, &ParticipantTemplateEditItem::updateItem, this, &ParticipantTemplateEdit::onModifyItemInModel);
connect(this, &ParticipantTemplateEdit::usedEquipmentNumbersChanged, newItemDlg, &ParticipantTemplateEditItem::setUsedEquipmentNumbers);
if (m_firingUnitValidator)
{
const int unitGearClassType = m_firingUnitValidator->getGearClassType(m_model, selIndex);
newItemDlg->setFiringUnitRestrictions(m_model, true, m_firingUnitValidator->getRestrictions(m_model, selIndex), m_firingUnitValidator, unitGearClassType);
}
newItemDlg->show();
}
void ParticipantTemplateEdit::onRemoveItem()
{
removeCurrentRow();
}
void ParticipantTemplateEdit::onPrint()
{
LtsPrinting::printView(m_session, this, m_ui->treeViewEdit );
}
bool ParticipantTemplateEdit::apply()
{
ModifyTemplateDataRequest req;
req.data(m_model->templateData());
if (req.data().size() == 0)
return true;
m_bNeedCommitModifedData = true;
return m_requestHelper->startSingleRequest([this, req]()
{
return m_ftc->modifyTemplateDataRequest(req, this);
});
}
void ParticipantTemplateEdit::onInsertTemplate()
{
QModelIndex selIndex = selectedIndexView();
if (!selIndex.isValid())
return;
ParticipantTemplateChooserFrameless *templateChooser = new ParticipantTemplateChooserFrameless(m_session, this);
if (!templateChooser->init(m_dtc))
{
delete templateChooser;
return;
}
connect(templateChooser, &ParticipantTemplateChooserFrameless::selectedTemplate, this, &ParticipantTemplateEdit::onAddTemplateToModel);
connect(templateChooser, &ParticipantTemplateChooserFrameless::rejected, templateChooser, &ParticipantTemplateChooserFrameless::deleteLater);
templateChooser->show();
}
void ParticipantTemplateEdit::onAddTemplateToModel(int templateId)
{
m_model->onInsertTemplate(templateId, selectedIndexView(), true);
}
void ParticipantTemplateEdit::onSaveAsNewTemplate()
{
QModelIndex selIndex = selectedIndexView();
if (!selIndex.isValid())
return;
ModifyTemplateDataRequest req;
req.data(m_model->templateDataAsCopy(selIndex));
if (req.data().size() == 0)
return;
m_bNeedCommitModifedData = false;
m_requestHelper->startSingleRequest([this, req]()
{
return m_ftc->modifyTemplateDataRequest(req, this);
});
}
void ParticipantTemplateEdit::onAddItemToModel(const QModelIndex &parent, const TemplateData &templateData)
{
bool ret = m_model->onInsertRow(parent, templateData);
int typeId = m_model->privateData(parent)->data().value<ParticipantManagement::TemplateData>().typeId();
if (!ret && typeId <= 0)
return;
Type type = m_dtc->type(typeId);
if (type.typeClass() == TypeClass::Unit ||
type.typeClass() == TypeClass::SupportUnit)
{
m_ui->treeViewEdit->setExpanded(m_ui->treeViewEdit->selectionModel()->selectedIndexes().at(0), true);
}
emit usedEquipmentNumbersChanged(m_model->usedEquipmentNumbers());
}
void ParticipantTemplateEdit::onModifyItemInModel(const QModelIndex &index, const TemplateData &editData)
{
m_model->onUpdateRow(index, editData);
emit usedEquipmentNumbersChanged(m_model->usedEquipmentNumbers());
}
void ParticipantTemplateEdit::onDoubleClicked(const QModelIndex &selIndex)
{
if (!selIndex.isValid())
return;
onEditItem();
}
void ParticipantTemplateEdit::onSelectionChanged(const QItemSelection & /*selected*/,
const QItemSelection & /*deselected*/)
{
DEBUG_LOG(m_logger) << "onSelectionChanged";
enaDisa();
}
void ParticipantTemplateEdit::slotCustomContextMenuRequested(const QPoint &position)
{
QModelIndex selIndex = selectedIndexView();
if (!selIndex.isValid())
return;
enaDisa();
QMenu menu(m_ui->treeViewEdit);
menu.addAction(m_actionInsertTemplate);
menu.addAction(m_actionSaveAsNewTemplate);
menu.addSeparator();
menu.addAction(m_actionRemove);
menu.addSeparator();
menu.addAction(m_actionEdit);
menu.exec(m_ui->treeViewEdit->viewport()->mapToGlobal(position));
}
} //namespace ParticipantManagement
@@ -0,0 +1,116 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Edit Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include <ParticipantManagement/Gui/Common/participant_template_edit_model.h>
#include <ParticipantManagement/logger.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <LtsUtilsGuiDds/request_helper.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
class NGLTreeItem;
class QItemSelection;
namespace Ui
{
class ParticipantTemplateEdit;
}
namespace ParticipantManagement
{
class FiringUnitValidator;
//----------------------------------------------------------------------------
class ParticipantTemplateEdit : public LtsWidgets::LtsDialog
, protected ParticipantManagement::Interface::Ftc::ModifyTemplateDataReplyHandler
{
Q_OBJECT
public:
ParticipantTemplateEdit(LtsSession::LtsSession *session,
int rootId,
bool asSupportService,
QWidget *parent = nullptr);
virtual ~ParticipantTemplateEdit();
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc);
void onModifyTemplateDataReply(const Core::FunctionReplyObject &replyObject) override final;
public Q_SLOTS:
bool apply() override final;
private:
void retranslate() override;
QModelIndex selectedIndexView() const;
bool isContainer(const QModelIndex &index);
void enaDisa(); // enable/disable the widgets
void removeCurrentRow();
signals:
void signalTeTemplateInserted();
void signalAccept();
void usedEquipmentNumbersChanged(const QSet<int> &usedEquipmentNumbers);
protected slots:
void onAddItem();
void onEditItem();
void onRemoveItem();
void onPrint();
void onInsertTemplate();
void onAddTemplateToModel(int templateId);
void onSaveAsNewTemplate();
void onAddItemToModel(const QModelIndex &parent, const TemplateData &templateData);
void onModifyItemInModel(const QModelIndex &index, const TemplateData &editData);
void onDoubleClicked(const QModelIndex &selIndex);
void onSelectionChanged(const QItemSelection & /*selected*/,
const QItemSelection & /*deselected*/);
void slotCustomContextMenuRequested(const QPoint &position);
private:
int m_rootId;
bool m_asSupportService;
bool m_bNeedCommitModifedData;
ParticipantTemplateEditModel *m_model;
QAction *m_actionInsertTemplate;
QAction *m_actionSaveAsNewTemplate;
QAction *m_actionRemove;
QAction *m_actionEdit;
LtsUtils::RequestHelper *m_requestHelper;
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<AdvancedSymbology::ForeignDataInterface> m_asbIfc;
LtsSession::LtsSession *m_session;
FiringUnitValidator *m_firingUnitValidator { nullptr };
Ui::ParticipantTemplateEdit *m_ui;
NGL::INGLLogger &m_logger;
};
} //ParticipantManagement
@@ -0,0 +1,54 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantTemplateEdit</class>
<widget class="QWidget" name="ParticipantTemplateEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string notr="true">setwindowtitle in source</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lblTemplates">
<property name="text">
<string>Templates:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="treeViewEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
<property name="iconSize">
<size>
<width>22</width>
<height>22</height>
</size>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,118 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - ParticipantTemplate
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "participant_templates_gui_plugin.h"
#include "participant_template_chooser.h"
#include "participant_template_chooser_model.h"
#include "participant_template_edit.h"
#include <LtsWidgets/lts_base_layout_widget.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <QGridLayout>
#include <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.ParticipantTemplates"))
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_ppmGuiOrgChartIfc(nullptr)
{}
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
{
QVector<LtsWidgets::PluginData> ret;
//no dialoges in exercise
if(m_session->partitionType() == IDL::PartitionType::Exercise)
return ret;
LtsWidgets::PluginData pd;
pd.menuGroup = menuGroup();
pd.layoutArea = LtsWidgets::LayoutArea::eDialogTab;
pd.menuText = tr("Participant Templates");
pd.identifier = QStringLiteral("viewTemplates");
pd.menuIcon = QIcon(QLatin1String("icon:define_force_templates.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onShowTemplateChooser(parent, false); };
pd.operatorRight = OperatorRights::ParticipantTemplates::ParticipantTemplatesShow;
pd.exercisePart = LtsWidgets::ExercisePart::ePlanning;
ret.append(pd);
pd.menuText = tr("Support Templates");
pd.identifier = QStringLiteral("viewSupTemplates");
pd.menuIcon = QIcon(QLatin1String("icon:define_force_templates.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onShowTemplateChooser(parent, true); };
pd.operatorRight = OperatorRights::ParticipantTemplates::SupportParticipantTemplatesShow;
pd.exercisePart = LtsWidgets::ExercisePart::ePlanning;
ret.append(pd);
return ret;
}
QString InterfaceImpl::menuGroup() const
{
return tr("Participants");
}
bool InterfaceImpl::getTemplateModel(QTreeView *treeView, bool asSupportService)
{
ParticipantTemplateChooserModel *model = new ParticipantTemplateChooserModel(asSupportService, treeView);
if (model->initModel(m_session, m_dtc))
{
treeView->setModel(model);
return true;
}
return false;
}
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;
//optional
m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiOrgChartInterface>(m_ppmGuiOrgChartIfc);
return true;
}
void InterfaceImpl::clearInterfaces()
{
m_dtc = nullptr;
m_ftc = nullptr;
m_ppmGuiCbxIfc = nullptr;
m_ppmGuiOrgChartIfc = nullptr;
}
LtsWidgets::LtsDialog *InterfaceImpl::onShowTemplateChooser(QWidget *parent, bool asSupportService)
{
return LtsWidgets::initDialog(new ParticipantTemplateChooser(menuGroup(), asSupportService, m_session, parent),
m_dtc, m_ftc, m_ppmGuiCbxIfc, m_ppmGuiOrgChartIfc);
}
} // namespace ParticipantManagement
@@ -0,0 +1,74 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - ParticipantManagement
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_templates_gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_org_chart_gui_plugin.h>
#include <QTreeView>
namespace ParticipantManagement
{
class ParticipantTemplateChooserModel;
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
{
Q_PLUGIN_METADATA(IID "gui:3:ppm.template")
Q_INTERFACES(GuiPluginBase::Plugin)
Q_OBJECT
public:
GuiPlugin() = default;
~GuiPlugin() = default;
QString pluginName() override { return QStringLiteral("ParticipantManagement.GuiPlugin.ParticipantTemplates"); }
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 ForeignGuiTemplatesInterface, public GuiPluginBase::Interface
{
Q_OBJECT
public:
explicit InterfaceImpl(LtsSession::LtsSession *session);
QVector<LtsWidgets::PluginData> getActions() override;
bool fetchInterfaces() override;
void clearInterfaces() override;
QString menuGroup() const override;
bool availableInPartition(IDL::PartitionType partition) const override
{
return partition == IDL::PartitionType::Global ||
partition == IDL::PartitionType::Exercise;
}
bool getTemplateModel(QTreeView *treeView, bool asSupportService) override final;
private:
LtsWidgets::LtsDialog *onShowTemplateChooser(QWidget *parent, bool asSupportService = false);
private:
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<ParticipantManagement::ForeignGuiOrgChartInterface> m_ppmGuiOrgChartIfc;
};
} // namespace ParticipantManagement
@@ -0,0 +1,98 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Name Template Unit Frameless Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-07
*/
#include "template_unit_namer.h"
#include "ui_template_unit_namer.h"
#include <LtsSession/lts_session_manager.h>
namespace ParticipantManagement
{
TemplateUnitNamer::TemplateUnitNamer(bool asSupportService, const std::shared_ptr<Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_asSupportService(asSupportService)
, m_dtc(dtc)
, m_ppmGuiCbxIfc(ppmGuiCbxIfc)
, m_ui(new Ui::TemplateUnitNamer)
, m_validator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("[^,;\"'´`]*")), this))
, m_logger(getLogger("TemplateTemplateChooser"))
{
m_ui->setupUi(this);
if (!m_ppmGuiCbxIfc || !m_dtc)
return;
m_ui->leDesignator->setValidator(m_validator);
m_ui->leTactIdentifier->setValidator(m_validator);
connect(m_ui->cbxTypeClass,
static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
this,
&TemplateUnitNamer::onTypeClassChanged);
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Ok)->setVisible(false);
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Apply)->setVisible(false);
m_ui->ltsDialogButtonBox->connectButton(LtsWidgets::DialogButton::Add, this, &TemplateUnitNamer::onSetUnitName);
m_ui->ltsDialogButtonBox->setText(LtsWidgets::DialogButton::Add, tr("Add"));
connect(m_ui->leTactIdentifier, &QLineEdit::textChanged, this, &TemplateUnitNamer::enaDisa);
//HACK as close is not allowed directly
connect(m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &TemplateUnitNamer::close);
const int filter = m_asSupportService ? ForeignGuiComboboxInterface::eOcUnits : ForeignGuiComboboxInterface::eUnits;
m_ppmGuiCbxIfc->fillTypeClassComboBox(m_ui->cbxTypeClass, filter);
onTypeClassChanged();
}
TemplateUnitNamer::~TemplateUnitNamer()
{
delete m_ui;
}
//SLOTS
void ParticipantManagement::TemplateUnitNamer::onSetUnitName()
{
ParticipantManagement::TemplateData templateData;
templateData.modId(1);
templateData.hierarchyNumber(1);
templateData.designator(m_ui->leDesignator->text().toStdString());
templateData.tacticalIdentifier(m_ui->leTactIdentifier->text().toStdString());
templateData.typeId(m_ui->cbxType->currentData().toInt());
templateData.symbol(m_dtc->type(templateData.typeId()).symbol());
emit newUnitTemplateRoot(templateData);
close();
}
void TemplateUnitNamer::onTypeClassChanged()
{
TypeClass currentClass(static_cast<TypeClass_def::type>(m_ui->cbxTypeClass->currentData().toInt()));
m_ppmGuiCbxIfc->fillTypeComboBox(m_ui->cbxType, currentClass);
enaDisa();
}
void TemplateUnitNamer::enaDisa()
{
m_ui->ltsDialogButtonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, (!m_ui->leTactIdentifier->text().isEmpty() &&
m_ui->cbxType->count()));
}
} //namespace ParticipantManagement
@@ -0,0 +1,54 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Name Template Unit Frameless Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-07
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <LtsWidgets/lts_frameless_dialog.h>
#include <memory>
namespace Ui
{
class TemplateUnitNamer;
}
namespace ParticipantManagement
{
class TemplateUnitNamer : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
explicit TemplateUnitNamer(bool asSupportService,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
QWidget *parent = nullptr);
~TemplateUnitNamer();
private:
void onSetUnitName();
void onTypeClassChanged();
void enaDisa();
Q_SIGNALS:
void newUnitTemplateRoot(const ParticipantManagement::TemplateData &);
private:
bool m_asSupportService;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
Ui::TemplateUnitNamer *m_ui;
QValidator *m_validator;
LOGGER_T m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TemplateUnitNamer</class>
<widget class="QWidget" name="TemplateUnitNamer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>429</width>
<height>176</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Type Class:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="LtsWidgets::LtsComboBox" name="cbxTypeClass">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="LtsWidgets::LtsComboBox" name="cbxType">
<property name="minimumSize">
<size>
<width>200</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Designator:</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tactical Identifier:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLineEdit" name="leDesignator">
<property name="maxLength">
<number>8</number>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="leTactIdentifier">
<property name="maxLength">
<number>20</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="6" column="0" colspan="3">
<widget class="LtsWidgets::LtsDialogButtonBox" name="ltsDialogButtonBox"/>
</item>
<item row="4" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>/</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsDialogButtonBox</class>
<extends>QWidget</extends>
<header>LtsWidgets/lts_dialog_button_box.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>cbxTypeClass</tabstop>
<tabstop>cbxType</tabstop>
<tabstop>leDesignator</tabstop>
<tabstop>leTactIdentifier</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>