Files
qt6-migration-pipeline/Lts/Common/PluginInterfaces/topic_replay_interface.h
T

125 lines
2.6 KiB
C++
Executable File

#pragma once
#include <TopicEditorBase/topic_editor_utils.h>
#include <QJsonObject>
#include <QVector>
class QWidget;
namespace TopicEditorBase { class ExportNotifier; }
namespace TopicReplay
{
class Interface
{
public:
static QJsonObject timeRange(qint64 start, qint64 end)
{
return { {QStringLiteral("start"), start}, {QStringLiteral("end"), end} };
}
struct SituationReplayTime
{
int id = 0;
qint64 topicStart_s = -1;
qint64 topicEnd_s = -1;
qint64 replayStart_ms = -1;
qint64 replayEnd_ms = -1;
double replaySpeedFactor = 1;
QJsonObject toReplayInformation() const
{
return {
{QStringLiteral("id"), id},
{QStringLiteral("timeInPresentation"), timeRange(topicStart_s * 1000, topicEnd_s * 1000)},
};
}
QJsonObject toPlaybackTime(double max) const
{
QJsonObject ret = timeRange(replayStart_ms, std::min(replayEnd_ms * replaySpeedFactor, max));
ret[QStringLiteral("replaySpeedFactor")] = replaySpeedFactor;
return ret;
}
QJsonObject toJson(double maxReplayEndMs) const
{
return {
{QStringLiteral("playbackTime"), toPlaybackTime(maxReplayEndMs)},
{QStringLiteral("replayInformation"), toReplayInformation()},
};
}
};
Interface() = default;
virtual ~Interface() = default;
virtual QWidget *createWidget() { return nullptr; }
virtual bool playbackInit(const QJsonObject &attributes) { Q_UNUSED(attributes); return true; }
virtual bool playbackStart(int secondsOffset) { Q_UNUSED(secondsOffset); return true; }
virtual bool playbackPause() { return true; }
virtual bool playbackStop() { return true; }
virtual void setExportPlaybackTimes(
qint64 startTimeSec, qint64 durationSec, const QVector<SituationReplayTime> &sitReplayTimes
)
{
Q_UNUSED(startTimeSec);
Q_UNUSED(durationSec);
Q_UNUSED(sitReplayTimes);
}
virtual bool exportTopic(
const QJsonObject &attributes, const QString &strFolderPath, TopicEditorBase::ExportNotifier *pExportNotifier
) = 0;
virtual QVector<TopicEditorBase::TopicData> additionalTrackEntries(const QJsonObject &attributes) const
{
Q_UNUSED(attributes);
return {};
}
virtual QVector<TopicEditorBase::TopicData> additionalTrackEntries(const QJsonObject &attributes, bool &keepOriginalTopic) const
{
keepOriginalTopic = true;
return additionalTrackEntries(attributes);
}
virtual void setBasePath(const QString &basePath) { Q_UNUSED(basePath); }
};
class Factory
{
public:
virtual ~Factory() = default;
virtual Interface *createInterface(TopicEditorBase::TopicType topicType) = 0;
};
}