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
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