Qt6 Migration: Complete migration with DDS/RTI support and build validation

Major Changes:
- Merged latest Qt5 devel content from dlbo (292 files changed, 7 new dirs)
- Consolidated forward-declarations and include folders
- Removed unneeded modules per Niklas' repo check list

Build System Fixes:
- Fixed CMake VERSION_GREATER syntax in ParticipantManagement/CMakeLists.txt
- Added VLC packages (libvlc-dev, vlc-plugin-base) to docker_build.sh
- Added PostgreSQL dev packages (libpq-dev, postgresql-server-dev-all) to Dockerfile
- Fixed locale warnings (ANSI_X3.4-1968 → C.UTF-8)
- Fixed ArcGIS SDK path warnings when BUILD_ARCGIS=OFF

Code Generation Fixes:
- Fixed IDL enum collisions (PortType→CorePortType/DdsutPortType, PdmEventType)
- Fixed Grantlee template svc_translation.cpp.grantlee:
  - Changed {{ idl_enum.name }}_def:: to {{ idl_enum.name }}::
  - Fixed .underlying() calls for C++11 scoped enums (enum class)
- Removed generated files from repo (moc_*, *_dtc.h, *_ftc.h)

Validation:
- BUILD_RTI=ON: SUCCESS
- BUILD_RTI=OFF: SUCCESS
- C++17 standard maintained for RTI 7.7 compatibility
- Ubuntu 26.04 Docker environment verified

Remaining Warnings (expected):
- BgViewer, KDChart, KDReports, Poppler-Qt6 not found (optional features)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
torstenandCopilot committed 2026-09-15 18:20:26 +00:00
1 parent f23384bb68
commit 7173785915
18662 files changed
+4115092 -5435

No files matched your search

@@ -1,224 +1,264 @@
#include "flm_hq_report_converter.h"
#include <AreaEffectSimulation/Utils/polygons.h>
#include <flm_data_plugin_interface.h>
#include <Lts/Services/FileManagement/flm_ftc.h>
#include <FileManagement/flm_data_plugin_interface.h>
#include <FileManagement/flm_ftc.h>
#include <FileManagement/flm_ftc_types.h>
#include <GeometryModel/geometry_model_factory.h>
#include <LtsSession/lts_session.h>
#include <LtsSession/lts_session_data.h>
#include <LtsUtils/LtsUtilsCore/dds_vector.h>
#include <ParticipantManagement/ppm_data_plugin_interface.h>
#include <Symbology/sidc_builder_base.h>
#include <Symbology/sidc_codec.h>
#include <Symbology/symbol_dictionary.h>
#include <SymbologyXML/symbol_types.h>
#include <GeometryModel/geometry_model_factory.h>
#include <LtsSession/lts_session.h>
#include <LtsSession/lts_session_data.h>
#include <LtsUtilsCore/dds_vector.h>
#include <AreaEffectSimulation/Utils/polygons.h>
#include <ParticipantManagement/ppm_data_plugin_interface.h>
namespace FileManagement
{
FlmHqReportConverter::FlmHqReportConverter() : m_logger(getLogger("HQReportConverter"))
FlmHqReportConverter::FlmHqReportConverter()
: m_logger(getLogger("HQReportConverter"))
{
connect(this, &FlmHqReportConverter::allRequestsFinished, this, &FlmHqReportConverter::onRequestsFinished);
connect(this, &FlmHqReportConverter::allRequestsFinished, this, &FlmHqReportConverter::onRequestsFinished);
}
bool FlmHqReportConverter::init(LtsSession::LtsSession* session, int currentPartyId)
bool FlmHqReportConverter::init(LtsSession::LtsSession *session, int currentPartyId)
{
if (session == nullptr)
{
ERROR_LOG(m_logger) << "Got invalid session";
if (session == nullptr)
{
ERROR_LOG(m_logger) << "Got invalid session";
return false;
}
return false;
}
m_session = session;
m_session = session;
if (!m_session->getDtc<DataInterface>(m_flmDtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Dtc.";
if (!m_session->getDtc<DataInterface>(m_flmDtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Dtc.";
return false;
}
return false;
}
if (!m_session->getFtc<DataInterface>(m_flmFtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Ftc.";
if (!m_session->getFtc<DataInterface>(m_flmFtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Ftc.";
return false;
}
return false;
}
if (!session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not get PPM Dtc.";
if (!session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
{
ERROR_LOG(m_logger) << "Could not get PPM Dtc.";
return false;
}
return false;
}
if (!m_flmFtc->enableFileContentModify())
{
ERROR_LOG(m_logger) << "Could enable fileContentModify.";
if (!m_flmFtc->enableFileContentModify())
{
ERROR_LOG(m_logger) << "Could enable fileContentModify.";
return false;
}
return false;
}
m_flmDtc->enableFileContent();
m_flmDtc->enableFolder();
m_flmDtc->enableFileContent();
m_flmDtc->enableFolder();
if (m_geometryModel != nullptr)
{
delete m_geometryModel;
m_geometryModel = nullptr;
}
if (m_geometryModel != nullptr)
{
delete m_geometryModel;
m_geometryModel = nullptr;
}
m_geometryModel = SituationMap::GeometryModelFactory::singleton()->create();
m_geometryModel = SituationMap::GeometryModelFactory::singleton()->create();
m_partyId = currentPartyId;
m_partyId = currentPartyId;
return true;
return true;
}
void FlmHqReportConverter::addHqToPlanIds(const QMap<int, QList<int>>& hqToPlanIds)
void FlmHqReportConverter::addHqToPlanIds(const QMap<int, QSet<int>> &hqToPlanIds)
{
for (auto it = hqToPlanIds.constBegin(); it != hqToPlanIds.constEnd(); ++it)
for (auto it = hqToPlanIds.constBegin(); it != hqToPlanIds.constEnd(); ++it)
{
int planFileId = it.key();
const QSet<int> &hqMessageIds = it.value();
for (int id : hqMessageIds)
{
m_hqToPlanIds[it.key()].append(it.value());
if (id == planFileId) // Eventueller Eintrag in Map wegen QTreeView verhindern
continue;
m_hqToPlanIds[planFileId].append(id);
}
}
}
void FlmHqReportConverter::processCollectedHqs()
{
for (auto it = m_hqToPlanIds.constBegin(); it != m_hqToPlanIds.constEnd(); ++it)
for (auto it = m_hqToPlanIds.constBegin(); it != m_hqToPlanIds.constEnd(); ++it)
{
int planId = it.key();
for (int id : it.value())
m_pendingRequests++;
}
for (auto it = m_hqToPlanIds.constBegin(); it != m_hqToPlanIds.constEnd(); ++it)
{
int planId = it.key();
const QList<int> &hqMessageIds = it.value();
for (int id : hqMessageIds)
{
m_pendingRequests += it.value().size();
}
for (auto it = m_hqToPlanIds.constBegin(); it != m_hqToPlanIds.constEnd(); ++it)
{
int planId = it.key();
const QList<int>& reportIds = it.value();
for (int id : reportIds)
{
DEBUG_LOG(m_logger) << "Request File with ID: " << id << " from plan with ID: " << planId;
FileManagement::GetFileContentDataRequest request(id);
m_flmFtc->getFileContentDataRequest(request, this);
}
DEBUG_LOG(m_logger) << "Request File with ID: " << id << " from plan with ID: " << planId;
FileManagement::GetFileContentDataRequest request(id);
m_flmFtc->getFileContentDataRequest(request, this);
}
}
}
void FlmHqReportConverter::createGeometryFromReport(const HqReportData& data)
{
m_symbolFactory.build(data.art, data, m_geometryModel);
}
void FlmHqReportConverter::createGeometryFromReport(const HqReportData &data) { m_symbolFactory.build(data.art, data, m_geometryModel); }
void FlmHqReportConverter::checkIfAllFinished()
{
if (m_pendingRequests <= 0)
emit allRequestsFinished();
if (m_pendingRequests <= 0)
emit allRequestsFinished();
}
void FlmHqReportConverter::onGetFileContentDataReply(const FileManagement::GetFileContentDataReply& reply)
void FlmHqReportConverter::onGetFileContentDataReply(const FileManagement::GetFileContentDataReply &reply)
{
m_pendingRequests--;
m_pendingRequests--;
if (reply.errorString().size() > 0)
const int id = static_cast<int>(reply.id());
int planId = -1;
for (auto it = m_hqToPlanIds.constBegin(); it != m_hqToPlanIds.constEnd(); ++it)
{
if (it.value().contains(id))
{
ERROR_LOG(m_logger) << "Got onGetFileContentDataReply error: " << reply.errorString();
return;
planId = it.key();
break;
}
}
int id = static_cast<int>(reply.id());
int planId = -1;
DEBUG_LOG(m_logger) << "Reply File with ID: " << id << " from plan with ID: " << planId;
INFO_LOG(m_logger) << "Got reply with id " << id;
DEBUG_LOG(m_logger) << "Reply File with ID: " << id << " from plan with ID: " << planId;
QByteArray fileContent = QByteArray::fromRawData(reinterpret_cast<const char *>(reply.content().data()), reply.content().size());
INFO_LOG(m_logger) << "Got reply with id " << id << " and errorString " << reply.errorString();
DEBUG_LOG(m_logger) << "fileContent: " << fileContent;
QByteArray fileContent = QByteArray(reinterpret_cast<const char*>(reply.content().data()), reply.content().size());
FileManagement::FileContent flc = m_flmDtc->fileContent(reply.id());
FlmHqReportJsonParser m_parser = FlmHqReportJsonParser();
DEBUG_LOG(m_logger) << "FlmHqReportConverter::onGetFileContentDataReply FILECONTENTNAME: " << flc.name();
HqReportData data = m_parser.parse(fileContent);
data.contentFileId = id;
HqReportData data = m_parser.parse(fileContent);
data.contentFileId = id;
data.name = QString::fromStdString(flc.name());
DEBUG_LOG(m_logger) << "Party: " << m_partyId
<< " has Color: " << QColor::fromRgb(QRgb(m_ppmDtc->party(m_partyId).color())).value();
data.partyColor = QColor::fromRgb(m_ppmDtc->party(m_partyId).color());
data.partyColor = QColor::fromRgb(QRgb(m_ppmDtc->party(m_partyId).color()));
m_convertedHqToPlanIds[planId].append(std::move(data));
for (auto it = m_hqToPlanIds.constBegin(); it != m_hqToPlanIds.constEnd(); ++it)
{
if (it.value().contains(id))
{
planId = it.key();
break;
}
}
DEBUG_LOG(m_logger) << "Content size: " << reply.content().size();
m_convertedHqToPlanIds[planId].append(data);
DEBUG_LOG(m_logger) << "Content size: " << reply.content().size();
checkIfAllFinished();
checkIfAllFinished();
}
void FlmHqReportConverter::onFileContentModifyReply(const Core::FunctionReplyObject& reply)
void FlmHqReportConverter::onFileContentModifyReply(const Core::FunctionReplyObject &reply)
{
DEBUG_LOG(m_logger) << "Got FileContentModify Reply: " << reply.translated();
DEBUG_LOG(m_logger) << "Got FileContentModify Reply: " << reply.translated();
if (reply.error())
{
ERROR_LOG(m_logger) << "Error while insert HX Message: " << reply.translated() << ", error: " << reply.error();
}
if (reply.error())
ERROR_LOG(m_logger) << "Error while insert HX Message: " << reply.translated() << ", error: " << reply.error();
}
void FlmHqReportConverter::onFileContentRemoveReply(const Core::FunctionReplyObject& reply)
void FlmHqReportConverter::onFileContentRemoveReply(const Core::FunctionReplyObject &reply)
{
DEBUG_LOG(m_logger) << "Got FileContentRemove Reply: " << reply.translated();
DEBUG_LOG(m_logger) << "Got FileContentRemove Reply: " << reply.translated();
if (reply.error())
{
ERROR_LOG(m_logger) << "Error while insert HX Message: " << reply.translated() << ", error: " << reply.error();
}
if (reply.error())
ERROR_LOG(m_logger) << "Error while insert HX Message: " << reply.translated() << ", error: " << reply.error();
}
void FlmHqReportConverter::onRequestsFinished()
{
DEBUG_LOG(m_logger) << "ALL REQUESTS FINISHED";
DEBUG_LOG(m_logger) << "ALL REQUESTS FINISHED -> STARTING CONTENT FETCH";
for (auto it = m_convertedHqToPlanIds.constBegin(); it != m_convertedHqToPlanIds.constEnd(); ++it)
{
int planId = it.key();
const QList<HqReportData>& reportDatas = it.value();
for (auto it = m_convertedHqToPlanIds.constBegin(); it != m_convertedHqToPlanIds.constEnd(); ++it)
{
int planId = it.key();
QList<HqReportData> reportDatas = it.value();
const FileManagement::FileContent flc = m_flmDtc->fileContent(planId);
FileManagement::GetFileContentDataRequest req;
req.fileContentId(planId);
for (auto& reportData : reportDatas)
{
DEBUG_LOG(m_logger) << "createGeometryFromReport :" << reportData.art;
createGeometryFromReport(reportData);
}
m_flmFtc->getFileContentDataRequest(req,
[this, planId, reportDatas = std::move(reportDatas), flc = std::move(flc)](const FileManagement::GetFileContentDataReply &reply)
{
const auto &fetchedFlc = reply;
if (fetchedFlc.content().size() > 0)
{
QByteArray existingContent
= QByteArray::fromRawData(reinterpret_cast<const char *>(fetchedFlc.content().data()), fetchedFlc.content().size());
const FileManagement::FileContent& flc = m_flmDtc->fileContent(planId);
if (!m_geometryModel->fromByteArray(existingContent))
WARNING_LOG(m_logger) << "Could not load existing geometry content for planId" << planId;
}
FileManagement::FileContentModifyRequest data;
QJsonArray jsonNameArray;
QJsonDocument existingDocs = QJsonDocument::fromJson(QByteArray::fromRawData(flc.properties().data(), flc.properties().size()));
DEBUG_LOG(m_logger) << "FILE CONTENT: " << flc.name() << " " << flc.folderId();
if (existingDocs.isArray())
jsonNameArray = existingDocs.array();
data.id(flc.id());
data.name(flc.name());
data.isTemplate(false);
data.isHidden(false);
data.folderId(flc.folderId());
data.fileStatus(FileManagement::FileStatus::Valid);
data.fileCategory(FileManagement::FileCategory::Exercise);
data.fileType(FileManagement::FileType::TacticalPlan);
data.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
data.lastModified(QDateTime::currentMSecsSinceEpoch());
data.content(LtsUtils::convert<std::vector<uint8_t>>(m_geometryModel->toByteArray()));
data.exerciseId(m_session->exerciseId());
for (const auto &reportData : reportDatas)
{
m_flmFtc->fileContentModifyRequest(data, this);
bool alreadyExists = false;
for (const QJsonValue &value : jsonNameArray)
{
if (value.toString() == reportData.name)
{
alreadyExists = true;
break;
}
}
m_geometryModel->clearModel();
}
if (!alreadyExists)
{
createGeometryFromReport(reportData);
jsonNameArray.append(reportData.name);
}
}
QJsonDocument jsonDoc(jsonNameArray);
QString combinedNames = QString::fromUtf8(jsonDoc.toJson(QJsonDocument::Compact));
FileManagement::FileContentModifyRequest data;
DEBUG_LOG(m_logger) << "FILE CONTENT: " << flc.name() << " " << flc.folderId();
data.id(flc.id());
data.name(flc.name());
data.isTemplate(false);
data.isHidden(false);
data.folderId(flc.folderId());
data.fileStatus(FileManagement::FileStatus::Valid);
data.fileCategory(FileManagement::FileCategory::Exercise);
data.fileType(FileManagement::FileType::TacticalPlan);
data.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
data.lastModified(QDateTime::currentMSecsSinceEpoch());
data.content(LtsUtils::convert<std::vector<uint8_t>>(m_geometryModel->toByteArray()));
data.exerciseId(m_session->exerciseId());
data.properties(combinedNames.toStdString());
m_flmFtc->fileContentModifyRequest(data, this);
m_geometryModel->clearModel();
});
}
}
} // namespace FileManagement
@@ -1,10 +1,10 @@
#pragma once
#include <FileManagement/logger.h>
#include <GeometryModel/geometry_model.h>
#include "flm_hq_report_json_parser.h"
#include "flm_hq_report_symbol_factory.h"
#include <Lts/Services/FileManagement/logger.h>
#include <GeometryModel/geometry_model.h>
namespace LtsSession
{
class LtsSession;
@@ -18,53 +18,64 @@ class Dtc;
class Ftc;
} // namespace Interface
class FlmHqReportConverter : public QObject,
public Interface::Ftc::GetFileContentDataReplyHandler,
public Interface::Ftc::FileContentModifyReplyHandler,
public Interface::Ftc::FileContentRemoveReplyHandler
class FlmHqReportConverter
: public QObject
, public Interface::Ftc::GetFileContentDataReplyHandler
, public Interface::Ftc::FileContentModifyReplyHandler
, public Interface::Ftc::FileContentRemoveReplyHandler
{
Q_OBJECT
Q_OBJECT
public:
FlmHqReportConverter();
~FlmHqReportConverter() = default;
FlmHqReportConverter();
~FlmHqReportConverter() = default;
bool init(LtsSession::LtsSession* session, int currentPartyId);
void addHqToPlanIds(const QMap<int, QList<int>>& hqToPlanIds);
void processCollectedHqs();
void createGeometryFromReport(const HqReportData& data);
bool init(LtsSession::LtsSession *session, int currentPartyId);
/**
* @brief add hqToPlanIds to m_hqToPlanIds
* @param const QMap<int, QList<int>> &hqToPlanIds -> <planId, QList<HqIds>>
*/
void addHqToPlanIds(const QMap<int, QSet<int>> &hqToPlanIds);
/**
* @brief Iterate and send GetFileContentDataRequest to get File Information HQ
*/
void processCollectedHqs();
/**
* @brief create GeometryModel from HQ Report
* @param {data} HQ Report Data
*/
void createGeometryFromReport(const HqReportData &data);
private:
void checkIfAllFinished();
void checkIfAllFinished();
protected:
NGL::INGLLogger& m_logger;
void onGetFileContentDataReply(const FileManagement::GetFileContentDataReply& reply) override;
void onFileContentModifyReply(const Core::FunctionReplyObject& reply) override;
void onFileContentRemoveReply(const Core::FunctionReplyObject& reply) override;
void onGetFileContentDataReply(const FileManagement::GetFileContentDataReply &reply) override;
void onFileContentModifyReply(const Core::FunctionReplyObject &reply) override;
void onFileContentRemoveReply(const Core::FunctionReplyObject &reply) override;
public slots:
void onRequestsFinished();
void onRequestsFinished();
signals:
void allRequestsFinished();
/**
* @brief checks if all getFileContentDataRequests are finished
*/
void allRequestsFinished();
private:
LtsSession::LtsSession* m_session{nullptr};
std::shared_ptr<Interface::Dtc> m_flmDtc;
std::shared_ptr<Interface::Ftc> m_flmFtc;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
LOGGER_T m_logger;
LtsSession::LtsSession *m_session{nullptr};
std::shared_ptr<Interface::Dtc> m_flmDtc;
std::shared_ptr<Interface::Ftc> m_flmFtc;
std::shared_ptr<ParticipantManagement::Interface::Dtc> m_ppmDtc;
SituationMap::GeometryModel* m_geometryModel{nullptr};
QList<SituationMap::GeometryModel::Node> m_planNodes;
SymbolFactory m_symbolFactory;
SituationMap::GeometryModel *m_geometryModel{nullptr};
QList<SituationMap::GeometryModel::Node> m_planNodes;
SymbolFactory m_symbolFactory;
int m_partyId;
int m_pendingRequests{0};
QMap<int, QList<int>> m_hqToPlanIds;
QMap<int, int> m_hqToPlanIdsLookup;
QMap<int, QList<HqReportData>> m_convertedHqToPlanIds;
};
int m_partyId;
int m_pendingRequests{0};
FlmHqReportJsonParser m_parser;
QMap<int, QList<int>> m_hqToPlanIds; /// Map<planIds, QList<HQMessageId>>
QMap<int, int> m_hqToPlanIdsLookup; /// Map<planIds, HQMessageId> for Lookup
QMap<int, QList<HqReportData>> m_convertedHqToPlanIds; /// Map<planIds, QList<convertedHqMessage>>
}; // class FlmHqReportConverter
} // namespace FileManagement
@@ -1,385 +1,361 @@
#include "flm_hq_report_edit.h"
#include "flm_hq_report_model.h"
#include "ui_flm_hq_report_edit.h"
#include <PluginInterfaces/gui_plugin_interface.h>
#include <Plugins/ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <LtsSession/lts_session.h>
#include <LtsSession/lts_session_data.h>
#include <LtsUtils/LtsUtilsCore/dds_vector.h>
#include <ParticipantManagement/ppm_gui_combobox_plugin_interface.h>
#include <PluginInterfaces/gui_plugin_interface.h>
#include <flm_data_plugin_interface.h>
#include <QtCore/QDateTime>
#include <QtWidgets/QInputDialog>
#include <Plugins/FileManagement/flm_data_plugin_interface.h>
#include <QDateTime>
#include <QInputDialog>
#include <SituationMap/GeometryModel/geometry_model.h>
#include <SituationMap/GeometryModel/geometry_model_factory.h>
#include <LtsUtils/LtsUtilsCore/dds_vector.h>
namespace FileManagement
{
HQReportEdit::HQReportEdit(const QString& menuGroup, QWidget* parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel), m_ui(new Ui::HQReportEdit),
m_menuGroup(menuGroup)
HQReportEdit::HQReportEdit(const QString &menuGroup, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_ui(new Ui::HQReportEdit)
, m_logger(getLogger("HQReportEdit"))
, m_menuGroup(menuGroup)
{
m_ui->setupUi(this);
m_ui->setupUi(this);
m_buttonBox->getButton(LtsWidgets::DialogButton::Add)->setText(tr("New Plan"));
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &HQReportEdit::onCreateNewPlanClicked);
m_buttonBox->getButton(LtsWidgets::DialogButton::Add)->setText(tr("New Plan"));
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &HQReportEdit::onCreateNewPlanClicked);
connect(m_ui->pbShift, &QPushButton::clicked, this, &HQReportEdit::onShiftClicked);
setOnlineHelpFilename(QStringLiteral("Situation-HQReport"));
connect(m_ui->pbShift, &QPushButton::clicked, this, &HQReportEdit::onShiftClicked);
setOnlineHelpFilename(QStringLiteral("Situation-HQReport"));
}
HQReportEdit::~HQReportEdit()
HQReportEdit::~HQReportEdit() { delete m_ui; }
bool HQReportEdit::init(LtsSession::LtsSession *session, int partyId)
{
delete m_ui;
}
if (session == nullptr)
{
ERROR_LOG(m_logger) << "Got invalid session";
bool HQReportEdit::init(LtsSession::LtsSession* session, int partyId)
{
if (session == nullptr)
{
ERROR_LOG(m_logger) << "Got invalid session";
return false;
}
return false;
}
m_session = session;
m_session = session;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> partyCboInterface;
std::shared_ptr<ParticipantManagement::ForeignGuiComboboxInterface> partyCboInterface;
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(partyCboInterface))
{
ERROR_LOG(m_logger) << "Could not get Party Combobox Interface.";
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(partyCboInterface))
{
ERROR_LOG(m_logger) << "Could not get Party Combobox Interface.";
return false;
}
return false;
}
if (!partyCboInterface->fillPartyComboBox(m_ui->cboParties) || m_ui->cboParties->count() == 0)
{
ERROR_LOG(m_logger) << "Could not fill Parties.";
if (!partyCboInterface->fillPartyComboBox(m_ui->cboParties) || m_ui->cboParties->count() == 0)
{
ERROR_LOG(m_logger) << "Could not fill Parties.";
return false;
}
return false;
}
if (!m_session->getDtc<DataInterface>(m_flmDtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Dtc.";
if (!m_session->getDtc<DataInterface>(m_flmDtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Dtc.";
return false;
}
return false;
}
if (!m_session->getFtc<DataInterface>(m_flmFtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Ftc.";
if (!m_session->getFtc<DataInterface>(m_flmFtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Ftc.";
return false;
}
return false;
}
if (!m_flmFtc->enableFileContentModify())
{
ERROR_LOG(m_logger) << "Could enable fileContentModify.";
if (!m_flmFtc->enableFileContentModify())
{
ERROR_LOG(m_logger) << "Could enable fileContentModify.";
return false;
}
return false;
}
// init models
qDeleteAll(m_hqModels);
m_hqModels.clear();
qDeleteAll(m_hqModels);
m_hqModels.clear();
qDeleteAll(m_planModels);
m_planModels.clear();
qDeleteAll(m_planModels);
m_planModels.clear();
for (int index = 0; index < m_ui->cboParties->count(); ++index)
{
const int partyId = m_ui->cboParties->itemData(index).toInt();
const int partyFolderId = m_flmDtc->getPartyFolderId(m_session->exerciseId(), partyId);
FlmHQReportModel* planModel = new FlmHQReportModel(m_ui->listViewPlan);
if (!planModel->init(m_session, partyFolderId, FileType::inner_enum::TacticalPlan))
{
WARNING_LOG(m_logger) << "Could not init planModel for partyId " << partyId;
delete planModel;
planModel = nullptr;
continue;
}
const int hqReportFolderId = m_flmDtc->findFolder(partyFolderId, QStringLiteral("Messages"));
FlmHQReportModel* hqReportModel = new FlmHQReportModel(m_ui->listViewMessage);
if (!hqReportModel->init(m_session, hqReportFolderId, FileType::inner_enum::AdlerJson))
{
WARNING_LOG(m_logger) << "Could not init hqReportModel for partyId " << partyId;
delete planModel;
planModel = nullptr;
delete hqReportModel;
hqReportModel = nullptr;
continue;
}
connect(planModel, &FlmHQReportModel::dataAddedOrRemoved, this, &HQReportEdit::slotChangesMade);
m_planModels.insert(partyId, planModel);
m_hqModels.insert(partyId, hqReportModel);
}
m_ui->listViewPlan->setDragDropMode(QAbstractItemView::DropOnly);
m_ui->listViewPlan->setDefaultDropAction(Qt::CopyAction);
m_ui->listViewPlan->setDropIndicatorShown(true);
m_ui->listViewMessage->setDragDropMode(QAbstractItemView::DragOnly);
m_ui->listViewMessage->setDefaultDropAction(Qt::CopyAction);
m_ui->listViewMessage->setDropIndicatorShown(true);
onPartyChanged();
if (!m_flmFtc->enableFileContentModify())
{
ERROR_LOG(m_logger) << "Could enable fileContentModify.";
return false;
}
qDeleteAll(m_hqModels);
m_hqModels.clear();
qDeleteAll(m_planModels);
m_planModels.clear();
for (int index = 0; index < m_ui->cboParties->count(); ++index)
{
const int partyId = m_ui->cboParties->itemData(index).toInt();
createModels(partyId);
}
m_ui->listViewPlan->setDragDropMode(QAbstractItemView::DropOnly);
m_ui->listViewPlan->setDefaultDropAction(Qt::MoveAction);
m_ui->listViewPlan->setDropIndicatorShown(true);
m_ui->listViewMessage->setDragDropMode(QAbstractItemView::DragOnly);
m_ui->listViewMessage->setDefaultDropAction(Qt::MoveAction);
m_ui->listViewMessage->setDropIndicatorShown(true);
onPartyChanged();
connect(m_ui->cboParties, qOverload<int>(&QComboBox::currentIndexChanged), this, &HQReportEdit::onPartyChanged);
int partyIndex = m_ui->cboParties->findData(partyId);
m_ui->cboParties->setCurrentIndex(partyIndex < 0 ? 0 : partyIndex);
return true;
}
void HQReportEdit::createModels(const int partyId)
{
for (int index = 0; index < m_ui->cboParties->count(); ++index)
{
const int partyId = m_ui->cboParties->itemData(index).toInt();
const int partyFolderId = m_flmDtc->getPartyFolderId(m_session->exerciseId(), partyId);
if (partyFolderId == 0)
FlmHQReportModel *planModel = new FlmHQReportModel(m_ui->listViewPlan);
if (!planModel->init(m_session, partyFolderId, FileType::inner_enum::TacticalPlan))
{
WARNING_LOG(m_logger) << "No partyFolderId found for partyId " << partyId;
return;
WARNING_LOG(m_logger) << "Could not init planModel for partyId " << partyId;
delete planModel;
planModel = nullptr;
continue;
}
const int hqReportFolderId = m_flmDtc->findFolder(partyFolderId, QStringLiteral("Messages"));
auto* planModel = new FlmHQReportModel(m_ui->listViewPlan);
if (!planModel->init(m_session, partyFolderId, FileType::inner_enum::TacticalPlan))
{
WARNING_LOG(m_logger) << "Could not init planModel for partyId " << partyId;
delete planModel;
return;
}
FlmHQReportModel *hqReportModel = new FlmHQReportModel(m_ui->listViewMessage);
auto* hqReportModel = new FlmHQReportModel(m_ui->listViewMessage);
if (!hqReportModel->init(m_session, hqReportFolderId, FileType::inner_enum::AdlerJson))
{
WARNING_LOG(m_logger) << "Could not init hqReportModel for partyId " << partyId;
delete planModel;
delete hqReportModel;
return;
WARNING_LOG(m_logger) << "Could not init hqReportModel for partyId " << partyId;
delete planModel;
planModel = nullptr;
delete hqReportModel;
hqReportModel = nullptr;
continue;
}
connect(planModel, &FlmHQReportModel::dataAddedOrRemoved, this, &HQReportEdit::slotChangesMade);
m_planModels.insert(partyId, planModel);
m_hqModels.insert(partyId, hqReportModel);
}
// configure listViewPlan
m_ui->listViewPlan->setDragDropMode(QAbstractItemView::DropOnly);
m_ui->listViewPlan->setDefaultDropAction(Qt::CopyAction);
m_ui->listViewPlan->setDropIndicatorShown(true);
m_ui->listViewPlan->setHeaderHidden(true);
// configure listViewMessage
m_ui->listViewMessage->setDragDropMode(QAbstractItemView::DragOnly);
m_ui->listViewMessage->setDefaultDropAction(Qt::CopyAction);
m_ui->listViewMessage->setDropIndicatorShown(true);
onPartyChanged();
if (!m_flmFtc->enableFileContentModify())
{
ERROR_LOG(m_logger) << "Could enable fileContentModify.";
return false;
}
connect(m_ui->cboParties, qOverload<int>(&QComboBox::currentIndexChanged), this, &HQReportEdit::onPartyChanged);
int partyIndex = m_ui->cboParties->findData(partyId); // in case of notification: onPartyChanged() is called when index changes
m_ui->cboParties->setCurrentIndex(partyIndex < 0 ? 0 : partyIndex);
return true;
}
void HQReportEdit::createModels(const int partyId)
{
const int partyFolderId = m_flmDtc->getPartyFolderId(m_session->exerciseId(), partyId);
if (partyFolderId == 0)
{
WARNING_LOG(m_logger) << "No partyFolderId found for partyId " << partyId;
delete m_planModels.take(partyId);
delete m_hqModels.take(partyId);
return;
}
const int hqReportFolderId = m_flmDtc->findFolder(partyFolderId, QStringLiteral("Messages"));
delete m_planModels.take(partyId);
delete m_hqModels.take(partyId);
auto *planModel = new FlmHQReportModel(m_ui->listViewPlan);
if (!planModel->init(m_session, partyFolderId, FileType::inner_enum::TacticalPlan))
{
WARNING_LOG(m_logger) << "Could not init planModel for partyId " << partyId;
delete planModel;
return;
}
auto *hqReportModel = new FlmHQReportModel(m_ui->listViewMessage);
if (!hqReportModel->init(m_session, hqReportFolderId, FileType::inner_enum::AdlerJson))
{
WARNING_LOG(m_logger) << "Could not init hqReportModel for partyId " << partyId;
delete planModel;
delete hqReportModel;
return;
}
connect(planModel, &FlmHQReportModel::dataAddedOrRemoved, this, &HQReportEdit::slotChangesMade);
m_planModels.insert(partyId, planModel);
m_hqModels.insert(partyId, hqReportModel);
}
bool HQReportEdit::apply()
{
QMap<int, QList<int>> allHqToPlanIds;
QMap<int, QSet<int>> allHqToPlanIds;
for (auto it = m_planModels.begin(); it != m_planModels.end(); ++it)
for (auto it = m_planModels.begin(); it != m_planModels.end(); ++it)
{
QMap<int, QSet<int>> hqToPlanIds = it.value()->getChangedPlans(); // <planId, hq-message ids>
for (auto it = hqToPlanIds.constBegin(); it != hqToPlanIds.constEnd(); ++it)
{
QMap<int, QList<int>> hqToPlanIds = it.value()->getHQToPlan();
for (auto planId : hqToPlanIds.keys())
{
allHqToPlanIds[planId].append(hqToPlanIds[planId]);
it.value()->clearMovedData();
}
allHqToPlanIds[it.key()] += it.value();
}
}
const int currentPartyId = m_ui->cboParties->currentData().toInt();
FlmHqReportConverter* hqRepConv = new FlmHqReportConverter();
const int currentPartyId = m_ui->cboParties->currentData().toInt();
FlmHqReportConverter *hqRepConv = new FlmHqReportConverter();
if (hqRepConv->init(m_session, currentPartyId))
{
DEBUG_LOG(m_logger) << "Add HQ to Converter";
if (hqRepConv->init(m_session, currentPartyId))
{
DEBUG_LOG(m_logger) << "Add HQ to Converter";
hqRepConv->addHqToPlanIds(allHqToPlanIds);
hqRepConv->addHqToPlanIds(allHqToPlanIds);
hqRepConv->processCollectedHqs();
}
hqRepConv->processCollectedHqs();
}
return true;
return true;
}
void HQReportEdit::retranslate()
{
translate(m_ui, tr("HQ Report"));
}
void HQReportEdit::retranslate() { translate(m_ui, tr("HQ Report")); }
void HQReportEdit::onPartyChanged(int index)
{
Q_UNUSED(index);
Q_UNUSED(index);
const int currentPartyId = m_ui->cboParties->currentData().toInt();
DEBUG_LOG(m_logger) << "onPartyChanged " << currentPartyId;
const int currentPartyId = m_ui->cboParties->currentData().toInt();
createModels(currentPartyId);
if (!m_planModels.contains(currentPartyId) || !m_hqModels.contains(currentPartyId))
{
INFO_LOG(m_logger) << "Models for party" << currentPartyId << "not found. Attempting to create...";
createModels(currentPartyId);
}
QAbstractItemModel *hqModel = m_hqModels.value(currentPartyId, nullptr);
QAbstractItemModel *planModel = m_planModels.value(currentPartyId, nullptr);
QAbstractItemModel* hqModel = m_hqModels.value(currentPartyId, nullptr);
QAbstractItemModel* planModel = m_planModels.value(currentPartyId, nullptr);
if (m_ui->listViewMessage->selectionModel())
{
m_ui->listViewMessage->selectionModel()->disconnect(this);
}
if (m_ui->listViewPlan->selectionModel())
{
m_ui->listViewPlan->selectionModel()->disconnect(this);
}
if (m_ui->listViewMessage->selectionModel())
{
m_ui->listViewMessage->selectionModel()->disconnect(this);
}
if (m_ui->listViewPlan->selectionModel())
{
m_ui->listViewPlan->selectionModel()->disconnect(this);
}
m_ui->listViewMessage->setModel(hqModel);
m_ui->listViewPlan->setModel(planModel);
m_ui->listViewMessage->setModel(hqModel);
m_ui->listViewPlan->setModel(planModel);
if (hqModel && planModel)
{
connect(m_ui->listViewMessage->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&HQReportEdit::onSelectionChanged);
connect(m_ui->listViewPlan->selectionModel(), &QItemSelectionModel::selectionChanged, this,
&HQReportEdit::onSelectionChanged);
}
else
{
ERROR_LOG(m_logger) << "Failed to switch to party" << currentPartyId << ": Models still missing.";
}
if (hqModel && planModel)
{
connect(m_ui->listViewMessage->selectionModel(), &QItemSelectionModel::selectionChanged, this, &HQReportEdit::onSelectionChanged);
connect(m_ui->listViewPlan->selectionModel(), &QItemSelectionModel::selectionChanged, this, &HQReportEdit::onSelectionChanged);
}
else
{
ERROR_LOG(m_logger) << "Failed to switch to party" << currentPartyId << ": Models still missing.";
}
}
void HQReportEdit::onCreateNewPlanClicked()
{
bool ok = false;
QString planName =
QInputDialog::getText(this, tr("Enter Plan name"), tr("Name:"), QLineEdit::Normal, QString(), &ok);
bool ok = false;
QString planName = QInputDialog::getText(this, tr("Enter Plan name"), tr("Name:"), QLineEdit::Normal, QString(), &ok);
if (!ok)
{
DEBUG_LOG(m_logger) << "No name for new plan entered.";
if (!ok)
{
DEBUG_LOG(m_logger) << "No name for new plan entered.";
return;
}
return;
}
FlmHQReportModel* planModel = static_cast<FlmHQReportModel*>(m_ui->listViewPlan->model());
FlmHQReportModel *planModel = static_cast<FlmHQReportModel *>(m_ui->listViewPlan->model());
if (planModel == nullptr)
{
ERROR_LOG(m_logger) << "Could not create plan --> no plan model present.";
if (planModel == nullptr)
{
ERROR_LOG(m_logger) << "Could not create plan --> no plan model present.";
return;
}
return;
}
SituationMap::GeometryModel* geometryModel = SituationMap::GeometryModelFactory::singleton()->create();
SituationMap::GeometryModel *geometryModel = SituationMap::GeometryModelFactory::singleton()->create();
if (geometryModel == nullptr)
{
ERROR_LOG(m_logger) << "Could not create plan --> not possible to create GeometryModel.";
if (geometryModel == nullptr)
{
ERROR_LOG(m_logger) << "Could not create plan --> not possible to create GeometryModel.";
return;
}
return;
}
if (m_session == nullptr)
{
ERROR_LOG(m_logger) << "Could not create plan --> not possible to create GeometryModel.";
if (m_session == nullptr)
{
ERROR_LOG(m_logger) << "Could not create plan --> not possible to create GeometryModel.";
return;
}
return;
}
FileManagement::FileContentModifyRequest data;
FileManagement::FileContentModifyRequest data;
data.name(planName.toStdString());
data.isTemplate(false);
data.isHidden(false);
data.folderId(planModel->folderId());
data.fileStatus(FileManagement::FileStatus::Valid);
data.fileCategory(FileManagement::FileCategory::Exercise);
data.fileType(FileManagement::FileType::TacticalPlan);
data.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
data.lastModified(QDateTime::currentMSecsSinceEpoch());
data.content(LtsUtils::convert<std::vector<uint8_t>>(geometryModel->toByteArray()));
data.exerciseId(m_session->exerciseId());
data.name(planName.toStdString());
data.isTemplate(false);
data.isHidden(false);
data.folderId(planModel->folderId());
data.fileStatus(FileManagement::FileStatus::Valid);
data.fileCategory(FileManagement::FileCategory::Exercise);
data.fileType(FileManagement::FileType::TacticalPlan);
data.operatorId(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
data.lastModified(QDateTime::currentMSecsSinceEpoch());
data.content(LtsUtils::convert<std::vector<uint8_t>>(geometryModel->toByteArray()));
data.exerciseId(m_session->exerciseId());
m_flmFtc->fileContentModifyRequest(data, [this](const Core::FunctionReplyObject& reply) {
if (reply.error())
{
const QString errorMessage = tr("Could not save plan: %1").arg(QString::fromStdString(reply.str()));
m_flmFtc->fileContentModifyRequest(data,
[this](const Core::FunctionReplyObject &reply)
{
if (reply.error())
{
const QString errorMessage = tr("Could not save plan: %1").arg(QString::fromStdString(reply.str()));
ERROR_LOG(m_logger) << errorMessage;
ERROR_LOG(m_logger) << errorMessage;
new LtsWidgets::LtsMessageDialogNew(this, errorMessage, tr("Save failed"));
}
});
new LtsWidgets::LtsMessageDialogNew(this, errorMessage, tr("Save failed"));
}
});
}
void HQReportEdit::onSelectionChanged(const QItemSelection&, const QItemSelection&)
void HQReportEdit::onSelectionChanged(const QItemSelection &, const QItemSelection &)
{
m_ui->pbShift->setEnabled(m_ui->listViewMessage->selectionModel()->hasSelection() &&
m_ui->listViewPlan->selectionModel()->hasSelection());
m_ui->pbShift->setEnabled(m_ui->listViewMessage->selectionModel()->hasSelection() && m_ui->listViewPlan->selectionModel()->hasSelection());
}
void HQReportEdit::onShiftClicked()
{
const int currentPartyId = m_ui->cboParties->currentData().toInt();
const int currentPartyId = m_ui->cboParties->currentData().toInt();
FlmHQReportModel* messageModel = m_hqModels.value(currentPartyId);
FlmHQReportModel* planModel = m_planModels.value(currentPartyId);
FlmHQReportModel *messageModel = m_hqModels.value(currentPartyId);
FlmHQReportModel *planModel = m_planModels.value(currentPartyId);
if (messageModel == nullptr || planModel == nullptr)
return;
if (messageModel == nullptr || planModel == nullptr)
return;
const QModelIndex currentMessageIndex = m_ui->listViewMessage->currentIndex();
const QModelIndex currentMessageIndex = m_ui->listViewMessage->currentIndex();
if (!currentMessageIndex.isValid())
return;
if (!currentMessageIndex.isValid())
return;
QMimeData* mimeData = messageModel->mimeData({currentMessageIndex});
QMimeData *mimeData = messageModel->mimeData({currentMessageIndex});
if (mimeData == nullptr)
return;
if (mimeData == nullptr)
return;
if (!planModel->dropMimeData(mimeData, Qt::CopyAction, -1, 0, m_ui->listViewPlan->currentIndex()))
return;
if (!planModel->dropMimeData(mimeData, Qt::CopyAction, -1, 0, m_ui->listViewPlan->currentIndex()))
return;
m_ui->listViewPlan->viewport()->update();
m_ui->listViewPlan->viewport()->update();
}
} // namespace FileManagement
@@ -15,7 +15,7 @@
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="2">
<widget class="QListView" name="listViewPlan"/>
<widget class="QTreeView" name="listViewPlan"/>
</item>
<item row="2" column="2">
<widget class="QLabel" name="lblPlans">
@@ -1,299 +1,430 @@
#include "flm_hq_report_model.h"
#include <QJsonArray>
#include <QJsonDocument>
#include <LtsSession/lts_session.h>
#include <flm_data_plugin_interface.h>
#include <Plugins/FileManagement/flm_data_plugin_interface.h>
namespace FileManagement
{
FlmHQReportModel::FlmHQReportModel(QObject* parent)
: QAbstractListModel(parent), m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger())
FlmHQReportModel::FlmHQReportModel(QObject *parent)
: QAbstractItemModel(parent)
, m_logger(getLogger("HQReportModel"))
{
}
bool FlmHQReportModel::init(LtsSession::LtsSession* session, int contentFolderId, const FileType& fileType)
bool FlmHQReportModel::init(LtsSession::LtsSession *session, int contentFolderId, const FileType &fileType)
{
if (!session)
{
ERROR_LOG(m_logger) << "Got invalid Session";
if (!session)
{
ERROR_LOG(m_logger) << "Got invalid Session";
return false;
}
return false;
}
if (!session->getDtc<FileManagement::DataInterface>(m_flmDtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Dtc";
if (!session->getDtc<FileManagement::DataInterface>(m_flmDtc))
{
ERROR_LOG(m_logger) << "Could not get FLM Dtc";
return false;
}
return false;
}
m_contentFolderId = contentFolderId;
m_fileType = fileType;
m_contentFolderId = contentFolderId;
m_fileType = fileType;
m_flmDtc->enableFileContent();
m_flmDtc->waitForHistoricalDataFileContent(3000);
m_flmDtc->fileContents(
[this](const FileContent& content) { onFileContentChanged(content, DataModification::eAdded); });
m_flmDtc->enableFileContent();
m_flmDtc->waitForHistoricalDataFileContent(3000);
m_flmDtc->fileContents([this](const FileContent &content) { onFileContentChanged(content, DataModification::eAdded); });
connect(m_flmDtc.get(), &Interface::Dtc::fileContentChanged, this, &FlmHQReportModel::onFileContentChanged);
connect(m_flmDtc.get(), &Interface::Dtc::fileContentChanged, this, &FlmHQReportModel::onFileContentChanged);
return true;
return true;
}
int FlmHQReportModel::rowCount(const QModelIndex& parent) const
int FlmHQReportModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid())
return 0;
if (!parent.isValid())
return m_data.count();
if (parent.internalId() != 0)
return 0;
if (parent.row() >= 0 && parent.row() < m_data.size())
{
const HQData &data = m_data.at(parent.row());
auto it = m_movedData.constFind(data.id);
if (it != m_movedData.constEnd())
return it.value().count();
}
return 0;
}
QVariant FlmHQReportModel::data(const QModelIndex& index, int role) const
QModelIndex FlmHQReportModel::parent(const QModelIndex &index) const
{
if (!index.isValid())
return QVariant();
if (role == Qt::DisplayRole)
return createText(index.row());
if (!index.isValid())
return QModelIndex();
return QVariant();
quintptr internalId = index.internalId();
if (internalId == 0)
return QModelIndex();
int parentRow = static_cast<int>(internalId) - 1;
return createIndex(parentRow, 0, quintptr(0));
}
Qt::ItemFlags FlmHQReportModel::flags(const QModelIndex& index) const
QVariant FlmHQReportModel::data(const QModelIndex &index, int role) const
{
Qt::ItemFlags defaultFlags = QAbstractListModel::flags(index);
if (!index.isValid())
return {};
if (!index.isValid())
return defaultFlags;
if (role == Qt::DisplayRole)
{
quintptr internalId = index.internalId();
return defaultFlags | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
if (internalId == 0)
{
if (index.row() >= 0 && index.row() < m_data.size())
return m_data.at(index.row()).name;
}
else // Child-Item
{
int parentRow = static_cast<int>(internalId) - 1;
if (parentRow >= 0 && parentRow < m_data.size())
{
const HQData &parentData = m_data.at(parentRow);
auto it = m_movedData.constFind(parentData.id);
if (it != m_movedData.constEnd())
{
const QList<HQData> &children = it.value();
if (index.row() >= 0 && index.row() < children.size())
return children.at(index.row()).name;
}
}
}
}
return {};
}
Qt::DropActions FlmHQReportModel::supportedDropActions() const
Qt::ItemFlags FlmHQReportModel::flags(const QModelIndex &index) const
{
return Qt::CopyAction;
Qt::ItemFlags defaultFlags = QAbstractItemModel::flags(index);
if (!index.isValid())
return defaultFlags;
return defaultFlags | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
}
Qt::DropActions FlmHQReportModel::supportedDragActions() const
{
return Qt::CopyAction;
}
Qt::DropActions FlmHQReportModel::supportedDropActions() const { return Qt::CopyAction; }
Qt::DropActions FlmHQReportModel::supportedDragActions() const { return Qt::CopyAction; }
QStringList FlmHQReportModel::mimeTypes() const
{
QStringList types;
types << mimeType;
return types;
QStringList types;
types << mimeType;
return types;
}
bool FlmHQReportModel::removeRows(int row, int count, const QModelIndex& parent)
bool FlmHQReportModel::removeRows(int row, int count, const QModelIndex &parent)
{
if (parent.isValid() || row < 0 || row >= m_data.size() || (row + count) > m_data.size())
return false;
if (parent.isValid() || row < 0 || row >= m_data.size() || (row + count) > m_data.size())
return false;
beginRemoveRows(QModelIndex(), row, row + count - 1);
beginRemoveRows(QModelIndex(), row, row + count - 1);
for (int i = 0; i < count; ++i)
m_data.removeAt(row);
for (int i = 0; i < count; ++i)
m_data.removeAt(row);
endRemoveRows();
endRemoveRows();
return true;
return true;
}
QMimeData* FlmHQReportModel::mimeData(const QList<QModelIndex>& indexes) const
QMimeData *FlmHQReportModel::mimeData(const QList<QModelIndex> &indexes) const
{
QMimeData* mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
QMimeData *mimeData = new QMimeData();
QByteArray encodedData;
QDataStream stream(&encodedData, QIODevice::WriteOnly);
for (const QModelIndex& index : indexes)
for (const QModelIndex &index : indexes)
{
if (index.isValid())
{
if (index.isValid())
HQData md;
QString visibleName = index.data(Qt::DisplayRole).toString();
if (index.internalId() != 0)
{
int parentRow = static_cast<int>(index.internalId()) - 1;
if (parentRow >= 0 && parentRow < m_data.size())
{
HQData md = m_data.at(index.row());
stream << md.id << md.name;
const HQData &parentData = m_data.at(parentRow);
const auto &children = m_movedData.value(parentData.id);
if (index.row() >= 0 && index.row() < children.size())
{
md = children.at(index.row());
}
}
}
else
{
if (index.row() >= 0 && index.row() < m_data.size())
{
const HQData &originalData = m_data.at(index.row());
md.id = originalData.id;
md.name = visibleName;
md.properties = originalData.properties;
}
}
md.name = visibleName;
stream << md.id << md.name;
}
mimeData->setData(mimeType, encodedData);
return mimeData;
}
mimeData->setData(mimeType, encodedData);
return mimeData;
}
bool FlmHQReportModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent)
bool FlmHQReportModel::dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent)
{
Q_UNUSED(row)
Q_UNUSED(column)
Q_UNUSED(row)
Q_UNUSED(column)
if (!parent.isValid() || !data->hasFormat(mimeType) || action != Qt::CopyAction)
return false;
if (!parent.isValid() || !data->hasFormat(mimeType) || action != Qt::CopyAction)
return false;
QByteArray encodedData = data->data(mimeType);
QDataStream stream(&encodedData, QIODevice::ReadOnly);
QByteArray encodedData = data->data(mimeType);
QDataStream stream(&encodedData, QIODevice::ReadOnly);
while (!stream.atEnd())
{
HQData md;
if (parent.isValid() && parent.row() >= 0 && parent.row() < m_data.size())
DEBUG_LOG(m_logger) << "DROP ZIEL (Parent im Tree): " << m_data.at(parent.row()).name;
stream >> md.id >> md.name;
while (!stream.atEnd())
{
HQData md;
stream >> md.id >> md.name;
addMovedData(parent.row(), md);
}
DEBUG_LOG(m_logger) << "DROP INHALT aus Stream -> ID: " << md.id << ", NAME: " << md.name;
emit dataAddedOrRemoved();
addMovedData(parent, md);
}
emit dataAddedOrRemoved();
return true;
}
bool FlmHQReportModel::canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const
{
Q_UNUSED(row)
Q_UNUSED(column)
if (!parent.isValid() || !data->hasFormat(mimeType) || action != Qt::CopyAction || parent.row() < 0 || parent.row() >= m_data.size())
return false;
QByteArray encodedData = data->data(mimeType);
QDataStream stream(&encodedData, QIODevice::ReadOnly);
const HQData &currentParentData = m_data.at(parent.row());
if (!m_movedData.contains(currentParentData.id))
return true;
}
bool FlmHQReportModel::canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) const
{
Q_UNUSED(row)
Q_UNUSED(column)
const QList<HQData> &existingChildren = m_movedData.value(currentParentData.id);
if (!parent.isValid() || !data->hasFormat(mimeType) || action != Qt::CopyAction || parent.row() < 0 ||
parent.row() >= m_data.size())
while (!stream.atEnd())
{
HQData incomingData;
stream >> incomingData.id >> incomingData.name;
for (const HQData &child : existingChildren)
{
if (child.id == incomingData.id)
return false;
QByteArray encodedData = data->data(mimeType);
QDataStream stream(&encodedData, QIODevice::ReadOnly);
const HQData& currentData = m_data.at(parent.row());
if (!m_movedData.contains(currentData.id))
return true;
const QList<HQData>& movedDataListForCurrentData = m_movedData.value(currentData.id);
while (!stream.atEnd())
{
HQData movedData;
stream >> movedData.id >> movedData.name;
if (movedDataListForCurrentData.contains(movedData))
return false;
}
return true;
}
return true;
}
void FlmHQReportModel::addHQReportData(const HQData& data)
QModelIndex FlmHQReportModel::index(int row, int column, const QModelIndex &parent) const
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_data.append(data);
endInsertRows();
if (!hasIndex(row, column, parent))
return QModelIndex();
if (!parent.isValid())
{
if (row >= 0 && row < m_data.size())
return createIndex(row, column, quintptr(0)); // internalId = 0 für Parents
}
else
{
if (parent.internalId() == 0)
{
int parentRow = parent.row();
return createIndex(row, column, quintptr(parentRow + 1));
}
}
return QModelIndex();
}
void FlmHQReportModel::addHQReportData(const HQData &data)
{
QList<HQData> childProperties;
HQData copyData = data;
if (!data.properties.empty())
{
QJsonDocument doc = QJsonDocument::fromJson(QByteArray::fromStdString(data.properties));
// Hole Einträge aus den properties
if (doc.isArray())
{
QJsonArray jsonArray = doc.array();
for (const QJsonValue &value : jsonArray)
{
QString prop = value.toString().trimmed();
if (!prop.isEmpty() && prop != data.name)
{
HQData childData;
childData.id = data.id;
childData.name = prop;
copyData.children.insert(childData.id);
childProperties.append(childData);
}
}
}
else
{
QString prop = QString::fromStdString(data.properties).trimmed();
if (!prop.isEmpty() && prop != data.name)
{
HQData childData;
childData.id = data.id;
childData.name = prop;
childProperties.append(childData);
}
}
}
beginInsertRows(QModelIndex(), m_data.count(), m_data.count());
m_data.append(copyData);
if (!childProperties.isEmpty())
m_movedData.insert(data.id, childProperties);
endInsertRows();
}
void FlmHQReportModel::deleteHQReportData(const HQData& data)
void FlmHQReportModel::deleteHQReportData(const HQData &data)
{
beginInsertRows(QModelIndex(), rowCount(), rowCount());
endInsertRows();
const int zeile = m_data.indexOf(data);
const int zeile = m_data.indexOf(data);
if (zeile == -1)
{
return;
}
beginRemoveRows(QModelIndex(), zeile, zeile);
m_data.removeAt(zeile);
endRemoveRows();
if (zeile == -1)
return;
beginRemoveRows(QModelIndex(), zeile, zeile);
m_data.removeAt(zeile);
endRemoveRows();
return;
}
void FlmHQReportModel::onFileContentChanged(const FileContent& content, DataModification modType)
void FlmHQReportModel::onFileContentChanged(const FileContent &content, DataModification modType)
{
HQData data;
data.id = content.id();
data.name = QString::fromStdString(content.name());
if (content.folderId() != m_contentFolderId || content.fileType() != m_fileType)
return;
if (content.folderId() != m_contentFolderId || content.fileType() != m_fileType)
return;
if (content.fileStatus() == FileStatus::Deleted)
{
if (modType == DataModification::eModified || modType == DataModification::eAdded)
{
deleteHQReportData(data);
}
}
else if (modType == DataModification::eAdded)
{
addHQReportData(data);
}
HQData data;
data.id = content.id();
data.name = QString::fromStdString(content.name());
data.properties = content.properties();
DEBUG_LOG(m_logger) << "FlmHQReportModel::onFileContentChanged " << "properties " << data.properties << " " << " Name: " << data.name;
if (content.fileStatus() == FileStatus::Deleted)
{
if (modType == DataModification::eModified || modType == DataModification::eAdded)
deleteHQReportData(data);
}
else if (modType == DataModification::eAdded)
{
addHQReportData(data);
}
}
int FlmHQReportModel::folderId() const
{
return m_contentFolderId;
}
int FlmHQReportModel::folderId() const { return m_contentFolderId; }
QMap<int, QList<int>> FlmHQReportModel::getHQToPlan() const
QMap<int, QSet<int>> FlmHQReportModel::getChangedPlans() const
{
QMap<int, QList<int>> hqToPlan;
QMap<int, QSet<int>> hqToPlan;
for (auto it = m_movedData.constBegin(); it != m_movedData.constEnd(); ++it)
for (auto it = m_movedData.constBegin(); it != m_movedData.constEnd(); ++it)
{
const QList<HQData> &movedData = it.value();
QSet<int> hqIds;
hqIds.reserve(movedData.size());
for (const HQData &currentData : movedData)
hqIds.insert(currentData.id);
HQData myPlan;
for (const auto &plan : m_data)
{
const QList<HQData>& movedData = it.value();
QList<int> hqIds;
hqIds.reserve(movedData.size());
for (const HQData& currentData : movedData)
hqIds.append(currentData.id);
hqToPlan.insert(it.key(), hqIds);
if (plan.id == it.key())
{
myPlan = plan;
break;
}
}
if (myPlan.children != hqIds)
hqToPlan.insert(it.key(), hqIds);
}
return hqToPlan;
return hqToPlan;
}
void FlmHQReportModel::clearMovedData()
{
m_movedData.clear();
if (m_movedData.isEmpty())
return;
emit dataAddedOrRemoved();
emit dataChanged(index(0, 0), index(rowCount() - 1, 0));
beginResetModel();
m_movedData.clear();
endResetModel();
emit dataAddedOrRemoved();
}
QString FlmHQReportModel::createText(int dataIndex) const
void FlmHQReportModel::addMovedData(const QModelIndex &parentIndex, const HQData &movedData)
{
DEBUG_LOG(m_logger) << Q_FUNC_INFO << " dataIndex: " << dataIndex;
int dataIndex = parentIndex.row();
if (dataIndex < 0 || dataIndex >= m_data.size())
return;
if (dataIndex < 0 || dataIndex >= m_data.size())
return QString();
const HQData &data = m_data.at(dataIndex);
const HQData& data = m_data.at(dataIndex);
if (data.id == movedData.id)
{
DEBUG_LOG(m_logger) << "DROP ABGEWIESEN: PlanId entspricht der ReportId (" << data.id << ")";
return;
}
if (!m_movedData.contains(data.id))
if (!m_movedData.contains(data.id))
m_movedData.insert(data.id, QList<HQData>());
const QList<HQData> &existingChildren = m_movedData[data.id];
for (const HQData &child : existingChildren)
{
if (child.id == movedData.id || child.name.trimmed() == movedData.name.trimmed())
{
DEBUG_LOG(m_logger) << "No moved data for " << data.name;
return data.name;
DEBUG_LOG(m_logger) << "DROP ABGEWIESEN: Element '" << movedData.name << "' ist bereits vorhanden.";
return;
}
}
const QList<HQData>& movedData = m_movedData.value(data.id);
QStringList movedDataNames;
int newRow = m_movedData[data.id].size();
movedDataNames.reserve(movedData.size());
for (const HQData& currentMovedData : movedData)
movedDataNames.append(currentMovedData.name);
return QString(QStringLiteral("%1 (%2)")).arg(data.name).arg(movedDataNames.join(QLatin1Char(',')));
beginInsertRows(parentIndex, newRow, newRow);
m_movedData[data.id].append(movedData);
endInsertRows();
}
void FlmHQReportModel::addMovedData(int dataIndex, const HQData& movedData)
{
DEBUG_LOG(m_logger) << Q_FUNC_INFO << " dataIndex: " << dataIndex << ", movedData.id: " << movedData.id
<< ", movedData.name: " << movedData.name;
if (dataIndex < 0 || dataIndex >= m_data.size())
return;
const HQData& data = m_data.at(dataIndex);
if (!m_movedData.contains(data.id))
m_movedData.insert(data.id, QList<HQData>());
m_movedData[data.id].append(movedData);
}
} // namespace FileManagement
@@ -1,21 +1,22 @@
#pragma once
#include <FileManagement/flm_enums.hpp>
#include <Lts/Services/FileManagement/logger.h>
#include <LtsUtils/LtsUtilsCore/data_modification_enum.h>
#include <QtCore/QAbstractListModel>
#include <QtCore/QByteArray>
#include <QtCore/QDataStream>
#include <QtCore/QList>
#include <QAbstractListModel>
#include <QByteArray>
#include <QDataStream>
#include <QMimeData>
#include <QtCore/QObject>
#include <QtGui/QStandardItemModel>
#include <QObject>
#include <QSet>
#include <QStandardItemModel>
#include <FileManagement/flm_enums.hpp>
#include <FileManagement/logger.h>
#include <LtsUtilsCore/data_modification_enum.h>
namespace FileManagement
{
class FileContent;
namespace Interface
{
class Dtc;
@@ -31,64 +32,64 @@ namespace FileManagement
{
struct HQData
{
int id;
QString name;
int id{0};
QString name;
std::string properties;
QSet<int> children;
bool operator==(const HQData& other) const
{
return id == other.id && name == other.name;
}
bool operator==(const HQData &other) const { return id == other.id && name == other.name; }
};
class FlmHQReportModel : public QAbstractListModel
class FlmHQReportModel : public QAbstractItemModel
{
Q_OBJECT
Q_OBJECT
public:
explicit FlmHQReportModel(QObject* parent = nullptr);
explicit FlmHQReportModel(QObject *parent = nullptr);
bool init(LtsSession::LtsSession* session, int contentFolderId, const FileManagement::FileType& fileType);
bool init(LtsSession::LtsSession *session, int contentFolderId, const FileManagement::FileType &fileType);
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
Qt::DropActions supportedDropActions() const override;
Qt::DropActions supportedDragActions() const override;
QStringList mimeTypes() const override;
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
Qt::DropActions supportedDropActions() const override;
Qt::DropActions supportedDragActions() const override;
QStringList mimeTypes() const override;
bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex()) override;
QMimeData* mimeData(const QList<QModelIndex>& indexes) const override;
bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) override;
bool canDropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column,
const QModelIndex& parent) const override;
QMimeData *mimeData(const QList<QModelIndex> &indexes) const override;
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
bool canDropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) const override;
QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override { return 1; }
QModelIndex parent(const QModelIndex &index) const override;
void addHQReportData(const HQData& data);
void deleteHQReportData(const HQData& data);
void addHQReportData(const HQData &data);
void deleteHQReportData(const HQData &data);
int folderId() const;
int folderId() const;
QMap<int, QList<int>> getHQToPlan() const;
void clearMovedData();
QMap<int, QSet<int>> getChangedPlans() const;
void clearMovedData();
private:
NGL::INGLLogger& m_logger;
QString createText(int dataIndex) const;
void addMovedData(int dataIndex, const HQData& movedData);
void addMovedData(const QModelIndex &parentIndex, const HQData &movedData);
private Q_SLOTS:
void onFileContentChanged(const FileContent& content, DataModification modType);
void onFileContentChanged(const FileContent &content, DataModification modType);
Q_SIGNALS:
void dataAddedOrRemoved();
void dataAddedOrRemoved();
private:
QList<HQData> m_data;
QMap<int, QList<HQData>> m_movedData;
const QString mimeType = QStringLiteral("application/x-custom-hqdata");
int m_contentFolderId{-1};
FileManagement::FileType m_fileType;
std::shared_ptr<FileManagement::Interface::Dtc> m_flmDtc;
QList<HQData> m_data;
QMap<int, QList<HQData>> m_movedData;
const QString mimeType = QStringLiteral("application/x-custom-hqdata");
int m_contentFolderId{-1};
FileManagement::FileType m_fileType;
std::shared_ptr<FileManagement::Interface::Dtc> m_flmDtc;
LOGGER_T m_logger;
};
} // namespace FileManagement