Files
RRJServer/InstructorsAndTrainees/instructors/viewerinstructors.cpp
2025-09-17 17:42:34 +03:00

117 lines
3.1 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),
dlgEditor(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(dlgEditor)
dlgEditor->close();
delete ui;
}
void ViewerInstructors::setAuthComplited(bool authComplited)
{
this->authComplited = authComplited;
updateButtons();
}
void ViewerInstructors::deactivate()
{
if(dlgEditor)
dlgEditor->close();
CommonView::deactivate();
updateButtons();
}
void ViewerInstructors::changeEvent(QEvent *event)
{
// В случае получения события изменения языка приложения
if (event->type() == QEvent::LanguageChange)
{// переведём окно заново
ui->retranslateUi(this);
reSetHeadTreeWidget();
slot_NeedUpdateUI(true, false);
}
}
void ViewerInstructors::on_btnEditorInstructors_clicked()
{
Q_EMIT signal_BlockAutorization(true);
EditorInstructors* editorInstructors = new EditorInstructors(connectorToServer, adminMode);
connect(connectorToServer, &ConnectorToServer::signal_UpdateDB, editorInstructors, &EditorInstructors::slot_NeedUpdateUI);
editorInstructors->activate();
dlgEditor = new QDialog(this);
QHBoxLayout *layout = new QHBoxLayout(dlgEditor);
layout->addWidget(editorInstructors);
dlgEditor->setWindowTitle(tr("Editor of instructors"));
dlgEditor->setMinimumSize(1400, 700);
dlgEditor->setWindowFlags(dlgEditor->windowFlags() & ~Qt::WindowContextHelpButtonHint);
dlgEditor->exec();
delete dlgEditor;
dlgEditor = nullptr;
if(authComplited)
loadInstructorsFromDB();
Q_EMIT signal_BlockAutorization(false);
}
void ViewerInstructors::on_treeWidgetItemClicked(QTreeWidgetItem *item, int column)
{
if(item == nullptr)
return;
//if(current->childCount() == 0)
{//Выбран обучаемый
QString login = item->text(ColumnsTreeInsructors::clmn_Login);
//if(login != "")
{
int newCurrentID = connectorToServer->getIdInstructorByLogin(login);
//if(newCurrentID == lastCurrentID)
//return;
lastCurrentID = newCurrentID;
Q_EMIT signal_instructorSelected(newCurrentID);
}
}
}
void ViewerInstructors::updateButtons()
{
if(adminMode && authComplited)
{
ui->btnEditorInstructors->setEnabled(true);
}
else
{
ui->btnEditorInstructors->setEnabled(false);
}
}