Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTag Class Reference

The KisTag loads a tag from a .tag file. A .tag file is a .desktop file. The following fields are important: More...

#include <KisTag.h>

Classes

class  Private
 

Public Member Functions

bool active () const
 
KisTagSP clone () const
 
QString comment (bool translated=true) const
 The translated tooltips for the tag.
 
QMap< QString, QString > comments () const
 
QStringList defaultResources () const
 
QString filename ()
 
int id () const
 
 KisTag ()
 
 KisTag (const KisTag &rhs)
 
bool load (QIODevice &io)
 
QString name (bool translated=true) const
 The translated names of the tag.
 
QMap< QString, QString > names () const
 
KisTagoperator= (const KisTag &rhs)
 
QString resourceType () const
 
bool save (QIODevice &io)
 
void setComment (const QString comment)
 
void setComments (const QMap< QString, QString > &comments)
 
void setDefaultResources (const QStringList &defaultResources)
 
void setFilename (const QString &fileName)
 
void setName (const QString &name)
 
void setNames (const QMap< QString, QString > &names)
 
void setResourceType (const QString &resourceType)
 
void setUrl (const QString &url)
 
QString url () const
 The unique identifier for the tag. Since tag urls are compared COLLATE NOCASE, tag urls must be ASCII only.
 
bool valid () const
 
virtual ~KisTag ()
 

Static Public Member Functions

static QString currentLocale ()
 

Private Member Functions

void setActive (bool active)
 
void setId (int id)
 
void setValid (bool valid)
 

Private Attributes

QScopedPointer< Privated
 

Static Private Attributes

static const QString s_comment {"Comment"}
 
static const QString s_defaultResources {"Default Resources"}
 
static const QString s_desktop {"[Desktop Entry]"}
 
static const QString s_group {"Desktop Entry"}
 
static const QString s_name {"Name"}
 
static const QString s_resourceType {"ResourceType"}
 
static const QString s_tag {"Tag"}
 
static const QString s_type {"Type"}
 
static const QString s_url {"URL"}
 

Friends

class AbrTagIterator
 
class BundleTagIterator
 
class KisAllResourcesModel
 
class KisAllTagResourceModel
 
class KisAllTagsModel
 
class KisResourceLocator
 
class KisResourceModel
 
class KisTagChooserWidget
 
class KisTagModel
 
class TestTagModel
 

Detailed Description

The KisTag loads a tag from a .tag file. A .tag file is a .desktop file. The following fields are important:

name: the name of the tag, which can be translated comment: a tooltip for the tag, which can be translated url: the untranslated name of the tag

Definition at line 33 of file KisTag.h.

Constructor & Destructor Documentation

◆ KisTag() [1/2]

KisTag::KisTag ( )

Definition at line 47 of file KisTag.cpp.

48 : d(new Private)
49{
50}
QScopedPointer< Private > d
Definition KisTag.h:105

◆ ~KisTag()

KisTag::~KisTag ( )
virtual

Definition at line 52 of file KisTag.cpp.

53{
54}

◆ KisTag() [2/2]

KisTag::KisTag ( const KisTag & rhs)

Definition at line 56 of file KisTag.cpp.

57 : d(new Private)
58{
59 *this = rhs;
60}

Member Function Documentation

◆ active()

bool KisTag::active ( ) const

Definition at line 107 of file KisTag.cpp.

108{
109 return d->active;
110}

References d.

◆ clone()

KisTagSP KisTag::clone ( ) const

Definition at line 79 of file KisTag.cpp.

80{
81 return KisTagSP(new KisTag(*this));
82}
QSharedPointer< KisTag > KisTagSP
Definition KisTag.h:20
KisTag()
Definition KisTag.cpp:47

References KisTag().

◆ comment()

QString KisTag::comment ( bool translated = true) const

The translated tooltips for the tag.

Definition at line 146 of file KisTag.cpp.

147{
148 if (translated && d->comments.contains(currentLocale())) {
149 return d->comments[currentLocale()];
150 }
151 return d->comment;
152}
static QString currentLocale()
Definition KisTag.cpp:84

References currentLocale(), and d.

◆ comments()

QMap< QString, QString > KisTag::comments ( ) const

