File indexing completed on 2024-05-12 16:42:41

0001 /*
0002     SPDX-FileCopyrightText: 2012 Alessandro Russo <axela74@yahoo.it>
0003     SPDX-FileCopyrightText: 2017-2018 Łukasz Wojniłowicz <lukasz.wojnilowicz@gmail.com>
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef MYMONEYTAG_H
0008 #define MYMONEYTAG_H
0009 
0010 // ----------------------------------------------------------------------------
0011 // QT Includes
0012 
0013 #include <QMetaType>
0014 
0015 // ----------------------------------------------------------------------------
0016 // Project Includes
0017 
0018 #include "kmm_mymoney_export.h"
0019 #include "mymoneyobject.h"
0020 
0021 class QString;
0022 class QColor;
0023 
0024 /**
0025   * This class represents a tag within the MyMoney engine.
0026   */
0027 class MyMoneyTagPrivate;
0028 class KMM_MYMONEY_EXPORT MyMoneyTag : public MyMoneyObject
0029 {
0030     Q_DECLARE_PRIVATE(MyMoneyTag)
0031 
0032     KMM_MYMONEY_UNIT_TESTABLE
0033 
0034 public:
0035     MyMoneyTag();
0036     explicit MyMoneyTag(const QString &id);
0037 
0038     explicit MyMoneyTag(const QString& name,
0039                         const QColor& tagColor
0040                        );
0041 
0042     MyMoneyTag(const QString& id,
0043                const MyMoneyTag& tag);
0044 
0045     MyMoneyTag(const MyMoneyTag & other);
0046     MyMoneyTag(MyMoneyTag && other);
0047     MyMoneyTag & operator=(MyMoneyTag other);
0048     friend void swap(MyMoneyTag& first, MyMoneyTag& second);
0049 
0050     ~MyMoneyTag();
0051 
0052     QString name() const;
0053     void setName(const QString& val);
0054 
0055     bool isClosed() const;
0056     void setClosed(bool val);
0057 
0058     QColor tagColor() const;
0059     void setTagColor(const QColor& val);
0060     void setNamedTagColor(const QString &val);
0061 
0062     QString notes() const;
0063     void setNotes(const QString& val);
0064 
0065     // Equality operator
0066     bool operator == (const MyMoneyTag &) const;
0067     bool operator <(const MyMoneyTag& right) const;
0068 
0069     /**
0070       * This method checks if a reference to the given object exists. It returns,
0071       * a @p true if the object is referencing the one requested by the
0072       * parameter @p id. If it does not, this method returns @p false.
0073       *
0074       * @param id id of the object to be checked for references
0075       * @retval true This object references object with id @p id.
0076       * @retval false This object does not reference the object with id @p id.
0077       */
0078     bool hasReferenceTo(const QString& id) const override;
0079 
0080     static MyMoneyTag null;
0081 };
0082 
0083 inline void swap(MyMoneyTag& first, MyMoneyTag& second) // krazy:exclude=inline
0084 {
0085     using std::swap;
0086     swap(first.d_ptr, second.d_ptr);
0087 }
0088 
0089 inline MyMoneyTag::MyMoneyTag(MyMoneyTag && other) : MyMoneyTag() // krazy:exclude=inline
0090 {
0091     swap(*this, other);
0092 }
0093 
0094 inline MyMoneyTag & MyMoneyTag::operator=(MyMoneyTag other) // krazy:exclude=inline
0095 {
0096     swap(*this, other);
0097     return *this;
0098 }
0099 
0100 //inline bool operator==(const MyMoneyTag& lhs, const QString& rhs)
0101 //{
0102 //  return lhs.id() == rhs;
0103 //}
0104 
0105 /**
0106   * Make it possible to hold @ref MyMoneyTag objects inside @ref QVariant objects.
0107   */
0108 Q_DECLARE_METATYPE(MyMoneyTag)
0109 
0110 #endif