Переделано под один мега-проект LMS с общим CMakeLists.txt

This commit is contained in:
krivoshein
2025-01-15 12:34:56 +03:00
parent 3064818931
commit 1c93b1f94d
219 changed files with 68 additions and 51 deletions

View File

@@ -0,0 +1,19 @@
#include "dialogauthorizationinstructor.h"
#include "ui_dialogauthorizationinstructor.h"
DialogAuthorizationInstructor::DialogAuthorizationInstructor(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogAuthorizationInstructor)
{
ui->setupUi(this);
ui->editLogin->setProperty("mandatoryField", true);
ui->editPassword->setProperty("mandatoryField", true);
ui->editPassword->setEchoMode(QLineEdit::EchoMode::Password);
}
DialogAuthorizationInstructor::~DialogAuthorizationInstructor()
{
delete ui;
}

View File

@@ -0,0 +1,33 @@
#ifndef DIALOGAUTHORIZATIONINSTRUCTOR_H
#define DIALOGAUTHORIZATIONINSTRUCTOR_H
#include <QDialog>
#include "ui_dialogauthorizationinstructor.h"
namespace Ui {
class DialogAuthorizationInstructor;
}
class DialogAuthorizationInstructor : public QDialog
{
Q_OBJECT
public:
explicit DialogAuthorizationInstructor(QWidget *parent = nullptr);
~DialogAuthorizationInstructor();
QString getLogin()
{
return ui->editLogin->text();
}
QString getPassword()
{
return ui->editPassword->text();
}
private:
Ui::DialogAuthorizationInstructor *ui;
};
#endif // DIALOGAUTHORIZATIONINSTRUCTOR_H

View File

@@ -0,0 +1,148 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DialogAuthorizationInstructor</class>
<widget class="QDialog" name="DialogAuthorizationInstructor">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>300</width>
<height>140</height>
</rect>
</property>
<property name="font">
<font>
<family>Tahoma</family>
<pointsize>10</pointsize>
</font>
</property>
<property name="windowTitle">
<string>Instructor authorization</string>
</property>
<property name="windowIcon">
<iconset resource="../resources.qrc">
<normaloff>:/icons/login-user.png</normaloff>:/icons/login-user.png</iconset>
</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_1">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Login</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_2">
<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="editLogin">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>admin</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="editPassword">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>admin</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogAuthorizationInstructor</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogAuthorizationInstructor</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,79 @@
#include "dialogeditinstructor.h"
#include "ui_dialogeditinstructor.h"
#include <QPushButton>
DialogEditInstructor::DialogEditInstructor(QWidget *parent) :
QDialog(parent),
ui(new Ui::DialogEditInstructor),
instructorInput()
{
ui->setupUi(this);
verify();
ui->editName->setProperty("mandatoryField", true);
ui->editLogin->setProperty("mandatoryField", true);
ui->editPassword->setProperty("mandatoryField", true);
}
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);
else
ui->editName->setEnabled(true);
}
Instructor DialogEditInstructor::getInstructor()
{
Instructor instructor = instructorInput;
instructor.setName(ui->editName->text());
instructor.setLogin(ui->editLogin->text());
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->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
else
ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
}

View File

@@ -0,0 +1,39 @@
#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(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);
private:
void verify();
private:
Ui::DialogEditInstructor *ui;
Instructor instructorInput;
};
#endif // DIALOGEDITINSTRUCTOR_H

View File

