Initial commit
This commit is contained in:
commit
b7d90b9afe
16245 files changed
+3396666
No files matched your search
+419
@@ -0,0 +1,419 @@
|
||||
/**
|
||||
* @RDE_HEADER@
|
||||
* ServiceMonitor Dialog
|
||||
* $Id$
|
||||
* $HeadURL$
|
||||
* $Author$
|
||||
* Created by Astrid Mueller, SGAS, 2017-05-04
|
||||
*/
|
||||
|
||||
#include "smo_dialog.h"
|
||||
#include "ui_smo_dialog.h"
|
||||
#include <Common/logger.h>
|
||||
|
||||
#include "smo_egcu_model.h"
|
||||
#include "smo_egcu_edit.h"
|
||||
#include "smo_structure_element_edit.h"
|
||||
|
||||
#include <LtsSession/lts_session.h>
|
||||
#include <LtsPrinting/printing.h>
|
||||
#include <QTreeView>
|
||||
#include <QMenu>
|
||||
#include <QWidgetAction>
|
||||
#include <QLabel>
|
||||
|
||||
#include <Common/PluginInterfaces/gui_plugin_interface.h>
|
||||
#include <Plugins/Buildings/bld_data_plugin_interface.h>
|
||||
#include <Plugins/SituationMapPlugin/situation_map_gui_plugin_interface.h>
|
||||
|
||||
namespace ServiceMonitor
|
||||
{
|
||||
ServiceMonitorDialog::ServiceMonitorDialog(Monitor monitor,
|
||||
LtsSession::LtsSession *session,
|
||||
QWidget *parent)
|
||||
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
||||
, m_session(session)
|
||||
, m_ui(new Ui::ServiceMonitorDialog)
|
||||
, m_monitor(monitor)
|
||||
, m_proxyModel(nullptr)
|
||||
, m_ppmDtc(nullptr)
|
||||
, m_pdmDtc(nullptr)
|
||||
, m_logger(getLogger("ServiceMonitorDialog"))
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &ServiceMonitorDialog::onPrint);
|
||||
|
||||
if (m_monitor == Monitor::Bite)
|
||||
setOnlineHelpFilename(QStringLiteral("Situation-BITE_Monitor"));
|
||||
else if (m_monitor == Monitor::Manipulation)
|
||||
setOnlineHelpFilename(QStringLiteral("Situation-Manipulation_Monitor"));
|
||||
else if (m_monitor == Monitor::CtasError)
|
||||
setOnlineHelpFilename(QStringLiteral("Situation-GFS_Telegram_Monitor"));
|
||||
else if (m_monitor == Monitor::Egcu)
|
||||
setOnlineHelpFilename(QStringLiteral("Situation-Effect_representation"));
|
||||
}
|
||||
|
||||
|
||||
ServiceMonitorDialog::~ServiceMonitorDialog()
|
||||
{
|
||||
onParticipantClicked(-1);
|
||||
delete m_ui;
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::retranslate()
|
||||
{
|
||||
QString text;
|
||||
switch (m_monitor)
|
||||
{
|
||||
case Bite:
|
||||
{
|
||||
text = tr("BITE Monitor");
|
||||
break;
|
||||
}
|
||||
case Manipulation:
|
||||
{
|
||||
text = tr("Manipulation Monitor");
|
||||
break;
|
||||
}
|
||||
case CtasError:
|
||||
{
|
||||
text = tr("CTAS Error Monitor");
|
||||
break;
|
||||
}
|
||||
case Egcu:
|
||||
{
|
||||
text = tr("Egcu Monitor");
|
||||
break;
|
||||
}
|
||||
case Unset:
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
translate(m_ui, text);
|
||||
}
|
||||
|
||||
bool ServiceMonitorDialog::init()
|
||||
{
|
||||
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_ppmDtc))
|
||||
return false;
|
||||
if (!m_session->getDtc<ProjectDataManagement::DataInterface>(m_pdmDtc))
|
||||
return false;
|
||||
if (!m_session->getDtc<InfrastructureManagement::DataInterface>(m_ismDtc))
|
||||
return false;
|
||||
|
||||
delete m_proxyModel;
|
||||
m_proxyModel = nullptr;
|
||||
|
||||
switch (m_monitor)
|
||||
{
|
||||
case Bite:
|
||||
{
|
||||
BiteModel *biteModel = new BiteModel(this);
|
||||
biteModel->initModel(m_ppmDtc, m_pdmDtc);
|
||||
m_proxyModel = new BiteProxyModel(this);
|
||||
m_proxyModel->setSourceModel(biteModel);
|
||||
break;
|
||||
}
|
||||
case Manipulation:
|
||||
{
|
||||
ManipulationModel *maniModel = new ManipulationModel(this);
|
||||
maniModel->initModel(m_ppmDtc, m_pdmDtc);
|
||||
m_proxyModel = new ManipulationProxyModel(this);
|
||||
m_proxyModel->setSourceModel(maniModel);
|
||||
break;
|
||||
}
|
||||
case CtasError:
|
||||
{
|
||||
CtasErrorModel *ctasErrorModel = new CtasErrorModel(this);
|
||||
ctasErrorModel->initModel(m_ppmDtc);
|
||||
m_proxyModel = new CtasErrorProxyModel(this);
|
||||
m_proxyModel->setSourceModel(ctasErrorModel);
|
||||
break;
|
||||
}
|
||||
case Egcu:
|
||||
{
|
||||
EgcuModel *egcuModel = new EgcuModel(this);
|
||||
egcuModel->initModel(m_session);
|
||||
m_proxyModel = new EgcuProxyModel(this);
|
||||
m_proxyModel->setSourceModel(egcuModel);
|
||||
m_ui->ltsDataView->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
||||
connect(egcuModel, &EgcuModel::invalidateFilter, this, [this](const QModelIndex &mi)
|
||||
{
|
||||
Q_UNUSED(mi)
|
||||
m_proxyModel->invalidate();
|
||||
// This somehow does not work:
|
||||
// m_ui->ltsDataView->treeView()->expand(mi);
|
||||
m_ui->ltsDataView->treeView()->expandAll();
|
||||
});
|
||||
EgcuDelegate *treeDelegate = new EgcuDelegate(m_proxyModel);
|
||||
m_ui->ltsDataView->treeView()->setItemDelegateForColumn(EgcuModel::Columns::Status, treeDelegate);
|
||||
|
||||
break;
|
||||
}
|
||||
case Unset:
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!m_proxyModel)
|
||||
return false;
|
||||
m_ui->ltsDataView->setModel(m_proxyModel);
|
||||
|
||||
if (m_monitor == Egcu)
|
||||
{
|
||||
m_ui->ltsDataView->treeView()->expandAll();
|
||||
m_ui->ltsDataView->hideColumn(EgcuModel::Barcode);
|
||||
#ifndef LTS_DEBUG
|
||||
m_ui->ltsDataView->hideColumn(EgcuModel::Id);
|
||||
m_ui->ltsDataView->hideColumn(EgcuModel::Properties);
|
||||
m_ui->ltsDataView->hideColumn(EgcuModel::Hostname);
|
||||
#endif
|
||||
m_ui->ltsDataView->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
connect(m_ui->ltsDataView, &LtsDataView::LtsDataView::customContextMenuRequested, this, &ServiceMonitorDialog::onShowContextMenu);
|
||||
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &ServiceMonitorDialog::onEditItem);
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::No, this, &ServiceMonitorDialog::onAllOff);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::No)->setText(tr("All Off"));
|
||||
m_buttonBox->connectButton(LtsWidgets::DialogButton::Yes, this, &ServiceMonitorDialog::onAllAuto);
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Yes)->setText(tr("All Auto"));
|
||||
onTableViewSelectionChanged({});
|
||||
}
|
||||
|
||||
// connect signals of TableView:
|
||||
connect(m_ui->ltsDataView, &LtsDataView::LtsDataView::doubleClicked, this, &ServiceMonitorDialog::onTableViewClicked);
|
||||
connect(m_ui->ltsDataView, &LtsDataView::LtsDataView::selectionChanged, this, &ServiceMonitorDialog::onTableViewSelectionChanged);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Not yet implemented:
|
||||
void ServiceMonitorDialog::setSelectedStructureElements(const QVector<int> &structureElementIds, bool replace)
|
||||
{
|
||||
if (m_monitor != Monitor::Egcu)
|
||||
return;
|
||||
|
||||
EgcuModel *em = qobject_cast<EgcuModel*>(m_ui->ltsDataView->sourceModel());
|
||||
if (!em)
|
||||
return;
|
||||
|
||||
QMap<int,QModelIndex> map = em->setSelectedStructureElements(structureElementIds);
|
||||
if (map.isEmpty())
|
||||
return;
|
||||
|
||||
m_ui->ltsDataView->setUpdatesEnabled(false);
|
||||
if (replace)
|
||||
m_ui->ltsDataView->clearSelection();
|
||||
for (const auto index : map)
|
||||
{
|
||||
auto mappedIdx = m_proxyModel->mapFromSource(index);
|
||||
m_ui->ltsDataView->selectRow(mappedIdx);
|
||||
}
|
||||
m_ui->ltsDataView->scrollTo(m_proxyModel->mapFromSource(map.first()));
|
||||
m_ui->ltsDataView->setUpdatesEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
void ServiceMonitorDialog::onShowContextMenu(const QPoint &position)
|
||||
{
|
||||
LtsDataView::LtsDataView *tv = qobject_cast<LtsDataView::LtsDataView *>(sender());
|
||||
if (!tv)
|
||||
return;
|
||||
const QModelIndexList indexes = tv->selectedRows();
|
||||
if (indexes.isEmpty())
|
||||
return;
|
||||
|
||||
EgcuModel *em = qobject_cast<EgcuModel*>(m_ui->ltsDataView->sourceModel());
|
||||
if (!em)
|
||||
return;
|
||||
|
||||
|
||||
QMenu menu;
|
||||
em->getContextMenu(indexes, menu);
|
||||
menu.exec(tv->mapToGlobal(position));
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onTableViewClicked(const QModelIndex &index)
|
||||
{
|
||||
if (m_monitor == Egcu)
|
||||
{
|
||||
EgcuModel *em = qobject_cast<EgcuModel*>(m_ui->ltsDataView->sourceModel());
|
||||
if (!em)
|
||||
return;
|
||||
|
||||
NGLTreeItem *item = em->privateData(index);
|
||||
if (!item)
|
||||
return;
|
||||
|
||||
if (item->data().canConvert<EgcuData>())
|
||||
{
|
||||
EgcuData ed = item->data().value<EgcuData>();
|
||||
EgcuEdit *dlg = new EgcuEdit(menuGroup(), this);
|
||||
if (dlg->init(ed, m_session))
|
||||
addDialog(dlg, menuGroup(), dlg->dialogIdentifier(), LtsWidgets::LayoutArea::eDialogTab);
|
||||
else
|
||||
delete dlg;
|
||||
}
|
||||
else if (item->data().canConvert<InfrastructureManagement::StructureElement>())
|
||||
{
|
||||
InfrastructureManagement::StructureElement se = item->data().value<InfrastructureManagement::StructureElement>();
|
||||
StructureElementEdit *dlg = new StructureElementEdit(menuGroup(), this);
|
||||
if (dlg->init(se, m_session))
|
||||
addDialog(dlg, menuGroup(), dlg->dialogIdentifier(), LtsWidgets::LayoutArea::eDialogTab);
|
||||
else
|
||||
delete dlg;
|
||||
}
|
||||
}
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, index=" << index.row() << " - " << index.column();
|
||||
if (!m_ui->ltsDataView->sourceModel())
|
||||
return;
|
||||
onParticipantClicked(participantId(index));
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, index=" << index.row() << " - " << index.column();
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onEditItem()
|
||||
{
|
||||
if (m_ui->ltsDataView->selectedRows().count() != 1)
|
||||
return;
|
||||
|
||||
auto index = m_ui->ltsDataView->selectedRows().first();
|
||||
|
||||
onTableViewClicked(index);
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::setAllOverrides(InfrastructureManagement::EffectOverride eo)
|
||||
{
|
||||
const QModelIndexList indexes = m_ui->ltsDataView->selectedRows();
|
||||
if (indexes.isEmpty())
|
||||
return;
|
||||
|
||||
EgcuModel *em = qobject_cast<EgcuModel*>(m_ui->ltsDataView->sourceModel());
|
||||
if (!em)
|
||||
return;
|
||||
em->setAllOverrides(eo, indexes);
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onAllOff()
|
||||
{
|
||||
setAllOverrides(InfrastructureManagement::EffectOverride_def::PermanentOff);
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onAllAuto()
|
||||
{
|
||||
setAllOverrides(InfrastructureManagement::EffectOverride_def::Automatic);
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onTableViewSelectionChanged(const QItemSelection &selected)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START";
|
||||
if (m_monitor == Monitor::Egcu)
|
||||
{
|
||||
// Only ONE selected row enables the EDIT Button. This row MUST be a Building or a MountingPoint (==EGCU)
|
||||
bool ena = (m_ui->ltsDataView->selectedRows().count() == 1);
|
||||
if (ena)
|
||||
{
|
||||
// Model Pointer will be valid. Where else does the SelectionChange come from?
|
||||
EgcuModel *em = qobject_cast<EgcuModel*>(m_ui->ltsDataView->sourceModel());
|
||||
auto type = em->getStructureElementType(m_ui->ltsDataView->selectedRows().first());
|
||||
if (type != InfrastructureManagement::StructureElementType_def::Building &&
|
||||
type != InfrastructureManagement::StructureElementType_def::MountingPoint)
|
||||
ena = false;
|
||||
}
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Edit)->setEnabled(ena);
|
||||
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::Yes)->setEnabled(m_ui->ltsDataView->selectedRows().count());
|
||||
m_buttonBox->getButton(LtsWidgets::DialogButton::No)->setEnabled(m_ui->ltsDataView->selectedRows().count());
|
||||
}
|
||||
QModelIndexList mil = selected.indexes();
|
||||
if (mil.isEmpty())
|
||||
onParticipantClicked(-1); // -1 -> removeObjectIndicator
|
||||
else
|
||||
{
|
||||
onParticipantClicked(participantId(mil.first()));
|
||||
}
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END";
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onParticipantClicked(int participantId)
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, participantId=" << participantId;
|
||||
if (!m_session)
|
||||
return;
|
||||
|
||||
std::shared_ptr<SituationMap::ForeignGuiInterface> sitMapGuiIfc;
|
||||
m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(sitMapGuiIfc);
|
||||
if (!sitMapGuiIfc)
|
||||
return;
|
||||
|
||||
if (participantId < 0)
|
||||
sitMapGuiIfc->removeObjectIndicator();
|
||||
else
|
||||
if (!sitMapGuiIfc->objectIndicatorToParticipant(participantId))
|
||||
ERROR_LOG(m_logger) << LOGFUNCTION << " objectIndicatorToParticipant failed for participantId = " << participantId;
|
||||
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " END, participantId=" << participantId;
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::leaveEvent(QEvent *e)
|
||||
{
|
||||
BaseClass::leaveEvent(e);
|
||||
|
||||
std::shared_ptr<SituationMap::ForeignGuiInterface> sitMapGuiIfc;
|
||||
m_session->getForeignGuiInterface<SituationMap::ForeignGuiInterface>(sitMapGuiIfc);
|
||||
if (!sitMapGuiIfc)
|
||||
return;
|
||||
sitMapGuiIfc->removeObjectIndicator();
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::onPrint()
|
||||
{
|
||||
LtsPrinting::printView(m_session, this, m_ui->ltsDataView->treeView() );
|
||||
}
|
||||
|
||||
int ServiceMonitorDialog::participantId(const QModelIndex &index) const
|
||||
{
|
||||
TRACE_LOG(m_logger) << LOGFUNCTION << " START, index=" << index.row() << " - " << index.column();
|
||||
if (!m_ui->ltsDataView->sourceModel())
|
||||
return -1;
|
||||
|
||||
switch (m_monitor)
|
||||
{
|
||||
case Bite:
|
||||
{
|
||||
BiteModel *bm = qobject_cast<BiteModel*>(m_ui->ltsDataView->sourceModel());
|
||||
if (bm)
|
||||
{
|
||||
const ParticipantManagement::Bite &bite = bm->getRowData(index.row());
|
||||
return bite.participantId();
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Manipulation:
|
||||
{
|
||||
ManipulationModel *mm = qobject_cast<ManipulationModel*>(m_ui->ltsDataView->sourceModel());
|
||||
if (mm)
|
||||
{
|
||||
const ManipulationData &md = mm->getRowData(index.row());
|
||||
return md.participantId;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Egcu:
|
||||
case CtasError:
|
||||
case Unset:
|
||||
// currently not supported
|
||||
break;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void ServiceMonitorDialog::tableColumnOrganiserSetting()
|
||||
{
|
||||
//LtsColumnOrganiser
|
||||
m_ui->ltsDataView->setColumnsOrganiserEnabled(identifier(), true);
|
||||
}
|
||||
|
||||
} // namespace ServiceMonitor
|
||||
Reference in new issue
Block a user