DSettings::DSettings(QObject *parent) :
- QObject(parent), d_ptr(new DSettingsPrivate(this))
+ QObject(parent), dd_ptr(new DSettingsPrivate(this))
{
}
Q_D(const DSettings);
return d->childGroups.values();
}
-
+/*!
+ * \brief DSettings::group will recurrence find childGroup
+ * \param key
+ * \return
+ */
QPointer<DSettingsGroup> DSettings::group(const QString &key) const
{
Q_D(const DSettings);
- return d->childGroups.value(key);
+ auto childKeylist = key.split(".");
+ if (0 >= childKeylist.length()) {
+ return nullptr;
+ }
+
+ auto mainGroupKey = childKeylist.value(0);
+ if (1 >= childKeylist.length()) {
+ return d->childGroups.value(mainGroupKey);
+ }
+
+ return d->childGroups.value(mainGroupKey)->childGroup(key);
}
QList<QPointer<DSettingsOption> > DSettings::options() const
{
Q_OBJECT
public:
- explicit DSettings(QObject *parent = 0);
+ explicit DSettings(QObject *parent = Q_NULLPTR);
~DSettings();
void setBackend(DSettingsBackend *backend = nullptr);
void parseJson(const QByteArray &json);
void loadValue();
- QScopedPointer<DSettingsPrivate> d_ptr;
- Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), DSettings)
+ QScopedPointer<DSettingsPrivate> dd_ptr;
+ Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettings)
};
DCORE_END_NAMESPACE
};
DSettingsGroup::DSettingsGroup(QObject *parent) :
- QObject(parent), d_ptr(new DSettingsGroupPrivate(this))
+ QObject(parent), dd_ptr(new DSettingsGroupPrivate(this))
{
}
return d->name;
}
+QPointer<DSettingsGroup> DSettingsGroup::childGroup(const QString &key) const
+{
+ Q_D(const DSettingsGroup);
+ return d->childGroups.value(key);
+}
+
QList<QPointer<DSettingsGroup> > DSettingsGroup::childGroups() const
{
Q_D(const DSettingsGroup);
{
Q_OBJECT
public:
- explicit DSettingsGroup(QObject *parent = 0);
+ explicit DSettingsGroup(QObject *parent = Q_NULLPTR);
~DSettingsGroup();
QPointer<DSettingsGroup> parentGroup() const;
QString key() const;
QString name() const;
+ QPointer<DSettingsGroup> childGroup(const QString &key) const;
QList<QPointer<DSettingsGroup> > childGroups() const;
QList<QPointer<DSettingsOption> > childOptions() const;
QList<QPointer<DSettingsOption> > options() const;
private:
void parseJson(const QString &prefixKey, const QJsonObject &group);
- QScopedPointer<DSettingsGroupPrivate> d_ptr;
- Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), DSettingsGroup)
+ QScopedPointer<DSettingsGroupPrivate> dd_ptr;
+ Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsGroup)
};
typedef QPointer<DSettingsGroup> GroupPtr;
};
DSettingsOption::DSettingsOption(QObject *parent) :
- QObject(parent), d_ptr(new DSettingsOptionPrivate(this))
+ QObject(parent), dd_ptr(new DSettingsOptionPrivate(this))
{
}
Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged)
public:
- explicit DSettingsOption(QObject *parent = 0);
+ explicit DSettingsOption(QObject *parent = Q_NULLPTR);
~DSettingsOption();
QPointer<DSettingsGroup> parentGroup() const;
private:
void parseJson(const QString &prefixKey, const QJsonObject &option);
- QScopedPointer<DSettingsOptionPrivate> d_ptr;
- Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), DSettingsOption)
+ QScopedPointer<DSettingsOptionPrivate> dd_ptr;
+ Q_DECLARE_PRIVATE_D(qGetPtrHelper(dd_ptr), DSettingsOption)
};
typedef QPointer<DSettingsOption> OptionPtr;
--- /dev/null
+<RCC>
+ <qresource prefix="/">
+ <file>data/dt-settings.json</file>
+ </qresource>
+</RCC>
--- /dev/null
+{
+ "groups": [
+ {
+ "key": "base",
+ "name": "Basic settings",
+ "groups": [
+ {
+ "key": "theme",
+ "name": "Theme",
+ "options": [
+ {
+ "key": "theme",
+ "type": "checkpicture",
+ "default": 0
+ },
+ {
+ "key": "opticy",
+ "name": "Opticy",
+ "type": "slider",
+ "max": 100,
+ "min": 0,
+ "default": 90
+ }
+ ]
+ },
+ {
+ "key": "font",
+ "name": "Font Style",
+ "options": [
+ {
+ "key": "family",
+ "name": "Font",
+ "type": "combobox",
+ "default": ""
+ },
+ {
+ "key": "size",
+ "name": "Font Size",
+ "type": "spinbutton",
+ "default": 12
+ },
+ {
+ "key": "style",
+ "name": "Font Style",
+ "type": "buttongroup",
+ "items": ["B","/"],
+ "default": 0
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "key": "shortcuts",
+ "name": "Shortcuts",
+ "groups": [
+ {
+ "key": "ternimal",
+ "name": "Ternimal",
+ "options": [
+ {
+ "key": "copy",
+ "name": "Copy",
+ "type": "shortcut",
+ "default": "Ctrl+Alt+C"
+ },
+ {
+ "key": "paste",
+ "name": "Paste",
+ "type": "shortcut",
+ "default": "Ctrl+Alt+V"
+ },
+ {
+ "key": "scroll_up",
+ "name": "Scroll Up",
+ "type": "shortcut",
+ "default": "Alt+."
+ },
+ {
+ "key": "scroll_down",
+ "name": "Scroll down",
+ "type": "shortcut",
+ "default": "Alt+,"
+ }
+ ]
+ },
+ {
+ "key": "workspace",
+ "name": "Workspace",
+ "options": [
+ {
+ "key": "new_window",
+ "name": "New Window",
+ "type": "shortcut",
+ "default": "Ctrl+Shitf+<"
+ },
+ {
+ "key": "next_tab",
+ "name": "Next Tab",
+ "type": "shortcut",
+ "default": "Ctrl+N"
+ },
+ {
+ "key": "prev_up",
+ "name": "Previous Tab",
+ "type": "shortcut",
+ "default": "Ctrl+Shitf+>"
+ },
+ {
+ "key": "close_tab",
+ "name": "Close Tab",
+ "type": "shortcut",
+ "default": "Ctrl+W"
+ }
+ ]
+ }
+ ]
+ },
+ {
+ "key": "advance",
+ "name": "Advance",
+ "groups": [
+ {
+ "key": "cursor",
+ "name": "Cursor",
+ "options": [
+ {
+ "key": "shrap",
+ "name": "Cursor Shrap",
+ "type": "buttongroup",
+ "items": ["█","_","|"],
+ "default": 0
+ },
+ {
+ "key": "blink",
+ "type": "checkbox",
+ "text": "Cursor blink",
+ "default": true
+ },
+ {
+ "key": "radiogroup",
+ "name": " ",
+ "type": "radiogroup",
+ "items": ["Minimize to tray","Exit Deepin Music"],
+ "default": 0
+ }
+ ]
+ },
+ {
+ "key": "encoding",
+ "name": "Default encoding",
+ "options": [
+ {
+ "key": "encoding",
+ "name": "Encoding",
+ "type": "combobox",
+ "default": "utf-8"
+ }
+ ]
+ },
+ {
+ "key": "coustom",
+ "name": "Coustom",
+ "options": [
+ {
+ "key": "coustom_command",
+ "name": "Coustom Command",
+ "type": "lineedit",
+ "default": ""
+ },
+ {
+ "key": "coustom_directory",
+ "name": "Coustom Directory",
+ "type": "lineedit",
+ "default": ""
+ }
+ ]
+ },
+ {
+ "key": "scroll",
+ "name": "Scroll",
+ "options": [
+ {
+ "key": "scroll_bottom",
+ "text": "Scroll Bottom",
+ "type": "checkbox",
+ "default": ""
+ },
+ {
+ "key": "scroll_line_count",
+ "name": "Scroll line count",
+ "type": "spinbutton",
+ "default": 10
+ }
+ ]
+ },
+ {
+ "key": "compatibility",
+ "name": "Compatibility",
+ "options": [
+ {
+ "key": "breakspce_action",
+ "name": "Breakspce Action",
+ "type": "combobox",
+ "default": ""
+ },
+ {
+ "key": "delete_action",
+ "name": "Delete Action",
+ "type": "combobox",
+ "default": ""
+ }
+ ]
+ }
+ ]
+ }
+ ]
+}
#include "singletontester.h"
#include "util/dtimeunitformatter.h"
#include "util/ddisksizeformatter.h"
+#include "settings/dsettings.h"
+#include "settings/dsettingsgroup.h"
+#include "settings/dsettingsoption.h"
DCORE_USE_NAMESPACE
-TestDUtil::TestDUtil()
-{
-
-}
-
void TestDUtil::testLogPath()
{
qApp->setOrganizationName("deepin");
const auto d2 = diskFormatter.formatAs(100000000000, DDiskSizeFormatter::B, DDiskSizeFormatter::T);
Q_ASSERT(qFuzzyCompare(0.09094947017729282, d2));
}
+
+void TestDUtil::testGroups()
+{
+ auto path = ":/data/dt-settings.json";
+ auto settings = DSettings::fromJsonFile(path);
+
+ qDebug() << settings->groupKeys();
+ qDebug() << settings->group("shortcuts");
+ for (auto cg : settings->group("shortcuts")->childGroups()) {
+ qDebug() << cg->key();
+ }
+ qDebug() << settings->group("shortcuts.ternimal");
+ qDebug() << settings->group("shortcuts.ternimal")->options();
+}
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#ifndef DUTILTESTER_H
-#define DUTILTESTER_H
+#pragma once
#include <QObject>
class TestDUtil: public QObject
{
Q_OBJECT
-public:
- TestDUtil();
private Q_SLOTS:
void testLogPath();
void testDiskFormatter();
void testDiskFormatterList();
void testDiskFormatter1024();
+
+ void testGroups();
};
-#endif // DUTILTESTER_H
+
Q_OBJECT
friend class Dtk::Core::DSingleton<Singleton>;
public:
- explicit Singleton(QObject *parent = 0);
+ explicit Singleton(QObject *parent = nullptr);
void test();
};
{
Q_OBJECT
public:
- explicit MultiSingletonTester(QObject *parent = 0);
+ explicit MultiSingletonTester(QObject *parent = nullptr);
void run();
};
INCLUDEPATH += $$PWD/../src
DEPENDPATH += $$PWD/../src
QMAKE_RPATHDIR += $$PWD/../src
+
+RESOURCES += \
+ data.qrc