Files
qt5-legatus-legacy/Lts/Common/TopicEditorBase/topic_editor_base.h
T
2026-08-13 18:33:10 +02:00

135 lines
3.7 KiB
C++
Executable File

/**
* @RDE_HEADER@
* Base Class of Topic Editor for the Script Editor (not the Script Player)
* $Id$
* $HeadURL$
* $Author$
*
* Created by Mike Wille, SLSE, 2017-04-27
*/
#pragma once
#include "topic_editor_utils.h"
#include <TopicEditorBase/topiceditorbase_export.h>
#include <LtsWidgets/lts_dialog.h>
#include <LtsUtilsCore/promise.h>
#include <QJsonArray>
#include <QJsonObject>
namespace LtsUtils { class Promise; }
namespace TopicEditorBase
{
class TopicPreviewWidget;
class TOPICEDITORBASE_EXPORT ExportNotifier : public QObject // TODO: Where to put this class? Qt6 needs Promises !!!!!
{
Q_OBJECT
public:
ExportNotifier(QObject *parent)
: QObject(parent)
{}
bool isSuccessful = false;
QString successMessage;
void setExportSuccessful(const QString &message)
{
isSuccessful = true;
successMessage = message;
emit exportSuccessful(message);
emit exportFinished();
}
void setExportFailed()
{
isSuccessful = false;
successMessage = QString();
emit exportFailed();
emit exportFinished();
}
signals:
void stillAlive();
void exportSuccessful(const QString &);
void exportFailed();
void exportFinished();
};
class TOPICEDITORBASE_EXPORT TopicEditor: public LtsWidgets::LtsDialog
{
Q_OBJECT
public:
explicit TopicEditor(QWidget *parent = nullptr);
virtual ~TopicEditor() = default;
TopicData &topicData() { return m_topicData; }
void setTopicData(const TopicData &data);
int topicId() const { return m_topicData.id; }
int startTime() const { return m_topicData.startTime; }
void setStartTime(int start) { m_topicData.startTime = start; }
int duration() const { return m_topicData.duration; }
void setDuration(int duration);
QString description() const { return m_topicData.description; }
void setDescription(const QString &description) { m_topicData.description = description; }
TopicPreviewWidget *topicPreviewWidget() { return m_previewWidget; }
protected:
void init(TopicPreviewWidget *widget);
/**
* @brief updateInternalData is called after the dialog was automatically changed to read-only mode, also the topic preview widget was already updated
* because of the read-only mode, any updates to the ui will not trigger a changes made signal (keeping ok / apply buttons disabled (if already))
* do not reset the preview widget, this was already done automatically before calling this method
*/
virtual void updateInternalData() = 0;
virtual void updateInternalLength() {} // override if your topic is sensitive to topic length changes - e.g. the replay topic, as the end time changes when the length changes
TopicType topicType() const { return m_topicData.topicType; }
QJsonValue getTopicDataValue(const QString &key) const { return m_topicData.properties.value(key); }
QJsonArray getTopicVDataAsArray(const QString &key) const { return m_topicData.properties.value(key).toArray(); }
bool hasTopicDataProperties() const { return !m_topicData.properties.isEmpty(); }
void setTopicDataProperty(const QString &key, const QJsonValue &value);
void applied(); // execute if apply was successful
public slots:
virtual bool apply2() = 0;
void setIsPlaying(bool isPlaying);
private slots:
bool apply() override final;
signals:
void topicDataChanged(); // Do not emit yourself.
void topicEditorRequested(const TopicData &);
void durationCheckRequested(int duration, LtsUtils::Promise *promise);
void signalSetTopicPosition(QWidget *widget, int ignoreTopicForReplay);
void changesSaved(const TopicData &data);
protected:
TopicData m_topicData;
int m_topicDuration{-1};
bool m_isPlaying {false};
TopicPreviewWidget *m_previewWidget{nullptr};
};
} // namespace TopicEditorBase