akregator/src
tag.cpp00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "shared.h"
00026 #include "tag.h"
00027 #include "tagset.h"
00028
00029 #include <qstring.h>
00030 #include <qvaluelist.h>
00031
00032 namespace Akregator {
00033
00034 class Tag::TagPrivate : public Shared
00035 {
00036 public:
00037 QString id;
00038 QString name;
00039 QString scheme;
00040 QString icon;
00041
00042 QValueList<TagSet*> tagSets;
00043 bool operator==(const TagPrivate& other) const
00044 {
00045 return id == other.id;
00046 }
00047 };
00048
00049 Tag::Tag() : d(new TagPrivate)
00050 {}
00051
00052 Tag::Tag(const QString& id, const QString& name, const QString& scheme) : d(new TagPrivate)
00053 {
00054 d->id = id;
00055 d->name = name.isNull() ? id : name;
00056 d->scheme = scheme;
00057 d->icon = "rss_tag";
00058 }
00059
00060 Tag Tag::fromCategory(const QString& term, const QString& scheme, const QString& name)
00061 {
00062 Tag tag(scheme + "/" + term, name, scheme);
00063 return tag;
00064 }
00065
00066
00067 Tag::Tag(const Tag& other) : d(0)
00068 {
00069 *this = other;
00070 }
00071
00072 Tag::~Tag()
00073 {
00074 if (d->deref())
00075 {
00076 delete d;
00077 d = 0;
00078 }
00079 }
00080
00081 Tag& Tag::operator=(const Tag& other)
00082 {
00083 if (this != &other)
00084 {
00085 other.d->ref();
00086 if (d && d->deref())
00087 delete d;
00088 d = other.d;
00089 }
00090 return *this;
00091 }
00092
00093
00094 bool Tag::operator==(const Tag& other) const
00095 {
00096 return *(other.d) == *d;
00097 }
00098
00099 bool Tag::operator<(const Tag& other) const
00100 {
00101 return (name() < other.name()) || (name() == other.name() && id() < other.id());
00102 }
00103
00104 bool Tag::isNull() const
00105 {
00106 return d->id.isNull();
00107 }
00108
00109 QString Tag::name() const
00110 {
00111 return d->name;
00112 }
00113
00114 QString Tag::scheme() const
00115 {
00116 return d->scheme;
00117 }
00118
00119 QString Tag::icon() const
00120 {
00121 return d->icon;
00122 }
00123
00124 void Tag::setIcon(const QString& icon)
00125 {
00126 if (icon != d->icon)
00127 {
00128 d->icon = icon;
00129 for (QValueList<TagSet*>::ConstIterator it = d->tagSets.begin(); it != d->tagSets.end(); ++it)
00130 (*it)->tagUpdated(*this);
00131 }
00132 }
00133
00134
00135 void Tag::setName(const QString& name)
00136 {
00137 if (name != d->name)
00138 {
00139 d->name = name;
00140 for (QValueList<TagSet*>::ConstIterator it = d->tagSets.begin(); it != d->tagSets.end(); ++it)
00141 (*it)->tagUpdated(*this);
00142 }
00143 }
00144
00145 void Tag::addedToTagSet(TagSet* tagSet) const
00146 {
00147 d->tagSets.append(tagSet);
00148 }
00149
00150 void Tag::removedFromTagSet(TagSet* tagSet) const
00151 {
00152 d->tagSets.remove(tagSet);
00153 }
00154
00155 QString Tag::id() const
00156 {
00157 return d->id;
00158 }
00159
00160 }
|