Sayonara Player
Toggle main menu visibility
Loading...
Searching...
No Matches
src
Utils
Settings
Setting.h
1
/* Setting.h */
2
3
/* Copyright (C) 2011-2024 Michael Lugmair (Lucio Carreras)
4
*
5
* This file is part of sayonara player
6
*
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
11
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
16
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19
*/
20
21
#pragma once
22
#ifndef SAYONARA_PLAYER_SETTING_H
23
#define SAYONARA_PLAYER_SETTING_H
24
25
#include "Utils/Settings/SettingConverter.h"
26
#include "Utils/Settings/SettingKey.h"
27
#include "Utils/Pimpl.h"
28
29
class
AbstrSetting
30
{
31
PIMPL(AbstrSetting)
32
33
private
:
34
AbstrSetting();
35
AbstrSetting(
const
AbstrSetting& other);
36
AbstrSetting& operator=(
const
AbstrSetting& other);
37
AbstrSetting(AbstrSetting&& other)
noexcept
;
38
AbstrSetting& operator=(AbstrSetting&& other)
noexcept
;
39
40
protected
:
41
explicit
AbstrSetting(SettingKey key);
42
AbstrSetting(SettingKey key,
const
char
* dbKey);
43
44
public
:
45
virtual
~AbstrSetting();
46
47
[[nodiscard]] SettingKey getKey()
const
;
48
[[nodiscard]] QString dbKey()
const
;
49
[[nodiscard]]
bool
isDatabaseSetting()
const
;
50
51
void
assignValue(
const
QString& value);
52
53
virtual
bool
loadValueFromString(
const
QString& str) = 0;
54
[[nodiscard]]
virtual
QString valueToString()
const
= 0;
55
virtual
void
assignDefaultValue() = 0;
56
};
57
58
template
<
typename
KeyClass>
59
class
Setting :
60
public
AbstrSetting
61
{
62
public
:
63
Setting() =
delete
;
64
Setting(
const
Setting&) =
delete
;
65
66
Setting(
const
char
* databaseKey,
const
typename
KeyClass::Data& value) :
67
AbstrSetting(KeyClass::key, databaseKey),
68
m_value {value},
69
m_defaultValue {value} {}
70
71
explicit
Setting(
const
typename
KeyClass::Data& value) :
72
AbstrSetting(KeyClass::key),
73
m_value {value},
74
m_defaultValue {value} {}
75
76
~Setting()
override
=
default
;
77
78
void
assignDefaultValue()
override
{ m_value = m_defaultValue; }
79
80
[[nodiscard]] QString valueToString()
const override
{
return
SettingConverter::toString(m_value); }
81
82
bool
loadValueFromString(
const
QString& str)
override
{
return
SettingConverter::fromString(str, m_value); }
83
84
const
typename
KeyClass::Data& value()
const
{
return
m_value; }
85
86
//const typename KeyClass::Data& default_value() const { return m_defaultValue; }
87
88
bool
assignValue(
const
typename
KeyClass::Data& val)
89
{
90
if
(m_value == val)
91
{
92
return
false
;
93
}
94
95
m_value = val;
96
97
return
true
;
98
}
99
100
private
:
101
typename
KeyClass::Data m_value;
102
typename
KeyClass::Data m_defaultValue;
103
};
104
105
#endif
// SAYONARA_PLAYER_SETTING_H
Generated on
for Sayonara Player by
1.17.0