DtkCore
DTK Core module
Dtk::Core::DConfigFile类 参考

规范配置文件读写的相关接口的配置文件实现. 更多...

类 Dtk::Core::DConfigFile 继承关系图:
Dtk::Core::DObject

struct  Version
 版本信息 更多...
 

Public 类型

enum  Flag { NoOverride = 1 << 0 , Global = 1 << 1 }
 
enum  Permissions { ReadOnly , ReadWrite }
 
enum  Visibility { Private , Public }
 

Public 成员函数

 DConfigFile (const QString &appId, const QString &name, const QString &subpath=QString())
 构造配置文件管理对象 appId 应用程序唯一标识 name 配置文件名 subpath 子目录
 
 DConfigFile (const DConfigFile &other)
 
bool load (const QString &localPrefix=QString())
 解析配置文件 localPrefix 为目录前缀 更多...
 
bool load (QIODevice *meta, const QList< QIODevice * > &overrides)
 解析配置文件流 meta 为原型流 overrides 为覆盖机制查找的文件流 更多...
 
bool save (const QString &localPrefix=QString(), QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool sync=false) const
 保存缓存的值到磁盘中 format 保存格式 sync 是否立即刷新 更多...
 
bool isValid () const
 检测配置文件是否有效 更多...
 
QVariant value (const QString &key, DConfigCache *userCache=nullptr) const
 DConfigFile::value 更多...
 
bool setValue (const QString &key, const QVariant &value, const QString &callerAppid, DConfigCache *userCache=nullptr)
 设置缓存中的值 key 配置项名称 value 需要设置的值 uid 设置时的用户id appid 设置时的应用id 更多...
 
DConfigCachecreateUserCache (const uint uid)
 
DConfigCacheglobalCache () const
 返回全局缓存 更多...
 
DConfigMetameta ()
 返回原型对象 更多...
 

静态 Public 成员函数

static constexpr Version supportedVersion ()
 支持的版本 更多...
 

友元

QDebug operator<< (QDebug, const DConfigFile &)
 

额外继承的成员函数

- Protected 成员函数 继承自 Dtk::Core::DObject
 DObject (DObject *parent=nullptr)
 只有在不需要数据成员的派生类中才会使用 parent 父类指针
 
 DObject (DObjectPrivate &dd, DObject *parent=nullptr)
 在派生类中比较常用的构造函数 dd 私有类对象
 
- Protected 属性 继承自 Dtk::Core::DObject
QScopedPointer< DObjectPrivated_d_ptr
 

详细描述

规范配置文件读写的相关接口的配置文件实现.

\inmodule dtkcore

成员枚举类型说明

◆ Flag

\value NoOverride 存在此标记时,将表明则此配置项不可被覆盖(详见下述 override 机制)。 反之,不存在此标记时表明此配置项允许被覆盖,对于此类配置项, 如若其有界面设置入口,则当此项不可写时,应当隐藏或禁用界面的设置入口. \value Global 当读写此类配置时,将忽略用户身份,无论程序使用哪个用户身份执行,读操作都将获取到同样的数据, 写操作将对所有用户都生效。但是,如果对应的配置存储目录不存在或无权限写入,则忽略此标志.

◆ Permissions

\value ReadOnly 将配置项覆盖为只读, \value ReadWrite 将配置项覆盖为可读可写.

◆ Visibility

\value Private 仅限程序内部使用, 对外不可见。此类配置项完全由程序自己读写,可随意增删改写其含义,无需做兼容性考虑, \value Public 外部程序可使用。 此类配置项一旦发布,在兼容性版本的升级中,要保障此配置项向下兼容, 简而言之,只允许在程序/库的大版本升级时才允许删除或修改此类配置项, 当配置项的 permissions、visibility、flags 任意一个属性被修改则认为此配置项被修改, 除此之外修改 value、name、description 属性时则不需要考虑兼容性.

成员函数说明

◆ globalCache()

DConfigCache * Dtk::Core::DConfigFile::globalCache ( ) const

返回全局缓存

返回

◆ isValid()

bool Dtk::Core::DConfigFile::isValid ( ) const

检测配置文件是否有效

返回

◆ load() [1/2]

bool Dtk::Core::DConfigFile::load ( const QString &  localPrefix = QString())

解析配置文件 localPrefix 为目录前缀

返回

◆ load() [2/2]

bool Dtk::Core::DConfigFile::load ( QIODevice *  meta,
const QList< QIODevice * > &  overrides 
)

解析配置文件流 meta 为原型流 overrides 为覆盖机制查找的文件流

返回

◆ meta()

DConfigMeta * Dtk::Core::DConfigFile::meta ( )

返回原型对象

返回

◆ save()

bool Dtk::Core::DConfigFile::save ( const QString &  localPrefix = QString(),
QJsonDocument::JsonFormat  format = QJsonDocument::Indented,
bool  sync = false 
) const

保存缓存的值到磁盘中 format 保存格式 sync 是否立即刷新

返回

◆ setValue()

bool Dtk::Core::DConfigFile::setValue ( const QString &  key,
const QVariant &  value,
const QString &  callerAppid,
DConfigCache userCache = nullptr 
)

设置缓存中的值 key 配置项名称 value 需要设置的值 uid 设置时的用户id appid 设置时的应用id

返回
为true时表示重新设置了新值,false表示没有设置

◆ supportedVersion()

constexpr DConfigFile::Version Dtk::Core::DConfigFile::supportedVersion ( )
staticconstexpr

支持的版本

返回

◆ value()

QVariant Dtk::Core::DConfigFile::value ( const QString &  key,
DConfigCache userCache = nullptr 
) const

DConfigFile::value

参数
key配置项名称
uid用户id,当key为全局项时,uid无效
返回

该类的文档由以下文件生成: