itom  3.0.0
UserModel.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet 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 
28 namespace ito
29 {
30 
31 enum UserRole
32 {
33  userRoleBasic = 0,
34  userRoleAdministrator = 1,
35  userRoleDeveloper = 2
36 };
37 
38 enum UserFeature
39 {
40  featDeveloper = 1,
41  featFileSystem = 2,
42  featUserManag = 4,
43  featPlugins = 8,
44  featConsoleRead = 16,
45  featConsoleReadWrite = 32,
46  featProperties = 64
47 };
48 
49 Q_DECLARE_FLAGS(UserFeatures, UserFeature)
50 
51 
56 {
57  UserInfoStruct() {};
58  UserInfoStruct(const QString &sname, const QString &suid, const QString siniFile, UserRole srole, UserFeatures sfeatures, bool sStandardUser) : name(sname), id(suid), iniFile(siniFile), role(srole), features(sfeatures), standardUser(sStandardUser) {}
59  QString name;
60  QString id;
61  QString iniFile;
62  UserRole role;
63  UserFeatures features;
64  bool standardUser;
65 };
66 
73 class UserModel : public QAbstractItemModel
74 {
75  Q_OBJECT
76 
77  public:
78  UserModel(/*const QString &data, QObject *parent = 0*/);
79  ~UserModel();
80 
81  enum UserModelIndex
82  {
83  umiName = 0,
84  umiId = 1,
85  umiRole = 2,
86  umiIniFile = 3,
87  umiFeatures = 4
88  };
89 
90  QString getRoleName(const UserRole &role) const;
91  QString getFeatureName(const UserFeature &feature) const;
92 
93  QVariant data(const QModelIndex &index, int role) const;
94  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
95  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
96  QModelIndex parent(const QModelIndex &index) const;
97  int rowCount(const QModelIndex &parent = QModelIndex()) const;
98  int columnCount(const QModelIndex &parent = QModelIndex()) const;
99  int addUser(const UserInfoStruct &newUser);
100  void removeAllUsers();
101  bool removeUser(const QModelIndex &index);
102 
103  private:
104  QList<QString> m_headers;
105  QList<QVariant> m_alignment;
106  QList<UserInfoStruct> m_userInfo;
107 };
108 } //end namespace ito
109 
110 Q_DECLARE_METATYPE(ito::UserRole);
111 Q_DECLARE_METATYPE(ito::UserFeatures);
112 Q_DECLARE_METATYPE(ito::UserFeature);
113 
114 
115 
116 #endif //USERMODEL_H
QList< UserInfoStruct > m_userInfo
list with user information
Definition: UserModel.h:106
int addUser(const UserInfoStruct &newUser)
Definition: UserModel.cpp:190
class for for visualizing the available users
Definition: UserModel.h:73
Definition: apiFunctionsGraph.cpp:39
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
Definition: UserModel.cpp:173
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
Definition: UserModel.cpp:76
int rowCount(const QModelIndex &parent=QModelIndex()) const
Definition: UserModel.cpp:67
QModelIndex parent(const QModelIndex &index) const
Definition: UserModel.cpp:57
QList< QString > m_headers
string list of names of column headers
Definition: UserModel.h:104
~UserModel()
Definition: UserModel.cpp:44
int columnCount(const QModelIndex &parent=QModelIndex()) const
Definition: UserModel.cpp:158
UserModel()
Definition: UserModel.cpp:34
QList< QVariant > m_alignment
list of alignments for the corresponding headers
Definition: UserModel.h:105
QVariant data(const QModelIndex &index, int role) const
Definition: UserModel.cpp:99
Definition: UserModel.h:55