Commit 58bd9351 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

Settings: Add a flag system

parent c0b50af4
......@@ -24,12 +24,13 @@
#include <QtDebug>
SettingValue::SettingValue( SettingValue::Type type, const QVariant& defaultValue,
const char* name, const char* desc ) :
const char* name, const char* desc, SettingValue::Flags flags ) :
m_val( defaultValue ),
m_defaultVal( defaultValue ),
m_name( name ),
m_desc( desc ),
m_type( type )
m_type( type ),
m_flags( flags )
{
}
......@@ -72,3 +73,9 @@ SettingValue::type() const
{
return m_type;
}
SettingValue::Flags
SettingValue::flags() const
{
return m_flags;
}
......@@ -46,6 +46,13 @@ class SettingValue : public QObject
Language,
KeyboardShortcut
};
enum Flags
{
Nothing = 0,
/// If this flag is used, then the variable should not be shown in the config widgets.
Private = 1,
};
/**
* \brief Constructs a setting value with its default value and description
*
......@@ -53,7 +60,7 @@ class SettingValue : public QObject
* \param desc The setting description
*/
SettingValue( Type type, const QVariant& defaultValue, const char* name,
const char* desc );
const char* desc, Flags flags = Nothing );
/**
* \brief setter for the m_val member
......@@ -77,6 +84,7 @@ class SettingValue : public QObject
const char *name() const;
Type type() const;
Flags flags() const;
private:
/**
......@@ -87,6 +95,7 @@ class SettingValue : public QObject
const char* m_name;
const char* m_desc;
Type m_type;
Flags m_flags;
signals:
/**
* \brief This signal is emmited while the m_val
......
......@@ -196,14 +196,15 @@ SettingsManager::load( const QDomElement &root )
void
SettingsManager::createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue, const char *name,
const char *desc, SettingsManager::Type varType /*= Vlmc*/ )
const char *desc, SettingsManager::Type varType /*= Vlmc*/,
SettingValue::Flags flags /*= SettingValue::Nothing*/ )
{
QWriteLocker wlock( &m_rwLock );
if ( varType == Vlmc && m_classicSettings.contains( key ) == false )
m_classicSettings.insert( key, new SettingValue( type, defaultValue, name, desc ) );
m_classicSettings.insert( key, new SettingValue( type, defaultValue, name, desc, flags ) );
else if ( varType == Project && m_xmlSettings.contains( key ) == false )
m_xmlSettings.insert( key, new SettingValue( type, defaultValue, name, desc ) );
m_xmlSettings.insert( key, new SettingValue( type, defaultValue, name, desc, flags ) );
else
Q_ASSERT_X( false, __FILE__, "creating an already created variable" );
}
......@@ -51,35 +51,42 @@ class QDomElement;
#define VLMC_PROJECT_GET_BOOL( key ) SettingsManager::getInstance()->value( key, SettingsManager::Project )->get().toBool()
#define VLMC_CREATE_PROJECT_VAR( type, key, defaultValue, name, desc ) \
#define VLMC_CREATE_PROJECT_VAR( type, key, defaultValue, name, desc, flags ) \
SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
desc, SettingsManager::Project );
desc, SettingsManager::Project, flags );
#define VLMC_CREATE_PROJECT_INT( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Int, key, defaultValue, name, desc )
VLMC_CREATE_PROJECT_VAR( SettingValue::Int, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PROJECT_STRING( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, name, desc )
VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PROJECT_DOUBLE( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc )
VLMC_CREATE_PROJECT_VAR( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PROJECT_BOOL( key, defaultValue, name, desc ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc )
VLMC_CREATE_PROJECT_VAR( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc ) \
#define VLMC_CREATE_PREFERENCE( type, key, defaultValue, name, desc, flags ) \
SettingsManager::getInstance()->createVar( type, key, defaultValue, name, \
desc, SettingsManager::Vlmc );
desc, SettingsManager::Vlmc, flags );
/// Vlmc preferences maccros
#define VLMC_CREATE_PREFERENCE_INT( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, name, desc )
VLMC_CREATE_PREFERENCE( SettingValue::Int, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE_STRING( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, name, desc )
VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE_DOUBLE( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Double, key, defaultValue, name, desc )
VLMC_CREATE_PREFERENCE( SettingValue::Double, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE_LANGUAGE( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Language, key, defaultValue, name, desc )
VLMC_CREATE_PREFERENCE( SettingValue::Language, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE_KEYBOARD( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc )
VLMC_CREATE_PREFERENCE( SettingValue::KeyboardShortcut, key, defaultValue, name, desc, SettingValue::Nothing )
#define VLMC_CREATE_PREFERENCE_BOOL( key, defaultValue, name, desc ) \
VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc )
VLMC_CREATE_PREFERENCE( SettingValue::Bool, key, defaultValue, name, desc, SettingValue::Nothing )
//Convenience maccros :
#define VLMC_CREATE_PRIVATE_PREFERENCE_STRING( key, defaultValue ) \
VLMC_CREATE_PREFERENCE( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
#define VLMC_CREATE_PRIVATE_PROJECT_STRING( key, defaultValue ) \
VLMC_CREATE_PROJECT_VAR( SettingValue::String, key, defaultValue, "", "", SettingValue::Private )
class SettingsManager : public QObject, public Singleton<SettingsManager>
{
......@@ -104,7 +111,8 @@ class SettingsManager : public QObject, public Singleton<SettingsManager>
void createVar( SettingValue::Type type, const QString &key,
const QVariant &defaultValue,
const char *name, const char *desc,
Type varType = Vlmc );
Type varType = Vlmc,
SettingValue::Flags flags = SettingValue::Nothing );
bool watchValue( const QString &key,
QObject* receiver,
const char *method,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment