mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
146 lines
3.8 KiB
C++
146 lines
3.8 KiB
C++
#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),
|
||
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);
|
||
}
|
||
|
||
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;
|
||
}
|
||
|
||
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::on_btnEditorInstructors_clicked()
|
||
{
|
||
connectorToServer->sendQueryBlockAuth(true);
|
||
|
||
dlgRedactor = new DialogRedactorInstructors(connectorToServer, adminMode, this);
|
||
dlgRedactor->exec();
|
||
|
||
if(dlgRedactor)
|
||
{
|
||
delete dlgRedactor;
|
||
dlgRedactor = nullptr;
|
||
}
|
||
|
||
if(authComplited)
|
||
loadInstructorsFromDB();
|
||
|
||
connectorToServer->sendQueryBlockAuth(false);
|
||
}
|
||
|
||
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);
|
||
}
|
||
}
|