217 lines
6.6 KiB
C++
Executable File
217 lines
6.6 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for Observer Controller - Fault Message Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2018-03-27
|
|
*/
|
|
|
|
#include "osc_fault_message.h"
|
|
#include "ui_osc_fault_message.h"
|
|
#include <AdvancedSymbology/asb_data_plugin_interface.h>
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
|
|
namespace OcSituationClient
|
|
{
|
|
|
|
FaultMessage::FaultMessage(LtsSession::LtsSession *session, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::OkApplyCancel)
|
|
, m_session(session)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_selectedEqNr(-1)
|
|
, m_maxChars(255)
|
|
, m_maxPartChars(35)
|
|
, m_ownEquipmentId(0)
|
|
, m_model(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_tabocDtc(nullptr)
|
|
, m_ppmCbxGui(nullptr)
|
|
, m_ui(new Ui::FaultMessage)
|
|
, m_logger(getLogger("FaultMessageDialog"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->lblCountMax->setText(QString::number(m_maxChars));
|
|
m_ui->lblCount->setText(QString::number(0));
|
|
m_ui->lblDevCountMax->setText(QString::number(m_maxPartChars));
|
|
m_ui->lblDevCount->setText(QString::number(0));
|
|
connect(m_ui->teComment, &QPlainTextEdit::textChanged, this, &FaultMessage::onTextChanged);
|
|
connect(m_ui->leDevice, &QLineEdit::textChanged, this, &FaultMessage::onDevTextChanged);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("OC-Fault_Message"));
|
|
|
|
}
|
|
|
|
FaultMessage::~FaultMessage()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
bool FaultMessage::init(const std::shared_ptr<Interface::Ftc> &ftc)
|
|
{
|
|
if (!ftc)
|
|
return false;
|
|
|
|
m_ftc = ftc;
|
|
std::shared_ptr<ParticipantManagement::Interface::Dtc> dtcPpm;
|
|
if (!m_session->getDtc<ParticipantManagement::DataInterface>(dtcPpm))
|
|
return false;
|
|
|
|
if (!m_session->getDtc<TrainingAreaBaseOC::DataInterface>(m_tabocDtc))
|
|
return false;
|
|
|
|
if (!m_session->getForeignGuiInterface<ParticipantManagement::ForeignGuiComboboxInterface>(m_ppmCbxGui))
|
|
return false;
|
|
#ifdef TABLET_MODE
|
|
//css didn"t worked
|
|
m_ui->dvParticipants->setIconSize(QSize(50,50));
|
|
#endif
|
|
std::shared_ptr<AdvancedSymbology::ForeignDataInterface> asb;
|
|
m_session->getForeignDataInterface<AdvancedSymbology::DataInterface>(asb);
|
|
m_model = new ParticipantManagement::ParticipantEditModel(this, dtcPpm, asb);
|
|
// only needed to set recursiveFilteringEnabled
|
|
m_proxyModel = new ParticipantManagement::ParticipantTreeFilterProxyModel(this);
|
|
m_proxyModel->setSourceModel(m_model);
|
|
m_proxyModel->setRecursiveFilteringEnabled(true);
|
|
m_ui->dvParticipants->setModel(m_proxyModel);
|
|
|
|
m_ppmCbxGui->fillPartyComboBox(m_ui->cbParty);
|
|
connect(m_ui->dvParticipants, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &FaultMessage::onSlotSelectionChanged);
|
|
|
|
connect(m_tabocDtc.get(), &TrainingAreaBaseOC::Interface::Dtc::specificsEquipmentChanged,
|
|
this, &FaultMessage::onSpecificsEquipmentChanged);
|
|
m_tabocDtc->specificsEquipments([this](const TrainingAreaBaseOC::SpecificsEquipment & data) { onSpecificsEquipmentChanged(data, DataModification::eAdded); });
|
|
|
|
|
|
connect(m_ui->cbParty, &LtsWidgets::LtsComboBox::currentTextChanged, this, [this]
|
|
{
|
|
m_model->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->dvParticipants->expandAll();
|
|
});
|
|
|
|
m_model->onReinitModel(m_ui->cbParty->currentData().toInt());
|
|
m_ui->dvParticipants->expandAll();
|
|
m_ui->dvParticipants->setSortIndicator(0, Qt::AscendingOrder);
|
|
|
|
m_ui->leParticipant->setValidator( new QIntValidator(1, 10000, this) );
|
|
|
|
return true;
|
|
}
|
|
|
|
void FaultMessage::onSlotSelectionChanged()
|
|
{
|
|
m_selectedEqNr = 0;
|
|
|
|
const auto selIndexes = m_ui->dvParticipants->selectedRows();
|
|
if (!selIndexes.isEmpty())
|
|
{
|
|
ParticipantManagement::ParticipantData part = m_model->getParticipantData(selIndexes.first());
|
|
if (part.equipmentNumber().is_set())
|
|
m_selectedEqNr = part.equipmentNumber().get();
|
|
else
|
|
m_selectedEqNr = -1;
|
|
}
|
|
slotChangesMade();
|
|
if (m_selectedEqNr > 0)
|
|
m_ui->leParticipant->setText(QString::number(m_selectedEqNr));
|
|
|
|
|
|
}
|
|
|
|
void FaultMessage::onTextChanged()
|
|
{
|
|
QString plainText(m_ui->teComment->toPlainText());
|
|
int currentUsedChars = plainText.toUtf8().size();
|
|
bool bNeedSetNew = false;
|
|
|
|
while (currentUsedChars > m_maxChars)
|
|
{
|
|
plainText.chop(1);
|
|
currentUsedChars = plainText.toUtf8().size();
|
|
bNeedSetNew = true; // do not set text directly, results in recursion
|
|
}
|
|
|
|
// if text longer than allowed
|
|
if (bNeedSetNew)
|
|
{
|
|
m_ui->teComment->setPlainText(plainText);
|
|
m_ui->teComment->moveCursor(QTextCursor::End);
|
|
}
|
|
m_ui->lblCount->setText(QString::number(currentUsedChars));
|
|
}
|
|
|
|
void FaultMessage::onDevTextChanged()
|
|
{
|
|
timText(m_ui->leDevice, m_ui->lblDevCount);
|
|
}
|
|
|
|
|
|
void FaultMessage::timText(QLineEdit *le, QLabel *lbl)
|
|
{
|
|
|
|
QString plainText(le->text());
|
|
int currentUsedChars = plainText.toUtf8().size();
|
|
bool bNeedSetNew = false;
|
|
|
|
while (currentUsedChars > m_maxPartChars)
|
|
{
|
|
plainText.chop(1);
|
|
currentUsedChars = plainText.toUtf8().size();
|
|
bNeedSetNew = true; // do not set text directly, results in recursion
|
|
}
|
|
|
|
// if text longer than allowed
|
|
if (bNeedSetNew)
|
|
{
|
|
le->setText(plainText);
|
|
}
|
|
lbl->setText(QString::number(currentUsedChars));
|
|
|
|
}
|
|
|
|
void FaultMessage::retranslate()
|
|
{
|
|
translate(m_ui, tr("Fault Message") );
|
|
m_uiRequirements->clear();
|
|
|
|
m_uiRequirements->addRequirement({m_ui->lblDevice, [this]() { return !m_ui->leDevice->text().isEmpty(); },
|
|
tr("Name the faulty devices.")});
|
|
|
|
m_uiRequirements->addRequirement({m_ui->lblComment, [this]()
|
|
{
|
|
return (!m_ui->teComment->toPlainText().isEmpty() &&
|
|
m_ui->teComment->toPlainText().count() <= m_maxChars);
|
|
},
|
|
tr("Add a text comment.")});
|
|
|
|
}
|
|
|
|
bool FaultMessage::apply()
|
|
{
|
|
if (m_ui->leParticipant->text().toInt() <= 0)
|
|
return false;
|
|
SendEquipmentErrorRegistrationRequest req;
|
|
req.device(m_ui->leDevice->text().toStdString());
|
|
req.faultEquipmentNumber(m_ui->leParticipant->text().toStdString());
|
|
req.text(m_ui->teComment->toPlainText().toStdString());
|
|
req.ocEquipmentNumber(m_ownEquipmentId);
|
|
|
|
return m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->sendEquipmentErrorRegistrationRequest(req, this);
|
|
});
|
|
}
|
|
|
|
void FaultMessage::onSpecificsEquipmentChanged(const TrainingAreaBaseOC::SpecificsEquipment &data, const DataModification &modType)
|
|
{
|
|
if (DataModification::eRemoved == modType)
|
|
return;
|
|
|
|
m_ownEquipmentId = data.equipmentNumber();
|
|
if (m_ownEquipmentId <= 0)
|
|
WARNING_LOG(m_logger) << "EquipmentNumber " << data.equipmentNumber() << " is not present ";
|
|
|
|
}
|
|
} // namespace OcSituationClient
|