blob: 4b9210d191432c4fe7650a6a30859470f590b717 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#include "atomchannelimage.h"
#include <QXmlStreamReader>
#include "macros.h"
AtomChannelImage::AtomChannelImage(QXmlStreamReader *xmlReader)
{
Q_ASSERT(xmlReader != nullptr);
const QString urlTag{"url"};
const QString titleTag{"title"};
const QString linkTag{"link"};
const QString widthTag{"width"};
const QString heightTag{"height"};
while (!xmlReader->atEnd() && !xmlReader->hasError()) {
const auto itemNext = xmlReader->readNext();
switch (itemNext) {
case QXmlStreamReader::TokenType::StartElement: {
const auto name = xmlReader->name();
// qDebug() << __func__ << ":" << name;
const auto elementText = xmlReader->readElementText();
if (name == urlTag)
url = elementText;
else if (name == titleTag)
title = elementText;
else if (name == linkTag)
link = elementText;
else if (name == widthTag)
width = elementText.toInt();
else if (name == heightTag)
height = elementText.toInt();
break;
}
case QXmlStreamReader::TokenType::EndElement:
// qDebug() << "EndElement: " << xmlReader->name();
return;
case QXmlStreamReader::TokenType::Characters:
const auto characters = xmlReader->text().toString().simplified();
if (characters.isEmpty())
break;
qDebug() << "image: characters: " << characters;
break;
}
}
}
QDebug operator<<(QDebug debug, const AtomChannelImage &image)
{
QDebugStateSaver saver{debug};
debug.nospace() << typeid(AtomChannelImage).name() << " {" << Qt::endl;
PRINT_ATOM_FIELD(image, url);
PRINT_ATOM_FIELD(image, title);
PRINT_ATOM_FIELD(image, link);
PRINT_ATOM_FIELD(image, width);
PRINT_ATOM_FIELD(image, height);
debug.nospace() << "}";
return debug;
}
|