Skip to content

Commit

Permalink
feat(DSettings): support set default value
Browse files Browse the repository at this point in the history
Change-Id: I83684be7756e5038f55c9fb468195c474259f1e1
  • Loading branch information
Iceyer committed Feb 7, 2018
1 parent 1893cff commit 5fe9bfd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/settings/dsettingsoption.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class DSettingsOptionPrivate
DSettingsOption::DSettingsOption(QObject *parent) :
QObject(parent), d_ptr(new DSettingsOptionPrivate(this))
{

}

DSettingsOption::~DSettingsOption()
Expand Down Expand Up @@ -95,7 +94,7 @@ QVariant DSettingsOption::defaultValue() const
QVariant DSettingsOption::value() const
{
Q_D(const DSettingsOption);
return d->value;
return (d->value.isValid() || d->value.isNull()) ? d->defalutValue : d->value;
}

QVariant DSettingsOption::data(const QString &dataType) const
Expand Down Expand Up @@ -135,6 +134,16 @@ void DSettingsOption::setValue(QVariant value)
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;
}

void DSettingsOption::setData(const QString &dataType, QVariant value)
{
Q_D(DSettingsOption);
Expand Down Expand Up @@ -167,7 +176,6 @@ void DSettingsOptionPrivate::parseJson(const QString &prefixKey, const QJsonObje
defalutValue = option.value("default").toVariant();
hidden = !option.contains("hide") ? false : option.value("hide").toBool();
viewType = option.value("type").toString();
value = defalutValue;

QStringList revserdKeys;
revserdKeys << "key" << "name" << "reset"
Expand Down
1 change: 1 addition & 0 deletions src/settings/dsettingsoption.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class DSettingsOption : public QObject

public Q_SLOTS:
void setValue(QVariant value);
void setDefault(QVariant value);
void setData(const QString &dataType, QVariant value);

private:
Expand Down

0 comments on commit 5fe9bfd

Please sign in to comment.