KD Reports API Documentation  2.2
KDReportsXmlHelper.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Reports library.
4 **
5 ** SPDX-FileCopyrightText: 2011 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
11 #include "KDReportsXmlHelper.h"
12 #include <QDebug>
13 #include <QDomElement>
14 
15 Qt::AlignmentFlag KDReports::XmlHelper::stringToAlignment(const QString &str)
16 {
17  if (str == QLatin1String("left"))
18  return Qt::AlignLeft;
19  else if (str == QLatin1String("right"))
20  return Qt::AlignRight;
21  else if (str == QLatin1String("hcenter"))
22  return Qt::AlignHCenter;
23  else
24  qWarning("Unexpected alignment flag in KDReports::Report::stringToAlignment(): %s", qPrintable(str));
25  return Qt::AlignLeft;
26 }
27 
29 {
30  if (type == QLatin1String("pagenumber"))
31  return KDReports::PageNumber;
32  else if (type == QLatin1String("pagecount"))
33  return KDReports::PageCount;
34  else if (type == QLatin1String("textdate"))
35  return KDReports::TextDate;
36  else if (type == QLatin1String("isodate"))
37  return KDReports::ISODate;
38  else if (type == QLatin1String("localedate"))
39  return KDReports::LocaleDate;
40  else if (type == QLatin1String("texttime"))
41  return KDReports::TextTime;
42  else if (type == QLatin1String("isotime"))
43  return KDReports::ISOTime;
44  else if (type == QLatin1String("localetime"))
45  return KDReports::LocaleTime;
46  qWarning("Unexpected variable type: %s", qPrintable(type));
47  return KDReports::PageNumber;
48 }
49 
50 QColor KDReports::XmlHelper::readColor(const QDomElement &element, const char *attributeName)
51 {
52  QColor ret;
53  const QString name = element.attribute(QLatin1String(attributeName));
54  if (!name.isEmpty()) {
55  ret = QColor(name);
56  }
57  return ret;
58 }
59 
60 QColor KDReports::XmlHelper::readBackground(const QDomElement &element)
61 {
62  QColor ret;
63  if (element.hasAttribute(QStringLiteral("background"))) {
64  const QString name = element.attribute(QStringLiteral("background"));
65  ret = QColor(name);
66  } else if (element.hasAttribute(QStringLiteral("bgred")) && element.hasAttribute(QStringLiteral("bggreen")) && element.hasAttribute(QStringLiteral("bgblue"))) {
67  int red = 0;
68  int green = 0;
69  int blue = 0;
70  bool ok = true;
71  red = element.attribute(QStringLiteral("bgred")).toInt(&ok);
72  if (ok) {
73  green = element.attribute(QStringLiteral("bggreen")).toInt(&ok);
74  if (ok) {
75  blue = element.attribute(QStringLiteral("bgblue")).toInt(&ok);
76  if (ok) {
77  ret.setRed(red);
78  ret.setGreen(green);
79  ret.setBlue(blue);
80  }
81  }
82  }
83  }
84  return ret;
85 }
86 
87 KDReports::HeaderLocations KDReports::XmlHelper::parseHeaderLocation(const QString &xmlAttr)
88 {
89  if (xmlAttr.isEmpty())
90  return KDReports::AllPages;
91  KDReports::HeaderLocations loc;
92  const QStringList tokens = xmlAttr.toLower().split(QLatin1Char(','));
93  for (const QString &s : tokens) {
94  QString token = s.trimmed();
95  if (token == QLatin1String("first"))
96  loc |= KDReports::FirstPage;
97  else if (token == QLatin1String("last"))
98  loc |= KDReports::LastPage;
99  else if (token == QLatin1String("odd"))
100  loc |= KDReports::OddPages;
101  else if (token == QLatin1String("even"))
102  loc |= KDReports::EvenPages;
103  else if (token == QLatin1String("all"))
104  loc |= KDReports::AllPages;
105  else
106  qWarning() << "Found unexpected token in header location attribute:" << token;
107  }
108  return loc;
109 }
static KDReports::VariableType stringToVariableType(const QString &type)
static Qt::AlignmentFlag stringToAlignment(const QString &str)
static QColor readBackground(const QDomElement &element)
static QColor readColor(const QDomElement &element, const char *attributeName)
static KDReports::HeaderLocations parseHeaderLocation(const QString &xmlAttr)
@ ISODate
names but unlocalized order of names and numbers
@ TextTime
Current time in text format like "13:42:59".
@ PageNumber
Page number.
@ LocaleDate
Current date in locale-dependent format, deprecated in favour of SystemLocaleShortDate or SystemLocal...
@ LocaleTime
Current time in locale-dependent format.
@ PageCount
Page count.
@ ISOTime
Current time in ISO 8601 format like "13:42:59".
@ AllPages
All pages (except first and last if FirstPage or LastPage have their own headers)
@ FirstPage
The first page of the report.
@ EvenPages
The even pages of the report: 2, 4, 6 etc.
@ LastPage
The last page of the report.
@ OddPages
The odd pages of the report: 1 (unless FirstPage has its own header), 3, 5, 7 etc.

© Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-reports/
Generated by doxygen 1.9.1