forked from 4lex4/scantailor-advanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultParamsProvider.cpp
59 lines (48 loc) · 1.65 KB
/
DefaultParamsProvider.cpp
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "DefaultParamsProvider.h"
#include <QtCore/QSettings>
#include <cassert>
#include "DefaultParams.h"
#include "DefaultParamsProfileManager.h"
std::unique_ptr<DefaultParamsProvider> DefaultParamsProvider::m_instance = nullptr;
DefaultParamsProvider::DefaultParamsProvider() {
QSettings settings;
DefaultParamsProfileManager defaultParamsProfileManager;
const QString profile = settings.value("settings/current_profile", "Default").toString();
if (profile == "Default") {
m_params = defaultParamsProfileManager.createDefaultProfile();
m_profileName = profile;
} else if (profile == "Source") {
m_params = defaultParamsProfileManager.createSourceProfile();
m_profileName = profile;
} else {
std::unique_ptr<DefaultParams> params = defaultParamsProfileManager.readProfile(profile);
if (params != nullptr) {
m_params = std::move(params);
m_profileName = profile;
} else {
m_params = defaultParamsProfileManager.createDefaultProfile();
m_profileName = "Default";
settings.setValue("settings/current_profile", "Default");
}
}
}
DefaultParamsProvider* DefaultParamsProvider::getInstance() {
if (m_instance == nullptr) {
m_instance.reset(new DefaultParamsProvider());
}
return m_instance.get();
}
const QString& DefaultParamsProvider::getProfileName() const {
return m_profileName;
}
DefaultParams DefaultParamsProvider::getParams() const {
assert(m_params != nullptr);
return *m_params;
}
void DefaultParamsProvider::setParams(std::unique_ptr<DefaultParams> params, const QString& name) {
if (params == nullptr) {
return;
}
m_params = std::move(params);
m_profileName = name;
}