mirror of
https://gitea.msk.dinamika-avia.ru/Constanta-Design/RRJServer.git
synced 2026-03-28 19:55:48 +03:00
PSQL 30.10.2024
This commit is contained in:
45
DBXML/InstructorsAndTrainees/trainees/computersLocations.cpp
Normal file
45
DBXML/InstructorsAndTrainees/trainees/computersLocations.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include "computersLocations.h"
|
||||
|
||||
ComputersLocations::ComputersLocations():
|
||||
locations(),
|
||||
computers(),
|
||||
listComputerInLocation()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ComputersLocations::addComputer(QString computer, QString location)
|
||||
{
|
||||
if(!computers.contains(computer))
|
||||
{
|
||||
computers.append(computer);
|
||||
if(!locations.contains(location))
|
||||
locations.append(location);
|
||||
|
||||
computerInLocation comp = {computer, location};
|
||||
listComputerInLocation.append(comp);
|
||||
}
|
||||
}
|
||||
|
||||
QString ComputersLocations::getLocationOfComputer(QString computer)
|
||||
{
|
||||
for(computerInLocation compInLoc : listComputerInLocation)
|
||||
{
|
||||
if(computer == compInLoc.computer)
|
||||
return compInLoc.location;
|
||||
}
|
||||
return QString(QStringLiteral(""));
|
||||
}
|
||||
|
||||
QStringList ComputersLocations::getAllComputersOfLocation(QString location)
|
||||
{
|
||||
QStringList list;
|
||||
|
||||
for(computerInLocation compInLoc : listComputerInLocation)
|
||||
{
|
||||
if(location == compInLoc.location)
|
||||
list.append(compInLoc.computer);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
46
DBXML/InstructorsAndTrainees/trainees/computersLocations.h
Normal file
46
DBXML/InstructorsAndTrainees/trainees/computersLocations.h
Normal file
@@ -0,0 +1,46 @@
|
||||
#ifndef COMPUTERSLOCATIONS_H
|
||||
#define COMPUTERSLOCATIONS_H
|
||||
|
||||
#include <QStringList>
|
||||
#include "instructorsAndTrainees_global.h"
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT ComputersLocations
|
||||
{
|
||||
public:
|
||||
ComputersLocations();
|
||||
|
||||
struct computerInLocation
|
||||
{
|
||||
QString computer;
|
||||
QString location;
|
||||
};
|
||||
|
||||
void clear()
|
||||
{
|
||||
listComputerInLocation.clear();
|
||||
locations.clear();
|
||||
computers.clear();
|
||||
}
|
||||
|
||||
void addComputer(QString computer, QString location);
|
||||
|
||||
QStringList getAllLocations()
|
||||
{
|
||||
return locations;
|
||||
}
|
||||
|
||||
QStringList getAllComputers()
|
||||
{
|
||||
return computers;
|
||||
}
|
||||
|
||||
QString getLocationOfComputer(QString computer);
|
||||
QStringList getAllComputersOfLocation(QString location);
|
||||
|
||||
private:
|
||||
QStringList locations;
|
||||
QStringList computers;
|
||||
QList <computerInLocation> listComputerInLocation;
|
||||
};
|
||||
|
||||
#endif // COMPUTERSLOCATIONS_H
|
||||
587
DBXML/InstructorsAndTrainees/trainees/databasetrainees.cpp
Normal file
587
DBXML/InstructorsAndTrainees/trainees/databasetrainees.cpp
Normal file
@@ -0,0 +1,587 @@
|
||||
#include "databasetrainees.h"
|
||||
#include <QDomDocument>
|
||||
#include <QFile>
|
||||
#include <QDebug>
|
||||
|
||||
DataBaseTrainees::DataBaseTrainees(QString appPath, DataBaseLMS* dbLMS)
|
||||
{
|
||||
listOfColorGroup.append(QColor(170, 190, 170));
|
||||
listOfColorGroup.append(QColor(180, 180, 220));
|
||||
listOfColorGroup.append(QColor(240, 220, 230));
|
||||
listOfColorGroup.append(QColor(85, 170, 127));
|
||||
listOfColorGroup.append(QColor(170, 115, 120));
|
||||
listOfColorGroup.append(QColor(110, 160, 170));
|
||||
listOfColorGroup.append(QColor(110, 170, 130));
|
||||
listOfColorGroup.append(QColor(170, 170, 120));
|
||||
listOfColorGroup.append(QColor(160, 170, 45));
|
||||
listOfColorGroup.append(QColor(170, 140, 60));
|
||||
listOfColorGroup.append(QColor(200, 200, 200));
|
||||
|
||||
appDirPath = appPath;
|
||||
|
||||
this->dbLMS = dbLMS;
|
||||
|
||||
if(this->dbLMS != nullptr)
|
||||
LoadTraineesGroupsPSQL();
|
||||
else
|
||||
LoadTraineesGroupsXML();
|
||||
}
|
||||
|
||||
DataBaseTrainees::~DataBaseTrainees()
|
||||
{
|
||||
if(dbLMS == nullptr)
|
||||
SaveTraineesGroupsXML();
|
||||
}
|
||||
|
||||
void DataBaseTrainees::LoadTraineesGroupsXML()
|
||||
{
|
||||
QDomDocument groupsTraineesDOM;
|
||||
QString xmlFileName = appDirPath + QStringLiteral("/DBXML/groupsTrainees.xml");
|
||||
QFile xmlInFile(xmlFileName);
|
||||
if (!xmlInFile.open(QFile::ReadOnly | QFile::Text))
|
||||
{
|
||||
qDebug() << QStringLiteral("LoadTraineesGroupsXML: Не удалось открыть файл ") + xmlFileName;
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
listOfTrainees.clear();
|
||||
listOfGroups.clear();
|
||||
|
||||
groupsTraineesDOM.setContent(xmlInFile.readAll());
|
||||
xmlInFile.close();
|
||||
|
||||
QDomNode groupsTraineesNode = groupsTraineesDOM.namedItem(QStringLiteral("groupsTrainees"));
|
||||
|
||||
for(int i = 0; i < groupsTraineesNode.childNodes().count(); i++)
|
||||
{
|
||||
QDomNode groupNode = groupsTraineesNode.childNodes().at(i);
|
||||
if(groupNode.nodeName().toLower() == QStringLiteral("group"))
|
||||
{//Группа
|
||||
|
||||
Group group;
|
||||
group.setName(groupNode.toElement().attribute(QStringLiteral("name")));
|
||||
group.setColor((Group::ColorGroup)(groupNode.toElement().attribute(QStringLiteral("color")).toInt()));
|
||||
listOfGroups.append(group);
|
||||
|
||||
for(int j = 0; j < groupNode.childNodes().count(); j++)
|
||||
{
|
||||
QDomNode traineeNode = groupNode.childNodes().at(j);
|
||||
if(traineeNode.nodeName().toLower() == QStringLiteral("trainee"))
|
||||
{//Обучаемый
|
||||
|
||||
Trainee trainee;
|
||||
|
||||
trainee.setGroup(group.getName());
|
||||
|
||||
trainee.setName(traineeNode.toElement().attribute(QStringLiteral("name")));
|
||||
trainee.setLogin(traineeNode.toElement().attribute(QStringLiteral("login")));
|
||||
trainee.setPassword(traineeNode.toElement().attribute(QStringLiteral("password")));
|
||||
trainee.setArchived(traineeNode.toElement().attribute(QStringLiteral("archived")) == QStringLiteral("да") ? true : false);
|
||||
trainee.setWhatItDoes(traineeNode.toElement().attribute(QStringLiteral("whatItDoes")));
|
||||
|
||||
trainee.setLoggedIn(false);
|
||||
trainee.setLearnClass(QStringLiteral(""));
|
||||
trainee.setComputer(QStringLiteral(""));
|
||||
|
||||
listOfTrainees.append(trainee);
|
||||
}
|
||||
}
|
||||
}
|
||||
}//for(int i = 0; i < groupsTraineesNode.childNodes().count(); i++)
|
||||
}//else
|
||||
}
|
||||
|
||||
void DataBaseTrainees::SaveTraineesGroupsXML()
|
||||
{
|
||||
QDomDocument groupsTraineesDOM;
|
||||
QFile blankFile(QStringLiteral(":/blankXML/groupsTrainees.xml"));
|
||||
|
||||
if (! blankFile.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qDebug() << "SaveTraineesGroupsXML: Не удалось считать файл :/blankXML/groupsTrainees.xml";
|
||||
return;
|
||||
}
|
||||
|
||||
groupsTraineesDOM.setContent(blankFile.readAll());
|
||||
blankFile.close();
|
||||
|
||||
QDomNode groupsTraineesNode = groupsTraineesDOM.namedItem(QStringLiteral("groupsTrainees"));
|
||||
|
||||
for(Group group : listOfGroups)
|
||||
{
|
||||
//Группа
|
||||
QDomNode groupNode = groupsTraineesDOM.createElement(QStringLiteral("group"));
|
||||
groupsTraineesNode.appendChild(groupNode);
|
||||
groupNode.toElement().setAttribute(QStringLiteral("name"), group.getName());
|
||||
groupNode.toElement().setAttribute(QStringLiteral("color"), QString::number((int)group.getColor()));
|
||||
|
||||
//Обучаемые
|
||||
QList<Trainee> listTrainees;
|
||||
listTrainees = getListTraineesInGroup(group.getName());
|
||||
for(Trainee trainee : listTrainees)
|
||||
{
|
||||
QDomNode traineeNode = groupsTraineesDOM.createElement(QStringLiteral("trainee"));
|
||||
groupNode.appendChild(traineeNode);
|
||||
traineeNode.toElement().setAttribute(QStringLiteral("name"), trainee.getName());
|
||||
traineeNode.toElement().setAttribute(QStringLiteral("login"), trainee.getLogin());
|
||||
traineeNode.toElement().setAttribute(QStringLiteral("password"), trainee.getPassword());
|
||||
traineeNode.toElement().setAttribute(QStringLiteral("archived"), trainee.getArchived() ? QStringLiteral("да") : QStringLiteral("нет"));
|
||||
traineeNode.toElement().setAttribute(QStringLiteral("whatItDoes"), trainee.getWhatItDoes());
|
||||
}
|
||||
}
|
||||
|
||||
QString xmlFileName = appDirPath + QStringLiteral("/DBXML/groupsTrainees.xml");
|
||||
QFile xmlOutFile(xmlFileName);
|
||||
if (!xmlOutFile.open(QFile::WriteOnly | QFile::Text))
|
||||
{
|
||||
qDebug() << QStringLiteral("SaveTraineesGroupsXML: Не удалось записать файл ") + xmlFileName;
|
||||
return;
|
||||
}
|
||||
QTextStream outFile(&xmlOutFile);
|
||||
groupsTraineesDOM.save(outFile, 4);
|
||||
xmlOutFile.close();
|
||||
}
|
||||
|
||||
void DataBaseTrainees::LoadTraineesGroupsPSQL()
|
||||
{
|
||||
listOfTrainees.clear();
|
||||
listOfGroups.clear();
|
||||
|
||||
listOfTrainees = dbLMS->selectAllTrainees();
|
||||
listOfGroups = dbLMS->selectAllGroups();
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::AuthorizationTrainee(QString login, QString password, QString learnClass, QString computer)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getArchived())
|
||||
continue;
|
||||
|
||||
if(listOfTrainees[i].getLogin() == login && listOfTrainees[i].getPassword() == password)
|
||||
{
|
||||
listOfTrainees[i].setLoggedIn(true);
|
||||
listOfTrainees[i].setLearnClass(learnClass);
|
||||
listOfTrainees[i].setComputer(computer);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::deAuthorizationTrainee(QString login)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
//if(listOfTrainees[i].getArchived())
|
||||
//continue;
|
||||
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
{
|
||||
listOfTrainees[i].setLoggedIn(false);
|
||||
listOfTrainees[i].setLearnClass(QStringLiteral(""));
|
||||
listOfTrainees[i].setComputer(QStringLiteral(""));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void DataBaseTrainees::setWhatItDoes(QString login, QString whatItDoes)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
listOfTrainees[i].setWhatItDoes(whatItDoes);
|
||||
}
|
||||
}
|
||||
|
||||
QStringList DataBaseTrainees::getWhatItDoes(QString login)
|
||||
{
|
||||
QString whatItDoes = QStringLiteral("");
|
||||
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
whatItDoes = listOfTrainees[i].getWhatItDoes();
|
||||
}
|
||||
|
||||
return whatItDoes.split(QStringLiteral(";"));
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::getNameTraineeOnComputer(QString computer)
|
||||
{
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getComputer() == computer)
|
||||
return trainee.getName();
|
||||
}
|
||||
return QString(QStringLiteral(""));
|
||||
}
|
||||
|
||||
Trainee DataBaseTrainees::getTraineeOnComputer(QString computer)
|
||||
{
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getComputer() == computer)
|
||||
return trainee;
|
||||
}
|
||||
return Trainee();
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::getNameTraineeByLogin(QString login)
|
||||
{
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getLogin() == login)
|
||||
return trainee.getName();
|
||||
}
|
||||
return QString(QStringLiteral(""));
|
||||
}
|
||||
|
||||
QColor DataBaseTrainees::getColorGroupByLogin(QString login)
|
||||
{
|
||||
QString nameTrainee = getNameTraineeByLogin(login);
|
||||
Trainee trainee = getTrainee(nameTrainee);
|
||||
QString nameGroup = trainee.getGroup();
|
||||
Group group = getGroup(nameGroup);
|
||||
return getColorGroup(group.getColor());
|
||||
}
|
||||
|
||||
QList<Trainee> DataBaseTrainees::getListTraineesInGroup(QString nameGroup)
|
||||
{
|
||||
QList<Trainee> listTrainees;
|
||||
|
||||
for(Trainee trainee : listOfTrainees)
|
||||
{
|
||||
if(trainee.getGroup() == nameGroup)
|
||||
listTrainees.append(trainee);
|
||||
}
|
||||
|
||||
return listTrainees;
|
||||
}
|
||||
|
||||
QList<Group> DataBaseTrainees::getListGroups()
|
||||
{
|
||||
return listOfGroups;
|
||||
}
|
||||
|
||||
QColor DataBaseTrainees::getColorGroup(Group::ColorGroup numColor)
|
||||
{
|
||||
if(numColor > listOfColorGroup.count() - 1)
|
||||
return listOfColorGroup.at(Group::ColorGroup::colorAther);
|
||||
|
||||
return listOfColorGroup.at(numColor);
|
||||
}
|
||||
|
||||
Trainee DataBaseTrainees::getTrainee(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
return listOfTrainees[i];
|
||||
}
|
||||
return Trainee();
|
||||
}
|
||||
|
||||
Group DataBaseTrainees::getGroup(QString nameGroup)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == nameGroup)
|
||||
return listOfGroups[i];
|
||||
}
|
||||
return Group();
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::newGroup()
|
||||
{
|
||||
Group group;
|
||||
group.setName(generateDefaultNameGroup());
|
||||
group.setColor(generateDefaultColorGroup());
|
||||
|
||||
bool result = dbLMS->insertGroup(group);
|
||||
|
||||
if(result)
|
||||
{
|
||||
listOfGroups.append(group);
|
||||
return group.getName();
|
||||
}
|
||||
else
|
||||
return QStringLiteral("");
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::deleteGroup(QString name)
|
||||
{
|
||||
if(getListTraineesInGroup(name).count() > 0)
|
||||
{//Группа не пуста
|
||||
return false;
|
||||
}
|
||||
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == name)
|
||||
{
|
||||
int id = listOfGroups[i].getID();
|
||||
|
||||
bool result = dbLMS->deleteGroup(id);
|
||||
|
||||
if(result)
|
||||
listOfGroups.removeAt(i);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::editGroup(QString name, QString newName)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == name)
|
||||
{
|
||||
if(!checkExistNameGroup(newName) || newName == name)
|
||||
{
|
||||
Group group = listOfGroups[i];
|
||||
group.setName(newName);
|
||||
|
||||
bool result = dbLMS->updateGroup(group);
|
||||
|
||||
if(result)
|
||||
{
|
||||
listOfGroups[i].setName(newName);
|
||||
|
||||
//Меняем имя группы у всех Обучаемых этой группы
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getGroup() == name)
|
||||
listOfTrainees[i].setGroup(newName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::newTrainee(QString nameGroup)
|
||||
{
|
||||
Trainee trainee;
|
||||
trainee.setGroup(nameGroup);
|
||||
trainee.setName(generateDefaultNameTrainee());
|
||||
trainee.setLogin(generateDefaultLoginTrainee());
|
||||
trainee.setPassword(QStringLiteral("<password>"));
|
||||
trainee.setLearnClass(QStringLiteral(""));
|
||||
trainee.setComputer(QStringLiteral(""));
|
||||
trainee.setArchived(false);
|
||||
trainee.setLoggedIn(false);
|
||||
trainee.setWhatItDoes(QStringLiteral(""));
|
||||
|
||||
bool result = dbLMS->insertTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
{
|
||||
listOfTrainees.append(trainee);
|
||||
return trainee.getName();
|
||||
}
|
||||
else
|
||||
return QStringLiteral("");
|
||||
}
|
||||
|
||||
void DataBaseTrainees::deleteTrainee(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
{
|
||||
int id = listOfTrainees[i].getID();
|
||||
|
||||
bool result = dbLMS->deleteTrainee(id);
|
||||
|
||||
if(result)
|
||||
listOfTrainees.removeAt(i);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataBaseTrainees::toArchiveTrainee(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
if(! listOfTrainees[i].getArchived())
|
||||
{
|
||||
Trainee trainee = listOfTrainees[i];
|
||||
trainee.setArchived(true);
|
||||
|
||||
bool result = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
listOfTrainees[i].setArchived(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DataBaseTrainees::fromeArchiveTrainee(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
if(listOfTrainees[i].getArchived())
|
||||
{
|
||||
Trainee trainee = listOfTrainees[i];
|
||||
trainee.setArchived(false);
|
||||
|
||||
bool result = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
listOfTrainees[i].setArchived(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::editTrainee(QString name, Trainee trainee)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
{
|
||||
if( (!checkExistNameTrainee(trainee.getName()) || trainee.getName() == name) &&
|
||||
(!checkExistLoginTrainee(trainee.getLogin()) || trainee.getLogin() == listOfTrainees[i].getLogin()) )
|
||||
{
|
||||
trainee.setID(listOfTrainees[i].getID());
|
||||
|
||||
bool result = dbLMS->updateTrainee(trainee);
|
||||
|
||||
if(result)
|
||||
{
|
||||
listOfTrainees.replace(i, trainee);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::isArchived(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
return listOfTrainees[i].getArchived();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::generateDefaultNameGroup()
|
||||
{
|
||||
int numGroup = 0;
|
||||
QString name;
|
||||
do
|
||||
{
|
||||
name = tr("Group") + QStringLiteral(" ") + QString::number(++numGroup);
|
||||
}while(checkExistNameGroup(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::generateDefaultNameTrainee()
|
||||
{
|
||||
int numTrainee = 0;
|
||||
QString name;
|
||||
do
|
||||
{
|
||||
name = QStringLiteral("<") + tr("Trainee") + QStringLiteral(" ") + QString::number(++numTrainee) + QStringLiteral(">");
|
||||
}while(checkExistNameTrainee(name));
|
||||
return name;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistNameGroup(QString name)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getName() == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistNameTrainee(QString name)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getName() == name)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QString DataBaseTrainees::generateDefaultLoginTrainee()
|
||||
{
|
||||
int numTrainee = 0;
|
||||
QString login;
|
||||
do
|
||||
{
|
||||
login = QStringLiteral("<O") + QString::number(++numTrainee) + QStringLiteral(">");
|
||||
}while(checkExistLoginTrainee(login));
|
||||
return login;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistLoginTrainee(QString login)
|
||||
{
|
||||
//Обучаемые
|
||||
for(int i = 0; i < listOfTrainees.count(); i++)
|
||||
{
|
||||
if(listOfTrainees[i].getLogin() == login)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Group::ColorGroup DataBaseTrainees::generateDefaultColorGroup()
|
||||
{
|
||||
for(int i = 0; i < Group::ColorGroup::countColor; i++)
|
||||
{
|
||||
Group::ColorGroup color = (Group::ColorGroup)i;
|
||||
if(!checkExistColorGroup(color))
|
||||
return color;
|
||||
}
|
||||
return Group::ColorGroup::colorAther;
|
||||
}
|
||||
|
||||
bool DataBaseTrainees::checkExistColorGroup(Group::ColorGroup color)
|
||||
{
|
||||
//Группы
|
||||
for(int i = 0; i < listOfGroups.count(); i++)
|
||||
{
|
||||
if(listOfGroups[i].getColor() == color)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
82
DBXML/InstructorsAndTrainees/trainees/databasetrainees.h
Normal file
82
DBXML/InstructorsAndTrainees/trainees/databasetrainees.h
Normal file
@@ -0,0 +1,82 @@
|
||||
#ifndef DATABASETRAINEES_H
|
||||
#define DATABASETRAINEES_H
|
||||
|
||||
#include "instructorsAndTrainees_global.h"
|
||||
#include "trainee.h"
|
||||
#include "group.h"
|
||||
|
||||
#include "databaselms.h"
|
||||
|
||||
#include <QList>
|
||||
#include <QColor>
|
||||
#include <QObject>
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT DataBaseTrainees : QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
DataBaseTrainees(QString appPath, DataBaseLMS* dbLMS = nullptr);
|
||||
~DataBaseTrainees();
|
||||
|
||||
void LoadTraineesGroupsXML();
|
||||
void SaveTraineesGroupsXML();
|
||||
|
||||
void LoadTraineesGroupsPSQL();
|
||||
|
||||
bool AuthorizationTrainee(QString login, QString password, QString learnClass, QString computer);
|
||||
bool deAuthorizationTrainee(QString login);
|
||||
|
||||
void setWhatItDoes(QString login, QString whatItDoes);
|
||||
QStringList getWhatItDoes(QString login);
|
||||
|
||||
QString getNameTraineeOnComputer(QString computer);
|
||||
Trainee getTraineeOnComputer(QString computer);
|
||||
|
||||
QString getNameTraineeByLogin(QString login);
|
||||
QColor getColorGroupByLogin(QString login);
|
||||
|
||||
QList<Trainee> getListTraineesInGroup(QString nameGroup);
|
||||
QList<Group> getListGroups();
|
||||
|
||||
QColor getColorGroup(Group::ColorGroup numColor);
|
||||
|
||||
Trainee getTrainee(QString name);
|
||||
Group getGroup(QString nameGroup);
|
||||
|
||||
QString newGroup();
|
||||
bool deleteGroup(QString name);
|
||||
bool editGroup(QString name, QString newName);
|
||||
|
||||
QString newTrainee(QString nameGroup);
|
||||
void deleteTrainee(QString name);
|
||||
void toArchiveTrainee(QString name);
|
||||
void fromeArchiveTrainee(QString name);
|
||||
bool editTrainee(QString name, Trainee trainee);
|
||||
|
||||
bool isArchived(QString name);
|
||||
|
||||
private:
|
||||
QString generateDefaultNameGroup();
|
||||
QString generateDefaultNameTrainee();
|
||||
bool checkExistNameGroup(QString name);
|
||||
bool checkExistNameTrainee(QString name);
|
||||
|
||||
QString generateDefaultLoginTrainee();
|
||||
bool checkExistLoginTrainee(QString login);
|
||||
|
||||
Group::ColorGroup generateDefaultColorGroup();
|
||||
bool checkExistColorGroup(Group::ColorGroup color);
|
||||
|
||||
private:
|
||||
QList<Trainee> listOfTrainees;
|
||||
QList<Group> listOfGroups;
|
||||
|
||||
QList<QColor> listOfColorGroup;
|
||||
|
||||
QString appDirPath;
|
||||
|
||||
DataBaseLMS* dbLMS;
|
||||
};
|
||||
|
||||
#endif // DATABASETRAINEES_H
|
||||
14
DBXML/InstructorsAndTrainees/trainees/dialogeditgroup.cpp
Normal file
14
DBXML/InstructorsAndTrainees/trainees/dialogeditgroup.cpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#include "dialogeditgroup.h"
|
||||
#include "computersLocations.h"
|
||||
|
||||
DialogEditGroup::DialogEditGroup(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogEditGroup)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
DialogEditGroup::~DialogEditGroup()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
34
DBXML/InstructorsAndTrainees/trainees/dialogeditgroup.h
Normal file
34
DBXML/InstructorsAndTrainees/trainees/dialogeditgroup.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef DIALOGEDITGROUP_H
|
||||
#define DIALOGEDITGROUP_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "ui_dialogeditgroup.h"
|
||||
#include "computersLocations.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogEditGroup;
|
||||
}
|
||||
|
||||
class DialogEditGroup : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogEditGroup(QWidget *parent = nullptr);
|
||||
~DialogEditGroup();
|
||||
|
||||
void setName(QString name)
|
||||
{
|
||||
ui->editName->setText(name);
|
||||
}
|
||||
|
||||
QString getName()
|
||||
{
|
||||
return ui->editName->text();
|
||||
}
|
||||
|
||||
private:
|
||||
Ui::DialogEditGroup *ui;
|
||||
};
|
||||
|
||||
#endif // DIALOGEDITGROUP_H
|
||||
96
DBXML/InstructorsAndTrainees/trainees/dialogeditgroup.ui
Normal file
96
DBXML/InstructorsAndTrainees/trainees/dialogeditgroup.ui
Normal file
@@ -0,0 +1,96 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogEditGroup</class>
|
||||
<widget class="QDialog" name="DialogEditGroup">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>96</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Group</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/group.png</normaloff>:/icons/group.png</iconset>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editName"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<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>DialogEditGroup</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>DialogEditGroup</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>
|
||||
46
DBXML/InstructorsAndTrainees/trainees/dialogedittrainee.cpp
Normal file
46
DBXML/InstructorsAndTrainees/trainees/dialogedittrainee.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "dialogedittrainee.h"
|
||||
#include "ui_dialogedittrainee.h"
|
||||
#include "computersLocations.h"
|
||||
|
||||
DialogEditTrainee::DialogEditTrainee(ComputersLocations* computersLocations, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogEditTrainee),
|
||||
computersLocations(computersLocations),
|
||||
nameGroup()
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
DialogEditTrainee::~DialogEditTrainee()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogEditTrainee::setTrainee(Trainee trainee)
|
||||
{
|
||||
ui->editName->setText(trainee.getName());
|
||||
ui->editLogin->setText(trainee.getLogin());
|
||||
ui->editPassword->setText(trainee.getPassword());
|
||||
|
||||
ui->checkArchived->setChecked(trainee.getArchived());
|
||||
ui->checkLoggedIn->setChecked(trainee.getLoggedIn());
|
||||
|
||||
nameGroup = trainee.getGroup();
|
||||
}
|
||||
|
||||
Trainee DialogEditTrainee::getTrainee()
|
||||
{
|
||||
Trainee trainee;
|
||||
trainee.setName(ui->editName->text());
|
||||
trainee.setLogin(ui->editLogin->text());
|
||||
trainee.setPassword(ui->editPassword->text());
|
||||
trainee.setLearnClass(QStringLiteral(""));
|
||||
trainee.setComputer(QStringLiteral(""));
|
||||
trainee.setArchived(ui->checkArchived->isChecked());
|
||||
trainee.setLoggedIn(ui->checkLoggedIn->isChecked());
|
||||
trainee.setWhatItDoes(QStringLiteral(""));
|
||||
|
||||
trainee.setGroup(nameGroup);
|
||||
|
||||
return trainee;
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#include "dialogedittrainee.h"
|
||||
#include "ui_dialogedittrainee.h"
|
||||
#include "computersLocations.h"
|
||||
|
||||
DialogEditTrainee::DialogEditTrainee(ComputersLocations* computersLocations, QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::DialogEditTrainee),
|
||||
computersLocations(computersLocations),
|
||||
nameGroup()
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->comboLocation->clear();
|
||||
ui->comboLocation->addItems(computersLocations->getAllLocations());
|
||||
ui->comboLocation->setCurrentIndex(0);
|
||||
//setLocation(getLocation());
|
||||
ui->comboComputer->clear();
|
||||
ui->comboComputer->addItems(computersLocations->getAllComputersOfLocation(ui->comboLocation->currentText()));
|
||||
}
|
||||
|
||||
DialogEditTrainee::~DialogEditTrainee()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void DialogEditTrainee::setTrainee(Trainee trainee)
|
||||
{
|
||||
ui->editName->setText(trainee.getName());
|
||||
ui->editLogin->setText(trainee.getLogin());
|
||||
ui->editPassword->setText(trainee.getPassword());
|
||||
|
||||
ui->comboLocation->setCurrentText(trainee.getLearnClass());
|
||||
ui->comboComputer->clear();
|
||||
ui->comboComputer->addItems(computersLocations->getAllComputersOfLocation(ui->comboLocation->currentText()));
|
||||
|
||||
ui->comboComputer->setCurrentText(trainee.getComputer());
|
||||
ui->checkArchived->setChecked(trainee.getArchived());
|
||||
ui->checkLoggedIn->setChecked(trainee.getLoggedIn());
|
||||
ui->editWhatItDoes->setText(trainee.getWhatItDoes());
|
||||
|
||||
nameGroup = trainee.getGroup();
|
||||
}
|
||||
|
||||
Trainee DialogEditTrainee::getTrainee()
|
||||
{
|
||||
Trainee trainee;
|
||||
trainee.setName(ui->editName->text());
|
||||
trainee.setLogin(ui->editLogin->text());
|
||||
trainee.setPassword(ui->editPassword->text());
|
||||
trainee.setLearnClass(ui->comboLocation->currentText());
|
||||
trainee.setComputer(ui->comboComputer->currentText());
|
||||
trainee.setArchived(ui->checkArchived->isChecked());
|
||||
trainee.setLoggedIn(ui->checkLoggedIn->isChecked());
|
||||
trainee.setWhatItDoes(ui->editWhatItDoes->text());
|
||||
|
||||
trainee.setGroup(nameGroup);
|
||||
|
||||
return trainee;
|
||||
}
|
||||
|
||||
void DialogEditTrainee::on_comboLocation_currentIndexChanged(const QString &arg1)
|
||||
{
|
||||
ui->comboComputer->clear();
|
||||
ui->comboComputer->addItems(computersLocations->getAllComputersOfLocation(arg1));
|
||||
}
|
||||
30
DBXML/InstructorsAndTrainees/trainees/dialogedittrainee.h
Normal file
30
DBXML/InstructorsAndTrainees/trainees/dialogedittrainee.h
Normal file
@@ -0,0 +1,30 @@
|
||||
#ifndef DIALOGEDITTRAINEE_H
|
||||
#define DIALOGEDITTRAINEE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "trainee.h"
|
||||
#include "computersLocations.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogEditTrainee;
|
||||
}
|
||||
|
||||
class DialogEditTrainee : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogEditTrainee(ComputersLocations* computersLocations, QWidget *parent = nullptr);
|
||||
~DialogEditTrainee();
|
||||
|
||||
void setTrainee(Trainee trainee);
|
||||
Trainee getTrainee();
|
||||
|
||||
private:
|
||||
Ui::DialogEditTrainee *ui;
|
||||
ComputersLocations* computersLocations;
|
||||
|
||||
QString nameGroup;
|
||||
};
|
||||
|
||||
#endif // DIALOGEDITTRAINEE_H
|
||||
@@ -0,0 +1,33 @@
|
||||
#ifndef DIALOGEDITTRAINEE_H
|
||||
#define DIALOGEDITTRAINEE_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "trainee.h"
|
||||
#include "computersLocations.h"
|
||||
|
||||
namespace Ui {
|
||||
class DialogEditTrainee;
|
||||
}
|
||||
|
||||
class DialogEditTrainee : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DialogEditTrainee(ComputersLocations* computersLocations, QWidget *parent = nullptr);
|
||||
~DialogEditTrainee();
|
||||
|
||||
void setTrainee(Trainee trainee);
|
||||
Trainee getTrainee();
|
||||
|
||||
private slots:
|
||||
void on_comboLocation_currentIndexChanged(const QString &arg1);
|
||||
|
||||
private:
|
||||
Ui::DialogEditTrainee *ui;
|
||||
ComputersLocations* computersLocations;
|
||||
|
||||
QString nameGroup;
|
||||
};
|
||||
|
||||
#endif // DIALOGEDITTRAINEE_H
|
||||
165
DBXML/InstructorsAndTrainees/trainees/dialogedittrainee.ui
Normal file
165
DBXML/InstructorsAndTrainees/trainees/dialogedittrainee.ui
Normal file
@@ -0,0 +1,165 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DialogEditTrainee</class>
|
||||
<widget class="QDialog" name="DialogEditTrainee">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>252</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Trainee</string>
|
||||
</property>
|
||||
<property name="windowIcon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/trainee.png</normaloff>:/icons/trainee.png</iconset>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="0">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<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>
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Name</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editName"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Login</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editLogin"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Password</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLineEdit" name="editPassword"/>
|
||||
</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="text">
|
||||
<string>Archived</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/archive.png</normaloff>
|
||||
<disabledoff>:/icons/archive.png</disabledoff>:/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="text">
|
||||
<string>Logged</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/circleGreen.png</normaloff>
|
||||
<disabledoff>:/icons/circleGreen.png</disabledoff>:/icons/circleGreen.png</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>DialogEditTrainee</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>DialogEditTrainee</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>
|
||||
280
DBXML/InstructorsAndTrainees/trainees/editortrainees.cpp
Normal file
280
DBXML/InstructorsAndTrainees/trainees/editortrainees.cpp
Normal file
@@ -0,0 +1,280 @@
|
||||
#include <QMessageBox>
|
||||
#include "editortrainees.h"
|
||||
#include "ui_editortrainees.h"
|
||||
#include "dialogeditgroup.h"
|
||||
#include "dialogedittrainee.h"
|
||||
|
||||
EditorTrainees::EditorTrainees(DataBaseTrainees* db, ComputersLocations* computersLocations, QWidget *parent) :
|
||||
//QDialog(parent),
|
||||
TraineesView(db, CommonView::TypeView::control, parent),
|
||||
ui(new Ui::EditorTrainees),
|
||||
computersLocations(computersLocations)
|
||||
{
|
||||
ui->setupUi((QDialog*)this);
|
||||
|
||||
preparationTreeWidget(ui->treeWidget);
|
||||
setNotLoggedInVisible(true);
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
|
||||
EditorTrainees::~EditorTrainees()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnNewGroup_clicked()
|
||||
{
|
||||
QString nameGroup = dbTrainees->newGroup();
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(nameGroup);
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnDeleteGroup_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа
|
||||
QString name = treeItemCurrent->text(0);
|
||||
if(dbTrainees->deleteGroup(name))
|
||||
{//Удалено
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"), tr("The group is not empty.\nIt is not possible to delete a non-empty group."));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnNewTrainee_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа. Можно добавить Обучаемого
|
||||
QString nameGroup = treeItemCurrent->text(0);
|
||||
dbTrainees->newTrainee(nameGroup);
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(nameGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnDeleteTrainee_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent != nullptr)
|
||||
{//Выбран обучаемый
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
QString nameGroup = treeItemParent->text(0);
|
||||
|
||||
if(QMessageBox::warning(this, tr("Attention!"), tr("The deletion will be irrevocable.\nDelete anyway?"), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok)
|
||||
{
|
||||
dbTrainees->deleteTrainee(name);
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(nameGroup);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnToOrFromArchiveTrainee_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent != nullptr)
|
||||
{
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent != nullptr)
|
||||
{//Выбран обучаемый
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
|
||||
if(dbTrainees->isArchived(name))
|
||||
{//Архивный
|
||||
dbTrainees->fromeArchiveTrainee(name);
|
||||
loadTraineesFromDB();
|
||||
setCurrentTrainee(name);
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
dbTrainees->toArchiveTrainee(name);
|
||||
|
||||
if(!archiveVisible)
|
||||
ui->btnArchive->click();
|
||||
|
||||
loadTraineesFromDB();
|
||||
setCurrentTrainee(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnEdit_clicked()
|
||||
{
|
||||
QTreeWidgetItem *treeItemCurrent = ui->treeWidget->currentItem();
|
||||
|
||||
if(treeItemCurrent == nullptr)
|
||||
return;
|
||||
|
||||
QTreeWidgetItem *treeItemParent = treeItemCurrent->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа
|
||||
|
||||
QString nameGroup = treeItemCurrent->text(0);
|
||||
|
||||
DialogEditGroup dlg(this);
|
||||
dlg.setName(nameGroup);
|
||||
switch( dlg.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
if(dbTrainees->editGroup(nameGroup, dlg.getName()))
|
||||
{
|
||||
loadTraineesFromDB();
|
||||
setCurrentGroup(dlg.getName());
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"),
|
||||
tr("An existing group name has been entered.\nThe changes will not be accepted."));
|
||||
break;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{//Выбран обучаемый
|
||||
|
||||
QString name = treeItemCurrent->text(0);
|
||||
|
||||
DialogEditTrainee dlg(computersLocations, this);
|
||||
dlg.setTrainee(dbTrainees->getTrainee(name));
|
||||
|
||||
switch( dlg.exec() )
|
||||
{
|
||||
case QDialog::Accepted:
|
||||
{
|
||||
if(dbTrainees->editTrainee(name, dlg.getTrainee()))
|
||||
{
|
||||
loadTraineesFromDB();
|
||||
setCurrentTrainee(dlg.getTrainee().getName());
|
||||
}
|
||||
else
|
||||
QMessageBox::critical(this, tr("Editing error!"),
|
||||
tr("An existing trainee's name or login has been entered.\nThe changes will not be accepted."));
|
||||
break;
|
||||
}
|
||||
case QDialog::Rejected:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::on_btnArchive_clicked()
|
||||
{
|
||||
bool state = ui->btnArchive->isChecked();
|
||||
setArchiveVisible(state);
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
|
||||
void EditorTrainees::on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)
|
||||
{
|
||||
//Определяем доступность и функционал кнопок для выбранного элемента
|
||||
|
||||
if(current == nullptr)
|
||||
return;
|
||||
|
||||
QTreeWidgetItem *treeItemParent = current->parent();
|
||||
if(treeItemParent == nullptr)
|
||||
{//Выбрана группа
|
||||
ui->btnNewGroup->setEnabled(true);
|
||||
ui->btnDeleteGroup->setEnabled(true);
|
||||
ui->btnNewTrainee->setEnabled(true);
|
||||
ui->btnDeleteTrainee->setEnabled(false);
|
||||
ui->btnToOrFromArchiveTrainee->setEnabled(false);
|
||||
ui->btnEdit->setEnabled(true);
|
||||
ui->btnArchive->setEnabled(true);
|
||||
|
||||
ui->btnToOrFromArchiveTrainee->setText(tr("To archive"));
|
||||
ui->btnToOrFromArchiveTrainee->setIcon(QIcon(QStringLiteral(":/icons/traineeArchive.png")));
|
||||
}
|
||||
else
|
||||
{//Выбран обучаемый
|
||||
QString name = current->text(0);
|
||||
|
||||
ui->btnNewGroup->setEnabled(false);
|
||||
ui->btnDeleteGroup->setEnabled(false);
|
||||
ui->btnNewTrainee->setEnabled(false);
|
||||
|
||||
if(dbTrainees->isArchived(name))
|
||||
{//Архивный
|
||||
ui->btnDeleteTrainee->setEnabled(true);
|
||||
|
||||
ui->btnToOrFromArchiveTrainee->setText(tr("From archive"));
|
||||
ui->btnToOrFromArchiveTrainee->setIcon(QIcon(QStringLiteral(":/icons/traineeFromArchive.png")));
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
ui->btnDeleteTrainee->setEnabled(false);
|
||||
|
||||
ui->btnToOrFromArchiveTrainee->setText(tr("To archive"));
|
||||
ui->btnToOrFromArchiveTrainee->setIcon(QIcon(QStringLiteral(":/icons/traineeArchive.png")));
|
||||
}
|
||||
|
||||
ui->btnToOrFromArchiveTrainee->setEnabled(true);
|
||||
|
||||
ui->btnEdit->setEnabled(true);
|
||||
ui->btnArchive->setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::setCurrentGroup(QString nameGroup)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
|
||||
if(item != nullptr)
|
||||
if(item->text(0) == nameGroup)
|
||||
{
|
||||
treeWidget->setCurrentItem(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorTrainees::setCurrentTrainee(QString name)
|
||||
{
|
||||
for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(i);
|
||||
if(item != nullptr)
|
||||
{
|
||||
for (int j = 0; j < item->childCount(); j++)
|
||||
{
|
||||
QTreeWidgetItem * itemChild = item->child(j);
|
||||
if(itemChild != nullptr)
|
||||
if(itemChild->text(0) == name)
|
||||
{
|
||||
treeWidget->setCurrentItem(itemChild);
|
||||
break;
|
||||
}
|
||||
}//for (int j = 0; j < item->childCount(); j++)
|
||||
}
|
||||
}//for(int i = 0; i < treeWidget->topLevelItemCount(); i++)
|
||||
}
|
||||
43
DBXML/InstructorsAndTrainees/trainees/editortrainees.h
Normal file
43
DBXML/InstructorsAndTrainees/trainees/editortrainees.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef DIALOGTRAINEESGROUPS_H
|
||||
#define DIALOGTRAINEESGROUPS_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QTreeWidget>
|
||||
#include "computersLocations.h"
|
||||
#include "databasetrainees.h"
|
||||
#include "traineesview.h"
|
||||
|
||||
namespace Ui {
|
||||
class EditorTrainees;
|
||||
}
|
||||
|
||||
//Диалог для просмотра и управления БД Обучаемых
|
||||
|
||||
class EditorTrainees : /*public QDialog,*/ public TraineesView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit EditorTrainees(DataBaseTrainees* db, ComputersLocations* computersLocations, QWidget *parent = nullptr);
|
||||
~EditorTrainees();
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_btnNewGroup_clicked();
|
||||
void on_btnDeleteGroup_clicked();
|
||||
void on_btnNewTrainee_clicked();
|
||||
void on_btnDeleteTrainee_clicked();
|
||||
void on_btnToOrFromArchiveTrainee_clicked();
|
||||
void on_btnEdit_clicked();
|
||||
void on_btnArchive_clicked();
|
||||
void on_treeWidget_currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous);
|
||||
|
||||
private:
|
||||
void setCurrentGroup(QString nameGroup);
|
||||
void setCurrentTrainee(QString name);
|
||||
|
||||
private:
|
||||
Ui::EditorTrainees *ui;
|
||||
ComputersLocations* computersLocations;
|
||||
};
|
||||
|
||||
#endif // DIALOGTRAINEESGROUPS_H
|
||||
390
DBXML/InstructorsAndTrainees/trainees/editortrainees.ui
Normal file
390
DBXML/InstructorsAndTrainees/trainees/editortrainees.ui
Normal file
@@ -0,0 +1,390 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>EditorTrainees</class>
|
||||
<widget class="QDialog" name="EditorTrainees">
|
||||
<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 trainees</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>12</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(240, 240, 240);</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_1">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_1">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QWidget" name="widget_2" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>130</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(180, 180, 180);</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QToolButton" name="btnNewGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="styleSheet">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New group</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/newGroup.png</normaloff>:/icons/newGroup.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="btnDeleteGroup">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete group</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/deleteGroup.png</normaloff>:/icons/deleteGroup.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="btnNewTrainee">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>New trainee</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/addTrainee.png</normaloff>:/icons/addTrainee.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="btnDeleteTrainee">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</width>
|
||||
<height>55</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Delete trainee</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="../resources.qrc">
|
||||
<normaloff>:/icons/deleteTrainee.png</normaloff>:/icons/deleteTrainee.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="btnToOrFromArchiveTrainee">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>170</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>:/icons/traineeArchive.png</normaloff>:/icons/traineeArchive.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>170</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>:/icons/edit.png</normaloff>:/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>170</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>:/icons/archive.png</normaloff>:/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>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources>
|
||||
<include location="../resources.qrc"/>
|
||||
</resources>
|
||||
<connections/>
|
||||
</ui>
|
||||
132
DBXML/InstructorsAndTrainees/trainees/traineesview.cpp
Normal file
132
DBXML/InstructorsAndTrainees/trainees/traineesview.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include <QHeaderView>
|
||||
#include "traineesview.h"
|
||||
|
||||
TraineesView::TraineesView(DataBaseTrainees* db, TypeView type, QWidget *parent):
|
||||
CommonView(type, parent),
|
||||
dbTrainees(db)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void TraineesView::preparationTreeWidget(QTreeWidget *tree)
|
||||
{
|
||||
treeWidget = tree;
|
||||
|
||||
if(treeWidget == nullptr)
|
||||
return;
|
||||
|
||||
treeWidget->setColumnCount(8);
|
||||
|
||||
reSetHeadTreeWidget();
|
||||
|
||||
treeWidget->header()->setStyleSheet(QStringLiteral("font-size: 12pt;"));
|
||||
|
||||
treeWidget->setColumnWidth(0, 200);
|
||||
treeWidget->setColumnWidth(1, 130);
|
||||
treeWidget->setColumnWidth(2, 130);
|
||||
treeWidget->setColumnWidth(3, 130);
|
||||
treeWidget->setColumnWidth(4, 130);
|
||||
treeWidget->setColumnWidth(5, 130);
|
||||
treeWidget->setColumnWidth(6, 130);
|
||||
treeWidget->setColumnWidth(7, 100);
|
||||
|
||||
if(typeView == TypeView::onlyView)
|
||||
{//onlyView
|
||||
treeWidget->setColumnHidden(1, true);
|
||||
treeWidget->setColumnHidden(2, true);
|
||||
treeWidget->setColumnHidden(5, true);
|
||||
treeWidget->setColumnHidden(7, true);
|
||||
}
|
||||
else
|
||||
{//control
|
||||
treeWidget->setColumnHidden(5, true);
|
||||
}
|
||||
}
|
||||
|
||||
void TraineesView::loadTraineesFromDB()
|
||||
{
|
||||
if(treeWidget == nullptr)
|
||||
return;
|
||||
|
||||
//Обновление дерева
|
||||
treeWidget->clear();
|
||||
|
||||
for(Group group : dbTrainees->getListGroups())
|
||||
{
|
||||
//Группа
|
||||
QTreeWidgetItem *ItemGroup = new QTreeWidgetItem(treeWidget);
|
||||
ItemGroup->setText(0, group.getName());
|
||||
ItemGroup->setIcon(0, QIcon(QStringLiteral(":/icons/group.png")));
|
||||
QColor color = dbTrainees->getColorGroup(/*group.getColor()*/Group::color0);
|
||||
setItemColor(ItemGroup, color);
|
||||
|
||||
//Обучаемые
|
||||
QList<Trainee> listTrainees;
|
||||
listTrainees = dbTrainees->getListTraineesInGroup(group.getName());
|
||||
for(Trainee trainee : listTrainees)
|
||||
{
|
||||
QTreeWidgetItem *ItemTrainee = new QTreeWidgetItem();
|
||||
|
||||
ItemTrainee->setText(0, trainee.getName());
|
||||
ItemTrainee->setText(1, trainee.getLogin());
|
||||
ItemTrainee->setText(2, trainee.getPassword());
|
||||
ItemTrainee->setText(3, trainee.getLearnClass());
|
||||
ItemTrainee->setText(4, trainee.getComputer());
|
||||
|
||||
if(trainee.getArchived())
|
||||
{//Архивный
|
||||
ItemTrainee->setText(5, tr("yes"));
|
||||
ItemTrainee->setIcon(0, QIcon(QStringLiteral(":/icons/traineeArchive.png")));
|
||||
setItemColorArchive(ItemTrainee);
|
||||
}
|
||||
else
|
||||
{//Не Архивный
|
||||
ItemTrainee->setText(5, tr("no"));
|
||||
ItemTrainee->setIcon(0, QIcon(QStringLiteral(":/icons/trainee.png")));
|
||||
setItemColorNoArchive(ItemTrainee);
|
||||
}
|
||||
|
||||
if(trainee.getLoggedIn())
|
||||
{//Залогинен
|
||||
ItemTrainee->setText(6, tr("yes"));
|
||||
ItemTrainee->setIcon(6, QIcon(QStringLiteral(":/icons/circleGreen.png")));
|
||||
}
|
||||
else
|
||||
{//Не Залогинен
|
||||
ItemTrainee->setText(6, tr("no"));
|
||||
ItemTrainee->setIcon(6, QIcon(QStringLiteral(":/icons/circleGray.png")));
|
||||
}
|
||||
|
||||
ItemTrainee->setText(7, trainee.getWhatItDoes());
|
||||
|
||||
ItemGroup->addChild(ItemTrainee);
|
||||
|
||||
//Скрываем архивных (при необходимости)
|
||||
if(trainee.getArchived())
|
||||
if(!archiveVisible)
|
||||
ItemTrainee->setHidden(true);
|
||||
|
||||
//Скрываем незалогиненых (при необходимости)
|
||||
if(! trainee.getLoggedIn())
|
||||
if(! notLoggedInVisible)
|
||||
ItemTrainee->setHidden(true);
|
||||
}
|
||||
}
|
||||
|
||||
treeWidget->setSortingEnabled(true);
|
||||
treeWidget->sortItems(0, Qt::SortOrder::AscendingOrder);
|
||||
treeWidget->expandAll();
|
||||
|
||||
if(typeView == TypeView::control)
|
||||
{
|
||||
QTreeWidgetItem * item = treeWidget->topLevelItem(0);
|
||||
if(item != nullptr)
|
||||
treeWidget->setCurrentItem(item);
|
||||
}
|
||||
}
|
||||
|
||||
void TraineesView::reSetHeadTreeWidget()
|
||||
{
|
||||
QStringList listHeaders = {tr("Trainee"), tr("Login"), tr("Password"), tr("Class"), tr("Computer"), tr("Archived"), tr("Logged"), tr("Tasks")};
|
||||
treeWidget->setHeaderLabels(listHeaders);
|
||||
}
|
||||
27
DBXML/InstructorsAndTrainees/trainees/traineesview.h
Normal file
27
DBXML/InstructorsAndTrainees/trainees/traineesview.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#ifndef TRAINEESVIEW_H
|
||||
#define TRAINEESVIEW_H
|
||||
|
||||
#include "instructorsAndTrainees_global.h"
|
||||
#include "databasetrainees.h"
|
||||
#include "commonview.h"
|
||||
|
||||
//Родительский класс представления БД Обучаемых (для просмотра и управления)
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT TraineesView: public CommonView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TraineesView(DataBaseTrainees* db, TypeView type, QWidget *parent = nullptr);
|
||||
|
||||
protected:
|
||||
void preparationTreeWidget(QTreeWidget* tree);
|
||||
void loadTraineesFromDB();
|
||||
|
||||
void reSetHeadTreeWidget();
|
||||
|
||||
protected:
|
||||
DataBaseTrainees* dbTrainees;
|
||||
};
|
||||
|
||||
#endif // TRAINEESVIEW_H
|
||||
75
DBXML/InstructorsAndTrainees/trainees/viewertrainees.cpp
Normal file
75
DBXML/InstructorsAndTrainees/trainees/viewertrainees.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
#include "viewertrainees.h"
|
||||
#include "ui_viewertrainees.h"
|
||||
|
||||
ViewerTrainees::ViewerTrainees(DataBaseTrainees* db, QWidget *parent) :
|
||||
//QWidget(parent),
|
||||
TraineesView(db, CommonView::TypeView::onlyView, parent),
|
||||
ui(new Ui::ViewerTrainees)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
// Сделаем первоначальную инициализацию перевода для окна виджета
|
||||
qtLanguageTranslator.load(QString(QStringLiteral("translations/InstructorsAndTrainees_")) + QString(QStringLiteral("ru_RU")), QStringLiteral("."));
|
||||
qApp->installTranslator(&qtLanguageTranslator);
|
||||
|
||||
preparationTreeWidget(ui->treeWidget);
|
||||
setNotLoggedInVisible(true);
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
|
||||
ViewerTrainees::~ViewerTrainees()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
void ViewerTrainees::setFilterTraineeLoggedIn(bool enabled)
|
||||
{
|
||||
setNotLoggedInVisible(!enabled);
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
|
||||
void ViewerTrainees::on_treeWidget_itemClicked(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
if(item->childCount() == 0)
|
||||
{//Выбран обучаемый
|
||||
QString login = item->text(1);
|
||||
Q_EMIT signal_traineeSelected(login);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerTrainees::slot_tabMessengerChanged(QString login)
|
||||
{
|
||||
for (int i = 0; i < ui->treeWidget->topLevelItemCount(); i++)
|
||||
{//Проход по группам
|
||||
int countChild = ui->treeWidget->topLevelItem(i)->childCount();
|
||||
|
||||
for (int j = 0; j < countChild; j++)
|
||||
{//Проход по обучаемым
|
||||
QString loginChild = ui->treeWidget->topLevelItem(i)->child(j)->text(1);
|
||||
if(loginChild == login)
|
||||
{
|
||||
ui->treeWidget->setCurrentItem(ui->treeWidget->topLevelItem(i)->child(j));
|
||||
Q_EMIT signal_traineeSelected(login);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerTrainees::changeEvent(QEvent *event)
|
||||
{
|
||||
// В случае получения события изменения языка приложения
|
||||
if (event->type() == QEvent::LanguageChange)
|
||||
{
|
||||
ui->retranslateUi(this); // переведём окно заново
|
||||
|
||||
reSetHeadTreeWidget();
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerTrainees::slot_LanguageChanged(QString language)
|
||||
{
|
||||
qtLanguageTranslator.load(QString(QStringLiteral("translations/InstructorsAndTrainees_")) + language, QStringLiteral("."));
|
||||
qApp->installTranslator(&qtLanguageTranslator);
|
||||
}
|
||||
56
DBXML/InstructorsAndTrainees/trainees/viewertrainees.h
Normal file
56
DBXML/InstructorsAndTrainees/trainees/viewertrainees.h
Normal file
@@ -0,0 +1,56 @@
|
||||
#ifndef TRAINEESWIDGET_H
|
||||
#define TRAINEESWIDGET_H
|
||||
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QEvent>
|
||||
#include "instructorsAndTrainees_global.h"
|
||||
#include "databasetrainees.h"
|
||||
#include "traineesview.h"
|
||||
|
||||
namespace Ui {
|
||||
class ViewerTrainees;
|
||||
}
|
||||
|
||||
//Виджет только для просмотра БД Обучаемых
|
||||
|
||||
class INSTRUCTORSANDTRAINEES_EXPORT ViewerTrainees : /*public QWidget,*/ public TraineesView
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ViewerTrainees(DataBaseTrainees* db, QWidget *parent = nullptr);
|
||||
~ViewerTrainees();
|
||||
|
||||
protected:
|
||||
// Метод получения событий
|
||||
// В нём будет производиться проверка события смены перевода приложения
|
||||
void changeEvent(QEvent * event) override;
|
||||
|
||||
public Q_SLOTS:
|
||||
void slot_LanguageChanged(QString language);
|
||||
|
||||
public:
|
||||
void updateTrainees()
|
||||
{
|
||||
loadTraineesFromDB();
|
||||
}
|
||||
|
||||
void setFilterTraineeLoggedIn( bool enabled );
|
||||
|
||||
private Q_SLOTS:
|
||||
void on_treeWidget_itemClicked(QTreeWidgetItem *item, int column);
|
||||
|
||||
public Q_SLOTS:
|
||||
//слот обработки сигнала об изменении вкладки диалога в мессенджере
|
||||
void slot_tabMessengerChanged(QString login);
|
||||
|
||||
Q_SIGNALS:
|
||||
//сигнал о выборе обучаемого
|
||||
void signal_traineeSelected(QString login);
|
||||
|
||||
private:
|
||||
Ui::ViewerTrainees *ui;
|
||||
};
|
||||
|
||||
#endif // TRAINEESWIDGET_H
|
||||
58
DBXML/InstructorsAndTrainees/trainees/viewertrainees.ui
Normal file
58
DBXML/InstructorsAndTrainees/trainees/viewertrainees.ui
Normal file
@@ -0,0 +1,58 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>ViewerTrainees</class>
|
||||
<widget class="QWidget" name="ViewerTrainees">
|
||||
<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>
|
||||
</font>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Trainees</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeWidget" name="treeWidget">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Tahoma</family>
|
||||
<pointsize>10</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="iconSize">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="columnCount">
|
||||
<number>1</number>
|
||||
</property>
|
||||
<column>
|
||||
<property name="text">
|
||||
<string notr="true">1</string>
|
||||
</property>
|
||||
</column>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Reference in New Issue
Block a user