规范配置文件读写的相关接口的配置文件实现
更多...
#include <dconfigfile.h>
|
| DConfigFile (const QString &appId, const QString &name, const QString &subpath=QString()) |
| DConfigFile构造函数,构造配置文件管理对象。 更多...
|
|
| DConfigFile (const DConfigFile &other) |
| DConfigFile构造函数,构造配置文件管理对象。 更多...
|
|
bool | load (const QString &localPrefix=QString()) |
| 解析配置文件 更多...
|
|
bool | load (QIODevice *meta, const QList< QIODevice * > &overrides) |
| 解析配置文件流 更多...
|
|
bool | save (const QString &localPrefix=QString(), QJsonDocument::JsonFormat format=QJsonDocument::Indented, bool sync=false) const |
| 保存缓存的值到磁盘中 更多...
|
|
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) |
| 设置缓存中的值 更多...
|
|
DConfigCache * | createUserCache (const uint uid) |
| 创建用户缓存
|
|
DConfigCache * | globalCache () const |
| 返回全局缓存 更多...
|
|
DConfigMeta * | meta () |
| 返回原型对象 更多...
|
|
◆ Flag
配置项名称
值 | 序号 | 含义 |
NoOverride | 0 | 存在此标记时,将表明则此配置项不可被覆盖(详见下述 override 机制)。反之,不存在此标记时表明此配置项允许被覆盖,对于此类配置项,如若其有界面设置入口,则当此项不可写时,应当隐藏或禁用界面的设置入口. |
Global | 1 | 当读写此类配置时,将忽略用户身份,无论程序使用哪个用户身份执行,读操作都将获取到同样的数据,写操作将对所有用户都生效。但是,如果对应的配置存储目录不存在或无权限写入,则忽略此标志 |
◆ Permissions
配置项的权限
值 | 序号 | 含义 |
ReadOnly | 0 | 将配置项覆盖为只读 |
ReadWrite | 1 | 将配置项覆盖为可读可写 |
◆ Visibility
配置项的可见性
值 | 序号 | 含义 |
Private | 0 | 仅限程序内部使用,对外不可见。此类配置项完全由程序自己读写,可随意增删改写其含义,无需做兼容性考虑 |
Public | 1 | 外部程序可使用。 此类配置项一旦发布,在兼容性版本的升级中,要保障此配置项向下兼容,简而言之,只允许在程序/库的大版本升级时才允许删除或修改此类配置项,当配置项的 permissions、visibility、flags 任意一个属性被修改则认为此配置项被修改,除此之外修改 value、name、description 属性时则不需要考虑兼容性。 |
◆ DConfigFile() [1/2]
Dtk::Core::DConfigFile::DConfigFile |
( |
const QString & |
appId, |
|
|
const QString & |
name, |
|
|
const QString & |
subpath = QString() |
|
) |
| |
|
explicit |
DConfigFile构造函数,构造配置文件管理对象。
- 参数
-
[in] | appId | 应用程序唯一标识 |
[in] | name | 配置文件名 |
[in] | subpath | 子目录 |
◆ DConfigFile() [2/2]
Dtk::Core::DConfigFile::DConfigFile |
( |
const DConfigFile & |
other | ) |
|
|
explicit |
DConfigFile构造函数,构造配置文件管理对象。
- 参数
-
[in] | appId | 应用程序唯一标识 |
[in] | name | 配置文件名 |
[in] | subpath | 子目录 |
◆ 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() | ) |
|
◆ load() [2/2]
bool Dtk::Core::DConfigFile::load |
( |
QIODevice * |
meta, |
|
|
const QList< QIODevice * > & |
overrides |
|
) |
| |
解析配置文件流
- 参数
-
[in] | meta | 为原型流 |
[in] | overrides | 为覆盖机制查找的文件流 |
- 返回
◆ meta()
◆ save()
bool Dtk::Core::DConfigFile::save |
( |
const QString & |
localPrefix = QString() , |
|
|
QJsonDocument::JsonFormat |
format = QJsonDocument::Indented , |
|
|
bool |
sync = false |
|
) |
| const |
保存缓存的值到磁盘中
- 参数
-
[in] | format | 保存格式 |
[in] | sync | 是否立即刷新 |
- 返回
◆ setValue()
bool Dtk::Core::DConfigFile::setValue |
( |
const QString & |
key, |
|
|
const QVariant & |
value, |
|
|
const QString & |
callerAppid, |
|
|
DConfigCache * |
userCache = nullptr |
|
) |
| |
设置缓存中的值
- 参数
-
[in] | key | 配置项名称 |
[in] | value | 需要设置的值 |
[in] | uid | 设置时的用户id |
[in] | appid | 设置时的应用id |
- 返回
- 为true时表示重新设置了新值,false表示没有设置
◆ supportedVersion()
◆ value()
QVariant Dtk::Core::DConfigFile::value |
( |
const QString & |
key, |
|
|
DConfigCache * |
userCache = nullptr |
|
) |
| const |
该类的文档由以下文件生成: