KReport

KReportDesign.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2001-2007 by OpenMFG, LLC <info@openmfg.com>
3 * Copyright (C) 2007-2010 by Adam Pigg <adam@piggz.co.uk>
4 * Copyright (C) 2011-2015 Jarosław Staniek <staniek@kde.org>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "KReportDesign.h"
21#include "KReportDesign_p.h"
22#include "KReportElement.h"
23#include "KReportUnit.h"
24#include "KReportUtils.h"
25#include "KReportPluginManager.h"
26#include "KReportPluginInterface.h"
27
28#include <QDomDocument>
29#include <QDomElement>
30#include <QPrinterInfo>
31
32class Q_DECL_HIDDEN KReportDesignReadingStatus::Private
33{
34public:
36 QString errorDetails;
37 int errorLineNumber = -1;
38 int errorColumnNumber = -1;
39};
40
44
45KReportDesignReadingStatus::~KReportDesignReadingStatus()
46{
47 delete d;
48}
49
51{
52 *this = other;
53}
54
55KReportDesignReadingStatus& KReportDesignReadingStatus::operator=(const KReportDesignReadingStatus &other)
56{
57 if (this != &other) {
58 setErrorMessage(other.errorMessage());
59 setErrorDetails(other.errorDetails());
60 setErrorLineNumber(other.errorLineNumber());
61 setErrorColumnNumber(other.errorColumnNumber());
62 }
63
64 return *this;
65}
66
67
69{
70 return d->errorLineNumber >= 0 && d->errorColumnNumber >= 0;
71}
72
74{
75 return d->errorColumnNumber;
76}
77
79{
80 return d->errorDetails;
81}
82
84{
85 return d->errorMessage;
86}
87
88
90{
91 return d->errorLineNumber;
92}
93
94void KReportDesignReadingStatus::setErrorColumnNumber(int column)
95{
96 d->errorColumnNumber = column;
97}
98
99void KReportDesignReadingStatus::setErrorDetails(const QString& details)
100{
101 d->errorDetails = details;
102}
103
104void KReportDesignReadingStatus::setErrorLineNumber(int line)
105{
106 d->errorLineNumber = line;
107}
108
109void KReportDesignReadingStatus::setErrorMessage(const QString& msg)
110{
111 d->errorMessage = msg;
112}
113
115{
116 if (status.isError()) {
117 dbg.nospace() << qPrintable(
118 QString::fromLatin1("KReportDesignReadingStatus: errorMessage=\"%1\" "
119 "errorDetails=\"%2\" line=%3 column=%4")
120 .arg(status.errorMessage()).arg(status.errorDetails())
121 .arg(status.errorLineNumber()).arg(status.errorColumnNumber()));
122 } else {
123 dbg.nospace() << "KReportDesignReadingStatus: OK";
124 }
125 return dbg.space();
126}
127
128//-----------------------------------
129
130KReportDesign::KReportDesign()
131 : d(new Private(this))
132{
133}
134
135KReportDesign::~KReportDesign()
136{
137 delete d;
138}
139
141{
142 QDomDocument doc;
143 QString errorDetails;
144 int errorLine;
145 int errorColumn;
146
147 if (!doc.setContent(text, &errorDetails, &errorLine, &errorColumn))
148 {
149 if (status) {
150 status->setErrorMessage(tr("Could not parse XML document."));
151 status->setErrorDetails(errorDetails);
152 status->setErrorLineNumber(errorLine);
153 status->setErrorColumnNumber(errorColumn);
154 }
155 return false;
156 }
157 bool ret = d->processDocument(doc, status);
158 if (!ret && status) {
159 status->setErrorMessage(tr("Error in XML document."));
160 }
161 return ret;
162}
163
165{
166 Q_UNUSED(indent);
167 //! @todo
168 return QString();
169}
170
172{
173 return d->pageLayout;
174}
175
177{
178 return d->title;
179}
180
182{
183 d->title = title;
184}
185
187{
188 d->pageLayout = pageLayout;
189 d->pageLayout.setUnits(QPageLayout::Point);
190}
191
193{
194 QDomElement el;
196 KReportPluginInterface* plugin = d->findPlugin(typeName, el, &status);
197 if (!plugin) {
198 if (errorMessage) {
199 *errorMessage = status.errorMessage();
200 }
201 return KReportElement();
202 }
203 return plugin->createElement();
204}
205
206bool KReportDesign::hasSection(KReportSection::Type type) const
207{
208 const int index = static_cast<int>(type) - 1;
209 if (0 <= index && index < d->sections.length()) {
210 return d->sections[index];
211 }
212 return false;
213}
214
215KReportSection KReportDesign::section(KReportSection::Type type) const
216{
217 const int index = static_cast<int>(type) - 1;
218 if (0 <= index && index < d->sections.length()) {
219 KReportSection *section = d->sections[index];
220 if (section) {
221 return *section;
222 }
223 }
224 return KReportSection();
225}
226
228{
229 const int index = static_cast<int>(section.type()) - 1;
230 if (0 <= index && index < d->sections.length()) {
231 if (d->sections[index]) {
232 *d->sections[index] = section;
233 } else {
234 d->sections[index] = new KReportSection(section);
235 }
236 }
237}
238
239// static
241{
242 QPageLayout layout = KReportDesignGlobal::self()->defaultPageLayout;
243 if (!layout.pageSize().isValid()) {
244 if (!QPrinterInfo::defaultPrinter().isNull()) {
245 layout.setPageSize(QPrinterInfo::defaultPrinter().defaultPageSize());
246 }
247 else {
248 layout.setPageSize(QPageSize(DEFAULT_PAGE_SIZE));
249 }
250 }
251 return layout;
252}
253
254// static
256{
257 KReportDesignGlobal::self()->defaultPageLayout = pageLayout;
258 KReportDesignGlobal::self()->defaultPageLayout.setUnits(QPageLayout::Point);
259}
260
261#ifdef KREPORT_SCRIPTING
262QString KReportDesign::script() const
263{
264 return d->script;
265}
266#endif
The KReportDesignReadStatus represents status of reading a report design in .kreport format.
QString errorDetails() const
Detailed error message, partially translated.
int errorLineNumber() const
Line number (counting from 0) in which the error occured. -1 if there is no error.
QString errorMessage() const
Error message suitable for displaying to the user, translated.
int errorColumnNumber() const
Column number (counting from 0) in which the error occured. -1 if there is no error.
KReportDesignReadingStatus()
Creates an empty status object.
void setPageLayout(const QPageLayout &pageLayout)
Sets the page layout to pageLayout.
static void setDefaultPageLayout(const QPageLayout &pageLayout)
Sets default page layout to pageLayout This information is used when a new report design is created.
QPageLayout pageLayout() const
QString toString(int indent=1) const
Converts the report document back to its textual representation.
QString title() const
static QPageLayout defaultPageLayout()
void addSection(const KReportSection &section)
Add section section. Previous section of the same type is removed from this design.
void setTitle(const QString &title)
Sets title for this design to title.
KReportSection section(KReportSection::Type type) const
bool hasSection(KReportSection::Type type) const
KReportElement createElement(const QString &typeName, QString *errorMessage)
Creates and returns report element of type typeName On success errorMessage is cleared,...
bool setContent(const QString &text, KReportDesignReadingStatus *status=nullptr)
Reads the XML document in .kreport format from the string text.
The KReportElement class represents a functional visual element of a report design.
An interface for plugins delivering KReport elements.
The KReportSection class represents a section of a report design.
KReportSection::Type type
Q_SCRIPTABLE CaptureState status()
KCALUTILS_EXPORT QString errorMessage(const KCalendarCore::Exception &exception)
QDebug operator<<(QDebug dbg, const PerceptualColor::LchaDouble &value)
QDebug & nospace()
QDebug & space()
bool setContent(const QByteArray &data, bool namespaceProcessing, QString *errorMsg, int *errorLine, int *errorColumn)
QPageSize pageSize() const const
void setPageSize(const QPageSize &pageSize, const QMarginsF &minMargins)
void setUnits(QPageLayout::Unit units)
bool isValid() const const
QPrinterInfo defaultPrinter()
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:48:09 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.