178 lines
5.9 KiB
C++
Executable File
178 lines
5.9 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for Messaging - Messaging Overview Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-10-05
|
|
*/
|
|
|
|
#include "msg_messaging.h"
|
|
#include "ui_msg_messaging.h"
|
|
#include "msg_show_message_dialog.h"
|
|
#include "msg_new_message_dialog.h"
|
|
|
|
#include <LtsSession/lts_session_manager.h>
|
|
#include <LtsSession/lts_session_data.h>
|
|
|
|
#include <LtsPrinting/printing.h>
|
|
#include <QTreeView>
|
|
|
|
namespace Messaging
|
|
{
|
|
|
|
MessagingView::MessagingView(const QString &menuGroup, LtsSession::LtsSession *session, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_menuGroup(menuGroup)
|
|
, m_model(nullptr)
|
|
, m_box(MessagingModel::Box::InBox)
|
|
, m_dtc(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_opmCbxDtc(nullptr)
|
|
, m_uniqueMsgId(0)
|
|
, m_session(session)
|
|
, m_ui(new Ui::MessagingView)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_logger(getLogger("MessagingDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->widget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
// connects fuer Widgetaenderungen
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &MessagingView::onSelectionChanged);
|
|
|
|
// Show-Button erzeugen
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Show, this, &MessagingView::onShowMessage);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, false);
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked, this, &MessagingView::onShowMessage);
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalEnterPressed, this, &MessagingView::onShowMessage);
|
|
|
|
// Create Add-Button
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &MessagingView::onNewMessage);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, true);
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Add, tr("Add"));
|
|
|
|
|
|
// Create Remove-Button
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &MessagingView::onRemoveMessage);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &MessagingView::onPrint);
|
|
|
|
} // end of ctor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
MessagingView::~MessagingView()
|
|
{
|
|
delete m_ui;
|
|
} // end of dtor()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MessagingView::retranslate()
|
|
{
|
|
translate(m_ui, m_box == MessagingModel::Box::InBox ? tr("Inbox") : tr("Outbox"));
|
|
}
|
|
|
|
bool MessagingView::init(const std::shared_ptr<Messaging::Interface::Dtc> &dtc,
|
|
const std::shared_ptr<Messaging::Interface::Ftc> &ftc,
|
|
const std::shared_ptr<ParticipantManagement::Interface::Dtc> &ppmDtc,
|
|
const std::shared_ptr<TrainingAreaBaseOC::Interface::Dtc> &tabocDtc,
|
|
const std::shared_ptr<OperatorManagement::ForeignGuiComboboxInterface> &opmCbxDtc,
|
|
const MessagingModel::Box &box)
|
|
{
|
|
if (!dtc || !ftc || !opmCbxDtc)
|
|
return false;
|
|
|
|
m_dtc = dtc;
|
|
m_ftc = ftc;
|
|
m_opmCbxDtc = opmCbxDtc;
|
|
m_box = box;
|
|
|
|
m_model = new MessagingModel(this);
|
|
m_model->initModel(m_dtc, ppmDtc, tabocDtc, m_session, m_box);
|
|
m_proxyModel = new MessagingProxyModel(this);
|
|
m_proxyModel->setSourceModel(m_model);
|
|
m_ui->widget->setModel(m_proxyModel);
|
|
|
|
#ifndef LTS_DEBUG
|
|
m_ui->widget->hideColumn(0);
|
|
#endif
|
|
|
|
m_ui->widget->setSortIndicator(1, Qt::AscendingOrder);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Function_Group_Messages"));
|
|
/*
|
|
if (m_box == MessagingModel::Box::InBox)
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Inbox"));
|
|
else
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Outbox"));
|
|
*/
|
|
|
|
return true;
|
|
} // end of init()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MessagingView::onSelectionChanged() // aka. enaDisa
|
|
{
|
|
QModelIndexList selectedRows = m_ui->widget->selectedRows();
|
|
const int cntSelectedRows = selectedRows.size();
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, cntSelectedRows == 1);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, cntSelectedRows == 1);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Show, cntSelectedRows == 1);
|
|
} // end of onSelectionChanged()
|
|
//-----------------------------------------------------------------------------
|
|
|
|
void MessagingView::onShowMessage()
|
|
{
|
|
const QModelIndex idx = m_ui->widget->currentIndex();
|
|
|
|
int row = idx.row();
|
|
if (row < 0)
|
|
return;
|
|
|
|
Messaging::OperatorMessage operatorMessage = m_model->getRowData(row);
|
|
|
|
ShowMessageDialog *dialog = new ShowMessageDialog(m_session, this);
|
|
dialog->init(m_dtc, m_ftc, m_opmCbxDtc, m_box, operatorMessage, m_menuGroup);
|
|
|
|
addDialog(dialog, m_menuGroup, QStringLiteral("msgShowMessage%1").arg(operatorMessage.id()), LtsWidgets::LayoutArea::eDialogTab);
|
|
|
|
} // end of onShowMessage()
|
|
|
|
|
|
// Window to create and send a new Message
|
|
void MessagingView::onNewMessage()
|
|
{
|
|
NewMessageDialog *dialog = new NewMessageDialog(m_session);
|
|
dialog->init(m_dtc, m_ftc, m_opmCbxDtc);
|
|
addDialog(dialog, m_menuGroup, QStringLiteral("msgNewMessage%1").arg(m_uniqueMsgId++), LtsWidgets::LayoutArea::eDialogTab);
|
|
} // end of onNewMessage()
|
|
|
|
// Window to remove a Message
|
|
void MessagingView::onRemoveMessage()
|
|
{
|
|
m_requestHelper->startSingleRequest([this]()
|
|
{
|
|
return m_ftc->modifyOperatorMessageRequest(ModifyOperatorMessageRequest(m_model->getRowData(m_ui->widget->currentIndex().row()).id(), false, false, true), this);
|
|
});
|
|
|
|
// TODO: enaDisa !! or does a view trigger it, because the selection might have changed?
|
|
|
|
} // end of onRemoveMessage()
|
|
|
|
void MessagingView::onPrint()
|
|
{
|
|
LtsPrinting::printView(m_session, this, m_ui->widget->treeView());
|
|
}
|
|
|
|
void MessagingView::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
} // namespace Messaging
|