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,52 @@
#
# $Id$
# $HeadURL$
# $Author$
# Created by Mike Wille, SLSE, 2016-05-05
#
SET(participant_edit_gui_SRCS
participant_edit_gui_plugin.cpp
participant_edit_gui_plugin.h
participant_edit.cpp
participant_edit.h
participant_orga_model.cpp
participant_orga_model.h
participant_organisation.cpp
participant_organisation.h
participant_pool_model.cpp
participant_pool_model.h
participant_unit_namer.cpp
participant_unit_namer.h
tactical_organisation.cpp
tactical_organisation.h
)
NGL_WRAP_UI(participant_edit_gui_SRCS
participant_edit.ui
participant_organisation.ui
participant_unit_namer.ui
tactical_organisation.ui
)
NGL_ADD_LIBRARY2(WS PpmParticipantEditGuiPlugin MODULE ${participant_edit_gui_SRCS})
NGL_TARGET_LINK_LIBRARIES(PpmParticipantEditGuiPlugin
AsbDataPluginInterface
AsbHelper
nglwidgets
NGLLogger
LtsPrinting
PpmCommon
PpmGuiParticipantsPluginInterface
PpmGuiComboboxPluginInterface
PpmGuiTemplatesPluginInterface
PpmDataPluginInterface
LtsDataView
LtsWidgets
LtsSession
LtsSessionData
LtsUtilsGuiDds
LtsUtilsSettings
svcCoreClient # Core Ftc - for TLH
)
@@ -0,0 +1,593 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - Participant Edit
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_edit.h"
#include "ui_participant_edit.h"
#include <Common/participant_beautify_view.h>
#include <Common/participant_edit_item.h>
#include <Common/participant_edit_model.h>
#include <Common/participant_firing_unit_validator.h>
#include <Common/participant_tree_edit_handler.h>
#include <LtsDataView/search_model.h>
#include <LtsPrinting/printing.h>
#include <LtsSession/lts_session.h>
#include <ParticipantManagement/logger.h>
#include <QAction>
#include <QHeaderView>
#include <QJsonDocument>
#include <QTableView>
#include <QTimer>
#include <QTreeView>
namespace ParticipantManagement
{
int ParticipantEdit::s_preselectedParty = -1;
ParticipantEdit::ParticipantEdit(LtsSession::LtsSession *session, bool asSupportService, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_asSupportService(asSupportService)
, m_actionRemove(nullptr)
, m_actionEdit(nullptr)
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_session(session)
, m_pbTreeView(new QPushButton(tr("Tree View")))
, m_pbTableView(new QPushButton(tr("Table View")))
, m_pbTreeViewDummy(new QPushButton(m_pbTreeView->text()))
, m_pbTableViewDummy(new QPushButton(m_pbTableView->text()))
, m_ui(new Ui::ParticipantEdit)
, m_logger(getLogger("ParticipantEdit"))
{
m_ui->setupUi(this);
m_ui->cbParty->setVisible(!m_asSupportService); // hide when SupportService
m_ui->lblParty->setVisible(!m_asSupportService);
m_ui->treeViewEdit->treeView()->setDragEnabled(true);
m_ui->treeViewEdit->treeView()->setDragDropMode(QAbstractItemView::DragDrop);
m_ui->treeViewEdit->treeView()->setDefaultDropAction(Qt::MoveAction);
// this will make the tree view look like a table
m_ui->tableViewEdit->treeView()->setIndentation(0);
m_ui->tableViewEdit->treeView()->setItemsExpandable(false);
// add buttons to switch between a tree view and a table view
m_pbTreeViewDummy->setEnabled(false);
m_pbTableViewDummy->setEnabled(false);
QHBoxLayout *hboxTree = new QHBoxLayout;
hboxTree->addWidget(m_pbTreeViewDummy);
hboxTree->addWidget(m_pbTableView);
QWidget *widgetTree = new QWidget;
widgetTree->setLayout(hboxTree);
m_ui->treeViewEdit->setCustomWidget(widgetTree);
m_pbTreeViewDummy->setEnabled(false);
m_pbTableViewDummy->setEnabled(false);
QHBoxLayout *hboxTable = new QHBoxLayout;
hboxTable->addWidget(m_pbTreeView);
hboxTable->addWidget(m_pbTableViewDummy);
QWidget *widgetTable = new QWidget;
widgetTable->setLayout(hboxTable);
m_ui->tableViewEdit->setCustomWidget(widgetTable);
connect(m_pbTreeView, &QPushButton::clicked, this, &ParticipantEdit::onSwitchToTreeView);
connect(m_pbTableView, &QPushButton::clicked, this, &ParticipantEdit::onSwitchToTableView);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &ParticipantEdit::onAddItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &ParticipantEdit::onEditItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &ParticipantEdit::onPrint);
if (m_asSupportService)
setOnlineHelpFilename(QStringLiteral("Situation-Edit_Support_Participants"));
else
setOnlineHelpFilename(QStringLiteral("Situation-Edit_Participants"));
m_ui->treeViewEdit->treeView()->setContextMenuPolicy(Qt::CustomContextMenu);
m_ui->tableViewEdit->treeView()->setContextMenuPolicy(Qt::CustomContextMenu);
setStyleSheet(QStringLiteral("QToolTip { background-color: #ffffff; }"));
}
ParticipantEdit::~ParticipantEdit() { delete m_ui; }
bool ParticipantEdit::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
{
// interfaces ...............................................................................................................
if (!dtc || !ftc || !ppmGuiCbxIfc)
return false;
if (m_dtc)
return false;
m_dtc = dtc;
m_ftc = ftc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
m_asb = asbIfc;
// tree model ...............................................................................................................
m_model = new ParticipantEditModel(this, m_dtc, m_asb);
connect(m_model, &ParticipantEditModel::internalDataChanged, this, &ParticipantEdit::slotChangesMade);
// proxy model for the tree view ............................................................................................
m_proxyTree = new ParticipantTreeFilterProxyModel(this);
m_proxyTree->setSourceModel(m_model);
// firing unit validator ....................................................................................................
if (m_firingUnitValidator)
delete m_firingUnitValidator;
m_firingUnitValidator = new FiringUnitValidator(m_dtc, this);
m_ui->treeViewEdit->setModel(m_proxyTree);
m_ui->treeViewEdit->setContextMenuPolicy(Qt::CustomContextMenu);
#ifndef LTS_DEBUG
m_ui->treeViewEdit->setColumnHidden(ParticipantEditModel::ColParticipantId, true);
#endif
// proxy model for the table view ...........................................................................................
m_proxyTable = new ParticipantTableFilterProxyModel(this);
m_proxyTable->setSourceModel(m_model);
connect(m_ui->tableViewEdit, &LtsDataView::LtsDataView::filterChanged, m_proxyTable, &ParticipantTableFilterProxyModel::onFilter);
connect(m_ui->tableViewEdit, &LtsDataView::LtsDataView::sortOrderChanged, this, &ParticipantEdit::onSortTableView);
connect(m_model, &ParticipantEditModel::internalDataChanged, m_proxyTable, &ParticipantTableFilterProxyModel::init);
m_ui->tableViewEdit->setModel(m_proxyTable);
m_ui->tableViewEdit->setContextMenuPolicy(Qt::CustomContextMenu);
#ifndef LTS_DEBUG
m_ui->tableViewEdit->setColumnHidden(ParticipantEditModel::ColParticipantId, true);
#endif
// actions ..................................................................................................................
m_actionRemove = new QAction(QIcon(QLatin1String("icon:remove.svg")), tr("Remove"), this);
m_actionEdit = new QAction(QIcon(QLatin1String("icon:edit.svg")), tr("Edit"), this);
// party combo box ..........................................................................................................
connect(m_ui->cbParty, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged), this, &ParticipantEdit::onPartyChanged);
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty,
m_asSupportService ? ForeignGuiComboboxInterface::CbxPartyFilter::Oc : ForeignGuiComboboxInterface::CbxPartyFilter::NormalPool);
// tree handler .............................................................................................................
m_pTreehandler = new ParticipantTreeEditHandler(m_ui->treeViewEdit, m_dtc, m_ftc, m_asSupportService, this);
m_pTreehandler->setEditParticipantsAllowed(true);
connect(m_pTreehandler, &ParticipantTreeEditHandler::signalEditParticipant, this, &ParticipantEdit::onEditItem);
connect(m_pTreehandler, &ParticipantTreeEditHandler::signalDoubleClicked, this, &ParticipantEdit::onEditItem);
connect(m_pTreehandler, &ParticipantTreeEditHandler::signalSelectionChanged, this, &ParticipantEdit::onEnaDisa);
connect(m_pTreehandler, &ParticipantTreeEditHandler::signalChangesMade, this, &ParticipantEdit::onChangesMade);
connect(m_actionRemove, &QAction::triggered, m_pTreehandler, &ParticipantTreeEditHandler::onRemoveItem);
connect(m_actionEdit, &QAction::triggered, this, &ParticipantEdit::onEditItem);
connect(m_ui->tableViewEdit->treeView(), &QTreeView::customContextMenuRequested, m_pTreehandler, &ParticipantTreeEditHandler::showContextMenu);
connect(m_ui->tableViewEdit->treeView(), &QTreeView::doubleClicked, this, &ParticipantEdit::onEditItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, m_pTreehandler, &ParticipantTreeEditHandler::onRemoveItem);
// ..........................................................................................................................
const int idx = m_ui->cbParty->findData(s_preselectedParty);
if (idx >= 0)
m_ui->cbParty->setCurrentIndex(idx);
// synchronize tree view and table view .....................................................................................
// filtering
connect(m_ui->treeViewEdit,
&LtsDataView::LtsDataView::filterChanged,
this,
[this]() { onFilterChanged(m_ui->treeViewEdit->searchModel(), m_ui->tableViewEdit->searchModel()); });
connect(m_ui->tableViewEdit,
&LtsDataView::LtsDataView::filterChanged,
this,
[this]() { onFilterChanged(m_ui->tableViewEdit->searchModel(), m_ui->treeViewEdit->searchModel()); });
// selection
connect(m_ui->treeViewEdit, &LtsDataView::LtsDataView::selectionChanged, this, &ParticipantEdit::onSelectionChangedInTree);
connect(m_ui->tableViewEdit, &LtsDataView::LtsDataView::selectionChanged, this, &ParticipantEdit::onSelectionChangedInTable);
// column width
connect(m_ui->treeViewEdit->searchView()->header(),
&QHeaderView::sectionResized,
this,
[this](int column, int oldWidth, int newWidth)
{
Q_UNUSED(oldWidth);
onColumnWidthChanged(m_ui->tableViewEdit->searchView(), column, newWidth);
});
connect(m_ui->tableViewEdit->searchView()->header(),
&QHeaderView::sectionResized,
this,
[this](int column, int oldWidth, int newWidth)
{
Q_UNUSED(oldWidth);
onColumnWidthChanged(m_ui->treeViewEdit->searchView(), column, newWidth);
});
// ..........................................................................................................................
onSwitchToTreeView();
onPartyChanged();
onEnaDisa();
return true;
}
void ParticipantEdit::retranslate() { translate(m_ui, m_asSupportService ? tr("Edit Support Participants") : tr("Edit Participants")); }
bool ParticipantEdit::apply()
{
m_proxyTable->resetMapping();
bool ret = m_pTreehandler->onApplyChanges();
m_proxyTable->init();
return ret;
}
void ParticipantEdit::showIsSimulated()
{
QHash<LtsWidgets::Button, QString> texts({{LtsWidgets::Button::Yes, tr("Ok")}});
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Participant is simulated"), windowTitle(), LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes, texts);
}
void ParticipantEdit::lock()
{
DEBUG_LOG(m_logger) << LOGFUNCTION << " START";
m_ui->cbParty->setEnabled(true); // true!!
// avoid BaseClass::lock to be called. partyEdit stays enabled
DEBUG_LOG(m_logger) << LOGFUNCTION << " END";
}
void ParticipantEdit::unlock()
{
DEBUG_LOG(m_logger) << LOGFUNCTION << " START";
m_ui->cbParty->setEnabled(true);
DEBUG_LOG(m_logger) << LOGFUNCTION << " END";
}
void ParticipantEdit::onPartyChanged()
{
const int newPartyId = m_ui->cbParty->currentData().toInt();
s_preselectedParty = newPartyId;
if (hasUnsavedChanges())
{
switch (askApplyDiscardCancel())
{
case LtsWidgets::Button::Apply:
if (!apply())
return;
__unchange__();
break;
case LtsWidgets::Button::Cancel:
{
QSignalBlocker block(m_ui->cbParty);
m_ui->cbParty->setCurrentIndex(m_ui->cbParty->findData(m_model->partyId(), Qt::UserRole)); // reset position
s_preselectedParty = m_ui->cbParty->currentData().toInt();
return;
}
case LtsWidgets::Button::Discard:
__unchange__(); // can't call resetChanges() by myself :(
break;
default:
break;
}
}
// DEBUG_LOG(m_logger) << LOGFUNCTION << " ParticipantEdit::onPartyChanged !!! -> newPartyId=" << newPartyId;
// m_ui->cbParty->setEnabled(false); // will be re-enabled with reply (::lock, ::unlock)
// tryLockTopicNew(QStringLiteral("LockParty"), newPartyId);
m_proxyTable->resetMapping();
m_proxyTable->disableSorting();
m_pTreehandler->partyHasChanged(newPartyId);
m_proxyTable->init();
// Some icons in the table view won't update automatically after initialization (maybe a timing issue?).
// Workaround: emit dataChanged on the first items (up to 50 rows, since more will not be visible after reinit)
// with a slight delay of 100 msecs to force an update.
QTimer *timer = new QTimer(this);
timer->singleShot(100,
this,
[this, timer]()
{
m_ui->tableViewEdit->treeView()->dataChanged(m_proxyTable->index(0, 0),
m_proxyTable->index(std::min(50, m_proxyTable->rowCount()), 0),
{Qt::DecorationRole});
timer->deleteLater();
});
}
void ParticipantEdit::onPrint() { LtsPrinting::printView(m_session, this, m_ui->treeViewEdit->treeView()); }
void ParticipantEdit::onChangesMade()
{
onEnaDisa();
if (m_model->onReinitModel(s_preselectedParty))
beautifyTreeView(m_ui->treeViewEdit->treeView(), m_model, true);
}
void ParticipantEdit::onBeautifyTreeView() { beautifyTreeView(m_ui->treeViewEdit->treeView(), m_model, true); }
void ParticipantEdit::onEnaDisa()
{
bool enableAdd = false;
bool enableEdit = false;
bool enableRemove = false;
if (m_pTreehandler->isSelectedIndexValid())
{
if (m_dtc->isAdlerVerbund(m_pTreehandler->getSelectedData().typeId()))
{
DEBUG_LOG(m_logger) << "Can't Edit Adler SAA Participants";
enableEdit = true;
}
else
{
enableAdd = m_pTreehandler->isContainer();
if (m_firingUnitValidator)
enableAdd &= m_firingUnitValidator->hasUnitCapacities(m_model, m_pTreehandler->selectedIndexView());
if (m_pTreehandler->isSelectedIndexRemovable())
enableRemove = true;
enableEdit = true;
}
}
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, enableAdd && m_ui->treeViewEdit->isVisible());
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, enableEdit);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, enableRemove && m_ui->treeViewEdit->isVisible());
m_actionRemove->setEnabled(enableRemove);
m_actionEdit->setEnabled(enableEdit);
}
void ParticipantEdit::onAddItem()
{
ParticipantEditItem *newItemDlg = new ParticipantEditItem(m_asSupportService, m_session, this);
ParticipantManagement::ParticipantData dataAll = m_pTreehandler->getSelectedData();
ParticipantData data = ParticipantData();
data.designator(dataAll.designator());
data.tacticalIdentifier(dataAll.tacticalIdentifier());
const bool addItem = true;
newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
QModelIndex workingIndex = m_pTreehandler->selectedIndexView();
if (!newItemDlg->init(workingIndex,
m_ui->cbParty->currentData().toInt(),
m_dtc,
m_ppmGuiCbxIfc,
m_asb,
static_cast<const ParticipantData>(data),
addItem,
m_pTreehandler->usedEquipmentNumbers()))
{
delete newItemDlg;
return;
}
connect(newItemDlg, &ParticipantEditItem::addItem, m_model, &ParticipantEditModel::onInsertRow);
connect(newItemDlg, &ParticipantEditItem::addItem, this, &ParticipantEdit::onBeautifyTreeView);
connect(newItemDlg, &ParticipantEditItem::addItem, m_proxyTable, &ParticipantTableFilterProxyModel::init);
if (m_firingUnitValidator)
{
newItemDlg->setIsAdler(m_firingUnitValidator->isAdler(m_model, workingIndex));
const int unitGearClassType = m_firingUnitValidator->getGearClassType(m_model, workingIndex);
newItemDlg->setFiringUnitRestrictions(m_model, false, m_firingUnitValidator->getRestrictions(m_model, workingIndex), m_firingUnitValidator, unitGearClassType);
connect(newItemDlg,
&ParticipantEditItem::addItem,
this,
[this, newItemDlg, unitGearClassType](const QModelIndex &parent, const ParticipantData &newData)
{
Q_UNUSED(newData)
if (!newItemDlg || !m_firingUnitValidator)
return;
newItemDlg->setFiringUnitRestrictions(m_model, false, m_firingUnitValidator->getRestrictions(m_model, parent), m_firingUnitValidator, unitGearClassType);
});
}
newItemDlg->show();
}
void ParticipantEdit::onEditItem()
{
if (!m_pTreehandler->isSelectedIndexValid() || m_newItemDlg)
return;
ParticipantManagement::ParticipantData data = m_pTreehandler->getSelectedData();
if (data.isSimulated())
showIsSimulated();
m_newItemDlg = new ParticipantEditItem(m_asSupportService, m_session, this);
m_newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
QModelIndex workingIndex = m_pTreehandler->selectedIndexView();
if (!m_newItemDlg->init(workingIndex, m_ui->cbParty->currentData().toInt(), m_dtc, m_ppmGuiCbxIfc, m_asb, data, false, m_pTreehandler->usedEquipmentNumbers()))
{
delete m_newItemDlg;
return;
}
QObject::connect(m_newItemDlg,
&ParticipantEditItem::destroyed,
this,
[this]
{
m_newItemDlg = nullptr;
onEnaDisa();
});
QObject::connect(m_newItemDlg, &ParticipantEditItem::updateItem, m_model, &ParticipantEditModel::onUpdateRow);
if (m_firingUnitValidator)
{
const int unitGearClassType = m_firingUnitValidator->getGearClassType(m_model, workingIndex);
m_newItemDlg->setFiringUnitRestrictions(m_model, true, m_firingUnitValidator->getRestrictions(m_model, workingIndex), m_firingUnitValidator, unitGearClassType);
}
m_newItemDlg->show();
}
void ParticipantEdit::onSwitchToTreeView()
{
m_ui->tableViewEdit->hide();
m_ui->treeViewEdit->show();
m_ui->treeViewEdit->expandAll();
if (!m_ui->treeViewEdit->selectionModel()->selectedIndexes().isEmpty()) // scroll to selection
{
const QModelIndex &proxyIndex = m_ui->treeViewEdit->selectionModel()->selectedIndexes().first();
m_ui->treeViewEdit->scrollTo(proxyIndex);
} // if
onEnaDisa();
}
void ParticipantEdit::onSwitchToTableView()
{
m_ui->treeViewEdit->hide();
m_ui->tableViewEdit->show();
if (!m_ui->tableViewEdit->selectionModel()->selectedIndexes().isEmpty()) // scroll to selection
{
const QModelIndex &proxyIndex = m_ui->tableViewEdit->selectionModel()->selectedIndexes().first();
m_ui->tableViewEdit->scrollTo(proxyIndex);
} // if
onEnaDisa();
}
void ParticipantEdit::onSelectionChangedInTree(const QItemSelection &selected, const QItemSelection &deselected)
{
m_ui->tableViewEdit->blockSignals(true);
QModelIndexList indexes = deselected.indexes();
for (const QModelIndex &sourceIndex : qAsConst(indexes))
{
QModelIndex proxyIndex = m_proxyTable->mapFromSource(sourceIndex);
if (m_ui->tableViewEdit->selectionModel()->selectedIndexes().contains(proxyIndex))
m_ui->tableViewEdit->selectionModel()->select(proxyIndex, {QItemSelectionModel::Deselect, QItemSelectionModel::Rows});
} // for
indexes = selected.indexes();
for (const QModelIndex &sourceIndex : qAsConst(indexes))
{
QModelIndex proxyIndex = m_proxyTable->mapFromSource(sourceIndex);
if (!m_ui->tableViewEdit->selectionModel()->selectedIndexes().contains(proxyIndex))
m_ui->tableViewEdit->selectionModel()->select(proxyIndex, {QItemSelectionModel::Select, QItemSelectionModel::Rows});
} // for
m_ui->tableViewEdit->blockSignals(false);
}
void ParticipantEdit::onSelectionChangedInTable(const QItemSelection &selected, const QItemSelection &deselected)
{
m_ui->treeViewEdit->blockSignals(true);
QModelIndexList indexes = deselected.indexes();
for (const QModelIndex &sourceIndex : qAsConst(indexes))
{
QModelIndex proxyIndex = m_proxyTree->mapFromSource(sourceIndex);
if (m_ui->treeViewEdit->selectionModel()->selectedIndexes().contains(proxyIndex))
m_ui->treeViewEdit->selectionModel()->select(proxyIndex, {QItemSelectionModel::Deselect, QItemSelectionModel::Rows});
} // for
indexes = selected.indexes();
for (const QModelIndex &sourceIndex : qAsConst(indexes))
{
QModelIndex proxyIndex = m_proxyTree->mapFromSource(sourceIndex);
if (!m_ui->treeViewEdit->selectionModel()->selectedIndexes().contains(proxyIndex))
m_ui->treeViewEdit->selectionModel()->select(proxyIndex, {QItemSelectionModel::Select, QItemSelectionModel::Rows});
} // for
m_ui->treeViewEdit->blockSignals(false);
}
void ParticipantEdit::onFilterChanged(LtsDataView::SearchModel *from, LtsDataView::SearchModel *to)
{
for (int column = 0; column < to->columnCount(); ++column)
{
QModelIndex fromIndex = from->index(0, column, QModelIndex());
QModelIndex toIndex = to->index(0, column, QModelIndex());
QVariant columnFilter = from->data(fromIndex, Qt::EditRole);
QVariant comboBoxData = from->data(fromIndex, LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole);
if (columnFilter != to->data(toIndex, Qt::EditRole))
{
to->setData(toIndex, columnFilter, Qt::EditRole);
to->setData(toIndex, from->data(fromIndex, Qt::DisplayRole).toString(), Qt::DisplayRole);
} // if
else if (comboBoxData != to->data(toIndex, LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole))
{
to->setData(toIndex, comboBoxData, LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole);
LtsWidgets::ComboboxFilterContent comboFilterContent
= LtsWidgets::ComboboxFilterContent::fromVariant(m_model->headerData(column, Qt::Horizontal, LtsWidgets::LtsColumnFilterProxyModel::ComboboxFilterRole));
if (comboBoxData.toInt() == 0)
{
to->setData(toIndex, tr("<no filter>"), Qt::DisplayRole);
} // if
else
{
for (const LtsWidgets::ComboboxFilterData &data : qAsConst(comboFilterContent.data))
if (data.data == comboBoxData)
{
to->setData(toIndex, data.text, Qt::DisplayRole);
break;
} // if
} // else
} // else if
} // for
// undo selection
m_ui->tableViewEdit->blockSignals(true);
m_ui->tableViewEdit->selectionModel()->clearSelection();
m_ui->tableViewEdit->blockSignals(false);
m_ui->treeViewEdit->blockSignals(true);
m_ui->treeViewEdit->selectionModel()->clearSelection();
m_ui->treeViewEdit->blockSignals(false);
}
void ParticipantEdit::onSortTableView(int column, Qt::SortOrder order)
{
QModelIndex sourceIndex;
if (!m_ui->treeViewEdit->selectionModel()->selectedIndexes().isEmpty()) // store selected item
{
QModelIndex proxyIndex = m_ui->tableViewEdit->selectionModel()->selectedIndexes().first();
sourceIndex = m_proxyTable->mapToSource(proxyIndex);
m_ui->tableViewEdit->blockSignals(true);
m_ui->tableViewEdit->selectionModel()->select(proxyIndex, {QItemSelectionModel::Deselect, QItemSelectionModel::Rows});
m_ui->tableViewEdit->blockSignals(false);
} // if
m_proxyTable->onSort(column, order);
if (sourceIndex != QModelIndex()) // reselect item with new index
{
QModelIndex proxyIndex = m_proxyTable->mapFromSource(sourceIndex);
m_ui->tableViewEdit->blockSignals(true);
m_ui->tableViewEdit->selectionModel()->select(proxyIndex, {QItemSelectionModel::Select, QItemSelectionModel::Rows});
m_ui->tableViewEdit->blockSignals(false);
m_ui->tableViewEdit->scrollTo(proxyIndex);
} // if
}
void ParticipantEdit::onColumnWidthChanged(QTreeView *to, const int &column, const int &width)
{
if (to->columnWidth(column) != width)
to->setColumnWidth(column, width);
}
void ParticipantEdit::tableColumnOrganiserSetting()
{
// LtsColumnOrganiser
m_ui->tableViewEdit->setColumnsOrganiserEnabled(identifier(), true);
m_ui->treeViewEdit->setColumnsOrganiserEnabled(identifier(), true);
}
} // namespace ParticipantManagement
@@ -0,0 +1,130 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - Participant Edit
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#pragma once
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <LtsUtilsGuiDds/request_helper.h>
class QTreeView;
namespace AdvancedSymbology
{
class ForeignDataInterface;
}
namespace Ui
{
class ParticipantEdit;
}
namespace NGL
{
class INGLLogger;
}
namespace LtsDataView
{
class SearchModel;
}
namespace ParticipantManagement
{
class FiringUnitValidator;
class ParticipantEditModel;
class ParticipantEditItem;
class ParticipantTreeEditHandler;
class ParticipantTreeFilterProxyModel;
class ParticipantTableFilterProxyModel;
class ParticipantEdit : public LtsWidgets::LtsDialog
{
Q_OBJECT
using BaseClass = LtsWidgets::LtsDialog;
public:
ParticipantEdit(LtsSession::LtsSession *session, bool asSupportService, QWidget *parent = nullptr);
~ParticipantEdit();
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc);
private:
void retranslate() override;
bool apply() override;
void showIsSimulated();
void lock() override;
void unlock() override;
protected slots:
void onEnaDisa(); // enable/disable the widgets
void onAddItem();
void onEditItem();
void onPartyChanged();
void onPrint();
void onChangesMade();
void onBeautifyTreeView();
private slots:
void onSwitchToTreeView();
void onSwitchToTableView();
void onFilterChanged(LtsDataView::SearchModel *from, LtsDataView::SearchModel *to);
void onSortTableView(int column, Qt::SortOrder order);
void onSelectionChangedInTree(const QItemSelection &selected, const QItemSelection &deselected);
void onSelectionChangedInTable(const QItemSelection &selected, const QItemSelection &deselected);
void onColumnWidthChanged(QTreeView *to, const int &column, const int &width);
private:
void tableColumnOrganiserSetting() override;
bool m_asSupportService;
QAction *m_actionRemove;
QAction *m_actionEdit;
ParticipantTreeEditHandler *m_pTreehandler{nullptr};
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asb;
ParticipantEditItem *m_newItemDlg{nullptr};
LtsSession::LtsSession *m_session{nullptr};
static int s_preselectedParty;
ParticipantEditModel *m_model{nullptr};
ParticipantTreeFilterProxyModel *m_proxyTree{nullptr};
ParticipantTableFilterProxyModel *m_proxyTable{nullptr};
QPushButton *m_pbTreeView{nullptr};
QPushButton *m_pbTableView{nullptr};
QPushButton *m_pbTreeViewDummy{nullptr};
QPushButton *m_pbTableViewDummy{nullptr};
FiringUnitValidator *m_firingUnitValidator{nullptr};
Ui::ParticipantEdit *m_ui;
NGL::INGLLogger &m_logger;
};
} //ParticipantManagement
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantEdit</class>
<widget class="QWidget" name="ParticipantEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>655</width>
<height>472</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">setwindowtitle in source</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="2">
<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 row="0" column="0">
<widget class="QLabel" name="lblParty">
<property name="text">
<string>Party:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LtsWidgets::LtsComboBox" name="cbParty">
<property name="const" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<widget class="LtsDataView::LtsDataView" name="treeViewEdit">
<property name="showColumnCount" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="LtsDataView::LtsDataView" name="tableViewEdit">
<property name="showColumnCount" stdset="0">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,156 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - ParticipantEdit
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_edit_gui_plugin.h"
#include "participant_organisation.h"
#include "participant_edit.h"
#include "tactical_organisation.h"
#include <ParticipantManagement/ppm_operator_rights.h>
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
#include <LtsUtilsSettings/settings.h>
namespace ParticipantManagement
{
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
{
return std::make_shared<InterfaceImpl>(session);
}
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
: GuiPluginBase::Interface(session, getLogger("Plugins.Gui.Ppm.ParticipantTemplates"))
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiTemplateIfc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
{}
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
{
LtsUtils::ProjectSettings *ps = LtsUtils::ProjectSettings::getInstance();
QVector<LtsWidgets::PluginData> ret;
//were are in Exercise so only use exercise participants
LtsWidgets::PluginData pd;
pd.menuGroup = menuGroup();
pd.layoutArea = LtsWidgets::LayoutArea::eDialogTab;
pd.menuText = tr("Organise Participants");
pd.identifier = QStringLiteral("organiseParticipants");
pd.menuIcon = QIcon(QLatin1String("icon:force_organization.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onParticipantOrganisation(parent, false); };
pd.operatorRight = OperatorRights::ParticipantEdit::ParticipantsOrganise;
pd.exercisePart = LtsWidgets::ExercisePart::ePlanning;
ret.append(pd);
pd.menuText = tr("Edit Participants");
pd.identifier = QStringLiteral("editParticipants");
pd.menuIcon = QIcon(QLatin1String("icon:force_player_configuration.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onParticipantEdit(parent, false); };
pd.operatorRight = OperatorRights::ParticipantEdit::ParticipantsEdit;
pd.exercisePart = LtsWidgets::ExercisePart::ePlanning;
pd.exerciseStates = LtsWidgets::ExcState::eCreated | LtsWidgets::ExcState::eStarted | LtsWidgets::ExcState::ePaused;
ret.append(pd);
pd.menuText = tr("Tactical Organisation");
pd.identifier = QStringLiteral("tacticalParticipantOrganisation");
pd.menuIcon = QIcon(QLatin1String("icon:tactical_organization.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onTacticalParticipantOrganisation(parent); };
pd.operatorRight = OperatorRights::ParticipantEdit::TacticalParticipantOrganisation;
pd.exercisePart = LtsWidgets::ExercisePart::eExecution;
ret.append(pd);
if (ps->value(QStringLiteral("ppm"),
QStringLiteral("enableSupportParticipantsOrganise")).toBool())
{
pd.menuText = tr("Organise Support Participants");
pd.identifier = QStringLiteral("organiseSupParticipants");
pd.menuIcon = QIcon(QLatin1String("icon:oc_composition.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onParticipantOrganisation(parent, true); };
pd.operatorRight = OperatorRights::ParticipantEdit::SupportParticipantsOrganise;
pd.exercisePart = LtsWidgets::ExercisePart::ePlanning;
ret.append(pd);
}
if (ps->value(QStringLiteral("ppm"),
QStringLiteral("enableSupportParticipantsEdit")).toBool())
{
pd.menuText = tr("Edit Support Participants");
pd.identifier = QStringLiteral("editSupportParticipants");
pd.menuIcon = QIcon(QLatin1String("icon:oc_player_configuration.svg"));
pd.createWidgetFunc = [this](QWidget *parent) { return onParticipantEdit(parent, true); };
pd.operatorRight = OperatorRights::ParticipantEdit::SupportParticipantsEdit;
pd.exercisePart = LtsWidgets::ExercisePart::ePlanning;
pd.exerciseStates = LtsWidgets::ExcState::eCreated | LtsWidgets::ExcState::eStarted | LtsWidgets::ExcState::ePaused;
ret.append(pd);
}
return ret;
}
QString InterfaceImpl::menuGroup() const
{
return tr("Participants");
}
QString InterfaceImpl::menuGroupSup() const // TODO: UNUSED!
{
return tr("Support");
}
bool InterfaceImpl::fetchInterfaces()
{
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_dtc))
return false;
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ftc))
return false;
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiTemplatesInterface>(m_ppmGuiTemplateIfc))
return false;
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc))
return false;
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(m_asb);
return true;
}
void InterfaceImpl::clearInterfaces()
{
m_ppmGuiTemplateIfc = nullptr;
m_ppmGuiCbxIfc = nullptr;
m_dtc = nullptr;
m_ftc = nullptr;
m_asb = nullptr;
}
LtsWidgets::LtsDialog *InterfaceImpl::onParticipantEdit(QWidget *parent, bool asSupportService)
{
return LtsWidgets::initDialog(new ParticipantEdit(m_session, asSupportService, parent),
m_dtc, m_ftc, m_ppmGuiCbxIfc, m_asb);
}
LtsWidgets::LtsDialog *InterfaceImpl::onParticipantOrganisation(QWidget *parent, bool asSupportService)
{
return LtsWidgets::initDialog(new ParticipantOrganisationDialog(m_session, asSupportService, parent),
m_dtc, m_ftc, m_ppmGuiTemplateIfc, m_ppmGuiCbxIfc, m_asb);
}
LtsWidgets::LtsDialog *InterfaceImpl::onTacticalParticipantOrganisation(QWidget *parent)
{
return LtsWidgets::initDialog(new TacticalOrganisation(m_session, parent),
m_dtc, m_ftc, m_ppmGuiCbxIfc, m_asb);
}
} // namespace ParticipantManagement
@@ -0,0 +1,74 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - Participant Edit
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_participants_gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_templates_gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
namespace AdvancedSymbology
{
class ForeignDataInterface;
}
namespace ParticipantManagement
{
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
{
Q_PLUGIN_METADATA(IID "gui:3:ppm.participant")
Q_INTERFACES(GuiPluginBase::Plugin)
Q_OBJECT
public:
GuiPlugin() = default;
~GuiPlugin() = default;
QString pluginName() override { return QStringLiteral("ParticipantManagement.GuiPlugin.ParticipantEdit"); }
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
bool availableInPartition(IDL::PartitionType partition) const override
{
return (partition == IDL::PartitionType::Exercise);
}
};
class InterfaceImpl final : public QObject, public ForeignGuiParticipantsInterface, public GuiPluginBase::Interface
{
Q_OBJECT
public:
explicit InterfaceImpl(LtsSession::LtsSession *session);
QVector<LtsWidgets::PluginData> getActions() override;
bool fetchInterfaces() override;
void clearInterfaces() override;
QString menuGroup() const override;
QString menuGroupSup() const;
bool availableInPartition(IDL::PartitionType partition) const override { return partition == IDL::PartitionType::Exercise; }
private:
LtsWidgets::LtsDialog *onParticipantEdit(QWidget *parent, bool asSupportService);
LtsWidgets::LtsDialog *onParticipantOrganisation(QWidget *parent, bool asSupportService);
LtsWidgets::LtsDialog *onTacticalParticipantOrganisation(QWidget *parent);
private:
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
std::shared_ptr<ParticipantManagement::ForeignGuiTemplatesInterface> m_ppmGuiTemplateIfc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asb;
};
} // namespace ParticipantManagement
@@ -0,0 +1,513 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Organisation Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_orga_model.h"
#include <Plugins/ParticipantManagement/ppm_mime_datas.h>
#include <Common/participant_edit_model.h>
#include <ParticipantManagement/ppm_translation.h>
#include <Symbology/symbol_data_to_render_role.h>
#include <QMimeData>
#include <nglwidgets/ngltreeitem.h>
namespace ParticipantManagement
{
//----------------------------------------------------------------------------
ParticipantOrgaModel::ParticipantOrgaModel(PartyOrganisationType orgType,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
QObject *parent)
: ParticipantIconModelBase(ppmDtc,
asbIfc,
{ headerFromOrganisationType(orgType), tr("Participant Id") },
new NGLTreeItem(QVariant()),
parent,
getLogger(QStringLiteral("ParticipantOrgaModel.") + headerFromOrganisationType(orgType)))
, m_partyId(-1)
, m_orgType(orgType)
{
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::participantOrganisationChanged,
this, &ParticipantOrgaModel::onParticipantOrganisationChanged);
m_dtc->participantOrganisations([this](const ParticipantOrganisation &org) { m_participantOrganization[org.participantId()] = org;});
}
QVariant ParticipantOrgaModel::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::ParticipantData>())
{
const ParticipantManagement::ParticipantData participantData = item->data().value<ParticipantManagement::ParticipantData>();
switch (index.column())
{
case ColDescription:
return QVariant(QString::fromStdString(participantData.designator()) + QLatin1Char('/') +
QString::fromStdString(participantData.tacticalIdentifier()));
case ColParticipantId:
return participantData.id();
}
}
return NGLTreeModel::data(index, role);
}
int ParticipantOrgaModel::columnCount(const QModelIndex &parent) const
{
int cc = NGLTreeModel::columnCount(parent);
#ifndef LTS_DEBUG
// participant id only in dev mode
cc -= 1;
#endif
return cc;
}
Qt::ItemFlags ParticipantOrgaModel::flags(const QModelIndex &index) const
{
return NGLTreeModel::flags(index) | Qt::ItemIsDropEnabled;
}
QStringList ParticipantOrgaModel::mimeTypes() const
{
switch (m_orgType)
{
case PartyOrganisationType::Party:
return { ParticipantPoolRoot, ParticipantPartyDetached };
case PartyOrganisationType::Attached:
case PartyOrganisationType::Cooperate:
return { ParticipantPoolRoot, ParticipantPoolDetached };
case PartyOrganisationType::Detached:
return { ParticipantPartyChild };
}
return QStringList();
}
QMimeData *ParticipantOrgaModel::mimeData(const QModelIndexList &indexes) const
{
if (indexes.size() < 1)
return nullptr;
const QModelIndex &idx = indexes.first();
if (!idx.isValid())
return nullptr;
// we only allow to move the complete tree here
if (m_orgType == PartyOrganisationType::Detached ||
m_orgType == PartyOrganisationType::Attached ||
m_orgType == PartyOrganisationType::Cooperate)
{
if (idx.parent().isValid())
return nullptr;
}
const ParticipantData data = privateData(idx)->data().value<ParticipantManagement::ParticipantData>();
if (data.id() == 0)
return nullptr;
if (m_orgType == PartyOrganisationType::Detached)
{
// if attached to another party, do not allow to move it back to origin party ...
auto it = m_participantOrganization.find(data.id());
if (it != m_participantOrganization.end() && it.value().currentPartyId() != 0)
return nullptr;
}
const QByteArray encodedData(QByteArray::number(data.id()));
QMimeData *mimeData = new QMimeData;
switch (m_orgType)
{
case PartyOrganisationType::Party:
mimeData->setData(idx.parent().isValid() ? ParticipantPartyChild : ParticipantPartyRoot, encodedData);
break;
case PartyOrganisationType::Detached:
mimeData->setData(ParticipantPartyDetached, encodedData);
break;
case PartyOrganisationType::Attached:
case PartyOrganisationType::Cooperate:
mimeData->setData(ParticipantPartyAttached, encodedData);
break;
}
return mimeData;
}
bool ParticipantOrgaModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
{
if (!NGLTreeModel::canDropMimeData(data, action, row, column, parent))
return false;
// in Party - Mode we don't accept a new pool template since only one tree is allowed
if (m_orgType == PartyOrganisationType::Party)
{
if (data->hasFormat(ParticipantPoolRoot) && m_rootItem->childCount() > 0)
return false;
if (data->hasFormat(ParticipantPartyDetached) && !parent.isValid())
return false;
}
if (m_orgType == PartyOrganisationType::Attached ||
m_orgType == PartyOrganisationType::Cooperate)
{
if (data->hasFormat(ParticipantPoolRoot))
return true;
// don't allow attach/cooperate of own subunits
bool bOk;
const int participantId = data->data(ParticipantPoolDetached).toInt(&bOk);
if (bOk)
{
auto it = m_participantOrganization.find(participantId);
if (it != m_participantOrganization.end() &&
it.value().originPartyId() == m_partyId)
return false;
}
}
return true;
}
bool ParticipantOrgaModel::dropMimeData(const QMimeData *data, Qt::DropAction action,
int row, int column, const QModelIndex &parent)
{
Q_UNUSED(row)
Q_UNUSED(column)
Q_UNUSED(parent)
// only in PartyOrganisationType::Party mode
if (action != Qt::MoveAction)
{
ERROR_LOG(m_logger) << "Drop: action is not move action: " << action;
return false;
}
// all data we accept here is packaged the same, the different mime type
// is only used to (dis)allow the moves to the different models
// since we can only move one item, the data is a simple integer (=participantId)
int participantId = -1;
for (const auto &mt : { ParticipantPoolRoot, ParticipantPartyChild, ParticipantPartyDetached, ParticipantPoolDetached })
{
if (data->hasFormat(mt))
{
bool bOk;
participantId = data->data(mt).toInt(&bOk);
if (bOk)
break;
}
}
DEBUG_LOG(m_logger) << "Drop: participantId: " << participantId;
if (participantId <= 0)
{
WARNING_LOG(m_logger) << "Can not decode mime data - ignoring";
return false;
}
// since inferiorParticipants is walking recursivly the tree, the vector is sorted
QVector<Participant> movedParticipants = inferiorParticipants(participantId);
if (movedParticipants.isEmpty())
{
WARNING_LOG(m_logger) << "Can not find valid data for participant " << participantId;
return false;
}
// when we are attached/detached/cooperate then the participant is a new leader -> superiorId = 0, hierarchyNumber = 1
movedParticipants[0].superiorId(0);
movedParticipants[0].hierarchyNumber(1);
int rootParticipantId = 0;
NGLTreeItem *rootItem = m_rootItem;
QModelIndex rootModelIndex;
if (m_orgType == PartyOrganisationType::Party && data->hasFormat(ParticipantPartyDetached))
{
if (!parent.isValid())
return false;
NGLTreeItem *item = privateData(parent);
if (!item)
return false;
if (!item->data().canConvert<ParticipantManagement::ParticipantData>())
return false;
const ParticipantManagement::ParticipantData participantData = item->data().value<ParticipantManagement::ParticipantData>();
if (participantData.id() == 0)
return false;
rootParticipantId = participantData.id();
rootItem = item;
rootModelIndex = parent;
movedParticipants[0].superiorId(rootParticipantId);
movedParticipants[0].hierarchyNumber(-1);
}
DEBUG_LOG(m_logger) << "Drop: #movedParticipants: " << movedParticipants.size();
QHash<int, ParticipantManagement::ParticipantData> tmap;
tmap.reserve(movedParticipants.size());
QHash<int, QSet<int>> parentId2id;
parentId2id.reserve(movedParticipants.size());
for (const Participant &part : qAsConst(movedParticipants))
{
if (part.isDeleted())
continue;
// parentId -> id for lookup
parentId2id[part.superiorId()] += part.id();
tmap.insert(part.id(), m_dtc->convertParticipantToParticipantData(part));
}
// insert recursivly
insertChildrenOf(rootParticipantId, rootItem, rootModelIndex, parentId2id, tmap);
// save current party config
emit participantDataChanged(movedParticipants.at(0).id());
return true;
}
bool ParticipantOrgaModel::isParticipantType(int source_row, const QModelIndex &source_parent) const
{
NGLTreeItem *parentItem = privateData(source_parent);
if (!parentItem)
return false;
const NGLTreeItem *childItem = parentItem->child(source_row);
if (!childItem)
return false;
if (!childItem->data().canConvert<ParticipantManagement::ParticipantData>())
return false;
const ParticipantManagement::ParticipantData participantData = childItem->data().value<ParticipantManagement::ParticipantData>();
return !isUnitType(participantData.typeId());
}
QVector<Participant> ParticipantOrgaModel::inferiorParticipants(int partId) const
{
QVector<Participant> retVector;
const Participant participant = m_dtc->participant(partId);
retVector.reserve(participant.inferiorIds().size() + retVector.size() + 1);
retVector.append(participant);
for (int inferiorId : participant.inferiorIds())
retVector.append(inferiorParticipants(inferiorId));
return retVector;
}
QVector<ParticipantData> ParticipantOrgaModel::getChildrenOf(NGLTreeItem *parentItem, int parentId, int hierarchyNumber, int &highestModId) const
{
QVector<ParticipantData> ret;
if (!parentItem)
return ret;
ParticipantManagement::ParticipantData participantData = parentItem->data().value<ParticipantManagement::ParticipantData>();
participantData.superiorModId(parentId);
participantData.hierarchyNumber(hierarchyNumber);
if (participantData.modId() == 0)
participantData.modId(++highestModId);
ret += participantData;
for (int i = 0; i < parentItem->childCount(); i++)
ret.append(getChildrenOf(parentItem->child(i), participantData.modId(), i + 1, highestModId));
return ret;
}
QVector<ParticipantData> ParticipantOrgaModel::participantData(int partyId) const
{
QVector<ParticipantData> ret;
// gehen wir mal davon aus, dass man nie mehr als 1mrd template - Einträge angelegt hat...
int modId = 1000000000;
for (int i = 0; i < m_rootItem->childCount(); ++i)
{
NGLTreeItem *rootKnot = m_rootItem->child(0);
ret += getChildrenOf(rootKnot, 0, 1, modId);
}
for (int i = 0; i < ret.size(); ++i)
ret[i].partyId(partyId);
return ret;
}
QVector<int> ParticipantOrgaModel::rootParticipantIds() const
{
QVector<int> ret;
for (int i = 0; i < m_rootItem->childCount(); ++i)
{
const NGLTreeItem *rootKnot = m_rootItem->child(i);
const ParticipantManagement::ParticipantData participantData = rootKnot->data().value<ParticipantManagement::ParticipantData>();
// should not happen but who knows...
if (participantData.id() == 0)
continue;
ret += participantData.id();
}
return ret;
}
void ParticipantOrgaModel::onReinitModel(int partyId)
{
m_partyId = partyId;
const ParticipantManagement::Party &party = m_dtc->party(m_partyId);
m_partyRole = AdvancedSymbology::roleToRole<>(party.role());
m_partyColor = QColor::fromRgb(QRgb(party.color()));
m_symbolResultMapping.clear();
NGLTreeModel::resetModel();
QHash<int, ParticipantData> tmap;
QHash<int, QSet<int>> parentId2id;
auto cb = [this, &tmap, &parentId2id](const Participant & part)
{
if (part.isDeleted())
return;
if (m_orgType != PartyOrganisationType::Detached && part.partyId() != m_partyId)
return;
if (m_orgType == PartyOrganisationType::Detached && part.partyId() == m_partyId)
return;
if (part.superiorId() == 0 && !isRootParticipantRelevant(part, m_partyId))
return;
// parentId -> id for lookup
parentId2id[part.superiorId()] += part.id();
tmap.insert(part.id(), m_dtc->convertParticipantToParticipantData(part));
};
m_dtc->participants(cb);
// insert recursivly
insertChildrenOf(0, m_rootItem, QModelIndex(), parentId2id, tmap);
}
void ParticipantOrgaModel::onParticipantOrganisationChanged(const ParticipantOrganisation &data, DataModification modType)
{
switch (modType)
{
case DataModification::eAdded:
case DataModification::eModified:
m_participantOrganization[data.participantId()] = data;
break;
case DataModification::eRemoved:
m_participantOrganization.remove(data.participantId());
break;
}
}
void ParticipantOrgaModel::insertChildrenOf(int parentId,
NGLTreeItem *parent,
const QModelIndex &parentIdx,
const QHash<int, QSet<int>> &parentId2id,
const QHash<int, ParticipantData> &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 participant with id " << childId << " - ignoring";
continue;
}
const ParticipantData &data = it.value();
int insertPos = 0;
if (data.hierarchyNumber() > 0)
{
auto hierIt = currentHierachyNumbers.insert(data.hierarchyNumber(), data.hierarchyNumber());
insertPos = std::distance(currentHierachyNumbers.begin(), hierIt);
}
else
{
// append if no valid hierarchy number is set
const NGLTreeItem *treeItemParent = privateData(parentIdx);
if (treeItemParent)
insertPos = treeItemParent->childCount();
}
NGLTreeItem *childItem = createItem(QVariant::fromValue(data), QIcon());
DEBUG_LOG(m_logger) << "insert Child " << childItem << "(" << data.id() << ", " << data.hierarchyNumber()
<< ") to parent " << parent << " at pos " << insertPos;
insertRow(insertPos, parentIdx, childItem);
const QModelIndex childIdx = index(insertPos, 0, parentIdx);
insertChildrenOf(data.id(), childItem, childIdx, parentId2id, tmap);
}
}
QString ParticipantOrgaModel::headerFromOrganisationType(PartyOrganisationType orgType)
{
switch (orgType)
{
case PartyOrganisationType::Party:
return tr("Party");
case PartyOrganisationType::Attached:
return tr("Attached");
case PartyOrganisationType::Detached:
return tr("Detached");
case PartyOrganisationType::Cooperate:
return tr("Directed to Cooperate");
}
return QString();
}
bool ParticipantOrgaModel::isRootParticipantRelevant(const Participant &participant, int partyId) const
{
// this function assumes, that the participant is in the correct party
const int participantId = participant.id();
const int participantPartyId = participant.partyId();
const ParticipantOrganisation org = m_participantOrganization.value(participantId);
switch (m_orgType)
{
case PartyOrganisationType::Party:
return participantPartyId == partyId && org.participantId() == 0; // is 0 when not in m_participantOrganization
case PartyOrganisationType::Attached:
return participantPartyId == partyId && org.participantId() == participantId && org.isAttached();
case PartyOrganisationType::Detached:
return org.participantId() == participantId && org.originPartyId() == partyId;
case PartyOrganisationType::Cooperate:
return participantPartyId == partyId && org.participantId() == participantId && org.isCooperate();
}
return false;
}
NGLTreeItem *ParticipantOrgaModel::createItem(const QVariant &data, const QIcon &icon) const
{
auto ret = NGLTreeModel::createItem(data, icon);
const ParticipantData participantData = data.value<ParticipantData>();
if (participantData.symbol().size() != 0)
{
ParticipantOrgaModel *that = const_cast<ParticipantOrgaModel*>(this);
// mutable
that->tryRenderSymbol(QString::fromStdString(participantData.symbol()), ret);
}
return ret;
}
//----------------------------------------------------------------------------
void ParticipantOrgaProxyModel::onReinitModel(int partyId)
{
if (m_sourceModel)
m_sourceModel->onReinitModel(partyId);
}
//----------------------------------------------------------------------------
void ParticipantOrgaProxyModel::setSourceModel(QAbstractItemModel *sourceModel)
{
m_sourceModel = qobject_cast<ParticipantOrgaModel*>(sourceModel);
QSortFilterProxyModel::setSourceModel(sourceModel);
}
//----------------------------------------------------------------------------
bool ParticipantOrgaProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
{
if (!m_sourceModel || m_sourceModel->isParticipantType(source_row, source_parent))
return false;
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
}
} //namespace ParticipantManagement
@@ -0,0 +1,106 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Organisation Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include <Plugins/ParticipantManagement/Gui/Common/participant_icon_model_base.h>
#include <ParticipantManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <QSortFilterProxyModel>
#include <QSet>
namespace ParticipantManagement
{
//----------------------------------------------------------------------------
class ParticipantOrgaModel final : public ParticipantIconModelBase
{
Q_OBJECT
public:
enum Columns
{
ColDescription,
ColParticipantId
};
enum class PartyOrganisationType
{
Party,
Attached,
Detached,
Cooperate
};
ParticipantOrgaModel(PartyOrganisationType orgType,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
QObject *parent);
QVector<ParticipantData> participantData(int partyId) const;
QVector<int> rootParticipantIds() const;
QVariant data(const QModelIndex &index, int role) const override;
int columnCount(const QModelIndex &parent) const override;
// We can only move Units around but not copy them here
Qt::DropActions supportedDropActions() const override { return Qt::MoveAction; }
Qt::DropActions supportedDragActions() const override { return Qt::MoveAction; }
Qt::ItemFlags flags(const QModelIndex &index) const override;
QStringList mimeTypes()const override;
QMimeData *mimeData(const QModelIndexList &indexes) const 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;
void onReinitModel(int partyId);
// for ProxyModel
bool isParticipantType(int source_row, const QModelIndex &source_parent) const;
public Q_SLOTS:
void onParticipantOrganisationChanged(const ParticipantOrganisation &data, DataModification modType);
Q_SIGNALS:
void participantDataChanged(int addedParticipantId);
private:
void insertChildrenOf(int parentId,
NGLTreeItem *parent, const QModelIndex &parentIdx,
const QHash<int, QSet<int>> &parentId2id,
const QHash<int, ParticipantData> &tmap);
QVector<Participant> inferiorParticipants(int partId) const;
QVector<ParticipantData> getChildrenOf(NGLTreeItem *parentItem, int parentId, int hierarchyNumber, int &highestModId) const;
static QString headerFromOrganisationType(PartyOrganisationType orgType);
bool isRootParticipantRelevant(const Participant &participant, int partyId) const;
NGLTreeItem *createItem(const QVariant &data, const QIcon &icon) const override;
private:
int m_partyId;
PartyOrganisationType m_orgType;
QHash<int, ParticipantOrganisation> m_participantOrganization;
};
class ParticipantOrgaProxyModel final : public QSortFilterProxyModel
{
Q_OBJECT
public:
using QSortFilterProxyModel::QSortFilterProxyModel;
void onReinitModel(int partyId);
void setSourceModel(QAbstractItemModel *sourceModel) override;
protected:
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const override;
ParticipantOrgaModel *m_sourceModel;
};
} //namespace ParticipantManagement
@@ -0,0 +1,465 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - Participant Organisation
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_organisation.h"
#include "ui_participant_organisation.h"
#include "participant_unit_namer.h"
#include <Plugins/ParticipantManagement/Gui/ParticipantTemplates/participant_template_chooser_model.h>
#include <Plugins/ParticipantManagement/ppm_mime_datas.h>
#include <QMenu>
#include <QPainter>
#include <QRect>
#include <QMouseEvent>
#include <LtsWidgets/lts_message_dialog.h>
#include <LtsUtilsCore/dds_vector.h>
namespace ParticipantManagement
{
int ParticipantOrganisationDialog::s_preselectedParty = -1;
ParticipantOrganisationDialog::ParticipantOrganisationDialog(LtsSession::LtsSession *session,
bool asSupportService,
QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
, m_asSupportService(asSupportService)
, m_poolModel(nullptr)
, m_proxyModel(nullptr)
, m_partyModel(nullptr)
, m_attachedModel(nullptr)
, m_detachedModel(nullptr)
, m_cooperateModel(nullptr)
, m_delegate(nullptr)
, m_dtc(nullptr)
, m_ftc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_session(session)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_ui(new Ui::ParticipantOrganisation)
, m_logger(getLogger("ParticipantOrganisation"))
{
m_ui->setupUi(this);
m_ui->splitter->setStretchFactor(0, 1);
m_ui->splitter->setStretchFactor(1, 1);
m_ui->splitter->setStretchFactor(2, 2);
connect(m_ui->tvParty, &QTreeView::customContextMenuRequested,
this, &ParticipantOrganisationDialog::showContextMenu);
connect(m_ui->tvAttached, &QTreeView::customContextMenuRequested,
this, &ParticipantOrganisationDialog::showContextMenu);
connect(m_ui->tvDetached, &QTreeView::customContextMenuRequested,
this, &ParticipantOrganisationDialog::showContextMenu);
connect(m_ui->tvCooperate, &QTreeView::customContextMenuRequested,
this, &ParticipantOrganisationDialog::showContextMenu);
if (m_asSupportService)
setOnlineHelpFilename(QStringLiteral("Situation-Organise_Support_Participants"));
else
setOnlineHelpFilename(QStringLiteral("Situation-Organise_Participants"));
}
//----------------------------------------------------------------------------
ParticipantOrganisationDialog::~ParticipantOrganisationDialog()
{
delete m_ui;
}
void ParticipantOrganisationDialog::retranslate()
{
QString name;
if (m_asSupportService)
name = tr("Organise Support Participants");
else
name = tr("Organise Participants");
translate(m_ui, name);
}
void ParticipantOrganisationDialog::lock()
{
DEBUG_LOG(m_logger) << LOGFUNCTION << " START";
m_ui->cbParty->setEnabled(true); // true !!
// avoid BaseClass::lock to be called. PartyEdit stays enabled
m_ui->tvParty->setEnabled(false);
m_ui->tvAttached->setEnabled(false);
m_ui->tvCooperate->setEnabled(false);
m_ui->tvDetached->setEnabled(false);
DEBUG_LOG(m_logger) << LOGFUNCTION << " END";
}
void ParticipantOrganisationDialog::unlock()
{
DEBUG_LOG(m_logger) << LOGFUNCTION << " START";
m_ui->cbParty->setEnabled(true);
m_ui->tvParty->setEnabled(true);
m_ui->tvAttached->setEnabled(true);
m_ui->tvCooperate->setEnabled(true);
m_ui->tvDetached->setEnabled(true);
DEBUG_LOG(m_logger) << LOGFUNCTION << " END";
}
bool ParticipantOrganisationDialog::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ForeignGuiTemplatesInterface> &ppmGuiTemplateIfc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
{
if (!dtc || !ftc || !ppmGuiCbxIfc)
return false;
m_dtc = dtc;
m_ftc = ftc;
m_ppmGuiTemplateIfc = ppmGuiTemplateIfc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
//templateModel
m_ppmGuiTemplateIfc->getTemplateModel(m_ui->tvTemplate, m_asSupportService);
m_ui->tvTemplate->hideColumn(ParticipantTemplateChooserModel::ColTypeClass);
m_ui->tvTemplate->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
//poolModel
m_poolModel = new ParticipantPoolModel(this, m_session, m_dtc, m_asSupportService);
m_ui->tvPool->setModel(m_poolModel);
m_ui->tvPool->hideColumn(ParticipantPoolModel::ColTypeClass);
m_ui->tvPool->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
connect(m_poolModel, &ParticipantPoolModel::startUnitNamer, this, &ParticipantOrganisationDialog::onStartTemplateUnitNamer);
connect(m_poolModel, &ParticipantPoolModel::modifyParticipantData, this, &ParticipantOrganisationDialog::onPoolParticipantsChanged);
m_delegate = new DeleteDelegate(this);
connect(m_delegate, &DeleteDelegate::removePoolParty, this, &ParticipantOrganisationDialog::onRemovePoolParty);
m_ui->tvPool->setItemDelegateForColumn(ParticipantPoolModel::ColRemove, m_delegate);
if (m_asSupportService)
{
m_ui->lblParty->hide();
m_ui->cbParty->hide();
m_ui->tvParty->hide();
m_ui->tvAttached->hide();
m_ui->tvDetached->hide();
m_ui->tvCooperate->hide();
}
else
{
connect(m_ui->cbParty,
static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
this,
&ParticipantOrganisationDialog::onPartyChanged);
//PartyModels
m_partyModel = new ParticipantOrgaModel(ParticipantOrgaModel::PartyOrganisationType::Party,
m_dtc,
asbIfc,
this);
ParticipantOrgaProxyModel *partyProxy = new ParticipantOrgaProxyModel(this);
partyProxy->setSourceModel(m_partyModel);
m_ui->tvParty->setModel(partyProxy);
m_attachedModel = new ParticipantOrgaModel(ParticipantOrgaModel::PartyOrganisationType::Attached,
m_dtc,
asbIfc,
this);
ParticipantOrgaProxyModel *attachProxy = new ParticipantOrgaProxyModel(this);
attachProxy->setSourceModel(m_attachedModel);
m_ui->tvAttached->setModel(attachProxy);
m_detachedModel = new ParticipantOrgaModel(ParticipantOrgaModel::PartyOrganisationType::Detached,
m_dtc,
asbIfc,
this);
ParticipantOrgaProxyModel *detachProxy = new ParticipantOrgaProxyModel(this);
detachProxy->setSourceModel(m_detachedModel);
m_ui->tvDetached->setModel(detachProxy);
m_cooperateModel = new ParticipantOrgaModel(ParticipantOrgaModel::PartyOrganisationType::Cooperate,
m_dtc,
asbIfc,
this);
ParticipantOrgaProxyModel *cooperateProxy = new ParticipantOrgaProxyModel(this);
cooperateProxy->setSourceModel(m_cooperateModel);
m_ui->tvCooperate->setModel(cooperateProxy);
connect(m_partyModel, &ParticipantOrgaModel::participantDataChanged,
this, &ParticipantOrganisationDialog::onPartyParticipantsChanged);
connect(m_attachedModel, &ParticipantOrgaModel::participantDataChanged,
this, &ParticipantOrganisationDialog::onAttachedParticipantsChanged);
connect(m_detachedModel, &ParticipantOrgaModel::participantDataChanged,
this, &ParticipantOrganisationDialog::onDetachedParticipantsChanged);
connect(m_cooperateModel, &ParticipantOrgaModel::participantDataChanged,
this, &ParticipantOrganisationDialog::onCooperateParticipantsChanged);
}
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty);
const int idx = m_ui->cbParty->findData(s_preselectedParty);
if (idx >= 0)
m_ui->cbParty->setCurrentIndex(idx);
onPartyChanged();
return true;
}
void ParticipantOrganisationDialog::onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject)
{
m_requestHelper->requestReply(replyObject);
}
//private
QModelIndex ParticipantOrganisationDialog::selectedIndexView() const
{
QItemSelectionModel *selectionModel = m_ui->tvParty->selectionModel();
QModelIndexList indexL = selectionModel->selectedRows(0);
if (indexL.size() == 0)
return QModelIndex();
return m_proxyModel->mapToSource(indexL.at(0));
}
bool ParticipantOrganisationDialog::saveParticipantData(const ModifyParticipantDataRequest &request)
{
return m_requestHelper->startSingleRequest([this, request]()
{
return m_ftc->modifyParticipantDataRequest(request, this);
});
}
void ParticipantOrganisationDialog::onPoolParticipantsChanged(const QVector<ParticipantData> &participants,
const QString &originatorMimeType)
{
if (participants.isEmpty())
return;
ModifyParticipantDataRequest req;
req.data(LtsUtils::convert<std::vector<ParticipantData>>(participants));
// move from attached/coperate to pool -> update ParticipantOrganisation
if (originatorMimeType == ParticipantPartyAttached)
{
ParticipantOrganisation orga;
orga.participantId(participants.first().id());
orga.currentPartyId(0); // moved to pool
orga.isAttached(false);
orga.isCooperate(false);
req.participantOrganisation(orga);
}
saveParticipantData(req);
}
void ParticipantOrganisationDialog::onPartyParticipantsChanged(int addedParticipantId)
{
// move from pool/detached -> party was done
const int curPartyId = m_ui->cbParty->currentData().toInt();
const QVector<int> rootParticipantIds = m_partyModel->rootParticipantIds();
if (rootParticipantIds.isEmpty())
return;
bool bMovedFromPool = rootParticipantIds.contains(addedParticipantId);
ModifyParticipantDataRequest req;
if (!bMovedFromPool)
{
// search participantOrga with originPartyId = curPartyId, currentPartyId = 0,
// isAttached/isCooperate = false, participantId = addedParticipantId
// and remove it
ParticipantOrganisation orga;
orga.participantId(addedParticipantId);
orga.originPartyId(curPartyId);
orga.currentPartyId(curPartyId); // moved to currentParty
req.participantOrganisation(orga);
}
const QVector<ParticipantData> participantData = m_partyModel->participantData(curPartyId);
req.data(LtsUtils::convert<std::vector<ParticipantData>>(participantData));
saveParticipantData(req);
}
void ParticipantOrganisationDialog::onAttachedParticipantsChanged(int addedParticipantId)
{
// a move from pool -> attached was done
const int curPartyId = m_ui->cbParty->currentData().toInt();
// we need to create a new ParticipantOrganisation entry since addedParticipantId was attached to curParty
ModifyParticipantDataRequest req;
ParticipantOrganisation orga;
orga.participantId(addedParticipantId);
orga.currentPartyId(curPartyId); // moved from pool to curParty
orga.isAttached(true);
orga.isCooperate(false);
req.participantOrganisation(orga);
const QVector<ParticipantData> attachedtData = m_attachedModel->participantData(curPartyId); // moved from Pool
req.data(LtsUtils::convert<std::vector<ParticipantData>>(attachedtData));
saveParticipantData(req);
}
void ParticipantOrganisationDialog::onDetachedParticipantsChanged(int addedParticipantId)
{
// a move from party -> detached was done
const int curPartyId = m_ui->cbParty->currentData().toInt();
// we need to create a new ParticipantOrganisation entry since addedParticipantId was detached from curParty
ModifyParticipantDataRequest req;
ParticipantOrganisation orga;
orga.participantId(addedParticipantId);
orga.originPartyId(curPartyId);
orga.currentPartyId(0); // moved from currentParty to pool
req.participantOrganisation(orga);
const QVector<ParticipantData> participantData = m_partyModel->participantData(curPartyId);
const QVector<ParticipantData> detachedtData = m_detachedModel->participantData(0); // moved to Pool
req.data(LtsUtils::convert<std::vector<ParticipantData>>(participantData + detachedtData));
saveParticipantData(req);
}
void ParticipantOrganisationDialog::onCooperateParticipantsChanged(int addedParticipantId)
{
// a move from pool -> attached was done
const int curPartyId = m_ui->cbParty->currentData().toInt();
// we need to create a new ParticipantOrganisation entry since addedParticipantId was attached to curParty
ModifyParticipantDataRequest req;
ParticipantOrganisation orga;
orga.participantId(addedParticipantId);
orga.currentPartyId(curPartyId); // moved from pool to curParty
orga.isAttached(false);
orga.isCooperate(true);
req.participantOrganisation(orga);
const QVector<ParticipantData> attachedtData = m_cooperateModel->participantData(curPartyId); // moved from Pool
req.data(LtsUtils::convert<std::vector<ParticipantData>>(attachedtData));
saveParticipantData(req);
}
//slots
void ParticipantOrganisationDialog::onStartTemplateUnitNamer(int templateId)
{
const TemplateParticipant tempPart = m_dtc->templateParticipant(templateId);
//as a framelessdlg it will delete itself
ParticipantUnitNamer *namer = new ParticipantUnitNamer(QString::fromStdString(tempPart.designator()), QString::fromStdString(tempPart.tacticalIdentifier()), this);
connect(namer, &ParticipantUnitNamer::newUnitNames, this, [this, templateId](const QString & designator, const QString & tactIdentifer)
{
m_poolModel->addNewTemplateToPool(templateId, designator, tactIdentifer);
});
namer->show();
}
void ParticipantOrganisationDialog::onPartyChanged()
{
const int curPartyId = m_ui->cbParty->currentData().toInt();
s_preselectedParty = curPartyId;
DEBUG_LOG(m_logger) << LOGFUNCTION << " START, curPartyId" << curPartyId
<< ", m_asSupportService=" << m_asSupportService;
// if(!m_asSupportService)
// {
// m_ui->cbParty->setEnabled(false); // will be re-enabled with reply (::onLockDataChanged)
// tryLockTopicNew(QStringLiteral("LockParty"), curPartyId);
// }
for (auto tv : {m_ui->tvParty, m_ui->tvDetached, m_ui->tvAttached, m_ui->tvCooperate})
{
auto model = qobject_cast<ParticipantOrgaProxyModel *>(tv->model());
if (!model) // e.g. in O/C mode
continue;
model->onReinitModel(curPartyId);
const int colCount = tv->model()->columnCount(QModelIndex());
tv->expandAll();
for (int i = 0; i < colCount; ++i)
tv->resizeColumnToContents(i);
tv->header()->resizeSection(0, tv->columnWidth(0) + tv->iconSize().width() + 10);
}
//reinit PoolModel if no save on party
m_poolModel->onReinitModel();
}
void ParticipantOrganisationDialog::onRemovePoolParty()
{
const int curIdx = m_ui->tvPool->currentIndex().row();
if (m_poolModel->canRemoveRow(curIdx))
m_poolModel->removeRow(curIdx);
else
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Can not remove unit - is a detached subunit"), tr("Can not remove unit"));
}
void ParticipantOrganisationDialog::showContextMenu(const QPoint &position)
{
QTreeView *tv = qobject_cast<QTreeView *>(sender());
if (!tv)
return;
const QModelIndex idx = tv->currentIndex();
if (!idx.isValid())
return;
if (tv->model()->rowCount(idx) == 0)
return;
QMenu menu;
if (tv->isExpanded(idx))
{
QAction *collapseAction = new QAction(tr("Collapse"), &menu);
connect(collapseAction, &QAction::triggered, this, [tv, idx]() { tv->collapse(idx);});
menu.addAction(collapseAction);
}
else
{
QAction *expandAction = new QAction(tr("Expand"), &menu);
connect(expandAction, &QAction::triggered, this, [tv, idx]() { tv->expand(idx);});
menu.addAction(expandAction);
}
menu.exec(tv->viewport()->mapToGlobal(position));
}
//delegate for pool Entries
DeleteDelegate::DeleteDelegate(QObject *parent)
: QItemDelegate(parent)
{
}
void DeleteDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
if (index.column() == ParticipantManagement::ParticipantPoolModel::ColRemove)
{
painter->drawImage(option.rect.topLeft(), QImage(QLatin1String("icon:trash-alt.svg")).scaled(option.rect.height(), option.rect.height(),
Qt::KeepAspectRatio, Qt::SmoothTransformation));
}
else
QItemDelegate::paint(painter, option, index);
}
bool DeleteDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index)
{
if (event->type() != QEvent::MouseButtonRelease)
return QItemDelegate::editorEvent(event, model, option, index);
QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
QRect imageRect = option.rect;
imageRect.setWidth(imageRect.height());
if (mouseEvent && mouseEvent->button() == Qt::MouseButton::LeftButton &&
imageRect.intersects(QRect(mouseEvent->pos(), mouseEvent->pos())))
{
emit removePoolParty();
return true;
}
else
return QItemDelegate::editorEvent(event, model, option, index);
}
} //namespace ParticipantManagement
@@ -0,0 +1,119 @@
/**
* @RDE_HEADER@
* GUI Plugin for ParticipantManagement - Participant Organisaton
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#pragma once
#include <Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h>
#include "participant_pool_model.h"
#include "participant_orga_model.h"
#include <ParticipantManagement/logger.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <Services/ParticipantManagement/ppm_ftc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_templates_gui_plugin_interface.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsSession/lts_session.h>
#include <LtsUtilsGuiDds/request_helper.h>
#include <QItemDelegate>
class QSortFilterProxyModel;
namespace Ui
{
class ParticipantOrganisation;
}
namespace ParticipantManagement
{
class DeleteDelegate : public QItemDelegate
{
Q_OBJECT
public:
explicit DeleteDelegate(QObject *parent = nullptr);
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override;
Q_SIGNALS:
void removePoolParty();
};
//----------------------------------------------------------------------------
class ParticipantOrganisationDialog : public LtsWidgets::LtsDialog,
protected ParticipantManagement::Interface::Ftc::ModifyParticipantDataReplyHandler
{
Q_OBJECT
public:
ParticipantOrganisationDialog(LtsSession::LtsSession *session,
bool asSupportService,
QWidget *parent = nullptr);
~ParticipantOrganisationDialog();
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ParticipantManagement::ForeignGuiTemplatesInterface> &ppmGuiTemplateIfc,
const std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc);
void onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject) override final;
void retranslate() override;
void lock() override;
void unlock() override;
private:
QModelIndex selectedIndexView() const;
bool saveParticipantData(const ModifyParticipantDataRequest &request);
protected Q_SLOTS:
void onPoolParticipantsChanged(const QVector<ParticipantData> &participants, const QString &originatorMimeType);
void onPartyParticipantsChanged(int addedParticipantId);
void onAttachedParticipantsChanged(int addedParticipantId);
void onDetachedParticipantsChanged(int addedParticipantId);
void onCooperateParticipantsChanged(int addedParticipantId);
void onStartTemplateUnitNamer(int templateId);
void onPartyChanged();
void onRemovePoolParty();
void showContextMenu(const QPoint &position);
private:
bool m_asSupportService;
ParticipantPoolModel *m_poolModel;
QSortFilterProxyModel *m_proxyModel;
ParticipantOrgaModel *m_partyModel;
ParticipantOrgaModel *m_attachedModel;
ParticipantOrgaModel *m_detachedModel;
ParticipantOrgaModel *m_cooperateModel;
DeleteDelegate *m_delegate;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
std::shared_ptr<ParticipantManagement::ForeignGuiTemplatesInterface> m_ppmGuiTemplateIfc;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
LtsSession::LtsSession *m_session;
LtsUtils::RequestHelper *m_requestHelper;
static int s_preselectedParty;
Ui::ParticipantOrganisation *m_ui;
NGL::INGLLogger &m_logger;
};
} //ParticipantManagement
@@ -0,0 +1,206 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantOrganisation</class>
<widget class="QWidget" name="ParticipantOrganisation">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string notr="true">setwindowtitle in source</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="childrenCollapsible">
<bool>false</bool>
</property>
<widget class="QWidget" name="layoutWidget">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="lblTemplates">
<property name="text">
<string>Templates:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvTemplate">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::CopyAction</enum>
</property>
<property name="rootIsDecorated">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget1">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="lblPool">
<property name="text">
<string>Pool:</string>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvPool">
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="layoutWidget2">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblParty">
<property name="text">
<string>Party:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="LtsWidgets::LtsComboBox" name="cbParty"/>
</item>
<item row="0" column="2">
<spacer name="spcParty">
<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 row="1" column="0" colspan="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeView" name="tvParty">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvAttached">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvDetached">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
</widget>
</item>
<item>
<widget class="QTreeView" name="tvCooperate">
<property name="contextMenuPolicy">
<enum>Qt::CustomContextMenu</enum>
</property>
<property name="acceptDrops">
<bool>true</bool>
</property>
<property name="dragEnabled">
<bool>true</bool>
</property>
<property name="dragDropMode">
<enum>QAbstractItemView::DragDrop</enum>
</property>
<property name="defaultDropAction">
<enum>Qt::MoveAction</enum>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</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,422 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Pool Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-17
*/
#include "participant_pool_model.h"
#include <Plugins/ParticipantManagement/ppm_mime_datas.h>
#include <ParticipantManagement/ppm_translation.h>
#include <LtsSession/lts_session_data_dds.h>
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
#include <Symbology/symbol_data_to_render_role.h>
#include <QMimeData>
#include <QTimer>
namespace ParticipantManagement
{
//----------------------------------------------------------------------------
ParticipantPoolModel::ParticipantPoolModel(QObject *parent,
LtsSession::LtsSessionDataDds *session,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
bool asSupportService)
: LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>({tr("Delete"),
tr("Designator/Identifier"),
tr("Type Class"),
tr("Type"),
tr("Participant Id") },
parent)
, AdvancedSymbology::TableModelSymbolRenderer<ParticipantPoolModel>(ColDesignatorIdentifier)
, m_asSupportService(asSupportService)
, m_dtc(dtc)
, m_logger(getLogger("ParticipantPoolModel"))
{
// optional
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
AdvancedSymbology::TableModelSymbolRenderer<ParticipantPoolModel>::init(asb, this);
onReinitModel();
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::participantChanged,
this, &ParticipantPoolModel::onParticipantDataChanged);
connect(m_dtc.get(), &ParticipantManagement::Interface::Dtc::participantOrganisationChanged,
this, &ParticipantPoolModel::onParticipantOrganisationChanged);
m_dtc->participantOrganisations([this](const ParticipantOrganisation &org) { onParticipantOrganisationChanged(org, DataModification::eAdded); });
const ParticipantManagement::Party &party = m_dtc->party(poolPartyId());
setDefaultRoleAndColor(AdvancedSymbology::roleToRole<>(party.role()),
QColor::fromRgb(QRgb(party.color())));
}
bool ParticipantPoolModel::canRemoveRow(int row) const
{
if (row < 0 || row >= m_vecData.size())
return false;
return true;
/*
// commented out - we want to be able to also deleted detached structures.
const ParticipantManagement::ParticipantData &data = m_vecData.at(row);
if (data.id() == 0)
return true;
return !(m_participantOrganization.contains(data.id()));
*/
}
bool ParticipantPoolModel::removeRow(int row)
{
if (row < 0 || row >= m_vecData.size())
return false;
QVector<ParticipantData> datasToDelete;
ParticipantManagement::ParticipantData dataToDelete = getRowData(row);
removeRenderedSymbol(dataToDelete.id());
if (dataToDelete.id() != 0) //remove from DDS
{
dataToDelete.isDeleted(true);
datasToDelete.append(dataToDelete);
}
LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>::removeRow(row);
emit modifyParticipantData(datasToDelete, QString());
return true;
}
QVariant ParticipantPoolModel::data(const QModelIndex &index, int role) const
{
if (!indexIsValid(index) || (role != Qt::DisplayRole && role != Qt::DecorationRole))
return QVariant();
const ParticipantManagement::ParticipantData &participantData = m_vecData.at(index.row());
if (role == Qt::DecorationRole)
return decorationData(index, participantData.id());
switch (index.column())
{
case ColRemove:
break;
case ColDesignatorIdentifier:
return QString(QString::fromStdString(participantData.designator()) + QLatin1Char('/') +
QString::fromStdString(participantData.tacticalIdentifier()));
case ColTypeClass:
return ParticipantManagement::toString(m_dtc->type(participantData.typeId()).typeClass());
case ColType:
return ParticipantManagement::trTypeName(m_dtc->type(participantData.typeId()).name());
case ColParticipantId:
return participantData.id();
}
return QVariant();
}
int ParticipantPoolModel::columnCount(const QModelIndex &parent) const
{
int cc = LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>::columnCount(parent);
#ifndef LTS_DEBUG
// participant id only in dev mode
cc -= 1;
#endif
return cc;
}
QMimeData *ParticipantPoolModel::mimeData(const QModelIndexList &indexes) const
{
// nicht != 1 da eine komplette Zeile markiert ist
if (indexes.size() < 1)
return nullptr;
const QModelIndex &idx = indexes.first();
if (!indexIsValid(idx))
return nullptr;
const ParticipantData &data = m_vecData.at(idx.row());
if (data.id() == 0)
return nullptr;
const QByteArray encodedData(QByteArray::number(data.id()));
QMimeData *mimeData = new QMimeData;
const QString mimeType = m_participantOrganization.contains(data.id()) ? ParticipantPoolDetached : ParticipantPoolRoot;
mimeData->setData(mimeType, encodedData);
return mimeData;
}
Qt::ItemFlags ParticipantPoolModel::flags(const QModelIndex &index) const
{
Qt::ItemFlags retFlags = LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>::flags(index);
retFlags |= Qt::ItemIsDragEnabled;
retFlags |= Qt::ItemIsDropEnabled;
return retFlags;
}
bool ParticipantPoolModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
Q_UNUSED(row);
Q_UNUSED(column);
Q_UNUSED(parent);
if (action != Qt::CopyAction && action != Qt::MoveAction)
return false;
DEBUG_LOG(m_logger) << "dropMimeData: " << data->formats().join(QLatin1Char(','));
if (!data->hasFormat(ParticipantTemplateRoot) &&
!data->hasFormat(ParticipantPartyRoot) &&
!data->hasFormat(ParticipantPartyAttached))
return false;
if (data->hasFormat(ParticipantManagement::ParticipantTemplateRoot))
{
bool bOk;
const int id = data->data(ParticipantManagement::ParticipantTemplateRoot).toInt(&bOk);
if (!bOk)
return false;
emit startUnitNamer(id);
}
else // == ParticipantPartyRoot | ParticipantPartyAttached
{
const QString mimeType = data->hasFormat(ParticipantPartyRoot) ? ParticipantPartyRoot : ParticipantPartyAttached;
bool bOk;
const int id = data->data(mimeType).toInt(&bOk);
if (!bOk)
return false;
moveFromPartyToPool(id, mimeType);
}
return true;
}
QStringList ParticipantPoolModel::mimeTypes() const
{
return { ParticipantTemplateRoot, ParticipantPartyRoot, ParticipantPartyAttached};
}
QVector<ParticipantData> ParticipantPoolModel::getPoolData() const
{
return m_dataToDelete + m_fullPoolData;
}
bool ParticipantPoolModel::onReinitModel()
{
clear();
const QMap<qint32, ParticipantManagement::Participant> participantMap(m_dtc->participants());
for (const ParticipantManagement::Participant &part : participantMap)
{
if (part.superiorId() > 0 || part.partyId() != poolPartyId() || part.isDeleted())
continue;
if (!isValidTypeClass(part.typeId()))
continue;
insertRow(part);
}
return true;
}
bool ParticipantPoolModel::addNewTemplateToPool(int id, const QString &designator, const QString &tactIdentifier)
{
QVector<TemplateParticipant> templateDatas;
m_dtc->templateParticipantsFromTemplateId(id, templateDatas);
//replace first UnitName
TemplateParticipant &root = templateDatas[0];
root.superiorTemplateId(0);
root.hierarchyNumber(1);
root.designator(designator.toStdString());
root.tacticalIdentifier(tactIdentifier.toStdString());
QVector<ParticipantManagement::ParticipantData> newPool;
newPool.reserve(templateDatas.size());
for (const TemplateParticipant &participant : qAsConst(templateDatas))
{
ParticipantData newData;
convertFromParticipantTemplateToParticipantData(participant, newData);
newPool.append(newData);
}
emit modifyParticipantData(newPool, QString());
return true;
}
void ParticipantPoolModel::onParticipantDataChanged(const Participant &data, DataModification modType)
{
if (!isValidTypeClass(data.typeId()))
return;
if (data.isDeleted())
modType = DataModification::eRemoved;
switch (modType)
{
case DataModification::eModified:
for (int i = 0; i < m_vecData.size(); ++i)
{
const ParticipantData &part = m_vecData.at(i);
if (part.id() == data.id())
{
DEBUG_LOG(m_logger) << "Modifed participant " << data.id() << ", old party: " << part.partyId() << ", new: " << data.partyId();
// no longer in pool?
if (data.partyId() != poolPartyId())
{
// do not call ParticipantPoolModel::removeRow() since the participant was not removed
// from within ParticipantPoolModel
// delay the remove of this participant since it can happen due to a dnd move operation
// which will cause a removeRow() afterwards and another entry will be removed then too ...
const int participantId = data.id();
QTimer::singleShot(100, this, [this, participantId]() { tryRemoveParticipantFromModel(participantId); });
}
else
{
setRowData(i, m_dtc->convertParticipantToParticipantData(data));
}
return;
}
}
// new item -> try to add
Q_FALLTHROUGH();
case DataModification::eAdded:
if (data.superiorId() != 0 && !m_participantOrganization.contains(data.id()))
return;
if (data.partyId() != poolPartyId())
return;
insertRow(data);
break;
case DataModification::eRemoved:
if (data.partyId() != poolPartyId())
return;
tryRemoveParticipantFromModel(data.id());
break;
}
}
void ParticipantPoolModel::onParticipantOrganisationChanged(const ParticipantOrganisation &data, DataModification modType)
{
switch (modType)
{
case DataModification::eAdded:
case DataModification::eModified:
m_participantOrganization[data.participantId()] = data;
break;
case DataModification::eRemoved:
m_participantOrganization.remove(data.participantId());
break;
}
}
bool ParticipantPoolModel::moveFromPartyToPool(int rootParticipantId, const QString &mimeType)
{
ERROR_LOG(m_logger) << "Moving participant " << rootParticipantId << " from party to root with mime type " << mimeType;
//start with building the tree
const Participant part = m_dtc->participant(rootParticipantId);
const QVector<Participant> newParticipants = getSuperiorParticipants(part.id());
QVector<ParticipantData> dataToSend;
dataToSend.reserve(newParticipants.size());
for (const Participant &part : newParticipants)
{
ParticipantData data = m_dtc->convertParticipantToParticipantData(part);
data.partyId(poolPartyId());
if (data.id() == rootParticipantId)
{
// the new root has no superior and a hierarchy number of 1
data.superiorModId(0);
data.hierarchyNumber(1);
}
dataToSend.append(data);
}
if (dataToSend.isEmpty())
return false;
emit modifyParticipantData(dataToSend, mimeType);
return true;
}
QVector<Participant> ParticipantPoolModel::getSuperiorParticipants(int participantId)
{
Participant part = m_dtc->participant(participantId);
QVector<Participant> retParticipants;
retParticipants.append(part);
for (auto const &inferierPart : part.inferiorIds())
retParticipants.append(getSuperiorParticipants(inferierPart));
return retParticipants;
}
bool ParticipantPoolModel::convertFromParticipantTemplateToParticipantData(const TemplateParticipant &inputParticipant, ParticipantData &outPutData)
{
//No assignsState out of template
outPutData.assignState(ParticipantManagement::ParticipantAssignState::NotAssigned);
// no participantId out of template
outPutData.id(0);
outPutData.partyId(poolPartyId());
//this could be intensive.. what about the second template with equipNumbers/
if (inputParticipant.equipmentNumber() != 0)
{
outPutData.equipmentNumber(inputParticipant.equipmentNumber());
outPutData.assignState(ParticipantAssignState::HandoutExcon);
}
outPutData.hierarchyNumber(inputParticipant.hierarchyNumber());
outPutData.info() = inputParticipant.info();
outPutData.name() = inputParticipant.name();
outPutData.designator() = inputParticipant.designator();
outPutData.tacticalIdentifier(inputParticipant.tacticalIdentifier());
outPutData.symbol(inputParticipant.symbol());
outPutData.typeId(inputParticipant.typeId());
outPutData.isSimulated(false);
//modIDgames
outPutData.modId(inputParticipant.templateId());
outPutData.superiorModId(inputParticipant.superiorTemplateId());
outPutData.hierarchyNumber(inputParticipant.hierarchyNumber());
return true;
}
bool ParticipantPoolModel::isValidTypeClass(int typeId) const
{
const TypeClass tc = m_dtc->type(typeId).typeClass();
switch (tc.underlying())
{
case TypeClass_def::Unit:
return !m_asSupportService;
case TypeClass_def::SupportUnit:
return m_asSupportService;
default:
break;
}
return false;
}
void ParticipantPoolModel::insertRow(const Participant &participant)
{
tryRenderSymbol(QString::fromStdString(participant.symbol()), participant.id());
LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>::insertRow(
m_dtc->convertParticipantToParticipantData(participant));
}
void ParticipantPoolModel::tryRemoveParticipantFromModel(int participantId)
{
for (int i = 0; i < m_vecData.size(); ++i)
{
const ParticipantData &part = m_vecData.at(i);
if (part.id() == participantId)
{
DEBUG_LOG(m_logger) << "Removing participant " << participantId;
// we must not call removeRow(i) since this will trigger a ModifyRequest which removes the complete subtree ...
LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>::removeRow(i);
break;
}
}
}
} //namespace ParticipantManagement
@@ -0,0 +1,94 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Participant Pool Model
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <Services/ParticipantManagement/ppm_dtc.h>
#include <LtsWidgets/lts_abstract_table_model.h>
#include <Plugins/AdvancedSymbology/Helper/table_model_symbol_renderer.h>
namespace LtsSession
{
class LtsSessionDataDds;
}
namespace ParticipantManagement
{
//----------------------------------------------------------------------------
class ParticipantPoolModel final : public LtsWidgets::LtsAbstractTableModel<ParticipantManagement::ParticipantData>
, public AdvancedSymbology::TableModelSymbolRenderer<ParticipantPoolModel>
{
Q_OBJECT
friend class AdvancedSymbology::TableModelSymbolRenderer<ParticipantPoolModel>;
public:
enum Columns
{
ColRemove,
ColDesignatorIdentifier,
ColTypeClass,
ColType,
ColParticipantId
};
ParticipantPoolModel(QObject *parent,
LtsSession::LtsSessionDataDds *session,
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
bool asSupportService);
bool onReinitModel();
bool canRemoveRow(int row) const;
bool removeRow(int row) override;
QVariant data(const QModelIndex &index, int role) const override;
int columnCount(const QModelIndex &parent) const override;
QMimeData *mimeData(const QModelIndexList &indexes) const override;
Qt::ItemFlags flags(const QModelIndex &index) 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::CopyAction; }
Qt::DropActions supportedDragActions() const override { return Qt::MoveAction; }
QStringList mimeTypes() const override;
QVector<ParticipantManagement::ParticipantData> getPoolData() const;
bool addNewTemplateToPool(int id, const QString &designator, const QString &tactIdentifier);
public Q_SLOTS:
void onParticipantDataChanged(const Participant &data, DataModification modType);
void onParticipantOrganisationChanged(const ParticipantOrganisation &data, DataModification modType);
Q_SIGNALS:
void startUnitNamer(int);
void modifyParticipantData(const QVector<ParticipantData> &participantData, const QString &originatorMimeType);
private:
bool moveFromPartyToPool(int rootParticipantId, const QString &mimeType);
QVector<Participant> getSuperiorParticipants(int participantId);
bool convertFromParticipantTemplateToParticipantData(const ParticipantManagement::TemplateParticipant &inputParticipant, ParticipantManagement::ParticipantData &outPutData);
bool isValidTypeClass(int typeId) const;
void insertRow(const Participant &participant);
void tryRemoveParticipantFromModel(int participantId);
int poolPartyId() const { return m_asSupportService ? 1 : 0; }
private:
bool m_asSupportService;
QVector<ParticipantData> m_fullPoolData;
QVector<ParticipantData> m_dataToDelete;
QHash<int, ParticipantOrganisation> m_participantOrganization;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
NGL::INGLLogger &m_logger;
};
} //namespace ParticipantManagement
@@ -0,0 +1,60 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Name Unit Frameless Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-07
*/
#include "participant_unit_namer.h"
#include "ui_participant_unit_namer.h"
#include <LtsSession/lts_session_manager.h>
namespace ParticipantManagement
{
ParticipantUnitNamer::ParticipantUnitNamer(const QString &designator, const QString &tactIdent, QWidget *parent)
: LtsWidgets::LtsFramelessDialog(parent, LtsWidgets::Behaviour::Modal)
, m_ui(new Ui::ParticipantUnitNamer)
, m_validator(new QRegularExpressionValidator(QRegularExpression(QStringLiteral("[^,;\"'´`]*")), this))
, m_logger(getLogger("ParticipantTemplateChooser"))
{
m_ui->setupUi(this);
m_ui->leDesignator->setValidator(m_validator);
m_ui->leTactIdentifier->setValidator(m_validator);
m_ui->leDesignator->setText(designator);
m_ui->leTactIdentifier->setText(tactIdent);
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Ok)->setVisible(false);
m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Apply)->setVisible(false);
m_ui->ltsDialogButtonBox->connectButton(LtsWidgets::DialogButton::Add, this, &ParticipantUnitNamer::onSetUnitName);
m_ui->ltsDialogButtonBox->setText(LtsWidgets::DialogButton::Add, tr("OK")); // TODO: undo workaround !
// FIXME: HACK: as close is not allowed directly (for a FramelessDialog)
connect(m_ui->ltsDialogButtonBox->getButton(LtsWidgets::DialogButton::Close), &QPushButton::clicked, this, &ParticipantUnitNamer::close);
}
ParticipantUnitNamer::~ParticipantUnitNamer()
{
delete m_ui;
}
//SLOTS
void ParticipantManagement::ParticipantUnitNamer::onSetUnitName()
{
if (m_ui->leDesignator->text().isEmpty() || m_ui->leTactIdentifier->text().isEmpty())
return;
emit newUnitNames(m_ui->leDesignator->text(), m_ui->leTactIdentifier->text());
close();
}
} //namespace ParticipantManagement
@@ -0,0 +1,42 @@
/**
* @RDE_HEADER@
* HMI Plugin for ParticipantManagement - Name Unit Frameless Dialog
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-11-07
*/
#pragma once
#include <ParticipantManagement/logger.h>
#include <LtsWidgets/lts_frameless_dialog.h>
namespace Ui
{
class ParticipantUnitNamer;
}
namespace ParticipantManagement
{
class ParticipantUnitNamer : public LtsWidgets::LtsFramelessDialog
{
Q_OBJECT
public:
explicit ParticipantUnitNamer(const QString &designator, const QString &tactIdent, QWidget *parent = nullptr);
~ParticipantUnitNamer();
private Q_SLOTS:
void onSetUnitName();
Q_SIGNALS:
void newUnitNames(const QString &, const QString &);
private:
Ui::ParticipantUnitNamer *m_ui;
QValidator *m_validator;
LOGGER_T m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ParticipantUnitNamer</class>
<widget class="QWidget" name="ParticipantUnitNamer">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>432</width>
<height>114</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true"/>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="2">
<widget class="QLineEdit" name="leTactIdentifier">
<property name="maxLength">
<number>20</number>
</property>
</widget>
</item>
<item row="5" column="0" colspan="3">
<widget class="LtsWidgets::LtsDialogButtonBox" name="ltsDialogButtonBox"/>
</item>
<item row="2" column="0">
<widget class="QLineEdit" name="leDesignator">
<property name="maxLength">
<number>8</number>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Designator:</string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string notr="true">/</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Tactical Identifier:</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsDialogButtonBox</class>
<extends>QWidget</extends>
<header>LtsWidgets/lts_dialog_button_box.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
@@ -0,0 +1,388 @@
/**
* @RDE_HEADER@
* Tactical Organisation of Parties (during exercise execution)
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#include "tactical_organisation.h"
#include "ui_tactical_organisation.h"
#include <Common/participant_beautify_view.h>
#include <Common/participant_edit_item.h>
#include <Plugins/ParticipantManagement/Gui/Common/participant_edit_model.h>
#include <Plugins/ParticipantManagement/Gui/Common/participant_search_modal.h>
#include <LtsSession/lts_session.h>
#include <QMenu>
#include <QTreeView>
#include <Core/core_ftc.h>
#include <LtsSession/lts_session_data.h>
namespace ParticipantManagement
{
int TacticalOrganisation::s_preselectedPartyLeft = -1;
int TacticalOrganisation::s_preselectedPartyRight = -1;
TacticalOrganisation::TacticalOrganisation(LtsSession::LtsSession *session, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_session(session)
, m_requestHelper(new LtsUtils::RequestHelper(this))
, m_addEquipmentNumberAction(new QAction(tr("Add Participant"), this))
, m_tvContextMenu(nullptr)
, m_newItemDlg(nullptr)
, m_ui(new Ui::TacticalOrganisation)
, m_logger(getLogger("TacticalOrganisation"))
{
m_ui->setupUi(this);
connect(m_addEquipmentNumberAction, &QAction::triggered,
this, &TacticalOrganisation::onAddParticipant);
setOnlineHelpFilename(QStringLiteral("Situation-Tactical_Organisation"));
// deactivate TopicLockHandler created by framework
setNoTopicLock();
}
TacticalOrganisation::~TacticalOrganisation()
{
if (m_unlockId)
m_coreFtc->tryUnlockEntityRequest(Core::TryUnlockEntityRequest(m_unlockId));
delete m_ui;
}
bool TacticalOrganisation::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc)
{
if (m_dtc)
return false;
if (!dtc || !ftc || !ppmGuiCbxIfc)
return false;
if (!m_session)
return false;
if (!m_session->createTopicClient<Core::Interface::Ftc>(m_coreFtc))
{
ERROR_LOG(m_logger) << LOGFUNCTION << " create coreFtc failed";
return false;
}
m_coreFtc->enableAll();
m_dtc = dtc;
m_ftc = ftc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
m_asbIfc = asbIfc;
connect(m_ui->cbPartyLeft, &LtsWidgets::LtsComboBox::currentTextChanged,
this, &TacticalOrganisation::onReinitLeft);
connect(m_ui->cbPartyRight, &LtsWidgets::LtsComboBox::currentTextChanged,
this, &TacticalOrganisation::onReinitRight);
for (auto tv : {m_ui->dvPartyLeft->treeView(), m_ui->dvPartyRight->treeView()})
{
tv->setDragEnabled(true);
tv->setDragDropMode(QAbstractItemView::DragDrop);
tv->setDefaultDropAction(Qt::MoveAction);
tv->setContextMenuPolicy(Qt::CustomContextMenu);
connect(tv, &QTreeView::customContextMenuRequested,
this, &TacticalOrganisation::showContextMenu);
}
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbPartyLeft, ParticipantManagement::ForeignGuiComboboxInterface::CbxPartyFilter::NormalPool);
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbPartyRight, ParticipantManagement::ForeignGuiComboboxInterface::CbxPartyFilter::NormalPool);
int idx = m_ui->cbPartyLeft->findData(s_preselectedPartyLeft);
if (idx >= 0)
m_ui->cbPartyLeft->setCurrentIndex(idx);
idx = m_ui->cbPartyRight->findData(s_preselectedPartyRight);
if (idx >= 0)
m_ui->cbPartyRight->setCurrentIndex(idx);
onReinitLeft();
onReinitRight();
initLockedState();
return true;
}
void TacticalOrganisation::retranslate()
{
translate(m_ui, tr("Tactical Organisation"));
}
bool TacticalOrganisation::apply()
{
ModifyParticipantDataRequest req;
std::vector<ParticipantData> &dataToSend = req.data();
for (const ParticipantEditModel *model : qAsConst(m_participantModels))
{
const auto c = model->participantData();
dataToSend.insert(dataToSend.end(), c.begin(), c.end());
}
if (req.data().size() == 0)
return true;
return m_requestHelper->startSingleRequest([this, req]()
{
return m_ftc->modifyParticipantDataRequest(req, this);
});
}
void TacticalOrganisation::onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject)
{
if (!replyObject.error())
{
for (ParticipantEditModel *model : qAsConst(m_participantModels))
model->dataCommitted();
}
m_requestHelper->requestReply(replyObject);
}
void TacticalOrganisation::onReinitLeft()
{
const int partyId = m_ui->cbPartyLeft->currentData().toInt();
s_preselectedPartyLeft = partyId;
auto *model = modelForParty(partyId, true);
INFO_LOG(m_logger) << "Set model left: " << model;
m_ui->dvPartyLeft->setModel(model);
#ifndef LTS_DEBUG
m_ui->dvPartyLeft->setColumnHidden(ParticipantEditModel::ColParticipantId, true);
#endif
beautifyTreeView(m_ui->dvPartyLeft->treeView(), model);
}
void TacticalOrganisation::onReinitRight()
{
const int partyId = m_ui->cbPartyRight->currentData().toInt();
s_preselectedPartyRight = partyId;
auto *model = modelForParty(partyId, false);
INFO_LOG(m_logger) << "Set model right: " << model;
m_ui->dvPartyRight->setModel(model);
#ifndef LTS_DEBUG
m_ui->dvPartyRight->setColumnHidden(ParticipantEditModel::ColParticipantId, true);
#endif
beautifyTreeView(m_ui->dvPartyRight->treeView(), model);
}
void TacticalOrganisation::onAddParticipant()
{
ParticipantSearchModal *sm = new ParticipantSearchModal(this);
if (!sm->init(m_dtc))
{
sm->deleteLater();
return;
}
connect(sm, &ParticipantSearchModal::participantSelected, this, &TacticalOrganisation::onParticipantSelected);
sm->show();
}
void TacticalOrganisation::onParticipantSelected(int participantId)
{
auto s = sender();
if (s)
s->deleteLater();
if (!m_tvContextMenu)
return;
const QModelIndex newIdx = m_tvContextMenu->currentIndex();
if (!newIdx.isValid())
return;
Participant participant = m_dtc->participant(participantId);
if (participant.id() != participantId)
return;
ParticipantTreeFilterProxyModel *newModel = static_cast<ParticipantTreeFilterProxyModel *>(m_tvContextMenu->model());
ParticipantEditModel *oldPem = editModelForParty(participant.partyId());
ParticipantEditModel *newPem = editModelForParty(newModel->partyId());
QModelIndex oldIdx = oldPem->indexFromParticipantId(participantId);
if (!oldIdx.isValid())
{
for (ParticipantEditModel *model : qAsConst(m_participantModels))
{
oldPem = model;
oldIdx = oldPem->indexFromParticipantId(participantId);
if (oldIdx.isValid())
break;
}
if (!oldIdx.isValid())
return;
}
const ParticipantData pd = oldPem->privateData(oldIdx)->participant;
oldPem->removeRow(oldIdx.row(), oldIdx.parent());
newPem->insertParticipant(newModel->mapToSource(newIdx), pd, false);
}
void TacticalOrganisation::editParticipant(const QModelIndex &idx)
{
if (m_newItemDlg || !idx.isValid())
return;
const ParticipantTreeFilterProxyModel *pfpm = qobject_cast<const ParticipantTreeFilterProxyModel *>(idx.model());
if (!pfpm)
return;
const QModelIndex srcIdx = pfpm->mapToSource(idx);
if (!srcIdx.isValid())
return;
ParticipantEditModel *pem = editModelForParty(pfpm->partyId());
const auto pd = pem->privateData(srcIdx);
if (!pd)
return;
m_newItemDlg = new ParticipantEditItem(false, m_session, this);
m_newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
if (!m_newItemDlg->init(srcIdx, pfpm->partyId(), m_dtc, m_ppmGuiCbxIfc, m_asbIfc, pd->participant))
{
delete m_newItemDlg;
return;
}
QObject::connect(m_newItemDlg, &ParticipantEditItem::destroyed, this, [this]{ m_newItemDlg = nullptr; });
QObject::connect(m_newItemDlg, &ParticipantEditItem::updateItem, pem, &ParticipantEditModel::onUpdateRow);
m_newItemDlg->show();
}
// duplicated from ParticipantTreeEditHandler since we need slight modifcations here
void TacticalOrganisation::showContextMenu(const QPoint position)
{
m_tvContextMenu = qobject_cast<QTreeView *>(sender());
if (!m_tvContextMenu)
return;
QModelIndex idx = m_tvContextMenu->currentIndex();
if (!idx.isValid())
return;
if (idx.column() != 0)
idx = m_tvContextMenu->model()->index(idx.row(), 0, idx.parent());
QMenu menu;
QAction *editParticipantAction = new QAction(tr("Edit"), &menu);
connect(editParticipantAction, &QAction::triggered, this, [this, idx]() { editParticipant(idx); });
menu.addAction(editParticipantAction);
if (m_tvContextMenu->model()->rowCount(idx) != 0)
{
menu.addAction(m_addEquipmentNumberAction);
if (m_tvContextMenu->isExpanded(idx))
{
QAction *collapseAction = new QAction(tr("Collapse"), &menu);
connect(collapseAction, &QAction::triggered, this, [this, idx]() { m_tvContextMenu->collapse(idx);});
menu.addAction(collapseAction);
QAction *collapseAllAction = new QAction(tr("Collapse all"), &menu);
connect(collapseAllAction, &QAction::triggered, this, [this, idx]() { expandNodeChildren(m_tvContextMenu, idx, false); });
menu.addAction(collapseAllAction);
}
else
{
QAction *expandAction = new QAction(tr("Expand"), &menu);
connect(expandAction, &QAction::triggered, this, [this, idx]() { m_tvContextMenu->expand(idx);});
menu.addAction(expandAction);
}
QAction *expandAllAction = new QAction(tr("Expand all"), &menu);
connect(expandAllAction, &QAction::triggered, this, [this, idx]() { expandNodeChildren(m_tvContextMenu, idx, true); });
menu.addAction(expandAllAction);
}
if (!menu.actions().isEmpty())
menu.exec(m_tvContextMenu->viewport()->mapToGlobal(position));
}
// duplicated from ParticipantTreeEditHandler since we can't use it here :(
/*
* 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 TacticalOrganisation::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);
}
ParticipantTreeFilterProxyModel *TacticalOrganisation::modelForParty(int partyId, bool bLeftSide)
{
// we need a different filter model for left and for right side!
int partyIdToSearch = bLeftSide ? partyId : partyId + 10000000;
auto ret = m_participantProxyModels.value(partyIdToSearch);
if (ret)
return ret;
ret = new ParticipantTreeFilterProxyModel(this);
ret->setSourceModel(editModelForParty(partyId));
m_participantProxyModels.insert(partyIdToSearch, ret);
return ret;
}
ParticipantEditModel *TacticalOrganisation::editModelForParty(int partyId)
{
auto pem = m_participantModels.value(partyId);
if (!pem)
{
pem = new ParticipantEditModel(this, m_dtc, m_asbIfc);
pem->onReinitModel(partyId);
pem->setMimeType(QStringLiteral("TacticalOrganisation"));
connect(pem, &ParticipantEditModel::internalDataChanged,
this, &TacticalOrganisation::slotChangesMade);
m_participantModels.insert(partyId, pem);
}
return pem;
}
void TacticalOrganisation::initLockedState()
{
Core::TryLockEntityRequest lockRequest;
lockRequest.id(0);
lockRequest.entityTypeName(QString(QStringLiteral("PpmTacticalOrganisation")).toStdString());
lockRequest.entityId(m_entityId);
lockRequest.exerciseId(m_session->exerciseId());
lockRequest.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
lockRequest.workstationId(LtsSessionData::LtsSessionData::getInstance()->getWorkstationId());
Core::TryLockEntityReply lockReply = m_coreFtc->tryLockEntityRequest(lockRequest);
if (lockReply.alreadyLocked().is_set() && QString::fromStdString(lockReply.alreadyLocked().get().operatorName()) != LtsSessionData::LtsSessionData::getInstance()->getOperatorName())
{
m_topicLockedBy = QString::fromStdString(lockReply.alreadyLocked().get().operatorName());
setUnchangeable(true);
retranslate();
return;
}
m_unlockId = lockReply.id();
}
void TacticalOrganisation::tableColumnOrganiserSetting()
{
//LtsColumnOrganiser
m_ui->dvPartyLeft->setColumnsOrganiserEnabled(identifier(), true);
m_ui->dvPartyRight->setColumnsOrganiserEnabled(identifier(), true);
}
} // namespace ParticipantManagement
@@ -0,0 +1,101 @@
/**
* @RDE_HEADER@
* Tactical Organisation of Parties (during exercise execution)
* $Id$
* $HeadURL$
* $Author$
* Created by Patric Karwat, SLSE, 2016-10-05
*/
#pragma once
#include <LtsWidgets/lts_dialog.h>
#include <ParticipantManagement/logger.h>
#include <ParticipantManagement/ppm_dtc.h>
#include <ParticipantManagement/ppm_ftc.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <LtsUtilsGuiDds/request_helper.h>
class QTreeView;
namespace AdvancedSymbology
{
class ForeignDataInterface;
}
namespace LtsSession
{
class LtsSession;
}
namespace Core
{
namespace Interface
{
class Ftc;
}
}
namespace Ui
{
class TacticalOrganisation;
}
namespace ParticipantManagement
{
class ParticipantEditItem;
class ParticipantEditModel;
class ParticipantTreeFilterProxyModel;
class TacticalOrganisation final : public LtsWidgets::LtsDialog
, protected ParticipantManagement::Interface::Ftc::ModifyParticipantDataReplyHandler
{
Q_OBJECT
public:
explicit TacticalOrganisation(LtsSession::LtsSession *session, QWidget *parent = nullptr);
~TacticalOrganisation();
bool init(const std::shared_ptr<Interface::Dtc> &dtc,
const std::shared_ptr<Interface::Ftc> &ftc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc);
void retranslate() override;
protected:
bool apply() override;
void onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject) override;
private Q_SLOTS:
void onReinitLeft();
void onReinitRight();
void onAddParticipant();
void onParticipantSelected(int participantId);
void showContextMenu(const QPoint position);
private:
void expandNodeChildren(QTreeView *pTreeView, const QModelIndex &index, bool expand);
void editParticipant(const QModelIndex &idx);
ParticipantTreeFilterProxyModel *modelForParty(int partyId, bool bLeftSide);
ParticipantEditModel *editModelForParty(int partyId);
void initLockedState();
void tableColumnOrganiserSetting() override;
private:
std::shared_ptr<Interface::Dtc> m_dtc;
std::shared_ptr<Interface::Ftc> m_ftc;
std::shared_ptr<ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbIfc;
std::shared_ptr<Core::Interface::Ftc> m_coreFtc;
QHash<int, ParticipantEditModel *> m_participantModels;
QHash<int, ParticipantTreeFilterProxyModel *> m_participantProxyModels;
LtsSession::LtsSession *m_session;
LtsUtils::RequestHelper *m_requestHelper;
QAction *m_addEquipmentNumberAction;
QTreeView *m_tvContextMenu;
ParticipantEditItem *m_newItemDlg;
static int s_preselectedPartyLeft;
static int s_preselectedPartyRight;
// used for topic locking
static const qint64 m_entityId { 12345678901 };
int32_t m_unlockId {0};
Ui::TacticalOrganisation *m_ui;
NGL::INGLLogger &m_logger;
};
} // namespace ParticipantManagement
@@ -0,0 +1,123 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>TacticalOrganisation</class>
<widget class="QWidget" name="TacticalOrganisation">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>683</width>
<height>471</height>
</rect>
</property>
<property name="windowTitle">
<string notr="true">Form</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QSplitter" name="splitter">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<widget class="QWidget" name="gridLayoutWidget_3">
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="1">
<widget class="LtsWidgets::LtsComboBox" name="cbPartyLeft">
<property name="const" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblPartyLeft">
<property name="text">
<string>Party:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<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 row="1" column="0" colspan="3">
<widget class="LtsDataView::LtsDataView" name="dvPartyLeft">
<property name="showColumnCount" stdset="0">
<bool>false</bool>
</property>
<property name="toolButtonsVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="gridLayoutWidget_2">
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="1">
<widget class="LtsWidgets::LtsComboBox" name="cbPartyRight">
<property name="const" stdset="0">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lblPartyRight">
<property name="text">
<string>Party:</string>
</property>
</widget>
</item>
<item row="0" column="2">
<spacer name="horizontalSpacer_2">
<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 row="1" column="0" colspan="3">
<widget class="LtsDataView::LtsDataView" name="dvPartyRight">
<property name="showColumnCount" stdset="0">
<bool>false</bool>
</property>
<property name="toolButtonsVisible">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>LtsWidgets::LtsComboBox</class>
<extends>QComboBox</extends>
<header>LtsWidgets/lts_combo_box.h</header>
</customwidget>
<customwidget>
<class>LtsDataView::LtsDataView</class>
<extends>QWidget</extends>
<header>LtsDataView/lts_data_view.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>