784 lines
28 KiB
C++
Executable File
784 lines
28 KiB
C++
Executable File
/**
|
|
* @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
|