179 lines
5.2 KiB
C++
Executable File
179 lines
5.2 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* Topic Editor for the Plan Topic in the Script Editor
|
|
* $Id: topic_editor.cpp 48499 2019-09-26 07:56:34Z ojog_i $
|
|
* $HeadURL: svn://slssvn/TDS/branches/product/devel/trunk/Lts/Plugins/FileManagement/Gui/Explorer/TopicEditor/topic_editor.cpp $
|
|
* $Author: ojog_i $
|
|
*
|
|
* Created by Mike Wille, NLE, 2019-11-11
|
|
*/
|
|
|
|
#include "topic_editor.h"
|
|
#include "ui_topic_editor.h"
|
|
#include "../plan_overlays_gui_plugin.h"
|
|
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <NGLLogger/NGLLoggerBootstrap.h>
|
|
#include <TopicEditorBase/topic_previewer.h>
|
|
|
|
#include <QInputDialog>
|
|
#include <QJsonObject>
|
|
#include <QJsonArray>
|
|
#include <QMessageBox>
|
|
#include <QPushButton>
|
|
|
|
|
|
namespace PlanOverlaysPlugin
|
|
{
|
|
|
|
PlanTopicEditor::PlanTopicEditor(
|
|
ForeignGuiInterface **ifc, const std::shared_ptr<FileManagement::Interface::Dtc> &flmDtc, QWidget *parent
|
|
)
|
|
: TopicEditorBase::TopicEditor(parent)
|
|
, m_ifc(ifc)
|
|
, m_flmDtc(flmDtc)
|
|
, m_model(nullptr)
|
|
, m_ui(new Ui::PlanTopicEditor)
|
|
, m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("PlanTopicEditor"))
|
|
{
|
|
// init UI
|
|
m_ui->setupUi(this);
|
|
init(m_ui->widget);
|
|
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Edit, tr("Manage Plan Overlays"));
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &PlanTopicEditor::onOpenPlanOverlayDialog);
|
|
if ((*m_ifc) == nullptr)
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
|
|
return;
|
|
}
|
|
else
|
|
m_ui->lblReadOnly->hide();
|
|
|
|
m_model = (*m_ifc)->planOverlayModel();
|
|
|
|
#ifndef LTS_DEBUG
|
|
if (LtsSessionData::LtsSessionData::getInstance()->debugFlagValue(QStringLiteral("PlanOverlays.TopicEditor.ShowFakeButton")) == QVariant(true))
|
|
#endif
|
|
{
|
|
QPushButton *pb = new QPushButton(QStringLiteral("[fake compatibility mode data]"));
|
|
layout()->addWidget(pb);
|
|
connect(pb, &QPushButton::clicked,
|
|
this, [this]()
|
|
{
|
|
// fake data to test compatibility mode:
|
|
m_topicData.properties = QJsonObject();
|
|
bool k = true;
|
|
int fileId = QInputDialog::getInt(this, QStringLiteral("fileId"), QStringLiteral("Enter the file id of an existing plan overlay"), 1003, 0, 999999, 1, &k);
|
|
if (!k)
|
|
{
|
|
QMessageBox::critical(this, QStringLiteral("nan"), QStringLiteral("nan!"));
|
|
return;
|
|
}
|
|
m_topicData.properties[QStringLiteral("FileId")] = fileId;
|
|
updateInternalData();
|
|
});
|
|
}
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Script_Editor-Add_Tactical_Plan_Topic"));
|
|
}
|
|
|
|
PlanTopicEditor::~PlanTopicEditor()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PRIVATE
|
|
|
|
void PlanTopicEditor::updateInternalData()
|
|
{
|
|
if (!hasTopicDataProperties())
|
|
return;
|
|
|
|
m_planItems = QJsonArray(); // reset
|
|
|
|
// compatibility for old plan type topics (old topic only had ONE plan and was determined by only its 'FileId')
|
|
int fileId = getTopicDataValue(QStringLiteral("FileId")).toInt(-1);
|
|
|
|
if (fileId != -1)
|
|
{
|
|
DEBUG_LOG(m_logger) << "topic compatibility mode - converting..";
|
|
|
|
QJsonObject fakePlanItem;
|
|
fakePlanItem[QStringLiteral("keyId")] = 0;
|
|
fakePlanItem[QStringLiteral("fileId")] = fileId;
|
|
QString fileName;
|
|
if (m_flmDtc)
|
|
fileName = QString::fromStdString(m_flmDtc->fileContent(fileId).name());
|
|
if (fileName.isEmpty())
|
|
fileName = tr("Plan file id %1").arg(fileId);
|
|
fakePlanItem[QStringLiteral("fileName")] = fileName;
|
|
fakePlanItem[QStringLiteral("opacity")] = 1.0; // otherwise opacity is 0 and the user can't see it
|
|
m_planItems += fakePlanItem;
|
|
}
|
|
else
|
|
m_planItems = getTopicDataValue(QStringLiteral("PlanItems")).toArray();
|
|
|
|
|
|
if (m_planItems.isEmpty())
|
|
{
|
|
WARNING_LOG(m_logger) << "topic empty";
|
|
return;
|
|
}
|
|
|
|
retable();
|
|
}
|
|
|
|
void PlanTopicEditor::retranslate()
|
|
{
|
|
translate(m_ui, tr("Plan Topic Editor"));
|
|
}
|
|
|
|
|
|
void PlanTopicEditor::retable()
|
|
{
|
|
while (m_ui->plans->rowCount())
|
|
m_ui->plans->removeRow(m_ui->plans->rowCount() - 1);
|
|
|
|
for (auto i = m_planItems.constBegin(); i != m_planItems.constEnd(); ++i)
|
|
{
|
|
m_ui->plans->insertRow(0);
|
|
m_ui->plans->setItem(0, 0, new QTableWidgetItem((*i).toObject()[QStringLiteral("fileName")].toString(tr("(unknown)"))));
|
|
}
|
|
}
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
// PRIVATE SLOTS
|
|
|
|
bool PlanTopicEditor::apply2()
|
|
{
|
|
m_topicData.properties.remove(QStringLiteral("FileId")); // remove old plan file id (if available)
|
|
setTopicDataProperty(QStringLiteral("PlanItems"), m_planItems);
|
|
setDescription(m_ui->widget->description());
|
|
m_ui->widget->previewer()->setTopicData(m_topicData);
|
|
return true;
|
|
}
|
|
|
|
|
|
void PlanTopicEditor::onOpenPlanOverlayDialog()
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false); // disable until already opened plan overlay dialog was closed or fully disable because essentials view was closed
|
|
|
|
if ((*m_ifc) == nullptr)
|
|
{
|
|
new LtsWidgets::LtsMessageDialogNew(this, tr("Plans can't be edited because essentials view was closed"));
|
|
return;
|
|
}
|
|
|
|
connect((*m_ifc)->openPlanOverlayDialog(m_planItems, true), &QWidget::destroyed, this, [this]()
|
|
{
|
|
m_planItems = m_model->toJson();
|
|
retable();
|
|
slotChangesMade();
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit);
|
|
});
|
|
}
|
|
|
|
} // namespace PlanOverlaysPlugin
|