itom 1.4.0
|
00001 /* ******************************************************************** 00002 itom software 00003 URL: http://www.uni-stuttgart.de/ito 00004 Copyright (C) 2013, Institut für Technische Optik (ITO), 00005 Universität Stuttgart, Germany 00006 00007 This file is part of itom. 00008 00009 itom is free software; you can redistribute it and/or modify it 00010 under the terms of the GNU Library General Public Licence as published by 00011 the Free Software Foundation; either version 2 of the Licence, or (at 00012 your option) any later version. 00013 00014 itom is distributed in the hope that it will be useful, but 00015 WITHOUT ANY WARRANTY; without even the implied warranty of 00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library 00017 General Public Licence for more details. 00018 00019 You should have received a copy of the GNU Library General Public License 00020 along with itom. If not, see <http://www.gnu.org/licenses/>. 00021 *********************************************************************** */ 00022 00023 #ifndef USERMODEL_H 00024 #define USERMODEL_H 00025 00026 #include <qabstractitemmodel.h> 00027 00028 namespace ito 00029 { 00030 00031 enum UserRole 00032 { 00033 userRoleBasic = 0, 00034 userRoleAdministrator = 1, 00035 userRoleDeveloper = 2 00036 }; 00037 00038 enum UserFeature 00039 { 00040 featDeveloper = 1, 00041 featFileSystem = 2, 00042 featUserManag = 4, 00043 featPlugins = 8, 00044 featConsoleRead = 16, 00045 featConsoleReadWrite = 32, 00046 featProperties = 64 00047 }; 00048 00049 Q_DECLARE_FLAGS(UserFeatures, UserFeature) 00050 00051 00055 struct UserInfoStruct 00056 { 00057 UserInfoStruct() {}; 00058 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) {} 00059 QString name; 00060 QString id; 00061 QString iniFile; 00062 UserRole role; 00063 UserFeatures features; 00064 bool standardUser; 00065 }; 00066 00073 class UserModel : public QAbstractItemModel 00074 { 00075 Q_OBJECT 00076 00077 public: 00078 UserModel(/*const QString &data, QObject *parent = 0*/); 00079 ~UserModel(); 00080 00081 enum UserModelIndex 00082 { 00083 umiName = 0, 00084 umiId = 1, 00085 umiRole = 2, 00086 umiIniFile = 3, 00087 umiFeatures = 4 00088 }; 00089 00090 QString getRoleName(const UserRole &role) const; 00091 QString getFeatureName(const UserFeature &feature) const; 00092 00093 QVariant data(const QModelIndex &index, int role) const; 00094 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; 00095 QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; 00096 QModelIndex parent(const QModelIndex &index) const; 00097 int rowCount(const QModelIndex &parent = QModelIndex()) const; 00098 int columnCount(const QModelIndex &parent = QModelIndex()) const; 00099 int addUser(const UserInfoStruct &newUser); 00100 void removeAllUsers(); 00101 bool removeUser(const QModelIndex &index); 00102 00103 private: 00104 QList<QString> m_headers; 00105 QList<QVariant> m_alignment; 00106 QList<UserInfoStruct> m_userInfo; 00107 }; 00108 } 00109 00110 Q_DECLARE_METATYPE(ito::UserRole); 00111 Q_DECLARE_METATYPE(ito::UserFeatures); 00112 Q_DECLARE_METATYPE(ito::UserFeature); 00113 00114 #endif //USERMODEL_H