mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-27 19:45:43 +03:00
refact1
This commit is contained in:
158
LibInstructorsAndTrainees/instructors/dialogeditinstructor.cpp
Normal file
158
LibInstructorsAndTrainees/instructors/dialogeditinstructor.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "dialogeditinstructor.h"
|
||||
#include "ui_dialogeditinstructor.h"
|
||||
#include "hashtools.h"
|
||||
#include <QPushButton>
|
||||
#include <QRegExpValidator>
|
||||
#include <QToolTip>
|
||||
|
||||
DialogEditInstructor::DialogEditInstructor(bool adminMode, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogEditInstructor),
|
||||
instructorInput(),
|
||||
flNeedHashPassword(false),
|
||||
adminMode(adminMode)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
verify();
|
||||
|
||||
ui->editName->setProperty("mandatoryField", true);
|
||||
ui->editLogin->setProperty("mandatoryField", true);
|
||||
ui->editPassword->setProperty("mandatoryField", true);
|
||||
|
||||
ui->btnViewPassword->setObjectName("btnViewPassword");
|
||||
ui->btnChangePassword->setObjectName("btnChangePassword");
|
||||
|
||||
//ui->editName->setValidator(new QRegExpValidator(QRegExp("[A-Za-zА-Яа-я0-9 _\\d]+"), this));
|
||||
ui->editLogin->setValidator(new QRegExpValidator(QRegExp("[A-Za-z\\d]+"), this));
|
||||
|
||||
ui->editPassword->setEnabled(false);
|
||||
//#ifndef PROJECT_TYPE_DEBUG
|
||||
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
//#endif
|
||||
|
||||
ui->btnViewPassword->setEnabled(false);
|
||||
ui->btnChangePassword->setEnabled(false);
|
||||
|
||||
ui->btnOK->setEnabled(false);
|
||||
}
|
||||
|
||||
DialogEditInstructor::~DialogEditInstructor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogEditInstructor::setInstructor(Instructor instructor)
|
||||
{
|
||||
instructorInput = instructor;
|
||||
|
||||
ui->editName ->setText(instructor.getName());
|
||||
ui->editLogin->setText(instructor.getLogin());
|
||||
ui->editPassword->setText(instructor.getPassword());
|
||||
|
||||
ui->checkIsAdmin->setChecked(instructor.getIsAdmin());
|
||||
ui->checkArchived->setChecked(instructor.getArchived());
|
||||
ui->checkLoggedIn->setChecked(instructor.getLoggedIn());
|
||||
|
||||
if(instructor.getIsAdmin())
|
||||
{
|
||||
ui->editName->setEnabled(false);
|
||||
ui->editLogin->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->editName->setEnabled(true);
|
||||
ui->editLogin->setEnabled(true);
|
||||
}
|
||||
|
||||
if(instructor.getNeedSetPassword())
|
||||
{
|
||||
ui->editPassword->setEnabled(true);
|
||||
ui->btnViewPassword->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(adminMode)
|
||||
ui->btnChangePassword->setEnabled(true);
|
||||
}
|
||||
|
||||
ui->btnOK->setEnabled(false);
|
||||
}
|
||||
|
||||
Instructor DialogEditInstructor::getInstructor()
|
||||
{
|
||||
Instructor instructor = instructorInput;
|
||||
|
||||
instructor.setName(ui->editName->text());
|
||||
instructor.setLogin(ui->editLogin->text());
|
||||
|
||||
if(flNeedHashPassword)
|
||||
{
|
||||
QString psw = ui->editPassword->text();
|
||||
psw = HashTools::hashingMD5string(psw);
|
||||
instructor.setPassword(psw);
|
||||
}
|
||||
else
|
||||
instructor.setPassword(ui->editPassword->text());
|
||||
|
||||
instructor.setIsAdmin(ui->checkIsAdmin->isChecked());
|
||||
instructor.setArchived(ui->checkArchived->isChecked());
|
||||
instructor.setLoggedIn(ui->checkLoggedIn->isChecked());
|
||||
|
||||
return instructor;
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_editName_textChanged(const QString &arg1)
|
||||
{
|
||||
verify();
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_editLogin_textChanged(const QString &arg1)
|
||||
{
|
||||
verify();
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_editPassword_textChanged(const QString &arg1)
|
||||
{
|
||||
verify();
|
||||
}
|
||||
|
||||
void DialogEditInstructor::verify()
|
||||
{
|
||||
if(ui->editName->text().trimmed() == QStringLiteral("") ||
|
||||
ui->editLogin->text().trimmed() == QStringLiteral("") ||
|
||||
ui->editPassword->text().trimmed() == QStringLiteral(""))
|
||||
ui->btnOK->setEnabled(false);
|
||||
else
|
||||
ui->btnOK->setEnabled(true);
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_btnOK_clicked()
|
||||
{
|
||||
this->accept();
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_btnViewPassword_pressed()
|
||||
{
|
||||
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Normal);
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_btnViewPassword_released()
|
||||
{
|
||||
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_btnChangePassword_clicked()
|
||||
{
|
||||
ui->editPassword->setEnabled(true);
|
||||
ui->btnViewPassword->setEnabled(true);
|
||||
|
||||
ui->editPassword->setText("");
|
||||
flNeedHashPassword = true;
|
||||
|
||||
ui->editPassword->setFocus();
|
||||
}
|
||||
|
||||
void DialogEditInstructor::on_editLogin_inputRejected()
|
||||
{
|
||||
QToolTip::showText(QCursor::pos(),tr("Only Latin letters and numbers"));
|
||||
}
|
||||
53
LibInstructorsAndTrainees/instructors/dialogeditinstructor.h
Normal file
53
LibInstructorsAndTrainees/instructors/dialogeditinstructor.h
Normal file
@@ -0,0 +1,53 @@
|
||||
#ifndef DIALOGEDITINSTRUCTOR_H
|
||||
#define DIALOGEDITINSTRUCTOR_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "instructor.h"
|
||||
//#include "ui_dialogeditinstructor.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogEditInstructor;
|
||||
}
|
||||
|
||||
class DialogEditInstructor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogEditInstructor(bool adminMode, QWidget *parent = nullptr);
|
||||
~DialogEditInstructor();
|
||||
|
||||
void setInstructor(Instructor instructor);
|
||||
Instructor getInstructor();
|
||||
|
||||
private slots:
|
||||
void on_editName_textChanged(const QString &arg1);
|
||||
|
||||
void on_editLogin_textChanged(const QString &arg1);
|
||||
|
||||
void on_editPassword_textChanged(const QString &arg1);
|
||||
|
||||
void on_btnOK_clicked();
|
||||
|
||||
void on_btnViewPassword_pressed();
|
||||
|
||||
void on_btnViewPassword_released();
|
||||
|
||||
void on_btnChangePassword_clicked();
|
||||
|
||||
void on_editLogin_inputRejected();
|
||||
|
||||
private:
|
||||
void verify();
|
||||
|
||||
private:
|
||||
Ui::DialogEditInstructor *ui;
|
||||
|
||||
Instructor instructorInput;
|
||||
|
||||
bool flNeedHashPassword;
|
||||
|
||||
bool adminMode;
|
||||
};
|
||||
|
||||
#endif // DIALOGEDITINSTRUCTOR_H
|
||||
247
LibInstructorsAndTrainees/instructors/dialogeditinstructor.ui
Normal file
247
LibInstructorsAndTrainees/instructors/dialogeditinstructor.ui
Normal file
@@ -0,0 +1,247 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogEditInstructor</class>
|
||||
<widget class="QDialog" name="DialogEditInstructor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>470</width>
|
||||
<height>286</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Instructor</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editName">
|
||||
<property name="enabled">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editLogin"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_Password">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editPassword"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnViewPassword">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/eye.png</normaloff>:/resources/icons/eye.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>16</width>
|
||||
<height>16</height>
|
||||
</size>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnChangePassword">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/exchange.png</normaloff>:/resources/icons/exchange.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="Line" name="line">
|
||||
<property name="lineWidth">
|
||||
<number>2</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkIsAdmin">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Administrator</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/admin.png</normaloff>
|
||||
<disabledoff>:/resources/icons/admin.png</disabledoff>:/resources/icons/admin.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkArchived">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Archived</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/archive.png</normaloff>
|
||||
<disabledoff>:/resources/icons/archive.png</disabledoff>:/resources/icons/archive.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_7">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="checkLoggedIn">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Online</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/circleGreen.png</normaloff>
|
||||
<disabledoff>:/resources/icons/circleGreen.png</disabledoff>:/resources/icons/circleGreen.png</iconset>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnOK">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Save</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../InstructorsAndTrainees.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
@@ -0,0 +1,33 @@
|
||||
#include <QHBoxLayout>
|
||||
#include "dialogredactorinstructors.h"
|
||||
|
||||
DialogRedactorInstructors::DialogRedactorInstructors(ConnectorToServer* connectorToServer,
|
||||
bool adminMode, QWidget *parent) :
|
||||
QDialog(parent,
|
||||
Qt::WindowSystemMenuHint
|
||||
| Qt::WindowMaximizeButtonHint
|
||||
| Qt::WindowMinimizeButtonHint
|
||||
| Qt::WindowCloseButtonHint),
|
||||
editorInstructors(nullptr)
|
||||
{
|
||||
editorInstructors = new EditorInstructors(connectorToServer, adminMode, this);
|
||||
connect(connectorToServer, &ConnectorToServer::signal_UpdateDB, editorInstructors, &EditorInstructors::slot_NeedUpdateUI);
|
||||
editorInstructors->activate();
|
||||
|
||||
QHBoxLayout *layout = new QHBoxLayout(this);
|
||||
layout->addWidget(editorInstructors);
|
||||
this->setWindowTitle(tr("Editor of instructors"));
|
||||
this->setMinimumSize(1400, 700);
|
||||
//this->setWindowState(Qt::WindowMaximized);
|
||||
this->setModal(true);
|
||||
}
|
||||
|
||||
DialogRedactorInstructors::~DialogRedactorInstructors()
|
||||
{
|
||||
delete editorInstructors;
|
||||
}
|
||||
|
||||
void DialogRedactorInstructors::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
editorInstructors->close();
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#ifndef DIALOGREDACTORINSTRUCTORS_H
|
||||
#define DIALOGREDACTORINSTRUCTORS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QObject>
|
||||
#include "connectortoserver.h"
|
||||
#include "editorinstructors.h"
|
||||
|
||||
class DialogRedactorInstructors : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
DialogRedactorInstructors(ConnectorToServer* connectorToServer, bool adminMode, QWidget *parent = nullptr);
|
||||
~DialogRedactorInstructors();
|
||||
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private:
|
||||
EditorInstructors* editorInstructors;
|
||||
};
|
||||
|
||||
#endif // DIALOGREDACTORINSTRUCTORS_H
|
||||
371
LibInstructorsAndTrainees/instructors/editorinstructors.cpp
Normal file
371
LibInstructorsAndTrainees/instructors/editorinstructors.cpp
Normal file
@@ -0,0 +1,371 @@
|
||||
#include <QMessageBox>
|
||||
#include "editorinstructors.h"
|
||||
#include "specialmessagebox.h"
|
||||
#include "ui_editorinstructors.h"
|
||||
|
||||
EditorInstructors::EditorInstructors(ConnectorToServer* connectorToServer, bool adminMode, QWidget *parent) :
|
||||
InstructorsView(connectorToServer, CommonView::TypeView::control, parent),
|
||||
ui(new Ui::EditorInstructors),
|
||||
dlgEditInstructor(nullptr)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(false);
|
||||
|
||||
connect(treeWidget, &QTreeWidget::currentItemChanged, this, &EditorInstructors::on_treeWidgetCurrentItemChanged);
|
||||
|
||||
ui->verticalLayout_1->addWidget(treeWidget);
|
||||
|
||||
this->adminMode = adminMode;
|
||||
|
||||
preparationTreeWidget();
|
||||
//setNotLoggedInVisible(true);
|
||||
loadInstructorsFromDB();
|
||||
|
||||
if(adminMode)
|
||||
ui->btnArchive->click();
|
||||
|
||||
waitAnimationWidget->setParent(this);
|
||||
|
||||
authComplited = true;
|
||||
}
|
||||
|
||||
EditorInstructors::~EditorInstructors()
|
||||
{
|
||||
if(dlgEditInstructor)
|
||||
{
|
||||
dlgEditInstructor->close();
|
||||
delete dlgEditInstructor;
|
||||
dlgEditInstructor = nullptr;
|
||||
}
|
||||
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditorInstructors::closeEvent(QCloseEvent *event)
|
||||
{
|
||||
if(dlgEditInstructor)
|
||||
dlgEditInstructor->close();
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnNewInstructor_clicked()
|
||||
{
|
||||
Instructor instructor;
|
||||
Instructor instructor_edit;
|
||||
|
||||
instructor.setNeedSetPassword(true);
|
||||
|
||||
if(editInstructor(instructor, &instructor_edit))
|
||||
{
|
||||
waitAnimationWidget->showWithPlay();
|
||||
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR, 0, &instructor_edit);
|
||||
}
|
||||
|
||||
lastCurrentID = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnDeleteInstructor_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
int id = treeItemCurrent->text(ColumnsTreeUsers::clmn_ID).toInt();
|
||||
|
||||
if(connectorToServer->isAdminInstructor(id))
|
||||
{//Это Админ!
|
||||
SpecMsgBox::CriticalClose(this, tr("You cannot delete the Administrator."));
|
||||
return;
|
||||
}
|
||||
|
||||
if(connectorToServer->isLoggedInInstructor(id))
|
||||
{//Инструктор залогирован!
|
||||
SpecMsgBox::CriticalClose(this, tr("You cannot delete a logged-in instructor."));
|
||||
return;
|
||||
}
|
||||
|
||||
if(SpecMsgBox::WarningYesNo(this, tr("The deletion will be irrevocable.\nDelete it anyway?")) == QDialog::Accepted)
|
||||
{
|
||||
waitAnimationWidget->showWithPlay();
|
||||
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_DEL_INSTRUCTOR, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnToOrFromArchive_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
int id = treeItemCurrent->text(ColumnsTreeUsers::clmn_ID).toInt();
|
||||
|
||||
Instructor instructor = connectorToServer->getInstructor(id);
|
||||
if(instructor.getID() == 0)
|
||||
return;
|
||||
|
||||
if(connectorToServer->isArchivedInstructor(id))
|
||||
{//Архивный
|
||||
instructor.setArchived(false);
|
||||
waitAnimationWidget->showWithPlay();
|
||||
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor);
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
if(connectorToServer->isLoggedInInstructor(id))
|
||||
{//Инструктор залогирован!
|
||||
SpecMsgBox::CriticalClose(this, tr("You cannot archive a logged-in instructor."));
|
||||
return;
|
||||
}
|
||||
|
||||
instructor.setArchived(true);
|
||||
waitAnimationWidget->showWithPlay();
|
||||
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor);
|
||||
if(!archiveVisible)
|
||||
ui->btnArchive->click();
|
||||
/*if(int id_edit = dbLMS->editInstructor(instructor))
|
||||
{
|
||||
if(!archiveVisible)
|
||||
ui->btnArchive->click();
|
||||
|
||||
loadInstructorsFromDB();
|
||||
setCurrentInstructor(id_edit);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnEdit_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent == nullptr)
|
||||
return;
|
||||
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран Инструктор
|
||||
|
||||
int id = treeItemCurrent->text(ColumnsTreeUsers::clmn_ID).toInt();
|
||||
|
||||
if(connectorToServer->isLoggedInInstructor(id) && !adminMode)
|
||||
{//Инструктор залогирован!
|
||||
SpecMsgBox::CriticalClose(this, tr("You cannot edit a logged-in instructor."));
|
||||
return;
|
||||
}
|
||||
|
||||
Instructor instructor = connectorToServer->getInstructor(id);
|
||||
if(instructor.getID() == 0)
|
||||
return;
|
||||
|
||||
Instructor instructor_edit;
|
||||
|
||||
if(editInstructor(instructor, &instructor_edit))
|
||||
{
|
||||
waitAnimationWidget->showWithPlay();
|
||||
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor_edit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorInstructors::on_btnArchive_clicked()
|
||||
{
|
||||
bool state = ui->btnArchive->isChecked();
|
||||
setArchiveVisible(state);
|
||||
if(!state)
|
||||
{
|
||||
Instructor instructor = connectorToServer->getInstructor(lastCurrentID);
|
||||
if(instructor.getID())
|
||||
{
|
||||
if(instructor.getArchived())
|
||||
lastCurrentID = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
lastCurrentID = 0;
|
||||
}
|
||||
}
|
||||
loadInstructorsFromDB();
|
||||
}
|
||||
|
||||
void EditorInstructors::on_treeWidgetCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||
{
|
||||
//Определяем доступность и функционал кнопок для выбранного элемента
|
||||
|
||||
if(current == nullptr)
|
||||
{
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
QTreeWidgetItem *treeItemParent = current->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбран инструктор
|
||||
|
||||
int id = current->text(ColumnsTreeUsers::clmn_ID).toInt();
|
||||
|
||||
lastCurrentID = id;
|
||||
|
||||
if(connectorToServer->isArchivedInstructor(id))
|
||||
{//Архивный
|
||||
ui->btnToOrFromArchive->setText(tr("From archive"));
|
||||
ui->btnToOrFromArchive->setIcon(QIcon(QStringLiteral(":/resources/icons/instructorFromArchive.png")));
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
ui->btnToOrFromArchive->setText(tr("To archive"));
|
||||
ui->btnToOrFromArchive->setIcon(QIcon(QStringLiteral(":/resources/icons/instructorArchive.png")));
|
||||
}
|
||||
|
||||
ui->btnNewInstructor->setEnabled(true);
|
||||
|
||||
if(connectorToServer->isAdminInstructor(id))
|
||||
{//Это Админ! Удалять/Архивировать/Редактировать нельзя! (Только сменить пароль, если это он сам)
|
||||
if(adminMode)
|
||||
{
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(false);
|
||||
}
|
||||
}
|
||||
else if(connectorToServer->isLoggedInInstructor(id))
|
||||
{//Это Админ или залогированный! Удалять/Архивировать/Редактировать нельзя!
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->btnToOrFromArchive->setEnabled(true);
|
||||
|
||||
if(connectorToServer->isArchivedInstructor(id))
|
||||
ui->btnDeleteInstructor->setEnabled(true);
|
||||
else
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
|
||||
ui->btnEdit->setEnabled(true);
|
||||
}
|
||||
|
||||
//ui->btnEdit->setEnabled(true);
|
||||
ui->btnArchive->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
ui->btnDeleteInstructor->setEnabled(false);
|
||||
ui->btnToOrFromArchive->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
bool EditorInstructors::verifyInstructor(Instructor instructor)
|
||||
{
|
||||
//Проверка корректности логина, имени, пароля
|
||||
|
||||
if(instructor.getName() == QStringLiteral("<name>"))
|
||||
{//Имя не корректно!
|
||||
SpecMsgBox::CriticalClose(this, tr("Unacceptable instructor name has been entered.\nThe changes will not be accepted."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(instructor.getLogin() == QStringLiteral("<login>"))
|
||||
{//Логин не корректен!
|
||||
SpecMsgBox::CriticalClose(this, tr("Unacceptable instructor login has been entered.\nThe changes will not be accepted."));
|
||||
return false;
|
||||
}
|
||||
|
||||
if(instructor.getPassword() == QStringLiteral("<password>"))
|
||||
{//Пароль не корректный!
|
||||
SpecMsgBox::CriticalClose(this, tr("Unacceptable instructor password has been entered.\nThe changes will not be accepted."));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
int user_I = connectorToServer->getIdInstructorByLogin(instructor.getLogin());
|
||||
int user_T = connectorToServer->getIdTraineeByLogin(instructor.getLogin());
|
||||
if((user_I && (user_I != instructor.getID())) || (user_T && (user_T != instructor.getID())))
|
||||
{//Логин уже существует!
|
||||
SpecMsgBox::CriticalClose(this, tr("An existing instructor or trainee login has been entered.\nThe changes will not be accepted."));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool EditorInstructors::editInstructor(Instructor instructor, Instructor* instructor_edit)
|
||||
{
|
||||
dlgEditInstructor = new DialogEditInstructor(adminMode, this);
|
||||
dlgEditInstructor->setWindowFlags(dlgEditInstructor->windowFlags() & ~Qt::WindowContextHelpButtonHint);
|
||||
|
||||
dlgEditInstructor->setInstructor(instructor);
|
||||
|
||||
bool flStop = false;
|
||||
bool res = false;
|
||||
|
||||
while (!flStop)
|
||||
{
|
||||
switch( dlgEditInstructor->exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
*instructor_edit = dlgEditInstructor->getInstructor();
|
||||
|
||||
if(! verifyInstructor(*instructor_edit))
|
||||
{
|
||||
dlgEditInstructor->setInstructor(*instructor_edit);
|
||||
continue;
|
||||
}
|
||||
|
||||
if(instructor_edit->getNeedSetPassword())
|
||||
{
|
||||
//Хэшируем пароль
|
||||
instructor_edit->hashingPassword();
|
||||
instructor_edit->setNeedSetPassword(false);
|
||||
}
|
||||
|
||||
flStop = true;
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
flStop = true;
|
||||
res = false;
|
||||
break;
|
||||
default:
|
||||
flStop = true;
|
||||
res = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(dlgEditInstructor)
|
||||
{
|
||||
delete dlgEditInstructor;
|
||||
dlgEditInstructor = nullptr;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
48
LibInstructorsAndTrainees/instructors/editorinstructors.h
Normal file
48
LibInstructorsAndTrainees/instructors/editorinstructors.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef DIALOGINSTRUCTORS_H
|
||||
#define DIALOGINSTRUCTORS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTreeWidget>
|
||||
#include "instructorsview.h"
|
||||
#include "dialogeditinstructor.h"
|
||||
#include "specialmessagebox.h"
|
||||
|
||||
class DialogEditInstructor;
|
||||
|
||||
namespace Ui {
|
||||
class EditorInstructors;
|
||||
}
|
||||
|
||||
//Виджет для редактирования БД Инструкторов
|
||||
|
||||
class EditorInstructors : public InstructorsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditorInstructors(ConnectorToServer* connectorToServer, bool adminMode, QWidget *parent = nullptr);
|
||||
~EditorInstructors();
|
||||
|
||||
void closeEvent(QCloseEvent *event) override;
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_btnNewInstructor_clicked();
|
||||
void on_btnDeleteInstructor_clicked();
|
||||
void on_btnToOrFromArchive_clicked();
|
||||
void on_btnEdit_clicked();
|
||||
void on_btnArchive_clicked();
|
||||
void on_treeWidgetCurrentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
private:
|
||||
//void setCurrentInstructor(int id);
|
||||
bool verifyInstructor(Instructor instructor);
|
||||
|
||||
bool editInstructor(Instructor instructor, Instructor* instructor_edit);
|
||||
|
||||
private:
|
||||
Ui::EditorInstructors *ui;
|
||||
|
||||
DialogEditInstructor* dlgEditInstructor;
|
||||
};
|
||||
|
||||
#endif // DIALOGINSTRUCTORS_H
|
||||
246
LibInstructorsAndTrainees/instructors/editorinstructors.ui
Normal file
246
LibInstructorsAndTrainees/instructors/editorinstructors.ui
Normal file
@@ -0,0 +1,246 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditorInstructors</class>
|
||||
<widget class="QWidget" name="EditorInstructors">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1300</width>
|
||||
<height>800</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>List instructors</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_1">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_1"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnNewInstructor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>160</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New instructor</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/addInstructor.png</normaloff>:/resources/icons/addInstructor.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnDeleteInstructor">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>160</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete instructor</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/deleteInstructor.png</normaloff>:/resources/icons/deleteInstructor.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnToOrFromArchive">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>160</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>To archive</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/instructorArchive.png</normaloff>:/resources/icons/instructorArchive.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnEdit">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>160</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/edit.png</normaloff>:/resources/icons/edit.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnArchive">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>160</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Show archive</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/archive.png</normaloff>:/resources/icons/archive.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../InstructorsAndTrainees.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
150
LibInstructorsAndTrainees/instructors/instructorsview.cpp
Normal file
150
LibInstructorsAndTrainees/instructors/instructorsview.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#include <QHeaderView>
|
||||
#include <QTranslator>
|
||||
#include <QResizeEvent>
|
||||
#include <QScrollBar>
|
||||
#include "instructorsview.h"
|
||||
|
||||
InstructorsView::InstructorsView(ConnectorToServer* connectorToServer, TypeView type, QWidget *parent):
|
||||
CommonView(connectorToServer, type, parent)
|
||||
{
|
||||
typeObject = TypeObject::objInstructor;
|
||||
TypeUserDB = User::TypeUserDBInstructor;
|
||||
}
|
||||
|
||||
void InstructorsView::slot_NeedUpdateUI(bool treeInstructor, bool treeTrainee)
|
||||
{
|
||||
updateButtons();
|
||||
|
||||
if(authComplited)
|
||||
{
|
||||
if(treeInstructor)
|
||||
loadInstructorsFromDB();
|
||||
}
|
||||
}
|
||||
|
||||
void InstructorsView::loadInstructorsFromDB()
|
||||
{
|
||||
mtxTreeWidget.lock();
|
||||
|
||||
//Обновление дерева
|
||||
treeWidget->clear();
|
||||
|
||||
//Инструкторы
|
||||
QList<Instructor> listInstructors;
|
||||
|
||||
listInstructors = connectorToServer->getListInstructors();
|
||||
|
||||
for(Instructor instructor : listInstructors)
|
||||
{
|
||||
QTreeWidgetItem *ItemInstructor = new QTreeWidgetItem(treeWidget);
|
||||
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_ID, QString::number(instructor.getID()));
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Name, instructor.getName());
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Login, instructor.getLogin());
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Password, instructor.getPassword());
|
||||
|
||||
//Сокрытие пароля
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Password, QStringLiteral("******"));
|
||||
|
||||
if(instructor.getArchived())
|
||||
{//Архивный
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Archived, tr("yes"));
|
||||
ItemInstructor->setIcon(ColumnsTreeUsers::clmn_Name, QIcon(QStringLiteral(":/resources/icons/archive.png")));
|
||||
setItemColorArchive(ItemInstructor);
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Archived, tr("no"));
|
||||
ItemInstructor->setIcon(ColumnsTreeUsers::clmn_Name, QIcon(QStringLiteral(":/resources/icons/instructor.png")));
|
||||
setItemColorNoArchive(ItemInstructor);
|
||||
}
|
||||
|
||||
if(instructor.getIsAdmin())
|
||||
{//Админ
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Administrator, tr("yes"));
|
||||
ItemInstructor->setIcon(ColumnsTreeUsers::clmn_Name, QIcon(QStringLiteral(":/resources/icons/admin.png")));
|
||||
}
|
||||
else
|
||||
{//Не Админ
|
||||
ItemInstructor->setText(ColumnsTreeUsers::clmn_Administrator, tr("no"));
|
||||
}
|
||||
|
||||
if(instructor.getLoggedIn())
|
||||
{//Залогинен
|
||||
//ItemInstructor->setText(ColumnsTreeUsers::clmn_Logged, tr("yes"));
|
||||
ItemInstructor->setIcon(ColumnsTreeUsers::clmn_Logged, QIcon(QStringLiteral(":/resources/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{//Не Залогинен
|
||||
//ItemInstructor->setText(ColumnsTreeUsers::clmn_Logged, tr("no"));
|
||||
ItemInstructor->setIcon(ColumnsTreeUsers::clmn_Logged, QIcon(QStringLiteral(":/resources/icons/circleGray.png")));
|
||||
}
|
||||
|
||||
//Скрываем архивных (при необходимости)
|
||||
if(instructor.getArchived())
|
||||
if(! archiveVisible)
|
||||
ItemInstructor->setHidden(true);
|
||||
|
||||
//Скрываем незалогиненых (при необходимости)
|
||||
if(! instructor.getLoggedIn())
|
||||
if(! notLoggedInVisible)
|
||||
ItemInstructor->setHidden(true);
|
||||
|
||||
mtxmapNewMsg.lock();
|
||||
if(mapNewMsg.contains(instructor.getID()))
|
||||
{//Есть непрочитанные сообщения от него
|
||||
if(mapNewMsg.value(instructor.getID()))
|
||||
{
|
||||
if(lastCurrentID == instructor.getID())
|
||||
mapNewMsg.take(lastCurrentID);
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < ColumnsTreeUsers::clmn_count; i++)
|
||||
{
|
||||
ItemInstructor->setBackground(i, QBrush(QColor(250, 210, 1)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mtxmapNewMsg.unlock();
|
||||
}
|
||||
|
||||
treeWidget->expandAll();
|
||||
|
||||
/*
|
||||
//if(typeView == TypeView::control)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(0);
|
||||
if(item != nullptr)
|
||||
treeWidget->setCurrentItem(item);
|
||||
}*/
|
||||
|
||||
setCurrentInstructor(lastCurrentID);
|
||||
|
||||
treeWidget->sortItems(ColumnsTreeUsers::clmn_Name, Qt::SortOrder::AscendingOrder);
|
||||
|
||||
mtxTreeWidget.unlock();
|
||||
|
||||
waitAnimationWidget->hideWithStop();
|
||||
}
|
||||
|
||||
void InstructorsView::setCurrentInstructor(int id)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
|
||||
if(item != nullptr)
|
||||
if(item->text(ColumnsTreeUsers::clmn_ID).toInt() == id)
|
||||
{
|
||||
treeWidget->setCurrentItem(item);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(0);
|
||||
if(item != nullptr)
|
||||
treeWidget->setCurrentItem(item);
|
||||
*/
|
||||
}
|
||||
|
||||
26
LibInstructorsAndTrainees/instructors/instructorsview.h
Normal file
26
LibInstructorsAndTrainees/instructors/instructorsview.h
Normal file
@@ -0,0 +1,26 @@
|
||||
#ifndef INSTRUCTORSVIEW_H
|
||||
#define INSTRUCTORSVIEW_H
|
||||
|
||||
#include "instructorsAndTrainees_global.h"
|
||||
#include "commonview.h"
|
||||
|
||||
//Родительский класс представления БД Инструкторов (для просмотра и управления)
|
||||
|
||||
class InstructorsView: public CommonView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
InstructorsView(ConnectorToServer* connectorToServer, TypeView type, QWidget *parent = nullptr);
|
||||
|
||||
public Q_SLOTS:
|
||||
//Слот обработки сигнала необходимости обновления интерфейса
|
||||
void slot_NeedUpdateUI(bool treeInstructor, bool treeTrainee);
|
||||
|
||||
protected:
|
||||
virtual void updateButtons(){};
|
||||
void loadInstructorsFromDB();
|
||||
void setCurrentInstructor(int id);
|
||||
};
|
||||
|
||||
#endif // INSTRUCTORSVIEW_H
|
||||
143
LibInstructorsAndTrainees/instructors/viewerinstructors.cpp
Normal file
143
LibInstructorsAndTrainees/instructors/viewerinstructors.cpp
Normal file
@@ -0,0 +1,143 @@
|
||||
#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);
|
||||
}
|
||||
}
|
||||
51
LibInstructorsAndTrainees/instructors/viewerinstructors.h
Normal file
51
LibInstructorsAndTrainees/instructors/viewerinstructors.h
Normal file
@@ -0,0 +1,51 @@
|
||||
#ifndef INSTRUCTORSWIDGET_H
|
||||
#define INSTRUCTORSWIDGET_H
|
||||
|
||||
#include "instructorsview.h"
|
||||
#include "dialogredactorinstructors.h"
|
||||
|
||||
namespace Ui {
|
||||
class ViewerInstructors;
|
||||
}
|
||||
|
||||
//Виджет только для просмотра БД Инструкторов
|
||||
|
||||
class ViewerInstructors : public InstructorsView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ViewerInstructors(ConnectorToServer* connectorToServer, QWidget *parent = nullptr);
|
||||
~ViewerInstructors();
|
||||
|
||||
public:
|
||||
void setAuthComplited(bool authComplited);
|
||||
|
||||
void deactivate();
|
||||
|
||||
protected:
|
||||
void changeEvent(QEvent * event) override;
|
||||
|
||||
public slots:
|
||||
void slot_receiveMessage(ClientMessage clientMessage);
|
||||
|
||||
public Q_SLOTS:
|
||||
void on_btnEditorInstructors_clicked();
|
||||
|
||||
void on_treeWidgetItemClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
Q_SIGNALS:
|
||||
//сигнал о выборе инструктора
|
||||
void signal_instructorSelected(int id_instructor);
|
||||
|
||||
private:
|
||||
void updateButtons() override;
|
||||
|
||||
private:
|
||||
DialogRedactorInstructors* dlgRedactor;
|
||||
|
||||
private:
|
||||
Ui::ViewerInstructors *ui;
|
||||
};
|
||||
|
||||
#endif // INSTRUCTORSWIDGET_H
|
||||
73
LibInstructorsAndTrainees/instructors/viewerinstructors.ui
Normal file
73
LibInstructorsAndTrainees/instructors/viewerinstructors.ui
Normal file
@@ -0,0 +1,73 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ViewerInstructors</class>
|
||||
<widget class="QWidget" name="ViewerInstructors">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Instructors</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_0">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_1"/>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnEditorInstructors">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>58</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Editor of Instructors</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../InstructorsAndTrainees.qrc">
|
||||
<normaloff>:/resources/icons/DB-instructors.png</normaloff>:/resources/icons/DB-instructors.png</iconset>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>32</width>
|
||||
<height>32</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="toolButtonStyle">
|
||||
<enum>Qt::ToolButtonTextUnderIcon</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../InstructorsAndTrainees.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user