Files
qt6-migration-pipeline/Lts/Common/TopicEditorBase/topic_editor_base.cpp
T

123 lines
2.3 KiB
C++
Executable File

#include "topic_editor_base.h"
#include "topic_preview_widget.h"
#include <LtsWidgets/lts_dialog.h>
#include <QMessageBox>
#include <QDebug>
namespace TopicEditorBase
{
TopicEditor::TopicEditor(QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_previewWidget(nullptr)
{
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
}
void TopicEditor::setTopicData(const TopicEditorBase::TopicData &data)
{
m_topicData = data;
m_topicDuration = data.duration;
if (m_previewWidget == nullptr)
{
QMessageBox::critical(
nullptr, QStringLiteral("An den Entwickler!"),
QStringLiteral("!! STOP !! - Dieser Topic Editor hatte 'init()' vorher nicht aufgerufen!")
);
return;
}
m_previewWidget->setTopicData(m_topicData);
bool isAlreadyUnchangeable = unchangeable();
if (!isAlreadyUnchangeable)
setUnchangeable(true);
updateInternalData();
if (!isAlreadyUnchangeable)
setUnchangeable(false);
}
void TopicEditor::setDuration(int duration)
{
m_topicData.duration = duration;
updateInternalLength();
}
void TopicEditor::init(TopicPreviewWidget *widget)
{
m_previewWidget = widget;
connect(m_previewWidget, &TopicPreviewWidget::deleteMe,
this, &TopicEditor::deleteLater);
m_previewWidget->setTopicEnabled(false);
connect(this, &TopicEditor::signalChangesMade, this, [this]()
{
m_previewWidget->setTopicEnabled(false);
});
}
void TopicEditor::setTopicDataProperty(const QString &key, const QJsonValue &value)
{
m_topicData.properties[key] = value;
emit signalChangesMade();
}
void TopicEditor::applied()
{
m_previewWidget->setTopicEnabled(true);
emit topicDataChanged();
}
void TopicEditor::setIsPlaying(bool isPlaying)
{
m_isPlaying = isPlaying;
}
bool TopicEditor::apply()
{
if (m_previewWidget == nullptr)
{
QMessageBox::critical(
nullptr, QStringLiteral("An den Entwickler!"),
QStringLiteral("!! STOP !! - Dieser Topic Editor hatte 'init()' vorher nicht aufgerufen!")
);
return false;
}
if (m_isPlaying)
{
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Please Stop Playback first"));
return false;
}
bool result = apply2();
if (result)
applied();
return result;
}
}