PDA

View Full Version : Widgets wich depended from user permissions



alex1
16th September 2011, 19:28
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);

nightghost
20th September 2011, 11:43
You could do something like this (not compilable!, just to get the idea):




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::T ype 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 (http://doc.qt.nokia.com/latest/qflags.html)
QObject::installEventHandler (http://doc.qt.nokia.com/latest/qobject.html#installEventHandler)

alex1
21st September 2011, 08:16
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!!!!!!!!!!!