Files
RRJServer/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp

180 lines
4.8 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include <QMessageBox>
#include "editorinstructors.h"
#include "viewerinstructors.h"
#include "ui_viewerinstructors.h"
ViewerInstructors::ViewerInstructors(ConnectorToServer* connectorToServer, QWidget *parent) :
InstructorsView(connectorToServer, CommonView::TypeView::onlyView, parent),
dlgRedactor(nullptr),
flTryEditorInstructors(false),
ui(new Ui::ViewerInstructors)
{
ui->setupUi(this);
connect(treeWidget, &QTreeWidget::currentItemChanged, this, &ViewerInstructors::on_treeWidgetCurrentItemChanged);
ui->horizontalLayout_1->addWidget(treeWidget);
//treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
preparationTreeWidget();
setNotLoggedInVisible(true);
ui->btnEditorInstructors->setVisible(false);
connect(connectorToServer, &ConnectorToServer::sigTryBlockResult, this, &ViewerInstructors::slot_checkTryBlockResult);
}
ViewerInstructors::~ViewerInstructors()
{
if(dlgRedactor)
{
dlgRedactor->close();
delete dlgRedactor;
dlgRedactor = nullptr;
}
delete ui;
}
void ViewerInstructors::setAuthComplited(bool authComplited)
{
this->authComplited = authComplited;
updateButtons();
}
void ViewerInstructors::deactivate()
{
if(dlgRedactor)
{
dlgRedactor->close();
delete dlgRedactor;
dlgRedactor = nullptr;
}
flTryEditorInstructors = false;
CommonView::deactivate();
updateButtons();
}
void ViewerInstructors::changeEvent(QEvent *event)
{
// В случае получения события изменения языка приложения
if (event->type() == QEvent::LanguageChange)
{// переведём окно заново
ui->retranslateUi(this);
reSetHeadTreeWidget();
slot_NeedUpdateUI(true, false);
}
}
void ViewerInstructors::slot_receiveMessage(ClientMessage clientMessage)
{
int id_instructor = clientMessage.fromId.toInt();
mtxmapNewMsg.lock();
mapNewMsg.insert(id_instructor, mapNewMsg.value(id_instructor) + 1);
mtxmapNewMsg.unlock();
slot_NeedUpdateUI(true, false);
}
void ViewerInstructors::slot_checkTryBlockResult(bool result, QString type)
{
if(flTryEditorInstructors)
{
if(type == "EditorInstructors")
{
if(result)
{//Одобрено
dialog_EditorInstructors();
}
else
{//Отказ
SpecMsgBox::WarningClose(this, tr("The server rejected your request to access instructors control.\nAnother instructor is managing instructors.\nPlease try again later."));
}
flTryEditorInstructors = false;
}
}
}
void ViewerInstructors::on_btnEditorInstructors_clicked()
{
emit signal_needShowWait(true);
flTryEditorInstructors = true;
connectorToServer->sendQueryBlockAuth(true, "EditorInstructors");
}
void ViewerInstructors::on_treeWidgetCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
if(current == nullptr)
return;
//if(current->childCount() == 0)
{//Выбран обучаемый
QString login = current->text(ColumnsTreeUsers::clmn_Login);
//if(login != "")
{
int newCurrentID = connectorToServer->getIdInstructorByLogin(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_instructorSelected(newCurrentID);
}
}
}
void ViewerInstructors::updateButtons()
{
if(adminMode && authComplited)
{
ui->btnEditorInstructors->setEnabled(true);
}
else
{
ui->btnEditorInstructors->setEnabled(false);
}
}
void ViewerInstructors::dialog_EditorInstructors()
{
emit signal_needShowWait(false);
dlgRedactor = new DialogRedactorInstructors(connectorToServer, adminMode, this);
dlgRedactor->exec();
if(dlgRedactor)
{
delete dlgRedactor;
dlgRedactor = nullptr;
}
if(authComplited)
loadInstructorsFromDB();
connectorToServer->sendQueryBlockAuth(false, "EditorInstructors");
}