Files
qt5-legatus-legacy/Lts/Plugins/ParticipantManagement/Gui/MSDL/ppm_msdl_edit.cpp
T
2026-08-13 18:33:10 +02:00

273 lines
8.6 KiB
C++
Executable File

/**
* @RDE_HEADER@
* $Id$
* $HeadURL$
* $Author$
* Created by Philipp Last, SLSE, 2017-10-26
*/
#include "ppm_msdl_edit.h"
#include "ui_ppm_msdl_edit.h"
#include "msdl/msdl_import.h"
#include "msdl/msdl_export.h"
#include <QAction>
#include <AdvancedSymbology/asb_data_plugin_interface.h>
#include <Common/participant_edit_model.h>
#include <Common/participant_edit_item.h>
#include <Common/participant_tree_edit_handler.h>
#include <Common/participant_distype_editor.h>
#include <QTreeView>
namespace ParticipantManagement
{
MSDLEdit::MSDLEdit(LtsSession::LtsSession *session, QWidget *parent)
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
, m_actionRemove(nullptr)
, m_actionEdit(nullptr)
, m_ppmDtc(nullptr)
, m_ppmFtc(nullptr)
, m_ppmGuiCbxIfc(nullptr)
, m_session(session)
, m_pTreehandlerSystem(nullptr)
, m_pTreehandlerImport(nullptr)
, m_pModelSystem(nullptr)
, m_pModelImport(nullptr)
, m_ui(new Ui::MSDLDialog)
, m_logger(getLogger("MSDLEdit"))
{
m_ui->setupUi(this);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &MSDLEdit::onAddItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &MSDLEdit::onEditItem);
connect(m_ui->m_pushButton_Import, &QPushButton::clicked, this, &MSDLEdit::onImport);
connect(m_ui->m_pushButton_Export, &QPushButton::clicked, this, &MSDLEdit::onExport);
connect(m_ui->m_pushButton_distypeEditor, &QPushButton::clicked, this, &MSDLEdit::onDistypeEditor);
setOnlineHelpFilename(QStringLiteral("Situation-Import-Export_MSDL"));
m_ui->m_treeViewEdit_Right->treeView()->setDragDropMode(QAbstractItemView::DragOnly);
m_ui->m_treeViewEdit_Right->treeView()->setSelectionMode(QAbstractItemView::SingleSelection);
m_ui->m_treeViewEdit_Right->treeView()->setDragEnabled(true);
m_ui->m_treeViewEdit_Left->treeView()->setDragDropMode(QAbstractItemView::DropOnly);
m_ui->m_treeViewEdit_Left->treeView()->setAcceptDrops(true);
m_ui->m_treeViewEdit_Left->treeView()->setDropIndicatorShown(true);
}
MSDLEdit::~MSDLEdit()
{
delete m_pTreehandlerImport;
delete m_pTreehandlerSystem;
delete m_ui;
}
void MSDLEdit::retranslate()
{
translate(m_ui, tr("MSDL Import/Export"));
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty, ForeignGuiComboboxInterface::CbxPartyFilter::Normal);
}
void MSDLEdit::onDistypeEditor()
{
ParticipantManagement::DistypeEditor dialog(this, m_ppmDtc, m_ppmFtc);
dialog.exec();
}
void MSDLEdit::onImport()
{
m_pModelImport->resetModel();
m_pModelImport->setMimeType(QStringLiteral("MSDLDialog"));
m_pModelSystem->setMimeType(QStringLiteral("MSDLDialog"));
msdl::ImportMsdl dialog(m_pModelImport, QModelIndex(), this, m_session);
dialog.exec(); // TODO: use show(), use signals & slots !
m_pTreehandlerImport->beautifyTreeView(false);
}
void MSDLEdit::onExport()
{
msdl::ExportMsdl dialog(m_session, this);
dialog.exec(); // TODO: use show(), use signals & slots !
}
bool MSDLEdit::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc)
{
if (!dtc || !ftc || !ppmGuiCbxIfc)
{
m_ui->m_pushButton_Import->setEnabled(false);
m_ui->m_pushButton_Export->setEnabled(false);
m_ui->m_pushButton_distypeEditor->setEnabled(false);
return false;
}
m_ppmDtc = dtc;
m_ppmFtc = ftc;
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(m_asb);
m_pModelImport = new ParticipantEditModel(this, m_ppmDtc, m_asb);
m_ui->m_treeViewEdit_Right->setModel(m_pModelImport);
m_pModelSystem = new ParticipantEditModel(this, m_ppmDtc, m_asb);
connect(m_pModelSystem, &ParticipantEditModel::internalDataChanged, this, &MSDLEdit::slotChangesMade);
m_ui->m_treeViewEdit_Left->setModel(m_pModelSystem);
m_ui->m_treeViewEdit_Left->setContextMenuPolicy(Qt::CustomContextMenu);
m_actionRemove = new QAction(QIcon(QLatin1String("icon:remove.svg")), tr("Remove"), this);
m_actionEdit = new QAction(QIcon(QLatin1String("icon:edit.svg")), tr("Edit"), this);
connect(m_ui->cbParty, static_cast<void (LtsWidgets::LtsComboBox::*)(int)>(&LtsWidgets::LtsComboBox::currentIndexChanged),
this, &MSDLEdit::onPartyChanged);
m_ppmGuiCbxIfc->fillPartyComboBox(m_ui->cbParty, ForeignGuiComboboxInterface::CbxPartyFilter::Normal);
m_pTreehandlerSystem = new ParticipantTreeEditHandler(m_ui->m_treeViewEdit_Left, m_ppmDtc, m_ppmFtc, false);
connect(m_actionRemove, &QAction::triggered, m_pTreehandlerSystem, &ParticipantTreeEditHandler::onRemoveItem);
connect(m_actionEdit, &QAction::triggered, this, &MSDLEdit::onEditItem);
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, m_pTreehandlerSystem, &ParticipantTreeEditHandler::onRemoveItem);
connect(m_pTreehandlerSystem, &ParticipantTreeEditHandler::signalDoubleClicked, this, &MSDLEdit::onEditItem);
connect(m_pTreehandlerSystem, &ParticipantTreeEditHandler::signalSelectionChanged, this, &MSDLEdit::onEnaDisa);
connect(m_pTreehandlerSystem, &ParticipantTreeEditHandler::signalChangesMade, this, &MSDLEdit::onEnaDisa);
// Editing not allowed, just enable context menu (Collapse/Expand item)
m_pTreehandlerImport = new ParticipantTreeEditHandler(m_ui->m_treeViewEdit_Right, m_ppmDtc, m_ppmFtc, false);
onPartyChanged();
onEnaDisa();
return true;
}
void MSDLEdit::onPartyChanged()
{
const int newPartyId = m_ui->cbParty->currentData().toInt();
if (hasUnsavedChanges())
{
switch (askApplyDiscardCancel())
{
case LtsWidgets::Button::Apply:
if (!apply())
return;
break;
case LtsWidgets::Button::Cancel:
m_ui->cbParty->setCurrentIndex(m_ui->cbParty->findData(m_pModelSystem->partyId(), Qt::UserRole));
return;
case LtsWidgets::Button::Discard:
__unchange__(); // can't call resetChanges() by myself :(
break;
default:
break;
}
}
// DEBUG_LOG(m_logger) << LOGFUNCTION << " onPartyChanged !!! -> newPartyId=" << newPartyId;
// m_ui->cbParty->setEnabled(false); // will be re-enabled with reply (::lock, ::unlock)
// tryLockTopicNew(QStringLiteral("LockParty"), newPartyId);
m_pTreehandlerSystem->partyHasChanged(newPartyId, false);
}
bool MSDLEdit::apply()
{
return m_pTreehandlerSystem->onApplyChanges();
}
void MSDLEdit::lock()
{
m_ui->cbParty->setEnabled(true); // true!!
}
void MSDLEdit::unlock()
{
m_ui->cbParty->setEnabled(true);
}
void MSDLEdit::tableColumnOrganiserSetting()
{
//LtsColumnOrganiser
m_ui->m_treeViewEdit_Left->setColumnsOrganiserEnabled(identifier(), true);
m_ui->m_treeViewEdit_Right->setColumnsOrganiserEnabled(identifier(), true);
}
void MSDLEdit::onEnaDisa()
{
bool enableAdd = false;
bool enableEdit = false;
bool enableRemove = false;
if (m_pTreehandlerSystem->isSelectedIndexValid())
{
if (m_pTreehandlerSystem->isContainer()) //only add to units
enableAdd = true;
if (m_pTreehandlerSystem->isSelectedIndexRemovable())
enableRemove = true;
enableEdit = true;
}
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, enableAdd);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, enableEdit);
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, enableRemove);
m_actionRemove->setEnabled(enableRemove);
m_actionEdit->setEnabled(enableEdit);
}
void MSDLEdit::onAddItem()
{
ParticipantEditItem *newItemDlg = new ParticipantEditItem(false, m_session, this);
newItemDlg->setAttribute(Qt::WA_DeleteOnClose);
if (!newItemDlg->init(m_pTreehandlerSystem->selectedIndexView(),
m_ui->cbParty->currentData().toInt(),
m_ppmDtc, m_ppmGuiCbxIfc, m_asb))
{
newItemDlg->deleteLater();
return;
}
connect(newItemDlg, &ParticipantEditItem::addItem, m_pModelSystem, &ParticipantEditModel::onInsertRow);
newItemDlg->show();
onEnaDisa();
}
void MSDLEdit::onEditItem()
{
if (!m_pTreehandlerSystem->isSelectedIndexValid())
return;
ParticipantManagement::ParticipantData data = m_pTreehandlerSystem->getSelectedData();
ParticipantEditItem *newItemDlg = new ParticipantEditItem(false, m_session, this);
if (!newItemDlg->init(m_pTreehandlerSystem->selectedIndexView(),
m_ui->cbParty->currentData().toInt(),
m_ppmDtc, m_ppmGuiCbxIfc, m_asb, data))
{
newItemDlg->deleteLater();
return;
}
connect(newItemDlg, &ParticipantEditItem::updateItem, m_pModelSystem, &ParticipantEditModel::onUpdateRow);
newItemDlg->exec();
onEnaDisa();
}
} //namespace ParticipantManagement