Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
@@ -0,0 +1,50 @@
|
||||
#
|
||||
# $Id$
|
||||
# $HeadURL$
|
||||
# $Author$
|
||||
# Created by Mike Wille, SLSE, 2016-09-06
|
||||
#
|
||||
|
||||
#
|
||||
# Data Plugin
|
||||
#
|
||||
SET(participant_org_chart_gui_SRCS
|
||||
participant_org_chart_gui_plugin.cpp
|
||||
participant_org_chart_gui_plugin.h
|
||||
participant_org_chart.cpp
|
||||
participant_org_chart.h
|
||||
participant_org_chart_helper.cpp
|
||||
participant_org_chart_helper.h
|
||||
combat_power.cpp
|
||||
combat_power.h
|
||||
org_chart_main.cpp
|
||||
org_chart_main.h
|
||||
org_chart_main_helper.cpp
|
||||
org_chart_main_helper.h
|
||||
)
|
||||
NGL_WRAP_UI(participant_org_chart_gui_SRCS
|
||||
participant_org_chart.ui
|
||||
combat_power.ui
|
||||
org_chart_main.ui
|
||||
)
|
||||
|
||||
NGL_ADD_LIBRARY2(WS PpmOrgChartGuiPlugin MODULE ${participant_org_chart_gui_SRCS} )
|
||||
NGL_TARGET_LINK_LIBRARIES(PpmOrgChartGuiPlugin
|
||||
PRIVATE
|
||||
AsbDataPluginInterface
|
||||
Qt5::Widgets
|
||||
Qt5::WebEngineCore
|
||||
Qt5::WebEngineWidgets
|
||||
LtsSession
|
||||
NGLLogger
|
||||
PUBLIC
|
||||
Qt5::Core
|
||||
nglwidgets
|
||||
svcPpmCommon
|
||||
PpmCommon
|
||||
PpmGuiOrgChartPluginInterface
|
||||
AsbDataPluginInterface
|
||||
advancedSymbology ## BulkRenderer
|
||||
LtsUtilsGuiDds
|
||||
svcCoreClient # Core Ftc - for TLH
|
||||
)
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
#include "combat_power.h"
|
||||
#include "ui_combat_power.h"
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
int CombatPower::s_preselectedParty = -1;
|
||||
|
||||
CombatPower::CombatPower(QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_orgChart(nullptr)
|
||||
, m_dtc(nullptr)
|
||||
, m_asbIfc(nullptr)
|
||||
, m_ppmGuiCbxIfc(nullptr)
|
||||
, m_ppmGuiInfoIfc(nullptr)
|
||||
, m_ui(new Ui::CombatPower)
|
||||
, m_logger(getLogger("CombatPower"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("Situation-Combat_Power"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
CombatPower::~CombatPower()
|
||||
{
|
||||
m_orgChart->setParent(nullptr); //Workaround
|
||||
m_orgChart->deleteLater();
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void CombatPower::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Combat Power"));
|
||||
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty);
|
||||
}
|
||||
|
||||
bool CombatPower::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
||||
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
|
||||
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
|
||||
const std::shared_ptr<ForeignParticipantInfoGuiInterface> &ppmGuiInfoIfc)
|
||||
{
|
||||
if (!dtc || !asbIfc || !ppmGuiCbxIfc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not load all interfaces needed";
|
||||
return false;
|
||||
}
|
||||
m_dtc = dtc;
|
||||
m_asbIfc = asbIfc;
|
||||
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
|
||||
if (ppmGuiInfoIfc)
|
||||
m_ppmGuiInfoIfc = ppmGuiInfoIfc;
|
||||
m_orgChart = new ParticipantManagement::LtsParticipantsOrgChart(this);
|
||||
connect(m_orgChart, &LtsParticipantsOrgChart::startDBClick, this, &CombatPower::onOpenInfo);
|
||||
if (!m_orgChart->init(m_dtc, m_asbIfc))
|
||||
return false;
|
||||
connect(m_dtc.get(), &Interface::Dtc::dynamicParticipantDataChanged, this, &CombatPower::onUpdateDynamicParticipantData, Qt::UniqueConnection);
|
||||
connect(m_dtc.get(), &Interface::Dtc::participantChanged, this, &CombatPower::onUpdateParticipant, Qt::UniqueConnection);
|
||||
connect(m_ui->cbParty,
|
||||
static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
|
||||
this,
|
||||
&CombatPower::onPartyChanged, Qt::UniqueConnection);
|
||||
|
||||
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty);
|
||||
const int idx = m_ui->cbParty->findData(s_preselectedParty);
|
||||
if (idx >= 0)
|
||||
m_ui->cbParty->setCurrentIndex(idx);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Init CombatPower - parties: " << m_ui->cbParty->count();
|
||||
onPartyChanged();
|
||||
m_ui->vLay->addWidget(m_orgChart);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CombatPower::onPartyChanged()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onPartyChanged - parties: " << m_ui->cbParty->count();
|
||||
if (s_preselectedParty == -1)
|
||||
m_ui->cbParty->setCurrentIndex(s_preselectedParty);
|
||||
s_preselectedParty = m_ui->cbParty->currentData().toUInt();
|
||||
if (m_orgChart)
|
||||
m_orgChart->loadParty(m_ui->cbParty->currentData().toInt());
|
||||
}
|
||||
|
||||
void CombatPower::onOpenInfo(int id)
|
||||
{
|
||||
if (m_ppmGuiInfoIfc)
|
||||
m_ppmGuiInfoIfc->showParticipantInfoWindow(id);
|
||||
}
|
||||
|
||||
void CombatPower::onUpdateParticipant(const Participant &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onUpdateParticipant - parties: " << m_ui->cbParty->count();
|
||||
if (data.partyId() != m_ui->cbParty->currentData().toInt())
|
||||
return;
|
||||
if (modType == DataModification::eModified)
|
||||
m_orgChart->updateParticipant(data.id());
|
||||
else
|
||||
onPartyChanged();
|
||||
}
|
||||
|
||||
void CombatPower::onUpdateDynamicParticipantData(const DynamicParticipantData &data, DataModification modType)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "onUpdateDynamicParticipantData - parties: " << m_ui->cbParty->count();
|
||||
if (m_dtc->participant(data.participantId()).partyId() != m_ui->cbParty->currentData().toInt())
|
||||
return;
|
||||
if (modType == DataModification::eModified)
|
||||
m_orgChart->updateParticipant(data.participantId());
|
||||
else
|
||||
onPartyChanged();
|
||||
}
|
||||
|
||||
} //namespace ParticipantManagement
|
||||
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Participant Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "participant_org_chart.h"
|
||||
|
||||
#include <ParticipantManagement/logger.h>
|
||||
#include <Services/ParticipantManagement/ppm_dtc.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_participant_info_gui_plugin_interface.h>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class CombatPower;
|
||||
}
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class CombatPower : public LtsWidgets::LtsDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit CombatPower(QWidget *parent = nullptr);
|
||||
~CombatPower();
|
||||
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc
|
||||
, const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc
|
||||
, const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc
|
||||
, const std::shared_ptr<ForeignParticipantInfoGuiInterface> &ppmGuiInfoIfc);
|
||||
|
||||
private slots:
|
||||
void onPartyChanged();
|
||||
void onOpenInfo(int id);
|
||||
void onUpdateDynamicParticipantData(const ParticipantManagement::DynamicParticipantData &data, DataModification modType);
|
||||
void onUpdateParticipant(const Participant &data, DataModification modType);
|
||||
|
||||
private:
|
||||
void retranslate() override;
|
||||
|
||||
ParticipantManagement::LtsParticipantsOrgChart *m_orgChart;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignParticipantInfoGuiInterface> m_ppmGuiInfoIfc;
|
||||
|
||||
static int s_preselectedParty;
|
||||
|
||||
Ui::CombatPower *m_ui;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} //ParticipantManagement
|
||||
@@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>CombatPower</class>
|
||||
<widget class="QWidget" name="CombatPower">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>279</width>
|
||||
<height>248</height>
|
||||
</rect>
|
||||
</property>
|
||||
<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_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="vLay">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblParty">
|
||||
<property name="text">
|
||||
<string>Party:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LtsWidgets::LtsComboBox" name="cbParty"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LtsWidgets::LtsComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>LtsWidgets/lts_combo_box.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+783
@@ -0,0 +1,783 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
#include "org_chart_main.h"
|
||||
#include "ui_org_chart_main.h"
|
||||
#include <QBuffer>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
#include <ParticipantManagement/ppm_translation.h>
|
||||
#include <LtsUtilsCore/dds_vector.h>
|
||||
#include <LtsWidgets/lts_drag_icon.h>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
#include <Plugins/ParticipantManagement/Gui/Common/participant_edit_item.h>
|
||||
#include <Symbology/symbol_data_to_render_role.h>
|
||||
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
OrgChartMain::OrgChartMain(LtsSession::LtsSession *session
|
||||
, QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
||||
, m_orgChart(nullptr)
|
||||
, m_dtc(nullptr)
|
||||
, m_ftc(nullptr)
|
||||
, m_asbIfc(nullptr)
|
||||
, m_ppmGuiCbxIfc(nullptr)
|
||||
, m_ppmGuiInfoIfc(nullptr)
|
||||
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
||||
, m_session(session)
|
||||
, m_useSymData(true)
|
||||
, m_asSupportService(false)
|
||||
, m_isTemplate(false)
|
||||
, m_party(-1)
|
||||
, m_ui(new Ui::OrgChartMain)
|
||||
, m_logger(getLogger("OrgChartMain"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Close)->hide();
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Load, this, &OrgChartMain::onReload);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Load)->setText(tr("Reset"));
|
||||
|
||||
setOnlineHelpFilename(QStringLiteral("Organisation_Chart"));
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
OrgChartMain::~OrgChartMain()
|
||||
{
|
||||
m_topicLockHanderData.disconnect();
|
||||
|
||||
m_orgChart->setParent(nullptr); //Workaround
|
||||
m_orgChart->deleteLater();
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void OrgChartMain::retranslate()
|
||||
{
|
||||
translate(m_ui, tr("Organisation Edit"));
|
||||
fillComboBoxes();
|
||||
}
|
||||
|
||||
void OrgChartMain::fillComboBoxes()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
if (!m_isTemplate)
|
||||
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty);
|
||||
|
||||
DEBUG_LOG(m_logger) << "Init OrgChartMain - parties: " << m_ui->cbParty->count() << " is template? " << m_isTemplate;
|
||||
}
|
||||
|
||||
void OrgChartMain::updateButtonMimeData()
|
||||
{
|
||||
//here we update all buttons according to party
|
||||
int partyId = -1;
|
||||
if (!m_asSupportService && m_ui->cbParty->isVisible())
|
||||
partyId = m_ui->cbParty->currentData().toInt();
|
||||
|
||||
QMapIterator<LtsWidgets::LtsDragIcon *, std::tuple<QString, AdvancedSymbology::SymbolResultWatcher *>> it(m_buttonMap);
|
||||
while (it.hasNext())
|
||||
{
|
||||
it.next();
|
||||
const QString &symbolString = std::get<0>(it.value());
|
||||
AdvancedSymbology::SymbolResultWatcher *symbolWatcher = std::get<1>(it.value());
|
||||
|
||||
|
||||
if (partyId > 0)
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender(symbolString);
|
||||
symDataToRender.role = AdvancedSymbology::roleToRole(m_dtc->party(m_party).role());
|
||||
symDataToRender.fillColor = QColor::fromRgb(QRgb(m_dtc->party(partyId).color()));
|
||||
symDataToRender.fillColorReplace = true;
|
||||
symbolWatcher->setSymbolResult(m_asbIfc->findImage(symDataToRender));
|
||||
}
|
||||
else
|
||||
symbolWatcher->setSymbolResult(m_asbIfc->findBaseSymbol(symbolString));
|
||||
}
|
||||
}
|
||||
|
||||
QColor OrgChartMain::currentPartyColor()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
QColor color = AdvancedSymbology::SymbolDataToRender::unknownColor();
|
||||
|
||||
int partyId = -1;
|
||||
if (!m_asSupportService && m_ui->cbParty->isVisible())
|
||||
partyId = m_ui->cbParty->currentData().toInt();
|
||||
|
||||
if (partyId > 0)
|
||||
color = QColor::fromRgb(QRgb(m_dtc->party(partyId).color()));
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " color=" << color.name()
|
||||
<< " (partyId = " << partyId << ")"
|
||||
<< " (m_asSupportService=" << m_asSupportService << ")"
|
||||
<< " (m_ui->cbParty->isVisible()=" << m_ui->cbParty->isVisible() << ")";
|
||||
return color;
|
||||
}
|
||||
|
||||
AdvancedSymbology::Role OrgChartMain::currentPartyRole()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
AdvancedSymbology::Role role = AdvancedSymbology::Role::Unknown;
|
||||
|
||||
int partyId = -1;
|
||||
if (!m_asSupportService && m_ui->cbParty->isVisible())
|
||||
partyId = m_ui->cbParty->currentData().toInt();
|
||||
|
||||
if (partyId > 0)
|
||||
role = AdvancedSymbology::roleToRole<>(m_dtc->party(partyId).role());
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " role=" << role
|
||||
<< " (partyId = " << partyId << ")"
|
||||
<< " (m_asSupportService=" << m_asSupportService << ")"
|
||||
<< " (m_ui->cbParty->isVisible()=" << m_ui->cbParty->isVisible() << ")";
|
||||
return role;
|
||||
}
|
||||
|
||||
bool OrgChartMain::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
|
||||
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
|
||||
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
|
||||
const std::shared_ptr<ForeignParticipantInfoGuiInterface> &ppmGuiInfoIfc,
|
||||
bool useSymData,
|
||||
bool asSupportService,
|
||||
int templateId)
|
||||
{
|
||||
if (!dtc || !ftc || !ppmGuiCbxIfc || !asbIfc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not load all interfaces needed";
|
||||
return false;
|
||||
}
|
||||
m_dtc = dtc;
|
||||
m_ftc = ftc;
|
||||
m_asbIfc = asbIfc;
|
||||
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
|
||||
m_isTemplate = templateId > 0;
|
||||
m_rootTemplateId = templateId;
|
||||
m_ppmGuiInfoIfc = ppmGuiInfoIfc;
|
||||
m_useSymData = useSymData;
|
||||
m_asSupportService = asSupportService;
|
||||
|
||||
m_orgChart = new ParticipantManagement::LtsParticipantsOrgChart(nullptr);
|
||||
connect(m_orgChart, &LtsParticipantsOrgChart::startDBClick, this, &OrgChartMain::onOpenInfo);
|
||||
connect(m_orgChart, &LtsParticipantsOrgChart::startEdit, this, &OrgChartMain::onEdit);
|
||||
connect(m_orgChart, &LtsParticipantsOrgChart::startDelete, this, &OrgChartMain::onDelete);
|
||||
connect(m_orgChart, &LtsParticipantsOrgChart::gotNewHierarchy, this, &OrgChartMain::onNewHierarchy);
|
||||
connect(m_orgChart, &LtsParticipantsOrgChart::movedParticipant, this, &OrgChartMain::slotChangesMade);
|
||||
|
||||
if (!m_orgChart->init(m_dtc, m_asbIfc, m_useSymData, true, true))
|
||||
return false;
|
||||
connect(m_dtc.get(), &Interface::Dtc::participantChanged, this, &OrgChartMain::onUpdateParticipant, Qt::UniqueConnection);
|
||||
|
||||
initTopicLockHandler();
|
||||
|
||||
m_ui->vLay->addWidget(m_orgChart);
|
||||
if (m_session->partitionType() != IDL::PartitionType::Global)
|
||||
{
|
||||
connect(m_ui->cbParty,
|
||||
static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
|
||||
this,
|
||||
&OrgChartMain::onPartyChanged, Qt::UniqueConnection);
|
||||
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty);
|
||||
DEBUG_LOG(m_logger) << "Init OrgChartMain - parties: " << m_ui->cbParty->count();
|
||||
onPartyChanged();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ui->cbParty->setVisible(false);
|
||||
m_ui->lblParty->setVisible(false);
|
||||
if (m_rootTemplateId > 0)
|
||||
m_orgChart->loadTemplate(m_rootTemplateId);
|
||||
}
|
||||
return initButtons();
|
||||
}
|
||||
|
||||
void OrgChartMain::initTopicLockHandler()
|
||||
{
|
||||
std::shared_ptr<Core::Interface::Ftc> coreFtc;
|
||||
|
||||
if (!m_session->createTopicClient<Core::Interface::Ftc>(coreFtc))
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " create coreFtc failed";
|
||||
return;
|
||||
}
|
||||
coreFtc->enableAll();
|
||||
m_topicLockHanderData.m_debugName = QStringLiteral("TlhOrgChart");
|
||||
m_topicLockHanderData.init(coreFtc, m_session->exerciseId());
|
||||
connect(&m_topicLockHanderData, &LtsSession::TopicLockHanderData::lockDataChanged,
|
||||
this, &OrgChartMain::onLockDataChanged, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
void OrgChartMain::onLockDataChanged()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
m_ui->cbParty->setEnabled(true);
|
||||
|
||||
// update LtsDialog::m_topicLockedBy
|
||||
m_topicLockedBy = m_topicLockHanderData.getLockedBy();
|
||||
|
||||
|
||||
if (m_topicLockedBy.isEmpty())
|
||||
{
|
||||
// not locked by another -> READ-WRITE
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " READ-WRITE";
|
||||
setUnchangeable(false);
|
||||
m_orgChart->setDisabled(false);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// locked by another -> READ-ONLY
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " READ-ONLY";
|
||||
|
||||
setUnchangeable(true);
|
||||
m_orgChart->setDisabled(true);
|
||||
}
|
||||
|
||||
retranslate(); // to update ButtonBox
|
||||
}
|
||||
|
||||
|
||||
bool OrgChartMain::loadTemplate(int templateRootId, bool isSupport)
|
||||
{
|
||||
if (!m_orgChart)
|
||||
return false;
|
||||
m_isTemplate = templateRootId > 0;
|
||||
m_rootTemplateId = templateRootId;
|
||||
m_asSupportService = isSupport;
|
||||
initButtons();
|
||||
m_ui->cbParty->setVisible(false);
|
||||
m_ui->lblParty->setVisible(false);
|
||||
return m_orgChart->loadTemplate(m_rootTemplateId);
|
||||
}
|
||||
|
||||
bool OrgChartMain::initButtons()
|
||||
{
|
||||
for (auto it = m_buttonMap.begin(); it != m_buttonMap.end(); ++it)
|
||||
{
|
||||
LtsWidgets::LtsDragIcon *icon = it.key();
|
||||
|
||||
std::tuple<QString, AdvancedSymbology::SymbolResultWatcher *> tup = it.value();
|
||||
std::get<1>(tup)->deleteLater();
|
||||
m_session->removeMenuAction(icon);
|
||||
icon->deleteLater();
|
||||
|
||||
}
|
||||
m_buttonMap.clear();
|
||||
|
||||
//now create new ones
|
||||
LtsWidgets::PluginData plAction;
|
||||
plAction.layoutArea = LtsWidgets::LayoutArea::eUnknown;
|
||||
//plAction.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
|
||||
|
||||
const QMap<qint32, Type> mapTypes = m_dtc->types();
|
||||
for (const Type &type : mapTypes)
|
||||
{
|
||||
if ((!m_asSupportService && (type.typeClass() == TypeClass::SupportUnit || type.typeClass() == TypeClass::SupportEntity))
|
||||
|| (m_asSupportService && (type.typeClass() != TypeClass::SupportUnit && type.typeClass() != TypeClass::SupportEntity)))
|
||||
continue;
|
||||
plAction.menuGroup = ParticipantManagement::toString(type.typeClass());
|
||||
plAction.identifier = QString::fromStdString(type.name()) + QString::number(type.equipmentTypeId());
|
||||
plAction.menuText = QString::fromStdString(type.name());
|
||||
plAction.directFunc = [](const LtsWidgets::PluginData &) { return; };
|
||||
|
||||
LtsWidgets::LtsDragIcon *icon = m_session->addAction(plAction);
|
||||
if (!icon)
|
||||
continue;
|
||||
//connect to drop
|
||||
//connect(icon, &LtsWidgets::LtsDragIcon::dropSuccesfull, this, &OrgChartMain::slotChangesMade);
|
||||
connect(icon, &LtsWidgets::LtsDragIcon::dropSuc, this , &OrgChartMain::slotChangesMade);
|
||||
AdvancedSymbology::SymbolResultWatcherQWidgetBase *symbolWatcher =
|
||||
new AdvancedSymbology::SymbolResultWatcherQWidget<LtsWidgets::LtsDragIcon>(icon); // icon serves as parent, QSize(45,45)
|
||||
|
||||
|
||||
//now add a symbolwatcher for mimeDataIcons
|
||||
AdvancedSymbology::SymbolResultWatcher *mimeDataSymbolWatcher = new AdvancedSymbology::SymbolResultWatcher(this);
|
||||
connect(mimeDataSymbolWatcher, &AdvancedSymbology::SymbolResultWatcher::resultReady,
|
||||
mimeDataSymbolWatcher, [this, icon, type, mimeDataSymbolWatcher]()
|
||||
{
|
||||
if (mimeDataSymbolWatcher->symbolResult())
|
||||
{
|
||||
QImage imgCopy = mimeDataSymbolWatcher->symbolResult()->symbolImage().image();
|
||||
imgCopy = imgCopy.scaled(QSize(45, 45), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
icon->addMimeData(QStringLiteral("text/plain"), getMimeData(type, imgCopy));
|
||||
}
|
||||
});
|
||||
|
||||
QString symbolString = QString::fromStdString(type.symbol());
|
||||
symbolWatcher->setSymbolResult(m_asbIfc->findPreview(symbolString));
|
||||
m_buttonMap.insert(icon, std::tuple<QString, AdvancedSymbology::SymbolResultWatcher *>(symbolString, mimeDataSymbolWatcher));
|
||||
}
|
||||
|
||||
//now ad Templates
|
||||
|
||||
//change Group
|
||||
plAction.menuGroup = tr("Templates");
|
||||
|
||||
QVector<ParticipantManagement::TemplateParticipant> templates;
|
||||
m_dtc->rootTemplates(templates);
|
||||
if (templates.isEmpty())
|
||||
return true;
|
||||
for (const ParticipantManagement::TemplateParticipant &templateData : qAsConst(templates))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " templateId = " << templateData.templateId()
|
||||
<< " typeId = " << templateData.typeId()
|
||||
<< " designator= " << templateData.designator().c_str()
|
||||
<< " tactIdent= " << templateData.tacticalIdentifier().c_str();
|
||||
|
||||
const Type &type = m_dtc->type(templateData.typeId());
|
||||
const TypeClass &tc = type.typeClass();
|
||||
if ((m_asSupportService &&
|
||||
(tc == TypeClass::SupportEntity || tc == TypeClass::SupportUnit)) //ifSupport only add Support Entities
|
||||
||
|
||||
(!m_asSupportService &&
|
||||
(tc != TypeClass::SupportEntity) &&
|
||||
(tc != TypeClass::SupportUnit))) //if not support NO Support Entities
|
||||
{
|
||||
//normaly only units but well we are RME
|
||||
|
||||
plAction.identifier = QString::fromStdString(templateData.designator()) + QString::number(templateData.templateId());
|
||||
QString templateText = QString::fromStdString(templateData.designator());
|
||||
if (!templateText.isEmpty() && templateData.tacticalIdentifier().size() > 0)
|
||||
templateText.append(QStringLiteral(" / "));
|
||||
templateText.append(QString::fromStdString(templateData.tacticalIdentifier()));
|
||||
|
||||
plAction.menuText = templateText;
|
||||
plAction.directFunc = [](const LtsWidgets::PluginData &) { return; };
|
||||
|
||||
const int templateId = templateData.templateId();
|
||||
LtsWidgets::LtsDragIcon *icon = m_session->addAction(plAction);
|
||||
|
||||
// render icon of LtsDragIcon
|
||||
AdvancedSymbology::SymbolResultWatcherQWidgetBase *symbolWatcher =
|
||||
new AdvancedSymbology::SymbolResultWatcherQWidget<LtsWidgets::LtsDragIcon>(icon); // icon serves as parent
|
||||
QString symbolString = QString::fromStdString(type.symbol());
|
||||
symbolWatcher->setSymbolResult(m_asbIfc->findPreview(symbolString));
|
||||
|
||||
|
||||
// render mimeData of LtsDragIcon
|
||||
OrgChartMain_MimeDataHelper *mimeDataHelper = new OrgChartMain_MimeDataHelper(icon); // icon serves as parent
|
||||
m_templateMimeDataHelpers[icon] = mimeDataHelper;
|
||||
if (!mimeDataHelper->init(icon, templateId, m_dtc, AdvancedSymbology::SymbolDictionary::defaultSymbologyType()))
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " init failed"
|
||||
<< " (m_ui->cbParty->isVisible() " << m_ui->cbParty->isVisible() << ")";
|
||||
continue;
|
||||
}
|
||||
|
||||
//const QColor &col = currentPartyColor();
|
||||
// The visibility is not reliable at this moment.
|
||||
// So use just:
|
||||
QColor color = AdvancedSymbology::SymbolDataToRender::unknownColor();
|
||||
AdvancedSymbology::Role role = AdvancedSymbology::Role::Unknown;
|
||||
if (!m_asSupportService)
|
||||
{
|
||||
int partyId = m_ui->cbParty->currentData().toInt();
|
||||
if (partyId > 0)
|
||||
{
|
||||
color = QColor::fromRgb(QRgb(m_dtc->party(partyId).color()));
|
||||
role = AdvancedSymbology::roleToRole<>(m_dtc->party(partyId).role());
|
||||
}
|
||||
}
|
||||
mimeDataHelper->run(role, color);
|
||||
|
||||
// do not insert into m_buttonMap :-)
|
||||
|
||||
}
|
||||
}
|
||||
updateButtonMimeData();
|
||||
return true;
|
||||
}
|
||||
|
||||
QByteArray OrgChartMain::getMimeData(const Type &type, const QImage &image)
|
||||
{
|
||||
QJsonObject retObj;
|
||||
QString isUnit = (type.typeClass() == ParticipantManagement::TypeClass::Unit
|
||||
|| type.typeClass() == ParticipantManagement::TypeClass::SupportUnit)
|
||||
? QStringLiteral("true") : QString();
|
||||
|
||||
retObj.insert(QStringLiteral("name"), QString::fromStdString(type.name()));
|
||||
retObj.insert(QStringLiteral("title"), QString::fromStdString(type.name()));
|
||||
retObj.insert(QStringLiteral("typeId"), type.id());
|
||||
retObj.insert(QStringLiteral("symbol"), QString::fromStdString(type.symbol()));
|
||||
retObj.insert(QStringLiteral("eqNr"), 0);
|
||||
retObj.insert(QStringLiteral("info"), QString());
|
||||
retObj.insert(QStringLiteral("sign"), QString());
|
||||
retObj.insert(QStringLiteral("tactIdentifier"), QString::fromStdString(type.name()));
|
||||
retObj.insert(QStringLiteral("designator"), QString());
|
||||
retObj.insert(QStringLiteral("isUnit"), isUnit);
|
||||
retObj.insert(QStringLiteral("ddsId"), 0);
|
||||
retObj.insert(QStringLiteral("id"), -1);
|
||||
retObj.insert(QStringLiteral("assignState"), -1);
|
||||
|
||||
//addImage!
|
||||
if (!image.isNull())
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
image.save(&buffer, "PNG", 100);
|
||||
QString imageAdd = QStringLiteral("<img src=\"data:image/png;base64,%1\">").arg(QString::fromLatin1(data.toBase64()));
|
||||
retObj.insert(QStringLiteral("image"), imageAdd);
|
||||
}
|
||||
|
||||
return QJsonDocument(retObj).toJson();
|
||||
}
|
||||
|
||||
QVector<ParticipantData> OrgChartMain::getDataOf(const QJsonObject &obj, int superiorModId, int hierarchyNr)
|
||||
{
|
||||
QVector<ParticipantData> ret;
|
||||
ParticipantData pData;
|
||||
pData.designator() = obj.value(QStringLiteral("designator")).toString().toStdString();
|
||||
if (obj.value(QStringLiteral("eqNr")).toInt() > 0)
|
||||
pData.equipmentNumber().set(obj.value(QStringLiteral("eqNr")).toInt());
|
||||
//pData.hierarchyNumber()
|
||||
pData.info() = obj.value(QStringLiteral("info")).toString().toStdString();
|
||||
pData.name() = obj.value(QStringLiteral("sign")).toString().toStdString();
|
||||
pData.modId(obj.value(QStringLiteral("id")).toInt());
|
||||
pData.id(obj.value(QStringLiteral("ddsId")).toInt() < 0 ? 0 : obj.value(QStringLiteral("ddsId")).toInt());
|
||||
pData.partyId(m_party);
|
||||
pData.superiorModId(superiorModId);
|
||||
pData.hierarchyNumber(hierarchyNr);
|
||||
pData.symbol() = obj.value(QStringLiteral("symbol")).toString().toStdString();
|
||||
pData.tacticalIdentifier() = obj.value(QStringLiteral("tactIdentifier")).toString().toStdString();
|
||||
pData.typeId(obj.value(QStringLiteral("typeId")).toInt());
|
||||
if (obj.value(QStringLiteral("assignState")).toInt() >= 0)
|
||||
pData.assignState(static_cast<ParticipantAssignState_def::type>(obj.value(QStringLiteral("assignState")).toInt()));
|
||||
QJsonArray arr = obj.value(QStringLiteral("children")).toArray();
|
||||
int hierarNr = 1;
|
||||
for (auto arrItem = arr.constBegin(); arrItem != arr.constEnd(); ++arrItem)
|
||||
{
|
||||
ret.append(getDataOf((*arrItem).toObject(), pData.modId(), hierarNr));
|
||||
hierarNr++;
|
||||
}
|
||||
ret.append(pData);
|
||||
return ret;
|
||||
}
|
||||
|
||||
QVector<TemplateData> OrgChartMain::getTemplateDataOf(const QJsonObject &obj, int superiorModId, int hierarchyNr)
|
||||
{
|
||||
QVector<TemplateData> ret;
|
||||
TemplateData tData;
|
||||
tData.designator() = obj.value(QStringLiteral("designator")).toString().toStdString();
|
||||
tData.equipmentNumber(obj.value(QStringLiteral("eqNr")).toInt());
|
||||
//pData.hierarchyNumber()
|
||||
tData.info() = obj.value(QStringLiteral("info")).toString().toStdString();
|
||||
tData.name() = obj.value(QStringLiteral("sign")).toString().toStdString();
|
||||
tData.modId(obj.value(QStringLiteral("id")).toInt());
|
||||
if (obj.value(QStringLiteral("ddsId")).toInt() > 0)
|
||||
tData.templateId(obj.value(QStringLiteral("ddsId")).toInt());
|
||||
tData.superiorModId(superiorModId);
|
||||
tData.hierarchyNumber(hierarchyNr);
|
||||
tData.symbol() = obj.value(QStringLiteral("symbol")).toString().toStdString();
|
||||
tData.tacticalIdentifier() = obj.value(QStringLiteral("tactIdentifier")).toString().toStdString();
|
||||
tData.typeId(obj.value(QStringLiteral("typeId")).toInt());
|
||||
QJsonArray arr = obj.value(QStringLiteral("children")).toArray();
|
||||
int hierarNr = 1;
|
||||
for (auto arrItem = arr.constBegin(); arrItem != arr.constEnd(); ++arrItem)
|
||||
{
|
||||
ret.append(getTemplateDataOf((*arrItem).toObject(), tData.modId(), hierarNr));
|
||||
hierarNr++;
|
||||
}
|
||||
ret.append(tData);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
bool OrgChartMain::apply()
|
||||
{
|
||||
m_orgChart->getWholeHierarchy();
|
||||
return true;
|
||||
}
|
||||
|
||||
ParticipantData OrgChartMain::convertFromJson(const QJsonObject &obj)
|
||||
{
|
||||
ParticipantData pData;
|
||||
pData.designator(obj.value(QStringLiteral("designator")).toString().toStdString());
|
||||
pData.tacticalIdentifier(obj.value(QStringLiteral("tactIdentifier")).toString().toStdString());
|
||||
pData.info(obj.value(QStringLiteral("info")).toString().toStdString());
|
||||
pData.equipmentNumber().set(obj.value(QStringLiteral("eqNr")).toInt());
|
||||
pData.typeId(obj.value(QStringLiteral("typeId")).toInt());
|
||||
pData.modId(obj.value(QStringLiteral("ddsId")).toInt());
|
||||
pData.name(obj.value(QStringLiteral("sign")).toString().toStdString());
|
||||
pData.partyId(m_party);
|
||||
pData.id(obj.value(QStringLiteral("ddsId")).toInt());
|
||||
if (obj.value(QStringLiteral("assignState")).toInt() >= 0)
|
||||
pData.assignState(static_cast<ParticipantAssignState_def::type>(obj.value(QStringLiteral("assignState")).toInt()));
|
||||
pData.symbol(obj.value(QStringLiteral("symbol")).toString().toStdString());
|
||||
return pData;
|
||||
}
|
||||
|
||||
TemplateData OrgChartMain::fromParticipantData(const ParticipantData &data)
|
||||
{
|
||||
TemplateData ret;
|
||||
ret.name() = data.name();
|
||||
ret.isDeleted(data.isDeleted());
|
||||
ret.modId(data.modId());
|
||||
ret.superiorModId(data.superiorModId());
|
||||
ret.equipmentNumber(data.hierarchyNumber());
|
||||
ret.info() = data.info();
|
||||
ret.symbol() = data.symbol();
|
||||
ret.tacticalIdentifier() = data.tacticalIdentifier();
|
||||
ret.templateId(ret.modId());
|
||||
ret.typeId(data.typeId());
|
||||
return ret;
|
||||
}
|
||||
|
||||
void OrgChartMain::onPartyChanged()
|
||||
{
|
||||
if (hasUnsavedChanges())
|
||||
{
|
||||
const LtsWidgets::Button btn = askApplyDiscardCancel();
|
||||
switch (btn)
|
||||
{
|
||||
case LtsWidgets::Button::Apply:
|
||||
{
|
||||
apply();
|
||||
__unchange__();
|
||||
Q_FALLTHROUGH();
|
||||
}
|
||||
case LtsWidgets::Button::Cancel:
|
||||
{
|
||||
//reset index
|
||||
QSignalBlocker blk(m_ui->cbParty);
|
||||
m_ui->cbParty->setCurrentIndex(m_ui->cbParty->findData(m_party));
|
||||
return;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
__unchange__();
|
||||
DEBUG_LOG(m_logger) << "onPartyChanged - parties: " << m_ui->cbParty->count();
|
||||
m_party = m_ui->cbParty->currentData().toInt();
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << " OrgChartMain::onPartyChanged()!!! -> newPartyId" << m_party;
|
||||
|
||||
m_ui->cbParty->setEnabled(false); // will be re-enabled with reply (::onLockDataChanged)
|
||||
|
||||
// first unlock old party (if there is already an old, locked party)
|
||||
if (m_topicLockHanderData.isLocked())
|
||||
{
|
||||
m_topicLockHanderData.unlock(); // blocks until reply for request received!
|
||||
}
|
||||
|
||||
// .. then lock another party
|
||||
LtsWidgets::TopicInfo topicInfo;
|
||||
topicInfo.setTopicName(QStringLiteral("LockParty"));
|
||||
topicInfo.setEntity(m_party);
|
||||
topicInfo.setValid();
|
||||
m_topicLockHanderData.slotTryLock(topicInfo); // blocks until reply for request received!
|
||||
|
||||
if (m_orgChart)
|
||||
m_orgChart->loadParty(m_party);
|
||||
|
||||
updateButtonMimeData();
|
||||
|
||||
|
||||
// update mimeData of templates/LtsDragIcons:
|
||||
const QColor &partyColor = currentPartyColor();
|
||||
AdvancedSymbology::Role role = currentPartyRole();
|
||||
for (const auto &helper : qAsConst(m_templateMimeDataHelpers))
|
||||
{
|
||||
if (helper)
|
||||
helper->run(role, partyColor);
|
||||
} // for
|
||||
|
||||
}
|
||||
|
||||
void OrgChartMain::onOpenInfo(int id)
|
||||
{
|
||||
if (m_ppmGuiInfoIfc)
|
||||
m_ppmGuiInfoIfc->showParticipantInfoWindow(id);
|
||||
}
|
||||
|
||||
void OrgChartMain::onEdit(const QString &data)
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8());
|
||||
if (doc.isEmpty() || doc.object().isEmpty())
|
||||
return;
|
||||
|
||||
QJsonObject obj = doc.object();
|
||||
const ParticipantData &pData = convertFromJson(obj);
|
||||
const QString group = tr("Participant Edit");
|
||||
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
|
||||
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
|
||||
ParticipantEditItemTab *tab = new ParticipantEditItemTab(false, m_session, this);
|
||||
if (tab->init(m_dtc, m_ppmGuiCbxIfc, asb, pData, true))
|
||||
{
|
||||
m_session->addWidget(tab,
|
||||
group,
|
||||
QStringLiteral("Edit %1").arg(pData.modId()),
|
||||
LtsWidgets::LayoutArea::eDialogTab);
|
||||
connect(tab, &ParticipantEditItemTab::updateItem, this, &OrgChartMain::onUpdateItem);
|
||||
}
|
||||
else
|
||||
tab->deleteLater();
|
||||
}
|
||||
|
||||
void OrgChartMain::onDelete(const QString &data)
|
||||
{
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8());
|
||||
if (doc.isEmpty() || doc.object().isEmpty())
|
||||
return;
|
||||
QJsonObject obj = doc.object();
|
||||
|
||||
if (obj.value(QStringLiteral("id")).toInt() != obj.value(QStringLiteral("ddsId")).toInt())
|
||||
return;
|
||||
|
||||
ParticipantData pData = convertFromJson(obj);
|
||||
pData.isDeleted(true);
|
||||
if (!m_isTemplate)
|
||||
m_participantsToDelete.append(pData);
|
||||
else
|
||||
m_templateParticipantsToDelete.append(fromParticipantData((pData)));
|
||||
slotChangesMade();
|
||||
|
||||
}
|
||||
|
||||
void OrgChartMain::onUpdateItem(const QModelIndex &parent, const ParticipantData &editData)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
Q_UNUSED(parent);
|
||||
//now build json object
|
||||
QJsonObject obj;
|
||||
Type type = m_dtc->type(editData.typeId());
|
||||
|
||||
QString isUnit = (type.typeClass() == ParticipantManagement::TypeClass::Unit
|
||||
|| type.typeClass() == ParticipantManagement::TypeClass::SupportUnit)
|
||||
? QStringLiteral("true") : QString();
|
||||
|
||||
QString name = QString::fromStdString(editData.designator()) + QLatin1Char(' ') + QString::fromStdString(editData.tacticalIdentifier());
|
||||
obj.insert(QStringLiteral("name"), name);
|
||||
obj.insert(QStringLiteral("designator"), QString::fromStdString(editData.designator()));
|
||||
obj.insert(QStringLiteral("tactIdentifier"), QString::fromStdString(editData.tacticalIdentifier()));
|
||||
obj.insert(QStringLiteral("info"), QString::fromStdString(editData.info()));
|
||||
obj.insert(QStringLiteral("sign"), QString::fromStdString(editData.name()));
|
||||
obj.insert(QStringLiteral("title"), QString::fromStdString(type.name()));
|
||||
obj.insert(QStringLiteral("typeId"), editData.typeId());
|
||||
obj.insert(QStringLiteral("symbol"), QString::fromStdString(editData.symbol()));
|
||||
obj.insert(QStringLiteral("eqNr"), editData.equipmentNumber().is_set() ? editData.equipmentNumber().get() : 0);
|
||||
obj.insert(QStringLiteral("isUnit"), isUnit);
|
||||
obj.insert(QStringLiteral("assignState"), editData.assignState().underlying());
|
||||
obj.insert(QStringLiteral("ddsId"), editData.id());
|
||||
obj.insert(QStringLiteral("id"), editData.modId());
|
||||
|
||||
|
||||
// SymbolResultWatcher:
|
||||
AdvancedSymbology::SymbolResultWatcher *watcher = new AdvancedSymbology::SymbolResultWatcher(this);
|
||||
|
||||
connect(watcher, &AdvancedSymbology::SymbolResultWatcher::resultReady,
|
||||
watcher, [this, watcher, obj, editData]() mutable
|
||||
{
|
||||
if (watcher->symbolResult())
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
QImage image = watcher->symbolResult()->symbolImage().image();
|
||||
image = image.scaled(QSize(45, 45), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
image.save(&buffer, "PNG", 100);
|
||||
QString imageAdd = QStringLiteral("<img src=\"data:image/png;base64,%1\">")
|
||||
.arg(QString::fromLatin1(data.toBase64()));
|
||||
obj.insert(QStringLiteral("image"), imageAdd);
|
||||
m_orgChart->sendToOrgChart(editData.modId(), obj);
|
||||
slotChangesMade();
|
||||
}
|
||||
});
|
||||
|
||||
if (m_ui->cbParty->isVisible())
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender(QString::fromStdString(editData.symbol()));
|
||||
symDataToRender.role = AdvancedSymbology::roleToRole(m_dtc->party(m_party).role());
|
||||
symDataToRender.fillColor = QColor::fromRgb(QRgb(m_dtc->party(m_party).color()));
|
||||
symDataToRender.fillColorReplace = true;
|
||||
watcher->setSymbolResult(m_asbIfc->findImage(symDataToRender));
|
||||
}
|
||||
else
|
||||
watcher->setSymbolResult(m_asbIfc->findBaseSymbol(QString::fromStdString(editData.symbol())));
|
||||
}
|
||||
|
||||
void OrgChartMain::onNewHierarchy(const QString &data)
|
||||
{
|
||||
//do the magic here
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8());
|
||||
//qWarning() << data;
|
||||
if (doc.object().isEmpty())
|
||||
return;
|
||||
|
||||
if (!m_isTemplate)
|
||||
{
|
||||
QVector<ParticipantData> sendTo = getDataOf(doc.object(), 0, 1);
|
||||
sendTo.append(m_participantsToDelete);
|
||||
if (sendTo.isEmpty())
|
||||
return;
|
||||
|
||||
ModifyParticipantDataRequest req;
|
||||
LtsUtils::convert(sendTo, req.data());
|
||||
m_requestHelper->addRequest([this, req]()
|
||||
{
|
||||
return m_ftc->modifyParticipantDataRequest(req, this);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
QVector<TemplateData> sendTo = getTemplateDataOf(doc.object(), 0, 1);
|
||||
sendTo.append(m_templateParticipantsToDelete);
|
||||
if (sendTo.isEmpty())
|
||||
return;
|
||||
|
||||
ModifyTemplateDataRequest req;
|
||||
LtsUtils::convert(sendTo, req.data());
|
||||
m_requestHelper->addRequest([this, req]()
|
||||
{
|
||||
return m_ftc->modifyTemplateDataRequest(req, this);
|
||||
});
|
||||
}
|
||||
|
||||
if (!m_requestHelper->startRequests())
|
||||
{
|
||||
slotChangesMade();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
void OrgChartMain::onReload()
|
||||
{
|
||||
if (m_ui->cbParty->isVisible())
|
||||
{
|
||||
if (m_orgChart)
|
||||
m_orgChart->loadParty(m_party);
|
||||
}else
|
||||
{
|
||||
if (m_orgChart)
|
||||
m_orgChart->loadTemplate(m_rootTemplateId);
|
||||
}
|
||||
__unchange__();
|
||||
|
||||
}
|
||||
|
||||
void OrgChartMain::onUpdateParticipant(const Participant &data, DataModification modType)
|
||||
{
|
||||
if (data.partyId() != m_party)
|
||||
return;
|
||||
if (modType == DataModification::eModified)
|
||||
m_orgChart->updateParticipant(data.id());
|
||||
else
|
||||
onPartyChanged();
|
||||
}
|
||||
|
||||
} //namespace ParticipantManagement
|
||||
+120
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Participant Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "participant_org_chart.h"
|
||||
#include "org_chart_main_helper.h"
|
||||
|
||||
#include <ParticipantManagement/logger.h>
|
||||
#include <Services/ParticipantManagement/ppm_dtc.h>
|
||||
#include <Services/ParticipantManagement/ppm_ftc.h>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_participant_info_gui_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_participants_gui_plugin_interface.h>
|
||||
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsSession/lts_session_lock_handler.h>
|
||||
#include <LtsUtilsGuiDds/request_helper.h>
|
||||
|
||||
#include <QPointer>
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class OrgChartMain;
|
||||
}
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class OrgChartMain : public LtsWidgets::LtsDialog
|
||||
, protected ParticipantManagement::Interface::Ftc::ModifyParticipantDataReplyHandler
|
||||
, protected ParticipantManagement::Interface::Ftc::ModifyTemplateDataReplyHandler
|
||||
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OrgChartMain(LtsSession::LtsSession *session
|
||||
, QWidget *parent = nullptr);
|
||||
~OrgChartMain();
|
||||
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc
|
||||
, const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc
|
||||
, const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc
|
||||
, const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc
|
||||
, const std::shared_ptr<ForeignParticipantInfoGuiInterface> &ppmGuiInfoIfc
|
||||
, bool useSymData = true
|
||||
, bool asSupportService = false
|
||||
, int templateId = -1);
|
||||
void initTopicLockHandler();
|
||||
|
||||
void onModifyParticipantDataReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
void onModifyTemplateDataReply(const Core::FunctionReplyObject &replyObject) override final { m_requestHelper->requestReply(replyObject); }
|
||||
bool loadTemplate(int templateRootId, bool isSupport = false);
|
||||
|
||||
private:
|
||||
void retranslate() override;
|
||||
bool initButtons();
|
||||
QByteArray getMimeData(const Type &type, const QImage &image);
|
||||
QVector<ParticipantData> getDataOf(const QJsonObject &obj, int superiorModId, int hierarchyNr);
|
||||
QVector<TemplateData> getTemplateDataOf(const QJsonObject &obj, int superiorModId, int hierarchyNr);
|
||||
bool apply() override;
|
||||
ParticipantData convertFromJson(const QJsonObject &obj);
|
||||
TemplateData fromParticipantData(const ParticipantData &data);
|
||||
void fillComboBoxes();
|
||||
void updateButtonMimeData();
|
||||
QColor currentPartyColor();
|
||||
AdvancedSymbology::Role currentPartyRole();
|
||||
|
||||
private slots:
|
||||
void onPartyChanged();
|
||||
void onOpenInfo(int id);
|
||||
void onEdit(const QString &data);
|
||||
void onDelete(const QString &data);
|
||||
void onUpdateItem(const QModelIndex &parent, const ParticipantData &editData);
|
||||
void onNewHierarchy(const QString &data);
|
||||
void onReload();
|
||||
|
||||
void onUpdateParticipant(const Participant &data, DataModification modType);
|
||||
void onLockDataChanged();
|
||||
|
||||
private:
|
||||
ParticipantManagement::LtsParticipantsOrgChart *m_orgChart;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignParticipantInfoGuiInterface> m_ppmGuiInfoIfc;
|
||||
|
||||
LtsUtils::RequestHelper *m_requestHelper;
|
||||
LtsSession::LtsSession *m_session;
|
||||
QVector<ParticipantData> m_participantsToDelete;
|
||||
QVector<TemplateData> m_templateParticipantsToDelete;
|
||||
QMap<LtsWidgets::LtsDragIcon *, std::tuple<QString, AdvancedSymbology::SymbolResultWatcher *>> m_buttonMap;
|
||||
|
||||
QMap<QPointer<LtsWidgets::LtsDragIcon>, QPointer<OrgChartMain_MimeDataHelper>> m_templateMimeDataHelpers;
|
||||
|
||||
// global TopicLockHandler does not exists, create our own:
|
||||
LtsSession::TopicLockHanderData m_topicLockHanderData;
|
||||
|
||||
|
||||
bool m_useSymData;
|
||||
bool m_asSupportService;
|
||||
bool m_isTemplate;
|
||||
int m_rootTemplateId;
|
||||
int m_party;
|
||||
Ui::OrgChartMain *m_ui;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} //ParticipantManagement
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>OrgChartMain</class>
|
||||
<widget class="QWidget" name="OrgChartMain">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>279</width>
|
||||
<height>248</height>
|
||||
</rect>
|
||||
</property>
|
||||
<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_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="vLay">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="layout">
|
||||
<item>
|
||||
<widget class="QLabel" name="lblParty">
|
||||
<property name="text">
|
||||
<string>Party:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LtsWidgets::LtsComboBox" name="cbParty">
|
||||
<property name="const" stdset="0">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LtsWidgets::LtsComboBox</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>LtsWidgets/lts_combo_box.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
+215
@@ -0,0 +1,215 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
#include "org_chart_main_helper.h"
|
||||
|
||||
#include <QBuffer>
|
||||
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
OrgChartMain_MimeDataHelper::OrgChartMain_MimeDataHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_logger(getLogger("OrgChartMain_MimeDataHelper"))
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
OrgChartMain_MimeDataHelper::~OrgChartMain_MimeDataHelper()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
|
||||
delete m_bulkRendererFindImage;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
bool OrgChartMain_MimeDataHelper::init(LtsWidgets::LtsDragIcon *widget,
|
||||
int templateId,
|
||||
const std::shared_ptr<Interface::Dtc> &dtc,
|
||||
AdvancedSymbology::SymbologyType symbologyType)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
|
||||
|
||||
m_templateId = templateId;
|
||||
m_symbologyType = symbologyType;
|
||||
|
||||
if (!widget)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << "no widget";
|
||||
return false;
|
||||
}
|
||||
m_widget = widget;
|
||||
|
||||
|
||||
if (!dtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not load all interfaces needed";
|
||||
return false;
|
||||
}
|
||||
m_dtc = dtc;
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
return true;
|
||||
}
|
||||
|
||||
void OrgChartMain_MimeDataHelper::run(AdvancedSymbology::Role role, const QColor &color)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START"
|
||||
<< " m_symbologyType = " << m_symbologyType
|
||||
<< " role = " << role
|
||||
<< " color = " << color.name();
|
||||
|
||||
m_role = role;
|
||||
m_color = color;
|
||||
|
||||
if (!m_dtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not load all interfaces needed";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_widget)
|
||||
m_widget->setDisabled(true);
|
||||
|
||||
|
||||
delete m_bulkRendererFindImage;
|
||||
m_bulkRendererFindImage = new AdvancedSymbology::BulkRendererFindImage(m_symbologyType);
|
||||
|
||||
connect(m_bulkRendererFindImage, &AdvancedSymbology::BulkRendererFindImage::resultsReady,
|
||||
this, &OrgChartMain_MimeDataHelper::onRenderingFinished, Qt::UniqueConnection);
|
||||
|
||||
prepareBulkRenderer(m_templateId);
|
||||
|
||||
m_bulkRendererFindImage->run();
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
void OrgChartMain_MimeDataHelper::prepareBulkRenderer(int templateId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START"
|
||||
<< " templateId= " << templateId;
|
||||
|
||||
const TemplateParticipant &tPart = m_dtc->templateParticipant(templateId);
|
||||
|
||||
const AdvancedSymbology::SymbolDataToRender &symDataToRender =
|
||||
symbolDataToRender(QString::fromStdString(tPart.symbol())); // (was type.symbol())
|
||||
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " addRequest for templateId = " << templateId << ": "
|
||||
<< " tPart = " << tPart
|
||||
<< " symDataToRender=" << symDataToRender.toString();
|
||||
|
||||
m_bulkRendererFindImage->addRequest(symDataToRender);
|
||||
|
||||
//
|
||||
// recursion
|
||||
//
|
||||
if (tPart.inferiorIds().is_set())
|
||||
{
|
||||
const std::vector<int> &inferior = tPart.inferiorIds().get();
|
||||
for (int infId : inferior)
|
||||
prepareBulkRenderer(infId);
|
||||
}
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
QJsonObject OrgChartMain_MimeDataHelper::getMimeData(int templateId)
|
||||
{
|
||||
QJsonObject retObj;
|
||||
|
||||
const TemplateParticipant &tPart = m_dtc->templateParticipant(templateId);
|
||||
const Type &type = m_dtc->type(tPart.typeId());
|
||||
QString isUnit = (type.typeClass() == ParticipantManagement::TypeClass::Unit
|
||||
|| type.typeClass() == ParticipantManagement::TypeClass::SupportUnit)
|
||||
? QLatin1String("true") : QLatin1String("");
|
||||
|
||||
retObj.insert(QLatin1String("name"), QString::fromStdString(tPart.designator()));
|
||||
retObj.insert(QLatin1String("title"), QString::fromStdString(tPart.designator()));
|
||||
retObj.insert(QLatin1String("typeId"), tPart.typeId());
|
||||
retObj.insert(QLatin1String("symbol"), QString::fromStdString(tPart.symbol()));
|
||||
retObj.insert(QLatin1String("eqNr"), 0);
|
||||
retObj.insert(QLatin1String("info"), QString::fromStdString(tPart.info()));
|
||||
retObj.insert(QLatin1String("sign"), QString::fromStdString(tPart.name()));
|
||||
retObj.insert(QLatin1String("tactIdentifier"), QString::fromStdString(tPart.tacticalIdentifier()));
|
||||
retObj.insert(QLatin1String("isUnit"), isUnit);
|
||||
retObj.insert(QLatin1String("ddsId"), -1);
|
||||
retObj.insert(QLatin1String("id"), -1);
|
||||
retObj.insert(QLatin1String("assignState"), -1);
|
||||
|
||||
const AdvancedSymbology::SymbolDataToRender &symDataToRender =
|
||||
symbolDataToRender(QString::fromStdString(tPart.symbol()));
|
||||
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " getResult for templateId = " << templateId
|
||||
<< " symDataToRender=" << symDataToRender.toString();
|
||||
|
||||
QSharedPointer<AdvancedSymbology::SymbolResultWatcher> watcher =
|
||||
m_bulkRendererFindImage->getResult(symDataToRender);
|
||||
if (watcher)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
const AdvancedSymbology::SymbolImage &symbolImage = watcher->symbolResult()->symbolImage();
|
||||
QImage image = symbolImage.image().scaled(QSize(45, 45), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
image.save(&buffer, "PNG", 100);
|
||||
QString imageAdd = QStringLiteral("<img src=\"data:image/png;base64,%1\">")
|
||||
.arg(QString::fromLatin1(data.toBase64()));
|
||||
retObj.insert(QStringLiteral("image"), imageAdd);
|
||||
} else {
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " getResult failed! "
|
||||
<< " templateId = " << templateId
|
||||
<< " symDataToRender=" << symDataToRender.toString();
|
||||
}
|
||||
|
||||
//
|
||||
// recursion (2nd)
|
||||
//
|
||||
if (tPart.inferiorIds().is_set())
|
||||
{
|
||||
QJsonArray arr;
|
||||
|
||||
const std::vector<int> &inferior = tPart.inferiorIds().get();
|
||||
for (int infId : inferior)
|
||||
arr.append(getMimeData(infId));
|
||||
retObj.insert(QLatin1String("children"), arr);
|
||||
}
|
||||
|
||||
return retObj;
|
||||
}
|
||||
|
||||
AdvancedSymbology::SymbolDataToRender OrgChartMain_MimeDataHelper::symbolDataToRender(const QString &sidc)
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender(sidc);
|
||||
symDataToRender.role = m_role;
|
||||
symDataToRender.fillColor = m_color;
|
||||
symDataToRender.fillColorReplace = true;
|
||||
return symDataToRender;
|
||||
}
|
||||
|
||||
void OrgChartMain_MimeDataHelper::onRenderingFinished()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START, bulkRendererFindImage->size: " << m_bulkRendererFindImage->size();
|
||||
|
||||
const QJsonObject &obj = getMimeData(m_templateId);
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " m_templateId =" << m_templateId
|
||||
<< " obj.size = " << obj.size()
|
||||
<< " size2 = " << QJsonDocument(obj).toJson().size();
|
||||
|
||||
if (m_widget)
|
||||
{
|
||||
m_widget->addMimeData(QLatin1String("text/plain"), QJsonDocument(obj).toJson());
|
||||
m_widget->setEnabled(true);
|
||||
}
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
} //namespace ParticipantManagement
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Participant Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Norbert Thoden, SLSE, 2018-02-07
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <ParticipantManagement/logger.h>
|
||||
#include <Services/ParticipantManagement/ppm_dtc.h>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
#include <Symbology/bulk_renderer.h>
|
||||
|
||||
#include <LtsWidgets/lts_drag_icon.h>
|
||||
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonArray>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The OrgChartMain_MimeDataHelper class supports OrgChartMain.
|
||||
* For a templateId the according mimeData is assigned to the given widget.
|
||||
* The widget is disabled while running
|
||||
*
|
||||
* Within run, the BulkRendererFindImage is setup.
|
||||
* Then (prepareBulkRenderer) we are iteration through the tree and addRequests.
|
||||
* After iterating the rendering is triggered.
|
||||
* OnRenderingFinished iterates through the tree again (getMimeData).
|
||||
* Within the mimeData is accumulated and uses the just rendered images.
|
||||
* Finally the complete mimeData (including the images) is set to the widget
|
||||
* and the widget is enabled again.
|
||||
*/
|
||||
class OrgChartMain_MimeDataHelper final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit OrgChartMain_MimeDataHelper(QObject *parent = nullptr);
|
||||
~OrgChartMain_MimeDataHelper();
|
||||
|
||||
bool init(LtsWidgets::LtsDragIcon *widget,
|
||||
int templateId,
|
||||
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
||||
AdvancedSymbology::SymbologyType symbologyType);
|
||||
|
||||
void run(AdvancedSymbology::Role role, const QColor &color);
|
||||
|
||||
|
||||
protected slots:
|
||||
void onRenderingFinished();
|
||||
|
||||
private:
|
||||
void prepareBulkRenderer(int templateId);
|
||||
QJsonObject getMimeData(int templateId);
|
||||
AdvancedSymbology::SymbolDataToRender symbolDataToRender(const QString &sidc);
|
||||
|
||||
LtsWidgets::LtsDragIcon *m_widget = nullptr;
|
||||
int m_templateId = -1;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
|
||||
|
||||
AdvancedSymbology::Role m_role = AdvancedSymbology::Role::Unknown;
|
||||
QColor m_color;
|
||||
AdvancedSymbology::SymbologyType m_symbologyType = AdvancedSymbology::SymbologyType::None;
|
||||
AdvancedSymbology::BulkRendererFindImage *m_bulkRendererFindImage = nullptr;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} //ParticipantManagement
|
||||
+372
@@ -0,0 +1,372 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* HMI Plugin for ParticipantManagement - Participant OrgChart Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
#include "participant_org_chart.h"
|
||||
#include "ui_participant_org_chart.h"
|
||||
#include <QtWebEngineWidgets/QWebEngineSettings>
|
||||
|
||||
#include <Symbology/symbol_data_to_render_role.h>
|
||||
|
||||
#include <QFile>
|
||||
#include <QtWebEngine/QtWebEngine>
|
||||
#include <QtWebEngineWidgets/QWebEnginePage>
|
||||
#include <QJsonArray>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
inline bool compareState(const StateInformation &a,
|
||||
const StateInformation &b)
|
||||
{
|
||||
if (a.stateTime() != b.stateTime())
|
||||
return a.stateTime() < b.stateTime();
|
||||
return a.vulnerabilityState() < b.vulnerabilityState();
|
||||
}
|
||||
|
||||
LtsParticipantsOrgChart::LtsParticipantsOrgChart(QWidget *parent)
|
||||
: QWidget(parent)
|
||||
, m_partyId(-1)
|
||||
, m_useSymData(true)
|
||||
, m_isMenuEnabled(false)
|
||||
, m_isDragEnabled(false)
|
||||
, m_channel(nullptr)
|
||||
, m_notifier(nullptr)
|
||||
, m_dtc(nullptr)
|
||||
, m_asbItc(nullptr)
|
||||
, m_ui(new Ui::LtsParticipantsOrgChart)
|
||||
, m_logger(getLogger("LtsParticipantsOrgChart"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
}
|
||||
|
||||
LtsParticipantsOrgChart::~LtsParticipantsOrgChart()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
bool LtsParticipantsOrgChart::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc
|
||||
, const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc
|
||||
, bool useSymData
|
||||
, bool isMenuEnabled
|
||||
, bool isDragEnabled)
|
||||
{
|
||||
if (!dtc || !asbIfc)
|
||||
return false;
|
||||
|
||||
m_dtc = dtc;
|
||||
m_asbItc = asbIfc;
|
||||
m_useSymData = useSymData;
|
||||
m_isMenuEnabled = isMenuEnabled;
|
||||
m_isDragEnabled = isDragEnabled;
|
||||
|
||||
m_channel = new QWebChannel(this);
|
||||
m_notifier = new WebNofitifier(this);
|
||||
connect(m_notifier, &WebNofitifier::edit, this, &LtsParticipantsOrgChart::startEdit);
|
||||
connect(m_notifier, &WebNofitifier::remove, this, &LtsParticipantsOrgChart::startDelete);
|
||||
connect(m_notifier, &WebNofitifier::dbClick, this, &LtsParticipantsOrgChart::startDBClick);
|
||||
connect(m_notifier, &WebNofitifier::movedParticipant, this, &LtsParticipantsOrgChart::movedParticipant);
|
||||
connect(m_notifier, &WebNofitifier::newHierarchy, this, &LtsParticipantsOrgChart::gotNewHierarchy);
|
||||
connect(this, &LtsParticipantsOrgChart::sendUpdateString, m_notifier, &WebNofitifier::onSetUpdateString, Qt::QueuedConnection);
|
||||
|
||||
m_ui->wevOrgChart->setAcceptDrops(true);
|
||||
m_ui->wevOrgChart->page()->settings()->setAttribute(QWebEngineSettings::JavascriptEnabled, true);
|
||||
m_ui->wevOrgChart->page()->settings()->setAttribute(QWebEngineSettings::LocalStorageEnabled, true);
|
||||
m_ui->wevOrgChart->page()->settings()->setAttribute(QWebEngineSettings::JavascriptCanAccessClipboard, true);
|
||||
m_ui->wevOrgChart->page()->settings()->setAttribute(QWebEngineSettings::LocalContentCanAccessFileUrls, true);
|
||||
m_ui->wevOrgChart->page()->settings()->setAttribute(QWebEngineSettings::JavascriptCanOpenWindows, true);
|
||||
|
||||
auto readFiles = { QLatin1String(":/jquery-3.1.0.min.js"),
|
||||
QLatin1String(":/qwebchannel.js"),
|
||||
QLatin1String(":/jquery.orgchart.js"),
|
||||
QLatin1String(":/scripts.js") };
|
||||
QFile readFile;
|
||||
//start with loading files.
|
||||
for (const auto &file : readFiles)
|
||||
{
|
||||
readFile.setFileName(file);
|
||||
if (!readFile.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
m_scriptString.append(QString::fromUtf8(readFile.readAll()));
|
||||
readFile.close();
|
||||
}
|
||||
//Now we read the basic html file
|
||||
readFile.setFileName(QLatin1String(":/start.html"));
|
||||
if (!readFile.open(QIODevice::ReadOnly))
|
||||
return false;
|
||||
|
||||
m_html.append(QString::fromUtf8(readFile.readAll()));
|
||||
readFile.close();
|
||||
|
||||
//so now load orgFrom Dtc
|
||||
//loadParty(partyId);
|
||||
m_ui->wevOrgChart->page()->setWebChannel(m_channel);
|
||||
|
||||
connect(m_ui->wevOrgChart, &QWebEngineView::loadFinished, this, [=](bool suc)
|
||||
{
|
||||
|
||||
QString url = m_ui->wevOrgChart->page()->url().toString();
|
||||
|
||||
if (url == QLatin1String("about:blank"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (suc)
|
||||
{
|
||||
//if (m_ui->wevOrgChart->page()->findText(QLatin1String() );
|
||||
// return;
|
||||
if (m_dataSource.size() > 10)
|
||||
m_ui->wevOrgChart->page()->runJavaScript(m_dataSource + m_scriptString);
|
||||
}
|
||||
|
||||
});
|
||||
m_channel->registerObject(QLatin1String("webNotifier"), m_notifier);
|
||||
m_notifier->setJsonString(QLatin1String("test"));
|
||||
|
||||
|
||||
m_ui->wevOrgChart->page()->setHtml(m_html);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LtsParticipantsOrgChart::loadParty(int partyId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << "loadParty " << partyId;
|
||||
m_partyId = partyId;
|
||||
const QMap<qint32, ParticipantManagement::Participant> participantMap = m_dtc->participants();
|
||||
|
||||
ParticipantManagement::Participant root;
|
||||
|
||||
QString preDefThing = QLatin1String(" var datascource = ");
|
||||
//first get all participants from Party
|
||||
for (const ParticipantManagement::Participant &part : participantMap)
|
||||
{
|
||||
if (part.isDeleted() || part.partyId() != m_partyId)
|
||||
continue;
|
||||
if (part.superiorId() == 0)
|
||||
{
|
||||
root = part;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (root.inferiorIds().size() == 0)
|
||||
{
|
||||
m_dataSource = preDefThing;
|
||||
m_ui->wevOrgChart->reload();
|
||||
return;
|
||||
}
|
||||
|
||||
// transfer to m_participantOrgChart_MimeDataHelper:
|
||||
delete m_participantOrgChart_MimeDataHelper.data();
|
||||
m_participantOrgChart_MimeDataHelper.clear();
|
||||
m_participantOrgChart_MimeDataHelper = new ParticipantOrgChart_MimeDataHelper(this);
|
||||
if (!m_participantOrgChart_MimeDataHelper->init(m_dtc, AdvancedSymbology::SymbolDictionary::defaultSymbologyType(), true))
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " init failed";
|
||||
return;
|
||||
}
|
||||
|
||||
connect(m_participantOrgChart_MimeDataHelper.data(), &ParticipantOrgChart_MimeDataHelper::finished,
|
||||
this, &LtsParticipantsOrgChart::onParticipantOrgChart_MimeDataHelperFinished);
|
||||
|
||||
m_participantOrgChart_MimeDataHelper->run(root.id(),
|
||||
false,
|
||||
AdvancedSymbology::roleToRole<>(m_dtc->party(m_partyId).role()),
|
||||
QColor::fromRgb(QRgb(m_dtc->party(m_partyId).color())),
|
||||
m_useSymData);
|
||||
}
|
||||
|
||||
void LtsParticipantsOrgChart::onParticipantOrgChart_MimeDataHelperFinished()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
QString preDefThing = QLatin1String(" var datascource = ");
|
||||
|
||||
const QJsonObject &json = m_participantOrgChart_MimeDataHelper->getMimeDataResult();
|
||||
preDefThing.append(QString::fromUtf8(QJsonDocument(json).toJson()));
|
||||
|
||||
m_dataSource = preDefThing;
|
||||
|
||||
QString isMenuEnabled = QLatin1String("; var isMenuEnabled = ");
|
||||
QString isDragEnabled = QLatin1String("; var isDragEnabled = ");
|
||||
QString menuDelete = QLatin1String("; var menuDelete = '") + tr("Delete") + QLatin1String("';");
|
||||
QString menuEdit = QLatin1String("; var menuEdit = '") + tr("Edit") + QLatin1String("';");
|
||||
QString unitName = QLatin1String("; var unitName = '") + tr("Unit") + QLatin1String("';");
|
||||
|
||||
isMenuEnabled.append(m_isMenuEnabled ? QLatin1String("true;") : QLatin1String("false;"));
|
||||
isDragEnabled.append(m_isDragEnabled ? QLatin1String("true;") : QLatin1String("false;"));
|
||||
|
||||
m_dataSource.append(isMenuEnabled);
|
||||
m_dataSource.append(isDragEnabled);
|
||||
m_dataSource.append(menuEdit);
|
||||
m_dataSource.append(menuDelete);
|
||||
m_dataSource.append(unitName);
|
||||
|
||||
//only reload when page is ready
|
||||
if (m_ui->wevOrgChart->page()->url().toString() != QLatin1String("about:blank"))
|
||||
{
|
||||
m_ui->wevOrgChart->reload();
|
||||
}
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
|
||||
bool LtsParticipantsOrgChart::loadTemplate(int templateRootId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
ParticipantManagement::TemplateParticipant root = m_dtc->templateParticipant(templateRootId);
|
||||
|
||||
if (m_ui->wevOrgChart->page()->url().toString() == QLatin1String("about:blank"))
|
||||
{
|
||||
m_ui->wevOrgChart->page()->setHtml(QString());
|
||||
m_ui->wevOrgChart->page()->setHtml(m_html);
|
||||
}
|
||||
// transfer to m_participantOrgChart_MimeDataHelper:
|
||||
m_participantOrgChart_MimeDataHelper.clear();
|
||||
m_participantOrgChart_MimeDataHelper = new ParticipantOrgChart_MimeDataHelper(this);
|
||||
if (!m_participantOrgChart_MimeDataHelper->init(m_dtc, AdvancedSymbology::SymbolDictionary::defaultSymbologyType(), false))
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " init failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
connect(m_participantOrgChart_MimeDataHelper.data(), &ParticipantOrgChart_MimeDataHelper::finished,
|
||||
this, &LtsParticipantsOrgChart::onParticipantOrgChart_MimeDataHelperFinished);
|
||||
|
||||
m_participantOrgChart_MimeDataHelper->run(root.templateId(),
|
||||
false,
|
||||
AdvancedSymbology::roleToRole<>(m_dtc->party(m_partyId).role()),
|
||||
QColor::fromRgb(QRgb(m_dtc->party(m_partyId).color())),
|
||||
false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void LtsParticipantsOrgChart::updateParticipant(int participantId)
|
||||
{
|
||||
QSharedPointer<ParticipantOrgChart_MimeDataHelper> helper =
|
||||
QSharedPointer<ParticipantOrgChart_MimeDataHelper>(new ParticipantOrgChart_MimeDataHelper());
|
||||
|
||||
if (!helper->init(m_dtc, AdvancedSymbology::SymbolDictionary::defaultSymbologyType(), true))
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " init failed";
|
||||
return;
|
||||
}
|
||||
|
||||
m_participantOrgChart_MimeDataHelperMap[participantId] = helper; // update will cancel/destroy the former one.. :-)
|
||||
|
||||
connect(helper.data(), &ParticipantOrgChart_MimeDataHelper::finished,
|
||||
this, &LtsParticipantsOrgChart::onSingleParticipantOrgChart_MimeDataHelperFinished);
|
||||
|
||||
helper->run(participantId,
|
||||
true,
|
||||
AdvancedSymbology::roleToRole<>(m_dtc->party(m_partyId).role()),
|
||||
QColor::fromRgb(QRgb(m_dtc->party(m_partyId).color())),
|
||||
m_useSymData);
|
||||
}
|
||||
|
||||
void LtsParticipantsOrgChart::onSingleParticipantOrgChart_MimeDataHelperFinished()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
|
||||
ParticipantOrgChart_MimeDataHelper *senderWatcher = qobject_cast<ParticipantOrgChart_MimeDataHelper*>(sender());
|
||||
if (!senderWatcher)
|
||||
{
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " sender failed";
|
||||
return;
|
||||
}
|
||||
|
||||
const int participantId = senderWatcher->getParticipantId();
|
||||
const QJsonObject &newJson = senderWatcher->getMimeDataResult();
|
||||
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION << " sendUpdateString:"
|
||||
<< " participantId=" << participantId;
|
||||
|
||||
emit sendUpdateString(participantId, newJson);
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
|
||||
void LtsParticipantsOrgChart::sendToOrgChart(int participantId, const QJsonObject &json)
|
||||
{
|
||||
emit sendUpdateString(participantId, json);
|
||||
}
|
||||
|
||||
void LtsParticipantsOrgChart::getWholeHierarchy()
|
||||
{
|
||||
m_notifier->getWholeHierarchy();
|
||||
}
|
||||
|
||||
|
||||
//Notifier
|
||||
WebNofitifier::WebNofitifier(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_currentJsonString(QString())
|
||||
, m_updateString(QString())
|
||||
, m_updateTimer(new QTimer(this))
|
||||
{
|
||||
connect(m_updateTimer, &QTimer::timeout, this, &WebNofitifier::onTimerTick);
|
||||
}
|
||||
|
||||
void WebNofitifier::startEdit(const QString &data)
|
||||
{
|
||||
emit edit(data);
|
||||
}
|
||||
|
||||
void WebNofitifier::startDelete(const QString &data)
|
||||
{
|
||||
emit remove(data);
|
||||
}
|
||||
|
||||
void WebNofitifier::doMoveChanged()
|
||||
{
|
||||
emit movedParticipant();
|
||||
}
|
||||
|
||||
void WebNofitifier::startDBClick(int id)
|
||||
{
|
||||
emit dbClick(id);
|
||||
}
|
||||
|
||||
void WebNofitifier::gotHierarchy(const QString &data)
|
||||
{
|
||||
emit newHierarchy(data);
|
||||
}
|
||||
|
||||
void WebNofitifier::onSetUpdateString(int ddsId, const QJsonObject &updateString)
|
||||
{
|
||||
m_dataToChange.insert(ddsId, QString::fromUtf8(QJsonDocument(updateString).toJson()));
|
||||
if (!m_updateTimer->isActive())
|
||||
m_updateTimer->start(277);
|
||||
}
|
||||
|
||||
void WebNofitifier::onTimerTick()
|
||||
{
|
||||
const QString dataToSend = m_dataToChange.take(m_dataToChange.firstKey());
|
||||
if (m_dataToChange.isEmpty())
|
||||
m_updateTimer->stop();
|
||||
|
||||
emit updateStringChanged(dataToSend);
|
||||
}
|
||||
|
||||
void WebNofitifier::getWholeHierarchy()
|
||||
{
|
||||
emit getHierarchy();
|
||||
}
|
||||
|
||||
void WebNofitifier::setJsonString(const QString &string)
|
||||
{
|
||||
m_currentJsonString = string;
|
||||
emit jsonStringChanged(string);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* HMI Plugin for ParticipantManagement - Participant OrgChart Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include <participant_org_chart_helper.h>
|
||||
#include <QWidget>
|
||||
#include <QtWebChannel/QWebChannel>
|
||||
//PPM
|
||||
#include <Plugins/ParticipantManagement/Gui/Common/ppmcommon_export.h>
|
||||
#include <Services/ParticipantManagement/ppm_dtc.h>
|
||||
#include <ParticipantManagement/logger.h>
|
||||
|
||||
//asb
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
|
||||
// Qt
|
||||
#include <QPointer>
|
||||
|
||||
|
||||
namespace Ui
|
||||
{
|
||||
class LtsParticipantsOrgChart;
|
||||
}
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
class WebNofitifier : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit WebNofitifier(QObject *parent = nullptr);
|
||||
|
||||
Q_PROPERTY(QString jsonString READ jsonString WRITE setJsonString NOTIFY jsonStringChanged)
|
||||
// Q_PROPERTY(QString updateString MEMBER m_updateString NOTIFY updateStringChanged)
|
||||
Q_PROPERTY(QString updateString READ jsonString WRITE setJsonString NOTIFY updateStringChanged)
|
||||
Q_INVOKABLE void startEdit(const QString &data);
|
||||
Q_INVOKABLE void startDelete(const QString &data);
|
||||
Q_INVOKABLE void startDBClick(int id);
|
||||
Q_INVOKABLE void doMoveChanged();
|
||||
Q_INVOKABLE void gotHierarchy(const QString &data);
|
||||
|
||||
|
||||
void setJsonString(const QString &string);
|
||||
QString jsonString() { return m_currentJsonString; }
|
||||
void getWholeHierarchy();
|
||||
|
||||
public Q_SLOTS:
|
||||
void onSetUpdateString(int ddsId, const QJsonObject &updateString);
|
||||
void onTimerTick();
|
||||
|
||||
signals:
|
||||
void jsonStringChanged(const QString &newJson);
|
||||
void updateStringChanged(const QString &updateJson);
|
||||
void edit(const QString &data);
|
||||
void remove(const QString &data);
|
||||
void dbClick(int);
|
||||
void movedParticipant();
|
||||
void getHierarchy();
|
||||
void newHierarchy(const QString &data);
|
||||
private :
|
||||
QString m_currentJsonString;
|
||||
QString m_updateString;
|
||||
QMap<int, QString> m_dataToChange;
|
||||
QTimer *m_updateTimer;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
class LtsParticipantsOrgChart : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit LtsParticipantsOrgChart(QWidget *parent);
|
||||
~LtsParticipantsOrgChart();
|
||||
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
||||
const std::shared_ptr<AdvancedSymbology::ForeignDataInterface> &asbIfc,
|
||||
bool useSymData = true,
|
||||
bool isMenuEnabled = false,
|
||||
bool isDragEnabled = false);
|
||||
void loadParty(int partyId);
|
||||
bool loadTemplate(int templateRootId);
|
||||
void updateParticipant(int participantId);
|
||||
void sendToOrgChart(int participantId, const QJsonObject &json);
|
||||
void getWholeHierarchy();
|
||||
|
||||
private slots:
|
||||
void onParticipantOrgChart_MimeDataHelperFinished();
|
||||
void onSingleParticipantOrgChart_MimeDataHelperFinished();
|
||||
|
||||
signals:
|
||||
void startEdit(const QString &);
|
||||
void startDelete(const QString &);
|
||||
void startDBClick(int);
|
||||
void gotNewHierarchy(const QString &);
|
||||
void movedParticipant();
|
||||
void sendUpdateString(int, const QJsonObject &);
|
||||
|
||||
private:
|
||||
int m_partyId;
|
||||
bool m_useSymData;
|
||||
bool m_isMenuEnabled;
|
||||
bool m_isDragEnabled;
|
||||
QString m_scriptString;
|
||||
QString m_dataSource;
|
||||
QString m_html;
|
||||
QWebChannel *m_channel;
|
||||
WebNofitifier *m_notifier;
|
||||
|
||||
QPointer<ParticipantOrgChart_MimeDataHelper> m_participantOrgChart_MimeDataHelper;
|
||||
QMap<int, QSharedPointer<ParticipantOrgChart_MimeDataHelper>> m_participantOrgChart_MimeDataHelperMap;
|
||||
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbItc;
|
||||
Ui::LtsParticipantsOrgChart *m_ui;
|
||||
|
||||
LOGGER_T m_logger;
|
||||
};
|
||||
|
||||
}
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>LtsParticipantsOrgChart</class>
|
||||
<widget class="QWidget" name="LtsParticipantsOrgChart">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="whatsThis">
|
||||
<string/>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QWebEngineView" name="wevOrgChart">
|
||||
<property name="url">
|
||||
<url>
|
||||
<string>about:blank</string>
|
||||
</url>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QWebEngineView</class>
|
||||
<extends>QWidget</extends>
|
||||
<header location="global">QtWebEngineWidgets/QWebEngineView</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Executable
+176
@@ -0,0 +1,176 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Participant Combat Power Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
#include "participant_org_chart_gui_plugin.h"
|
||||
|
||||
#include "combat_power.h"
|
||||
#include <LtsWidgets/lts_dialog.h>
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <ParticipantManagement/ppm_operator_rights.h>
|
||||
|
||||
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
std::shared_ptr<GuiPluginBase::Interface> GuiPlugin::createGuiInterface(LtsSession::LtsSession *session)
|
||||
{
|
||||
return std::make_shared<InterfaceImpl>(session);
|
||||
}
|
||||
|
||||
|
||||
InterfaceImpl::InterfaceImpl(LtsSession::LtsSession *session)
|
||||
: GuiPluginBase::Interface(session, getLogger("Plugins.Gui.Ppm.OrgChart"))
|
||||
, m_orgChart(nullptr)
|
||||
, m_dtc(nullptr)
|
||||
, m_ftc(nullptr)
|
||||
, m_asbIfc(nullptr)
|
||||
, m_ppmGuiCbxIfc(nullptr)
|
||||
, m_ppmGuiInfoIfc(nullptr)
|
||||
, m_asSupportService(false)
|
||||
, m_templateId(-1)
|
||||
{}
|
||||
|
||||
|
||||
QVector<LtsWidgets::PluginData> InterfaceImpl::getActions()
|
||||
{
|
||||
|
||||
QVector<LtsWidgets::PluginData> ret;
|
||||
|
||||
|
||||
|
||||
LtsWidgets::PluginData plData;
|
||||
plData.menuGroup = menuGroup();
|
||||
|
||||
if (getFlags().testFlag(LtsAppDescriptor::PluginInfo::Flag::MAIN))
|
||||
{
|
||||
plData.layoutArea = LtsWidgets::LayoutArea::eMainTab;
|
||||
plData.operatorRight = OperatorRights::ParticipantEdit::ParticipantsEdit;
|
||||
|
||||
plData.createInstant = LtsWidgets::CreateInstantType::CreateInstantAndDiscardAction;
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onShowOrgDialog(parent);
|
||||
};
|
||||
plData.menuText = tr("Show Org Chart");
|
||||
plData.identifier = QStringLiteral("orgChartMain");
|
||||
ret.append(plData);
|
||||
|
||||
}
|
||||
|
||||
if (m_session->partitionType() != IDL::PartitionType::Global && appId() != LtsAppDescriptor::App::OrgChart)
|
||||
{
|
||||
plData.createInstant = LtsWidgets::CreateInstantType::DontCreateInstant;
|
||||
|
||||
plData.layoutArea = LtsWidgets::LayoutArea::eDialogTab;
|
||||
plData.menuText = tr("Combat Power");
|
||||
plData.identifier = QStringLiteral("combatPower");
|
||||
plData.operatorRight = OperatorRights::ParticipantInfo::ParticipantInfoWindowShow;
|
||||
plData.exercisePart = LtsWidgets::ExercisePart::eExecution;
|
||||
plData.menuIcon = QIcon(QLatin1String("icon:set_marker_situation.svg")); // TODO: TDM!
|
||||
plData.createWidgetFunc = [this](QWidget * parent)
|
||||
{
|
||||
return onCombatPower(parent);
|
||||
};
|
||||
ret.append(plData);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
QString InterfaceImpl::menuGroup() const
|
||||
{
|
||||
return tr("Participants");
|
||||
}
|
||||
|
||||
|
||||
bool InterfaceImpl::fetchInterfaces()
|
||||
{
|
||||
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_dtc))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Failed to fetch PPM Dtc ";
|
||||
return false;
|
||||
}
|
||||
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ftc))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Failed to fetch PPM Ftc ";
|
||||
return false;
|
||||
}
|
||||
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmGuiCbxIfc))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Failed to fetch PPM Combo Ifc ";
|
||||
return false;
|
||||
}
|
||||
if (!m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(m_asbIfc))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "Failed to fetch ASB Data Ifc ";
|
||||
return false;
|
||||
}
|
||||
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignParticipantInfoGuiInterface>(m_ppmGuiInfoIfc))
|
||||
{
|
||||
WARNING_LOG(m_logger) << "Failed to fetch PPM Info Ifc, but it is optional";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterfaceImpl::clearInterfaces()
|
||||
{
|
||||
m_ppmGuiCbxIfc = nullptr;
|
||||
m_asbIfc = nullptr;
|
||||
m_ppmGuiInfoIfc = nullptr;
|
||||
m_ftc = nullptr;
|
||||
m_dtc = nullptr;
|
||||
}
|
||||
|
||||
bool InterfaceImpl::loadTemplate(int templateRootId, bool asSupportService)
|
||||
{
|
||||
m_asSupportService = asSupportService;
|
||||
m_templateId = templateRootId;
|
||||
|
||||
if (!m_orgChart)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Load Template after: " <<m_templateId;
|
||||
return true;
|
||||
}
|
||||
return m_orgChart->loadTemplate(templateRootId, m_asSupportService);
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onShowOrgDialog(QWidget *parent)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "START RORGCHART";
|
||||
|
||||
//TODO: wait for asb?
|
||||
m_orgChart = new OrgChartMain(m_session, parent);
|
||||
bool useSymData = m_session->partitionType() != IDL::PartitionType::Global; //Templates do not
|
||||
|
||||
if (!m_orgChart->init(m_dtc, m_ftc, m_asbIfc, m_ppmGuiCbxIfc, m_ppmGuiInfoIfc, useSymData, m_asSupportService, m_templateId))
|
||||
{
|
||||
m_orgChart->deleteLater();
|
||||
m_orgChart = nullptr;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return m_orgChart;
|
||||
}
|
||||
|
||||
LtsWidgets::LtsDialog *InterfaceImpl::onCombatPower(QWidget *parent)
|
||||
{
|
||||
CombatPower *dialog = new CombatPower(parent);
|
||||
|
||||
if (!dialog->init(m_dtc, m_asbIfc, m_ppmGuiCbxIfc, m_ppmGuiInfoIfc))
|
||||
{
|
||||
dialog->deleteLater();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dialog;
|
||||
}
|
||||
|
||||
|
||||
} // namespace ParticipantManagement
|
||||
Executable
+83
@@ -0,0 +1,83 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Participant Combat Power Plugin Interface
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "org_chart_main.h"
|
||||
|
||||
|
||||
#include <ParticipantManagement/logger.h>
|
||||
|
||||
#include <PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_org_chart_gui_plugin.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_participant_info_gui_plugin_interface.h>
|
||||
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
class GuiPlugin final : public QObject, public GuiPluginBase::Plugin
|
||||
{
|
||||
Q_PLUGIN_METADATA(IID "gui:3:ppm.orgchart")
|
||||
Q_INTERFACES(GuiPluginBase::Plugin)
|
||||
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit GuiPlugin() = default;
|
||||
~GuiPlugin() = default;
|
||||
|
||||
QString pluginName() override { return QStringLiteral("ParticipantManagement.GuiPlugin.OrgChart"); }
|
||||
std::shared_ptr<GuiPluginBase::Interface> createGuiInterface(LtsSession::LtsSession *session) override;
|
||||
bool availableInPartition(IDL::PartitionType partition) const override
|
||||
{
|
||||
return (partition == IDL::PartitionType::Global ||
|
||||
partition == IDL::PartitionType::Exercise ||
|
||||
partition == IDL::PartitionType::Replay);
|
||||
}
|
||||
};
|
||||
|
||||
class InterfaceImpl final : public QObject, public ForeignGuiOrgChartInterface, 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 loadTemplate(int templateRootId, bool asSupportService = false) override;
|
||||
|
||||
bool availableInPartition(IDL::PartitionType partition) const override
|
||||
{
|
||||
return (partition == IDL::PartitionType::Global ||
|
||||
partition == IDL::PartitionType::Exercise ||
|
||||
partition == IDL::PartitionType::Replay);
|
||||
}
|
||||
|
||||
private:
|
||||
LtsWidgets::LtsDialog *onShowOrgDialog(QWidget *parent);
|
||||
LtsWidgets::LtsDialog *onCombatPower(QWidget *parent);
|
||||
OrgChartMain *m_orgChart;
|
||||
private:
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
|
||||
std::shared_ptr<ParticipantManagement::Interface::Ftc> m_ftc;
|
||||
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> m_asbIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> m_ppmGuiCbxIfc;
|
||||
std::shared_ptr<ParticipantManagement::ForeignParticipantInfoGuiInterface> m_ppmGuiInfoIfc;
|
||||
bool m_asSupportService;
|
||||
int m_templateId;
|
||||
|
||||
};
|
||||
|
||||
} // namespace ParticipantManagement
|
||||
Executable
+376
@@ -0,0 +1,376 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Patric Karwat, SLSE, 2017-04-07
|
||||
*/
|
||||
|
||||
#include "participant_org_chart_helper.h"
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
ParticipantOrgChart_MimeDataHelper::ParticipantOrgChart_MimeDataHelper(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_logger(getLogger("ParticipantOrgChart_MimeDataHelper"))
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
ParticipantOrgChart_MimeDataHelper::~ParticipantOrgChart_MimeDataHelper()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
|
||||
delete m_bulkRendererFindImage;
|
||||
delete m_bulkRendererFindBaseSymbol;
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
bool ParticipantOrgChart_MimeDataHelper::init(const std::shared_ptr<Interface::Dtc> &dtc,
|
||||
AdvancedSymbology::SymbologyType symbologyType, bool participantMode)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START";
|
||||
|
||||
m_symbologyType = symbologyType;
|
||||
m_participantMode = participantMode;
|
||||
if (!dtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not load all interfaces needed";
|
||||
return false;
|
||||
}
|
||||
m_dtc = dtc;
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
return true;
|
||||
}
|
||||
|
||||
void ParticipantOrgChart_MimeDataHelper::run(int participantId, bool single, AdvancedSymbology::Role role, const QColor &color, bool useSymData)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START"
|
||||
<< ", participantId=" << participantId
|
||||
<< ", single=" << single
|
||||
<< ", role=" << role
|
||||
<< ", color=" << color.name()
|
||||
<< ", useSymData" << useSymData;
|
||||
m_mimeData = QJsonObject();
|
||||
m_participantId = participantId;
|
||||
m_single = single;
|
||||
m_role = role;
|
||||
m_color = color;
|
||||
m_useSymData = useSymData;
|
||||
|
||||
if (!m_dtc)
|
||||
{
|
||||
ERROR_LOG(m_logger) << "Could not load all interfaces needed";
|
||||
return;
|
||||
}
|
||||
|
||||
delete m_bulkRendererFindImage;
|
||||
m_bulkRendererFindImage = nullptr;
|
||||
delete m_bulkRendererFindBaseSymbol;
|
||||
m_bulkRendererFindBaseSymbol = nullptr;
|
||||
if (m_useSymData)
|
||||
{
|
||||
m_bulkRendererFindImage = new AdvancedSymbology::BulkRendererFindImage(m_symbologyType);
|
||||
connect(m_bulkRendererFindImage, &AdvancedSymbology::BulkRendererFindImage::resultsReady,
|
||||
this, &ParticipantOrgChart_MimeDataHelper::onRenderingFinished, Qt::UniqueConnection);
|
||||
} else {
|
||||
m_bulkRendererFindBaseSymbol = new AdvancedSymbology::BulkRendererFindBaseSymbol(m_symbologyType);
|
||||
connect(m_bulkRendererFindBaseSymbol, &AdvancedSymbology::BulkRendererFindBaseSymbol::resultsReady,
|
||||
this, &ParticipantOrgChart_MimeDataHelper::onRenderingFinished, Qt::UniqueConnection);
|
||||
}
|
||||
|
||||
prepareBulkRenderer(m_participantId, m_single);
|
||||
|
||||
if (m_useSymData)
|
||||
m_bulkRendererFindImage->run();
|
||||
else
|
||||
m_bulkRendererFindBaseSymbol->run();
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END"
|
||||
<< ", color=" << color.name()
|
||||
<< ", useSymData" << useSymData;
|
||||
}
|
||||
|
||||
bool ParticipantOrgChart_MimeDataHelper::prepareBulkRenderer(int participantId, bool single)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START"
|
||||
<< ", participantId=" << participantId
|
||||
<< ", single=" << single;
|
||||
|
||||
std::vector<int> inferior;
|
||||
QString sidc;
|
||||
|
||||
if (m_participantMode)
|
||||
{
|
||||
const Participant &part = m_dtc->participant(participantId);
|
||||
if (part.id() != participantId)
|
||||
return false;
|
||||
inferior = part.inferiorIds();
|
||||
sidc = QString::fromStdString(part.symbol());
|
||||
}else
|
||||
{
|
||||
const TemplateParticipant &part = m_dtc->templateParticipant(participantId);
|
||||
if (part.templateId() != participantId)
|
||||
return false;
|
||||
|
||||
sidc = QString::fromStdString(part.symbol());
|
||||
if (part.inferiorIds().is_set())
|
||||
inferior = part.inferiorIds().get();
|
||||
}
|
||||
|
||||
if (m_bulkRendererFindImage) // m_useSymData == false [former if (m_useSymData)]
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender =
|
||||
symbolDataToRender(participantId, sidc);
|
||||
m_bulkRendererFindImage->addRequest(symDataToRender);
|
||||
}
|
||||
// .. or ..
|
||||
if (m_bulkRendererFindBaseSymbol) // m_useSymData == false
|
||||
{
|
||||
m_bulkRendererFindBaseSymbol->addRequest(sidc);
|
||||
}
|
||||
|
||||
//
|
||||
// recursion
|
||||
//
|
||||
// // if (part.inferiorIds().is_set())
|
||||
|
||||
for (int infId : inferior)
|
||||
prepareBulkRenderer(infId, single);
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
return true;
|
||||
}
|
||||
|
||||
QJsonObject ParticipantOrgChart_MimeDataHelper::getMimeData(int participantId, bool single)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START"
|
||||
<< ", participantId=" << participantId
|
||||
<< ", single=" << single;
|
||||
|
||||
ParticipantManagement::Participant part = m_dtc->participant(participantId);
|
||||
if (part.id() != participantId)
|
||||
return QJsonObject();
|
||||
ParticipantManagement::Type type = m_dtc->type(part.typeId());
|
||||
|
||||
int eqNr = part.equipmentNumber().is_set() ? part.equipmentNumber().get() : 0;
|
||||
QString isUnit = (type.typeClass() == ParticipantManagement::TypeClass::Unit
|
||||
|| type.typeClass() == ParticipantManagement::TypeClass::SupportUnit)
|
||||
? QLatin1String("true") : QString();
|
||||
|
||||
QJsonObject retObj;
|
||||
QString name = QString::fromStdString(part.designator()) + QLatin1Char(' ') + QString::fromStdString(part.tacticalIdentifier());
|
||||
retObj.insert(QLatin1String("name"), name);
|
||||
retObj.insert(QLatin1String("designator"), QString::fromStdString(part.designator()));
|
||||
retObj.insert(QLatin1String("tactIdentifier"), QString::fromStdString(part.tacticalIdentifier()));
|
||||
retObj.insert(QLatin1String("title"), QString::fromStdString(type.name()));
|
||||
retObj.insert(QLatin1String("info"), QString::fromStdString(part.info()));
|
||||
retObj.insert(QLatin1String("sign"), QString::fromStdString(part.name()));
|
||||
retObj.insert(QLatin1String("typeId"), part.typeId());
|
||||
retObj.insert(QLatin1String("symbol"), QString::fromStdString(part.symbol()));
|
||||
retObj.insert(QLatin1String("eqNr"), eqNr);
|
||||
retObj.insert(QLatin1String("isUnit"), isUnit);
|
||||
retObj.insert(QLatin1String("ddsId"), part.id());
|
||||
retObj.insert(QLatin1String("id"), part.id());
|
||||
retObj.insert(QLatin1String("assignState"), part.assignState().underlying());
|
||||
|
||||
|
||||
const QString &sidc = QString::fromStdString(part.symbol());
|
||||
QSharedPointer<AdvancedSymbology::SymbolResultWatcher> watcher;
|
||||
|
||||
if (m_bulkRendererFindImage)
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender =
|
||||
symbolDataToRender(participantId, sidc);
|
||||
watcher = m_bulkRendererFindImage->getResult(symDataToRender);
|
||||
}
|
||||
|
||||
if (m_bulkRendererFindBaseSymbol)
|
||||
watcher = m_bulkRendererFindBaseSymbol->getResult(sidc);
|
||||
|
||||
if (watcher)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
const AdvancedSymbology::SymbolImage &symbolImage = watcher->symbolResult()->symbolImage();
|
||||
QImage image = symbolImage.image().scaled(QSize(45, 45), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
image.save(&buffer, "PNG", 100);
|
||||
QString imageAdd = QStringLiteral("<img src=\"data:image/png;base64,%1\">")
|
||||
.arg(QString::fromLatin1(data.toBase64()));
|
||||
retObj.insert(QStringLiteral("image"), imageAdd);
|
||||
} else {
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " SymbolResultWatcher for 2nd recusion not found";
|
||||
}
|
||||
|
||||
//
|
||||
// recursion (2nd)
|
||||
//
|
||||
if (part.inferiorIds().size() > 0 && !single)
|
||||
{
|
||||
QJsonArray arr;
|
||||
|
||||
const std::vector<int> &inferior = part.inferiorIds();
|
||||
for (int infId : inferior)
|
||||
arr.append(getMimeData(infId));
|
||||
retObj.insert(QLatin1String("children"), arr);
|
||||
}
|
||||
|
||||
return retObj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
QJsonObject ParticipantOrgChart_MimeDataHelper::getTemplateMimeData(int participantId, bool single)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START"
|
||||
<< ", participantTemplateId=" << participantId
|
||||
<< ", single=" << single;
|
||||
|
||||
ParticipantManagement::TemplateParticipant part = m_dtc->templateParticipant(participantId);
|
||||
if (part.templateId() != participantId)
|
||||
return QJsonObject();
|
||||
ParticipantManagement::Type type = m_dtc->type(part.typeId());
|
||||
|
||||
int eqNr = part.equipmentNumber();
|
||||
QString isUnit = (type.typeClass() == ParticipantManagement::TypeClass::Unit
|
||||
|| type.typeClass() == ParticipantManagement::TypeClass::SupportUnit)
|
||||
? QLatin1String("true") : QString();
|
||||
|
||||
QJsonObject retObj;
|
||||
QString name = QString::fromStdString(part.designator()) + QLatin1Char(' ') + QString::fromStdString(part.tacticalIdentifier());
|
||||
retObj.insert(QLatin1String("name"), name);
|
||||
retObj.insert(QLatin1String("designator"), QString::fromStdString(part.designator()));
|
||||
retObj.insert(QLatin1String("tactIdentifier"), QString::fromStdString(part.tacticalIdentifier()));
|
||||
retObj.insert(QLatin1String("title"), QString::fromStdString(type.name()));
|
||||
retObj.insert(QLatin1String("info"), QString::fromStdString(part.info()));
|
||||
retObj.insert(QLatin1String("sign"), QString::fromStdString(part.name()));
|
||||
retObj.insert(QLatin1String("typeId"), part.typeId());
|
||||
retObj.insert(QLatin1String("symbol"), QString::fromStdString(part.symbol()));
|
||||
retObj.insert(QLatin1String("eqNr"), eqNr);
|
||||
retObj.insert(QLatin1String("isUnit"), isUnit);
|
||||
retObj.insert(QLatin1String("ddsId"), part.templateId());
|
||||
retObj.insert(QLatin1String("id"), part.templateId());
|
||||
retObj.insert(QLatin1String("assignState"), -1);
|
||||
|
||||
|
||||
const QString &sidc = QString::fromStdString(part.symbol());
|
||||
QSharedPointer<AdvancedSymbology::SymbolResultWatcher> watcher;
|
||||
|
||||
if (m_bulkRendererFindImage)
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender =
|
||||
symbolDataToRender(participantId, sidc);
|
||||
watcher = m_bulkRendererFindImage->getResult(symDataToRender);
|
||||
}
|
||||
|
||||
if (m_bulkRendererFindBaseSymbol)
|
||||
watcher = m_bulkRendererFindBaseSymbol->getResult(sidc);
|
||||
|
||||
if (watcher)
|
||||
{
|
||||
QByteArray data;
|
||||
QBuffer buffer(&data);
|
||||
const AdvancedSymbology::SymbolImage &symbolImage = watcher->symbolResult()->symbolImage();
|
||||
QImage image = symbolImage.image().scaled(QSize(45, 45), Qt::KeepAspectRatio, Qt::SmoothTransformation);
|
||||
image.save(&buffer, "PNG", 100);
|
||||
QString imageAdd = QStringLiteral("<img src=\"data:image/png;base64,%1\">")
|
||||
.arg(QString::fromLatin1(data.toBase64()));
|
||||
retObj.insert(QStringLiteral("image"), imageAdd);
|
||||
} else {
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " SymbolResultWatcher for 2nd recusion not found";
|
||||
}
|
||||
|
||||
//
|
||||
// recursion (2nd)
|
||||
//
|
||||
if (part.inferiorIds().is_set() && part.inferiorIds().get().size() > 0 && !single)
|
||||
{
|
||||
QJsonArray arr;
|
||||
|
||||
const std::vector<int> &inferior = part.inferiorIds().get();
|
||||
for (int infId : inferior)
|
||||
arr.append(getTemplateMimeData(infId));
|
||||
retObj.insert(QLatin1String("children"), arr);
|
||||
}
|
||||
|
||||
return retObj;
|
||||
}
|
||||
|
||||
AdvancedSymbology::Injury ParticipantOrgChart_MimeDataHelper::stateToInjury(const ProjectDataManagement::VulnerabilityState &state)
|
||||
{
|
||||
switch (state.underlying())
|
||||
{
|
||||
case ProjectDataManagement::VulnerabilityState::CombatReady:
|
||||
case ProjectDataManagement::VulnerabilityState::TemporarySeverance:
|
||||
case ProjectDataManagement::VulnerabilityState::NearMiss:
|
||||
case ProjectDataManagement::VulnerabilityState::HitWithNoEffect:
|
||||
return AdvancedSymbology::Injury::NoInjury;
|
||||
break;
|
||||
case ProjectDataManagement::VulnerabilityState::LightDamage:
|
||||
case ProjectDataManagement::VulnerabilityState::MediumDamage:
|
||||
case ProjectDataManagement::VulnerabilityState::HeavyDamage:
|
||||
case ProjectDataManagement::VulnerabilityState::NotReady:
|
||||
return AdvancedSymbology::Injury::Hit;
|
||||
break;
|
||||
case ProjectDataManagement::VulnerabilityState::MobilityKill:
|
||||
case ProjectDataManagement::VulnerabilityState::VisibleMobilityKill:
|
||||
return AdvancedSymbology::Injury::MobilityKill;
|
||||
break;
|
||||
case ProjectDataManagement::VulnerabilityState::WeaponSystemDamage:
|
||||
case ProjectDataManagement::VulnerabilityState::VisibleWeaponSystemDamage:
|
||||
return AdvancedSymbology::Injury::WeaponKill;
|
||||
case ProjectDataManagement::VulnerabilityState::CatastrophicKill:
|
||||
return AdvancedSymbology::Injury::TotalKill;
|
||||
default:
|
||||
return AdvancedSymbology::Injury::NoInjury;
|
||||
} // switch
|
||||
|
||||
}
|
||||
|
||||
|
||||
AdvancedSymbology::SymbolDataToRender ParticipantOrgChart_MimeDataHelper::symbolDataToRender(qint32 participantId, const QString &sidc)
|
||||
{
|
||||
AdvancedSymbology::SymbolDataToRender symDataToRender(sidc);
|
||||
|
||||
DynamicParticipantData dData = m_dtc->dynamicParticipantData(participantId);
|
||||
if (dData.participantId() == participantId && !m_isMenuEnabled)
|
||||
{
|
||||
const StateInformation &lastState = m_dtc->youngestStateInformation(dData.stateHistory());
|
||||
symDataToRender.injury = stateToInjury(lastState.vulnerabilityState());
|
||||
symDataToRender.injuryColor = Qt::black;
|
||||
}
|
||||
|
||||
symDataToRender.role = m_role; // QColor::fromRgb(QRgb(m_dtc->party(part.partyId()).color()));
|
||||
symDataToRender.fillColor = m_color; // QColor::fromRgb(QRgb(m_dtc->party(part.partyId()).color()));
|
||||
symDataToRender.fillColorReplace = true;
|
||||
|
||||
return symDataToRender;
|
||||
}
|
||||
|
||||
void ParticipantOrgChart_MimeDataHelper::onRenderingFinished()
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "START, bulkRendererFindImage->size: " << m_bulkRendererFindImage->size();
|
||||
if (m_participantMode)
|
||||
m_mimeData = getMimeData(m_participantId, m_single);
|
||||
else
|
||||
m_mimeData = getTemplateMimeData(m_participantId, m_single);
|
||||
DEBUG_LOG(m_logger) << LOGFUNCTION
|
||||
<< " m_participantId =" << m_participantId
|
||||
<< " m_single = " << m_single
|
||||
<< " m_mimeData.size = " << m_mimeData.size()
|
||||
<< " m_mimeData.size2 = " << QJsonDocument(m_mimeData).toJson().size();
|
||||
|
||||
emit finished();
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << "END";
|
||||
}
|
||||
|
||||
} //namespace ParticipantManagement
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* GUI Plugin for ParticipantManagement - Participant Combat Power Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Norbert Thoden, SLSE, 2018-02-07
|
||||
*/
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <ParticipantManagement/logger.h>
|
||||
#include <Services/ParticipantManagement/ppm_dtc.h>
|
||||
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
||||
#include <Symbology/bulk_renderer.h>
|
||||
|
||||
#include <QJsonObject>
|
||||
|
||||
namespace ParticipantManagement
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief The ParticipantOrgChart_MimeDataHelper class supports OrgChartMain.
|
||||
* For a templateId the according mimeData is assigned to the given widget.
|
||||
* The widget is disabled while running
|
||||
*
|
||||
* Within run, the BulkRendererXY is setup.
|
||||
* Then (prepareBulkRenderer) we are iteration through the tree and addRequests.
|
||||
* After iterating the rendering is triggered.
|
||||
* OnRenderingFinished iterates through the tree again (getMimeData).
|
||||
* Within the mimeData is accumulated and uses the just rendered images.
|
||||
* Finally 'the 'finished' is emitted.
|
||||
*/
|
||||
class ParticipantOrgChart_MimeDataHelper final : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ParticipantOrgChart_MimeDataHelper(QObject *parent = nullptr);
|
||||
~ParticipantOrgChart_MimeDataHelper();
|
||||
|
||||
bool init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
||||
AdvancedSymbology::SymbologyType symbologyType, bool participantMode);
|
||||
|
||||
void run(int participantId, bool single, AdvancedSymbology::Role role, const QColor &color, bool useSymData);
|
||||
|
||||
const QJsonObject &getMimeDataResult() const { return m_mimeData; }
|
||||
int getParticipantId() const { return m_participantId; }
|
||||
signals:
|
||||
void finished();
|
||||
|
||||
protected slots:
|
||||
void onRenderingFinished();
|
||||
|
||||
private:
|
||||
bool prepareBulkRenderer(int participantId, bool single = false);
|
||||
QJsonObject getMimeData(int participantId, bool single = false);
|
||||
QJsonObject getTemplateMimeData(int participantId, bool single = false);
|
||||
|
||||
AdvancedSymbology::Injury stateToInjury(const ProjectDataManagement::VulnerabilityState &state);
|
||||
|
||||
AdvancedSymbology::SymbolDataToRender symbolDataToRender(qint32 participantId, const QString &sidc);
|
||||
|
||||
int m_participantId = -1;
|
||||
bool m_single = false;
|
||||
|
||||
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_dtc;
|
||||
|
||||
AdvancedSymbology::Role m_role = AdvancedSymbology::Role::Unknown;
|
||||
QColor m_color;
|
||||
bool m_useSymData = true;
|
||||
bool m_isMenuEnabled = false;
|
||||
bool m_participantMode = true;
|
||||
|
||||
AdvancedSymbology::SymbologyType m_symbologyType = AdvancedSymbology::SymbologyType::None;
|
||||
AdvancedSymbology::BulkRendererFindImage *m_bulkRendererFindImage = nullptr;
|
||||
AdvancedSymbology::BulkRendererFindBaseSymbol *m_bulkRendererFindBaseSymbol = nullptr;
|
||||
QJsonObject m_mimeData;
|
||||
NGL::INGLLogger &m_logger;
|
||||
};
|
||||
|
||||
} //ParticipantManagement
|
||||
Reference in new issue
Block a user