HAL
settings_item.h
Go to the documentation of this file.
1 // MIT License
2 //
3 // Copyright (c) 2019 Ruhr University Bochum, Chair for Embedded Security. All Rights reserved.
4 // Copyright (c) 2019 Marc Fyrbiak, Sebastian Wallat, Max Hoffmann ("ORIGINAL AUTHORS"). All rights reserved.
5 // Copyright (c) 2021 Max Planck Institute for Security and Privacy. All Rights reserved.
6 // Copyright (c) 2021 Jörn Langheinrich, Julian Speith, Nils Albartus, René Walendy, Simon Klix ("ORIGINAL AUTHORS"). All Rights reserved.
7 //
8 // Permission is hereby granted, free of charge, to any person obtaining a copy
9 // of this software and associated documentation files (the "Software"), to deal
10 // in the Software without restriction, including without limitation the rights
11 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 // copies of the Software, and to permit persons to whom the Software is
13 // furnished to do so, subject to the following conditions:
14 //
15 // The above copyright notice and this permission notice shall be included in all
16 // copies or substantial portions of the Software.
17 //
18 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 // SOFTWARE.
25 
26 #pragma once
27 
28 #include <QObject>
29 #include <QString>
30 #include <QVariant>
31 
32 namespace hal
33 {
34  class SettingsWidget;
35 
45  class SettingsItem : public QObject
46  {
47  Q_OBJECT
48 
49  public:
56 
60  virtual ~ SettingsItem() {}
61 
67  virtual QVariant value() const = 0;
68 
74  virtual QVariant defaultValue() const = 0;
75 
81  virtual void setValue(const QVariant& v) = 0;
82 
88  virtual void setDefaultValue(const QVariant& dv) = 0;
89 
97  virtual SettingsWidget* editWidget(QWidget* parent = nullptr) = 0;
98 
104  virtual bool isDefaultValue() const
105  {
106  return value() == defaultValue();
107  }
108 
114  virtual QVariant persistToSettings() const
115  {
116  return value();
117  }
118 
124  virtual void restoreFromSettings(const QVariant& val)
125  {
126  setValue(val);
127  }
128 
134  virtual bool isGlobal() const
135  {
136  return mIsGlobal;
137  }
138 
144  virtual QString label() const
145  {
146  return mLabel;
147  }
148 
154  virtual QString description() const
155  {
156  return mDescription;
157  }
158 
164  virtual QString tag() const
165  {
166  return mTag;
167  }
168 
174  virtual QString category() const
175  {
176  return mCategory;
177  }
178 
179  Q_SIGNALS:
180 
184  void valueChanged();
185 
186  protected:
187  bool mIsGlobal;
192  };
193 }
The interface for the logical part of a setting.
Definition: settings_item.h:46
virtual ~ SettingsItem()
Definition: settings_item.h:60
virtual QString tag() const
SettingsItem(QObject *parent=nullptr)
Definition: settings_item.h:55
virtual void restoreFromSettings(const QVariant &val)
virtual QString category() const
virtual void setValue(const QVariant &v)=0
virtual QVariant value() const =0
virtual bool isDefaultValue() const
virtual QVariant persistToSettings() const
virtual QString label() const
virtual void setDefaultValue(const QVariant &dv)=0
virtual SettingsWidget * editWidget(QWidget *parent=nullptr)=0
virtual QString description() const
virtual QVariant defaultValue() const =0
virtual bool isGlobal() const
The base class for all specific SettingsWidgets.
Q_OBJECTQ_OBJECT
Q_SIGNALSQ_SIGNALS
QObject * parent() const const