Widgets wich depended from user permissions
Hi everybody.
My question is this :
I am currently developing a program on qt 4.7.3
I want that a part of my widgets would be dependent from user permissions.
For example,I want make, invisible a widget (if any user not have the desired permissions)
Is it possible to do so, even at the stage of development, for example by definition any property?
I dont want to write in my application a following code:
QWidget * myWidget = ....
...
myWidget->setVisible(permissions == Admin || permissions == Manager);
Re: Widgets wich depended from user permissions
You could do something like this (not compilable!, just to get the idea):
Code:
PermissionManager* manager = getPermissionManager();
foreach(widget, all-widgets-that-should-depend-on-permissions) {
manager->registerWidget(widget, Permission::Admin | Permission::Manager);
}
// later
void onPermissionChange(Permission::Type permission) {
PermissionManager* manager = getPermissionManager();
manager->setUserPermission(permission)
}
// implementation could be like this
PermissionManager::setUserPermission(Permission::Type permission) {
foreach(widget, widget-list) {
Permissions permissions = getPermissionsForWidget(widget);
widget->setVisible(permissions is valid permission));
}
}
You could also install a EventHandler an watch for the visible/enable events and control the permissions there. This would also catch if a widget is made visible directly. Interesting for implementation could be
- QFlags
- QObject::installEventHandler
Re: Widgets wich depended from user permissions
Thank you very much nightghost
But I really thought that there is already something similar in Qt.
Probably I going to use your idea
Thanks!!!!!!!!!!!