mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
273 lines
7.7 KiB
C++
273 lines
7.7 KiB
C++
#include "editortrainees.h"
|
||
#include "viewertrainees.h"
|
||
#include "personalcardtrainee.h"
|
||
#include "dialogcardtrainee.h"
|
||
#include "ui_viewertrainees.h"
|
||
|
||
ViewerTrainees::ViewerTrainees(ConnectorToServer* connectorToServer, MessangerController* messangerController, QWidget *parent) :
|
||
TraineesView(connectorToServer, CommonView::TypeView::onlyView, parent),
|
||
ammTasksWidgetCommon(nullptr),
|
||
fimTasksWidgetCommon(nullptr),
|
||
messangerController(messangerController),
|
||
dlgRedactor(nullptr),
|
||
dlgCardTrainee(nullptr),
|
||
flTryEditorTrainees(false),
|
||
ui(new Ui::ViewerTrainees)
|
||
{
|
||
ui->setupUi(this);
|
||
|
||
connect(treeWidget, &QTreeWidget::itemDoubleClicked, this, &ViewerTrainees::on_itemDoubleClicked);
|
||
connect(treeWidget, &QTreeWidget::currentItemChanged, this, &ViewerTrainees::on_treeWidgetCurrentItemChanged);
|
||
|
||
ui->horizontalLayout_1->addWidget(treeWidget);
|
||
|
||
ammTasksWidgetCommon = new AMMtasksWidget(connectorToServer, TypeListTreeAMMFIM::listCommon, /*this*/nullptr);
|
||
fimTasksWidgetCommon = new FIMtasksWidget(connectorToServer, TypeListTreeAMMFIM::listCommon, /*this*/nullptr);
|
||
|
||
connect(connectorToServer, &ConnectorToServer::signal_UpdateTasksFIM, fimTasksWidgetCommon, &FIMtasksWidget::slot_NeedUpdateUI);
|
||
connect(connectorToServer, &ConnectorToServer::signal_UpdateTasksAMM, ammTasksWidgetCommon, &AMMtasksWidget::slot_NeedUpdateUI);
|
||
connect(this, &ViewerTrainees::signal_traineeSelected, fimTasksWidgetCommon, &FIMtasksWidget::slot_traineeSelected);
|
||
connect(this, &ViewerTrainees::signal_traineeSelected, ammTasksWidgetCommon, &AMMtasksWidget::slot_traineeSelected);
|
||
|
||
preparationTreeWidget();
|
||
setNotLoggedInVisible(true);
|
||
|
||
ui->btnEditorTrainees->setVisible(false);
|
||
|
||
connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, this, &ViewerTrainees::slot_checkTryBlockResult);
|
||
}
|
||
|
||
ViewerTrainees::~ViewerTrainees()
|
||
{
|
||
if(ammTasksWidgetCommon)
|
||
{
|
||
delete ammTasksWidgetCommon;
|
||
ammTasksWidgetCommon = nullptr;
|
||
}
|
||
|
||
if(fimTasksWidgetCommon)
|
||
{
|
||
delete fimTasksWidgetCommon;
|
||
fimTasksWidgetCommon = nullptr;
|
||
}
|
||
|
||
if(dlgRedactor)
|
||
{
|
||
dlgRedactor->close();
|
||
delete dlgRedactor;
|
||
dlgRedactor = nullptr;
|
||
}
|
||
|
||
if(dlgCardTrainee)
|
||
dlgCardTrainee->close();
|
||
|
||
delete ui;
|
||
}
|
||
|
||
void ViewerTrainees::setAuthComplited(bool authComplited)
|
||
{
|
||
this->authComplited = authComplited;
|
||
updateButtons();
|
||
}
|
||
|
||
void ViewerTrainees::deactivate()
|
||
{
|
||
if(dlgRedactor)
|
||
{
|
||
dlgRedactor->close();
|
||
delete dlgRedactor;
|
||
dlgRedactor = nullptr;
|
||
}
|
||
|
||
if(dlgCardTrainee)
|
||
dlgCardTrainee->close();
|
||
|
||
flTryEditorTrainees = false;
|
||
|
||
CommonView::deactivate();
|
||
|
||
ammTasksWidgetCommon->deactivate();
|
||
fimTasksWidgetCommon->deactivate();
|
||
updateButtons();
|
||
}
|
||
|
||
void ViewerTrainees::changeEvent(QEvent *event)
|
||
{
|
||
// В случае получения события изменения языка приложения
|
||
if (event->type() == QEvent::LanguageChange)
|
||
{// переведём окно заново
|
||
ui->retranslateUi(this);
|
||
|
||
reSetHeadTreeWidget();
|
||
slot_NeedUpdateUI(false, true);
|
||
}
|
||
}
|
||
|
||
void ViewerTrainees::slot_receiveMessage(ClientMessage clientMessage)
|
||
{
|
||
int id_trainee = clientMessage.fromId.toInt();
|
||
|
||
mtxmapNewMsg.lock();
|
||
mapNewMsg.insert(id_trainee, mapNewMsg.value(id_trainee) + 1);
|
||
mtxmapNewMsg.unlock();
|
||
|
||
slot_NeedUpdateUI(false, true);
|
||
}
|
||
|
||
void ViewerTrainees::slot_checkTryBlockResult(bool result, QString type)
|
||
{
|
||
if(flTryEditorTrainees)
|
||
{
|
||
if(type == "EditorTrainees")
|
||
{
|
||
if(result)
|
||
{//Одобрено
|
||
dialog_EditorTrainees();
|
||
}
|
||
else
|
||
{//Отказ
|
||
SpecMsgBox::WarningClose(this, tr("The server rejected your request to access trainees control.\nAnother instructor is managing trainees.\nPlease try again later."));
|
||
}
|
||
|
||
flTryEditorTrainees = false;
|
||
}
|
||
}
|
||
}
|
||
|
||
void ViewerTrainees::on_btnEditorTrainees_clicked()
|
||
{
|
||
emit signal_needShowWait(true);
|
||
|
||
flTryEditorTrainees = true;
|
||
|
||
connectorToServer->sendQueryBlockAuth(true, "EditorTrainees");
|
||
}
|
||
|
||
void ViewerTrainees::on_btnPersonalCard_clicked()
|
||
{
|
||
if(lastCurrentID && typeObject == TypeObject::objTrainee)
|
||
{
|
||
dlgCardTrainee = new DialogCardTrainee(connectorToServer, messangerController, lastCurrentID, ammTasksWidgetCommon, fimTasksWidgetCommon, this);
|
||
dlgCardTrainee->exec();
|
||
|
||
ammTasksWidgetCommon->setParent(this);
|
||
fimTasksWidgetCommon->setParent(this);
|
||
|
||
if(dlgCardTrainee)
|
||
{
|
||
delete dlgCardTrainee;
|
||
dlgCardTrainee = nullptr;
|
||
}
|
||
}
|
||
}
|
||
|
||
void ViewerTrainees::on_itemDoubleClicked(QTreeWidgetItem *item, int column)
|
||
{
|
||
if(item == nullptr)
|
||
return;
|
||
|
||
if(item->childCount() == 0)
|
||
{//Выбран обучаемый
|
||
QString login = item->text(ColumnsTreeUsers::clmn_Login);
|
||
if(login != "")
|
||
{
|
||
int id_trainee = connectorToServer->getIdTraineeByLogin(login);
|
||
|
||
dlgCardTrainee = new DialogCardTrainee(connectorToServer, messangerController, id_trainee, ammTasksWidgetCommon, fimTasksWidgetCommon, this);
|
||
dlgCardTrainee->exec();
|
||
|
||
ammTasksWidgetCommon->setParent(this);
|
||
fimTasksWidgetCommon->setParent(this);
|
||
|
||
if(dlgCardTrainee)
|
||
{
|
||
delete dlgCardTrainee;
|
||
dlgCardTrainee = nullptr;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
void ViewerTrainees::on_treeWidgetCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||
{
|
||
if(current == nullptr)
|
||
return;
|
||
|
||
if(current->childCount() == 0)
|
||
{//Выбран обучаемый
|
||
typeObject = TypeObject::objTrainee;
|
||
|
||
QString login = current->text(ColumnsTreeUsers::clmn_Login);
|
||
//if(login != "")
|
||
{
|
||
int newCurrentID = connectorToServer->getIdTraineeByLogin(login);
|
||
|
||
//if(newCurrentID == lastCurrentID)
|
||
//return;
|
||
|
||
lastCurrentID = newCurrentID;
|
||
|
||
mtxmapNewMsg.lock();
|
||
if(mapNewMsg.contains(newCurrentID))
|
||
{//Есть непрочитанные сообщения от него
|
||
if(mapNewMsg.value(newCurrentID))
|
||
{
|
||
for (int i = 0; i < ColumnsTreeUsers::clmn_count; i++)
|
||
{
|
||
current->setBackground(i, QBrush(Qt::GlobalColor::white));
|
||
}
|
||
mapNewMsg.take(newCurrentID);
|
||
current->setIcon(ColumnsTreeUsers::clmn_Messages, QIcon());
|
||
current->setText(ColumnsTreeUsers::clmn_Messages, "");
|
||
}
|
||
}
|
||
mtxmapNewMsg.unlock();
|
||
|
||
Q_EMIT signal_traineeSelected(newCurrentID);
|
||
}
|
||
}
|
||
else
|
||
{//Выбрана группа
|
||
typeObject = TypeObject::objGroup;
|
||
|
||
int id_group = current->text(ColumnsTreeUsers::clmn_ID).toInt();
|
||
|
||
lastCurrentID = id_group;
|
||
typeObject = TypeObject::objGroup;
|
||
|
||
QString login = "";
|
||
Q_EMIT signal_traineeSelected(0);
|
||
}
|
||
}
|
||
|
||
void ViewerTrainees::updateButtons()
|
||
{
|
||
if(authComplited)
|
||
{
|
||
ui->btnEditorTrainees->setEnabled(true);
|
||
}
|
||
else
|
||
{
|
||
ui->btnEditorTrainees->setEnabled(false);
|
||
}
|
||
}
|
||
|
||
void ViewerTrainees::dialog_EditorTrainees()
|
||
{
|
||
emit signal_needShowWait(false);
|
||
|
||
dlgRedactor = new DialogRedactorTrainees(connectorToServer, adminMode, this);
|
||
dlgRedactor->exec();
|
||
|
||
if(dlgRedactor)
|
||
{
|
||
delete dlgRedactor;
|
||
dlgRedactor = nullptr;
|
||
}
|
||
|
||
if(authComplited)
|
||
loadTraineesFromDB();
|
||
|
||
connectorToServer->sendQueryBlockAuth(false, "EditorTrainees");
|
||
}
|