KReport

KReportUtils.h
1/* This file is part of the KDE project
2 Copyright (C) 2010-2015 Jarosław Staniek <staniek@kde.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18*/
19
20#ifndef KREPORTUTILS_H
21#define KREPORTUTILS_H
22
23#include "kreport_export.h"
24
25#include <QPageSize>
26#include <QRectF>
27#include <QColor>
28#include <QFont>
29
30class QDomDocument;
31class QDomElement;
32class QFont;
33class QPointF;
34class KProperty;
35class KReportTextStyleData;
37
38namespace KReportUtils
39{
40 KREPORT_EXPORT QString attr(const QDomElement &el, const QString &attrName,
41 const QString &defaultValue = QString());
42
43 KREPORT_EXPORT QByteArray attr(const QDomElement &el, const QString &attrName,
44 const QByteArray &defaultValue = QByteArray());
45
46 KREPORT_EXPORT bool attr(const QDomElement &el, const QString &attrName, bool defaultValue = false);
47
48 KREPORT_EXPORT int attr(const QDomElement &el, const QString &attrName, int defaultValue = 0);
49
50 KREPORT_EXPORT qreal attr(const QDomElement &el, const QString &attrName, qreal defaultValue = 0.0);
51
52 KREPORT_EXPORT QColor attr(const QDomElement &el, const QString &attrName, const QColor &defaultValue = QColor());
53
54 //! @return percent value converted to qreal, e.g. 1.0 for "100%", 0.505 for "50.5%".
55 //! @a defaultValue is returned if there is not "%" suffix or no proper number.
56 KREPORT_EXPORT qreal attrPercent(const QDomElement& el, const QString &attrName, qreal defaultValue = 0.0);
57
58 //! @return pen style from @a str or @a defaultValue
59 //! Values from ODF 1.2 19.493 style:line-style are also recognized.
60 KREPORT_EXPORT Qt::PenStyle penStyle(const QString &str, Qt::PenStyle defaultValue);
61
62 //! @return vertical alignment flag from @a str or @a defaultValue
63 KREPORT_EXPORT Qt::Alignment verticalAlignment(const QString &str, Qt::Alignment defaultValue);
64
65 //! @return horizontal alignment flag from @a str or @a defaultValue
66 KREPORT_EXPORT Qt::Alignment horizontalAlignment(const QString &str, Qt::Alignment defaultValue);
67
68 //! @return vertical alignment flag name from @a alignment
69 KREPORT_EXPORT QString verticalToString(Qt::Alignment alignment);
70
71 //! @return horizontal alignment flag from @a alignment
72 KREPORT_EXPORT QString horizontalToString(Qt::Alignment alignment);
73
74 //! @return name value read from report:name attribute of @a el.
75 //! If the attribute is missing, @a defaultValue is returned.
76 KREPORT_EXPORT QString readNameAttribute(
77 const QDomElement &el, const QString &defaultValue = QString());
78
79 //! @return size value read from svg:width and svg:height attributes of @a el.
80 //! If any of the attributes are missing, @a defaultValue is returned.
81 //! @a defaultValue should be specified in Points.
82 KREPORT_EXPORT QSizeF readSizeAttributes(
83 const QDomElement &el, const QSizeF &defaultValue = QSizeF());
84
85 //! @return rectangle value read from svg:x, svg:y, svg:width, svg:height attributes of @a el.
86 //! If any of the attributes are missing, @a defaultValue is returned.
87 //! @a defaultValue should be specified in Points.
88 KREPORT_EXPORT QRectF readRectAttributes(
89 const QDomElement &el, const QRectF &defaultValue = QRectF());
90
91 //! @return Z index value read from report:z-index attribute of @a el.
92 //! If the attribute is missing @a defaultValue is returned.
93 //! @a defaultValue should be specified in Points.
94 KREPORT_EXPORT qreal readZAttribute(const QDomElement &el, qreal defaultValue = 0.0);
95
96 //! @return name of section type read from report:section-type attribute of @a el.
97 //! If the attribute is missing, @a defaultValue is returned.
98 KREPORT_EXPORT QString readSectionTypeNameAttribute(
99 const QDomElement &el, const QString &defaultValue = QString());
100
101 //! @return percent value for element @a name. If the element is missing, returns @a defaultPercentValue.
102 //! If @a ok is not 0, *ok is set to the result.
103 KREPORT_EXPORT int readPercent(const QDomElement &el, const QString &attrName,
104 int defaultPercentValue, bool *ok);
105
106 //! Reads all font attributes for element @a el into @a font.
107 //! @todo add unit tests
108 KREPORT_EXPORT void readFontAttributes(const QDomElement& el, QFont* font);
109
110 //! Writes all attributes of font @a font into element @a el.
111 //! @todo add unit tests
112 KREPORT_EXPORT void writeFontAttributes(QDomElement *el, const QFont &font);
113
114 //! Writes attributes for the rect position @a pos, @a siz
115 KREPORT_EXPORT void buildXMLRect(QDomElement *entity, const QPointF &pos, const QSizeF &size);
116
117 //! Writes attributes for text style @a ts
118 KREPORT_EXPORT void buildXMLTextStyle(QDomDocument *doc, QDomElement *entity, const KReportTextStyleData &ts);
119
120 //! Writes attributes for line style @a ls
121 KREPORT_EXPORT void buildXMLLineStyle(QDomDocument *doc, QDomElement *entity, const KReportLineStyle &ls);
122
123 //! Writes attributes for the property @a p
124 KREPORT_EXPORT void addPropertyAsAttribute(QDomElement* e, KProperty* p);
125
126 /**
127 * Sets value of property @a p if element @e e has attribute named report:X where X is the name of @a p.
128 *
129 * Otherwise it does nothing and return @c false.
130 */
131 KREPORT_EXPORT bool setPropertyValue(KProperty *p, const QDomElement &e);
132
133 //! Writes @a attribute to element @a e, @a value is stored in points with unit 'pt'
134 KREPORT_EXPORT void setAttribute(QDomElement *e, const QString &attribute, double value);
135
136 //! Writes point @a value as attributes to element @a e
137 KREPORT_EXPORT void setAttribute(QDomElement *e, const QPointF &value);
138
139 //! Writes size @a value as attributes to element @a e
140 KREPORT_EXPORT void setAttribute(QDomElement *e, const QSizeF &value);
141
142 //! Writes @a attribute to element @a e, @a value is stored as boolean
143 KREPORT_EXPORT void setAttribute(QDomElement *e, const QString &attribute, bool value);
144
145 //! Reads attributes from @a elemSource into text style @a ts
146 KREPORT_EXPORT bool parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts);
147
148 //! Reads attributes from @a elemSource into line style @a ls
149 KREPORT_EXPORT bool parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls);
150
151 //! @return page size ID for page key (the PPD standard mediaOption keyword, e.g. "A4")
152 //! @note It's an efficient workaround because QPageSize misses this function.
153 KREPORT_EXPORT QPageSize::PageSizeId pageSizeId(const QString &key);
154
155 //! Like QPageSize::PageSizeId pageSizeId(const QString &key) but returns entire QPageSize object.
156 KREPORT_EXPORT QPageSize pageSize(const QString &key);
157} // KReportUtils
158
159#endif
The KReportLineStyle class represents line style.
KREPORT_EXPORT QPageSize::PageSizeId pageSize(const QString &key)
typedef Alignment
PenStyle
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:19:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.