173 lines
5.8 KiB
C++
Executable File
173 lines
5.8 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for ParticipantManagement - TlnInfoTableDialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Astrid Mueller, SGAS, 2017-07-10
|
|
*/
|
|
|
|
#include "participant_info_table_dialog.h"
|
|
#include "ui_participant_info_table_dialog.h"
|
|
|
|
#include "participant_info_table_add_dialog.h"
|
|
#include <PluginInterfaces/gui_plugin_interface.h>
|
|
#include <QSortFilterProxyModel>
|
|
#include <QMenu>
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
ParticipantInfoTableDialog::ParticipantInfoTableDialog(const QString &menuGroup, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_menuGroup(menuGroup)
|
|
, m_session(nullptr)
|
|
, m_dtc(nullptr)
|
|
, m_ppmGuiIfc(nullptr)
|
|
, m_ui(new Ui::ParticipantInfoTableDialog)
|
|
, m_logger(getLogger("ParticipantInfoTableDialog"))
|
|
, m_infoTableModel(nullptr)
|
|
, m_sortFilterProxyModel(nullptr)
|
|
, m_visibleColumns()
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
// Add-Button used as 'Hinzufuegen' as 'Erstellen'-Button
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Add, tr("Add"));
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add,
|
|
this,
|
|
&ParticipantInfoTableDialog::onAddClicked);
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, false);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove,
|
|
this,
|
|
&ParticipantInfoTableDialog::onRemoveClicked);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Participant_Info_Table"));
|
|
}
|
|
|
|
ParticipantInfoTableDialog::~ParticipantInfoTableDialog()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::retranslate()
|
|
{
|
|
translate(m_ui, tr("Participant Info Table"));
|
|
}
|
|
|
|
bool ParticipantInfoTableDialog::init(LtsSession::LtsSession *session,
|
|
const std::shared_ptr<Interface::Dtc> &dtc)
|
|
{
|
|
DEBUG_LOG(m_logger) << "**** init";
|
|
|
|
m_session = session;
|
|
m_dtc = dtc;
|
|
|
|
m_session->getForeignGuiInterface<ParticipantManagement::ForeignParticipantInfoGuiInterface>(m_ppmGuiIfc); // optional
|
|
|
|
m_infoTableModel = new ParticipantInfoTableModel(this);
|
|
m_infoTableModel->initModel(session, m_dtc, true);
|
|
m_sortFilterProxyModel = new QSortFilterProxyModel(this);
|
|
m_sortFilterProxyModel->setSourceModel(m_infoTableModel);
|
|
m_ui->tvParticipant->setModel(m_sortFilterProxyModel);
|
|
m_ui->tvParticipant->setSelectionMode(QAbstractItemView::ExtendedSelection);
|
|
m_ui->tvParticipant->resizeColumnsToContents();
|
|
m_ui->tvParticipant->horizontalHeader()->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
for (int i = 0; i < m_infoTableModel->columnCount(); ++i)
|
|
{
|
|
if (m_ui->tvParticipant->isColumnHidden(i))
|
|
continue;
|
|
m_visibleColumns.append(i);
|
|
}
|
|
|
|
QItemSelectionModel *selectionModel = m_ui->tvParticipant->selectionModel();
|
|
connect(selectionModel, &QItemSelectionModel::selectionChanged,
|
|
this, &ParticipantInfoTableDialog::onSelectionChanged);
|
|
|
|
connect(m_ui->tvParticipant, &QTableView::doubleClicked,
|
|
this, &ParticipantInfoTableDialog::onShowTlnInfo);
|
|
|
|
connect(m_ui->tvParticipant->horizontalHeader(), &QHeaderView::customContextMenuRequested,
|
|
this, &ParticipantInfoTableDialog::onColumnContextMenu);
|
|
|
|
return true;
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::onColumnContextMenu(const QPoint &position)
|
|
{
|
|
QAbstractScrollArea *w = qobject_cast<QAbstractScrollArea*>(sender());
|
|
QMenu contextMenu;
|
|
for (int col=0; col<m_infoTableModel->columnCount(); ++col)
|
|
{
|
|
QAction *a = contextMenu.addAction(m_infoTableModel->headerData(col, Qt::Horizontal).toString());
|
|
a->setCheckable(true);
|
|
a->setChecked(!m_ui->tvParticipant->isColumnHidden(col));
|
|
connect(a, &QAction::toggled, [this, col](bool checked){m_ui->tvParticipant->setColumnHidden(col, !checked);});
|
|
}
|
|
contextMenu.exec(w->viewport()->mapToGlobal(position));
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::onAddClicked()
|
|
{
|
|
DEBUG_LOG(m_logger) << "**** onAddClicked() ";
|
|
InfoTableAddDialog *addParticipantsDialog = new InfoTableAddDialog(this);
|
|
addParticipantsDialog->init(m_session, m_dtc);
|
|
|
|
addDialog(addParticipantsDialog, m_menuGroup, QLatin1String("AddParticipantsToParticipantTable"),
|
|
LtsWidgets::LayoutArea::eDialogTab);
|
|
|
|
connect(addParticipantsDialog, &InfoTableAddDialog::signalFinishedSelectParticipantIds,
|
|
this, &ParticipantInfoTableDialog::onAddParticipants);
|
|
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::onRemoveClicked()
|
|
{
|
|
DEBUG_LOG(m_logger) << "**** onRemoveClicked() ";
|
|
const QModelIndexList selectedRows = m_ui->tvParticipant->selectionModel()->selectedRows();
|
|
|
|
if (!selectedRows.count())
|
|
return;
|
|
|
|
QVector<int> selectedIds;
|
|
selectedIds.reserve(selectedRows.size());
|
|
for (const QModelIndex &idx : selectedRows)
|
|
{
|
|
QModelIndex realIdx = m_sortFilterProxyModel->mapToSource(idx);
|
|
if (realIdx.isValid())
|
|
selectedIds.append(m_infoTableModel->getRowData(realIdx.row()).id());
|
|
}
|
|
m_infoTableModel->removeItems(selectedIds);
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::onSelectionChanged(const QItemSelection &selected,
|
|
const QItemSelection &deselected)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onSelectionChanged";
|
|
Q_UNUSED(selected);
|
|
Q_UNUSED(deselected);
|
|
|
|
bool enable = !m_ui->tvParticipant->selectionModel()->selectedRows().empty();
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, enable);
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::onShowTlnInfo(const QModelIndex &idx)
|
|
{
|
|
DEBUG_LOG(m_logger) << "onDoubleClick --> showTlnInfo";
|
|
QModelIndex realIdx = m_sortFilterProxyModel->mapToSource(idx);
|
|
|
|
const int id = m_infoTableModel->getRowData(realIdx.row()).id();
|
|
if (m_ppmGuiIfc)
|
|
m_ppmGuiIfc->showParticipantInfoWindow(id);
|
|
}
|
|
|
|
void ParticipantInfoTableDialog::onAddParticipants(const QSet<int> &participantIds)
|
|
{
|
|
m_infoTableModel->updateDataView(participantIds);
|
|
m_ui->tvParticipant->sortByColumn(0, Qt::AscendingOrder);
|
|
}
|
|
|
|
} // namespace ParticipantManagement
|