Extended user interaction, fixed related problems
This commit is contained in:
parent
f742061a5e
commit
9bdce6a96b
5 changed files with 118 additions and 22 deletions
|
|
@ -12,12 +12,14 @@ SOURCES += \
|
||||||
main.cpp \
|
main.cpp \
|
||||||
loginwindow.cpp \
|
loginwindow.cpp \
|
||||||
objects/profession.cpp \
|
objects/profession.cpp \
|
||||||
objects/user.cpp
|
objects/user.cpp \
|
||||||
|
objects/userprofession.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
loginwindow.h \
|
loginwindow.h \
|
||||||
objects/profession.h \
|
objects/profession.h \
|
||||||
objects/user.h
|
objects/user.h \
|
||||||
|
objects/userprofession.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
loginwindow.ui
|
loginwindow.ui
|
||||||
|
|
|
||||||
|
|
@ -52,35 +52,53 @@ User User::createUser(QString login, QString password, UserType userType,
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool User::addProfession(const Profession &p) {
|
bool User::hasProfession(PID pid) {
|
||||||
if (p.pID() == mCurrentProfession) {
|
foreach (auto prof, mProfessions) {
|
||||||
|
if (prof.getProfession() == pid) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool User::addProfession(const Profession &p, ProfRank rank) {
|
||||||
|
if (hasProfession(p.pID())) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mProfessions.contains(p.pID())) {
|
|
||||||
if (mProfessions.size() >= 4) {
|
if (mProfessions.size() >= 4) {
|
||||||
mProfessions.remove(0);
|
mProfessions.remove(0);
|
||||||
}
|
}
|
||||||
mProfessions.push_back(p.pID());
|
UserProfession up(p.pID(), rank);
|
||||||
}
|
|
||||||
|
|
||||||
|
mProfessions.push_back(up);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool User::setCurrentProfession(const Profession &p) {
|
bool User::setCurrentProfession(PID pid) {
|
||||||
if (!mProfessions.contains(p.pID())) {
|
if (!hasProfession(pid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p.pID() != mCurrentProfession) {
|
mCurrentProfession = pid;
|
||||||
mCurrentProfession = p.pID();
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void User::removeProfession(const Profession &p) {
|
void User::removeProfession(PID pid) {
|
||||||
mProfessions.removeAll(p.pID());
|
// QMutableVectorIterator<UserProfession> i(mProfessions);
|
||||||
|
// while (i.hasNext()) {
|
||||||
|
// if (i.value().getProfession() == pid) {
|
||||||
|
// i.remove();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
auto pred = [pid](UserProfession p) {
|
||||||
|
return p.getProfession() == pid;
|
||||||
|
};
|
||||||
|
|
||||||
|
mProfessions.erase(std::remove_if(mProfessions.begin(), mProfessions.end(), pred),
|
||||||
|
mProfessions.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator==(const User &l, const User &r) {
|
bool operator==(const User &l, const User &r) {
|
||||||
|
|
|
||||||
|
|
@ -4,11 +4,13 @@
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
#include "profession.h"
|
#include "profession.h"
|
||||||
|
#include "userprofession.h"
|
||||||
|
|
||||||
typedef QUuid UID;
|
typedef QUuid UID;
|
||||||
typedef QVector<PID> ProfessionsList;
|
typedef QVector<UserProfession> ProfessionsList;
|
||||||
|
|
||||||
enum class UserType {
|
enum class UserType {
|
||||||
ADMINISTRATOR,
|
ADMINISTRATOR,
|
||||||
|
|
@ -44,9 +46,10 @@ public:
|
||||||
static User createUser(QString login, QString password, UserType userType,
|
static User createUser(QString login, QString password, UserType userType,
|
||||||
QString firstName, QString secondName, QString patronymic);
|
QString firstName, QString secondName, QString patronymic);
|
||||||
|
|
||||||
bool addProfession(const Profession &p);
|
bool hasProfession(PID pid);
|
||||||
bool setCurrentProfession(const Profession &p);
|
bool addProfession(const Profession &p, ProfRank rank);
|
||||||
void removeProfession(const Profession &p);
|
bool setCurrentProfession(PID pid);
|
||||||
|
void removeProfession(PID pid);
|
||||||
|
|
||||||
friend bool operator==(const User &l, const User &r);
|
friend bool operator==(const User &l, const User &r);
|
||||||
friend QDataStream& operator<<(QDataStream &stream, const User &usr);
|
friend QDataStream& operator<<(QDataStream &stream, const User &usr);
|
||||||
|
|
|
||||||
43
iFacility/objects/userprofession.cpp
Normal file
43
iFacility/objects/userprofession.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
#include "userprofession.h"
|
||||||
|
|
||||||
|
UserProfession::UserProfession(PID pid, ProfRank rank) {
|
||||||
|
mProfession = pid;
|
||||||
|
mRank = rank;
|
||||||
|
}
|
||||||
|
|
||||||
|
PID UserProfession::getProfession() const {
|
||||||
|
return mProfession;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDate UserProfession::getAcquiredDate() const {
|
||||||
|
return mAcquired;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProfRank UserProfession::getRank() const {
|
||||||
|
return mRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool UserProfession::setRank(quint8 newRank) {
|
||||||
|
if (newRank < 1) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mRank = newRank;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator==(const UserProfession &l, const UserProfession &r) {
|
||||||
|
return l.mProfession == r.mProfession &&
|
||||||
|
l.mAcquired == r.mAcquired &&
|
||||||
|
l.mRank == r.mRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream& operator<<(QDataStream &stream, const UserProfession &up) {
|
||||||
|
stream << up.mProfession << up.mAcquired << up.mRank;
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
|
|
||||||
|
QDataStream& operator>>(QDataStream &stream, UserProfession &up) {
|
||||||
|
stream >> up.mProfession >> up.mAcquired >> up.mRank;
|
||||||
|
return stream;
|
||||||
|
}
|
||||||
30
iFacility/objects/userprofession.h
Normal file
30
iFacility/objects/userprofession.h
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef USERPROFESSION_H
|
||||||
|
#define USERPROFESSION_H
|
||||||
|
|
||||||
|
#include <QDate>
|
||||||
|
|
||||||
|
#include "profession.h"
|
||||||
|
|
||||||
|
typedef quint8 ProfRank;
|
||||||
|
|
||||||
|
class UserProfession {
|
||||||
|
private:
|
||||||
|
PID mProfession;
|
||||||
|
QDate mAcquired;
|
||||||
|
ProfRank mRank;
|
||||||
|
|
||||||
|
public:
|
||||||
|
UserProfession() = default;
|
||||||
|
UserProfession(PID pid, ProfRank rank);
|
||||||
|
|
||||||
|
PID getProfession() const;
|
||||||
|
QDate getAcquiredDate() const;
|
||||||
|
ProfRank getRank() const;
|
||||||
|
bool setRank(quint8 newRank);
|
||||||
|
|
||||||
|
friend bool operator==(const UserProfession &l, const UserProfession &r);
|
||||||
|
friend QDataStream& operator<<(QDataStream &stream, const UserProfession &up);
|
||||||
|
friend QDataStream& operator>>(QDataStream &stream, UserProfession &up);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USERPROFESSION_H
|
||||||
Loading…
Add table
Add a link
Reference in a new issue