Definition at line 170 of file KisTag.cpp.

171{
172 return d->comments;
173}

References d.

◆ currentLocale()

QString KisTag::currentLocale ( )
static

Definition at line 84 of file KisTag.cpp.

85{
86 const QStringList languages = KLocalizedString::languages();
87 QString locale;
88 if (languages.isEmpty()) {
89 locale = QLocale().name();
90 }
91 else {
92 locale = languages.first();
93 }
94 return locale;
95}

◆ defaultResources()

QStringList KisTag::defaultResources ( ) const

Definition at line 190 of file KisTag.cpp.

191{
192 return d->defaultResources;
193}

References d.

◆ filename()

QString KisTag::filename ( )

Definition at line 112 of file KisTag.cpp.

113{
114 return d->filename;
115}

References d.

◆ id()

int KisTag::id ( ) const

Definition at line 102 of file KisTag.cpp.

103{
104 return d->id;
105}

References d.

◆ load()

bool KisTag::load ( QIODevice & io)

Definition at line 200 of file KisTag.cpp.

201{
202 if (!io.isOpen()) {
203 io.open(QIODevice::ReadOnly);
204 }
205 KIS_ASSERT(io.isOpen());
206
207 setValid(false);
208
209 QTextStream stream(&io);
211 QStringList lines;
212 QString line;
213
214 while (stream.readLineInto(&line)) {
215 lines << line;
216 }
217
218 if (lines.length() < 6 ) {
219 qWarning() << d->filename << ": Incomplete tag file" << lines.length();
220 return false;
221 }
222 if (lines[0].toUpper() != s_desktop.toUpper()) {
223 qWarning() << d->filename << ":Invalid tag file" << lines[0];
224 return false;
225 }
226
227 lines.removeFirst();
228
229 Q_FOREACH(const QString line, lines) {
230 if (line.isEmpty()) {
231 continue;
232 }
233
234 if (!line.contains("=")) {
235 qWarning() << "Found invalid line:" << line;
236 continue;
237 }
238 int isPos = line.indexOf("=");
239 QString key = line.left(isPos).trimmed();
240 QString value = line.right(line.size() - (isPos + 1)).trimmed();
241
242 if (key == s_url) {
243 d->url = value;
244 }
245 else if (key == s_resourceType) {
246 d->resourceType = value;
247 }
248 else if (key == s_defaultResources) {
249 d->defaultResources = value.split(',', Qt::SkipEmptyParts);
250 }
251 else if (key == s_name) {
252 d->name = value;
253 }
254 else if (key == s_comment) {
255 d->comment = value;
256 }
257 else if (key.startsWith(s_name + "[")) {
258 int start = key.indexOf('[') + 1;
259 int len = key.size() - (s_name.size() + 2);
260 QString language = key.mid(start, len);
261 d->names[language] = value;
262 }
263 else if (key.startsWith(s_comment + "[")) {
264 int start = key.indexOf('[') + 1;
265 int len = key.size() - (s_comment.size() + 2);
266 QString language = key.mid(start, len);
267 d->comments[language] = value;
268 }
269 }
270
271 setValid(true);
272
273 return true;
274}
float value(const T *src, size_t ch)
static const QString s_desktop
Definition KisTag.h:30
static const QString s_defaultResources
Definition KisTag.h:29
void setValid(bool valid)
Definition KisTag.cpp:313
static const QString s_url
Definition KisTag.h:27
static const QString s_comment
Definition KisTag.h:28
static const QString s_name
Definition KisTag.h:25
static const QString s_resourceType
Definition KisTag.h:26
#define KIS_ASSERT(cond)
Definition kis_assert.h:33
void setUtf8OnStream(QTextStream &stream)

References d, KIS_ASSERT, s_comment, s_defaultResources, s_desktop, s_name, s_resourceType, s_url, KisPortingUtils::setUtf8OnStream(), setValid(), and value().

◆ name()

QString KisTag::name ( bool translated = true) const

The translated names of the tag.

Definition at line 122 of file KisTag.cpp.

123{
124 if (translated && d->names.contains(currentLocale())) {
125 return d->names[currentLocale()];
126 }
127 Q_ASSERT(!d->name.isEmpty());
128 return d->name;
129}

