-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcustom_obj.cpp
94 lines (85 loc) · 2.37 KB
/
custom_obj.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include "custom_obj.h"
custom_obj::custom_obj(QObject *parent) : QObject(parent)
{
m_max_history = 50;
m_bgc = "#4681bb";
m_bgi = "";
}
void custom_obj::write_custom(QString file_path)
{
QString path;
if(file_path == "" || file_path.isEmpty() || file_path.isNull()) path = QDir::currentPath()+"/custom.dat";
else
{
if(file_path.indexOf(QRegExp("[/\\\\]")) == -1)
path = QDir::currentPath()+file_path;
else
{
if(file_path.indexOf(QRegExp("[/\\\\]$")) == -1)
path = file_path;
else path = file_path+"custom.dat";
}
}
QFile custom_file(path);
QDir a;
QRegExp path_dir_regexp("[/\\\\].*$");
path_dir_regexp.setMinimal(true);
a.mkpath(path.remove(path_dir_regexp));
custom_file.open(QFile::WriteOnly);
QDataStream custom_file_stream(&custom_file);
custom_file_stream << m_bgc << m_bgi << m_max_history;
custom_file.close();
}
void custom_obj::read_custom(QString file_path)
{
QString path;
if(file_path == "" || file_path.isEmpty() || file_path.isNull()) path = QDir::currentPath()+"/custom.dat";
else
{
if(file_path.indexOf(QRegExp("[/\\\\]")) == -1)
path = QDir::currentPath()+file_path;
else
{
if(file_path.indexOf(QRegExp("[/\\\\]$")) == -1)
path = file_path;
else path = file_path+"custom.dat";
}
}
QFile custom_file(path);
if(custom_file.exists() && custom_file.open(QFile::ReadOnly))
{
QDataStream custom_file_stream(&custom_file);
custom_file_stream >> m_bgc >> m_bgi >> m_max_history;
custom_file.close();
}
Q_EMIT bgiChanged(m_bgi);
Q_EMIT bgcChanged(m_bgc);
Q_EMIT max_historyChanged(m_max_history);
}
QString custom_obj::bgi() const
{
return m_bgi;
}
void custom_obj::setBgi(const QString & bgi)
{
m_bgi = bgi;
Q_EMIT bgiChanged(m_bgi);
}
QString custom_obj::bgc() const
{
return m_bgc;
}
void custom_obj::setBgc(const QString & bgc)
{
m_bgc = bgc;
Q_EMIT bgcChanged(m_bgc);
}
int custom_obj::max_history() const
{
return m_max_history;
}
void custom_obj::setMax_history(const int & max_history)
{
m_max_history = max_history;
Q_EMIT max_historyChanged(m_max_history);
}