1 /*
2 * Copyright 2012 Alessandro Russo <axela74@yahoo.it>
3 * Copyright 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #ifndef MYMONEYTAG_H
20 #define MYMONEYTAG_H
21
22 // ----------------------------------------------------------------------------
23 // QT Includes
24
25 #include <QMetaType>
26
27 // ----------------------------------------------------------------------------
28 // Project Includes
29
30 #include "kmm_mymoney_export.h"
31 #include "mymoneyobject.h"
32
33 class QString;
34 class QColor;
35
36 /**
37 * This class represents a tag within the MyMoney engine.
38 */
39 class MyMoneyTagPrivate;
40 class KMM_MYMONEY_EXPORT MyMoneyTag : public MyMoneyObject
41 {
42 Q_DECLARE_PRIVATE(MyMoneyTag)
43
44 KMM_MYMONEY_UNIT_TESTABLE
45
46 public:
47 MyMoneyTag();
48 explicit MyMoneyTag(const QString &id);
49
50 explicit MyMoneyTag(const QString& name,
51 const QColor& tagColor
52 );
53
54 MyMoneyTag(const QString& id,
55 const MyMoneyTag& tag);
56
57 MyMoneyTag(const MyMoneyTag & other);
58 MyMoneyTag(MyMoneyTag && other);
59 MyMoneyTag & operator=(MyMoneyTag other);
60 friend void swap(MyMoneyTag& first, MyMoneyTag& second);
61
62 ~MyMoneyTag();
63
64 QString name() const;
65 void setName(const QString& val);
66
67 bool isClosed() const;
68 void setClosed(bool val);
69
70 QColor tagColor() const;
71 void setTagColor(const QColor& val);
72 void setNamedTagColor(const QString &val);
73
74 QString notes() const;
75 void setNotes(const QString& val);
76
77 // Equality operator
78 bool operator == (const MyMoneyTag &) const;
79 bool operator <(const MyMoneyTag& right) const;
80
81 /**
82 * This method checks if a reference to the given object exists. It returns,
83 * a @p true if the object is referencing the one requested by the
84 * parameter @p id. If it does not, this method returns @p false.
85 *
86 * @param id id of the object to be checked for references
87 * @retval true This object references object with id @p id.
88 * @retval false This object does not reference the object with id @p id.
89 */
90 bool hasReferenceTo(const QString& id) const override;
91
92 static MyMoneyTag null;
93 };
94
swap(MyMoneyTag & first,MyMoneyTag & second)95 inline void swap(MyMoneyTag& first, MyMoneyTag& second) // krazy:exclude=inline
96 {
97 using std::swap;
98 swap(first.d_ptr, second.d_ptr);
99 }
100
MyMoneyTag(MyMoneyTag && other)101 inline MyMoneyTag::MyMoneyTag(MyMoneyTag && other) : MyMoneyTag() // krazy:exclude=inline
102 {
103 swap(*this, other);
104 }
105
106 inline MyMoneyTag & MyMoneyTag::operator=(MyMoneyTag other) // krazy:exclude=inline
107 {
108 swap(*this, other);
109 return *this;
110 }
111
112 //inline bool operator==(const MyMoneyTag& lhs, const QString& rhs)
113 //{
114 // return lhs.id() == rhs;
115 //}
116
117 /**
118 * Make it possible to hold @ref MyMoneyTag objects inside @ref QVariant objects.
119 */
120 Q_DECLARE_METATYPE(MyMoneyTag)
121
122 #endif
123