blob: a45eaad59dd97e6704d1cbb7e508279fd8a1b238 (
plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
/***************************************************************************
mymoneycategory.cpp
-------------------
copyright : (C) 2000 by Michael Edwardes
email : mte@users.sourceforge.net
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "mymoneycategory.h"
MyMoneyCategory::MyMoneyCategory()
{
m_income = true;
}
MyMoneyCategory::MyMoneyCategory(const bool income, const TQString name)
{
m_income = income;
m_name = name;
}
MyMoneyCategory::MyMoneyCategory(const bool income, const TQString name, TQStringList minors)
{
m_income = income;
m_name = name;
m_minorCategories = minors;
}
MyMoneyCategory::~MyMoneyCategory()
{
}
// Functions use the find method to search the list
bool MyMoneyCategory::addMinorCategory(const TQString val)
{
if (val.isEmpty() || val.isNull())
return false;
if (m_minorCategories.find(val) == m_minorCategories.end()) {
m_minorCategories.append(val);
return true;
}
return false;
}
bool MyMoneyCategory::removeMinorCategory(const TQString val)
{
if (val.isEmpty() || val.isNull())
return false;
if (m_minorCategories.find(val) != m_minorCategories.end()) {
m_minorCategories.remove(val);
return true;
}
return false;
}
bool MyMoneyCategory::renameMinorCategory(const TQString oldVal, const TQString newVal)
{
if (oldVal.isEmpty() || oldVal.isNull() || newVal.isEmpty() || newVal.isNull())
return false;
if (m_minorCategories.find(oldVal) != m_minorCategories.end() &&
m_minorCategories.find(newVal) == m_minorCategories.end() ) {
m_minorCategories.remove(oldVal);
return addMinorCategory(newVal);
}
return false;
}
bool MyMoneyCategory::addMinorCategory(TQStringList values)
{
for (TQStringList::Iterator it = values.begin(); it!=values.end(); ++it) {
addMinorCategory(*it);
}
return true;
}
bool MyMoneyCategory::setMinorCategories(TQStringList values)
{
m_minorCategories.clear();
return addMinorCategory(values);
}
bool MyMoneyCategory::removeAllMinors(void)
{
m_minorCategories.clear();
return true;
}
TQString MyMoneyCategory::firstMinor(void)
{
return m_minorCategories.first();
}
MyMoneyCategory::MyMoneyCategory(const MyMoneyCategory& right)
{
m_income = right.m_income;
m_name = right.m_name;
m_minorCategories.clear();
m_minorCategories = right.m_minorCategories;
}
MyMoneyCategory& MyMoneyCategory::operator = (const MyMoneyCategory& right)
{
m_income = right.m_income;
m_name = right.m_name;
m_minorCategories.clear();
m_minorCategories = right.m_minorCategories;
return *this;
}
TQDataStream &operator<<(TQDataStream &s, MyMoneyCategory &category)
{
if (category.m_income)
s << (TQ_INT32)1;
else
s << (TQ_INT32)0;
s << category.m_name;
s << (TQ_UINT32)category.m_minorCategories.count();
for (TQStringList::Iterator it = category.m_minorCategories.begin(); it!=category.m_minorCategories.end(); ++it) {
s << (*it);
}
return s;
}
TQDataStream &operator>>(TQDataStream &s, MyMoneyCategory &category)
{
TQ_INT32 inc;
s >> inc;
if (inc==0)
category.m_income = false;
else
category.m_income = true;
s >> category.m_name;
TQ_UINT32 minorCount;
TQString buffer;
s >> minorCount;
category.m_minorCategories.clear();
for (unsigned int i=0; i<minorCount; i++) {
s >> buffer;
category.m_minorCategories.append(buffer);
}
return s;
}
void MyMoneyCategory::clear(void)
{
m_minorCategories.clear();
}
|