References currentLocale(), and d.

◆ names()

QMap< QString, QString > KisTag::names ( ) const

Definition at line 136 of file KisTag.cpp.

137{
138 return d->names;
139}

References d.

◆ operator=()

KisTag & KisTag::operator= ( const KisTag & rhs)

Definition at line 62 of file KisTag.cpp.

63{
64 if (this != &rhs) {
65 d->valid = rhs.d->valid;
66 d->url = rhs.d->url;
67 d->name = rhs.d->name;
68 d->comment = rhs.d->comment;
69 d->names = rhs.d->names;
70 d->comments = rhs.d->comments;
71 d->defaultResources = rhs.d->defaultResources; d->resourceType = rhs.d->resourceType;
72 d->filename = rhs.d->filename;
73 d->id = rhs.d->id;
74 d->active = rhs.d->active;
75 }
76 return *this;
77}

References d, and valid().

◆ resourceType()

QString KisTag::resourceType ( ) const

Definition at line 180 of file KisTag.cpp.

181{
182 return d->resourceType;
183}

References d.

◆ save()

bool KisTag::save ( QIODevice & io)

Definition at line 276 of file KisTag.cpp.

277{
278 if (!io.isOpen()) {
279 io.open(QIODevice::WriteOnly | QIODevice::Text);
280 }
281
282 QTextStream stream(&io);
284 stream << s_desktop << '\n';
285 stream << s_type << '=' << s_tag << '\n';
286 stream << s_url << '=' << d->url << '\n';
287 stream << s_resourceType << '=' << d->resourceType << '\n';
288 stream << s_name << '=' << d->name << '\n';
289 stream << s_comment << '=' << d->comment << '\n';
290 stream << s_defaultResources << '=' << d->defaultResources.join(',') << '\n';
291
292 Q_FOREACH(const QString &language, d->names) {
293 stream << s_name << '[' << language << "]=" << d->names[language] << '\n';
294 }
295
296 Q_FOREACH(const QString &language, d->comments) {
297 stream << s_comment << '[' << language << "]=" << d->comments[language] << '\n';
298 }
299
300 return true;
301}
static const QString s_tag
Definition KisTag.h:24
static const QString s_type
Definition KisTag.h:23

References d, s_comment, s_defaultResources, s_desktop, s_name, s_resourceType, s_tag, s_type, s_url, and KisPortingUtils::setUtf8OnStream().

◆ setActive()

void KisTag::setActive ( bool active)
private

Definition at line 308 of file KisTag.cpp.

309{
310 d->active = active;
311}
bool active() const
Definition KisTag.cpp:107

References active(), and d.

◆ setComment()

void KisTag::setComment ( const QString comment)

Definition at line 154 of file KisTag.cpp.

155{
156 d->comment = comment;
157}
QString comment(bool translated=true) const
The translated tooltips for the tag.
Definition KisTag.cpp:146

References comment(), and d.

◆ setComments()

void KisTag::setComments ( const QMap< QString, QString > & comments)

Definition at line 175 of file KisTag.cpp.

176{
177 d->comments = comments;
178}
QMap< QString, QString > comments() const
Definition KisTag.cpp:170

References comments(), and d.

◆ setDefaultResources()

void KisTag::setDefaultResources ( const QStringList & defaultResources)

Definition at line 195 of file KisTag.cpp.

196{
197 d->defaultResources = defaultResources;
198}
QStringList defaultResources() const
Definition KisTag.cpp:190

References d, and defaultResources().

◆ setFilename()

void KisTag::setFilename ( const QString & fileName)

Definition at line 117 of file KisTag.cpp.

118{
119 d->filename = filename;
120}
QString filename()
Definition KisTag.cpp:112

References d, and filename().

◆ setId()

void KisTag::setId ( int id)
private

Definition at line 303 of file KisTag.cpp.

304{
305 d->id = id;
306}
int id() const
Definition KisTag.cpp:102

References d, and id().

◆ setName()

void KisTag::setName ( const QString & name)

Definition at line 131 of file KisTag.cpp.

132{
133 d->name = name;
134}
QString name(bool translated=true) const
The translated names of the tag.
Definition KisTag.cpp:122

References d, and name().

◆ setNames()

