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

© 2007-2021 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 on Sat Jan 8 2022 02:38:32 for KD Reports API Documentation by doxygen 1.8.17