Overte C++ Documentation
SettingInterface.h
1 //
2 // SettingInterface.h
3 //
4 //
5 // Created by Clement on 2/2/15.
6 // Copyright 2015 High Fidelity, Inc.
7 // Copyright 2022 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_SettingInterface_h
14 #define hifi_SettingInterface_h
15 
16 #include <memory>
17 #include <QtCore/QWeakPointer>
18 #include <QtCore/QString>
19 #include <QtCore/QVariant>
20 #include <QLoggingCategory>
21 
22 Q_DECLARE_LOGGING_CATEGORY(settings_interface)
23 
24 namespace Setting {
25  class Manager;
26 
27  void init();
28 
29  class Interface {
30  public:
31  const QString& getKey() const { return _key; }
32  bool isSet() const { return _isSet; }
33 
34  virtual void setVariant(const QVariant& variant) = 0;
35  virtual QVariant getVariant() = 0;
36 
37  protected:
38  Interface(const QString& key) : _key(key) {}
39  virtual ~Interface() = default;
40 
41  void init();
42  void maybeInit() const;
43  void deinit();
44 
45  void save();
46  void load();
47 
48  bool _isSet = false;
49  const QString _key;
50 
51  private:
52  mutable bool _isInitialized = false;
53 
54  friend class Manager;
55  mutable QWeakPointer<Manager> _manager;
56  };
57 }
58 
59 #endif // hifi_SettingInterface_h