summaryrefslogtreecommitdiffhomepage
path: root/options/group.hpp
blob: 05ef3b4b5b5ea9d781d9b58fa56137aaf278d1c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#pragma once

#include "export.hpp"
#include "compat/util.hpp"
#include <map>
#include <memory>
#include <QString>
#include <QList>
#include <QVariant>
#include <QSettings>

namespace options {

// snapshot of qsettings group at given time
class OPENTRACK_OPTIONS_EXPORT group final
{
private:
    std::map<QString, QVariant> kvs;
    QString name;
public:
    group(const QString& name);
    void save() const;
    void save_deferred(QSettings& s) const;
    void put(const QString& s, const QVariant& d);
    bool contains(const QString& s) const;
    static QString ini_directory();
    static QString ini_filename();
    static QString ini_pathname();
    static const QStringList ini_list();
    static const std::shared_ptr<QSettings> ini_file();
    bool operator==(const group& other) const;
    bool operator!=(const group& other) const { return !(*this == other); }

    template<typename t>
    t get(const QString& k) const
    {
        auto value = kvs.find(k);
        if (value != kvs.cend())
            return value->second.value<t>();
        return t();
    }
};

}