1 /*
2 * Copyright 2000-2001 Michael Edwardes <mte@users.sourceforge.net>
3 * Copyright 2002-2017 Thomas Baumgart <tbaumgart@kde.org>
4 * Copyright 2003 Kevin Tambascio <ktambascio@users.sourceforge.net>
5 * Copyright 2004-2006 Ace Jones <acejones@users.sourceforge.net>
6 * Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #ifndef MYMONEYINSTITUTION_H
23 #define MYMONEYINSTITUTION_H
24
25 // ----------------------------------------------------------------------------
26 // QT Includes
27
28 #include <QMetaType>
29
30 // ----------------------------------------------------------------------------
31 // Project Includes
32
33 #include "mymoneyobject.h"
34 #include "mymoneykeyvaluecontainer.h"
35 #include "kmm_mymoney_export.h"
36
37 class QString;
38 class QStringList;
39 class QPixmap;
40
41 /**
42 * This class represents a Bank contained within a MyMoneyFile object
43 *
44 * @author Thomas Baumgart
45 * @author Łukasz Wojniłowicz
46 */
47 class MyMoneyInstitutionPrivate;
48 class KMM_MYMONEY_EXPORT MyMoneyInstitution : public MyMoneyObject, public MyMoneyKeyValueContainer
49 {
50 Q_DECLARE_PRIVATE_D(MyMoneyObject::d_ptr, MyMoneyInstitution)
51
52 KMM_MYMONEY_UNIT_TESTABLE
53
54 public:
55
56 /**
57 * This is the constructor for a new empty institution description
58 */
59 MyMoneyInstitution();
60 explicit MyMoneyInstitution(const QString &id);
61
62 /**
63 * This is the constructor used by an application to fill the
64 * values required for a new institution. This object should then be
65 * passed to @see MyMoneyFile::addInstitution
66 */
67 explicit MyMoneyInstitution(const QString& name,
68 const QString& city,
69 const QString& street,
70 const QString& postcode,
71 const QString& telephone,
72 const QString& manager,
73 const QString& sortCode);
74
75 MyMoneyInstitution(const MyMoneyInstitution & other);
76 MyMoneyInstitution(MyMoneyInstitution && other);
77 MyMoneyInstitution & operator=(MyMoneyInstitution other);
78 friend void swap(MyMoneyInstitution& first, MyMoneyInstitution& second);
79
80 /**
81 * This is the destructor for any MyMoneyInstitution object
82 */
83 ~MyMoneyInstitution();
84
85 /**
86 * This is the constructor for a new institution known to the current file
87 *
88 * @param id id assigned to the new institution object
89 * @param right institution definition
90 */
91 MyMoneyInstitution(const QString& id, const MyMoneyInstitution& other);
92
93 QString manager() const;
94 void setManager(const QString& manager);
95
96 QString name() const;
97 void setName(const QString& name);
98
99 QString postcode() const;
100 void setPostcode(const QString& code);
101
102 QString street() const;
103 void setStreet(const QString& street);
104
105 QString telephone() const;
106 void setTelephone(const QString& tel);
107
108 QString town() const;
109 void setTown(const QString& town);
110
111 QString city() const;
112 void setCity(const QString& town);
113
114 QString sortcode() const;
115 void setSortcode(const QString& code);
116
117 /**
118 * This method adds the id of an account to the account list of
119 * this institution It is verified, that the account is only
120 * mentioned once.
121 *
122 * @param account id of the account to be added
123 */
124 void addAccountId(const QString& account);
125
126 /**
127 * This method deletes the id of an account from the account list
128 * of this institution
129 *
130 * @param account id of the account to be deleted
131 * @return id of account deleted, otherwise empty string
132 */
133 QString removeAccountId(const QString& account);
134
135 /**
136 * This method is used to return the set of accounts known to
137 * this institution
138 * return QStringList of account ids
139 */
140 QStringList accountList() const;
141
142 /**
143 * This method returns the number of accounts known to
144 * this institution
145 * @return number of accounts
146 */
147 unsigned int accountCount() const;
148
149 bool operator == (const MyMoneyInstitution&) const;
150 bool operator < (const MyMoneyInstitution& right) const;
151
152 /**
153 * This method checks if a reference to the given object exists. It returns,
154 * a @p true if the object is referencing the one requested by the
155 * parameter @p id. If it does not, this method returns @p false.
156 *
157 * @param id id of the object to be checked for references
158 * @retval true This object references object with id @p id.
159 * @retval false This object does not reference the object with id @p id.
160 */
161 bool hasReferenceTo(const QString& id) const override;
162
163 static QPixmap pixmap(const int size = 64);
164 };
165
swap(MyMoneyInstitution & first,MyMoneyInstitution & second)166 inline void swap(MyMoneyInstitution& first, MyMoneyInstitution& second) // krazy:exclude=inline
167 {
168 using std::swap;
169 swap(first.MyMoneyObject::d_ptr, second.MyMoneyObject::d_ptr);
170 swap(first.MyMoneyKeyValueContainer::d_ptr, second.MyMoneyKeyValueContainer::d_ptr);
171 }
172
MyMoneyInstitution(MyMoneyInstitution && other)173 inline MyMoneyInstitution::MyMoneyInstitution(MyMoneyInstitution && other) : MyMoneyInstitution() // krazy:exclude=inline
174 {
175 swap(*this, other);
176 }
177
178 inline MyMoneyInstitution & MyMoneyInstitution::operator=(MyMoneyInstitution other) // krazy:exclude=inline
179 {
180 swap(*this, other);
181 return *this;
182 }
183
184 /**
185 * Make it possible to hold @ref MyMoneyInstitution objects inside @ref QVariant objects.
186 */
187 Q_DECLARE_METATYPE(MyMoneyInstitution)
188
189 #endif
190