PDA

View Full Version : Advanced settings handling, suggestions?



Vultapher
3rd October 2010, 17:14
For my current project, I need a way to manage settings that goes beyond what QSettings provides.
For that, I'd like to ask you for suggestions.

One thing that I really need is to be able to define some properties of the individual settings, like range for integers, length for strings and so on. One idea to handle that is to make a base class for the settings items that stores the name and a pointer to the Settings class to which the setting belongs. class BasicType : public QObject {
Q_OBJECT
public:
BasicType( const QString &name, Settings *parent );
virtual ~BasicType();
virtual QVariant value() = 0;
virtual void set( const QVariant &newVal ) throw( something ) = 0;
};Based on that class, there would be a set of specialized classes like IntegerType which would know some details about the allowed contents.
The Settings class would then contain a member for each of the types it is responsible for together with a Q_PROPERTY and control access to each of the items (so that they are never visible to the outside). This would also probably be the point where access management would hook in to allow access only to items that have the USER property set to true in the Settings class or finer grained if there's a way to find out who wants access to the item.

Another way that came to my mind was the usage of just a Settings class and a set of visitors that would walk through the Settings class once one of the settings items change or just inspect the specific one and throw an exception if the new value would violate, say, the integer range of the item.

This Settings class could then provide a function to load and store its contents using QSettings.

What do you think? Suggestions welcome.

greetings,
Vultapher

tbscope
3rd October 2010, 18:17
An xml file.

Or a data stream

squidge
3rd October 2010, 19:33
Or even, maybe a sql data file, then you can search with specific parameters (like user=x and accesslevel>y).

Vultapher
3rd October 2010, 20:45
Well, that would be an option to store it and let an external system handle everything for me. The application will either define integer access levels or flags. What I'm interested in is a way to manage the config inside the program. I'd go with Q_PROPERTY's and some functions that would simply check for the USER property parameter to restrict access (using a function there that would ask an SQL db or LDAP dir), but that's insufficient as I couldn't really define limits for the settings. Basically, I'm not sure what the better approach is, but I've seen type-specific classes used to store one single setting, managed by a config class before and thought it's a nice and clear way to handle that. Do you think so too?