164 lines
4.6 KiB
C++
Executable File
164 lines
4.6 KiB
C++
Executable File
/**
|
|
* @RDE_HEADER@
|
|
* HMI Plugin for WarehouseManagement - Operator/User Overview Dialog
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
* Created by Christian Ehrlicher, SLSE, 2016-02-29
|
|
*/
|
|
|
|
#include "injury_model_list.h"
|
|
#include "ui_injury_model_list.h"
|
|
#include "injury_model_model.h"
|
|
#include "injury_model_add.h"
|
|
#include "injury_model_edit_dialog.h"
|
|
#include "CustomViews/whm_injury_model.h"
|
|
#include "../whm_data_plugin_interface.h"
|
|
|
|
#include <LtsSession/lts_session.h>
|
|
#include <WarehouseGuez/whg_ftc.h>
|
|
#include <WarehouseGuez/whg_dtc.h>
|
|
#include <LtsUtilsGuiDds/request_helper.h>
|
|
#include <WarehouseGuez/logger.h>
|
|
|
|
namespace WarehouseManagement
|
|
{
|
|
InjuryModelList::InjuryModelList(const QString &menuGroup, LtsSession::LtsSession *session, QWidget *parent)
|
|
: LtsWidgets::LtsDialog(parent, LtsWidgets::ButtonCombination::CloseOnly)
|
|
, m_menuGroup(menuGroup)
|
|
, m_model(nullptr)
|
|
, m_session(session)
|
|
, m_ftc(nullptr)
|
|
, m_dtc(nullptr)
|
|
, m_requestHelper(new LtsUtils::RequestHelper(this))
|
|
, m_logger(WarehouseGuez::getLogger("InjuryModelList"))
|
|
, m_ui(new Ui::InjuryModelList)
|
|
{
|
|
m_ui->setupUi(this);
|
|
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Add, this, &InjuryModelList::onAddInjuryModel);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Edit, this, &InjuryModelList::onEditInjuryModel);
|
|
m_buttonBox->connectButton(LtsWidgets::DialogButton::Remove, this, &InjuryModelList::onRemoveInjuryModel);
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalDoubleClicked,
|
|
this, &InjuryModelList::onEditInjuryModel);
|
|
|
|
setOnlineHelpFilename(QStringLiteral("Administrator-Injury_Model"));
|
|
}
|
|
|
|
InjuryModelList::~InjuryModelList()
|
|
{
|
|
delete m_model;
|
|
delete m_requestHelper;
|
|
delete m_ui;
|
|
}
|
|
|
|
void InjuryModelList::retranslate()
|
|
{
|
|
translate(m_ui, tr("Injury Models Overview"));
|
|
}
|
|
|
|
void InjuryModelList::tableColumnOrganiserSetting()
|
|
{
|
|
//LtsColumnOrganiser
|
|
m_ui->widget->setColumnsOrganiserEnabled(identifier(), true);
|
|
}
|
|
|
|
bool InjuryModelList::init()
|
|
{
|
|
if (!m_session->getFtc<WarehouseManagement::DataInterface>(m_ftc) ||
|
|
!m_session->getDtc<WarehouseManagement::DataInterface>(m_dtc))
|
|
return false;
|
|
|
|
m_model = new InjuryModelModel(this);
|
|
m_model->initModel(m_dtc);
|
|
m_ui->widget->setModel(m_model, [this]() { return new CustomViewInjuryModel(this); });
|
|
|
|
connect(m_ui->widget, &LtsDataView::LtsDataView::signalSelectionChanged,
|
|
this, &InjuryModelList::enaDisa);
|
|
|
|
enaDisa();
|
|
|
|
return true;
|
|
}
|
|
|
|
void InjuryModelList::onRemoveInjuryModelAgdusWhReply(const Core::FunctionReplyObject &reply)
|
|
{
|
|
m_requestHelper->requestReply(reply);
|
|
}
|
|
|
|
void InjuryModelList::onModifyInjuryModelAgdusWhReply(const Core::FunctionReplyObject &reply)
|
|
{
|
|
m_requestHelper->requestReply(reply);
|
|
|
|
if (reply.error())
|
|
return;
|
|
|
|
editInjuryModel(reply.id());
|
|
}
|
|
|
|
void InjuryModelList::enaDisa()
|
|
{
|
|
QModelIndexList selectedRows = m_ui->widget->selectedRows();
|
|
const int cntSelectedRows = selectedRows.size();
|
|
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Add, true);
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Edit, cntSelectedRows == 1 );
|
|
m_buttonBox->setButtonEnabled(LtsWidgets::DialogButton::Remove, cntSelectedRows == 1 );
|
|
}
|
|
|
|
void InjuryModelList::onRemoveInjuryModel()
|
|
{
|
|
QModelIndex idx = m_ui->widget->currentIndex();
|
|
Core::RemoveElementRequest req(m_model->getRowData(idx.row()).id());
|
|
|
|
m_requestHelper->startSingleRequest([req, this]()
|
|
{
|
|
return m_ftc->removeInjuryModelAgdusWhRequest(req, this);
|
|
});
|
|
}
|
|
|
|
void InjuryModelList::onAddInjuryModel()
|
|
{
|
|
const auto takenIds = m_model->takenIds();
|
|
QSet<int> availableIds;
|
|
for (int i = 1; i <= 255; ++i)
|
|
if (!takenIds.contains(i))
|
|
availableIds << i;
|
|
|
|
InjuryModelAdd *dlg = new InjuryModelAdd(availableIds, this);
|
|
connect(dlg, &InjuryModelAdd::newInjuryModel, this, &InjuryModelList::onNewInjuryModel);
|
|
dlg->show();
|
|
}
|
|
|
|
void InjuryModelList::editInjuryModel(int id)
|
|
{
|
|
InjuryModelEditDialog *dialog = LtsWidgets::initDialog(new InjuryModelEditDialog(id, m_session, this));
|
|
const QString identifier = QLatin1String("EditInjuryModel") + QString::number(id);
|
|
addDialog(dialog, m_menuGroup, identifier, LtsWidgets::LayoutArea::eDialogTab);
|
|
}
|
|
|
|
void InjuryModelList::onEditInjuryModel()
|
|
{
|
|
int id = m_model->getId(m_ui->widget->currentIndex());
|
|
|
|
if (id <= 0)
|
|
return;
|
|
|
|
editInjuryModel(id);
|
|
}
|
|
|
|
void InjuryModelList::onNewInjuryModel(int id)
|
|
{
|
|
WarehouseGuez::InjuryModelAgdusWh im;
|
|
im.id(0-id);
|
|
im.name(tr("New Name").toStdString());
|
|
im.version("-");
|
|
m_requestHelper->startSingleRequest([im, this]()
|
|
{
|
|
return m_ftc->modifyInjuryModelAgdusWhRequest(im, this);
|
|
});
|
|
}
|
|
|
|
} // namespace WarehouseManagement
|