Attica

eventparser.cpp
1 /*
2  This file is part of KDE.
3 
4  SPDX-FileCopyrightText: 2009 Eckhart W├Ârner <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8 
9 #include "eventparser.h"
10 
11 #include <QRegularExpression>
12 
13 using namespace Attica;
14 
15 Event Event::Parser::parseXml(QXmlStreamReader &xml)
16 {
17  Event event;
18 
19  while (!xml.atEnd()) {
20  xml.readNext();
21 
22  if (xml.isStartElement()) {
23  if (xml.name() == QLatin1String("id")) {
24  event.setId(xml.readElementText());
25  } else if (xml.name() == QLatin1String("name")) {
26  event.setName(xml.readElementText());
27  } else if (xml.name() == QLatin1String("description")) {
28  event.setDescription(xml.readElementText());
29  } else if (xml.name() == QLatin1String("user")) {
30  event.setUser(xml.readElementText());
31  } else if (xml.name() == QLatin1String("startdate")) {
32  QString date = xml.readElementText().remove(QRegularExpression(QStringLiteral("\\+.*$")));
33  event.setStartDate(QDate::fromString(date, Qt::ISODate));
34  } else if (xml.name() == QLatin1String("enddate")) {
35  QString date = xml.readElementText().remove(QRegularExpression(QStringLiteral("\\+.*$")));
36  event.setEndDate(QDate::fromString(date, Qt::ISODate));
37  } else if (xml.name() == QLatin1String("latitude")) {
38  event.setLatitude(xml.readElementText().toFloat());
39  } else if (xml.name() == QLatin1String("longitude")) {
40  event.setLongitude(xml.readElementText().toFloat());
41  } else if (xml.name() == QLatin1String("homepage")) {
42  event.setHomepage(QUrl(xml.readElementText()));
43  } else if (xml.name() == QLatin1String("country")) {
44  event.setCountry(xml.readElementText());
45  } else if (xml.name() == QLatin1String("city")) {
46  event.setCity(xml.readElementText());
47  } else {
48  event.addExtendedAttribute(xml.name().toString(), xml.readElementText());
49  }
50  } else if (xml.isEndElement() && xml.name() == QLatin1String("event")) {
51  break;
52  }
53  }
54 
55  return event;
56 }
57 
58 QStringList Event::Parser::xmlElement() const
59 {
60  return QStringList(QStringLiteral("event"));
61 }
bool atEnd() const const
QString toString() const const
Represents a single event.
Definition: event.h:26
QString & remove(int position, int n)
QDate fromString(const QString &string, Qt::DateFormat format)
QString readElementText(QXmlStreamReader::ReadElementTextBehaviour behaviour)
QXmlStreamReader::TokenType readNext()
bool isStartElement() const const
float toFloat(bool *ok) const const
QStringRef name() const const
bool isEndElement() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Jan 25 2021 23:06:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.