void KisTag::setNames ( const QMap< QString, QString > & names)

Definition at line 141 of file KisTag.cpp.

142{
143 d->names = names;
144}
QMap< QString, QString > names() const
Definition KisTag.cpp:136

References d, and names().

◆ setResourceType()

void KisTag::setResourceType ( const QString & resourceType)

Definition at line 185 of file KisTag.cpp.

186{
187 d->resourceType = resourceType;
188}
QString resourceType() const
Definition KisTag.cpp:180

References d, and resourceType().

◆ setUrl()

void KisTag::setUrl ( const QString & url)

Definition at line 164 of file KisTag.cpp.

165{
166 d->url = url;
167}
QString url() const
The unique identifier for the tag. Since tag urls are compared COLLATE NOCASE, tag urls must be ASCII...
Definition KisTag.cpp:159

References d, and url().

◆ setValid()

void KisTag::setValid ( bool valid)
private

Definition at line 313 of file KisTag.cpp.

314{
315 d->valid = valid;
316}
bool valid() const
Definition KisTag.cpp:97

References d, and valid().

◆ url()

QString KisTag::url ( ) const

The unique identifier for the tag. Since tag urls are compared COLLATE NOCASE, tag urls must be ASCII only.

Definition at line 159 of file KisTag.cpp.

160{
161 return d->url;
162}

References d.

◆ valid()

bool KisTag::valid ( ) const

Definition at line 97 of file KisTag.cpp.

98{
99 return d->valid;
100}

References d.

Friends And Related Symbol Documentation

◆ AbrTagIterator

friend class AbrTagIterator
friend

Definition at line 88 of file KisTag.h.

◆ BundleTagIterator

friend class BundleTagIterator
friend

Definition at line 87 of file KisTag.h.

◆ KisAllResourcesModel

friend class KisAllResourcesModel
friend

Definition at line 82 of file KisTag.h.

◆ KisAllTagResourceModel

friend class KisAllTagResourceModel
friend

Definition at line 81 of file KisTag.h.

◆ KisAllTagsModel

friend class KisAllTagsModel
friend

Definition at line 80 of file KisTag.h.

◆ KisResourceLocator

friend class KisResourceLocator
friend

Definition at line 86 of file KisTag.h.

◆ KisResourceModel

friend class KisResourceModel
friend

Definition at line 83 of file KisTag.h.

◆ KisTagChooserWidget

friend class KisTagChooserWidget
friend

Definition at line 84 of file KisTag.h.

◆ KisTagModel

friend class KisTagModel
friend

Definition at line 79 of file KisTag.h.

◆ TestTagModel

friend class TestTagModel
friend

Definition at line 85 of file KisTag.h.

Member Data Documentation

◆ d

QScopedPointer<Private> KisTag::d
private

Definition at line 105 of file KisTag.h.

◆ s_comment

const QString KisTag::s_comment {"Comment"}
staticprivate

Definition at line 28 of file KisTag.h.

28: the name of the tag, which can be translated

◆ s_defaultResources

const QString KisTag::s_defaultResources {"Default Resources"}
staticprivate

Definition at line 29 of file KisTag.h.

29: a tooltip for the tag, which can be translated

◆ s_desktop

const QString KisTag::s_desktop {"[Desktop Entry]"}
staticprivate

Definition at line 30 of file KisTag.h.

30: the untranslated name of the tag

◆ s_group

const QString KisTag::s_group {"Desktop Entry"}
staticprivate

Definition at line 22 of file KisTag.h.

◆ s_name

const QString KisTag::s_name {"Name"}
staticprivate

Definition at line 25 of file KisTag.h.

◆ s_resourceType

const QString KisTag::s_resourceType {"ResourceType"}
staticprivate

Definition at line 26 of file KisTag.h.

26:
27

◆ s_tag

const QString KisTag::s_tag {"Tag"}
staticprivate

Definition at line 24 of file KisTag.h.

◆ s_type

const QString KisTag::s_type {"Type"}
staticprivate

Definition at line 23 of file KisTag.h.

◆ s_url

const QString KisTag::s_url {"URL"}
staticprivate

Definition at line 27 of file KisTag.h.


The documentation for this class was generated from the following files: