+<a name="2.0.9.8"></a>
+## 2.0.9.8 (2018-11-09)
+
+
+#### Bug Fixes
+
+* can't get correct disk size in some case ([20a12b62](https://github.com/linuxdeepin/dtkcore/commit/20a12b622ea7b01f0616c15a8af85e31fc2d36cb))
+
+
+
<a name="2.0.9.5"></a>
## 2.0.9.5 (2018-10-26)
#include <QStorageInfo>
#include <QProcess>
#include <QDebug>
+#include <QJsonDocument>
+#include <QJsonArray>
#ifdef Q_OS_LINUX
#include <sys/sysinfo.h>
memoryTotalSize = get_phys_pages() * sysconf(_SC_PAGESIZE);
- const QString &root_part = QStorageInfo::root().device();
-
- if (root_part.isEmpty())
- return;
-
+ // Getting Disk Size
+ const QString &deviceName = QStorageInfo::root().device();
QProcess lsblk;
- lsblk.start("lsblk", {"-prno", "pkname", root_part}, QIODevice::ReadOnly);
-
- if (!lsblk.waitForFinished())
- return;
-
- const QString &root_disk = QString::fromLatin1(lsblk.readAllStandardOutput().trimmed());
+ lsblk.start("lsblk", {"-Jlpb", "-oNAME,KNAME,PKNAME,SIZE"}, QIODevice::ReadOnly);
- lsblk.start("lsblk", {"-prnbdo", "size", root_disk}, QIODevice::ReadOnly);
-
- if (!lsblk.waitForFinished())
+ if (!lsblk.waitForFinished()) {
return;
+ }
- const QByteArray &disk_size = lsblk.readAllStandardOutput().trimmed();
- diskSize = disk_size.toLongLong();
+ const QByteArray &diskStatusJson = lsblk.readAllStandardOutput();
+ QJsonDocument diskStatus = QJsonDocument::fromJson(diskStatusJson);
+ QJsonValue diskStatusJsonValue = diskStatus["blockdevices"];
+ QMap<QString, QPair<QString, qulonglong>> deviceParentAndSizeMap;
+
+ if (!diskStatusJsonValue.isUndefined()) {
+ QJsonArray diskStatusArray = diskStatusJsonValue.toArray();
+ QString keyName;
+ for (const QJsonValue &oneValue : diskStatusArray) {
+ if (keyName.isNull() && deviceName == oneValue["name"].toString()) {
+ keyName = oneValue["kname"].toString();
+ }
+ deviceParentAndSizeMap[oneValue["kname"].toString()] = QPair<QString, qulonglong>(oneValue["pkname"].toString(), oneValue["size"].toString().toULongLong());
+ }
+ while (!deviceParentAndSizeMap[keyName].first.isNull()) {
+ keyName = deviceParentAndSizeMap[keyName].first;
+ }
+ diskSize = deviceParentAndSizeMap[keyName].second;
+ }
#endif
}
#include "dpathbuf.h"
-Dtk::Core::DPathBuf::DPathBuf(const QString &path)
+/*!
+ * \~english \class Dtk::Core::DPathBuf
+ * \brief Dtk::Core::DPathBuf cat path friendly and supoort multiplatform.
+ */
+
+/*!
+ * \~chinese \class Dtk::Core::DPathBuf
+ * \brief Dtk::Core::DPathBuf是一个用于跨平台拼接路径的辅助类。
+ * 它能够方便的写出链式结构的路径拼接代码。
+```
+DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
+logPath = logPath / ".cache" / "deepin" / "deepin-test-dtk" / "deepin-test-dtk.log";
+```
+ */
+
+
+DCORE_BEGIN_NAMESPACE
+
+/*!
+ * \brief Create Dtk::Core::DPathBuf from string.
+ * \param path
+ */
+DPathBuf::DPathBuf(const QString &path)
{
m_path = QDir(path).absolutePath();
}
+
+DCORE_END_NAMESPACE
public:
DPathBuf(const QString &path);
+ /*!
+ * \brief join path with operator /
+ * \param p is subpath
+ * \return a new DPathBuf with subpath p
+ */
DPathBuf operator/(const QString &p) const
{
return DPathBuf(m_path + "/" + p);
}
+ /*!
+ * \brief join path to self with operator /=
+ * \param p is subpath to join
+ * \return self object
+ */
DPathBuf &operator/=(const QString &p)
{
return join(p);
}
+ /*!
+ * \brief join path with operator /
+ * \param p is subpath
+ * \return a new DPathBuf with subpath p
+ * \sa Dtk::Core::DPathBuf::operator/(const QString &p) const
+ */
DPathBuf operator/(const char *p) const
{
return operator /(QString(p));
}
+ /*!
+ * \brief join path to self with operator /=
+ * \param p is subpath to join
+ * \return self object
+ * \sa Dtk::Core::DPathBuf::operator/=(const QString &p)
+ */
DPathBuf &operator/=(const char *p)
{
return operator /=(QString(p));
}
+ /*!
+ * \brief join add subpath p to self
+ * \param p is subpath to join
+ * \return slef object with subpath joined
+ */
DPathBuf &join(const QString &p)
{
m_path += "/" + p;
return *this;
}
+ /*!
+ * \brief toString export native separators format string.
+ * \return string with native separators
+ */
QString toString() const
{
return QDir::toNativeSeparators(m_path);
DCORE_BEGIN_NAMESPACE
-
-class DSnapStandardPaths
+class DSnapStandardPathsPrivate
{
public:
inline static QString writableLocation(QStandardPaths::StandardLocation /*type*/)
}
private:
- DSnapStandardPaths();
- ~DSnapStandardPaths();
- Q_DISABLE_COPY(DSnapStandardPaths)
+ DSnapStandardPathsPrivate();
+ ~DSnapStandardPathsPrivate();
+ Q_DISABLE_COPY(DSnapStandardPathsPrivate)
};
+/*!
+ * \~chinese \class Dtk::Core::DStandardPaths
+ * \brief DStandardPaths提供兼容Snap/Dtk标准的路径模式。DStandardPaths实现了Qt的QStandardPaths主要接口。
+ * \sa QStandardPaths
+ *
+ * \enum DStandardPaths::Mode
+ * \brief DStandardPaths支持的路径产生模式。
+ * \var DStandardPaths::Mode DStandardPaths::Auto
+ * \brief 和Qt标准的行为表现一致。
+ * \var DStandardPaths::Mode DStandardPaths::Snap
+ * \brief 读取SNAP相关的环境变量,支持将配置存储在SNAP对应目录。
+ * \var DStandardPaths::Mode DStandardPaths::Test
+ * \brief 和Qt标准的行为表现一致,但是会开启测试模式,参考QStandardPaths::setTestModeEnabled。
+ */
+
+
static DStandardPaths::Mode s_mode = DStandardPaths::Auto;
QString DStandardPaths::writableLocation(QStandardPaths::StandardLocation type)
case Test:
return QStandardPaths::writableLocation(type);
case Snap:
- return DSnapStandardPaths::writableLocation(type);
+ return DSnapStandardPathsPrivate::writableLocation(type);
}
return QStandardPaths::writableLocation(type);
}
case Test:
return QStandardPaths::standardLocations(type);
case Snap:
- return DSnapStandardPaths::standardLocations(type);
+ return DSnapStandardPathsPrivate::standardLocations(type);
}
return QStandardPaths::standardLocations(type);
}
DCORE_BEGIN_NAMESPACE
-
QString unqtifyName(const QString &name)
{
QString ret;
Q_DECLARE_PUBLIC(GSettingsBackend)
};
+/*!
+ * \class GSettingsBackend
+ * \brief Storage backend of DSettings use gsettings.
+ *
+ * You should generate gsetting schema with /usr/lib/dtk2/dtk-settings.
+ *
+ * You can find this tool from libdtkcore-bin. use /usr/lib/dtk2/dtk-settings -h for help.
+ */
+
GSettingsBackend::GSettingsBackend(DSettings *settings, QObject *parent) :
DSettingsBackend(parent), d_ptr(new GSettingsBackendPrivate(this))
{
}
+/*!
+ * \brief List all gsettings keys.
+ * \return
+ */
QStringList GSettingsBackend::keys() const
{
Q_D(const GSettingsBackend);
return d->gsettings->keys();
}
+/*!
+ * \brief Get value of key.
+ * \return
+ */
QVariant GSettingsBackend::getOption(const QString &key) const
{
Q_D(const GSettingsBackend);
return d->gsettings->get(qtifyName(key));
}
+/*!
+ * \brief Set value to gsettings
+ * \return
+ */
void GSettingsBackend::doSetOption(const QString &key, const QVariant &value)
{
Q_D(GSettingsBackend);
}
}
+/*!
+ * \brief Trigger DSettings to sync option to storage.
+ */
void GSettingsBackend::doSync()
{
Q_EMIT sync();
{
Q_OBJECT
public:
- explicit GSettingsBackend(DSettings *settings, QObject *parent = 0);
+ explicit GSettingsBackend(DSettings *settings, QObject *parent = nullptr);
~GSettingsBackend();
virtual QStringList keys() const Q_DECL_OVERRIDE;
Q_DECLARE_PUBLIC(QSettingBackend)
};
+/*!
+ * \class QSettingBackend
+ * \brief Storage DSetttings to an QSettings
+ */
+
+/*!
+ * \brief Save data to filepath with QSettings::NativeFormat format.
+ * \param filepath is path to storage data.
+ * \param parent
+ */
QSettingBackend::QSettingBackend(const QString &filepath, QObject *parent) :
DSettingsBackend(parent), d_ptr(new QSettingBackendPrivate(this))
{
}
+/*!
+ * \brief List all keys of QSettings
+ * \return
+ */
QStringList QSettingBackend::keys() const
{
Q_D(const QSettingBackend);
return d->settings->childGroups();
}
+/*!
+ * \brief Get value of key from QSettings
+ * \param key
+ * \return
+ */
QVariant QSettingBackend::getOption(const QString &key) const
{
Q_D(const QSettingBackend);
return value;
}
+/*!
+ * \brief Set value of key to QSettings
+ * \param key
+ * \param value
+ */
void QSettingBackend::doSetOption(const QString &key, const QVariant &value)
{
Q_D(QSettingBackend);
d->writeLock.unlock();
}
+/*!
+ * \brief Trigger DSettings to save option value to QSettings
+ */
void QSettingBackend::doSync()
{
Q_D(QSettingBackend);
};
+/*!
+ * \~english \class DSettingsBackend
+ * \brief DSettingsBackend is interface of DSettings storage class.
+ *
+ * Simaple example:
+
+```json
+{
+ "groups": [{
+ "key": "base",
+ "name": "Basic settings",
+ "groups": [{
+ "key": "open_action",
+ "name": "Open Action",
+ "options": [{
+ "key": "alway_open_on_new",
+ "type": "checkbox",
+ "text": "Always Open On New Windows",
+ "default": true
+ },
+ {
+ "key": "open_file_action",
+ "name": "Open File:",
+ "type": "combobox",
+ "default": ""
+ }
+ ]
+ },
+ {
+ "key": "new_tab_windows",
+ "name": "New Tab & Window",
+ "options": [{
+ "key": "new_window_path",
+ "name": "New Window Open:",
+ "type": "combobox",
+ "default": ""
+ },
+ {
+ "key": "new_tab_path",
+ "name": "New Tab Open:",
+ "type": "combobox",
+ "default": ""
+ }
+ ]
+ }
+ ]
+ }]
+}
+```
+
+ * How to read/write key and value:
+
+```c++
+ // init a storage backend
+ QTemporaryFile tmpFile;
+ tmpFile.open();
+ auto backend = new Dtk::Core::QSettingBackend(tmpFile.fileName());
+
+ // read settings from json
+ auto settings = Dtk::Core::DSettings::fromJsonFile(":/resources/data/dfm-settings.json");
+ settings->setBackend(backend);
+
+ // read value
+ auto opt = settings->option("base.new_tab_windows.new_window_path");
+ qDebug() << opt->value();
+
+ // modify value
+ opt->setValue("Test")
+ qDebug() << opt->value();
+```
+ * \sa Dtk::Core::DSettingsOption
+ * \sa Dtk::Core::DSettingsGroup
+ * \sa Dtk::Core::DSettingsBackend
+ * \sa Dtk::Widget::DSettingsWidgetFactory
+ * \sa Dtk::Widget::DSettingsDialog
+ */
+
+
+/*!
+ * \~english \class DSettings
+ * \brief DSettings support base config storage and ui create tool for dtk applications.
+ * \sa Dtk::Core::DSettings
+ * \sa Dtk::Core::DSettingsBackend
+ *
+ * \fn virtual QStringList DSettingsBackend::keys() const = 0;
+ * \brief return all key of storage.
+ *
+ * \fn virtual QVariant DSettingsBackend::getOption(const QString &key) const = 0;
+ * \brief get value by key.
+ *
+ * \fn virtual void DSettingsBackend::doSync() = 0;
+ * \brief do the real sync action.
+ *
+ * \fn virtual void DSettingsBackend::doSetOption(const QString &key, const QVariant &value) = 0;
+ * \brief write key/value to storage.
+ *
+ * \fn void DSettingsBackend::optionChanged(const QString &key, const QVariant &value);
+ * \brief emited when option value changed.
+ *
+ * \fn void DSettingsBackend::sync();
+ * \brief private signal, please do not use it.
+ *
+ * \fn void DSettingsBackend::setOption(const QString &key, const QVariant &value);
+ * \brief private signal, please do not use it.
+ */
+
+/*!
+ * \~chinese \class DSettingsBackend
+ * \brief DSettingsBackend是一个纯虚类, 用来描述DSettings的存储接口。
+ * \sa Dtk::Core::DSettings
+ * \sa Dtk::Core::DSettingsBackend
+ *
+ * \fn virtual QStringList DSettingsBackend::keys() const = 0;
+ * \brief 返回全部键值。
+ *
+ * \fn virtual QVariant DSettingsBackend::getOption(const QString &key) const = 0;
+ * \brief 获取key对应的值。
+ *
+ * \fn virtual void DSettingsBackend::doSync() = 0;
+ * \brief 开始进行同步。
+ *
+ * \fn virtual void DSettingsBackend::doSetOption(const QString &key, const QVariant &value) = 0;
+ * \brief 设置key对应的值,并使用存储后端进行存储。
+ *
+ * \fn void DSettingsBackend::optionChanged(const QString &key, const QVariant &value);
+ * \brief DSettingsOption的值发生变化时发出的信号。
+ *
+ * \fn void DSettingsBackend::sync();
+ * \brief 私有信号,请勿使用。
+ *
+ * \fn void DSettingsBackend::setOption(const QString &key, const QVariant &value);
+ * \brief 私有信号,请勿使用。
+ */
+
+
+/*!
+ * \~chinese \class DSettings
+ * \brief DSettings是设计上为Dtk的应用程序提供统一的配置存储以及界面生成工具的基础库。
+ * DSetting使用json作为应用配置程序的描述文件。简单来说,应用查询的配置分为组/键值二个基础层级,
+ * 对于一个标准的Dtk配置控件,一般只包含组/子组/键值三个层级,对于超过三个层级的键值,可以通过
+ * DSettings的API接口进行读取和写入,但是不能在标准的DSettingsDialogs上显示出来。
+ *
+ * 一个简单的配置文件如下:
+```json
+{
+ "groups": [{
+ "key": "base",
+ "name": "Basic settings",
+ "groups": [{
+ "key": "open_action",
+ "name": "Open Action",
+ "options": [{
+ "key": "alway_open_on_new",
+ "type": "checkbox",
+ "text": "Always Open On New Windows",
+ "default": true
+ },
+ {
+ "key": "open_file_action",
+ "name": "Open File:",
+ "type": "combobox",
+ "default": ""
+ }
+ ]
+ },
+ {
+ "key": "new_tab_windows",
+ "name": "New Tab & Window",
+ "options": [{
+ "key": "new_window_path",
+ "name": "New Window Open:",
+ "type": "combobox",
+ "default": ""
+ },
+ {
+ "key": "new_tab_path",
+ "name": "New Tab Open:",
+ "type": "combobox",
+ "default": ""
+ }
+ ]
+ }
+ ]
+ }]
+}
+```
+
+ * 改组中包含一个base的root组,两个子组: open_action/new_tab_windows,每个子组有包含若干选项。
+ * 对于"New Window Open:"这个配置,其完整的访问id为base.new_tab_windows.new_window_path。
+ * 读取/设置其值的示例如下:
+
+```c++
+ // 初始化一个存储后端
+ QTemporaryFile tmpFile;
+ tmpFile.open();
+ auto backend = new Dtk::Core::QSettingBackend(tmpFile.fileName());
+
+ // 从json中初始化配置
+ auto settings = Dtk::Core::DSettings::fromJsonFile(":/resources/data/dfm-settings.json");
+ settings->setBackend(backend);
+
+ // 读取配置
+ auto opt = settings->option("base.new_tab_windows.new_window_path");
+ qDebug() << opt->value();
+
+ // 修改配置
+ opt->setValue("Test")
+ qDebug() << opt->value();
+```
+ * \sa Dtk::Core::DSettingsOption
+ * \sa Dtk::Core::DSettingsGroup
+ * \sa Dtk::Core::DSettingsBackend
+ * \sa Dtk::Widget::DSettingsWidgetFactory
+ * \sa Dtk::Widget::DSettingsDialog
+ */
+
DSettings::DSettings(QObject *parent) :
QObject(parent), dd_ptr(new DSettingsPrivate(this))
{
{
Q_OBJECT
public:
- explicit DSettingsBackend(QObject *parent = 0): QObject(parent)
+ explicit DSettingsBackend(QObject *parent = Q_NULLPTR): QObject(parent)
{
connect(this, &DSettingsBackend::sync, this, &DSettingsBackend::doSync, Qt::QueuedConnection);
connect(this, &DSettingsBackend::setOption, this, &DSettingsBackend::doSetOption, Qt::QueuedConnection);
Q_DECLARE_PUBLIC(DSettingsGroup)
};
+/*!
+ * \class DSettingsGroup
+ * \brief A group of DSettingsOption and DSettingsGroup.
+ * DSettingsGroup can contain a lost option and subgroup.
+ */
+
DSettingsGroup::DSettingsGroup(QObject *parent) :
QObject(parent), dd_ptr(new DSettingsGroupPrivate(this))
{
{
}
-
+/*!
+ * \brief Get direct parent group of this group.
+ * \return
+ */
QPointer<DSettingsGroup> DSettingsGroup::parentGroup() const
{
Q_D(const DSettingsGroup);
return d->parent;
}
+/*!
+ * \brief Change the direct parent group of this group.
+ * \param parentGroup
+ */
void DSettingsGroup::setParentGroup(QPointer<DSettingsGroup> parentGroup)
{
Q_D(DSettingsGroup);
d->parent = parentGroup;
}
+/*!
+ * \brief Return the full key of this group, include all parent.
+ * \return
+ */
QString DSettingsGroup::key() const
{
Q_D(const DSettingsGroup);
return d->key;
}
+/*!
+ * \brief Get display name of this group, it may be translated.
+ * \return
+ */
QString DSettingsGroup::name() const
{
Q_D(const DSettingsGroup);
return d->name;
}
+/*!
+ * \brief Check this group will show on DSettings dialog.
+ * \return true if group not bind to ui element.
+ */
bool DSettingsGroup::isHidden() const
{
Q_D(const DSettingsGroup);
return d->hide;
}
+/*!
+ * \brief Get the child group of groupKey
+ * \param groupKey is child group key
+ * \return
+ */
QPointer<DSettingsGroup> DSettingsGroup::childGroup(const QString &groupKey) const
{
Q_D(const DSettingsGroup);
return d->childGroups.value(groupKey);
}
+/*!
+ * \brief Get the child option of key
+ * \param key is child option key
+ * \return
+ */
QPointer<DSettingsOption> DSettingsGroup::option(const QString &key) const
{
Q_D(const DSettingsGroup);
return d->childOptions.value(key);
}
+/*!
+ * \brief Enum all direct child group of this group
+ * \return
+ */
QList<QPointer<DSettingsGroup> > DSettingsGroup::childGroups() const
{
Q_D(const DSettingsGroup);
return grouplist;
}
+/*!
+ * \brief Enum all direct child option with the raw order in json description file.
+ * \return
+ */
QList<QPointer<DSettingsOption> > DSettingsGroup::childOptions() const
{
Q_D(const DSettingsGroup);
return optionlist;
}
+/*!
+ * \brief Enum all direct child option of this group.
+ * \return
+ */
QList<QPointer<DSettingsOption> > DSettingsGroup::options() const
{
Q_D(const DSettingsGroup);
return d->options.values();
}
+/*!
+ * \brief Convert QJsonObject to DSettingsGroup.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \sa QPointer<DSettingsOption> Dtk::Core::DSettingsGroup::parseJson(const QString &prefixKey, const QJsonObject &json)
+ */
QPointer<DSettingsGroup> DSettingsGroup::fromJson(const QString &prefixKey, const QJsonObject &group)
{
auto groupPtr = QPointer<DSettingsGroup>(new DSettingsGroup);
return groupPtr;
}
+/*!
+ * \brief Parse QJsonObject to DSettingsGroup.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \sa QPointer<DSettingsOption> Dtk::Core::DSettingsGroup::fromJson(const QString &prefixKey, const QJsonObject &json)
+ */
void DSettingsGroup::parseJson(const QString &prefixKey, const QJsonObject &group)
{
Q_D(DSettingsGroup);
QList<QPointer<DSettingsOption> > options() const;
static QPointer<DSettingsGroup> fromJson(const QString &prefixKey, const QJsonObject &group);
-Q_SIGNALS:
-
-public Q_SLOTS:
private:
void parseJson(const QString &prefixKey, const QJsonObject &group);
Q_DECLARE_PUBLIC(DSettingsOption)
};
+/*!
+ * \class DSettingsOption
+ * \brief DSettingsOption is the base key/value item of DSettings.
+ *
+ * \fn void DSettingsOption::valueChanged(QVariant value);
+ * \brief Emit when option value change.
+ *
+ * \fn void DSettingsOption::dataChanged(const QString &dataType, QVariant value);
+ * \brief Emit when option data change.
+ *
+ *
+
+ * \property DSettingsOption::value
+ * \brief Current value of this option.
+ */
+
DSettingsOption::DSettingsOption(QObject *parent) :
QObject(parent), dd_ptr(new DSettingsOptionPrivate(this))
{
}
+/*!
+ * \brief Get direct parent group of this option.
+ * \return
+ */
QPointer<DSettingsGroup> DSettingsOption::parentGroup() const
{
Q_D(const DSettingsOption);
return d->parent;
}
+/*!
+ * \brief Change the direct parent group of this option.
+ * \param parentGroup
+ */
void DSettingsOption::setParentGroup(QPointer<DSettingsGroup> parentGroup)
{
Q_D(DSettingsOption);
d->parent = parentGroup;
}
+/*!
+ * \brief Return the full key of this option, include all parent.
+ * \return
+ */
QString DSettingsOption::key() const
{
Q_D(const DSettingsOption);
return d->key;
}
+/*!
+ * \brief Get display name of the option, it may be translated.
+ * \return
+ */
QString DSettingsOption::name() const
{
Q_D(const DSettingsOption);
return d->name;
}
+/*!
+ * \brief Check this option can be reset to default value. if false, reset action will not take effect.
+ * \return true if can be reset.
+ * \sa Dtk::Core::DSettings::reset
+ */
bool DSettingsOption::canReset() const
{
Q_D(const DSettingsOption);
return d->canReset;
}
+/*!
+ * \brief Default value of this option, must config in this json desciption file.
+ * \return
+ */
QVariant DSettingsOption::defaultValue() const
{
Q_D(const DSettingsOption);
return d->defalutValue;
}
+/*!
+ * \brief Get current value of option.
+ * \return
+ */
QVariant DSettingsOption::value() const
{
Q_D(const DSettingsOption);
return (!d->value.isValid() || d->value.isNull()) ? d->defalutValue : d->value;
}
+/*!
+ * \brief Custom data of option, like QObject::property.
+ * \param dataType
+ * \return
+ * \sa QObject::property
+ * \sa Dtk::Core::DSettingsOption::setData
+ */
QVariant DSettingsOption::data(const QString &dataType) const
{
Q_D(const DSettingsOption);
return d->datas.value(dataType);
}
+/*!
+ * \brief UI widget type of this option
+ * \return
+ * \sa Dtk::Widget::DSettingsWidgetFactory
+ */
QString DSettingsOption::viewType() const
{
Q_D(const DSettingsOption);
return d->viewType;
}
+/*!
+ * \brief Check this option will show on DSettings dialog.
+ * \return true if option not bind to ui element.
+ */
bool DSettingsOption::isHidden() const
{
Q_D(const DSettingsOption);
return d->hidden;
}
-QPointer<DSettingsOption> DSettingsOption::fromJson(const QString &prefixKey, const QJsonObject &group)
+/*!
+ * \brief Convert QJsonObject to DSettingsOption.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \return
+ */
+QPointer<DSettingsOption> DSettingsOption::fromJson(const QString &prefixKey, const QJsonObject &json)
{
auto optionPtr = QPointer<DSettingsOption>(new DSettingsOption);
- optionPtr->parseJson(prefixKey, group);
+ optionPtr->parseJson(prefixKey, json);
return optionPtr;
}
+/*!
+ * \brief Set current value of option
+ * \param value
+ */
void DSettingsOption::setValue(QVariant value)
{
Q_D(DSettingsOption);
Q_EMIT valueChanged(value);
}
-//!
-//! \brief DSettingsOption::setDefault will override default value of json
-//! \param value
-//!
-// void DSettingsOption::setDefault(QVariant value)
-// {
-// Q_D(DSettingsOption);
-// d->defalutValue = value;
-// }
-
+///*!
+// * \brief Override default value of json
+// * \param value
+// */
+//void DSettingsOption::setDefault(QVariant value)
+//{
+// Q_D(DSettingsOption);
+// d->defalutValue = value;
+//}
+
+/*!
+ * \brief Set custom data
+ * \param dataType is data id, just a unique string.
+ * \param value of the data id.
+ * \sa Dtk::Core::DSettingsOption::data
+ */
void DSettingsOption::setData(const QString &dataType, QVariant value)
{
Q_D(DSettingsOption);
Q_EMIT dataChanged(dataType, value);
}
+/*!
+ * \brief Parse QJsonObject to DSettingsOption.
+ * \param prefixKey instead parse prefix key from parent.
+ * \param json is an QJsonObejct instance.
+ * \sa QPointer<DSettingsOption> Dtk::Core::DSettingsOption::fromJson(const QString &prefixKey, const QJsonObject &json)
+ */
void DSettingsOption::parseJson(const QString &prefixKey, const QJsonObject &option)
{
Q_D(DSettingsOption);
QString viewType() const;
bool isHidden() const;
- static QPointer<DSettingsOption> fromJson(const QString &prefixKey, const QJsonObject &group);
+ static QPointer<DSettingsOption> fromJson(const QString &prefixKey, const QJsonObject &json);
Q_SIGNALS:
void valueChanged(QVariant value);
void dataChanged(const QString &dataType, QVariant value);
DCORE_BEGIN_NAMESPACE
+/*!
+ * \~chinese \class DAbstractUnitFormatter
+ * \~chinese \brief DAbstractUnitFormatter 类是对拥有相同类型数据管理的接口类
+ * 接口定义了最大值、最小值、转换单位和单位对应的字符串。
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitMax
+ * \~chinese \brief 返回列表中最大的单位
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitMin
+ * \~chinese \brief 返回列表中最小的单位
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitConvertRate
+ * \~chinese \brief 返回当前设置的转换单位
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitValueMax
+ * \~chinese \brief 返回列表中根据当前设置的转换单位的最大值
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitValueMin
+ * \~chinese \brief 返回列表中根据当前设置的转换单位的最小值
+ *
+ * \~chinese \fn DAbstractUnitFormatter::unitStr
+ * \~chinese \brief 传入id,返回列表中对应的字符串
+ */
+
+/*!
+ * \~chinese \brief DAbstractUnitFormatter 的构造函数
+ *
+ */
DAbstractUnitFormatter::DAbstractUnitFormatter()
{
}
+/*!
+ * \~chinese \brief DAbstractUnitFormatter 的析构函数
+ *
+ */
DAbstractUnitFormatter::~DAbstractUnitFormatter()
{
}
+/*!
+ * \~chinese \brief 将传入的值从当前转换单位转换到目标单位上,返回转换过的值
+ * 如果当前转换单位小于目标单位,值会被缩小,反之会放大,当前转换单位也会被缩小和放大,直至当前转换单位等于目标单位。
+ *
+ * @param value 原始数值
+ * @param currentUnit 当前的转换比率
+ * @param targetUnit 目标的转换比率
+ * @return qreal 返回转换过的值
+ */
qreal DAbstractUnitFormatter::formatAs(qreal value, int currentUnit, const int targetUnit) const
{
while (currentUnit < targetUnit)
return value;
}
+/*!
+ * \~chinese \brief 将值转换到最合适的单位上
+ *
+ * 如果值大于 unitMin() 或者小于 unitMax() ,会尽量保证值被转换到接近最小值的合适单位上。
+ *
+ * @param value 原始数值
+ * @param unit 当前的转换单位
+ * @return QPair<qreal, int> 转换过的数值和转化单位
+ */
QPair<qreal, int> DAbstractUnitFormatter::format(const qreal value, const int unit) const
{
// can convert to smaller unit
return QPair<qreal, int>(value, unit);
}
+/*!
+ * \~chinese \brief 是 format() ,但是包含了完整的转换数据
+ *
+ * @param value
+ * @param unit
+ * @return QList<QPair<qreal, int> >
+ */
QList<QPair<qreal, int> > DAbstractUnitFormatter::formatAsUnitList(const qreal value, int unit) const
{
if (qFuzzyIsNull(value))
DCORE_BEGIN_NAMESPACE
+/*!
+ * \~chinese \class DDiskSizeFormatter
+ *
+ * \~chinese \brief DDiskSizeFormatter 是用来获取磁盘容量单位的类, 通过枚举值
+ * 获取不同类型磁盘容量的单位
+ *
+ * \~chinese \enum DDiskSizeFormatter::DiskUnits 磁盘容量单位的枚举
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::B
+ * \~chinese \brief 字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::K
+ * \~chinese \brief 千字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::M
+ * \~chinese \brief 兆字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::G
+ * \~chinese \brief 吉字节
+ * \~chinese \var DDiskSizeFormatter::DiskUnits DDiskSizeFormatter::T
+ * \~chinese \brief 太字节
+ *
+ * \~chinese \fn DDiskSizeFormatter::unitMax
+ * \~chinese \brief 返回最大磁盘容量单位的枚举
+ *
+ * \~chinese \fn DDiskSizeFormatter::unitMin
+ * \~chinese \brief 返回最小磁盘容量单位的枚举
+ *
+ * \~chinese \fn DDiskSizeFormatter::unitConvertRate
+ * \~chinese \brief 返回当前的单位转换比率
+ */
+
+/*!
+ * \~chinese \brief DDiskSizeFormatter的构造函数
+ *
+ */
DDiskSizeFormatter::DDiskSizeFormatter()
: DAbstractUnitFormatter()
{
}
+/*!
+ * \~chinese \brief 根据枚举返回对应单位的字符串
+ *
+ * @param unitId DDiskSizeFormatter::DiskUnits 的枚举值
+ * @return QString 对应单位的字符串
+ */
QString DDiskSizeFormatter::unitStr(int unitId) const
{
switch (unitId)
return QString();
}
+/*!
+ * \~chinese \brief 设置当前的单位转换比率
+ *
+ * @param rate 转换比率
+ * @return DDiskSizeFormatter 返回 DDiskSizeFormatter 对象
+ */
DDiskSizeFormatter DDiskSizeFormatter::rate(int rate)
{
m_rate = rate;
DCORE_BEGIN_NAMESPACE
+/*!
+ * \~chinese \class DTimeUnitFormatter
+ *
+ * \~chinese \brief DTimeUnitFormatter是用来获取时间单位的类, 通过枚举值
+ * 获取不同类型时间单位的进制
+ *
+ * \~chinese \enum DTimeUnitFormatter::TimeUnits 时间单位的枚举
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Seconds
+ * \~chinese \brief 返回分钟单位的进制
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Minute
+ * \~chinese \brief 返回秒单位的进制
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Hour
+ * \~chinese \brief 返回小时单位的进制
+ * \~chinese \var DTimeUnitFormatter::TimeUnits DTimeUnitFormatter::Day
+ * \~chinese \brief 返回天单位的进制
+ *
+ * \~chinese \fn DTimeUnitFormatter::unitMax
+ * \~chinese \brief 返回最大时间单位的枚举
+ *
+ * \~chinese \fn DTimeUnitFormatter::unitMin
+ * \~chinese \brief 返回最小时间单位的枚举
+ */
+
+/*!
+ * \~chinese \brief DTimeUnitFormatter的构造函数
+ *
+ */
DTimeUnitFormatter::DTimeUnitFormatter()
: DAbstractUnitFormatter()
{
}
+/*!
+ * \~chinese \brief 根据枚举返回对应的单位进制
+ *
+ * @param unitId DTimeUnitFormatter::TimeUnits 的枚举值
+ * @return uint 对应的单位进制
+ */
uint DTimeUnitFormatter::unitConvertRate(int unitId) const
{
switch (unitId)
return 0;
}
+/*!
+ * \~chinese \brief 根据枚举返回对应单位的缩写
+ *
+ * @param unitId DTimeUnitFormatter::TimeUnits 的枚举值
+ * @return QString 对应单位的缩写
+ */
QString DTimeUnitFormatter::unitStr(int unitId) const
{
switch (unitId)
qApp->setApplicationName("deepin-test-dtk");
DPathBuf logPath(QStandardPaths::standardLocations(QStandardPaths::HomeLocation).first());
- logPath = logPath / ".cache/deepin/deepin-test-dtk/deepin-test-dtk.log";
+ logPath = logPath / ".cache" / "deepin" / "deepin-test-dtk" / "deepin-test-dtk.log";
QCOMPARE(DLogManager::getlogFilePath(), logPath.toString());
}
{
// basic method call
DDBusSender()
- .service("com.deepin.dde.ControlCenter")
- .interface("com.deepin.dde.ControlCenter")
- .path("/com/deepin/dde/ControlCenter")
- .method("ShowPage")
- .arg(QString("update"))
- .arg(QString("available-updates"))
- .call();
+ .service("com.deepin.dde.ControlCenter")
+ .interface("com.deepin.dde.ControlCenter")
+ .path("/com/deepin/dde/ControlCenter")
+ .method("ShowPage")
+ .arg(QString("update"))
+ .arg(QString("available-updates"))
+ .call();
// property set
QDBusPendingReply<> r1 = DDBusSender()
- .service("com.deepin.dde.daemon.Dock")
- .interface("com.deepin.dde.daemon.Dock")
- .path("/com/deepin/dde/daemon/Dock")
- .property("DisplayMode")
- .set(1); // set to efficient mode
+ .service("com.deepin.dde.daemon.Dock")
+ .interface("com.deepin.dde.daemon.Dock")
+ .path("/com/deepin/dde/daemon/Dock")
+ .property("DisplayMode")
+ .set(1); // set to efficient mode
// property get
QDBusPendingReply<QVariant> r2 = DDBusSender()
- .service("com.deepin.dde.daemon.Dock")
- .interface("com.deepin.dde.daemon.Dock")
- .path("/com/deepin/dde/daemon/Dock")
- .property("DisplayMode")
- .get(); // read mode
+ .service("com.deepin.dde.daemon.Dock")
+ .interface("com.deepin.dde.daemon.Dock")
+ .path("/com/deepin/dde/daemon/Dock")
+ .property("DisplayMode")
+ .get(); // read mode
- if (!r2.isError() && !r1.isError())
+ if (!r2.isError() && !r1.isError()) {
Q_ASSERT(r2.value().toInt() == 1);
+ }
// complex type property get
QDBusPendingReply<QVariant> r3 = DDBusSender()
- .service("com.deepin.dde.ControlCenter")
- .interface("com.deepin.dde.ControlCenter")
- .path("/com/deepin/dde/ControlCenter")
- .property("Rect")
- .get();
+ .service("com.deepin.dde.ControlCenter")
+ .interface("com.deepin.dde.ControlCenter")
+ .path("/com/deepin/dde/ControlCenter")
+ .property("Rect")
+ .get();
QVariant variant = r3.value();
const QDBusArgument v = variant.value<QDBusArgument>();