221 lines
6.4 KiB
C++
Executable File
221 lines
6.4 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for ParticipantManagement - Party View
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Patric Karwat, SLSE, 2016-11-11
|
|
*/
|
|
|
|
#include "ppm_party_view.h"
|
|
#include "ui_ppm_party_view.h"
|
|
#include "CustomView/ppm_party.h"
|
|
#include "ppm_party_edit.h"
|
|
|
|
#include <Plugins/ParticipantManagement/ppm_data_plugin_interface.h>
|
|
|
|
#include <LtsPrinting/printing.h>
|
|
#include <QTreeView>
|
|
|
|
namespace ParticipantManagement
|
|
{
|
|
|
|
PartyView::PartyView(const QString &menuGroup, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_menuGroup(menuGroup)
|
|
, m_model(nullptr)
|
|
, m_dtc(nullptr)
|
|
, m_ftc(nullptr)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_session(nullptr)
|
|
, m_ui(new Ui::PartyView)
|
|
, m_logger(getLogger("PartyView"))
|
|
{
|
|
m_ui->setupUi(this);
|
|
m_ui->widget->setSelectionMode(QAbstractItemView::SingleSelection);
|
|
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &PartyView::enaDisa);
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked, this, &PartyView::onEditParty);
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalEnterPressed, this, &PartyView::onEditParty);
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &PartyView::onEditParty);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &PartyView::onAddParty);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &PartyView::onRemoveParty);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Print, this, &PartyView::onPrint);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Load, this, &PartyView::onSyncParties);
|
|
m_buttonBox->setText(LtsWidgets::DialogButton::Load, tr("Synchronize Parties"));
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Situation-Parties"));
|
|
}
|
|
|
|
PartyView::~PartyView()
|
|
{
|
|
delete m_ui;
|
|
}
|
|
|
|
void PartyView::retranslate()
|
|
{
|
|
translate(m_ui, tr("Parties"));
|
|
}
|
|
|
|
bool PartyView::init(LtsSession::LtsSession *session)
|
|
{
|
|
m_session = session;
|
|
|
|
if (!m_session->getDtc<ParticipantManagement::DataInterface>(m_dtc))
|
|
return false;
|
|
if (!m_session->getFtc<ParticipantManagement::DataInterface>(m_ftc))
|
|
return false;
|
|
|
|
m_model = new PartyModel(this);
|
|
if (!m_model->initModel(m_session))
|
|
return false;
|
|
|
|
m_ui->widget->setModel(m_model, [this]() { return new CustomViewParty(this); });
|
|
|
|
#ifndef LTS_DEBUG
|
|
m_ui->widget->hideColumn(PartyModel::Id);
|
|
#endif
|
|
|
|
m_ui->widget->setSortingEnabled(false);
|
|
|
|
connect(m_model, &PartyModel::rowsInserted, this, &PartyView::enaDisa);
|
|
connect(m_model, &PartyModel::rowsRemoved, this, &PartyView::enaDisa);
|
|
|
|
enaDisa();
|
|
|
|
return true;
|
|
}
|
|
|
|
void PartyView::enaDisa()
|
|
{
|
|
const QModelIndex idx = m_ui->widget->currentIndex();
|
|
|
|
bool bAddVisible = m_model->rowCount() < 12; // 12 parties, OC and pool are not shown
|
|
bool bEditEnabled = true;
|
|
bool bRemoveEnabled = true;
|
|
bool bRemoveVisible = (m_session->exerciseId() > 0);
|
|
bool bLoadEnabled = true;
|
|
bool bLoadVisible = (m_session->exerciseId() > 0);
|
|
|
|
const int row = idx.row();
|
|
if (m_ui->widget->selectedRows().size() == 0 || row < 0)
|
|
{
|
|
bEditEnabled = false;
|
|
bRemoveEnabled = false;
|
|
}
|
|
else
|
|
{
|
|
const ParticipantManagement::Party party = m_model->getRowData(row);
|
|
bEditEnabled = party.id() > 0; // all but not pool
|
|
bRemoveEnabled = !party.isUsedBy();
|
|
}
|
|
|
|
if (m_session->exerciseId() > 0)
|
|
{
|
|
// no add parties in ex_N, they need to be added in ex_0 and synchronized. Last updated: 2018.04.12
|
|
bAddVisible = false;
|
|
|
|
// sync possible only in preparing exercise
|
|
const bool bInPreparation = (m_session->exerciseState() == LtsWidgets::ExerciseState::eCreated);
|
|
if (bInPreparation)
|
|
{
|
|
// sync possible only in preparing exercise
|
|
bLoadEnabled = true;
|
|
bLoadVisible = true;
|
|
bRemoveVisible = true;
|
|
}
|
|
else
|
|
{
|
|
// sync and delete not possible after starting exercise
|
|
bLoadEnabled = false;
|
|
bLoadVisible = false;
|
|
bRemoveVisible = false;
|
|
bRemoveEnabled = false;
|
|
}
|
|
}
|
|
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Add, bAddVisible);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, bEditEnabled);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, bRemoveEnabled);
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Remove, bRemoveVisible);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Load, bLoadEnabled);
|
|
m_buttonBox->setButtonVisible(LtsWidgets::DialogButton::Load, bLoadVisible);
|
|
}
|
|
|
|
void PartyView::onEditParty()
|
|
{
|
|
const QModelIndex idx = m_ui->widget->currentIndex();
|
|
|
|
int row = idx.row();
|
|
if (row < 0)
|
|
return;
|
|
|
|
ParticipantManagement::Party party = m_model->getRowData(row);
|
|
PartyEdit *dialog = new PartyEdit(this);
|
|
dialog->init(party.id(), m_session);
|
|
|
|
addDialog(dialog, m_menuGroup, QLatin1String("ppmEditParty")+QString::number(party.id()), LtsWidgets::LayoutArea::eDialogTab);
|
|
}
|
|
|
|
void PartyView::onAddParty()
|
|
{
|
|
PartyEdit *dialog = new PartyEdit(this);
|
|
dialog->init(-1 , m_session);
|
|
|
|
addDialog(dialog, m_menuGroup, QLatin1String("ppmAddParty"), LtsWidgets::LayoutArea::eDialogTab);
|
|
}
|
|
|
|
void PartyView::onRemoveParty()
|
|
{
|
|
const QModelIndex curIdx = m_ui->widget->currentIndex();
|
|
if (!curIdx.isValid())
|
|
return;
|
|
const Party party = m_model->getRowData(curIdx.row());
|
|
if (party.id() < 0)
|
|
return;
|
|
RemovePartyRequest req;
|
|
req.partyId(party.id());
|
|
m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->removePartyRequest(req, this);
|
|
});
|
|
enaDisa();
|
|
}
|
|
|
|
void PartyView::onPrint()
|
|
{
|
|
LtsPrinting::printView(m_session, this, m_ui->widget->treeView() );
|
|
}
|
|
|
|
void PartyView::onSyncParties()
|
|
{
|
|
LtsWidgets::Button button = LtsWidgets::LtsMessageDialog::showMessage(this,tr("Changes in this exercise will be lost. Do you wish to continue?"), tr("Warning"),
|
|
LtsWidgets::Behaviour::Modal, LtsWidgets::Button::Yes | LtsWidgets::Button::No);
|
|
|
|
if (button == LtsWidgets::Button::Yes)
|
|
{
|
|
m_requestHelper->startSingleRequest([this]()
|
|
{
|
|
SyncPartiesRequest req;
|
|
req.exerciseId(m_session->exerciseId());
|
|
|
|
DEBUG_LOG(m_logger) << "Sync parties for exercise " << req.exerciseId();
|
|
|
|
return m_ftc->syncPartiesRequest(req, this);
|
|
});
|
|
}
|
|
enaDisa();
|
|
}
|
|
|
|
void PartyView::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
} // namespace ParticipantManagement
|