Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportDesign_p.cpp
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 44 | { | |||
---|---|---|---|---|---|
45 | qDeleteAll(sections); | 45 | qDeleteAll(sections); | ||
46 | } | 46 | } | ||
47 | 47 | | |||
48 | KReportDesignGlobal::KReportDesignGlobal() | 48 | KReportDesignGlobal::KReportDesignGlobal() | ||
49 | : defaultSectionHeight(CM_TO_POINT(2.0)) | 49 | : defaultSectionHeight(CM_TO_POINT(2.0)) | ||
50 | , defaultSectionBackgroundColor(Qt::white) | 50 | , defaultSectionBackgroundColor(Qt::white) | ||
51 | { | 51 | { | ||
52 | defaultPageLayout.setUnits(QPageLayout::Point); | 52 | defaultPageLayout.setUnits(QPageLayout::Point); | ||
53 | defaultPageLayout.setMargins(QMarginsF(DEFAULT_PAGE_MARGIN, | 53 | defaultPageLayout.setMargins(QMarginsF(DEFAULT_PAGE_MARGIN_PT, | ||
54 | DEFAULT_PAGE_MARGIN, | 54 | DEFAULT_PAGE_MARGIN_PT, | ||
55 | DEFAULT_PAGE_MARGIN, | 55 | DEFAULT_PAGE_MARGIN_PT, | ||
56 | DEFAULT_PAGE_MARGIN)); | 56 | DEFAULT_PAGE_MARGIN_PT)); | ||
57 | defaultPageLayout.setMode(QPageLayout::StandardMode); | 57 | defaultPageLayout.setMode(QPageLayout::StandardMode); | ||
58 | defaultPageLayout.setOrientation(DEFAULT_PAGE_ORIENTATION); | 58 | defaultPageLayout.setOrientation(DEFAULT_PAGE_ORIENTATION); | ||
59 | } | 59 | } | ||
60 | 60 | | |||
61 | KReportSection::Type KReportDesignGlobal::sectionType(const QString& typeName) { | 61 | KReportSection::Type KReportDesignGlobal::sectionType(const QString& typeName) { | ||
62 | initSectionTypes(); | 62 | initSectionTypes(); | ||
63 | return sectionTypesForName.value(typeName); // returns InvalidType for invalid name | 63 | return sectionTypesForName.value(typeName); // returns InvalidType for invalid name | ||
staniek: typefor -> type for | |||||
64 | } | 64 | } | ||
65 | 65 | | |||
66 | QString KReportDesignGlobal::sectionTypeName(KReportSection::Type sectionType) { | 66 | QString KReportDesignGlobal::sectionTypeName(KReportSection::Type sectionType) { | ||
67 | initSectionTypes(); | 67 | initSectionTypes(); | ||
68 | return sectionTypeNames.value(sectionType); | 68 | return sectionTypeNames.value(sectionType); | ||
69 | } | 69 | } | ||
70 | 70 | | |||
71 | void KReportDesignGlobal::initSectionTypes() { | 71 | void KReportDesignGlobal::initSectionTypes() { | ||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Line(s) | 120 | { | |||
121 | if (node.isElement()) { | 121 | if (node.isElement()) { | ||
122 | return true; | 122 | return true; | ||
123 | } | 123 | } | ||
124 | setStatus(status, QString::fromLatin1("Element expected inside of <%1>") | 124 | setStatus(status, QString::fromLatin1("Element expected inside of <%1>") | ||
125 | .arg(node.parentNode().toElement().tagName()), node); | 125 | .arg(node.parentNode().toElement().tagName()), node); | ||
126 | return false; | 126 | return false; | ||
127 | } | 127 | } | ||
128 | 128 | | |||
129 | static void setNoAttributeStatus(const QDomElement &el, const char *attrName, KReportDesignReadingStatus *status) | 129 | static void setNoAttributeStatus(const QDomElement &el, const QString &attrName, KReportDesignReadingStatus *status) | ||
130 | { | 130 | { | ||
131 | setStatus(status, QString::fromLatin1("Attribute \"%1\" expected inside of <%1>") | 131 | setStatus(status, QString::fromLatin1("Attribute \"%1\" expected inside of <%1>") | ||
staniek: Mistake: `<%1>` -> `<%2>` | |||||
132 | .arg(QLatin1String(attrName)).arg(el.tagName()), el); | 132 | .arg(attrName).arg(el.tagName()), el); | ||
133 | } | 133 | } | ||
134 | 134 | | |||
135 | #if 0 // TODO unused for now | 135 | #if 0 // TODO unused for now | ||
136 | static bool checkAttribute(const QDomElement &el, const char *attrName, KReportDesignReadingStatus *status) | 136 | static bool checkAttribute(const QDomElement &el, const char *attrName, KReportDesignReadingStatus *status) | ||
137 | { | 137 | { | ||
138 | if (el.hasAttribute(QLatin1String(attrName))) { | 138 | if (el.hasAttribute(QLatin1String(attrName))) { | ||
139 | return true; | 139 | return true; | ||
140 | } | 140 | } | ||
141 | setNoAttributeStatus(el, attrName, status); | 141 | setNoAttributeStatus(el, attrName, status); | ||
142 | return false; | 142 | return false; | ||
143 | } | 143 | } | ||
144 | #endif | 144 | #endif | ||
145 | 145 | | |||
146 | KReportSection KReportDesign::Private::processSectionElement(const QDomElement &el, | 146 | KReportSection KReportDesign::Private::processSectionElement(const QDomElement &el, | ||
147 | KReportDesignReadingStatus *status) | 147 | KReportDesignReadingStatus *status) | ||
148 | { | 148 | { | ||
149 | const QString sectionTypeName = KReportUtils::attr(el, "report:section-type", QString()); | 149 | qDebug() << el.nodeName(); | ||
150 | KReportSection::Type sectionType = s_global->sectionType(sectionTypeName); | 150 | const KReportSection::Type sectionType | ||
151 | = s_global->sectionType(KReportUtils::readSectionTypeNameAttribute(el)); | ||||
151 | if (sectionType == KReportSection::InvalidType) { | 152 | if (sectionType == KReportSection::InvalidType) { | ||
152 | setStatus(status, | 153 | setStatus(status, | ||
153 | QString::fromLatin1("Invalid value of report:section-type=\"%1\" in element <%2>") | 154 | QString::fromLatin1( | ||
154 | .arg(sectionTypeName).arg(el.tagName()), el); | 155 | "Invalid value of report:section-type=\"%1\" in element <%2>") | ||
156 | .arg(KReportUtils::readSectionTypeNameAttribute(el)) | ||||
157 | .arg(el.tagName()), | ||||
158 | el); | ||||
155 | return KReportSection(); | 159 | return KReportSection(); | ||
156 | } | 160 | } | ||
157 | KReportSection section; | 161 | KReportSection section; | ||
158 | section.setType(sectionType); | 162 | section.setType(sectionType); | ||
159 | qreal height = KReportUtils::attr(el, "svg:height", -1.0); | 163 | const QSizeF size(KReportUtils::readSizeAttributes(el)); | ||
160 | if (height >= 0.0) { | 164 | if (size.height() >= 0) { | ||
161 | section.setHeight(height); | 165 | section.setHeight(size.height()); | ||
162 | } | 166 | } | ||
163 | section.setBackgroundColor(QColor(KReportUtils::attr(el, "fo:background-color", QString()))); | 167 | section.setBackgroundColor( | ||
168 | KReportUtils::attr(el, QLatin1String("fo:background-color"), QColor())); | ||||
164 | for (QDomNode node = el.firstChild(); !node.isNull(); node = node.nextSibling()) { | 169 | for (QDomNode node = el.firstChild(); !node.isNull(); node = node.nextSibling()) { | ||
165 | if (!checkElement(node, status)) { | 170 | if (!checkElement(node, status)) { | ||
166 | return KReportSection(); | 171 | return KReportSection(); | ||
167 | } | 172 | } | ||
168 | KReportElement element = processSectionElementChild(node.toElement(), status); | 173 | KReportElement element = processSectionElementChild(node.toElement(), status); | ||
169 | if (!element.rect().isValid() || (status && status->isError())) { | 174 | if (!element.rect().isValid() || (status && status->isError())) { | ||
170 | return KReportSection(); | 175 | return KReportSection(); | ||
171 | } | 176 | } | ||
Show All 29 Lines | 196 | { | |||
201 | KReportPluginInterface *plugin = findPlugin(QLatin1String(reportElementName), el, status); | 206 | KReportPluginInterface *plugin = findPlugin(QLatin1String(reportElementName), el, status); | ||
202 | if (!plugin) { | 207 | if (!plugin) { | ||
203 | return KReportElement(); | 208 | return KReportElement(); | ||
204 | } | 209 | } | ||
205 | KReportElement element = plugin->createElement(); | 210 | KReportElement element = plugin->createElement(); | ||
206 | if (!plugin->loadElement(&element, el, status)) { | 211 | if (!plugin->loadElement(&element, el, status)) { | ||
207 | return KReportElement(); | 212 | return KReportElement(); | ||
208 | } | 213 | } | ||
209 | element.setName(KReportUtils::attr(el, "report:name", QString())); | 214 | element.setName(KReportUtils::readNameAttribute(el)); | ||
210 | if (element.name().isEmpty()) { | 215 | if (element.name().isEmpty()) { | ||
211 | setNoAttributeStatus(el, "report:name", status); | 216 | setNoAttributeStatus(el, QLatin1String("report:name"), status); | ||
212 | return KReportElement(); | 217 | return KReportElement(); | ||
213 | } | 218 | } | ||
214 | return element; | 219 | return element; | ||
215 | } | 220 | } | ||
216 | 221 | | |||
217 | bool KReportDesign::Private::processGroupElement(const QDomElement &el, | 222 | bool KReportDesign::Private::processGroupElement(const QDomElement &el, | ||
218 | KReportDesignReadingStatus *status) | 223 | KReportDesignReadingStatus *status) | ||
219 | { | 224 | { | ||
▲ Show 20 Lines • Show All 108 Lines • ▼ Show 20 Line(s) | 332 | { | |||
328 | const QByteArray name = el.tagName().toLatin1(); | 333 | const QByteArray name = el.tagName().toLatin1(); | ||
329 | QPageLayout defaultPageLayout = KReportDesign::defaultPageLayout(); | 334 | QPageLayout defaultPageLayout = KReportDesign::defaultPageLayout(); | ||
330 | //kreportDebug() << name; | 335 | //kreportDebug() << name; | ||
331 | if (name == "report:title") { | 336 | if (name == "report:title") { | ||
332 | title = el.text(); | 337 | title = el.text(); | ||
333 | #ifdef KREPORT_SCRIPTING | 338 | #ifdef KREPORT_SCRIPTING | ||
334 | } else if (name == "report:script") { | 339 | } else if (name == "report:script") { | ||
335 | script = el.firstChildElement().text(); | 340 | script = el.firstChildElement().text(); | ||
336 | originalInterpreter = KReportUtils::attr(el, "report:script-interpreter", QString()); | 341 | originalInterpreter = KReportUtils::attr( | ||
342 | el, QLatin1String("report:script-interpreter"), QString()); | ||||
337 | #endif | 343 | #endif | ||
338 | } else if (name == "report:grid") { | 344 | } else if (name == "report:grid") { | ||
339 | showGrid = KReportUtils::attr(el, "report:grid-visible", DEFAULT_SHOW_GRID); | 345 | showGrid = KReportUtils::attr( | ||
340 | snapToGrid = KReportUtils::attr(el, "report:grid-snap", DEFAULT_SNAP_TO_GRID); | 346 | el, QLatin1String("report:grid-visible"), DEFAULT_SHOW_GRID); | ||
341 | gridDivisions = KReportUtils::attr(el, "report:grid-divisions", DEFAULT_GRID_DIVISIONS); | 347 | snapToGrid = KReportUtils::attr( | ||
342 | const QString pageUnitString = KReportUtils::attr(el, "report:page-unit", QString()); | 348 | el, QLatin1String("report:grid-snap"), DEFAULT_SNAP_TO_GRID); | ||
349 | gridDivisions = KReportUtils::attr( | ||||
350 | el, QLatin1String("report:grid-divisions"), DEFAULT_GRID_DIVISIONS); | ||||
351 | const QString pageUnitString | ||||
352 | = KReportUtils::attr(el, QLatin1String("report:page-unit"), QString()); | ||||
343 | bool found; | 353 | bool found; | ||
344 | pageUnit = KReportUnit::fromSymbol(pageUnitString, &found); | 354 | pageUnit = KReportUnit::fromSymbol(pageUnitString, &found); | ||
345 | if (!found) { | 355 | if (!found) { | ||
346 | pageUnit = DEFAULT_UNIT; | 356 | pageUnit = DEFAULT_UNIT; | ||
347 | if (!pageUnitString.isEmpty()) { | 357 | if (!pageUnitString.isEmpty()) { | ||
348 | qWarning() << "Invalid page unit" << pageUnitString << "specified in" << name | 358 | qWarning() << "Invalid page unit" << pageUnitString << "specified in" << name | ||
349 | << "element, defaulting to" << pageUnit.symbol(); | 359 | << "element, defaulting to" << pageUnit.symbol(); | ||
350 | } | 360 | } | ||
351 | } | 361 | } | ||
352 | } | 362 | } | ||
353 | else if (name == "report:page-style") { // see https://git.reviewboard.kde.org/r/115314 | 363 | else if (name == "report:page-style") { // see https://git.reviewboard.kde.org/r/115314 | ||
354 | const QByteArray pagetype = el.text().toLatin1(); | 364 | const QByteArray pagetype = el.text().toLatin1(); | ||
355 | if (pagetype == "predefined") { | 365 | if (pagetype == "predefined") { | ||
356 | pageLayout.setPageSize( | 366 | pageLayout.setPageSize(KReportUtils::pageSize( | ||
357 | KReportUtils::pageSize(KReportUtils::attr(el, "report:page-size", | 367 | KReportUtils::attr(el, QLatin1String("report:page-size"), | ||
358 | QPageSize(DEFAULT_PAGE_SIZE).key()))); | 368 | QPageSize(DEFAULT_PAGE_SIZE).key()))); | ||
359 | } else if (pagetype.isEmpty() || pagetype == "custom") { | 369 | } else if (pagetype.isEmpty() || pagetype == "custom") { | ||
360 | QSizeF size(KReportUtils::attr(el, "fo:page-width", -1.0), | 370 | QSizeF size(KReportUtils::attr(el, QLatin1String("fo:page-width"), -1.0), | ||
361 | KReportUtils::attr(el, "fo:page-height", -1.0)); | 371 | KReportUtils::attr(el, QLatin1String("fo:page-height"), -1.0)); | ||
362 | if (size.isValid()) { | 372 | if (size.isValid()) { | ||
363 | pageLayout.setPageSize(QPageSize(size, QPageSize::Point)); | 373 | pageLayout.setPageSize(QPageSize(size, QPageSize::Point)); | ||
364 | } else { | 374 | } else { | ||
365 | pageLayout.setPageSize(defaultPageLayout.pageSize()); | 375 | pageLayout.setPageSize(defaultPageLayout.pageSize()); | ||
366 | } | 376 | } | ||
367 | } else if (pagetype == "label") { | 377 | } else if (pagetype == "label") { | ||
368 | //! @todo? | 378 | //! @todo? | ||
369 | pageLayout.setPageSize(defaultPageLayout.pageSize()); | 379 | pageLayout.setPageSize(defaultPageLayout.pageSize()); | ||
370 | } | 380 | } | ||
371 | QMarginsF margins(KReportUtils::attr(el, "fo:margin-left", defaultPageLayout.margins().left()), | 381 | QMarginsF margins(KReportUtils::attr(el, QLatin1String("fo:margin-left"), | ||
372 | KReportUtils::attr(el, "fo:margin-top", defaultPageLayout.margins().top()), | 382 | defaultPageLayout.margins().left()), | ||
373 | KReportUtils::attr(el, "fo:margin-right", defaultPageLayout.margins().right()), | 383 | KReportUtils::attr(el, QLatin1String("fo:margin-top"), | ||
374 | KReportUtils::attr(el, "fo:margin-bottom", defaultPageLayout.margins().bottom())); | 384 | defaultPageLayout.margins().top()), | ||
385 | KReportUtils::attr(el, QLatin1String("fo:margin-right"), | ||||
386 | defaultPageLayout.margins().right()), | ||||
387 | KReportUtils::attr(el, QLatin1String("fo:margin-bottom"), | ||||
388 | defaultPageLayout.margins().bottom())); | ||||
375 | bool b = pageLayout.setMargins(margins); | 389 | bool b = pageLayout.setMargins(margins); | ||
376 | if (!b) { | 390 | if (!b) { | ||
377 | qWarning() << "Failed to set page margins to" << margins; | 391 | qWarning() << "Failed to set page margins to" << margins; | ||
378 | } | 392 | } | ||
379 | const QString s = KReportUtils::attr(el, "report:print-orientation", QString()); | 393 | const QString s = KReportUtils::attr( | ||
394 | el, QLatin1String("report:print-orientation"), QString()); | ||||
380 | if (s == QLatin1String("portrait")) { | 395 | if (s == QLatin1String("portrait")) { | ||
381 | pageLayout.setOrientation(QPageLayout::Portrait); | 396 | pageLayout.setOrientation(QPageLayout::Portrait); | ||
382 | } else if (s == QLatin1String("landscape")) { | 397 | } else if (s == QLatin1String("landscape")) { | ||
383 | pageLayout.setOrientation(QPageLayout::Landscape); | 398 | pageLayout.setOrientation(QPageLayout::Landscape); | ||
384 | } | 399 | } | ||
385 | else { | 400 | else { | ||
386 | pageLayout.setOrientation(defaultPageLayout.orientation()); | 401 | pageLayout.setOrientation(defaultPageLayout.orientation()); | ||
387 | } | 402 | } | ||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |
typefor -> type for