151 lines
4.1 KiB
C++
Executable File
151 lines
4.1 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Philipp Last, NLSE, 2018-01-11
|
|
*/
|
|
|
|
#include "evl_comments.h"
|
|
#include "ui_evl_comments.h"
|
|
#include "evl_comment_model.h"
|
|
|
|
#include <LtsSession/lts_session_data.h>
|
|
#include <PluginInterfaces/data_plugin_interface.h>
|
|
|
|
#include <QKeyEvent>
|
|
|
|
namespace Evaluations
|
|
{
|
|
EvlCommentsView::EvlCommentsView(const std::shared_ptr<Interface::Dtc> &evlDtc,
|
|
const std::shared_ptr<OperatorManagement::Interface::Dtc> &opmDtc,
|
|
QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly),
|
|
m_ui(new Ui::EvlCommentsDialog),
|
|
m_evlDtc(evlDtc),
|
|
m_opmDtc(opmDtc),
|
|
m_logger(getLogger("EvlComments::EvlCommentsView"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Display_O-C_Evaluations"));
|
|
|
|
m_ui->m_tableComments->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
connect(m_ui->m_tableComments, &LtsDataView::LtsDataView::signalDoubleClicked, this, &EvlCommentsView::onLtsDataView_DoubleClicked);
|
|
|
|
m_model = new EvlCommentDataViewModel(this);
|
|
m_proxyModel = new EvlCommentDataViewProxyModel(this);
|
|
m_proxyModel->setSourceModel(m_model);
|
|
m_ui->m_tableComments->setModel(m_proxyModel);
|
|
|
|
m_ui->m_tableComments->installEventFilter(this);
|
|
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Ok)->hide();
|
|
m_buttonBox->getButton(LtsWidgets::DialogButton::Apply)->hide();
|
|
|
|
// Get historical comments
|
|
auto cb = [this](const Evaluations::EvaluationComment & c)
|
|
{
|
|
insertComment(c);
|
|
};
|
|
m_evlDtc->evaluationComments(cb);
|
|
|
|
// Subscribe for new comments
|
|
connect(m_evlDtc.get(), &Evaluations::Interface::Dtc::evaluationCommentChanged, this, &EvlCommentsView::onCommentChanged, Qt::UniqueConnection);
|
|
}
|
|
|
|
|
|
EvlCommentsView::~EvlCommentsView()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
|
|
void EvlCommentsView::retranslate()
|
|
{
|
|
translate(m_ui, tr("Display O/C Evaluations"));
|
|
}
|
|
|
|
|
|
bool EvlCommentsView::eventFilter(QObject *object, QEvent *event)
|
|
{
|
|
if (object == m_ui->m_tableComments)
|
|
{
|
|
if (event->type() == QEvent::KeyPress)
|
|
{
|
|
QKeyEvent *pKeyEvent = static_cast<QKeyEvent *>(event);
|
|
// Enter: Enter on numpad
|
|
if (pKeyEvent->key() == Qt::Key_Return || pKeyEvent->key() == Qt::Key_Enter)
|
|
onLtsDataView_DoubleClicked();
|
|
}
|
|
}
|
|
|
|
return LtsWidgets::LtsDialog::eventFilter(object, event);
|
|
}
|
|
|
|
void EvlCommentsView::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->m_tableComments->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
|
|
void EvlCommentsView::onLtsDataView_DoubleClicked()
|
|
{
|
|
const QModelIndex idx = m_ui->m_tableComments->currentIndex();
|
|
|
|
if (idx.row() >= 0)
|
|
{
|
|
Evaluations::CommentTuple row = m_model->getRowData(idx.row());
|
|
LtsWidgets::LtsMessageDialog::showMessage(this, tr("Comment:") + QStringLiteral("\n") + row.m_text);
|
|
}
|
|
}
|
|
|
|
|
|
void EvlCommentsView::onCommentChanged(const EvaluationComment &data, DataModification modType)
|
|
{
|
|
switch (modType)
|
|
{
|
|
case DataModification::eAdded:
|
|
insertComment(data);
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool EvlCommentsView::insertComment(const Evaluations::EvaluationComment &c)
|
|
{
|
|
QString strSenderOperatorName, strReceiverOperatorName;
|
|
|
|
OperatorManagement::User sender = m_opmDtc->user(c.senderOperatorId());
|
|
strSenderOperatorName = QString::fromStdString(sender.name());
|
|
|
|
if (c.receiverOperatorId().is_set())
|
|
{
|
|
// Add only if receiver id matches to the current operator!
|
|
OperatorManagement::User loggedInOperator = m_opmDtc->user(LtsSessionData::LtsSessionData::getInstance()->getOperatorId());
|
|
|
|
if (c.receiverOperatorId().get() != loggedInOperator.id())
|
|
return false;
|
|
|
|
OperatorManagement::User receiver = m_opmDtc->user(c.receiverOperatorId().get());
|
|
strReceiverOperatorName = QString::fromStdString(receiver.name());
|
|
}
|
|
|
|
CommentTuple t;
|
|
t.m_commentId = c.id();
|
|
t.m_timestamp = QDateTime::fromMSecsSinceEpoch(c.ts());
|
|
t.m_sender = strSenderOperatorName;
|
|
t.m_receiver = strReceiverOperatorName;
|
|
t.m_text = QString::fromStdString(c.text());
|
|
t.m_hierarchy = QString::fromStdString(c.hierarchy());
|
|
|
|
return m_model->insertRow(t);
|
|
}
|
|
}
|
|
|