@@ -0,0 +1,226 @@
<?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>300</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>
<widget class="QLineEdit" name="editPassword"/>
</item>
</layout>
</item>
</layout>
</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="../resources.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="../resources.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>Logged</string>
</property>
<property name="icon">
<iconset resource="../resources.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>
</layout>
</item>
<item row="1" column="0">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="locale">
<locale language="English" country="UnitedStates"/>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>DialogEditInstructor</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>DialogEditInstructor</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,336 @@
#include <QMessageBox>
#include "editorinstructors.h"
#include "dialogeditinstructor.h"
#include "ui_editorinstructors.h"
EditorInstructors::EditorInstructors(ConnectorToServer* connectorToServer, bool adminMode, QWidget *parent) :
InstructorsView(connectorToServer, CommonView::TypeView::control, parent),
ui(new Ui::EditorInstructors)
{
ui->setupUi(this);
connect(treeWidget, &QTreeWidget::currentItemChanged, this, &EditorInstructors::on_treeWidget_currentItemChanged);
ui->verticalLayout_1->addWidget(treeWidget);
this->adminMode = adminMode;
preparationTreeWidget();
//setNotLoggedInVisible(true);
loadInstructorsFromDB();
if(adminMode)
ui->btnArchive->click();
}
EditorInstructors::~EditorInstructors()
{
delete ui;
}
void EditorInstructors::on_btnNewInstructor_clicked()
{
Instructor instructor;
Instructor instructor_edit;
if(editInstructor(instructor, &instructor_edit))
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_NEW_INSTRUCTOR, 0, &instructor_edit);
return;
/*
if(int id_instructor = dbLMS->newInstructor())
{
loadInstructorsFromDB();
setCurrentInstructor(id_instructor);
DialogEditInstructor dlg(this);
Instructor instructor = dbLMS->getInstructor(id_instructor);
if(instructor.getID() == 0)
return;
dlg.setInstructor(instructor);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
Instructor instructor_edit = dlg.getInstructor();
if(int id_edit = dbLMS->editInstructor(instructor_edit))
{//Отредактировано
loadInstructorsFromDB();
setCurrentInstructor(id_edit);
return;
}
else
{
dlg.setInstructor(instructor_edit);
continue;
}
}
case QDialog::Rejected:
dbLMS->delInstructor(id_instructor);
loadInstructorsFromDB();
return;
default:
dbLMS->delInstructor(id_instructor);
loadInstructorsFromDB();
return;
}
}
}
*/
}
void EditorInstructors::on_btnDeleteInstructor_clicked()
{
QTreeWidgetItem *treeItemCurrent = treeWidget->currentItem();
if(treeItemCurrent != nullptr)
{
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
if(treeItemParent == nullptr)
{//Выбран Инструктор
int id = treeItemCurrent->text(ColumnsTreeInsructors::clmn_ID).toInt();
if(connectorToServer->isAdminInstructor(id))
{//Это Админ!
QMessageBox::critical(this, tr("Error!"), tr("You cannot delete the Administrator."));
return;
}
if(connectorToServer->isLoggedInInstructor(id))
{//Инструктор залогирован!
QMessageBox::critical(this, tr("Error!"), tr("You cannot delete a logged-in instructor."));
return;
}
if(QMessageBox::warning(this, tr("Attention!"), tr("The deletion will be irrevocable.\nDelete it anyway?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
{
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(ColumnsTreeInsructors::clmn_ID).toInt();
Instructor instructor = connectorToServer->getInstructor(id);
if(instructor.getID() == 0)
return;
if(connectorToServer->isArchivedInstructor(id))
{//Архивный
instructor.setArchived(false);
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor);
}
else
{//Не Архивный
if(connectorToServer->isLoggedInInstructor(id))
{//Инструктор залогирован!
QMessageBox::critical(this, tr("Error!"), tr("You cannot archive a logged-in instructor."));
return;
}
instructor.setArchived(true);
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(ColumnsTreeInsructors::clmn_ID).toInt();
if(connectorToServer->isLoggedInInstructor(id))
{//Инструктор залогирован!
QMessageBox::critical(this, tr("Error!"), 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))
connectorToServer->sendQueryToDB(TypeQueryToDB::TYPE_QUERY_EDIT_INSTRUCTOR, id, &instructor_edit);
}
}
void EditorInstructors::on_btnArchive_clicked()
{
bool state = ui->btnArchive->isChecked();
setArchiveVisible(state);
if(!state)
{
lastCurrentID = 0;
}
loadInstructorsFromDB();
}
void EditorInstructors::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
{
//Определяем доступность и функционал кнопок для выбранного элемента
if(current == nullptr)
return;
QTreeWidgetItem *treeItemParent = current->parent();
if(treeItemParent == nullptr)
{//Выбран инструктор
int id = current->text(ColumnsTreeInsructors::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) || 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);
}
}
bool EditorInstructors::verifyInstructor(Instructor instructor)
{
//Проверка корректности логина, имени, пароля
if(instructor.getName() == QStringLiteral("<instructor>"))
{//Имя не корректно!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable instructor name has been entered.\nThe changes will not be accepted."));
return false;
}
if(instructor.getLogin() == QStringLiteral("<login>"))
{//Логин не корректен!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable instructor login has been entered.\nThe changes will not be accepted."));
return false;
}
if(instructor.getPassword() == QStringLiteral("<password>"))
{//Пароль не корректный!
QMessageBox::critical(this, tr("Editing error!"),
tr("Unacceptable instructor password has been entered.\nThe changes will not be accepted."));
return false;
}
QList<Instructor> listInstructors = connectorToServer->getListInstructors();
for(Instructor exist_instructor : listInstructors)
{
if(instructor.getName() == exist_instructor.getName() && instructor.getID() != exist_instructor.getID())
{//Имя уже существует
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing instructor name has been entered."));
return false;
}
if(instructor.getLogin() == exist_instructor.getLogin() && instructor.getID() != exist_instructor.getID())
{//Логин уже существует!
QMessageBox::critical(this, tr("Editing error!"),
tr("An existing instructor login has been entered.\nThe changes will not be accepted."));
return false;
}
}
return true;
}
bool EditorInstructors::editInstructor(Instructor instructor, Instructor* instructor_edit)
{
DialogEditInstructor dlg(this);
dlg.setInstructor(instructor);
while (true)
{
switch( dlg.exec() )
{
case QDialog::Accepted:
{
*instructor_edit = dlg.getInstructor();
if(! verifyInstructor(*instructor_edit))
{
dlg.setInstructor(*instructor_edit);
continue;
}
return true;
}
case QDialog::Rejected:
return false;
default:
return false;
}
}
}

View File

@@ -0,0 +1,40 @@
#ifndef DIALOGINSTRUCTORS_H
#define DIALOGINSTRUCTORS_H
#include <QDialog>
#include <QTreeWidget>
#include "instructorsview.h"
namespace Ui {
class EditorInstructors;
}
//Виджет для редактирования БД Инструкторов
class EditorInstructors : public InstructorsView
{
Q_OBJECT
public:
explicit EditorInstructors(ConnectorToServer* connectorToServer, bool adminMode, QWidget *parent = nullptr);
~EditorInstructors();
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_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
private:
//void setCurrentInstructor(int id);
bool verifyInstructor(Instructor instructor);
bool editInstructor(Instructor instructor, Instructor* instructor_edit);
private:
Ui::EditorInstructors *ui;
};
#endif // DIALOGINSTRUCTORS_H

View File

@@ -0,0 +1,240 @@
<?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="Fixed" 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="../resources.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="Fixed" 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="../resources.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="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="../resources.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="Fixed" 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="../resources.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="Fixed" 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="../resources.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="../resources.qrc"/>
</resources>
<connections/>
</ui>

View File

@@ -0,0 +1,203 @@
#include <QHeaderView>
#include <QTranslator>
#include "instructorsview.h"
InstructorsView::InstructorsView(ConnectorToServer* connectorToServer, TypeView type, QWidget *parent):
CommonView(connectorToServer, type, parent)
{
typeObject = TypeObject::objInstructor;
}
void InstructorsView::slot_NeedUpdateUI(bool treeInstructor, bool treeTrainee)
{
if(typeView == TypeView::onlyView)
{
if(adminMode)
archiveVisible = false;
else
archiveVisible = false;
}
else
{
archiveVisible = true;
}
if(adminMode)
{
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_ID, false);
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Archived, false);
}
else
{
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_ID, true);
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Archived, true);
}
updateButtons();
if(treeInstructor)
loadInstructorsFromDB();
}
void InstructorsView::preparationTreeWidget()
{
mtxTreeWidget.lock();
treeWidget->setColumnCount(7);
reSetHeadTreeWidget();
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_ID, 50);
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_Instructor, 250);
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_Login, 100);
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_Password, 100);
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_Administrator, 100);
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_Archived, 100);
treeWidget->setColumnWidth(ColumnsTreeInsructors::clmn_Logged, 100);
if(typeView == TypeView::onlyView)
{//onlyView
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_ID, true);
//treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Login, true);
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Password, true);
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Archived, true);
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Administrator, true);
if(adminMode)
archiveVisible = false;
else
archiveVisible = false;
notLoggedInVisible = true;
}
else
{//control
archiveVisible = true;
notLoggedInVisible = true;
if(adminMode)
{
}
else
{
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_ID, true);
treeWidget->setColumnHidden(ColumnsTreeInsructors::clmn_Archived, true);
}
}
treeWidget->setSortingEnabled(true);
treeWidget->sortItems(ColumnsTreeInsructors::clmn_Instructor, Qt::SortOrder::AscendingOrder);
mtxTreeWidget.unlock();
}
void InstructorsView::loadInstructorsFromDB()
{
mtxTreeWidget.lock();
//Обновление дерева
treeWidget->clear();
//Инструкторы
QList<Instructor> listInstructors;
listInstructors = connectorToServer->getListInstructors();
for(Instructor instructor : listInstructors)
{
QTreeWidgetItem *ItemInstructor = new QTreeWidgetItem(treeWidget);
ItemInstructor->setText(ColumnsTreeInsructors::clmn_ID, QString::number(instructor.getID()));
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Instructor, instructor.getName());
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Login, instructor.getLogin());
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Password, instructor.getPassword());
//Сокрытие пароля
if(!adminMode)
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Password, QStringLiteral("******"));
if(instructor.getArchived())
{//Архивный
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Archived, tr("yes"));
ItemInstructor->setIcon(ColumnsTreeInsructors::clmn_Instructor, QIcon(QStringLiteral(":/resources/icons/archive.png")));
setItemColorArchive(ItemInstructor);
}
else
{//Не Архивный
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Archived, tr("no"));
ItemInstructor->setIcon(ColumnsTreeInsructors::clmn_Instructor, QIcon(QStringLiteral(":/resources/icons/instructor.png")));
setItemColorNoArchive(ItemInstructor);
}
if(instructor.getIsAdmin())
{//Админ
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Administrator, tr("yes"));
ItemInstructor->setIcon(ColumnsTreeInsructors::clmn_Instructor, QIcon(QStringLiteral(":/resources/icons/admin.png")));
}
else
{//Не Админ
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Administrator, tr("no"));
}
if(instructor.getLoggedIn())
{//Залогинен
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Logged, tr("yes"));
ItemInstructor->setIcon(ColumnsTreeInsructors::clmn_Logged, QIcon(QStringLiteral(":/resources/icons/circleGreen.png")));
}
else
{//Не Залогинен
ItemInstructor->setText(ColumnsTreeInsructors::clmn_Logged, tr("no"));
ItemInstructor->setIcon(ColumnsTreeInsructors::clmn_Logged, QIcon(QStringLiteral(":/resources/icons/circleGray.png")));
}
//Скрываем архивных (при необходимости)
if(instructor.getArchived())
if(! archiveVisible)
ItemInstructor->setHidden(true);
//Скрываем незалогиненых (при необходимости)
if(! instructor.getLoggedIn())
if(! notLoggedInVisible)
ItemInstructor->setHidden(true);
}
treeWidget->expandAll();
/*
//if(typeView == TypeView::control)
{
QTreeWidgetItem * item = treeWidget->topLevelItem(0);
if(item != nullptr)
treeWidget->setCurrentItem(item);
}*/
setCurrentInstructor(lastCurrentID);
mtxTreeWidget.unlock();
}
void InstructorsView::reSetHeadTreeWidget()
{
QStringList listHeaders = {tr("Instructor"), tr("Login"), tr("Password"), tr("Administrator"), tr("Archived"), tr("Logged"), tr("ID")};
treeWidget->setHeaderLabels(listHeaders);
}
void InstructorsView::setCurrentInstructor(int id)
{
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
{
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
if(item != nullptr)
if(item->text(ColumnsTreeInsructors::clmn_ID).toInt() == id)
{
treeWidget->setCurrentItem(item);
return;
}
}
QTreeWidgetItem * item = treeWidget->topLevelItem(0);
if(item != nullptr)
treeWidget->setCurrentItem(item);
}

