规范配置文件读写的相关接口的配置文件实现.
更多...
|
enum | Flag { NoOverride = 1 << 0
, Global = 1 << 1
} |
|
enum | Permissions { ReadOnly
, ReadWrite
} |
|
enum | Visibility { Private
, 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 更多...
|
|
DConfigCache * | createUserCache (const uint uid) |
|
DConfigCache * | globalCache () const |
| 返回全局缓存 更多...
|
|
DConfigMeta * | meta () |
| 返回原型对象 更多...
|
|
规范配置文件读写的相关接口的配置文件实现.
\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()
◆ 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()
◆ value()
QVariant Dtk::Core::DConfigFile::value |
( |
const QString & |
key, |
|
|
DConfigCache * |
userCache = nullptr |
|
) |
| const |
该类的文档由以下文件生成: