Continues migration with DDS, Common

This commit is contained in:
torsten committed 2026-07-17 12:41:42 +02:00
1 parent 9b15cee841
commit fa48db111e
668 files changed
+111841 -2

No files matched your search

+318
View File
@@ -0,0 +1,318 @@
#include "topic_editor_utils.h"
#include <QColor>
#include <QHash>
#include <QIcon>
#include <QJsonDocument>
#include <QJsonObject>
#include <QLabel>
#include <QString>
namespace TopicEditorBase
{
QString topicTypeTranslation(TopicType topicType)
{
switch (topicType)
{
case TopicType::SituationMap:
return QLabel::tr("SituationMap");
case TopicType::SituationReplay:
return QLabel::tr("SituationReplay");
case TopicType::Image:
return QLabel::tr("Image");
case TopicType::Text:
return QLabel::tr("Text");
case TopicType::Pdf:
return QLabel::tr("Pdf");
case TopicType::Xml:
return QLabel::tr("Xml");
case TopicType::TacticalPlan:
return QLabel::tr("TacticalPlan");
case TopicType::MSOffice:
return QLabel::tr("MSOffice");
case TopicType::OpenOffice:
return QLabel::tr("OpenOffice");
case TopicType::Audio:
return QLabel::tr("Audio");
case TopicType::Video:
return QLabel::tr("Video");
case TopicType::Building:
return QLabel::tr("Building");
case TopicType::SituationMapFilter:
return QLabel::tr("SituationMapFilter");
case TopicType::Snapshot:
return QLabel::tr("Snapshot");
case TopicType::Evaluation:
return QLabel::tr("Evaluation");
case TopicType::Report:
return QLabel::tr("Report");
case TopicType::Situation:
return QLabel::tr("Situation");
case TopicType::Invalid:
default:
return QLabel::tr("Invalid");
}
Q_UNREACHABLE();
}
QString topicTypeString(TopicType topicType)
{
switch (topicType)
{
case TopicType::SituationMap:
return QStringLiteral("SituationMap");
case TopicType::SituationReplay:
return QStringLiteral("SituationReplay");
case TopicType::Image:
return QStringLiteral("Image");
case TopicType::Text:
return QStringLiteral("Text");
case TopicType::Pdf:
return QStringLiteral("Pdf");
case TopicType::Xml:
return QStringLiteral("Xml");
case TopicType::TacticalPlan:
return QStringLiteral("TacticalPlan");
case TopicType::MSOffice:
return QStringLiteral("MSOffice");
case TopicType::OpenOffice:
return QStringLiteral("OpenOffice");
case TopicType::Audio:
return QStringLiteral("Audio");
case TopicType::Video:
return QStringLiteral("Video");
case TopicType::Building:
return QStringLiteral("Building");
case TopicType::SituationMapFilter:
return QStringLiteral("SituationMapFilter");
case TopicType::Snapshot:
return QStringLiteral("Snapshot");
case TopicType::Evaluation:
return QStringLiteral("Evaluation");
case TopicType::Report:
return QStringLiteral("Report");
case TopicType::Situation:
return QStringLiteral("Situation");
case TopicType::Invalid:
default:
return QStringLiteral("Invalid");
}
Q_UNREACHABLE();
}
TopicType topicTypeFromString(const QString &topicName)
{
static const QHash<QString, TopicType> topics =
{
{ QStringLiteral("Invalid"), TopicType::Invalid },
{ QStringLiteral("SituationMap"), TopicType::SituationMap },
{ QStringLiteral("SituationReplay"), TopicType::SituationReplay },
{ QStringLiteral("Image"), TopicType::Image },
{ QStringLiteral("Text"), TopicType::Text },
{ QStringLiteral("Pdf"), TopicType::Pdf },
{ QStringLiteral("Xml"), TopicType::Xml },
{ QStringLiteral("TacticalPlan"), TopicType::TacticalPlan },
{ QStringLiteral("MSOffice"), TopicType::MSOffice },
{ QStringLiteral("OpenOffice"), TopicType::OpenOffice },
{ QStringLiteral("Audio"), TopicType::Audio },
{ QStringLiteral("Video"), TopicType::Video },
{ QStringLiteral("Building"), TopicType::Building },
{ QStringLiteral("SituationMapFilter"), TopicType::SituationMapFilter },
{ QStringLiteral("Snapshot"), TopicType::Snapshot },
{ QStringLiteral("Evaluation"), TopicType::Evaluation },
{ QStringLiteral("Report"), TopicType::Report },
{ QStringLiteral("Situation"), TopicType::Situation },
};
return topics.contains(topicName) ? topics.value(topicName) : TopicType::Invalid;
}
QIcon topicIcon(const TopicType topicType)
{
switch (topicType)
{
case TopicType::SituationMap:
return QIcon(QLatin1String("icon:add_situation.svg"));
case TopicType::Situation:
return QIcon(QLatin1String("icon:add_situation_combined.svg"));
case TopicType::SituationReplay:
return QIcon(QLatin1String("icon:add_restart.svg"));
case TopicType::Image:
return QIcon(QLatin1String("icon:create_image_topic.svg"));
case TopicType::Text:
return QIcon(QLatin1String("icon:document-new-txt.svg"));
case TopicType::Pdf:
return QIcon(QLatin1String("icon:create_pdf_topic.svg"));
case TopicType::Xml:
return QIcon(QLatin1String("icon:document-new-xml.svg"));
case TopicType::TacticalPlan:
return QIcon(QLatin1String("icon:tactical_organization.svg"));
case TopicType::MSOffice:
return QIcon(QLatin1String("icon:ms_office.svg"));
case TopicType::OpenOffice:
return QIcon(QLatin1String("icon:documents.svg"));
case TopicType::Audio:
return QIcon(QLatin1String("icon:create_lecture_topic.svg"));
case TopicType::Video:
return QIcon(QLatin1String("icon:add_video_menu.svg"));
case TopicType::Building:
return QIcon(QLatin1String("icon:configure_buildings.svg"));
case TopicType::SituationMapFilter:
return QIcon(QLatin1String("icon:filter_player.svg"));
case TopicType::Snapshot:
return QIcon(QLatin1String("icon:create_snapshot.svg"));
case TopicType::Evaluation:
return QIcon(QLatin1String("icon:add_evaluation_elements.svg"));
case TopicType::Report:
return QIcon(QLatin1String("icon:add_reports_display.svg"));
case TopicType::Invalid:
default:
return QIcon();
}
Q_UNREACHABLE();
}
QColor topicTypeColor(TopicType topicType)
{
switch (topicType)
{
case TopicType::SituationMap:
return QRgb(0xb1cbbb);
case TopicType::SituationReplay:
return QRgb(0xc94c4c);
case TopicType::Image:
return QRgb(0xfefbd8);
case TopicType::Text:
return QRgb(0x92a8d1);
case TopicType::Pdf:
return QRgb(0x80ced6);
case TopicType::Xml:
return QRgb(0xeea29a);
case TopicType::TacticalPlan:
return QRgb(0xdac292);
case TopicType::MSOffice:
return QRgb(0xf7cac9);
case TopicType::OpenOffice:
return QRgb(0xb2b2b2);
case TopicType::Audio:
return QRgb(0x034f84);
case TopicType::Video:
return QRgb(0x618685);
case TopicType::Building:
return QRgb(0xc6bcb6);
case TopicType::SituationMapFilter:
return QRgb(0x36486b);
case TopicType::Snapshot:
return QRgb(0xf18973);
case TopicType::Evaluation:
return QRgb(0xd6cbd3);
case TopicType::Report:
return QRgb(0xfeb236);
case TopicType::Situation:
return QRgb(0xb1c1cb);
case TopicType::Invalid:
default:
return Qt::black;
}
Q_UNREACHABLE();
return {};
}
std::ostream& operator<<(std::ostream& stream, TopicType topicType)
{
stream << "TopicType::" << topicTypeString(topicType).toStdString().c_str();
return stream;
}
const QString TopicData::mime = QStringLiteral("application/rheinmetall.topiceditorbase.topicdata");
TopicData::TopicData(TopicType topicType)
: topicType(topicType)
{}
TopicData::TopicData(TopicType topicType, int duration)
: topicType(topicType)
, duration(duration)
{}
TopicData::TopicData(
int id, TopicType topicType, int startTime, int duration, const QString &description, const QString &channel,
const QJsonObject &properties
)
: topicType(topicType)
, id(id)
, startTime(startTime)
, duration(duration)
, properties(properties)
, description(description)
, channel(channel)
{}
void TopicData::fromJson(const QJsonObject &obj)
{
id = obj[QStringLiteral("topicId")].toInt();
topicType = static_cast<TopicType>(obj[QStringLiteral("type")].toInt());
startTime = obj[QStringLiteral("startTime")].toInt(-1);
duration = obj[QStringLiteral("length")].toInt(-1);
state = obj[QStringLiteral("isSet")].toBool();
index = obj[QStringLiteral("index")].toInt();
properties = obj[QStringLiteral("detailData")].toObject();
description = obj[QStringLiteral("description")].toString();
channel = obj[QStringLiteral("channelName")].toString();
parentChannel = obj[QStringLiteral("filterParentChannel")].toString();
x = obj[QStringLiteral("x")].toDouble();
y = obj[QStringLiteral("y")].toDouble();
w = obj[QStringLiteral("w")].toDouble();
h = obj[QStringLiteral("h")].toDouble();
}
QJsonObject TopicData::toJson() const
{
return QJsonObject({
{ QStringLiteral("topicId"), id },
{ QStringLiteral("startTime"), startTime },
{ QStringLiteral("length"), duration },
{ QStringLiteral("type"), static_cast<int>(topicType) },
{ QStringLiteral("isSet"), state },
{ QStringLiteral("index"), index },
{ QStringLiteral("detailData"), properties },
{ QStringLiteral("description"), description },
{ QStringLiteral("channelName"), channel },
{ QStringLiteral("filterParentChannel"), parentChannel },
{ QStringLiteral("x"), x },
{ QStringLiteral("y"), y },
{ QStringLiteral("w"), w },
{ QStringLiteral("h"), h }
});
}
QDataStream &operator<<(QDataStream &stream, const TopicData &data)
{
const QByteArray properties = QJsonDocument(data.properties).toBinaryData();
stream << data.id << static_cast<quint8>(data.topicType) << data.startTime << data.duration << data.state << data.index
<< properties << data.description << data.channel << data.parentChannel << data.x << data.y << data.w << data.h;
return stream;
}
QDataStream &operator >>(QDataStream &stream, TopicData &data)
{
QByteArray properties;
quint8 topicType;
stream >> data.id >> topicType >> data.startTime >> data.duration >> data.state >> data.index >> properties
>> data.description >> data.channel >> data.parentChannel >> data.x >> data.y >> data.w >> data.h;
data.topicType = static_cast<TopicType>(topicType);
data.properties = QJsonDocument::fromBinaryData(properties).object();
return stream;
}
}