Changeset View
Changeset View
Standalone View
Standalone View
src/common/KReportDesign_p.cpp
Show All 28 Lines | |||||
29 | #include <QSizeF> | 29 | #include <QSizeF> | ||
30 | 30 | | |||
31 | KReportDesign::Private::Private(KReportDesign *design) | 31 | KReportDesign::Private::Private(KReportDesign *design) | ||
32 | : q(design) | 32 | : q(design) | ||
33 | , showGrid(DEFAULT_SHOW_GRID) | 33 | , showGrid(DEFAULT_SHOW_GRID) | ||
34 | , snapToGrid(DEFAULT_SNAP_TO_GRID) | 34 | , snapToGrid(DEFAULT_SNAP_TO_GRID) | ||
35 | , gridDivisions(DEFAULT_GRID_DIVISIONS) | 35 | , gridDivisions(DEFAULT_GRID_DIVISIONS) | ||
36 | , pageUnit(DEFAULT_UNIT) | 36 | , pageUnit(DEFAULT_UNIT) | ||
37 | , sections(KReportSection::Detail) | 37 | , sections(static_cast<int>(KReportSection::Type::Detail)) | ||
38 | { | 38 | { | ||
39 | memset(static_cast<void*>(sections.data()), 0, sizeof(void*) * sections.length()); | 39 | memset(static_cast<void*>(sections.data()), 0, sizeof(void*) * sections.length()); | ||
40 | pageLayout.setUnits(QPageLayout::Point); // initializate because of https://bugreports.qt.io/browse/QTBUG-47551 | 40 | pageLayout.setUnits(QPageLayout::Point); // initializate because of https://bugreports.qt.io/browse/QTBUG-47551 | ||
41 | } | 41 | } | ||
42 | 42 | | |||
43 | KReportDesign::Private::~Private() | 43 | KReportDesign::Private::~Private() | ||
44 | { | 44 | { | ||
45 | qDeleteAll(sections); | 45 | qDeleteAll(sections); | ||
Show All 9 Lines | 53 | defaultPageLayout.setMargins(QMarginsF(DEFAULT_PAGE_MARGIN, | |||
55 | DEFAULT_PAGE_MARGIN, | 55 | DEFAULT_PAGE_MARGIN, | ||
56 | DEFAULT_PAGE_MARGIN)); | 56 | DEFAULT_PAGE_MARGIN)); | ||
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 Invalid typefor invalid name | ||
64 | } | ||||
65 | | ||||
66 | inline uint qHash(KReportSection::Type sectionType, uint seed = 0) | ||||
67 | { | ||||
68 | return qHash(static_cast<uint>(sectionType), seed); | ||||
64 | } | 69 | } | ||
65 | 70 | | |||
66 | QString KReportDesignGlobal::sectionTypeName(KReportSection::Type sectionType) { | 71 | QString KReportDesignGlobal::sectionTypeName(KReportSection::Type sectionType) { | ||
67 | initSectionTypes(); | 72 | initSectionTypes(); | ||
68 | return sectionTypeNames.value(sectionType); | 73 | return sectionTypeNames.value(sectionType); | ||
69 | } | 74 | } | ||
70 | 75 | | |||
71 | void KReportDesignGlobal::initSectionTypes() { | 76 | void KReportDesignGlobal::initSectionTypes() { | ||
72 | if (!sectionTypesForName.isEmpty()) { | 77 | if (!sectionTypesForName.isEmpty()) { | ||
73 | return; | 78 | return; | ||
74 | } | 79 | } | ||
75 | for (const SectionTypeInfo *info = sectionTypes; info->name; ++info) { | 80 | for (const SectionTypeInfo *info = sectionTypes; info->name; ++info) { | ||
76 | sectionTypesForName.insert(QString::fromLatin1(info->name), info->type); | 81 | sectionTypesForName.insert(QString::fromLatin1(info->name), info->type); | ||
77 | sectionTypeNames.insert(info->type, QString::fromLatin1(info->name)); | 82 | sectionTypeNames.insert(info->type, QString::fromLatin1(info->name)); | ||
78 | } | 83 | } | ||
79 | } | 84 | } | ||
80 | 85 | | |||
81 | const KReportDesignGlobal::SectionTypeInfo KReportDesignGlobal::sectionTypes[] = { | 86 | const KReportDesignGlobal::SectionTypeInfo KReportDesignGlobal::sectionTypes[] = { | ||
82 | { KReportSection::InvalidType, "" }, | 87 | { KReportSection::Type::Invalid, "" }, | ||
83 | { KReportSection::PageHeaderAny, "header-page-any" }, | 88 | { KReportSection::Type::PageHeaderAny, "header-page-any" }, | ||
84 | { KReportSection::PageHeaderEven, "header-page-even" }, | 89 | { KReportSection::Type::PageHeaderEven, "header-page-even" }, | ||
85 | { KReportSection::PageHeaderOdd, "header-page-odd" }, | 90 | { KReportSection::Type::PageHeaderOdd, "header-page-odd" }, | ||
86 | { KReportSection::PageHeaderFirst, "header-page-first" }, | 91 | { KReportSection::Type::PageHeaderFirst, "header-page-first" }, | ||
87 | { KReportSection::PageHeaderLast, "header-page-last" }, | 92 | { KReportSection::Type::PageHeaderLast, "header-page-last" }, | ||
88 | { KReportSection::PageFooterAny, "footer-page-any" }, | 93 | { KReportSection::Type::PageFooterAny, "footer-page-any" }, | ||
89 | { KReportSection::PageFooterEven, "footer-page-even" }, | 94 | { KReportSection::Type::PageFooterEven, "footer-page-even" }, | ||
90 | { KReportSection::PageFooterOdd, "footer-page-odd" }, | 95 | { KReportSection::Type::PageFooterOdd, "footer-page-odd" }, | ||
91 | { KReportSection::PageFooterFirst, "footer-page-first" }, | 96 | { KReportSection::Type::PageFooterFirst, "footer-page-first" }, | ||
92 | { KReportSection::PageFooterLast, "footer-page-last" }, | 97 | { KReportSection::Type::PageFooterLast, "footer-page-last" }, | ||
93 | { KReportSection::ReportHeader, "header-report" }, | 98 | { KReportSection::Type::ReportHeader, "header-report" }, | ||
94 | { KReportSection::ReportFooter, "footer-report" }, | 99 | { KReportSection::Type::ReportFooter, "footer-report" }, | ||
95 | { KReportSection::GroupHeader, "group-header" }, | 100 | { KReportSection::Type::GroupHeader, "group-header" }, | ||
96 | { KReportSection::GroupFooter, "group-footer" }, | 101 | { KReportSection::Type::GroupFooter, "group-footer" }, | ||
97 | { KReportSection::Detail, "detail" }, | 102 | { KReportSection::Type::Detail, "detail" }, | ||
98 | { KReportSection::InvalidType, nullptr } | 103 | { KReportSection::Type::Invalid, nullptr } | ||
99 | }; | 104 | }; | ||
100 | 105 | | |||
101 | Q_GLOBAL_STATIC(KReportDesignGlobal, s_global) | 106 | Q_GLOBAL_STATIC(KReportDesignGlobal, s_global) | ||
102 | 107 | | |||
103 | //static | 108 | //static | ||
104 | KReportDesignGlobal* KReportDesignGlobal::self() | 109 | KReportDesignGlobal* KReportDesignGlobal::self() | ||
105 | { | 110 | { | ||
106 | return s_global; | 111 | return s_global; | ||
Show All 36 Lines | |||||
143 | } | 148 | } | ||
144 | #endif | 149 | #endif | ||
145 | 150 | | |||
146 | KReportSection KReportDesign::Private::processSectionElement(const QDomElement &el, | 151 | KReportSection KReportDesign::Private::processSectionElement(const QDomElement &el, | ||
147 | KReportDesignReadingStatus *status) | 152 | KReportDesignReadingStatus *status) | ||
148 | { | 153 | { | ||
149 | const QString sectionTypeName = KReportUtils::attr(el, "report:section-type", QString()); | 154 | const QString sectionTypeName = KReportUtils::attr(el, "report:section-type", QString()); | ||
150 | KReportSection::Type sectionType = s_global->sectionType(sectionTypeName); | 155 | KReportSection::Type sectionType = s_global->sectionType(sectionTypeName); | ||
151 | if (sectionType == KReportSection::InvalidType) { | 156 | if (sectionType == KReportSection::Type::Invalid) { | ||
152 | setStatus(status, | 157 | setStatus(status, | ||
153 | QString::fromLatin1("Invalid value of report:section-type=\"%1\" in element <%2>") | 158 | QString::fromLatin1("Invalid value of report:section-type=\"%1\" in element <%2>") | ||
154 | .arg(sectionTypeName).arg(el.tagName()), el); | 159 | .arg(sectionTypeName).arg(el.tagName()), el); | ||
155 | return KReportSection(); | 160 | return KReportSection(); | ||
156 | } | 161 | } | ||
157 | KReportSection section; | 162 | KReportSection section; | ||
158 | section.setType(sectionType); | 163 | section.setType(sectionType); | ||
159 | qreal height = KReportUtils::attr(el, "svg:height", -1.0); | 164 | qreal height = KReportUtils::attr(el, "svg:height", -1.0); | ||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Line(s) | 237 | for (QDomNode node = el.firstChild(); !node.isNull(); node = node.nextSibling()) { | |||
238 | if (name == "report:section") { | 243 | if (name == "report:section") { | ||
239 | if (!sectionEl.isNull()) { | 244 | if (!sectionEl.isNull()) { | ||
240 | return false; | 245 | return false; | ||
241 | } | 246 | } | ||
242 | KReportSection section = processSectionElement(childEl, status); | 247 | KReportSection section = processSectionElement(childEl, status); | ||
243 | if (status && status->isError()) { | 248 | if (status && status->isError()) { | ||
244 | return false; | 249 | return false; | ||
245 | } | 250 | } | ||
246 | if (section.type() != KReportSection::Detail) { | 251 | if (section.type() != KReportSection::Type::Detail) { | ||
247 | setStatus(status, | 252 | setStatus(status, | ||
248 | QString::fromLatin1("Only section of type \"detail\" allowed in <report:detail>"), el); | 253 | QString::fromLatin1("Only section of type \"detail\" allowed in <report:detail>"), el); | ||
249 | return false; | 254 | return false; | ||
250 | } | 255 | } | ||
251 | q->addSection(section); | 256 | q->addSection(section); | ||
252 | } | 257 | } | ||
253 | else if (name == "report:group") { | 258 | else if (name == "report:group") { | ||
254 | if (!processGroupElement(childEl, status)) { | 259 | if (!processGroupElement(childEl, status)) { | ||
Show All 35 Lines | 294 | if (status && status->isError()) { | |||
290 | return false; | 295 | return false; | ||
291 | } | 296 | } | ||
292 | if (q->hasSection(section.type())) { | 297 | if (q->hasSection(section.type())) { | ||
293 | setStatus(status, QString::fromLatin1("Could not add two sections of type \"%1\" " | 298 | setStatus(status, QString::fromLatin1("Could not add two sections of type \"%1\" " | ||
294 | "to the same report design") | 299 | "to the same report design") | ||
295 | .arg(s_global->sectionTypeName(section.type())), el); | 300 | .arg(s_global->sectionTypeName(section.type())), el); | ||
296 | return false; | 301 | return false; | ||
297 | } | 302 | } | ||
298 | if (section.type() == KReportSection::Detail) { | 303 | if (section.type() == KReportSection::Type::Detail) { | ||
299 | setStatus(status, | 304 | setStatus(status, | ||
300 | QString::fromLatin1("Section of type \"detail\" not allowed in <report:body>"), el); | 305 | QString::fromLatin1("Section of type \"detail\" not allowed in <report:body>"), el); | ||
301 | return false; | 306 | return false; | ||
302 | } | 307 | } | ||
303 | q->addSection(section); | 308 | q->addSection(section); | ||
304 | #if 0 //TODO | 309 | #if 0 //TODO | ||
305 | if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) { | 310 | if (section(KReportSectionData::sectionTypeFromString(sectiontype)) == 0) { | ||
306 | insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); | 311 | insertSection(KReportSectionData::sectionTypeFromString(sectiontype)); | ||
▲ Show 20 Lines • Show All 152 Lines • Show Last 20 Lines |