File indexing completed on 2024-04-28 15:39:59

0001 // SPDX-FileCopyrightText: 2022 Johannes Zarl-Zierl <johannes@zarl-zierl.at>
0002 //
0003 //  SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0004 
0005 #ifndef DB_TAGINFO_H
0006 #define DB_TAGINFO_H
0007 
0008 #include "Category.h"
0009 
0010 #include <QObject>
0011 
0012 namespace DB
0013 {
0014 class Category;
0015 
0016 /**
0017  * @brief The TagInfo class is a convenience class to bundle category and tag into a single object.
0018  * Instead of a pair of QStrings, this interface keeps a connection to the category object to update the tag name if a tag is renamed.
0019  */
0020 class TagInfo : public QObject
0021 {
0022     Q_OBJECT
0023 public:
0024     TagInfo();
0025     /**
0026      * @brief TagInfo
0027      * The TagInfo is parented to the DB::Category.
0028      *
0029      * @param category a valid category
0030      * @param tag a valid tag within the given category
0031      */
0032     TagInfo(Category *category, const QString &tag);
0033 
0034     /**
0035      * @brief category
0036      * @return A pointer to the DB::Category object for the tag.
0037      */
0038     Category *category() const;
0039     /**
0040      * @brief categoryName is a pure convenience function.
0041      * @return The category name, or an empty string if the TagInfo is null.
0042      */
0043     QString categoryName() const;
0044     /**
0045      * @brief tagName returns the name of the tag.
0046      * If you store the TagInfo object for a longer time, the tag name may change to a different value (if a tag is renamed) and even be empty (if a tag is removed).
0047      * Make sure that you check for an empty tag name if you don't use the TagInfo immediately.
0048      * @return The tag string.
0049      */
0050     QString tagName() const;
0051 
0052     /**
0053      * @brief isValid can be used to determine whether the TagInfo is actually usable.
0054      * A valid TagInfo can become invalid if the DB::Category or the tag is deleted.
0055      *
0056      * @return \c true, if both category and tag have valid values, \c false otherwise.
0057      */
0058     bool isValid() const;
0059     /**
0060      * @brief isNull
0061      * @return \c true, if the TagInfo is default-constructed, \c false otherwise.
0062      */
0063     bool isNull() const;
0064 
0065 private:
0066     Category *m_category;
0067     QString m_tag;
0068 
0069 private Q_SLOTS:
0070     void updateTagName(const QString &oldName, const QString &newName);
0071     void removeTagName(const QString &name);
0072 };
0073 
0074 } // namespace DB
0075 
0076 #endif // DB_TAGINFO_H