Files
RRJServer/LibInstructorsAndTrainees/instructors/viewerinstructors.cpp
2025-12-05 12:20:47 +03:00

144 lines
3.6 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),
ui(new Ui::ViewerInstructors)
{
ui->setupUi(this);
connect(treeWidget, &QTreeWidget::itemClicked, this, &ViewerInstructors::on_treeWidgetItemClicked);
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, true);
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_treeWidgetItemClicked(QTreeWidgetItem *item, int column)
{
if(item == nullptr)
return;
//if(current->childCount() == 0)
{//Выбран обучаемый
QString login = item->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++)
{
item->setBackground(i, QBrush(Qt::GlobalColor::white));
}
mapNewMsg.take(newCurrentID);
}
}
mtxmapNewMsg.unlock();
Q_EMIT signal_instructorSelected(newCurrentID);
}
}
}
void ViewerInstructors::updateButtons()
{
if(adminMode && authComplited)
{
ui->btnEditorInstructors->setEnabled(true);
}
else
{
ui->btnEditorInstructors->setEnabled(false);
}
}