itom
Loading...
Searching...
No Matches
UserModel.h
1/* ********************************************************************
2 itom software
3 URL: http://www.uni-stuttgart.de/ito
4 Copyright (C) 2020, Institut für Technische Optik (ITO),
5 Universität Stuttgart, Germany
6
7 This file is part of itom.
8
9 itom is free software; you can redistribute it and/or modify it
10 under the terms of the GNU Library General Public Licence as published by
11 the Free Software Foundation; either version 2 of the Licence, or (at
12 your option) any later version.
13
14 itom is distributed in the hope that it will be useful, but
15 WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17 General Public Licence for more details.
18
19 You should have received a copy of the GNU Library General Public License
20 along with itom. If not, see <http://www.gnu.org/licenses/>.
21*********************************************************************** */
22
23#ifndef USERMODEL_H
24#define USERMODEL_H
25
26#include <qabstractitemmodel.h>
27
28namespace ito
29{
30
33{
34 userRoleBasic = 0, /* basic user with lowest rights */
35 userRoleDeveloper = 1, /* developer user with many rights */
36 userRoleAdministrator = 2, /* most advanced user with all rights. */
37
38};
39
42{
43 featDeveloper = 0x01, /* the user has the right to create, open, view or edit python scripts */
44 featFileSystem = 0x02,
45 featUserManagement = 0x04,
46 featPlugins = 0x08,
47 featConsoleRead = 0x10,
48 featConsoleReadWrite = 0x20,
49 featProperties = 0x40
50};
51
52Q_DECLARE_FLAGS(UserFeatures, UserFeature)
53
54
59{
60 UserInfoStruct() {};
61 UserInfoStruct(const QString &sname, const QString &suid, const QString siniFile, UserRole srole,
62 UserFeatures sfeatures, QByteArray &spassword, bool sStandardUser)
63 : name(sname), id(suid), iniFile(siniFile), role(srole), password(spassword),
64 features(sfeatures), standardUser(sStandardUser) {}
65 QString name;
66 QString id;
67 QString iniFile;
68 QByteArray password;
69 UserRole role;
70 UserFeatures features;
71 bool standardUser;
72};
73
80class UserModel : public QAbstractItemModel
81{
82 Q_OBJECT
83
84 public:
85 UserModel(/*const QString &data, QObject *parent = 0*/);
86 ~UserModel();
87
88 enum UserModelIndex
89 {
90 umiName = 0,
91 umiId = 1,
92 umiRole = 2,
93 umiIniFile = 3,
94 umiFeatures = 4,
95 umiPassword = 5
96 };
97
98 QString getRoleName(const UserRole &role) const;
99 QString getFeatureName(const UserFeature &feature) const;
100
101 QVariant data(const QModelIndex &index, int role) const;
102 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
103 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
104 QModelIndex parent(const QModelIndex &index) const;
105 int rowCount(const QModelIndex &parent = QModelIndex()) const;
106 int columnCount(const QModelIndex &parent = QModelIndex()) const;
107
108 int addUser(const UserInfoStruct &newUser);
109 void removeAllUsers();
110 bool removeUser(const QModelIndex &index);
111
112 QModelIndex getUser(const QString &userId) const;
113 bool hasPassword(const QModelIndex &index) const;
114 bool checkPassword(const QModelIndex &index, const QString &password) const;
115 QString getUserName(const QModelIndex &index) const;
116 QString getUserId(const QModelIndex &index) const;
117 UserRole getUserRole(const QModelIndex &index) const;
118 UserFeatures getUserFeatures(const QModelIndex &index) const;
119 QString getUserSettingsFile(const QModelIndex &index) const;
120 QModelIndex currentUser() const { return m_currentUser; }
121 bool setCurrentUser(const QString &userId);
122
123 private:
124 QList<QString> m_headers;
125 QList<QVariant> m_alignment;
126 QList<UserInfoStruct> m_userInfo;
127 QModelIndex m_currentUser;
128};
129} //end namespace ito
130
131Q_DECLARE_METATYPE(ito::UserRole);
132Q_DECLARE_METATYPE(ito::UserFeatures);
133Q_DECLARE_METATYPE(ito::UserFeature);
134
135
136
137#endif //USERMODEL_H
class for for visualizing the available users
Definition UserModel.h:81
UserModel()
Definition UserModel.cpp:35
QModelIndex parent(const QModelIndex &index) const
Definition UserModel.cpp:60
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition UserModel.cpp:79
~UserModel()
Definition UserModel.cpp:47
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition UserModel.cpp:180
QList< UserInfoStruct > m_userInfo
list with user information
Definition UserModel.h:126
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition UserModel.cpp:165
QModelIndex m_currentUser
the model index of the currently logged-in user
Definition UserModel.h:127
QList< QVariant > m_alignment
list of alignments for the corresponding headers
Definition UserModel.h:125
QVariant data(const QModelIndex &index, int role) const
Definition UserModel.cpp:102
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition UserModel.cpp:70
int addUser(const UserInfoStruct &newUser)
Definition UserModel.cpp:197
QList< QString > m_headers
string list of names of column headers
Definition UserModel.h:124
Definition apiFunctionsGraph.cpp:40
UserFeature
Enumeration that defines some feature permissions for a user.
Definition UserModel.h:42
UserRole
Enumeration that defines some user roles.
Definition UserModel.h:33
Definition UserModel.h:59