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 #include "TagInfo.h"
0006 
0007 #include "Category.h"
0008 
0009 namespace DB
0010 {
0011 
0012 TagInfo::TagInfo()
0013     : QObject()
0014     , m_category(nullptr)
0015     , m_tag()
0016 {
0017 }
0018 
0019 TagInfo::TagInfo(Category *category, const QString &tag)
0020     : QObject(category)
0021     , m_category(category)
0022     , m_tag(tag)
0023 {
0024     Q_ASSERT(category->items().contains(tag));
0025     connect(m_category, &DB::Category::itemRenamed, this, &DB::TagInfo::updateTagName);
0026     connect(m_category, &DB::Category::itemRemoved, this, &DB::TagInfo::removeTagName);
0027 }
0028 
0029 Category *TagInfo::category() const
0030 {
0031     return m_category;
0032 }
0033 
0034 QString TagInfo::categoryName() const
0035 {
0036     return (m_category) ? m_category->name() : QString();
0037 }
0038 
0039 QString TagInfo::tagName() const
0040 {
0041     return m_tag;
0042 }
0043 
0044 bool TagInfo::isValid() const
0045 {
0046     return m_category != nullptr && !m_tag.isNull();
0047 }
0048 
0049 bool TagInfo::isNull() const
0050 {
0051     return m_category == nullptr && m_tag.isNull();
0052 }
0053 
0054 void TagInfo::updateTagName(const QString &oldName, const QString &newName)
0055 {
0056     if (oldName == m_tag) {
0057         m_tag = newName;
0058     }
0059 }
0060 
0061 void TagInfo::removeTagName(const QString &name)
0062 {
0063     if (name == m_tag) {
0064         m_tag.clear();
0065     }
0066 }
0067 
0068 } // namespace DB