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,75 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Mike Wille, SLSE, 2016-09-06
#
#
# Data Plugin
#
SET(participant_common_gui_SRCS
participant_dis_helper.cpp
participant_dis_helper.h
participant_dis_type_edit.cpp
participant_dis_type_edit.h
participant_distype_editor.cpp
participant_distype_editor.h
participant_edit_item.cpp
participant_edit_item.h
participant_edit_item_widget_base.cpp
participant_edit_item_widget_base.h
participant_edit_model.cpp
participant_edit_model.h
participant_firing_unit_validator.cpp
participant_firing_unit_validator.h
participant_icon_model_base.cpp
participant_icon_model_base.h
participant_search_modal.cpp
participant_search_modal.h
participant_time_point_model.cpp
participant_time_point_model.h
participant_template_edit_item.cpp
participant_template_edit_item.h
participant_template_edit_model.cpp
participant_template_edit_model.h
participant_tree_edit_handler.cpp
participant_tree_edit_handler.h
participant_vulnerability_types.cpp
participant_vulnerability_types.h
participant_beautify_view.h
participant_beautify_view.cpp
)
NGL_WRAP_UI(participant_common_gui_SRCS
participant_distype_editor.ui
participant_edit_item_widget_base.ui
participant_dis_type_edit.ui
participant_search_modal.ui
)
NGL_ADD_LIBRARY2(WS PpmCommon SHARED ${participant_common_gui_SRCS} )
NGL_TARGET_LINK_LIBRARIES(PpmCommon
PRIVATE
LtsSession
Qt5::Widgets
NGLLogger
AsbDataPluginInterface
ExmDataPluginInterface
advancedSymbologyGui
LtsUtilsSettings
PUBLIC
Qt5::Core
Qt5::Gui
nglwidgets
svcPpmCommon
LtsDataView
LtsUtilsGuiDds
)
NGL_TARGET_INCLUDE_DIRECTORIES(PpmCommon
PUBLIC
${CMAKE_CURRENT_BINARY_DIR}/../../..
${CMAKE_CURRENT_SOURCE_DIR}/..
)
@@ -0,0 +1,133 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#include "msdl_distype_editor.h"
#include "ui_msdl_distype_editor.h"
#include "msdl_types.h"
#include <LtsWidgets/lts_message_dialog.h>
#include <ParticipantManagement/ppm_translation.h>
#include <Common/participant_dis_helper.h>
#include <set>
namespace msdl
{
DistypeEditor::DistypeEditor(QWidget *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ppmFtc)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_ppmDtc(ppmDtc)
, m_ppmFtc(ppmFtc)
, m_pDISTypeEdit(nullptr)
, mUi(new Ui_MSDLDistypeEditor)
{
mUi->setupUi(this);
mUi->m_pushButton_Apply->setEnabled(false);
m_pDISTypeEdit = new ParticipantManagement::DIS::DISTypeEdit(this, m_ppmDtc, m_ppmFtc);
m_pDISTypeEdit->useMinimumListWidgetHeight(250);
connect(m_pDISTypeEdit, &ParticipantManagement::DIS::DISTypeEdit::signalChangesMade, this, &DistypeEditor::slotDISTypeEditChangesMade);
mUi->m_verticalLayout->insertWidget(1, m_pDISTypeEdit);
m_mapTypes = m_ppmDtc->types();
std::set<ParticipantManagement::TypeClass> setTypeClasses;
for (const ParticipantManagement::Type &type : qAsConst(m_mapTypes))
{
const ParticipantManagement::TypeClass typeClassId = type.typeClass();
if (typeClassId == ParticipantManagement::TypeClass::SupportUnit || typeClassId == ParticipantManagement::TypeClass::SupportEntity)
continue;
setTypeClasses.insert(typeClassId);
}
for (const auto &typeClassId : setTypeClasses)
mUi->m_ltsComboBox_typeClass->addItem(ParticipantManagement::toString(typeClassId), typeClassId.underlying());
slotTypeClassChanged();
connect(mUi->m_ltsComboBox_typeClass, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &DistypeEditor::slotTypeClassChanged);
connect(mUi->m_ltsComboBox_type, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &DistypeEditor::slotTypeChanged);
connect(mUi->m_pushButton_Apply, &QPushButton::clicked, this, &DistypeEditor::slotApply);
connect(mUi->m_pushButton_Close, &QPushButton::clicked, this, &DistypeEditor::slotClose);
}
DistypeEditor::~DistypeEditor()
{
delete m_requestHelper;
delete mUi;
}
void DistypeEditor::slotDISTypeEditChangesMade()
{
mUi->m_pushButton_Apply->setEnabled(true);
}
void DistypeEditor::slotClose()
{
if (m_pDISTypeEdit->hasChanges())
{
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this, tr("Changes to the DIS type mapping have been done. Do you want to save these changes?"), tr("Unsaved changes"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
if (button == LtsWidgets::Button::Yes)
slotApply();
}
close();
}
void DistypeEditor::slotApply()
{
bool success = false;
while (!(success = m_pDISTypeEdit->apply()))
{
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this, tr("Applied DIS mapping changes could not be saved to database. Do you want to retry?"), tr("Warning"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
if (button == LtsWidgets::Button::No)
break;
}
mUi->m_pushButton_Apply->setEnabled(!success);
}
void DistypeEditor::slotTypeClassChanged()
{
mUi->m_ltsComboBox_type->clear();
int currentTypeClass = mUi->m_ltsComboBox_typeClass->currentData().toInt();
for (const ParticipantManagement::Type &type : qAsConst(m_mapTypes))
{
if (type.typeClass().underlying() != currentTypeClass)
continue;
mUi->m_ltsComboBox_type->addItem(LtsUtils::str2QString(type.name()), type.id());
}
slotTypeChanged();
}
void DistypeEditor::slotTypeChanged()
{
int currentType = mUi->m_ltsComboBox_type->currentData().toInt();
m_pDISTypeEdit->switchType(currentType);
}
}
@@ -0,0 +1,50 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <LtsWidgets/lts_frameless_dialog.h>
#include "zwmsmsdl_export.h"
#include <QMap>
#include <memory>
#include <Common/participant_dis_type_edit.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
#include <LtsUtilsGuiDds/request_helper.h>
class Ui_MSDLDistypeEditor;
namespace msdl
{
class ZWMSMSDL_EXPORT DistypeEditor : public LtsWidgets::LtsFramelessDialog,
protected ParticipantManagement::Interface::Ftc::ModifyTypeReplyHandler
{
Q_OBJECT
public:
DistypeEditor(QWidget *parent, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc, const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ppmFtc);
~DistypeEditor();
void onModifyTypeReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
private slots:
void slotDISTypeEditChangesMade();
void slotTypeClassChanged();
void slotTypeChanged();
void slotClose();
void slotApply();
private:
QMap<int32_t, ParticipantManagement::Type> m_mapTypes;
LtsUtils::RequestHelper *m_requestHelper;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
ParticipantManagement::DIS::DISTypeEdit *m_pDISTypeEdit;
Ui_MSDLDistypeEditor *mUi;
};
}
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MSDLDistypeEditor</class>
<widget class="QWidget" name="MSDLDistypeEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>467</width>
<height>130</height>
</rect>
</property>
<property name="windowTitle">
<string>DIS Type Editor</string>
</property>
<layout class="QVBoxLayout" name="m_verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="LtsWidgets::LtsComboBox" name="m_ltsComboBox_typeClass"/>
</item>
<item row="0" column="2">
<widget class="LtsWidgets::LtsComboBox" name="m_ltsComboBox_type"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="2">
<widget class="QPushButton" name="m_pushButton_Close">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="m_pushButton_Apply">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item row="0" column="0">
<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>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Note: The first element will be used for HLA instantiation.</string>
</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>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,36 @@
/**
* @RDE_HEADER@
* Microsoft does strange things.
* $Id: participant_edit_model.h 52287 2020-10-08 11:54:01Z biedziak_f $
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/commaster/Lts/Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h $
* $Author: biedziak_f $
* Created by Mike Lennart Wille, SLTE, 2023-07-14
*/
#include <Common/participant_beautify_view.h>
#include <QTreeView>
#include <QHeaderView>
#include <QModelIndex>
namespace ParticipantManagement
{
/*
* Column widths are adjusted to the displayed content. Keeps all items expanded
* after identifying the optimal column width if 'keepExpanded' is true.
*/
void beautifyTreeView(QTreeView *tv, QAbstractItemModel *pModel, bool keepExpanded)
{
tv->expandAll();
int colCount = pModel->columnCount(QModelIndex());
for (int i = 0; i < colCount; ++i)
tv->resizeColumnToContents(i);
tv->header()->resizeSection(0, tv->columnWidth(0) + tv->iconSize().width() + 10);
if (!keepExpanded)
tv->collapseAll();
}
} // namespace ParticipantManagement
@@ -0,0 +1,22 @@
/**
* @RDE_HEADER@
* Microsoft does strange things.
* $Id: participant_edit_model.h 52287 2020-10-08 11:54:01Z biedziak_f $
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/commaster/Lts/Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h $
* $Author: biedziak_f $
* Created by Mike Lennart Wille, SLTE, 2023-07-14
*/
#pragma once
#include <Common/ppmcommon_export.h>
class QTreeView;
class QAbstractItemModel;
namespace ParticipantManagement
{
PPMCOMMON_EXPORT void beautifyTreeView(QTreeView *tv, QAbstractItemModel *pModel, bool keepExpanded = true);
} // namespace ParticipantManagement
@@ -0,0 +1,128 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Last, SLSE, 2017-12-01
*/
#include "participant_dis_helper.h"
namespace ParticipantManagement
{
namespace DIS
{
const QRegularExpression gRegExValidDIS(QStringLiteral("\\b([0-9])\\." // 8 Bit: Kind Field, exact values between 0 and 9
"(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\." // 8 bit unspecified: Domain Field
"(26[0-6]|2[0-5][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\." // 16 bit but highest value is 266 which is 'Uzbekistan'
"(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\.){3}" // 4x 8 bit unspecified: Category, Subcategory, Specific, Extra
"(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\\b")); // Disable leading zeros
/*
* Converts a given integer to a MSDL QString which has 21 characters.
* Adds leading zeros if missing.
*
* E.g: 3001222001246001000 (integer) becomes 003001222001246001000 (QString)
*/
QString convertDISTypeInteger2MSDLString(int64_t distype)
{
QString strDisType = QString::number(distype);
// Two leading zeros might be missing if the dis entity kind is small than 10 (-> [0, 255] i spossible]
while (strDisType.size() < 21)
strDisType.insert(0, QLatin1Char('0'));
return strDisType;
}
/*
* Converts a DIS type QString to an integer.
* Adds leading zeros (if missing) to each dis attribute.
*
* Example: 3.1.222.1.246.1.0 -> 3001222001246001000
*/
int64_t convertDISTypeString2Integer(const QString &strDisType)
{
const QStringList list = strDisType.split(QLatin1Char('.'));
if (list.size() != 7)
return -1;
QString strNumber(list[0]); // Prevent leading zeros
for (int i = 1; i < list.size(); ++i)
{
QString attribute = list[i];
while (attribute.size() < 3)
attribute.insert(0, QLatin1Char('0'));
strNumber += attribute;
}
bool ok;
int64_t number = strNumber.toLongLong(&ok, 10);
if (!ok)
return -1;
return number;
}
/*
* Converts a DIS type integer to a QString which can be correct (according to the DIS standard) visualized to the user.
* E.g. 3001222001246001000 (int) becomes 3.1.222.1.246.1.0 (QString)
*/
QString convertDISTypeInteger2DISString(int64_t distype)
{
QString strMSDL = convertDISTypeInteger2MSDLString(distype);
QString strDis;
if (strMSDL.size() != 21)
return strDis;
int index = 0;
for (int i = 0; i < 7; ++i)
{
QString part = strMSDL.mid(index, 3);
part.remove(QRegularExpression(QStringLiteral("^[0]*")));
// It may be possible that a part is "000" which would be completely erased
if (!part.size())
part = QStringLiteral("0");
strDis += part;
if (i != 6)
strDis += QLatin1Char('.');
index += 3;
}
return strDis;
}
int64_t convertMSDLString2Integer(const QString &strMSDL, bool *ok)
{
int64_t number = strMSDL.toLongLong(ok, 10);
return number;
}
QString convertMSDLString2DISString(const QString &strMSDL)
{
bool ok;
int64_t number = convertMSDLString2Integer(strMSDL, &ok);
if (!ok)
return QString();
return convertDISTypeInteger2DISString(number);
}
}
}
@@ -0,0 +1,35 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Last, SLSE, 2017-12-01
*/
#pragma once
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <QString>
#include <QRegularExpression>
namespace ParticipantManagement
{
namespace DIS
{
PPMCOMMON_EXPORT extern const QRegularExpression gRegExValidDIS;
/*
* MSDL-String: 003001222001246001000
* DIS-Integer: 3001222001246001000
* DIS-String : 3.1.222.1.246.1.0
*/
PPMCOMMON_EXPORT QString convertDISTypeInteger2MSDLString(int64_t distype);
PPMCOMMON_EXPORT QString convertDISTypeInteger2DISString(int64_t distype);
PPMCOMMON_EXPORT int64_t convertDISTypeString2Integer(const QString &strDisType);
PPMCOMMON_EXPORT int64_t convertMSDLString2Integer(const QString &strMSDL, bool *ok = nullptr);
PPMCOMMON_EXPORT QString convertMSDLString2DISString(const QString &strMSDL);
}
}
@@ -0,0 +1,259 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#include "participant_dis_type_edit.h"
#include "ui_participant_dis_type_edit.h"
#include "participant_dis_helper.h"
#include <LtsWidgets/lts_message_dialog.h>
#include <ParticipantManagement/ppm_translation.h>
#include <Common/participant_dis_helper.h>
#include <QDebug>
namespace ParticipantManagement
{
namespace DIS
{
DISTypeEdit::DISTypeEdit(QWidget *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc, int32_t typeId)
: QWidget(parent)
, m_typeId(typeId)
, m_ppmDtc(dtc)
, m_ppmFtc(ftc)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, mUi(new Ui_ParticipantDISTypeEdit)
{
mUi->setupUi(this);
connect(mUi->m_listWidget_distypes->model(), &QAbstractItemModel::rowsMoved, this, [this]()
{
m_setTouchedTypes << m_typeId;
m_DisEntitiesByType[m_typeId].clear();
for (int i=0; i< mUi->m_listWidget_distypes->count(); ++i)
m_DisEntitiesByType[m_typeId] << ParticipantManagement::DIS::convertDISTypeString2Integer(mUi->m_listWidget_distypes->item(i)->text());
emit signalChangesMade();
});
auto cbTypes = [this] (const ParticipantManagement::Type &type)
{
m_mapTypes[type.id()] = type;
const ParticipantManagement::TypeClass &typeClassId = type.typeClass();
if (typeClassId == ParticipantManagement::TypeClass::SupportUnit || typeClassId == ParticipantManagement::TypeClass::SupportEntity)
return;
// Update used DIS id map by adding all DIS ids of this type
for (const auto &disId : type.disEntities())
{
if (m_usedDisTypes.contains(disId))
continue;
m_DisEntitiesByType[type.id()] << disId;
// if (m_mapDisStr2TypeId.find(disId) != m_mapDisStr2TypeId.end())
// {
// // Warnung?
// continue;
// }
// //qWarning() << "m_mapDisStr2TypeId: disId: " << disId << ", typeId: " << type.id();
// m_mapDisStr2TypeId[disId] = type.id();
}
};
m_ppmDtc->types(cbTypes);
switchType(m_typeId);
connect(mUi->m_pushButton_AddNewDistype, &QPushButton::clicked,this, &DISTypeEdit::slotAddDistype);
connect(mUi->m_pushButton_RemoveSelectedDistypes, &QPushButton::clicked,this, &DISTypeEdit::slotRemoveSelectedDisTypes);
m_pValidator = new QRegularExpressionValidator(ParticipantManagement::DIS::gRegExValidDIS, this);
mUi->m_lineEdit_newDistype->setValidator(m_pValidator);
checkRemoveButtonStatus();
}
DISTypeEdit::~DISTypeEdit()
{
delete mUi;
}
void DISTypeEdit::useMinimumListWidgetHeight(int minHeight)
{
mUi->m_listWidget_distypes->setMinimumHeight(minHeight);
}
void DISTypeEdit::switchType(int32_t typeId)
{
setEnabled(true);
m_typeId = typeId;
if(m_typeId == 0)
{
setEnabled(false);
return;
}
mUi->m_listWidget_distypes->clear();
for (int64_t disId : qAsConst(m_DisEntitiesByType[m_typeId]))
mUi->m_listWidget_distypes->addItem(DIS::convertDISTypeInteger2DISString(disId));
// If desired: Setting text alignment is done by manipulating the actual Item object
checkRemoveButtonStatus();
}
bool DISTypeEdit::hasChanges() const
{
return m_setTouchedTypes.size();
}
bool DISTypeEdit::apply()
{
if(!hasChanges())
return true;
for(int32_t typeId : qAsConst(m_setTouchedTypes))
{
Type &touchedType = m_mapTypes[typeId];
touchedType.disEntities().clear();
for (int64_t disId : qAsConst(m_DisEntitiesByType[typeId]))
touchedType.disEntities().push_back(disId);
m_requestHelper->addRequest([this, touchedType]()
{
return m_ppmFtc->modifyTypeRequest(touchedType, this);
});
}
bool success = m_requestHelper->startRequests();
if(success)
m_setTouchedTypes.clear();
return success;
}
void DISTypeEdit::checkRemoveButtonStatus()
{
mUi->m_pushButton_RemoveSelectedDistypes->setEnabled(mUi->m_listWidget_distypes->count());
}
QVector<QString> DISTypeEdit::getDISTypes() const
{
QVector<QString> vecDISTypes;
vecDISTypes.reserve(mUi->m_listWidget_distypes->count());
for(int i = 0; i < mUi->m_listWidget_distypes->count(); ++i)
vecDISTypes.push_back(mUi->m_listWidget_distypes->item(i)->text());
return vecDISTypes;
}
void DISTypeEdit::slotAddDistype()
{
QString bgColorRed(QStringLiteral("QLineEdit { background: rgb(255, 0, 0); }"));
QString bgColorWhite(QStringLiteral("QLineEdit { background: rgb(255, 255, 255); }"));
mUi->m_lineEdit_newDistype->setStyleSheet(bgColorWhite);
int pos;
QString strDistype = mUi->m_lineEdit_newDistype->text();
if(m_pValidator->validate(strDistype, pos) != QValidator::Acceptable)
{
mUi->m_lineEdit_newDistype->setStyleSheet(bgColorRed);
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Specified DIS type is invalid. Please verify your input."), tr("DIS type invalid"));
return;
}
// Prevent adding same DIS type twice for the current type class
for(int i = 0; i < mUi->m_listWidget_distypes->count(); ++i)
{
QListWidgetItem* pItem = mUi->m_listWidget_distypes->item(i);
if(pItem->text() == strDistype)
{
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Specified DIS type is already used."), tr("DIS type invalid"));
return;
}
}
// Check whether other type classes make usage of the desired dis type
int64_t disId = ParticipantManagement::DIS::convertDISTypeString2Integer(strDistype);
int oldTypeId = 0;
QMapIterator<int32_t, QVector<int64_t> > it(m_DisEntitiesByType);
while(it.hasNext())
{
for (int64_t mapDisId : it.next().value())
{
if (disId == mapDisId)
{
oldTypeId = it.key();
break;
}
}
if (oldTypeId != 0)
break;
}
// User specified distype already exists? Notify user and ask for remapping
if(oldTypeId > 0)
{
const ParticipantManagement::Type& type = m_mapTypes[oldTypeId];
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this, tr("Specified DIS type is already mapped to:\nType id: %1\nName: \"%2\"\nType class: \"%3\".\nDo you want to change this mapping?").arg(QString::number(type.id()), QString::fromStdString(type.name()), ParticipantManagement::toString(type.typeClass())), tr("DIS type already in use"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
if (button == LtsWidgets::Button::No)
return;
/*
* Two touched types in this case: 'type.id()' from which we take the existing DIS id
* and our m_typeId which receives the taken DIS id
*/
m_setTouchedTypes.insert(oldTypeId);
m_DisEntitiesByType[oldTypeId].removeOne(disId);
}
m_setTouchedTypes.insert(m_typeId);
m_DisEntitiesByType[m_typeId] << disId;
mUi->m_listWidget_distypes->addItem(strDistype);
checkRemoveButtonStatus();
emit signalChangesMade();
}
void DISTypeEdit::slotRemoveSelectedDisTypes()
{
const QList<QListWidgetItem*> selectedItems = mUi->m_listWidget_distypes->selectedItems();
if (selectedItems.isEmpty())
return;
for (const QListWidgetItem *pItem : selectedItems)
{
int64_t disId = ParticipantManagement::DIS::convertDISTypeString2Integer(pItem->text());
m_DisEntitiesByType[m_typeId].removeAll(disId);
m_setTouchedTypes.insert(m_typeId);
delete pItem;
}
checkRemoveButtonStatus();
emit signalChangesMade();
}
}
}
@@ -0,0 +1,71 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <Services/ParticipantManagement/ppm.hpp>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <LtsUtilsGuiDds/request_helper.h>
#include <memory>
#include <QSet>
#include <QMap>
#include <QWidget>
#include <QRegularExpressionValidator>
class Ui_ParticipantDISTypeEdit;
namespace ParticipantManagement
{
namespace DIS
{
class PPMCOMMON_EXPORT DISTypeEdit : public QWidget, protected ParticipantManagement::Interface::Ftc::ModifyTypeReplyHandler
{
Q_OBJECT
public:
DISTypeEdit(QWidget *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
int32_t typeId = 0);
~DISTypeEdit();
bool apply();
bool hasChanges() const;
void useMinimumListWidgetHeight(int minHeight);
void switchType(int32_t typeId);
QVector<QString> getDISTypes() const;
signals:
void signalChangesMade();
private slots:
void slotAddDistype();
void slotRemoveSelectedDisTypes();
private:
void onModifyTypeReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
void checkRemoveButtonStatus();
//void setData(int32_t typeId);
int32_t m_typeId;
QSet<int64_t> m_usedDisTypes;
//QMap<int64_t, int32_t> m_mapDisStr2TypeId; // not sorted, since first entry is default
// typeID DIS-Int
QMap<int32_t, QVector<int64_t> > m_DisEntitiesByType;
QMap<int32_t, ParticipantManagement::Type> m_mapTypes;
QSet<int32_t> m_setTouchedTypes;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
LtsUtils::RequestHelper *m_requestHelper;
QRegularExpressionValidator *m_pValidator;
Ui_ParticipantDISTypeEdit *mUi;
};
}
}
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantDISTypeEdit</class>
<widget class="QWidget" name="ParticipantDISTypeEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>482</width>
<height>393</height>
</rect>
</property>
<property name="windowTitle">
<string>DIS Type Editor</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="m_listWidget_distypes">
<property name="dragDropMode">
<enum>QAbstractItemView::InternalMove</enum>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::MultiSelection</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLineEdit" name="m_lineEdit_newDistype">
<property name="minimumSize">
<size>
<width>220</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="m_pushButton_AddNewDistype">
<property name="text">
<string>Add DIS type</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="m_pushButton_RemoveSelectedDistypes">
<property name="text">
<string>Remove DIS types</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,132 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#include "participant_distype_editor.h"
#include "ui_participant_distype_editor.h"
#include <LtsWidgets/lts_message_dialog.h>
#include <ParticipantManagement/ppm_translation.h>
#include <Common/participant_dis_helper.h>
#include <set>
namespace ParticipantManagement
{
DistypeEditor::DistypeEditor(QWidget *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ppmFtc)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_ppmDtc(ppmDtc)
, m_ppmFtc(ppmFtc)
, m_pDISTypeEdit(nullptr)
, mUi(new Ui_ParticipantDistypeEditor)
{
mUi->setupUi(this);
mUi->m_pushButton_Apply->setEnabled(false);
m_pDISTypeEdit = new ParticipantManagement::DIS::DISTypeEdit(this, m_ppmDtc, m_ppmFtc);
m_pDISTypeEdit->useMinimumListWidgetHeight(250);
connect(m_pDISTypeEdit, &ParticipantManagement::DIS::DISTypeEdit::signalChangesMade, this, &DistypeEditor::slotDISTypeEditChangesMade);
mUi->m_verticalLayout->insertWidget(1, m_pDISTypeEdit);
m_mapTypes = m_ppmDtc->types();
std::set<ParticipantManagement::TypeClass> setTypeClasses;
for (const ParticipantManagement::Type &type : qAsConst(m_mapTypes))
{
const ParticipantManagement::TypeClass typeClassId = type.typeClass();
if (typeClassId == ParticipantManagement::TypeClass::SupportUnit || typeClassId == ParticipantManagement::TypeClass::SupportEntity)
continue;
setTypeClasses.insert(typeClassId);
}
for (const auto &typeClassId : setTypeClasses)
mUi->m_ltsComboBox_typeClass->addItem(ParticipantManagement::toString(typeClassId), typeClassId.underlying());
slotTypeClassChanged();
connect(mUi->m_ltsComboBox_typeClass, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &DistypeEditor::slotTypeClassChanged);
connect(mUi->m_ltsComboBox_type, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &DistypeEditor::slotTypeChanged);
connect(mUi->m_pushButton_Apply, &QPushButton::clicked, this, &DistypeEditor::slotApply);
connect(mUi->m_pushButton_Close, &QPushButton::clicked, this, &DistypeEditor::slotClose);
}
DistypeEditor::~DistypeEditor()
{
delete m_requestHelper;
delete mUi;
}
void DistypeEditor::slotDISTypeEditChangesMade()
{
mUi->m_pushButton_Apply->setEnabled(true);
}
void DistypeEditor::slotClose()
{
if (m_pDISTypeEdit->hasChanges())
{
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this, tr("Changes to the DIS type mapping have been done. Do you want to save these changes?"), tr("Unsaved changes"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
if (button == LtsWidgets::Button::Yes)
slotApply();
}
close();
}
void DistypeEditor::slotApply()
{
bool success = false;
while (!(success = m_pDISTypeEdit->apply()))
{
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this, tr("Applied DIS mapping changes could not be saved to database. Do you want to retry?"), tr("Warning"),
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
if (button == LtsWidgets::Button::No)
break;
}
mUi->m_pushButton_Apply->setEnabled(!success);
}
void DistypeEditor::slotTypeClassChanged()
{
mUi->m_ltsComboBox_type->clear();
int currentTypeClass = mUi->m_ltsComboBox_typeClass->currentData().toInt();
for (const ParticipantManagement::Type &type : qAsConst(m_mapTypes))
{
if (type.typeClass().underlying() != currentTypeClass)
continue;
mUi->m_ltsComboBox_type->addItem(QString::fromStdString(type.name()), type.id());
}
slotTypeChanged();
}
void DistypeEditor::slotTypeChanged()
{
int currentType = mUi->m_ltsComboBox_type->currentData().toInt();
m_pDISTypeEdit->switchType(currentType);
}
}
@@ -0,0 +1,49 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
*/
#pragma once
#include <LtsWidgets/lts_frameless_dialog.h>
#include <QMap>
#include <memory>
#include <Common/participant_dis_type_edit.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
#include <LtsUtilsGuiDds/request_helper.h>
class Ui_ParticipantDistypeEditor;
namespace ParticipantManagement
{
class PPMCOMMON_EXPORT DistypeEditor : public LtsWidgets::LtsFramelessDialog,
protected ParticipantManagement::Interface::Ftc::ModifyTypeReplyHandler
{
Q_OBJECT
public:
DistypeEditor(QWidget *parent, const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc, const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ppmFtc);
~DistypeEditor();
void onModifyTypeReply(const Core::FunctionReplyObject &replyObject) override { m_requestHelper->requestReply(replyObject); }
private slots:
void slotDISTypeEditChangesMade();
void slotTypeClassChanged();
void slotTypeChanged();
void slotClose();
void slotApply();
private:
QMap<int32_t, ParticipantManagement::Type> m_mapTypes;
LtsUtils::RequestHelper *m_requestHelper;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ppmFtc;
ParticipantManagement::DIS::DISTypeEdit *m_pDISTypeEdit;
Ui_ParticipantDistypeEditor *mUi;
};
}
@@ -0,0 +1,99 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantDistypeEditor</class>
<widget class="QWidget" name="ParticipantDistypeEditor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>467</width>
<height>385</height>
</rect>
</property>
<property name="windowTitle">
<string>DIS Type Editor</string>
</property>
<layout class="QVBoxLayout" name="m_verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="1">
<widget class="LtsWidgets::LtsComboBox" name="m_ltsComboBox_typeClass"/>
</item>
<item row="0" column="2">
<widget class="LtsWidgets::LtsComboBox" name="m_ltsComboBox_type"/>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="2">
<widget class="QPushButton" name="m_pushButton_Close">
<property name="text">
<string>Close</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="m_pushButton_Apply">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Apply</string>
</property>
</widget>
</item>
<item row="0" column="0">
<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>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Note: The first element will be used for HLA instantiation.</string>
</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>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,520 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Edit Item Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_edit_item.h"
#include "ui_participant_edit_item_widget_base.h"
#include <ParticipantManagement/ppm_translation.h>
#include <QStandardItemModel>
namespace ParticipantManagement
{
//
// ParticipantEditItemWidget
//
ParticipantEditItemWidget::ParticipantEditItemWidget(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: ParticipantEditItemWidgetBase(asSupportService, session, parent)
, m_isOrgChart(false)
{
connect(m_ui->tbAssignment, &QToolButton::clicked, this, &ParticipantEditItemWidget::onTbAssignmentClicked);
connect(m_ui->cbExternal, &QCheckBox::clicked, this, &ParticipantEditItemWidget::setAssignmentButton);
connect(m_ui->sbEquipNr, QOverload<int>::of(&QSpinBox::valueChanged), this, &ParticipantEditItemWidget::onEqNoChanged);
m_ui->tbAssignment->setCheckable(false);
m_ui->tbAssignment->setAutoRaise(false);
}
bool ParticipantEditItemWidget::init(const QModelIndex &workingIndex,
int partyId,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantManagement::ParticipantData &data,
bool isOrgChart,
const bool addItem,
const QVector<int> &usedEquipmentNumbers)
{
m_isOrgChart = isOrgChart;
m_editData = data;
m_currentAssignState = data.assignState();
m_partyId = partyId;
m_bEditMode = m_editData.typeId() > 0;
m_workingIndex = workingIndex;
m_alreadyAddedEquipmentNumbers = usedEquipmentNumbers;
return ParticipantEditItemWidgetBase::init(dtc, ppmGuiCbxIfc, asb, addItem);
}
void ParticipantEditItemWidget::setFiringUnitRestrictions(ParticipantEditModel *model, bool isEdit, const FiringUnitValidator::FiringUnitRestrictions &restrictions, FiringUnitValidator *firingUnitValidator, const int &unitGearClassType)
{
if (!firingUnitValidator || !model)
return;
if (restrictions.testFlag(FiringUnitValidator::NO_TYPE_CHANGE_ALLOWED))
{
m_ui->cbTypeClass->setDisabled(true);
m_ui->cbType->setDisabled(true);
if (isEdit) // if we are in edit mode (and not add), type and typeclass are already set where as want them to be
return;
const Type allowedType = firingUnitValidator->getAllowedType(model, m_workingIndex);
if (allowedType == Type())
return;
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(allowedType.typeClass().underlying()));
m_ui->cbType->setCurrentIndex(m_ui->cbType->findData(allowedType.id()));
return;
}
if (restrictions.testFlag(FiringUnitValidator::ONLY_SAME_GEAR_CLASS_ARTILLERY_ALLOWED))
{
if (isEdit)
return;
const QVector<Type> allowedTypes = firingUnitValidator->artilleryParticipantTypes();
m_ui->cbTypeClass->setDisabled(true);
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(allowedTypes.at(0).typeClass().underlying()));
m_ui->cbType->clear();
std::function<bool(Type)> funcIsSameGearType = [=](const Type &t)
{
if (m_isAdler)
return m_dtc->isAdlerType(t.id()) && (firingUnitValidator->getGearClassType(t.id()) == unitGearClassType);
return firingUnitValidator->getGearClassType(t.id()) == unitGearClassType;
};
QVector<Type>::ConstIterator typeIterator = std::find_if(allowedTypes.begin(), allowedTypes.end(), funcIsSameGearType);
if(typeIterator != allowedTypes.end())
{
m_ui->cbType->setDisabled(true);
m_ui->cbType->addItem(ParticipantManagement::trTypeName(typeIterator->name()), typeIterator->id());
}
else
{
for (const Type &currentType : allowedTypes)
m_ui->cbType->addItem(ParticipantManagement::trTypeName(currentType.name()), currentType.id());
m_ui->cbType->model()->sort(0);
}
m_ui->cbType->setCurrentIndex(0);
return;
}
if (isEdit && restrictions.testFlag(FiringUnitValidator::NO_FIRING_UNIT_TYPE_ALLOWED))
{
m_disabledTypeIds.unite(firingUnitValidator->firingUnitTypeIds());
QStandardItemModel *cbTypeModel = qobject_cast<QStandardItemModel *>(m_ui->cbType->model());
if (cbTypeModel == nullptr)
return;
for (int row = 0; row < m_ui->cbType->count(); ++row)
{
QStandardItem *item = cbTypeModel->item(row);
int typeId = item->data(Qt::UserRole).toInt();
if (!m_disabledTypeIds.contains(typeId))
continue;
item->setFlags(Qt::NoItemFlags);
}
}
if (restrictions.testFlag(FiringUnitValidator::NO_ARTILLERY_PARTICIPANTS_ALLOWED))
{
m_disabledTypeIds.unite(firingUnitValidator->artilleryParticipantTypeIds());
QStandardItemModel *cbTypeModel = qobject_cast<QStandardItemModel *>(m_ui->cbType->model());
if (cbTypeModel == nullptr)
return;
for (int row = 0; row < m_ui->cbType->count(); ++row)
{
QStandardItem *item = cbTypeModel->item(row);
int typeId = item->data(Qt::UserRole).toInt();
if (!m_disabledTypeIds.contains(typeId))
continue;
item->setFlags(Qt::NoItemFlags);
}
}
}
void ParticipantEditItemWidget::setData()
{
m_ui->leDesignator->setText(QString::fromStdString(m_editData.designator()));
m_ui->leTactIdent->setText(QString::fromStdString(m_editData.tacticalIdentifier()));
m_ui->leInfo->setText(QString::fromStdString(m_editData.info()));
m_ui->leSign->setText(QString::fromStdString(m_editData.identification()));
m_ui->cbExternal->setChecked(m_editData.externalId() > 0);
m_ui->leVerein->setText(QString::fromStdString(m_editData.name()));
Type type = m_dtc->type(m_editData.typeId());
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(type.typeClass().underlying()));
m_ui->cbType->setCurrentIndex(m_ui->cbType->findData(type.id()));
//set assingment first
setAssignmentButton();
if (isUnitType(m_editData.typeId()))
{
m_ui->cbTypeClass->setEnabled(false);
m_ui->sbEquipNr->setEnabled(false);
m_ui->tbAssignment->setEnabled(false); //units never get equipments and never reset
bool showVerein = m_dtc->isAdlerType(m_editData.typeId());
m_ui->lblVerein->setVisible(showVerein);
m_ui->leVerein->setVisible(showVerein);
}
else
{
const bool isEquipped = m_editData.equipmentNumber().is_set() && m_editData.equipmentNumber().get() > 0;
m_ui->cbTypeClass->setEnabled(!isEquipped);
m_ui->cbType->setEnabled(!isEquipped);
m_ui->sbEquipNr->setEnabled(m_editData.typeId() > 0);
}
if (m_editData.equipmentNumber().is_set())
m_ui->sbEquipNr->setValue(m_editData.equipmentNumber().get());
onChangeSymbol(QString::fromStdString(m_editData.symbol()));
// Saab Participants
if (m_editData.externalId() > 0)
{
m_ui->leTactIdent->setEnabled(false); // Set from OrbatImport or via HLA
m_ui->sbEquipNr->setEnabled(false); // EqNo cannot be changed on Saab Players
m_ui->tbAssignment->setEnabled(false);
// m_ui->leSign->setEnabled(); // I let it changeable at the moment...
}
}
void ParticipantEditItemWidget::setDesignatorData()
{
m_ui->leDesignator->setText(QString::fromStdString(m_editData.designator()));
m_ui->leTactIdent->setText(QString::fromStdString(m_editData.tacticalIdentifier()));
}
void ParticipantEditItemWidget::onAddItem()
{
ParticipantManagement::ParticipantData newParticipantData;
if (!collectParticipantData(newParticipantData))
return;
if (newParticipantData.equipmentNumber().is_set())
m_alreadyAddedEquipmentNumbers.append(newParticipantData.equipmentNumber().get());
DEBUG_LOG(m_logger) << "add item: " << newParticipantData;
if (m_workingIndex.isValid() || m_isOrgChart)
emit addItem(m_workingIndex, newParticipantData);
m_ui->leSign->clear();
m_ui->leInfo->clear();
}
bool ParticipantEditItemWidget::onEditItem()
{
ParticipantManagement::ParticipantData newParticipantData(m_editData);
if (!collectParticipantData(newParticipantData))
return false;
m_editData = newParticipantData;
m_currentAssignState = newParticipantData.assignState();
DEBUG_LOG(m_logger) << "edit item: " << m_editData;
if (m_workingIndex.isValid() || m_isOrgChart)
emit updateItem(m_workingIndex, m_editData);
emit readyToClose();
return true;
}
bool ParticipantEditItemWidget::collectParticipantData(ParticipantManagement::ParticipantData &data)
{
const int newEquipmentNumber = m_ui->sbEquipNr->value();
data.designator(m_ui->leDesignator->text().toStdString());
data.tacticalIdentifier(m_ui->leTactIdent->text().toStdString());
data.symbol(m_sidc.toStdString());
data.typeId(m_ui->cbType->currentData().toInt());
data.partyId(m_partyId);
data.identification(m_ui->leSign->text().toStdString());
data.info(m_ui->leInfo->text().toStdString());
data.assignState(m_currentAssignState);
// Verein is listed in name
data.name(m_ui->leVerein->text().toStdString());
if (newEquipmentNumber > 0)
{
if (newEquipmentNumber < m_typeMinimum)
{
m_ui->lbMinMaxEquipNr->setText(QStringLiteral("<span style=\"color:#aa0000;\">%1</span>").arg(m_ui->lbMinMaxEquipNr->text()));
return false;
}
if (m_editData.equipmentNumber() != newEquipmentNumber)
{
int exerciseId = 0;
if (!m_dtc->isEquipmentExerciseMappingEnabled())
{
m_dtc->enableEquipmentExerciseMapping();
m_dtc->waitForHistoricalDataEquipmentExerciseMapping(3000);
}
if (m_dtc->isEquipmentNumberInUse(newEquipmentNumber, exerciseId) || m_alreadyAddedEquipmentNumbers.contains(newEquipmentNumber))
{
if (m_session->exerciseId() == exerciseId)
{
LtsWidgets::LtsMessageDialog::showMessage(this,
tr("The equipment number is already used by another participant"),
tr("Equipment Number already in use"));
return false;
}
if (m_session->exerciseState() != LtsWidgets::ExcState::eCreated)
{
LtsWidgets::LtsMessageDialog::showMessage(this,
tr("The equipment number is already used by another participant in another exercise"),
tr("Equipment Number already in use"));
return false;
}
}
}
data.equipmentNumber(newEquipmentNumber);
data.externalId(m_ui->cbExternal->isChecked() ? newEquipmentNumber : 0);
m_ui->sbEquipNr->setValue(newEquipmentNumber + 1);
}
else
{
data.equipmentNumber().reset();
data.externalId(0);
}
return true;
}
void ParticipantEditItemWidget::onTbAssignmentClicked()
{
switch (m_currentAssignState.underlying())
{
case ParticipantManagement::ParticipantAssignState::AssignedWms:
m_currentAssignState = ParticipantManagement::ParticipantAssignState::HandoutExcon;
m_ui->sbEquipNr->setValue(0);
break;
case ParticipantManagement::ParticipantAssignState::HandoutWms:
m_currentAssignState = ParticipantManagement::ParticipantAssignState::ExconWmsOverruled;
m_ui->sbEquipNr->setValue(0);
break;
case ParticipantManagement::ParticipantAssignState::HandoutExcon:
case ParticipantManagement::ParticipantAssignState::ExconWmsOverruled:
m_currentAssignState = ParticipantManagement::ParticipantAssignState::NotAssigned;
m_ui->sbEquipNr->setValue(0);
break;
case ParticipantManagement::ParticipantAssignState::NotAssigned:
if (m_editData.assignState() == ParticipantManagement::ParticipantAssignState::ExconWmsOverruled ||
m_editData.assignState() == ParticipantManagement::ParticipantAssignState::HandoutWms)
m_currentAssignState = ParticipantManagement::ParticipantAssignState::ExconWmsOverruled;
else
m_currentAssignState = ParticipantManagement::ParticipantAssignState::HandoutExcon;
break;
}
setAssignmentButton();
}
void ParticipantEditItemWidget::onEqNoChanged()
{
if (m_currentAssignState == ParticipantManagement::ParticipantAssignState::NotAssigned &&
m_ui->sbEquipNr->value() != 0)
{
onTbAssignmentClicked();
return;
}
if (m_editData.assignState() == ParticipantManagement::ParticipantAssignState::AssignedWms)
{
if (m_editData.equipmentNumber().is_set() && m_editData.equipmentNumber().get() == m_ui->sbEquipNr->value())
m_currentAssignState = ParticipantManagement::ParticipantAssignState::AssignedWms;
else
m_currentAssignState = ParticipantManagement::ParticipantAssignState::HandoutExcon;
}
else if (m_editData.assignState() == ParticipantManagement::ParticipantAssignState::HandoutWms)
{
if (m_editData.equipmentNumber().is_set() && m_editData.equipmentNumber().get() == m_ui->sbEquipNr->value())
m_currentAssignState = ParticipantManagement::ParticipantAssignState::HandoutWms;
else
m_currentAssignState = ParticipantManagement::ParticipantAssignState::ExconWmsOverruled;
}
setAssignmentButton();
}
void ParticipantEditItemWidget::setAssignmentButton()
{
switch (m_currentAssignState.underlying())
{
case ParticipantManagement::ParticipantAssignState::AssignedWms:
case ParticipantManagement::ParticipantAssignState::HandoutWms:
{
if (m_editData.assignState().underlying() == ParticipantManagement::ParticipantAssignState::AssignedWms)
m_ui->tbAssignment->setText(tr("WH(A)"));
else
m_ui->tbAssignment->setText(tr("WH(H)"));
//can't override warehouse settings
break;
}
case ParticipantManagement::ParticipantAssignState::HandoutExcon:
{
m_ui->tbAssignment->setText(tr("EXC"));
break;
}
case ParticipantManagement::ParticipantAssignState::ExconWmsOverruled:
{
m_ui->tbAssignment->setText(tr("EXC(+)"));
break;
}
case ParticipantManagement::ParticipantAssignState::NotAssigned:
{
m_ui->tbAssignment->setText(QStringLiteral("-"));
break;
}
}
// Saab Participants: Can be taken down, but need to uncheck "External" first.
if (m_editData.externalId() > 0 && m_ui->cbExternal->isChecked())
{
m_ui->tbAssignment->setEnabled(false);
m_ui->sbEquipNr->setEnabled(false);
return;
}
m_ui->tbAssignment->setEnabled(true);
m_ui->sbEquipNr->setEnabled(true);
}
//
// ParticipantEditItem
//
ParticipantEditItem::ParticipantEditItem(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_editItemWidget(new ParticipantEditItemWidget(asSupportService, session, parent))
, m_buttonBox(new LtsWidgets::LtsDialogButtonBox(this))
{
//HACK as close is not allowed directly
setWindowTitle(tr("Edit Participant"));
connect(m_buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &ParticipantEditItem::close);
connect(m_editItemWidget, &ParticipantEditItemWidget::readyToClose, this, &ParticipantEditItem::close);
//connect to other signals
connect(m_editItemWidget, &ParticipantEditItemWidget::addItem, this, &ParticipantEditItem::addItem);
connect(m_editItemWidget, &ParticipantEditItemWidget::updateItem, this, &ParticipantEditItem::updateItem);
//hide ok and aplly
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->hide();
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
}
bool ParticipantEditItem::init(const QModelIndex &workingIndex,
int partyId,
const std::shared_ptr<Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantData &data,
const bool addItem,
const QVector<int> &usedEquipmentNumbers)
{
const bool isOrgChart = false;
if (!m_editItemWidget->init(workingIndex, partyId, dtc, ppmGuiCbxIfc, asb, data, isOrgChart, addItem, usedEquipmentNumbers))
return false;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_editItemWidget);
layout->addWidget(m_buttonBox);
setLayout(layout);
if (data.typeId() > 0)
{
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, m_editItemWidget, &ParticipantEditItemWidget::onEditItem);
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setText(tr("Apply"));
}
else
{
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, m_editItemWidget, &ParticipantEditItemWidget::onAddItem);
}
return true;
}
void ParticipantEditItem::setFiringUnitRestrictions(ParticipantEditModel *model, bool isEdit, const FiringUnitValidator::FiringUnitRestrictions &restrictions, FiringUnitValidator *firingUnitValidator, const int unitGearClassType)
{
if (restrictions == FiringUnitValidator::NO_RESTRICTION)
return;
if (restrictions.testFlag(FiringUnitValidator::IS_AT_MAX_CAPACITY))
m_buttonBox->getButton(LtsWidgets::DialogButton::Add)->setDisabled(true);
if (m_editItemWidget)
m_editItemWidget->setFiringUnitRestrictions(model, isEdit, restrictions, firingUnitValidator, unitGearClassType);
}
//
// ParticipantEditItemTab
//
ParticipantEditItemTab::ParticipantEditItemTab(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
, m_editItemWidget(new ParticipantEditItemWidget(asSupportService, session, this))
{
connect(m_editItemWidget, &ParticipantEditItemWidget::updateItem, this, &ParticipantEditItemTab::updateItem);
connect(m_editItemWidget, &ParticipantEditItemWidget::readyToClose, this, [this]()
{
m_buttonBox->getButton(LtsWidgets::DialogButton::Close)->click();
});
}
void ParticipantEditItemTab::retranslate()
{
// lupdate doesn't like translate(tr("foo")) ...
const QString txt(tr("Participant Item Edit"));
translate(txt);
}
bool ParticipantEditItemTab::init(const std::shared_ptr<Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantData &data,
bool isOrgChart)
{
if (!m_editItemWidget->init(QModelIndex(), data.partyId(), dtc, ppmGuiCbxIfc, asb, data, isOrgChart))
return false;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_editItemWidget);
setLayout(layout);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, m_editItemWidget, &ParticipantEditItemWidget::onEditItem);
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Apply"));
return true;
}
bool ParticipantEditItemTab::apply()
{
return m_editItemWidget->onEditItem();
}
} //namespace ParticipantManagement
@@ -0,0 +1,136 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Edit Item Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#pragma once
#include "participant_edit_item_widget_base.h"
#include <ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <LtsWidgets/lts_frameless_dialog.h>
#include <LtsWidgets/lts_dialog.h>
#include "participant_firing_unit_validator.h"
namespace LtsWidgets
{
class LtsDialogButtonBox;
}
namespace ParticipantManagement
{
class ParticipantEditItemWidget final : public ParticipantEditItemWidgetBase
{
Q_OBJECT
public:
explicit ParticipantEditItemWidget(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent = nullptr);
bool init(const QModelIndex &workingIndex,
int partyId,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantData &data,
bool isOrgChart = false,
const bool addItem = false,
const QVector<int> &usedEquipmentNumbers = QVector<int>());
void setFiringUnitRestrictions(ParticipantEditModel *model,
bool isEdit,
const FiringUnitValidator::FiringUnitRestrictions &restrictions,
FiringUnitValidator *firingUnitValidator,
const int &unitGearClassType);
void setIsAdler(bool isAdler) { m_isAdler = isAdler; }
protected:
void setData() override;
void setDesignatorData() override;
public:
void onAddItem() override;
bool onEditItem() override;
bool collectParticipantData(ParticipantManagement::ParticipantData &data);
protected Q_SLOTS:
void onTbAssignmentClicked();
void setAssignmentButton();
void onEqNoChanged();
protected:
int editTypeId() const override { return m_editData.typeId(); }
int currentPartyId() const override { return m_editData.partyId() > 1 ? m_editData.partyId() : m_partyId; }
private:
ParticipantManagement::ParticipantAssignState getAssignmentState() const;
Q_SIGNALS:
void addItem(const QModelIndex &parent, const ParticipantData &newData);
void updateItem(const QModelIndex &parent, const ParticipantData &editData);
private:
QModelIndex m_workingIndex;
ParticipantManagement::ParticipantAssignState m_currentAssignState;
int m_partyId;
bool m_isOrgChart;
bool m_isAdler {false};
ParticipantData m_editData;
QVector<int32_t> m_alreadyAddedEquipmentNumbers;
};
class PPMCOMMON_EXPORT ParticipantEditItem final : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
ParticipantEditItem(bool asSupportService, LtsSession::LtsSession *session, QWidget *parent = nullptr);
bool init(const QModelIndex &workingIndex, int partyId,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantData &data = ParticipantData(),
const bool addItem = false,
const QVector<int> &usedEquipmentNumbers = QVector<int>());
void setIsAdler(bool isAdler) { m_editItemWidget->setIsAdler(isAdler); }
void setFiringUnitRestrictions(ParticipantEditModel *model,
bool isEdit,
const FiringUnitValidator::FiringUnitRestrictions &restrictions,
FiringUnitValidator *firingUnitValidator,
const int unitGearClassType);
Q_SIGNALS:
void addItem(const QModelIndex &parent, const ParticipantData &newData);
void updateItem(const QModelIndex &parent, const ParticipantData &editData);
private:
ParticipantEditItemWidget *m_editItemWidget;
LtsWidgets::LtsDialogButtonBox *m_buttonBox;
};
class PPMCOMMON_EXPORT ParticipantEditItemTab final : public LtsWidgets::LtsDialog
{
Q_OBJECT
public:
ParticipantEditItemTab(bool asSupportService, LtsSession::LtsSession *session, QWidget *parent = nullptr);
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantData &data = ParticipantData(), bool isOrgChart = false);
Q_SIGNALS:
void addItem(int &row, const QModelIndex &parent, const ParticipantData &newData, bool asCopy);
void updateItem(const QModelIndex &parent, const ParticipantData &editData);
private:
void retranslate() override;
bool apply() override;
private:
ParticipantEditItemWidget *m_editItemWidget;
};
} // namespace ParticipantManagement
@@ -0,0 +1,293 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Edit Item Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_edit_item.h"
#include "ui_participant_edit_item_widget_base.h"
#include <ParticipantManagement/ppm_translation.h>
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
#include <ExerciseManagement/exm_data_plugin_interface.h>
#include <Symbology/symbol_data_to_render_role.h>
#include <SymbologyGui/base_symbol_lookup_dialog.h>
#include <SymbologyGui/symbol_modification_dialog.h>
#include <Symbology/sidc_codec.h>
#include <LtsUtilsSettings/settings.h>
#include <QStandardItemModel>
namespace ParticipantManagement
{
//
// ParticipantEditItemWidgetBase
//
static int s_lastTypeClassUsed = ParticipantManagement::TypeClass_def::Human;
static int s_lastTypeUsed = -1;
ParticipantEditItemWidgetBase::ParticipantEditItemWidgetBase(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: QWidget(parent)
, m_asSupportService(asSupportService)
, m_bEditMode(false)
, m_typeMinimum(0)
, m_validator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("[^,;\"'´`]*")), this))
, m_symbolConfig(nullptr)
, m_symbolWatcher(nullptr)
, m_dtc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_session(session)
, m_ui(new Ui::ParticipantEditItemWidgetBase)
, m_logger(getLogger("ParticipantEditItemWidgetBase"))
{
m_ui->setupUi(this);
setWindowTitle(tr("Edit Participant"));
connect(m_ui->pbIcon, &QToolButton::clicked, this, &ParticipantEditItemWidgetBase::onSymbolSelection);
connect(m_ui->pbSymbolConfig, &QToolButton::clicked, this, &ParticipantEditItemWidgetBase::onSymbolConfig);
connect(m_ui->cbTypeClass, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
this, &ParticipantEditItemWidget::onFillTypeCb);
connect(m_ui->cbType, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
this, &ParticipantEditItemWidget::onChangeMinMax);
m_ui->sbEquipNr->setEnabled(false);
m_ui->pbSymbolConfig->setEnabled(false);
m_ui->leDesignator->setValidator(m_validator);
m_ui->leTactIdent->setValidator(m_validator);
std::shared_ptr<ExerciseManagement::Interface::Dtc> exmDtc;
session->getDtc<ExerciseManagement::DataInterface>(exmDtc);
const bool hasHlaInterface = (LtsUtils::ProjectSettings::isFunctionEnabled(QStringLiteral("Exercises"),
QStringLiteral("HasHlaInterface"))
&& exmDtc
&& exmDtc->exercise(m_session->exerciseId()).hasHlaInterface());
if (!hasHlaInterface)
{
m_ui->cbExternal->hide();
m_ui->lblExternal->hide();
}
m_ui->lblVerein->hide();
m_ui->leVerein->hide();
}
constexpr unsigned short getUnsignedShortValue(const int value)
{
// return (value < USHRT_MAX ? value : USHRT_MAX);
return (value < 50000 ? value : 50000);
}
ParticipantEditItemWidgetBase::~ParticipantEditItemWidgetBase()
{
s_lastTypeClassUsed = m_ui->cbTypeClass->currentData().toInt();
s_lastTypeUsed = m_ui->cbType->currentData().toInt();
delete m_ui;
}
void ParticipantEditItemWidgetBase::slotRetranslate()
{
int filter = ForeignGuiComboboxInterface::eAll;
if (m_bEditMode)
{
if (isUnitType(editTypeId()))
filter = (m_asSupportService ? ForeignGuiComboboxInterface::eOcUnits : ForeignGuiComboboxInterface::eUnits);
else
filter = (m_asSupportService ? ForeignGuiComboboxInterface::eOc : ForeignGuiComboboxInterface::eParticipants);
}
else
{
filter = (m_asSupportService ? ForeignGuiComboboxInterface::eOc | ForeignGuiComboboxInterface::eOcUnits
: ForeignGuiComboboxInterface::eParticipants | ForeignGuiComboboxInterface::eUnits);
}
m_ppmGuiCbxIfc->fillTypeClassComboBox(m_ui->cbTypeClass, filter);
onFillTypeCb();
}
bool ParticipantEditItemWidgetBase::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const bool addItem)
{
DEBUG_LOG(m_logger) << "init addItem=" << addItem
<< " m_bEditMode=" << m_bEditMode;
if (!dtc || !ppmGuiCbxIfc)
return false;
m_dtc = dtc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
m_asbfc = asb;
m_ui->cbTypeClass->clear();
m_symbolWatcher = new AdvancedSymbology::SymbolResultWatcherQWidget<QToolButton>(m_ui->pbIcon);
slotRetranslate();
if (addItem)
{
DEBUG_LOG(m_logger) << "setDesignatorData()";
setDesignatorData();
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(s_lastTypeClassUsed));
const int idx = m_ui->cbType->findData(s_lastTypeUsed);
if (idx != -1)
m_ui->cbType->setCurrentIndex(idx);
}
else if (m_bEditMode)
{
DEBUG_LOG(m_logger) << "setData()";
setData();
}
return true;
}
void ParticipantEditItemWidgetBase::onFillTypeCb()
{
QSignalBlocker blocker(m_ui->cbType);
TypeClass currentClass(static_cast<TypeClass_def::type>(m_ui->cbTypeClass->currentData().toInt()));
m_ppmGuiCbxIfc->fillTypeComboBox(m_ui->cbType, currentClass);
if (!m_disabledTypeIds.isEmpty())
{
QStandardItemModel *cbTypeModel = qobject_cast<QStandardItemModel *>(m_ui->cbType->model());
if (cbTypeModel == nullptr)
return;
for (int row = 0; row < m_ui->cbType->count(); ++row)
{
QStandardItem *item = cbTypeModel->item(row);
int typeId = item->data(Qt::UserRole).toInt();
if (!m_disabledTypeIds.contains(typeId))
continue;
item->setFlags(Qt::NoItemFlags);
}
}
onChangeMinMax();
}
void ParticipantEditItemWidgetBase::onChangeMinMax()
{
const ParticipantManagement::Type type = m_dtc->type(m_ui->cbType->currentData().toInt());
const ParticipantManagement::EquipmentType eqType = m_dtc->equipmentType(type.equipmentTypeId());
m_ui->lbMinMaxEquipNr->setText(QString::number(getUnsignedShortValue(eqType.minEquipNo())) + QLatin1Char(':') + QString::number(getUnsignedShortValue(eqType.maxEquipNo())));
m_ui->sbEquipNr->setMaximum(getUnsignedShortValue(eqType.maxEquipNo()));
m_typeMinimum = eqType.minEquipNo();
bool isNoUnit = type.typeClass() != TypeClass::SupportUnit && type.typeClass() != TypeClass::Unit;
if (!isNoUnit)
m_ui->sbEquipNr->setValue(0);
m_ui->sbEquipNr->setEnabled(isNoUnit);
m_ui->tbAssignment->setEnabled(isNoUnit);
// Check Verein
bool showVerein = m_dtc->isAdlerType(type.id());
m_ui->lblVerein->setVisible(showVerein);
m_ui->leVerein->setVisible(showVerein);
onChangeSymbol(QString::fromStdString(type.symbol()));
}
void ParticipantEditItemWidgetBase::onSymbolSelection()
{
AdvancedSymbology::Gui::BaseSymbolLookupDialog *bslDlg =
AdvancedSymbology::Gui::BaseSymbolLookupDialog::showInstance();
connect(bslDlg, &AdvancedSymbology::Gui::BaseSymbolLookupDialog::finished, this, [this, bslDlg]() {
// qCritical() << " finished";
bslDlg->disconnect(this); // !!! disconnect my slots from bslDlg !!!
});
connect(bslDlg, &AdvancedSymbology::Gui::BaseSymbolLookupDialog::lookupAppliedCompleteSidc, this, &ParticipantEditItemWidget::onChangeSymbol);
bslDlg->setParticipantMode(true);
bslDlg->setCurrentSidc(m_sidc);
bslDlg->show();
return;
}
void ParticipantEditItemWidgetBase::onSymbolConfig()
{
if (!m_asbfc)
return;
m_symbolConfig = new AdvancedSymbology::Gui::SymbolModificationDialogFrameless(m_asbfc->getSymbolDictionary(AdvancedSymbology::SymbolDictionary::defaultSymbologyType()), false, this); //Todo Symboltype
m_symbolConfig->setSidc(m_sidc);
connect(m_symbolConfig, &AdvancedSymbology::Gui::SymbolModificationDialogFrameless::sidcOnClose, this, &ParticipantEditItemWidget::onChangeSymbol);
connect(m_symbolConfig, &AdvancedSymbology::Gui::SymbolModificationDialogFrameless::rejected, this, [this]()
{
m_symbolConfig->deleteLater();
m_symbolConfig = nullptr;
});
m_symbolConfig->show();
}
void ParticipantEditItemWidgetBase::onChangeSymbol(const QString &sidc)
{
TRACE_LOG(m_logger) << LOGFUNCTION << ", Changing symbol to " << sidc;
if (!m_asbfc || sidc == m_sidc)
return;
AdvancedSymbology::SymbolDataToRender symDataToRender(sidc);
if (currentPartyId())
{
symDataToRender.role = AdvancedSymbology::roleToRole<>((m_dtc->party(currentPartyId()).role()));
symDataToRender.fillColor = QColor::fromRgb(QRgb(m_dtc->party(currentPartyId()).color()));
symDataToRender.fillColorReplace = true;
} else {
// User-Defined Symbols (XML) need fillColor:
symDataToRender.fillColor = AdvancedSymbology::SymbolDataToRender::unknownColor();
symDataToRender.fillColorReplace = true;
}
m_symbolWatcher->setSymbolResult(m_asbfc->findImage(symDataToRender));
m_sidc = sidc;
if (AdvancedSymbology::SidcCodec::isEncoded(m_sidc))
{
const QString rawSidc = AdvancedSymbology::SidcCodec::decodeRawSidc(m_sidc);
m_ui->pbSymbolConfig->setEnabled(rawSidc.size() && (!AdvancedSymbology::SidcCodec::isCivil(m_sidc)));
}
else
{
ERROR_LOG(m_logger) << LOGFUNCTION << " sidc is not encoded, sidc = '" << sidc << "'";
m_ui->pbSymbolConfig->setEnabled(false);
}
if (m_symbolConfig)
{
m_symbolConfig->deleteLater();
m_symbolConfig = nullptr;
}
DEBUG_LOG(m_logger) << "Changing symbol to " << sidc << " is in progress";
}
ParticipantManagement::TypeClass ParticipantEditItemWidgetBase::typeClassIdFromTypeId(int typeId) const
{
auto it = m_type2TypeClass.find(typeId);
if (it != m_type2TypeClass.end())
return it.value();
auto cbTypes = [this](const ParticipantManagement::Type &type)
{
m_type2TypeClass[type.id()] = type.typeClass();
};
m_dtc->types(cbTypes);
return m_type2TypeClass.value(typeId);
}
bool ParticipantEditItemWidgetBase::isUnitType(int typeId) const
{
const ParticipantManagement::TypeClass typeClassId = typeClassIdFromTypeId(typeId);
return typeClassId == ParticipantManagement::TypeClass::Unit ||
typeClassId == ParticipantManagement::TypeClass::SupportUnit;
}
} //namespace ParticipantManagement
@@ -0,0 +1,97 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Edit Item Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <QWidget>
namespace AdvancedSymbology
{
class ForeignDataInterface;
class SymbolResultWatcherQWidgetBase;
namespace Gui
{
class SymbolModificationDialogFrameless;
class BaseSymbolModel;
class BaseSymbolProxyFilter;
}
}
namespace Ui
{
class ParticipantEditItemWidgetBase;
}
namespace ParticipantManagement
{
class ParticipantEditItemWidgetBase : public QWidget
{
Q_OBJECT
public:
explicit ParticipantEditItemWidgetBase(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent = nullptr);
~ParticipantEditItemWidgetBase();
protected:
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const bool addItem);
virtual void setData() = 0;
virtual void setDesignatorData() = 0;
public Q_SLOTS:
virtual void onAddItem() = 0;
virtual bool onEditItem() = 0;
void slotRetranslate();
protected Q_SLOTS:
void onFillTypeCb();
void onChangeMinMax();
void onSymbolSelection();
void onSymbolConfig();
void onChangeSymbol(const QString &sidc);
protected:
ParticipantManagement::TypeClass typeClassIdFromTypeId(int typeId) const;
bool isUnitType(int typeId) const;
virtual int editTypeId() const = 0;
virtual int currentPartyId() const = 0;
Q_SIGNALS:
void readyToClose();
protected:
bool m_asSupportService;
bool m_bEditMode;
int m_typeMinimum;
QString m_sidc;
QValidator *m_validator;
AdvancedSymbology::Gui::SymbolModificationDialogFrameless *m_symbolConfig;
AdvancedSymbology::SymbolResultWatcherQWidgetBase *m_symbolWatcher;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbfc;
mutable QHash<qint32, ParticipantManagement::TypeClass> m_type2TypeClass;
LtsSession::LtsSession *m_session;
QSet<int> m_disabledTypeIds;
Ui::ParticipantEditItemWidgetBase *m_ui;
LOGGER_T m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,352 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantEditItemWidgetBase</class>
<widget class="QWidget" name="ParticipantEditItemWidgetBase">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>710</width>
<height>245</height>
</rect>
</property>
<property name="windowTitle">
<string>setwindowtitle in source</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="2">
<widget class="QLabel" name="lbMinMaxEquipNr">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="text">
<string notr="true">[00000,00000]:</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="QLabel" name="lbInfo">
<property name="text">
<string>Info:</string>
</property>
</widget>
</item>
<item row="1" column="7" colspan="2">
<widget class="LtsWidgets::LtsComboBox" name="cbType"/>
</item>
<item row="0" column="6">
<widget class="QLabel" name="lbClass">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Class:</string>
</property>
</widget>
</item>
<item row="0" column="7" colspan="2">
<widget class="LtsWidgets::LtsComboBox" name="cbTypeClass"/>
</item>
<item row="0" column="5">
<spacer name="spacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="lbEquipNo">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Equip. No.:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="lbSign">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Sign:</string>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSpinBox" name="sbEquipNr">
<property name="maximum">
<number>9999</number>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QToolButton" name="tbAssignment">
<property name="minimumSize">
<size>
<width>60</width>
<height>0</height>
</size>
</property>
<property name="toolTip">
<string>Assignment</string>
</property>
<property name="statusTip">
<string>Assignment</string>
</property>
<property name="text">
<string notr="true">-</string>
</property>
</widget>
</item>
<item row="4" column="3" colspan="2">
<widget class="QLineEdit" name="leInfo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>40</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QLabel" name="lblSymbol">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Symbol:</string>
</property>
</widget>
</item>
<item row="2" column="9">
<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="3" column="3" colspan="2">
<widget class="QLineEdit" name="leSign">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>150</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QLabel" name="lbType">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Type:</string>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QToolButton" name="pbIcon">
<property name="minimumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="iconSize">
<size>
<width>60</width>
<height>60</height>
</size>
</property>
</widget>
</item>
<item row="2" column="8">
<widget class="QToolButton" name="pbSymbolConfig">
<property name="text">
<string>Configure Symbol</string>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2">
<widget class="QLineEdit" name="leTactIdent">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maxLength">
<number>20</number>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="QLabel" name="lbTactIdent">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Tactical Identifier:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="3">
<widget class="QLabel" name="lbDesignator">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Designator:</string>
</property>
</widget>
</item>
<item row="0" column="3" colspan="2">
<widget class="QLineEdit" name="leDesignator">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>100</width>
<height>0</height>
</size>
</property>
<property name="maxLength">
<number>8</number>
</property>
</widget>
</item>
<item row="3" column="6">
<widget class="QLabel" name="lblExternal">
<property name="text">
<string>External:</string>
</property>
</widget>
</item>
<item row="3" column="7" colspan="2">
<widget class="QCheckBox" name="cbExternal">
<property name="text">
<string>HLA</string>
</property>
</widget>
</item>
<item row="4" column="6">
<widget class="QLabel" name="lblVerein">
<property name="text">
<string>Verein:</string>
</property>
</widget>
</item>
<item row="4" column="7">
<widget class="QLineEdit" name="leVerein"/>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>17</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>leDesignator</tabstop>
<tabstop>leTactIdent</tabstop>
<tabstop>sbEquipNr</tabstop>
<tabstop>tbAssignment</tabstop>
<tabstop>leSign</tabstop>
<tabstop>leInfo</tabstop>
<tabstop>cbTypeClass</tabstop>
<tabstop>cbType</tabstop>
<tabstop>pbIcon</tabstop>
<tabstop>pbSymbolConfig</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>
File diff suppressed because it is too large. Load diff
@@ -0,0 +1,314 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Edit Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include "participant_icon_model_base.h"
#include <ParticipantManagement/logger.h>
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <nglwidgets/ngltreeitem.h>
#include <LtsWidgets/lts_column_filter_proxy_model.h>
#include <QSet>
class QTreeView;
namespace ParticipantManagement
{
class CheckedTreeItem;
class FiringUnitValidator;
//=============================================================================================================================
// PARTICIPANTEDITMODEL
//=============================================================================================================================
class PPMCOMMON_EXPORT ParticipantEditModel : public ParticipantIconModelBase
{
Q_OBJECT
public:
enum Columns
{
ColDesignator,
ColIdentifier,
ColTypeClass,
ColType,
ColEquipmentNumber,
ColParticipantId,
ColInfo,
ColSign
};
class CheckedTreeItem final : public NGLTreeItem
{
public:
using NGLTreeItem::NGLTreeItem;
ParticipantData participant;
bool bIsChecked = false;
};
ParticipantEditModel(QObject *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc);
Qt::ItemFlags flags(const QModelIndex &index) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QVariant data(const QModelIndex &index, int role) const override;
bool setData(const QModelIndex &index, const QVariant &value, int role) override;
bool canDropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) const override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent) override;
Qt::DropActions supportedDropActions() const override { return Qt::MoveAction; }
Qt::DropActions supportedDragActions() const override { return Qt::MoveAction; }
virtual bool onReinitModel(int partyId, const QSet<int> &checkedParticipants = QSet<int>(), Qt::CheckState cs = Qt::Checked);
bool insertRow(int row, const QModelIndex &parent, NGLTreeItem *item);
bool removeRow(int row, const QModelIndex &parent = QModelIndex());
bool isRowRemovable(const CheckedTreeItem *parentItem) const;
bool rowsCheckable() const { return m_bRowsAreCheckable; }
bool unitsSelectable() const { return m_bUnitsSelectable; }
int partyId() const { return m_partyId; }
void dataCommitted();
void processMissingSuperiorId();
void selectItemByParticipantId(int participantId,
const std::function<void(const QModelIndex &)> &selectItem,
const QModelIndex &parent = QModelIndex());
QModelIndexList getIndexesByParticipantIds(const std::vector<int32_t> &participantIds,
const QModelIndex &parent = QModelIndex()) const;
void setRowsCheckable(bool bCheckable);
void setUnitsSelectable(bool bSelectable) { m_bUnitsSelectable = bSelectable; }
bool setCheckStateForParticipants(const QSet<int> &checkedParticipants, Qt::CheckState cs);
ParticipantManagement::ParticipantData getParticipantData(const QModelIndex &idx) const;
std::vector<ParticipantData> participantData(bool bOnlyModified = true) const;
QSet<int> participantIds() const;
QSet<int> checkStateForParticipants(Qt::CheckState cs) const;
QVector<int> usedEquipmentNumbers() const;
CheckedTreeItem *privateData(const QModelIndex &index);
const CheckedTreeItem *privateData(const QModelIndex &index) const;
QModelIndex indexFromParticipantId(int participantId) const;
QString getHierarchyFromIndex(const QModelIndex &index) const;
protected:
void gatherParticipants(QHash<int, ParticipantData> &tmap,
QHash<int, QSet<int>> &parentId2id) const;
std::vector<ParticipantData> getChildrenOf(NGLTreeItem *item,
int parentId,
int hierarchyNumber,
bool bOnlyModifed,
int &highestModId) const;
bool updateChildrenOf(int parentId,
NGLTreeItem *parent,
const QHash<int, QSet<int>> &parentId2id,
const QHash<int, ParticipantData> &tmap);
void insertChildrenOf(int parentId,
NGLTreeItem *parent,
const QModelIndex &parentIdx,
const QHash<int, QSet<int>> &parentId2id,
const QHash<int, ParticipantData> &tmap,
const QSet<int> &checkedParticipants,
Qt::CheckState cs);
bool isParentOf(const NGLTreeItem *item, int participantId) const;
QSet<int> participantIds(NGLTreeItem *parentItem) const;
QSet<int> checkState(CheckedTreeItem *parentItem, Qt::CheckState cs) const;
QVector<int> usedEquipmentNumbers(NGLTreeItem *parentItem) const;
void setCheckState(CheckedTreeItem *parentItem, const QSet<int> &checkedParticipants, Qt::CheckState cs);
QModelIndex indexFromParticipantId(int participantId, const CheckedTreeItem *cti) const;
int participantIdFromItem(NGLTreeItem *item) const;
int equipmentNumberFromItem(NGLTreeItem *item) const;
CheckedTreeItem *searchParticipant(const NGLTreeItem *parentItem, int participantId) const;
NGLTreeItem *createItem(const QVariant &data, const QIcon &icon) const override;
QVariant getItemData(const NGLTreeItem *item) const override;
public slots:
int insertParticipant(const QModelIndex &parent, ParticipantData participantData, bool bNewParticipant);
int onInsertRow(const QModelIndex &parent, const ParticipantData &participantData);
bool onUpdateRow(const QModelIndex &index, const ParticipantData &participantData);
bool onDeleteRow(const QModelIndex &idx, bool isFirstItem = true);
void onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType);
signals:
void internalDataChanged();
protected:
int m_partyId;
bool m_bRowsAreCheckable;
bool m_bUnitsSelectable;
std::vector<ParticipantManagement::ParticipantData> m_dataToDelete;
QTimer *m_missingSuperiorIdTimer;
QSet<int> m_missingSuperiorId;
QSet<int> m_usedTypeIds;
QSet<TypeClass> m_usedTypeClassIds;
FiringUnitValidator *m_firingUnitValidator;
};
//=============================================================================================================================
// PARTICIPANTTREEFILTERPROXYMODEL
//=============================================================================================================================
class PPMCOMMON_EXPORT ParticipantTreeFilterProxyModel : public LtsWidgets::LtsColumnFilterProxyModel
{
Q_OBJECT
public:
using LtsWidgets::LtsColumnFilterProxyModel::LtsColumnFilterProxyModel;
void setAllowedTypes(const QSet<int> &allowedTypes);
void setSourceModel(QAbstractItemModel *sourceModel) override;
int partyId() const { return m_sourceModel ? m_sourceModel->partyId() : -1; }
protected:
bool lessThan(const QModelIndex &source_left, const QModelIndex &source_right) const override;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
bool filterTypeRecursive(const ParticipantEditModel::CheckedTreeItem *item) const;
#endif
private:
QSet<int> m_allowedTypes;
ParticipantEditModel *m_sourceModel{nullptr};
}; // class ParticipantTreeFilterProxyModel
//=============================================================================================================================
// PARTICIPANTTABLEFILTERPROXYMODEL
//=============================================================================================================================
/**
* @brief The ParticipantTableFilterProxyModel class enables a hierarchical tree model of
* participants to be treated like a flat table model.
*
* Important connect statements that must be implemented are:
* - LtsDataView::filterChanged -> onFilter()
* - LtsDataView::sortOrderChanged -> onSort()
* - ParticipantEditModel::internalDataChanged -> init()
* In order to keep the selection after sorting, LtsDataView::sortOrderChanged can be connected to
* another function that handles that and calls onSort() instead. Otherwise, after sorting, the same
* row will be selected with most likely a different tree item than the one selected before sorting.
*
* When using this model in parallel to a standard tree model, in order to have two views that are
* consistent with each other, additional connects and workarounds are necessary. Connects include:
* - LtsDataView::filterChanged -> some function that asserts consistency
* - LtsDataView::selectionChanged -> some function that asserts consistency
* An important workaround is required when the party is changed (s.
* ParticipantEdit::onPartyChanged).
*/
class PPMCOMMON_EXPORT ParticipantTableFilterProxyModel : public LtsWidgets::LtsColumnFilterProxyModel
{
Q_OBJECT
public:
struct SortData
{
bool isActive{false};
int column{-1};
Qt::SortOrder order{Qt::DescendingOrder};
bool ascending() const
{
return order == Qt::AscendingOrder;
}
bool descending() const
{
return order == Qt::DescendingOrder;
}
QString toString()
{
QString str{QStringLiteral("active=")};
str += isActive ? QStringLiteral("true") : QStringLiteral("false");
str += QStringLiteral(", column=") + QString::number(column) + QStringLiteral(", order=");
str += order == Qt::DescendingOrder ? QStringLiteral("Descending") : QStringLiteral("Ascending");
return str;
}
}; // struct SortData
explicit ParticipantTableFilterProxyModel(QObject *parent = nullptr);
void init();
void resetMapping();
void disableSorting() { m_sortData.isActive = false; }
void setSourceModel(QAbstractItemModel *sourceModel) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role) const override;
QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
QModelIndex mapFromSource(const QModelIndex &sourceIndex) const override;
QModelIndex mapToSource(const QModelIndex &proxyIndex) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
QModelIndex parent(const QModelIndex &child) const override;
QModelIndex sibling(int row, int column, const QModelIndex &idx) const override;
bool isFilterActive() const { return m_isFilterActive; }
bool hasChildren(const QModelIndex &parent) const override;
SortData sortData() const { return m_sortData; }
protected:
bool lessThan(const QModelIndex &sourceLeft, const QModelIndex &sourceRight) const override;
bool filterAcceptsColumn(int source_column, const QModelIndex &source_parent) const override;
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
bool filterAcceptsRowInternal(int sourceRow, const QModelIndex &sourceParent) const;
private:
/**
* @brief mapTreeToTable initializes m_mapFromSource and m_mapToSource. Do NOT USE this method
* directly! Call init() instead.
* @param parent index of the parent in the source model
* @param row parent's child at rowth position
* @return current row count
*/
int mapTreeToTable(const QModelIndex &parent = QModelIndex(), int row = 0);
public slots:
void onFilter();
void onSort(int column, Qt::SortOrder order);
private:
QHash<int, QModelIndex> m_mapToSource;
QHash<QModelIndex, int> m_mapFromSource;
QHash<int, QModelIndex> m_mapToSourceInternal;
QHash<QModelIndex, int> m_mapFromSourceInternal;
QHash<int, QModelIndex> m_mapToSourceFiltered;
QHash<QModelIndex, int> m_mapFromSourceFiltered;
QVector<int> m_sortMap;
bool m_isFilterActive{false};
SortData m_sortData;
ParticipantEditModel *m_sourceModel{nullptr};
NGL::INGLLogger &m_logger;
}; // class ParticipantTableFilterProxyModel
} //namespace ParticipantManagement
Q_DECLARE_METATYPE(ParticipantManagement::ParticipantData)
@@ -0,0 +1,140 @@
/**
* @RDE_HEADER@
* The FiringUnitValidator regulates the rules for firing units
* $Id: participant_dis_helper.h 37747 2017-12-08 08:07:01Z ehrlicher $
* $HeadURL: svn://10.196.0.54/TDS/branches/product/features/24_vulcano/Lts/Plugins/ParticipantManagement/Gui/Common/participant_dis_helper.h $
* $Author: ehrlicher $
* Created by Hannes Fritsche, ESZS, 2024-03-06
*/
#include "participant_firing_unit_validator.h"
#include <QJsonDocument>
#include <QJsonObject>
#include <QVariant>
#include <LtsUtilsSettings/settings.h>
namespace ParticipantManagement
{
FiringUnitValidator::FiringUnitValidator(const std::shared_ptr<Interface::Dtc> &ppmDtc, QObject *parent)
: QObject(parent)
, m_ppmDtc(ppmDtc)
{
fetchArtilleryTypes();
}
QSet<int> FiringUnitValidator::artilleryParticipantTypeIds() const { return m_artilleryParticipantTypeIds; }
QVector<Type> FiringUnitValidator::artilleryParticipantTypes() const
{
QVector<Type> artilleryParticipantTypes;
artilleryParticipantTypes.reserve(m_artilleryParticipantTypeIds.size());
std::function<void(const Type &)> getArtilleryType = [this, &artilleryParticipantTypes](const Type &type)
{
if (!m_artilleryParticipantTypeIds.contains(type.id()))
return;
artilleryParticipantTypes.append(type);
};
m_ppmDtc->types(getArtilleryType);
return artilleryParticipantTypes;
}
QSet<int> FiringUnitValidator::firingUnitTypeIds() const { return m_firingUnitTypeIds; }
uint FiringUnitValidator::maxParticipantsPerFiringUnit()
{
LtsUtils::ProjectSettings *settings = LtsUtils::ProjectSettings::getInstance();
return settings->value(QStringLiteral("PPM"), QStringLiteral("maxParticipantsPerFiringUnit"), 8).toUInt();
}
int FiringUnitValidator::getTypeId(const ParticipantEditModel *model, const QModelIndex &index) const
{
if (!model)
return -1;
const ParticipantData data = model->getParticipantData(index);
return data.typeId();
}
int FiringUnitValidator::getTypeId(const ParticipantTemplateEditModel *model, const QModelIndex &index) const
{
if (!model)
return -1;
const TemplateData data = model->getTemplateData(index);
return data.typeId();
}
void FiringUnitValidator::fetchArtilleryTypes()
{
m_firingUnitTypeIds.clear();
m_artilleryParticipantTypeIds.clear();
std::function<void(const ParticipantManagement::Type &type)> getArtilleryTypes = [this](const ParticipantManagement::Type &type)
{
if (!isArtilleryType(type))
return;
if (type.typeClass() == ParticipantManagement::TypeClass::inner_enum::Unit)
m_firingUnitTypeIds.insert(type.id());
else
m_artilleryParticipantTypeIds.insert(type.id());
};
m_ppmDtc->types(getArtilleryTypes);
}
bool FiringUnitValidator::isArtilleryType(int typeId) const { return m_ppmDtc->isArtilleryType(typeId) && !m_ppmDtc->isAdlerVerbund(typeId); }
bool FiringUnitValidator::isArtilleryType(const Type &type) const { return isArtilleryType(type.id()); }
bool FiringUnitValidator::isArtilleryUnit(int typeId) const
{
if (!isArtilleryType(typeId))
return false;
const ParticipantManagement::Type &type = m_ppmDtc->type(typeId);
return type.typeClass() == ParticipantManagement::TypeClass::Unit;
}
bool FiringUnitValidator::isArtilleryWeaponSystem(int typeId) const
{
if (!isArtilleryType(typeId))
return false;
const ParticipantManagement::Type &type = m_ppmDtc->type(typeId);
return type.typeClass() == ParticipantManagement::TypeClass::WeaponSystem;
}
bool FiringUnitValidator::isSameGearClassArtillery(int typeIdA, int typeIdB) const
{
const ProjectDataManagement::GearClass::type gearClassA = getGearClassType(typeIdA);
if (gearClassA == ProjectDataManagement::GearClass::Unknown)
return false;
const ProjectDataManagement::GearClass::type gearClassB = getGearClassType(typeIdB);
return gearClassA == gearClassB;
}
ProjectDataManagement::GearClass::type FiringUnitValidator::getGearClassType(int typeId) const
{
const Type type = m_ppmDtc->type(typeId);
const QJsonDocument properties = QJsonDocument::fromJson(QByteArray::fromStdString(type.properties()));
const QJsonObject propertiesObject = properties.object();
const int gearClassId = propertiesObject.value(QStringLiteral("gearClassId")).toInt(ProjectDataManagement::GearClass::Unknown);
return static_cast<ProjectDataManagement::GearClass::type>(gearClassId);
}
} // namespace ParticipantManagement
@@ -0,0 +1,152 @@
/**
* @RDE_HEADER@
* The FiringUnitValidator regulates the rules for firing units
* $Id: participant_dis_helper.h 37747 2017-12-08 08:07:01Z ehrlicher $
* $HeadURL: svn://10.196.0.54/TDS/branches/product/features/24_vulcano/Lts/Plugins/ParticipantManagement/Gui/Common/participant_dis_helper.h $
* $Author: ehrlicher $
* Created by Hannes Fritsche, ESZS, 2024-03-06
*/
#pragma once
#include <QObject>
#include <memory>
#include <ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <ParticipantManagement/ppm_dtc.h>
#include "participant_edit_model.h"
#include "participant_template_edit_model.h"
namespace ParticipantManagement
{
namespace Interface
{
class Dtc;
} //namespace Interface
class Participant;
class PPMCOMMON_EXPORT FiringUnitValidator : public QObject
{
public:
enum FiringUnitRestriction: short
{
NO_RESTRICTION = 0b0000000000000000,
NO_TYPE_CHANGE_ALLOWED = 0b0000000000000001,
IS_AT_MAX_CAPACITY = 0b0000000000000010,
ONLY_SAME_GEAR_CLASS_ARTILLERY_ALLOWED = 0b0000000000000100,
NO_FIRING_UNIT_TYPE_ALLOWED = 0b0000000000001000,
NO_ARTILLERY_PARTICIPANTS_ALLOWED = 0b0000000000010000
};
Q_DECLARE_FLAGS(FiringUnitRestrictions, FiringUnitRestriction)
explicit FiringUnitValidator(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc, QObject *parent = nullptr);
template <typename T>
bool hasUnitCapacities(T *model, const QModelIndex &unitIndex) const
{
FiringUnitRestrictions restrictions = getRestrictions(model, unitIndex);
return !restrictions.testFlag(IS_AT_MAX_CAPACITY);
}
template<typename T>
ProjectDataManagement::GearClass::type getGearClassType(const T *model, const QModelIndex &participantIndex) const
{
if (!model)
return {};
const int typeId = getTypeId(model, participantIndex);
return getGearClassType(typeId);
}
template<typename T>
bool isAdler(const T *model, const QModelIndex &participantIndex) const
{
if (!model)
return {};
const int typeId = getTypeId(model, participantIndex);
return m_ppmDtc->isAdlerType(typeId);
}
template <typename T>
FiringUnitRestrictions getRestrictions(const T *model, const QModelIndex &participantIndex) const
{
if (!model)
return NO_RESTRICTION;
const int typeId = getTypeId(model, participantIndex);
if (!isArtilleryType(typeId))
{
if (!model->hasChildren(participantIndex)) // since there are only children allowed on units, we have a participant here
return NO_ARTILLERY_PARTICIPANTS_ALLOWED;
// we do not allow a unit to be a firing unit if there are non artillery children under it
// and we do not allow to add artillery participants to a non artillery unit
return {NO_FIRING_UNIT_TYPE_ALLOWED | NO_ARTILLERY_PARTICIPANTS_ALLOWED};
}
if (!m_firingUnitTypeIds.contains(typeId)) // we have an artillery participant
return NO_TYPE_CHANGE_ALLOWED;
// else we have a firing unit
if (!model->hasChildren(participantIndex))
return ONLY_SAME_GEAR_CLASS_ARTILLERY_ALLOWED;
FiringUnitRestrictions restrictions = NO_TYPE_CHANGE_ALLOWED;
uint childCount = static_cast<uint>(model->rowCount(participantIndex));
if (childCount >= maxParticipantsPerFiringUnit())
restrictions.setFlag(IS_AT_MAX_CAPACITY);
return restrictions;
}
template <typename T>
Type getAllowedType(T *model, const QModelIndex &participantIndex) const
{
if (!model)
return Type();
FiringUnitRestrictions restrictions = getRestrictions(model, participantIndex);
if (restrictions.testFlag(NO_TYPE_CHANGE_ALLOWED) && model->hasChildren(participantIndex))
{
// since we do now allow mixed types in firing units, the type of the first child is returned
const QModelIndex childIndex = model->index(0, 0, participantIndex);
const int typeId = getTypeId(model, childIndex);
return m_ppmDtc->type(typeId);
}
return Type();
}
QVector<Type> artilleryParticipantTypes() const;
QSet<int> artilleryParticipantTypeIds() const;
QSet<int> firingUnitTypeIds() const;
static uint maxParticipantsPerFiringUnit();
bool isArtilleryType(int typeId) const;
bool isArtilleryUnit(int typeId) const;
bool isArtilleryWeaponSystem(int typeId) const;
bool isSameGearClassArtillery(int typeIdA, int typeIdB) const;
ProjectDataManagement::GearClass::type getGearClassType(int typeId) const;
private: // methods
int getTypeId(const ParticipantEditModel *model, const QModelIndex &index) const;
int getTypeId(const ParticipantTemplateEditModel *model, const QModelIndex &index) const;
void fetchArtilleryTypes();
bool isArtilleryType(const ParticipantManagement::Type &type) const;
private: // attributes
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
QSet<int> m_firingUnitTypeIds;
QSet<int> m_artilleryParticipantTypeIds;
}; // namespace FiringUnitValidator
} // namespace ParticipantManagement
@@ -0,0 +1,177 @@
/**
* @RDE_HEADER@
* A small helper class to provide icon rendering capabilities for NGLTreeModels
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2017-10-26
*/
#include "participant_icon_model_base.h"
#include <ParticipantManagement/ppm_translation.h>
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
#include <nglwidgets/ngltreeitem.h>
#include <QHash>
#include <QIcon>
#include <QPointer>
#include <QTimer>
namespace ParticipantManagement
{
ParticipantIconModelBase::ParticipantIconModelBase(const std::shared_ptr<Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
const QStringList &hdr,
NGLTreeItem *rootItem,
QObject *parent,
NGL::INGLLogger &logger)
: NGLTreeModel(parent, rootItem, hdr)
, m_dtc(ppmDtc)
, m_asb(asbIfc)
, m_partyRole(AdvancedSymbology::Role::Unknown)
, m_logger(logger)
{
this->setMimeDataWithIcon(false); // do not serialize icons, they are repaint on drop again (with the new party color)
connect(ppmDtc.get(), &ParticipantManagement::Interface::Dtc::typeChanged,
this, &ParticipantIconModelBase::onTypeChanged);
auto cbTypes = [this](const ParticipantManagement::Type &type)
{
onTypeChanged(type, DataModification::eAdded);
};
ppmDtc->types(cbTypes);
}
void ParticipantIconModelBase::onTypeChanged(const ParticipantManagement::Type &data, DataModification modType)
{
if (modType == DataModification::eRemoved)
{
m_types.remove(data.id());
return;
}
m_types[data.id()] = data;
}
// type handling
ParticipantManagement::TypeClass ParticipantIconModelBase::typeClassIdFromTypeId(int typeId) const
{
return m_types.value(typeId).typeClass();
}
QString ParticipantIconModelBase::typeClassStringFromTypeId(int typeId) const
{
auto it = m_types.find(typeId);
if (it == m_types.end())
return QString();
return ParticipantManagement::toString(it.value().typeClass());
}
bool ParticipantIconModelBase::isUnitType(int typeId) const
{
const ParticipantManagement::TypeClass typeClassId = typeClassIdFromTypeId(typeId);
return typeClassId == ParticipantManagement::TypeClass::Unit ||
typeClassId == ParticipantManagement::TypeClass::SupportUnit;
}
// symbol handling
void ParticipantIconModelBase::tryRenderSymbol(const QString &symbol, NGLTreeItem *item)
{
if ( (item) && (m_asb) && (!symbol.isEmpty()) )
{
AdvancedSymbology::SymbolDataToRender symDataToRender(symbol);
symDataToRender.role = m_partyRole;
DEBUG_LOG(m_logger) << "Rendering symbol '" << symbol << "' for item " << item;
if (m_partyColor.isValid())
{
symDataToRender.fillColor = m_partyColor;
symDataToRender.fillColorReplace = true;
}
else
{
// User-Defined Symbols (XML) need fillColor:
symDataToRender.fillColor = AdvancedSymbology::SymbolDataToRender::unknownColor();
symDataToRender.fillColorReplace = true;
}
QSharedPointer<AdvancedSymbology::SymbolResult> symRes = m_asb->findImage(symDataToRender);
AdvancedSymbology::SymbolResult *symResPtr = symRes.data();
if (!symResPtr)
{
WARNING_LOG(m_logger) << "Can not render symbol for sidc '" << symbol << "'";
return;
}
auto it = m_symbolResultMapping.find(symResPtr);
if (it == m_symbolResultMapping.end())
{
if (symResPtr->isResultReady())
{
item->setIcon(QIcon(QPixmap::fromImage(symRes->symbolImage().image())));
}
else
{
SymbolResultData symResData;
symResData.result = symRes;
symResData.treeItems.push_back(item);
m_symbolResultMapping.insertMulti(symResPtr, symResData);
QPointer<AdvancedSymbology::SymbolResult> qPointer(symResPtr);
// queued because the object is destroyed inside symbolRendered() due to QSharedPointer
connect(symResPtr, &AdvancedSymbology::SymbolResult::resultReadyInternal,
this, [this, qPointer]() { symbolRendered(qPointer); }, Qt::QueuedConnection);
}
}
else
{
SymbolResultData &srd = it.value();
srd.treeItems.push_back(item);
}
}
}
void ParticipantIconModelBase::symbolRendered(AdvancedSymbology::SymbolResult *symbolResult)
{
if ( (!symbolResult) || (!symbolResult->isResultReady()) )
return;
auto it = m_symbolResultMapping.constFind(symbolResult);
if (it == m_symbolResultMapping.constEnd())
return;
const SymbolResultData &symResData = it.value();
const QIcon icon(QPixmap::fromImage(symResData.result->symbolImage().image()));
for (NGLTreeItem *item : symResData.treeItems)
{
DEBUG_LOG(m_logger) << "Symbol for " << item << " ready";
// we need to search for srd.treeItem because it may be already destroyed
if (!updateIcon(QModelIndex(), item, icon))
WARNING_LOG(m_logger) << "updateIcon failed for item " << item;
}
m_symbolResultMapping.erase(it);
}
bool ParticipantIconModelBase::updateIcon(const QModelIndex &currentIndex, NGLTreeItem *itemToUpdate, const QIcon &icon)
{
const NGLTreeItem *currentItem = privateData(currentIndex);
if (currentItem == itemToUpdate)
{
itemToUpdate->setIcon(icon);
emit dataChanged(currentIndex, currentIndex, { Qt::DecorationRole });
return true;
}
const int childCount = currentItem->childCount();
for (int row = 0; row < childCount; ++row)
{
const QModelIndex childIndex = index(row, 0, currentIndex);
if (updateIcon(childIndex, itemToUpdate, icon))
return true;
}
return false;
}
} // namespace ParticipantManagement
@@ -0,0 +1,84 @@
/**
* @RDE_HEADER@
* A small helper class to provide icon rendering capabilities for NGLTreeModels
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2017-10-26
*/
#pragma once
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <nglwidgets/ngltreemodel.h>
#include <QColor>
#include <QSharedPointer>
namespace LtsSession
{
class LtsSessionDataDds;
}
namespace AdvancedSymbology
{
class ForeignDataInterface;
class SymbolResult;
enum class Role;
}
namespace NGL
{
class INGLLogger;
}
namespace ParticipantManagement
{
class PPMCOMMON_EXPORT ParticipantIconModelBase : public NGLTreeModel
{
Q_OBJECT
protected:
ParticipantIconModelBase(const std::shared_ptr<Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
const QStringList &hdr,
NGLTreeItem *rootItem,
QObject *parent,
NGL::INGLLogger &logger);
// type handling
ParticipantManagement::TypeClass typeClassIdFromTypeId(int typeId) const;
QString typeClassStringFromTypeId(int typeId) const;
bool isUnitType(int typeId) const;
// symbol handling
void tryRenderSymbol(const QString &symbol, NGLTreeItem *item);
void symbolRendered(AdvancedSymbology::SymbolResult *symbolResult);
bool updateIcon(const QModelIndex &currentIndex, NGLTreeItem *itemToUpdate, const QIcon &icon);
protected:
void onTypeChanged(const ParticipantManagement::Type &data, DataModification modType);
protected:
// misc
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
// type handling
QHash<qint32, ParticipantManagement::Type> m_types;
// symbol handling
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asb;
struct SymbolResultData
{
QSharedPointer<AdvancedSymbology::SymbolResult> result;
QVector<NGLTreeItem *> treeItems;
};
QHash<AdvancedSymbology::SymbolResult *, SymbolResultData> m_symbolResultMapping;
AdvancedSymbology::Role m_partyRole;
QColor m_partyColor;
NGL::INGLLogger &m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,100 @@
/**
* @RDE_HEADER@
* OperatorManagement - Operator Change Password (Frameless) Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Diers, SLSE, 2017-10-11
*/
#include "participant_search_modal.h"
#include "ui_participant_search_modal.h"
#include <LtsSession/lts_session_data_dds.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
#include <PluginInterfaces/gui_plugin_interface.h>
namespace ParticipantManagement
{
ParticipantSearchModal::ParticipantSearchModal(QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent)
, m_ui(new Ui::ParticipantSearchModal)
{
m_ui->setupUi(this);
connect(m_ui->pbCancel, &QPushButton::clicked, this, &ParticipantSearchModal::reject);
connect(m_ui->pbOk, &QPushButton::clicked, this, &ParticipantSearchModal::onOkay);
}
ParticipantSearchModal::~ParticipantSearchModal()
{
delete m_ui;
}
bool ParticipantSearchModal::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc)
{
if (!dtc)
return false;
auto cb = [this](const Participant &data)
{
if (!data.equipmentNumber().is_set())
return;
const int newEqId = data.equipmentNumber().get();
m_partId2EqId[data.id()] = newEqId;
m_eqId2PartId[newEqId] = data.id();
};
dtc->participants(cb);
connect(dtc.get(), &Interface::Dtc::participantChanged,
this, &ParticipantSearchModal::onParticipantChanged);
return true;
}
void ParticipantSearchModal::showEvent(QShowEvent *e)
{
LtsWidgets::LtsFramelessDialog::showEvent(e);
m_ui->leEquipmentNo->clear();
m_ui->leEquipmentNo->setFocus();
}
void ParticipantSearchModal::onOkay()
{
int participantId = m_eqId2PartId.value(m_ui->leEquipmentNo->text().toInt());
if (participantId > 0)
emit participantSelected(participantId);
close();
}
void ParticipantSearchModal::onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType)
{
const int newEqId = data.equipmentNumber().is_set() ? data.equipmentNumber().get() : 0;
switch (modType)
{
case DataModification::eAdded:
case DataModification::eModified:
{
const int oldEqId = m_partId2EqId.value(data.id());
if (oldEqId == newEqId)
return;
if (oldEqId != 0)
m_eqId2PartId.remove(oldEqId);
if (newEqId == 0)
return;
m_partId2EqId[data.id()] = newEqId;
m_eqId2PartId[newEqId] = data.id();
break;
}
case DataModification::eRemoved:
{
const int oldEqId = m_partId2EqId.value(data.id());
m_partId2EqId.remove(data.id());
if (oldEqId != 0)
m_eqId2PartId.remove(oldEqId);
}
}
}
} // namespace
@@ -0,0 +1,55 @@
/**
* @RDE_HEADER@
* ParticipantManagement - Show ParticipantInfo by Equipment No
* $Id$
* $HeadURL$
* $Author$
* Created by Malte Diers, NLSE, 2018-04-20
*/
#pragma once
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <LtsWidgets/lts_frameless_dialog.h>
#include <QMap>
#include <memory>
enum class DataModification;
namespace Ui
{
class ParticipantSearchModal;
}
namespace ParticipantManagement
{
class Participant;
namespace Interface
{
class Dtc;
}
class PPMCOMMON_EXPORT ParticipantSearchModal : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
explicit ParticipantSearchModal(QWidget *parent = nullptr);
~ParticipantSearchModal();
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc);
void showEvent(QShowEvent *e) override;
private slots:
void onOkay();
void onParticipantChanged(const ParticipantManagement::Participant &data, DataModification modType);
signals:
void participantSelected(int participantId);
private:
QMap<int,int> m_eqId2PartId;
QMap<int,int> m_partId2EqId;
Ui::ParticipantSearchModal *m_ui;
};
} // namespace
@@ -0,0 +1,90 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantSearchModal</class>
<widget class="LtsWidgets::LtsFramelessDialog" name="ParticipantSearchModal">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>188</width>
<height>79</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<item>
<widget class="QPushButton" name="pbOk">
<property name="text">
<string>OK</string>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pbCancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="leEquipmentNo">
<property name="maxLength">
<number>5</number>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblEquipmentNo">
<property name="text">
<string>Equipment No.:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<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>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsFramelessDialog</class>
<extends>QDialog</extends>
<header>LtsWidgets/lts_frameless_dialog.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,359 @@
/**
* @RDE_HEADER@
* HMI Plugin for MeteoDataManagement - Meteo Data Overview Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "participant_template_edit_item.h"
#include "ui_participant_edit_item_widget_base.h"
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <ParticipantManagement/ppm_translation.h>
#include <QStandardItemModel>
#include <LtsSession/lts_session_manager.h>
namespace ParticipantManagement
{
//
// ParticipantTemplateEditItemWidget
//
ParticipantTemplateEditItemWidget::ParticipantTemplateEditItemWidget(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: ParticipantEditItemWidgetBase(asSupportService, session, parent)
{
m_ui->lbInfo->hide();
m_ui->leInfo->hide();
m_ui->lbSign->hide();
m_ui->leSign->hide();
m_ui->tbAssignment->hide();
}
bool ParticipantTemplateEditItemWidget::init(const QModelIndex &workingIndex,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const ParticipantManagement::TemplateData &data,
const bool addItem)
{
m_workingIndex = workingIndex;
m_editData = data;
m_bEditMode = m_editData.typeId() > 0;
return ParticipantEditItemWidgetBase::init(dtc, ppmGuiCbxIfc, asb, addItem);
}
void ParticipantTemplateEditItemWidget::setFiringUnitRestrictions(ParticipantTemplateEditModel *model, bool isEdit, const FiringUnitValidator::FiringUnitRestrictions &restrictions, FiringUnitValidator *firingUnitValidator, const int &unitGearClassType)
{
if (!firingUnitValidator || !model)
return;
if (restrictions.testFlag(FiringUnitValidator::NO_TYPE_CHANGE_ALLOWED))
{
m_ui->cbTypeClass->setDisabled(true);
m_ui->cbType->setDisabled(true);
if (isEdit) // if we are in edit mode (and not add), type and typeclass are already set where as want them to be
return;
const Type allowedType = firingUnitValidator->getAllowedType(model, m_workingIndex);
if (allowedType == Type())
return;
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(allowedType.typeClass().underlying()));
m_ui->cbType->setCurrentIndex(m_ui->cbType->findData(allowedType.id()));
return;
}
if (restrictions.testFlag(FiringUnitValidator::ONLY_SAME_GEAR_CLASS_ARTILLERY_ALLOWED))
{
if (isEdit)
return;
const QVector<Type> allowedTypes = firingUnitValidator->artilleryParticipantTypes();
m_ui->cbTypeClass->setDisabled(true);
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(allowedTypes.at(0).typeClass().underlying()));
QSignalBlocker typeSignalBlocker(m_ui->cbType);
m_ui->cbType->clear();
std::function<bool(Type)> funcIsSameGearType = [=](const Type &t)
{
if (m_isAdler)
return m_dtc->isAdlerType(t.id()) && (firingUnitValidator->getGearClassType(t.id()) == unitGearClassType);
return firingUnitValidator->getGearClassType(t.id()) == unitGearClassType;
};
QVector<Type>::ConstIterator typeIterator = std::find_if(allowedTypes.begin(), allowedTypes.end(), funcIsSameGearType);
if(typeIterator != allowedTypes.end())
{
m_ui->cbType->setDisabled(true);
m_ui->cbType->addItem(ParticipantManagement::trTypeName(typeIterator->name()), typeIterator->id());
}
else
{
for (const Type &currentType : allowedTypes)
m_ui->cbType->addItem(ParticipantManagement::trTypeName(currentType.name()), currentType.id());
m_ui->cbType->model()->sort(0);
}
m_ui->cbType->setCurrentIndex(0);
return;
}
if (isEdit && restrictions.testFlag(FiringUnitValidator::NO_FIRING_UNIT_TYPE_ALLOWED))
{
m_disabledTypeIds.unite(firingUnitValidator->firingUnitTypeIds());
QStandardItemModel *cbTypeModel = qobject_cast<QStandardItemModel *>(m_ui->cbType->model());
if (cbTypeModel == nullptr)
return;
for (int row = 0; row < m_ui->cbType->count(); ++row)
{
QStandardItem *item = cbTypeModel->item(row);
int typeId = item->data(Qt::UserRole).toInt();
if (!m_disabledTypeIds.contains(typeId))
continue;
item->setFlags(Qt::NoItemFlags);
}
}
if (restrictions.testFlag(FiringUnitValidator::NO_ARTILLERY_PARTICIPANTS_ALLOWED))
{
m_disabledTypeIds.unite(firingUnitValidator->artilleryParticipantTypeIds());
QStandardItemModel *cbTypeModel = qobject_cast<QStandardItemModel *>(m_ui->cbType->model());
if (cbTypeModel == nullptr)
return;
for (int row = 0; row < m_ui->cbType->count(); ++row)
{
QStandardItem *item = cbTypeModel->item(row);
int typeId = item->data(Qt::UserRole).toInt();
if (!m_disabledTypeIds.contains(typeId))
continue;
item->setFlags(Qt::NoItemFlags);
}
}
}
void ParticipantTemplateEditItemWidget::setData()
{
m_ui->leDesignator->setText(QString::fromStdString(m_editData.designator()));
m_ui->leTactIdent->setText(QString::fromStdString(m_editData.tacticalIdentifier()));
Type type = m_dtc->type(m_editData.typeId());
m_ui->cbTypeClass->setCurrentIndex(m_ui->cbTypeClass->findData(type.typeClass().underlying()));
m_ui->cbType->setCurrentIndex(m_ui->cbType->findData(type.id()));
// set EqNr after all cbx change
m_ui->sbEquipNr->setValue(m_editData.equipmentNumber());
// Not templates for Externals.
m_ui->cbExternal->hide();
m_ui->cbExternal->setChecked(false);
m_ui->lblExternal->hide();
// nach den Setzen des Typs, sonst wird Default Typ-Symbol benutzt...
onChangeSymbol(QString::fromStdString(m_editData.symbol()));
}
void ParticipantTemplateEditItemWidget::setDesignatorData()
{
m_ui->leDesignator->setText(QString::fromStdString(m_editData.designator()));
m_ui->leTactIdent->setText(QString::fromStdString(m_editData.tacticalIdentifier()));
}
void ParticipantTemplateEditItemWidget::onAddItem()
{
ParticipantManagement::TemplateData newTemplateParticipant;
newTemplateParticipant.designator() = m_ui->leDesignator->text().toStdString();
newTemplateParticipant.tacticalIdentifier() = m_ui->leTactIdent->text().toStdString();
newTemplateParticipant.symbol(m_sidc.toStdString());
newTemplateParticipant.typeId(m_ui->cbType->currentData().toInt());
const int equipNo = m_ui->sbEquipNr->value();
if (!checkEquipNo(equipNo))
return;
newTemplateParticipant.equipmentNumber(equipNo);
DEBUG_LOG(m_logger) << "adding item: " << newTemplateParticipant;
emit addItem(m_workingIndex, newTemplateParticipant);
if (equipNo > 0)
m_ui->sbEquipNr->setValue(equipNo + 1);
}
bool ParticipantTemplateEditItemWidget::onEditItem()
{
m_editData.designator() = m_ui->leDesignator->text().toStdString();
m_editData.tacticalIdentifier() = m_ui->leTactIdent->text().toStdString();
m_editData.symbol(m_sidc.toStdString());
m_editData.typeId(m_ui->cbType->currentData().toInt());
//eqNr is set
const int equipNo = m_ui->sbEquipNr->value();
if (!checkEquipNo(equipNo))
return false;
m_editData.equipmentNumber(equipNo);
DEBUG_LOG(m_logger) << "edit item: " << m_editData;
emit updateItem(m_workingIndex, m_editData);
emit readyToClose();
return true;
}
bool ParticipantTemplateEditItemWidget::checkEquipNo(int equipNo)
{
if (equipNo > 0)
{
if (equipNo < m_typeMinimum)
{
//eqNr is below minimum!
m_ui->lbMinMaxEquipNr->setText(QStringLiteral("<span style=\"color:#aa0000;\">%1</span>").arg(equipNo));
return false;
}
if (m_editData.equipmentNumber() != equipNo)
{
//eqNr is in range (max is set in sp directly)
if (m_usedEquipmentNumbers.contains(equipNo))
{
const QString msg = tr("The equipment number is already used by another participant in this template");
LtsWidgets::LtsMessageDialog::showMessage(this,
msg,
tr("Equipment Number already in use"));
return false;
}
}
}
return true;
}
//
// ParticipantTemplateEditItem
//
ParticipantTemplateEditItem::ParticipantTemplateEditItem(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_editItemWidget(new ParticipantTemplateEditItemWidget(asSupportService, session, parent))
, m_buttonBox(new LtsWidgets::LtsDialogButtonBox(this))
{
//HACK as close is not allowed directly
connect(m_buttonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &ParticipantTemplateEditItem::close);
connect(m_editItemWidget, &ParticipantTemplateEditItemWidget::readyToClose, this, &ParticipantTemplateEditItem::close);
//connect to other signals
connect(m_editItemWidget, &ParticipantTemplateEditItemWidget::addItem, this, &ParticipantTemplateEditItem::addItem);
connect(m_editItemWidget, &ParticipantTemplateEditItemWidget::updateItem, this, &ParticipantTemplateEditItem::updateItem);
//hide ok and aplly
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->hide();
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
}
bool ParticipantTemplateEditItem::init(const QModelIndex &workingIndex,
const std::shared_ptr<Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const TemplateData &data,
const bool addItem)
{
if (!m_editItemWidget->init(workingIndex, dtc, ppmGuiCbxIfc, asb, data, addItem))
return false;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_editItemWidget);
layout->addWidget(m_buttonBox);
setLayout(layout);
if (data.typeId() > 0)
{
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, m_editItemWidget, &ParticipantTemplateEditItemWidget::onEditItem);
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setText(tr("Apply"));
}
else
{
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, m_editItemWidget, &ParticipantTemplateEditItemWidget::onAddItem);
}
return true;
}
void ParticipantTemplateEditItem::setFiringUnitRestrictions(ParticipantTemplateEditModel *model, bool isEdit, const FiringUnitValidator::FiringUnitRestrictions &restrictions, FiringUnitValidator *firingUnitValidator, const int unitGearClassType)
{
if (restrictions == FiringUnitValidator::NO_RESTRICTION)
return;
if (restrictions.testFlag(FiringUnitValidator::IS_AT_MAX_CAPACITY))
m_buttonBox->getButton(LtsWidgets::DialogButton::Add)->setDisabled(true);
if (m_editItemWidget)
m_editItemWidget->setFiringUnitRestrictions(model, isEdit, restrictions, firingUnitValidator, unitGearClassType);
}
//
// ParticipantTemplateEditItemTab
//
ParticipantTemplateEditItemTab::ParticipantTemplateEditItemTab(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
, m_editItemWidget(new ParticipantTemplateEditItemWidget(asSupportService, session, this))
{
connect(m_editItemWidget, &ParticipantTemplateEditItemWidget::updateItem, this, &ParticipantTemplateEditItemTab::updateItem);
connect(m_editItemWidget, &ParticipantTemplateEditItemWidget::readyToClose, this, [this]()
{
m_buttonBox->getButton(LtsWidgets::DialogButton::Close)->click();
});
}
bool ParticipantTemplateEditItemTab::init(const QModelIndex &workingIndex,
const std::shared_ptr<Interface::Dtc> &dtc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const TemplateData &data)
{
if (!m_editItemWidget->init(workingIndex, dtc, ppmGuiCbxIfc, asb, data))
return false;
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(m_editItemWidget);
setLayout(layout);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, m_editItemWidget, &ParticipantTemplateEditItemWidget::onEditItem);
return true;
}
void ParticipantTemplateEditItemTab::retranslate()
{
// lupdate doesn't like translate(tr("foo")) ...
const QString txt(tr("Participant Item Edit"));
translate(txt);
}
bool ParticipantTemplateEditItemTab::apply()
{
return m_editItemWidget->onEditItem();
}
} //namespace ParticipantManagement
@@ -0,0 +1,118 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Edit Item Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include "participant_edit_item_widget_base.h"
#include <ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include "participant_firing_unit_validator.h"
#include <LtsWidgets/lts_frameless_dialog.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsWidgets/lts_dialog_button_box.h>
#include <QModelIndex>
namespace ParticipantManagement
{
class ParticipantTemplateEditItemWidget final : public ParticipantEditItemWidgetBase
{
Q_OBJECT
public:
explicit ParticipantTemplateEditItemWidget(bool asSupportService,
LtsSession::LtsSession *session,
QWidget *parent = nullptr);
bool init(const QModelIndex &workingIndex,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const TemplateData &data,
const bool addItem = false);
void setUsedEquipmentNumbers(const QSet<int> &usedEquipmentNumbers) { m_usedEquipmentNumbers = usedEquipmentNumbers; }
void setFiringUnitRestrictions(ParticipantTemplateEditModel *model, bool isEdit, const FiringUnitValidator::FiringUnitRestrictions &restrictions, FiringUnitValidator *firingUnitValidator, const int &unitGearClassTyp);
void setIsAdler(bool isAdler) {m_isAdler = isAdler;}
protected:
void setData() override;
void setDesignatorData() override;
public:
void onAddItem() override;
bool onEditItem() override;
protected:
int editTypeId() const override { return m_editData.typeId(); }
int currentPartyId() const override { return 0; }
bool checkEquipNo(int equipNo);
Q_SIGNALS:
void addItem(const QModelIndex &parent, const TemplateData &newData);
void updateItem(const QModelIndex &index, const TemplateData &editData);
private:
QSet<int> m_usedEquipmentNumbers;
TemplateData m_editData;
QModelIndex m_workingIndex;
bool m_isAdler;
};
class PPMCOMMON_EXPORT ParticipantTemplateEditItem final : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
ParticipantTemplateEditItem(bool asSupportService, LtsSession::LtsSession *session, QWidget *parent = nullptr);
bool init(const QModelIndex &workingIndex,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const TemplateData &data = TemplateData(),
const bool addItem = false);
void setFiringUnitRestrictions(ParticipantTemplateEditModel *model, bool isEdit, const FiringUnitValidator::FiringUnitRestrictions &restrictions,
FiringUnitValidator *firingUnitValidator,
const int unitGearClassType);
void setIsAdler(bool isAdler) {m_editItemWidget->setIsAdler(isAdler);}
public Q_SLOTS:
void setUsedEquipmentNumbers(const QSet<int> &usedEquipmentNumbers) { m_editItemWidget->setUsedEquipmentNumbers(usedEquipmentNumbers); }
Q_SIGNALS:
void addItem(const QModelIndex &parent, const TemplateData &newData);
void updateItem(const QModelIndex &index, const TemplateData &editData);
private:
ParticipantTemplateEditItemWidget *m_editItemWidget;
LtsWidgets::LtsDialogButtonBox *m_buttonBox;
};
class PPMCOMMON_EXPORT ParticipantTemplateEditItemTab final : public LtsWidgets::LtsDialog
{
Q_OBJECT
public:
ParticipantTemplateEditItemTab(bool asSupportService, LtsSession::LtsSession *session, QWidget *parent = nullptr);
bool init(const QModelIndex &workingIndex,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asb,
const TemplateData &data = TemplateData());
Q_SIGNALS:
void addItem(int &row, const QModelIndex &parent, const TemplateData &newData, bool asCopy);
void updateItem(const QModelIndex &index, const TemplateData &editData);
private:
void retranslate() override;
bool apply() override;
private:
ParticipantTemplateEditItemWidget *m_editItemWidget;
};
} // namespace ParticipantManagement
@@ -0,0 +1,468 @@
/**
* @RDE_HEADER@
* This Model is used by the Force-Tree-Editors
* $Id: participant_template_edit_model.cpp 50265 2020-03-05 15:48:19Z ehrlicher $
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/3dws_devel/Lts/Plugins/ParticipantManagement/Gui/ParticipantTemplates/participant_template_edit_model.cpp $
* $Author: ehrlicher $
*/
#include "participant_template_edit_model.h"
#include <ParticipantManagement/ppm_translation.h>
#include "participant_firing_unit_validator.h"
#include <nglwidgets/ngltreeitem.h>
#include <QSet>
namespace ParticipantManagement
{
QDataStream &operator<<(QDataStream &ds, const TemplateData &td)
{
ds << td.templateId()
<< td.hierarchyNumber()
<< td.equipmentNumber()
<< td.typeId()
<< QString::fromStdString(td.symbol())
<< QString::fromStdString(td.name())
<< QString::fromStdString(td.designator())
<< QString::fromStdString(td.tacticalIdentifier())
<< QString::fromStdString(td.info())
<< td.modId()
<< td.superiorModId()
<< td.isDeleted();
return ds;
}
QDataStream &operator>>(QDataStream &ds, TemplateData &td)
{
int templateId, hierarchyNumber, equipmentNumber, typeId, modId, superiorModId;
QString symbol, name, designator, tacticalIdentifier, info;
bool isDeleted;
ds >> templateId
>> hierarchyNumber
>> equipmentNumber
>> typeId
>> symbol
>> name
>> designator
>> tacticalIdentifier
>> info
>> modId
>> superiorModId
>> isDeleted;
td.templateId(templateId);
td.equipmentNumber(equipmentNumber);
td.typeId(typeId);
td.symbol(symbol.toStdString());
td.name(name.toStdString());
td.designator(designator.toStdString());
td.tacticalIdentifier(tacticalIdentifier.toStdString());
td.info(info.toStdString());
td.modId(modId);
td.superiorModId(superiorModId);
td.isDeleted(isDeleted);
return ds;
}
//----------------------------------------------------------------------------
ParticipantTemplateEditModel::ParticipantTemplateEditModel(QObject *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
int rootId)
: ParticipantIconModelBase(ppmDtc,
asbIfc,
{ tr("Designator"), tr("Tact. Identifier"), tr("Class"), tr("Type"), tr("Equip. No."), QStringLiteral("TemplateId") },
new NGLTreeItem(QVariant()),
parent,
getLogger("ParticipantTemplateEditModel"))
, m_rootTemplateId(rootId)
, m_firingUnitValidator(new FiringUnitValidator(ppmDtc, this))
{
connect(this, &ParticipantTemplateEditModel::signalDataDropped,
this, &ParticipantTemplateEditModel::internalDataChanged);
qRegisterMetaTypeStreamOperators<ParticipantManagement::TemplateData>();
setMimeType(QStringLiteral("ParticipantTemplateEditModel_%1").arg(qlonglong(this)));
init();
}
QVariant ParticipantTemplateEditModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || role != Qt::DisplayRole)
return NGLTreeModel::data(index, role);
NGLTreeItem *item = privateData(index);
if (item->data().canConvert<ParticipantManagement::TemplateData>())
{
ParticipantManagement::TemplateData templateData = item->data().value<ParticipantManagement::TemplateData>();
switch (index.column())
{
case ColDesignator:
return QString::fromStdString(templateData.designator());
case ColIdentifier:
return QString::fromStdString(templateData.tacticalIdentifier());
case ColTypeClass:
return typeClassStringFromTypeId(templateData.typeId());
case ColType:
return ParticipantManagement::trTypeName(m_types.value(templateData.typeId()).name());
case ColEquipmentNumber:
if (templateData.equipmentNumber() != 0)
return templateData.equipmentNumber();
return QVariant();
case ColTemplateId:
return templateData.templateId();
}
}
return NGLTreeModel::data(index, role);
}
int ParticipantTemplateEditModel::columnCount(const QModelIndex &parent) const
{
int cc = NGLTreeModel::columnCount(parent);
#ifndef LTS_DEBUG
// template id only in dev mode
cc -= 1;
#endif
return cc;
}
void ParticipantTemplateEditModel::init()
{
NGLTreeModel::resetModel();
m_dataToDelete.clear();
onInsertTemplate(m_rootTemplateId, QModelIndex(), false);
}
std::vector<TemplateData> ParticipantTemplateEditModel::getChildrenOf(NGLTreeItem *item,
int parentId,
int hierarchyNumber,
bool bOnlyModified,
int &highestModId) const
{
if (!item)
return {};
std::vector<TemplateData> ret;
ParticipantManagement::TemplateData templateData = item->data().value<ParticipantManagement::TemplateData>();
templateData.superiorModId(parentId);
templateData.hierarchyNumber(hierarchyNumber);
if (templateData.modId() == 0)
templateData.modId(++highestModId);
// check for children of this item
for (int i = 0; i < item->childCount(); i++)
{
const auto c = getChildrenOf(item->child(i), templateData.modId(), i + 1, bOnlyModified, highestModId);
ret.insert(ret.end(), c.begin(), c.end());
}
if (!bOnlyModified || item->modified() || !ret.empty())
ret.push_back(std::move(templateData));
return ret;
}
//slots
bool ParticipantTemplateEditModel::onInsertRow(const QModelIndex &parent, ParticipantManagement::TemplateData templateData)
{
templateData.templateId(0); //reset templateId is new!
templateData.modId(0); //need new modId
QVariant data;
data.setValue(templateData);
NGLTreeItem *item = createItem(data, QIcon());
item->setModified(true);
emit internalDataChanged();
return NGLTreeModel::insertRow(rowCount(parent), parent, item);
}
bool ParticipantTemplateEditModel::onUpdateRow(const QModelIndex &index, const ParticipantManagement::TemplateData &templateData)
{
if (!index.isValid())
return false;
QVariant data;
data.setValue(templateData);
NGLTreeItem *item = privateData(index);
item->setIcon(QIcon());
tryRenderSymbol(QString::fromStdString(templateData.symbol()), item);
emit internalDataChanged();
return setItemData(index, data, item->icon());
}
bool ParticipantTemplateEditModel::onDeleteRow(const QModelIndex &idx, bool isFirstItem)
{
while (rowCount(idx) > 0)
onDeleteRow(NGLTreeModel::index(0, 0, idx), false);
if (m_rootTemplateId > 0 && isFirstItem) //edit mode
{
NGLTreeItem *item = privateData(idx);
ParticipantManagement::TemplateData data = item->data().value<ParticipantManagement::TemplateData>();
if (data.modId() != 0) //only append old items to remove list
{
data.isDeleted(true);
m_dataToDelete.append(data);
}
}
removeRow(idx.row(), idx.parent());
emit internalDataChanged();
return true;
}
std::vector<ParticipantManagement::TemplateData> ParticipantTemplateEditModel::templateData(bool bOnlyModified) const
{
return templateData(QModelIndex(), false, bOnlyModified);
}
std::vector<ParticipantManagement::TemplateData> ParticipantTemplateEditModel::templateDataAsCopy(const QModelIndex &idx) const
{
return templateData(idx, true, false);
}
std::vector<ParticipantManagement::TemplateData> ParticipantTemplateEditModel::templateData(const QModelIndex &idx, bool bAsNewTemplate, bool bOnlyModified) const
{
if (m_rootItem->childCount() == 0)
return {};
NGLTreeItem *root = idx.isValid() ? privateData(idx) : m_rootItem->child(0);
// gehen wir mal davon aus, dass man nie mehr als 1mrd template - Einträge angelegt hat...
int modId = 1000000000;
auto templateDatas(getChildrenOf(root, 0, 1, bOnlyModified, modId));
if (bAsNewTemplate)
{
// reset templateId
for (auto &templ : templateDatas)
templ.templateId(0);
}
else
{
templateDatas.insert(templateDatas.end(), m_dataToDelete.begin(), m_dataToDelete.end());
}
return templateDatas;
}
void ParticipantTemplateEditModel::dataCommitted()
{
m_dataToDelete.clear();
resetModifedFlag(m_rootItem);
}
QSet<int> ParticipantTemplateEditModel::usedEquipmentNumbers() const
{
return usedEquipmentNumbers(m_rootItem);
}
TemplateData ParticipantTemplateEditModel::getTemplateData(const QModelIndex &index) const
{
return privateData(index)->data().value<ParticipantManagement::TemplateData>();
}
QSet<int> ParticipantTemplateEditModel::usedEquipmentNumbers(NGLTreeItem *item) const
{
QSet<int> ret;
const TemplateData data = item->data().value<ParticipantManagement::TemplateData>();
if (data.equipmentNumber() != 0)
ret += data.equipmentNumber();
for (int i = 0; i < item->childCount(); ++i)
ret += usedEquipmentNumbers(item->child(i));
return ret;
}
Qt::ItemFlags ParticipantTemplateEditModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags f = NGLTreeModel::flags(index);
// can not drag the whole tree, also we allow only dragging the first column
if (index.column() != 0 || !index.parent().isValid())
f &= ~Qt::ItemIsDragEnabled;
// drop also only on first column
if (index.column() != 0)
f &= ~Qt::ItemIsDropEnabled;
return f;
}
bool ParticipantTemplateEditModel::canDropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
const QModelIndex &parent) const
{
if (!ParticipantIconModelBase::canDropMimeData(data, action, row, column, parent))
return false;
// only drop on first column allowed
if (column > 0)
return false;
// we do not allow creating a new root knot
if (!parent.isValid() && m_rootItem->childCount() > 0)
return false;
const TemplateData &parentItem = getTemplateData(parent);
if (!isUnitType(parentItem.typeId()))
return false;
DEBUG_LOG(m_logger) << "can drop on " << row << ", " << column << ", parent: "
<< parent.row() << "," << parent.column() << ", " << parent.isValid()
<< ", action: " << action;
// make sure to not drop a parent on a child of this parent
// QAbstractItemModel takes care for this within internal drops,
// but can not do this for external drops (e.g. tactical organisation)
const QVector<NGLTreeItem *> tiSources = getMimeDataItems(data, m_mimeType);
if (tiSources.isEmpty())
return false;
// copy due to qDeleteAll!
const TemplateData pdSource = tiSources.first()->data().value<ParticipantManagement::TemplateData>();
qDeleteAll(tiSources);
if (m_firingUnitValidator)
{
FiringUnitValidator::FiringUnitRestrictions restrictions = m_firingUnitValidator->getRestrictions(this, parent);
if (restrictions != FiringUnitValidator::NO_RESTRICTION)
{
if (restrictions.testFlag(FiringUnitValidator::IS_AT_MAX_CAPACITY))
return false;
if (restrictions.testFlag(FiringUnitValidator::ONLY_SAME_GEAR_CLASS_ARTILLERY_ALLOWED))
{
if (!m_firingUnitValidator->isSameGearClassArtillery(parentItem.typeId(), pdSource.typeId()))
return false;
if (m_firingUnitValidator->isArtilleryUnit(parentItem.typeId()) && m_firingUnitValidator->isArtilleryUnit(pdSource.typeId()))
return false;
}
if (restrictions.testFlag(FiringUnitValidator::NO_ARTILLERY_PARTICIPANTS_ALLOWED))
{
if (m_firingUnitValidator->isArtilleryWeaponSystem(pdSource.typeId()))
return false;
}
if (restrictions.testFlag(FiringUnitValidator::NO_TYPE_CHANGE_ALLOWED))
{
const Type allowedType = m_firingUnitValidator->getAllowedType(this, parent);
if (pdSource.typeId() != allowedType.id())
return false;
if (m_dtc->isAdlerVerbund(pdSource.typeId()))
return false;
}
}
}
return true;
}
bool ParticipantTemplateEditModel::onInsertTemplate(int rootId,
const QModelIndex &parentIndex,
bool asCopy)
{
if (rootId <= 0)
return false;
QHash<int, TemplateData> tmap;
QHash<int, QSet<int>> parentId2id;
const QSet<int> usedEquipNo(usedEquipmentNumbers());
QVector<ParticipantManagement::TemplateParticipant> templateMap;
m_dtc->templateParticipantsFromTemplateId(rootId, templateMap);
for (const ParticipantManagement::TemplateParticipant &tmpl : qAsConst(templateMap))
{
//should be there
if (!tmpl.templateId())
continue;
// parentId -> id for lookup
parentId2id[tmpl.superiorTemplateId()] += tmpl.templateId();
auto data = m_dtc->convertFromParticipantTemplateToTemplateData(tmpl);
if (asCopy)
{
data.templateId(0);
data.modId(0);
}
if (usedEquipNo.contains(data.equipmentNumber()))
data.equipmentNumber(0);
tmap.insert(tmpl.templateId(), data);
}
NGLTreeItem *root = parentIndex.isValid() ? privateData(parentIndex) : m_rootItem;
// insert recursivly
insertChildrenOf(0, root, parentIndex, parentId2id, tmap);
if (asCopy)
emit internalDataChanged();
return true;
}
//----------------------------------------------------------------------------
void ParticipantTemplateEditModel::insertChildrenOf(int parentId,
NGLTreeItem *parent,
const QModelIndex &parentIdx,
const QHash<int, QSet<int>> &parentId2id,
const QHash<int, TemplateData> &tmap)
{
const QSet<int> childIds = parentId2id.value(parentId);
QMap<int, int> currentHierachyNumbers; // no QSet, must be sorted!
for (int childId : childIds)
{
auto it = tmap.constFind(childId);
if (it == tmap.constEnd())
{
WARNING_LOG(m_logger) << "Can not find template with id " << childId << " - ignoring";
continue;
}
const int templateId = it.key(); // it.value().templateId() is optional and maybe not set
const TemplateData &data = it.value();
if (data.hierarchyNumber() <= 0)
{
WARNING_LOG(m_logger) << "Invalid / no hierarchy number set for participant " << data.templateId() << " - ignoring";
continue;
}
auto hierIt = currentHierachyNumbers.insert(data.hierarchyNumber(), data.hierarchyNumber());
const int insertPos = std::distance(currentHierachyNumbers.begin(), hierIt);
NGLTreeItem *childItem = createItem(QVariant::fromValue(data), QIcon());
DEBUG_LOG(m_logger) << "insert Child " << childItem << "(" << data.templateId() << ", " << data.hierarchyNumber()
<< ") to parent " << parent << " at pos " << insertPos;
insertRow(insertPos, parentIdx, childItem);
const QModelIndex childIdx = index(insertPos, 0, parentIdx);
insertChildrenOf(templateId, childItem, childIdx, parentId2id, tmap);
}
}
//----------------------------------------------------------------------------
NGLTreeItem *ParticipantTemplateEditModel::createItem(const QVariant &data, const QIcon &icon) const
{
auto ret = NGLTreeModel::createItem(data, icon);
const TemplateData templateData = data.value<TemplateData>();
if (templateData.symbol().size() != 0)
{
ParticipantTemplateEditModel *that = const_cast<ParticipantTemplateEditModel*>(this);
// mutable
that->tryRenderSymbol(QString::fromStdString(templateData.symbol()), ret);
}
return ret;
}
} //namespace ParticipantManagement
@@ -0,0 +1,105 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Template Edit Model
* $Id: participant_template_edit_model.h 49756 2020-02-04 08:46:35Z ehrlicher $
* $HeadURL: svn://192.168.133.21/TDS/branches/product/features/3dws_devel/Lts/Plugins/ParticipantManagement/Gui/ParticipantTemplates/participant_template_edit_model.h $
* $Author: ehrlicher $
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Common/participant_icon_model_base.h>
namespace AdvancedSymbology
{
class ForeignDataInterface;
class SymbolResult;
}
namespace LtsSession
{
class LtsSessionDataDds;
}
namespace ParticipantManagement
{
class FiringUnitValidator;
//----------------------------------------------------------------------------
class PPMCOMMON_EXPORT ParticipantTemplateEditModel final : public ParticipantIconModelBase
{
Q_OBJECT
public:
enum Columns
{
ColDesignator,
ColIdentifier,
ColTypeClass,
ColType,
ColEquipmentNumber,
ColTemplateId
};
ParticipantTemplateEditModel(QObject *parent,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
int rootId);
QVariant data(const QModelIndex &index, int role) const override;
int columnCount(const QModelIndex &parent) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
bool canDropMimeData(const QMimeData *data,
Qt::DropAction action,
int row,
int column,
const QModelIndex &parent) const override;
Qt::DropActions supportedDropActions() const override { return Qt::MoveAction; }
Qt::DropActions supportedDragActions() const override { return Qt::MoveAction; }
std::vector<TemplateData> templateData(bool bOnlyModified = true) const;
std::vector<TemplateData> templateDataAsCopy(const QModelIndex &idx = QModelIndex()) const;
void dataCommitted(); // the modified data returned by getTemplateData() was successfully commited into db
QSet<int> usedEquipmentNumbers() const;
TemplateData getTemplateData(const QModelIndex &index) const;
public slots:
bool onInsertRow(const QModelIndex &parent, TemplateData templateData);
bool onUpdateRow(const QModelIndex &index, const TemplateData &templateData);
bool onDeleteRow(const QModelIndex &idx, bool isFirstItem = true);
bool onInsertTemplate(int rootId, const QModelIndex &parentIndex,
bool asCopy);
signals:
void internalDataChanged();
private:
std::vector<TemplateData> templateData(const QModelIndex &idx, bool bAsNewTemplate, bool bOnlyModified) const;
void init();
std::vector<TemplateData> getChildrenOf(NGLTreeItem *item,
int parentId,
int hierarchyNumber,
bool bOnlyModified,
int &highestModId) const;
void insertChildrenOf(int parentId,
NGLTreeItem *parent,
const QModelIndex &parentIdx,
const QHash<int, QSet<int>> &parentId2id,
const QHash<int, TemplateData> &tmap);
NGLTreeItem *createItem(const QVariant &data, const QIcon &icon) const override;
QSet<int> usedEquipmentNumbers(NGLTreeItem *item) const;
private:
int m_rootTemplateId;
QVector<ParticipantManagement::TemplateData> m_dataToDelete;
FiringUnitValidator *m_firingUnitValidator;
};
} //namespace ParticipantManagement
Q_DECLARE_METATYPE(ParticipantManagement::TemplateData)
@@ -0,0 +1,101 @@
/**
* @RDE_HEADER@
* Enhanced Participant Edit Model - show participant structure at specific time point
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2018-02-15
*/
#include "participant_time_point_model.h"
#include <QDateTime>
#include <QTimer>
namespace ParticipantManagement
{
//----------------------------------------------------------------------------
ParticipantTimePointModel::ParticipantTimePointModel(QObject *parent,
const std::shared_ptr<Interface::Dtc> &ppmDtc,
const std::shared_ptr<Interface::Ftc> &ppmFtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
: ParticipantEditModel(parent, ppmDtc, asbIfc)
, m_requestTimer(new QTimer(this))
, m_currentTimePoint(0)
, m_csTimePointModel(Qt::Unchecked)
, m_ppmFtc(ppmFtc)
{
m_requestTimer->setSingleShot(true);
m_requestTimer->setInterval(50);
connect(m_requestTimer, &QTimer::timeout, this, &ParticipantTimePointModel::startRequest);
m_requestHelper.setQuiet(true);
}
void ParticipantTimePointModel::setTimePoint(qint64 tp)
{
if (m_currentTimePoint == tp)
return;
m_currentTimePoint = tp;
m_requestTimer->start();
}
bool ParticipantTimePointModel::onReinitModel(int partyId, const QSet<int> &checkedParticipants, Qt::CheckState cs)
{
if (m_partyId == partyId)
return true;
m_partyId = partyId;
m_partyColor = QColor::fromRgb(QRgb(m_dtc->party(m_partyId).color()));
m_checkedParticipantsTimepointModel = checkedParticipants;
m_csTimePointModel = cs;
m_requestTimer->start();
return true;
}
void ParticipantTimePointModel::startRequest()
{
ParticipantManagement::GetParticipantsRequest req;
req.partyId(partyId());
req.timeStamp(m_currentTimePoint);
m_requestHelper.startSingleRequest([this, req]() { return m_ppmFtc->getParticipantsRequest(req, this); });
}
void ParticipantTimePointModel::onGetParticipantsReply(const GetParticipantsReply &reply)
{
m_requestHelper.requestReply(reply);
NGLTreeModel::resetModel();
QHash<int, ParticipantData> tmap;
QHash<int, QSet<int>> parentId2id;
tmap.reserve(reply.participants().size());
parentId2id.reserve(reply.participants().size());
for (const auto &part : reply.participants())
{
if (part.isDeleted())
continue;
if (part.partyId() != m_partyId)
continue;
// parentId -> id for lookup
parentId2id[part.superiorId()] += part.id();
tmap.insert(part.id(), m_dtc->convertParticipantToParticipantData(part));
};
// insert recursivly
insertChildrenOf(0, m_rootItem, QModelIndex(), parentId2id, tmap, m_checkedParticipantsTimepointModel, m_csTimePointModel);
// unset modifed flag
resetModifedFlag(m_rootItem);
emit participantDataChanged();
}
} //namespace ParticipantManagement
@@ -0,0 +1,47 @@
/**
* @RDE_HEADER@
* Enhanced Participant Edit Model - show participant structure at specific time point
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, SLSE, 2018-02-15
*/
#pragma once
#include "participant_edit_model.h"
#include <ParticipantManagement/ppm_ftc.h>
#include <LtsUtilsGuiDds/request_helper.h>
class QTimer;
namespace ParticipantManagement
{
//----------------------------------------------------------------------------
class PPMCOMMON_EXPORT ParticipantTimePointModel : public ParticipantEditModel,
protected ParticipantManagement::Interface::Ftc::GetParticipantsReplyHandler
{
Q_OBJECT
public:
ParticipantTimePointModel(QObject *parent,
const std::shared_ptr<Interface::Dtc> &ppmDtc,
const std::shared_ptr<Interface::Ftc> &ppmFtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc);
void setTimePoint(qint64 tp);
bool onReinitModel(int partyId, const QSet<int> &checkedParticipants = QSet<int>(), Qt::CheckState cs = Qt::Checked) override;
qint64 timePoint() const { return m_currentTimePoint; }
Q_SIGNALS:
void participantDataChanged();
protected:
void startRequest();
void onGetParticipantsReply(const GetParticipantsReply &reply) override final;
private:
QTimer *m_requestTimer;
qint64 m_currentTimePoint;
LtsUtils::RequestHelper m_requestHelper;
QSet<int> m_checkedParticipantsTimepointModel;
Qt::CheckState m_csTimePointModel;
std::shared_ptr<Interface::Ftc> m_ppmFtc;
};
} // namespace ParticipantManagement
@@ -0,0 +1,229 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Last, SLSE, 2017-11-10
*/
#include "participant_tree_edit_handler.h"
#include "participant_edit_model.h"
#include <QAction>
#include <QMenu>
#include <QTreeView>
#include <QDebug>
namespace ParticipantManagement
{
ParticipantTreeEditHandler::ParticipantTreeEditHandler(LtsDataView::LtsDataView *dataView,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
bool asSupportService,
QObject *parent)
: QObject(parent)
, m_dataView(dataView)
, m_model(qobject_cast<ParticipantEditModel *>(m_dataView->sourceModel()))
, m_asSupportService(asSupportService)
, m_editParticipantsAllowed(false)
, m_dtc(dtc)
, m_ftc(ftc)
, m_requestHelper(nullptr)
{
Q_ASSERT(m_model);
m_dataView->setRootIsDecorated(true);
auto treeView = m_dataView->treeView();
connect(treeView, &QTreeView::customContextMenuRequested,
this, &ParticipantTreeEditHandler::showContextMenu);
QItemSelectionModel *selectionModel = treeView->selectionModel();
connect(selectionModel, &QItemSelectionModel::selectionChanged,
this, &ParticipantTreeEditHandler::signalSelectionChanged);
selectionModel->clearSelection();
connect(treeView, &QTreeView::doubleClicked,
this, &ParticipantTreeEditHandler::signalDoubleClicked);
}
//private
QModelIndex ParticipantTreeEditHandler::selectedIndexView() const
{
const QModelIndexList indexL = m_dataView->selectedRows();
return indexL.isEmpty() ? QModelIndex() : indexL.at(0);
}
bool ParticipantTreeEditHandler::isContainer() const
{
const QModelIndex idx = selectedIndexView();
if (!idx.isValid())
return false;
const int typeId = m_model->privateData(idx)->participant.typeId();
if (typeId <= 0)
return false;
if (m_asSupportService)
return m_dtc->type(typeId).typeClass() == ParticipantManagement::TypeClass_def::SupportUnit;
return m_dtc->type(typeId).typeClass() == ParticipantManagement::TypeClass_def::Unit;
}
QVector<int> ParticipantTreeEditHandler::usedEquipmentNumbers() const
{
return m_model->usedEquipmentNumbers();
}
bool ParticipantTreeEditHandler::isSelectedIndexValid() const
{
return selectedIndexView().isValid();
}
// is selected Index is equiped, it can't be removed
bool ParticipantTreeEditHandler::isSelectedIndexRemovable() const
{
const QModelIndex idx = selectedIndexView();
if (!idx.isValid() || !idx.parent().isValid())
return false;
return m_model->isRowRemovable(m_model->privateData(idx));
}
ParticipantManagement::ParticipantData ParticipantTreeEditHandler::getSelectedData() const
{
const QModelIndex idx = selectedIndexView();
return idx.isValid() ? m_model->privateData(idx)->participant : ParticipantData();
}
void ParticipantTreeEditHandler::removeCurrentRow()
{
const QModelIndex idx = selectedIndexView();
if (!idx.isValid())
return;
m_model->onDeleteRow(idx, true);
}
void ParticipantTreeEditHandler::onRemoveItem()
{
removeCurrentRow();
}
void ParticipantTreeEditHandler::beautifyTreeView(bool keepExpanded)
{
m_dataView->expandAll();
m_dataView->resizeHeadersByContent();
/*
m_dataView->resizeSection(0, m_dataView->treeView()->columnWidth(0) +
m_dataView->treeView()->iconSize().width() + 10);
*/
if (!keepExpanded)
m_dataView->collapseAll();
}
void ParticipantTreeEditHandler::partyHasChanged(int newPartyId, bool keepExpanded)
{
if (m_model->partyId() == newPartyId)
return;
if (m_model->onReinitModel(newPartyId))
beautifyTreeView(keepExpanded);
}
bool ParticipantTreeEditHandler::onApplyChanges()
{
ModifyParticipantDataRequest req;
req.data(m_model->participantData());
if (req.data().size() == 0)
return true;
if (!m_requestHelper)
m_requestHelper = new LtsUtils::RequestHelper(this);
m_requestHelper->addRequest([this, req]()
{
return m_ftc->modifyParticipantDataRequest(req, this);
});
return m_requestHelper->startRequests();
}
/*
* If 'expand' is true all subnodes of the currently selected node will be expanded.
* If 'expand' is false all subnodes of the currently selected node will be collapsed.
*/
void ParticipantTreeEditHandler::expandNodeChildren(QTreeView *pTreeView, const QModelIndex &index, bool expand)
{
if (!index.isValid())
return;
int childCount = index.model()->rowCount(index);
for (int i = 0; i < childCount; i++) {
const QModelIndex &child = index.model()->index(i,0, index);
// Recursively call the function for each child node.
expandNodeChildren(pTreeView, child, expand);
}
if(expand)
pTreeView->expand(index);
else
pTreeView->collapse(index);
}
void ParticipantTreeEditHandler::showContextMenu(const QPoint &position)
{
QTreeView *tv = qobject_cast<QTreeView*>(sender());
if (!tv)
return;
const QModelIndex curIdx = tv->currentIndex();
const QModelIndex idx = curIdx.column() == 0 ? curIdx : tv->model()->index(curIdx.row(), 0, curIdx.parent());
if (!idx.isValid())
return;
QMenu menu;
if (m_editParticipantsAllowed)
{
QAction *editParticipantAction = new QAction(tr("Edit"), &menu);
connect(editParticipantAction, &QAction::triggered, this, [this]() { emit signalEditParticipant(); });
menu.addAction(editParticipantAction);
}
if (tv->model()->rowCount(idx) != 0)
{
if (tv->isExpanded(idx))
{
QAction *collapseAction = new QAction(tr("Collapse"), &menu);
connect(collapseAction, &QAction::triggered, this, [tv, idx]() { tv->collapse(idx);});
menu.addAction(collapseAction);
QAction *collapseAllAction = new QAction(tr("Collapse all"), &menu);
connect(collapseAllAction, &QAction::triggered, this, [this, tv, idx]() { expandNodeChildren(tv, idx, false); });
menu.addAction(collapseAllAction);
}
else
{
QAction *expandAction = new QAction(tr("Expand"), &menu);
connect(expandAction, &QAction::triggered, this, [tv, idx]() { tv->expand(idx);});
menu.addAction(expandAction);
}
QAction *expandAllAction = new QAction(tr("Expand all"), &menu);
connect(expandAllAction, &QAction::triggered, this, [this, tv, idx]() { expandNodeChildren(tv, idx, true); });
menu.addAction(expandAllAction);
}
if (!menu.actions().isEmpty())
menu.exec(tv->viewport()->mapToGlobal(position));
}
void ParticipantTreeEditHandler::onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject)
{
if (!m_requestHelper)
return;
if (!replyObject.error())
m_model->dataCommitted();
emit signalChangesMade();
m_requestHelper->requestReply(replyObject);
}
}
@@ -0,0 +1,75 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Last, SLSE, 2017-11-10
*/
#pragma once
#include <memory>
#include <LtsDataView/lts_data_view.h>
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
#include <LtsUtilsGuiDds/request_helper.h>
namespace ParticipantManagement
{
class ParticipantEditModel;
class ParticipantTreeFilterProxyModel;
class PPMCOMMON_EXPORT ParticipantTreeEditHandler : public QObject, protected ParticipantManagement::Interface::Ftc::ModifyParticipantDataReplyHandler
{
Q_OBJECT
public:
ParticipantTreeEditHandler(LtsDataView::LtsDataView *dataView,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
bool asSupportService,
QObject *parent = nullptr);
void setEditParticipantsAllowed(bool bAllow) { m_editParticipantsAllowed = bAllow; }
QModelIndex selectedIndexView() const;
bool isSelectedIndexValid() const;
bool isSelectedIndexRemovable() const;
bool isContainer() const;
QVector<int> usedEquipmentNumbers() const;
ParticipantManagement::ParticipantData getSelectedData() const;
void beautifyTreeView(bool keepExpanded);
void partyHasChanged(int newPartyId, bool keepExpanded = true);
signals:
void signalChangesMade();
void signalDoubleClicked();
void signalSelectionChanged();
void signalEditParticipant(); // use getSelectedData() to retrieve the current participant data
public slots:
bool onApplyChanges();
void onRemoveItem();
void showContextMenu(const QPoint &position);
private:
void expandNodeChildren(QTreeView *pTreeView, const QModelIndex &index, bool expand);
void removeCurrentRow();
void onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject) override final;
LtsDataView::LtsDataView *m_dataView;
ParticipantEditModel *m_model;
bool m_asSupportService;
bool m_editParticipantsAllowed;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
LtsUtils::RequestHelper *m_requestHelper;
};
}
@@ -0,0 +1,181 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, NLE, 2020-02-10
*/
#include "participant_vulnerability_types.h"
#include <ProjectDataManagement/pdm_to_string.h>
#include <LtsUtilsSettings/settings.h>
#include <QComboBox>
#include <QDebug>
namespace ParticipantManagement
{
static ProjectDataManagement::VulnerabilityClass vulnerabilityClassFromTypeClass(TypeClass tc)
{
switch (tc.underlying())
{
case TypeClass::Human:
return ProjectDataManagement::VulnerabilityClass::SoldierInjuries;
case TypeClass::GroundVehicle:
case TypeClass::Vessel:
case TypeClass::VehicleWithGear:
case TypeClass::WeaponSystem:
return ProjectDataManagement::VulnerabilityClass::VehicleDamages;
case TypeClass::SupportEntity:
case TypeClass::SupportUnit:
case TypeClass::Unit:
case TypeClass::Unknown:
case TypeClass::Aircraft:
return ProjectDataManagement::VulnerabilityClass::Unknown;
}
Q_ASSERT(false);
return ProjectDataManagement::VulnerabilityClass::Unknown;
}
QVector<ProjectDataManagement::VulnerabilityState> vulnerabilityStatesForTypeClass(TypeClass tc)
{
using namespace ProjectDataManagement;
const LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
const bool hasVulnerabilityStateLightDamage = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateLightDamage")).toBool();
const bool hasVulnerabilityStateMediumDamage = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateMediumDamage")).toBool();
const bool hasVulnerabilityStateHeavyDamage = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateHeavyDamage")).toBool();
const bool hasVulnerabilityStateMobilityKill = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateMobilityKill")).toBool();
const bool hasVulnerabilityStateVisibleMobilityKill = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateVisibleMobilityKill")).toBool();
const bool hasVulnerabilityStateWeaponSystemDamage = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateWeaponSystemDamage")).toBool();
const bool hasVulnerabilityStateVisibleWeaponSystemDamage = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateVisibleWeaponSystemDamage")).toBool();
const bool hasVulnerabilityStateTemporarySeverance = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasVulnerabilityStateTemporarySeverance")).toBool();
switch (tc.underlying())
{
case TypeClass::Human:
{
QVector<ProjectDataManagement::VulnerabilityState> ret;
ret += VulnerabilityState::CombatReady;
if (hasVulnerabilityStateLightDamage)
ret += VulnerabilityState::LightDamage;
if (hasVulnerabilityStateMediumDamage)
ret += VulnerabilityState::MediumDamage;
if (hasVulnerabilityStateHeavyDamage)
ret += VulnerabilityState::HeavyDamage;
if (hasVulnerabilityStateWeaponSystemDamage)
ret += VulnerabilityState::WeaponSystemDamage;
if (hasVulnerabilityStateVisibleWeaponSystemDamage)
ret += VulnerabilityState::VisibleWeaponSystemDamage;
if (hasVulnerabilityStateTemporarySeverance)
ret += VulnerabilityState::TemporarySeverance;
ret += VulnerabilityState::CatastrophicKill;
return ret;
}
case TypeClass::GroundVehicle:
case TypeClass::Vessel:
case TypeClass::VehicleWithGear:
case TypeClass::WeaponSystem:
{
// ets nur CombatReady, LightDamage, HeavyDamage, MobilityKill, CatastrophicKill
QVector<ProjectDataManagement::VulnerabilityState> ret;
ret += VulnerabilityState::CombatReady;
if (hasVulnerabilityStateLightDamage)
ret += VulnerabilityState::LightDamage;
if (hasVulnerabilityStateMediumDamage)
ret += VulnerabilityState::MediumDamage;
if (hasVulnerabilityStateHeavyDamage)
ret += VulnerabilityState::HeavyDamage;
if (hasVulnerabilityStateMobilityKill)
ret += VulnerabilityState::MobilityKill;
if (hasVulnerabilityStateVisibleMobilityKill)
ret += VulnerabilityState::VisibleMobilityKill;
if (hasVulnerabilityStateWeaponSystemDamage)
ret += VulnerabilityState::WeaponSystemDamage;
if (hasVulnerabilityStateVisibleWeaponSystemDamage)
ret += VulnerabilityState::VisibleWeaponSystemDamage;
if (hasVulnerabilityStateTemporarySeverance)
ret += VulnerabilityState::TemporarySeverance;
ret += VulnerabilityState::CatastrophicKill;
return ret;
}
case TypeClass::SupportEntity:
case TypeClass::SupportUnit:
case TypeClass::Unit:
return {};
case TypeClass::Unknown:
case TypeClass::Aircraft:
return { VulnerabilityState::CombatReady, VulnerabilityState::CatastrophicKill };
}
Q_ASSERT(false);
return {};
}
QVector<ProjectDataManagement::OcCode> ocCodeForTypeClass(TypeClass tc)
{
using namespace ProjectDataManagement;
const LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
const bool hasOcCodeWoundingPaused = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasOcCodeWoundingPaused")).toBool();
const bool hasOcCodeWoundingContinue = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasOcCodeWoundingContinue")).toBool();
const bool hasOcCodeOptimalTreatment = ps->value(QStringLiteral("ppm"),
QStringLiteral("hasOcCodeOptimalTreatment")).toBool();
switch (tc.underlying())
{
case TypeClass::Human:
{
QVector<ProjectDataManagement::OcCode> ret;
ret.reserve(3);
if (hasOcCodeWoundingPaused)
ret += OcCode::WoundingPaused;
if (hasOcCodeWoundingContinue)
ret += OcCode::WoundingContinue;
if (hasOcCodeOptimalTreatment)
ret += OcCode::OptimalTreatment;
ret.squeeze();
return ret;
}
case TypeClass::GroundVehicle:
case TypeClass::Vessel:
case TypeClass::VehicleWithGear:
case TypeClass::WeaponSystem:
case TypeClass::SupportEntity:
case TypeClass::SupportUnit:
case TypeClass::Unit:
case TypeClass::Unknown:
case TypeClass::Aircraft:
return {};
}
Q_ASSERT(false);
return {};
}
void insertVulnerabilityStates(QComboBox *cbx, TypeClass tc)
{
using namespace ProjectDataManagement;
VulnerabilityClass cls = vulnerabilityClassFromTypeClass(tc);
const auto vec = vulnerabilityStatesForTypeClass(tc);
for (const auto vs : vec)
cbx->addItem(toString(vs, cls), vs.underlying());
// OcCodes
const auto ocVec = ocCodeForTypeClass(tc);
for (const auto vs : ocVec)
cbx->addItem(toString(vs), vs.underlying()+100);
}
}
@@ -0,0 +1,23 @@
/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Christian Ehrlicher, NLE, 2020-02-10
*/
#pragma once
#include <ProjectDataManagement/pdm_enums.hpp>
#include <ParticipantManagement/ppm_enums.hpp>
#include <ParticipantManagement/Gui/Common/ppmcommon_export.h>
#include <QVector>
class QComboBox;
namespace ParticipantManagement
{
PPMCOMMON_EXPORT QVector<ProjectDataManagement::VulnerabilityState> vulnerabilityStatesForTypeClass(TypeClass tc);
PPMCOMMON_EXPORT QVector<ProjectDataManagement::OcCode> ocCodeForTypeClass(TypeClass tc);
PPMCOMMON_EXPORT void insertVulnerabilityStates(QComboBox *cbx, TypeClass tc);
}