View File

@@ -0,0 +1,41 @@
#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);
protected:
enum ColumnsTreeInsructors{
clmn_Instructor = 0,
clmn_Login,
clmn_Password,
clmn_Administrator,
clmn_Archived,
clmn_Logged,
clmn_ID
};
public Q_SLOTS:
//Слот обработки сигнала необходимости обновления интерфейса
void slot_NeedUpdateUI(bool treeInstructor, bool treeTrainee);
protected:
virtual void updateButtons(){};
void preparationTreeWidget();
void loadInstructorsFromDB();
void reSetHeadTreeWidget();
void setCurrentInstructor(int id);
};
#endif // INSTRUCTORSVIEW_H

View File

@@ -0,0 +1,68 @@
#include <QMessageBox>
#include "editorinstructors.h"
#include "viewerinstructors.h"
#include "ui_viewerinstructors.h"
ViewerInstructors::ViewerInstructors(ConnectorToServer* connectorToServer, QWidget *parent) :
InstructorsView(connectorToServer, CommonView::TypeView::onlyView, parent),
ui(new Ui::ViewerInstructors)
{
ui->setupUi(this);
ui->horizontalLayout_1->addWidget(treeWidget);
treeWidget->setSelectionMode(QAbstractItemView::NoSelection);
preparationTreeWidget();
setNotLoggedInVisible(true);
}
ViewerInstructors::~ViewerInstructors()
{
delete ui;
}
void ViewerInstructors::changeEvent(QEvent *event)
{
// В случае получения события изменения языка приложения
if (event->type() == QEvent::LanguageChange)
{// переведём окно заново
ui->retranslateUi(this);
reSetHeadTreeWidget();
//loadInstructorsFromDB();
slot_NeedUpdateUI(true, false);
}
}
void ViewerInstructors::on_btnEditorInstructors_clicked()
{
Q_EMIT signal_BlockAutorization(true);
EditorInstructors editorInstructors(connectorToServer, adminMode);
connect(connectorToServer, &ConnectorToServer::signal_UpdateDB, &editorInstructors, &EditorInstructors::slot_NeedUpdateUI);
QDialog* dialog = new QDialog(this);
QHBoxLayout *layout = new QHBoxLayout(dialog);
layout->addWidget(&editorInstructors);
dialog->setWindowTitle(tr("Editor of instructors"));
dialog->setMinimumSize(1600, 800);
dialog->setStyleSheet(this->styleSheet());
dialog->exec();
loadInstructorsFromDB();
Q_EMIT signal_BlockAutorization(false);
}
void ViewerInstructors::updateButtons()
{
if(adminMode && authComplited)
{
ui->btnEditorInstructors->setEnabled(true);
}
else
{
ui->btnEditorInstructors->setEnabled(false);
}
}

View File

@@ -0,0 +1,37 @@
#ifndef INSTRUCTORSWIDGET_H
#define INSTRUCTORSWIDGET_H
#include "instructorsview.h"
namespace Ui {
class ViewerInstructors;
}
//Виджет только для просмотра БД Инструкторов
class ViewerInstructors : public InstructorsView
{
Q_OBJECT
public:
explicit ViewerInstructors(ConnectorToServer* connectorToServer, QWidget *parent = nullptr);
~ViewerInstructors();
protected:
void changeEvent(QEvent * event) override;
Q_SIGNALS:
//сигнал о блокировке авторизации
void signal_BlockAutorization(bool block);
private Q_SLOTS:
void on_btnEditorInstructors_clicked();
private:
void updateButtons() override;
private:
Ui::ViewerInstructors *ui;
};
#endif // INSTRUCTORSWIDGET_H

View File

@@ -0,0 +1,100 @@
<?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>
<widget class="QGroupBox" name="groupBox">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="title">
<string>Instructors</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_1"/>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<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="../resources.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>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources>
<include location="../resources.qrc"/>
</resources>
<connections/>
</ui>