234 lines
8.1 KiB
C++
Executable File
234 lines
8.1 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for ParticipantManagement - Template Overview Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-10-05
|
|
*/
|
|
|
|
#include "participant_template_chooser.h"
|
|
#include "ui_participant_template_chooser.h"
|
|
#include "CustomView/template.h"
|
|
|
|
#include "participant_template_edit.h"
|
|
#include "template_unit_namer.h"
|
|
|
|
#include <LtsSession/lts_session_manager.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <LtsAppManager/lts_app_manager.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <LtsPluginManager/lts_plugin_manager.h>
|
|
#include <LtsAppDescriptor/lts_app_descriptor.h>
|
|
#include <Plugins/AdvancedSymbology/asb_data_plugin_interface.h>
|
|
|
|
#include <LtsPrinting/printing.h>
|
|
#include <QTreeView>
|
|
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
|
|
ParticipantTemplateChooser::ParticipantTemplateChooser(const QString &menuGroup,
|
|
bool asSupportService,
|
|
LtsSession::LtsSession *session,
|
|
QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_menuGroup(menuGroup)
|
|
, m_asSupportService(asSupportService)
|
|
, m_model(nullptr)
|
|
, m_dtc(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_ppmGuiCbxIfc(nullptr)
|
|
, m_ppmGuiOrgChartIfc(nullptr)
|
|
, m_session(session)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_ui(new Ui::ParticipantTemplateChooser)
|
|
, m_logger(getLogger("ParticipantTemplateChooser"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->widget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
if (m_asSupportService)
|
|
setOnlineHelpFilename(QStringLiteral("Administrator-Support_Templates"));
|
|
else
|
|
setOnlineHelpFilename(QStringLiteral("Administrator-Participant_Templates"));
|
|
}
|
|
|
|
ParticipantTemplateChooser::~ParticipantTemplateChooser()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
void ParticipantTemplateChooser::retranslate()
|
|
{
|
|
translate(m_ui, m_asSupportService ? tr("Support Templates") : tr("Participant Templates"));
|
|
}
|
|
|
|
void ParticipantTemplateChooser::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
bool ParticipantTemplateChooser::init(const std::shared_ptr<ParticipantManagement::Interface::Dtc> &dtc,
|
|
const std::shared_ptr<ParticipantManagement::Interface::Ftc> &ftc,
|
|
const std::shared_ptr<ForeignGuiComboboxInterface> &ppmGuiCbxIfc,
|
|
const std::shared_ptr<ForeignGuiOrgChartInterface> &ppmGuiOrgChartIfc)
|
|
{
|
|
if (!dtc || !ftc || !ppmGuiCbxIfc)
|
|
return false;
|
|
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
m_ppmGuiCbxIfc = ppmGuiCbxIfc;
|
|
m_ppmGuiOrgChartIfc = ppmGuiOrgChartIfc;
|
|
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(m_asbIfc);
|
|
m_model = new ParticipantTemplateChooserModel(m_asSupportService, this);
|
|
m_model->initModel(m_session, m_dtc);
|
|
m_ui->widget->setModel(m_model, [this]() { return new CustomViewTemplate(this); });
|
|
//m_ui->widget->treeView()->header()->setSectionResizeMode(QHeaderView::ResizeToContents); // schön wäre es ...
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &ParticipantTemplateChooser::onAddTemplate);
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked,
|
|
this, &ParticipantTemplateChooser::onEditTemplate);
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, [this]
|
|
{
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, m_ui->widget->selectedRows().size());
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, m_ui->widget->selectedRows().size());
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, m_ui->widget->selectedRows().size());
|
|
});
|
|
|
|
const LtsAppDescriptor::AppDescriptionVector &vec = LtsAppManager::LtsAppManager::getInstance()->getAvailableApps();
|
|
for (const LtsAppDescriptor::AppDescription &descr : vec)
|
|
{
|
|
if (descr.id == LtsAppDescriptor::App::OrgChart && descr.active && m_ppmGuiOrgChartIfc)
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &ParticipantTemplateChooser::onEditTemplateOrgChart);
|
|
}
|
|
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &ParticipantTemplateChooser::onEditTemplate);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &ParticipantTemplateChooser::onRemoveTemplate);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &ParticipantTemplateChooser::onPrint);
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Print);
|
|
|
|
return true;
|
|
}
|
|
|
|
|
|
//SLOTS
|
|
|
|
void ParticipantTemplateChooser::onAddTemplate()
|
|
{
|
|
TemplateUnitNamer *namer = new TemplateUnitNamer(m_asSupportService, m_dtc, m_ppmGuiCbxIfc, this);
|
|
QObject::connect(namer, &TemplateUnitNamer::rejected, namer, &TemplateUnitNamer::deleteLater);
|
|
|
|
QObject::connect(namer, &TemplateUnitNamer::newUnitTemplateRoot, this, [this](const ParticipantManagement::TemplateData &tempData)
|
|
{
|
|
ModifyTemplateDataRequest req;
|
|
req.data({tempData});
|
|
|
|
m_requestHelper->addRequest([this,req]()
|
|
{
|
|
return m_ftc->modifyTemplateDataRequest(req, this);
|
|
});
|
|
m_requestHelper->startRequests();
|
|
});
|
|
|
|
namer->show();
|
|
}
|
|
|
|
void ParticipantTemplateChooser::onEditTemplate()
|
|
{
|
|
|
|
QModelIndex idx = m_ui->widget->currentIndex();
|
|
if (!idx.isValid())
|
|
return;
|
|
|
|
TemplateParticipant data = m_model->getRowData(m_ui->widget->currentIndex().row());
|
|
ParticipantTemplateEdit *edit = new ParticipantTemplateEdit(m_session, data.templateId(), m_asSupportService, this);
|
|
if (!edit->init(m_dtc, m_ftc, m_ppmGuiCbxIfc, m_asbIfc))
|
|
{
|
|
delete edit;
|
|
return;
|
|
}
|
|
addDialog(edit, m_menuGroup, QLatin1String("editTemplate") + QString::number(data.templateId()), LtsWidgets::LayoutArea::eDialogTab);
|
|
}
|
|
|
|
void ParticipantTemplateChooser::onEditTemplateOrgChart()
|
|
{
|
|
if(!m_ppmGuiOrgChartIfc)
|
|
return;
|
|
QModelIndex idx = m_ui->widget->currentIndex();
|
|
if (!idx.isValid())
|
|
return;
|
|
|
|
TemplateParticipant data = m_model->getRowData(idx.row());
|
|
|
|
// Was genau passiert hier??
|
|
//maybe add skip payload to create app'?
|
|
LtsSession::DdsConnectionParams connParams(m_session->connParams());
|
|
|
|
LtsSessionData::LtsSessionData::getInstance()->setPartitionPreset(connParams.partitionId, connParams.partitionType); // skip exc chooser
|
|
|
|
LtsPluginManager::LtsPluginManager *app = LtsAppManager::LtsAppManager::getInstance()->createApp(LtsAppDescriptor::App::OrgChart, connParams);
|
|
|
|
connect(app, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
|
this, [this, app, data, connParams]()
|
|
{
|
|
disconnect(app, &LtsPluginManager::LtsPluginManager::signalInitializationFinished,
|
|
this, nullptr);
|
|
|
|
LtsSession::LtsSession *session = app->getSession(connParams.partitionType, connParams.partitionId);
|
|
|
|
if (session == nullptr)
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Could not start Organisation Application properly."));
|
|
return;
|
|
}
|
|
|
|
if (!session->getForeignGuiInterface(m_ppmGuiOrgChartIfc))
|
|
{
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Unable to start Organisation Application properly."));
|
|
return;
|
|
}
|
|
|
|
m_ppmGuiOrgChartIfc->loadTemplate(data.templateId(), m_asSupportService);
|
|
});
|
|
|
|
//LtsSessionData::LtsSessionData::getInstance()->clear();
|
|
}
|
|
|
|
void ParticipantTemplateChooser::onRemoveTemplate()
|
|
{
|
|
QModelIndex idx = m_ui->widget->currentIndex();
|
|
if (!idx.isValid())
|
|
return;
|
|
|
|
const TemplateParticipant tmplParticipant = m_model->getRowData(idx.row());
|
|
auto tmplData = m_dtc->convertFromParticipantTemplateToTemplateData(tmplParticipant);
|
|
tmplData.isDeleted(true);
|
|
|
|
ModifyTemplateDataRequest req;
|
|
req.data({tmplData});
|
|
|
|
m_requestHelper->startSingleRequest([this, req]()
|
|
{
|
|
return m_ftc->modifyTemplateDataRequest(req, this);
|
|
});
|
|
}
|
|
|
|
void ParticipantTemplateChooser::onPrint()
|
|
{
|
|
LtsPrinting::printView(m_session, this, m_ui->widget->treeView() );
|
|
}
|
|
|
|
|
|
} //namespace ParticipantManagement
|