KReport

KReportDetailSectionData.cpp
1 /* This file is part of the KDE project
2  * Copyright (C) 2001-2007 by OpenMFG, LLC ([email protected])
3  * Copyright (C) 2007-2008 by Adam Pigg ([email protected])
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #include "KReportDetailSectionData.h"
20 #include "KReportSectionData.h"
21 #include "KReportDocument.h"
22 #include "KReportUtils.h"
23 
24 #include "kreport_debug.h"
25 #include <QDomElement>
26 
27 KReportDetailSectionData::KReportDetailSectionData(QObject *parent)
28  : QObject(parent)
29 {
30  pageBreak = PageBreak::None;
31  detailSection = nullptr;
32  m_valid = true;
33 }
34 
35 KReportDetailSectionData::KReportDetailSectionData(const QDomElement &elemSource, KReportDocument *report)
36  : QObject(report)
37 {
38  pageBreak = PageBreak::None;
39  detailSection = nullptr;
40  m_valid = false;
41  //kreportDebug() << elemSource.tagName();
42  if (elemSource.tagName() != QLatin1String("report:detail")) {
43  return;
44  }
45 
46  QDomNodeList sections = elemSource.childNodes();
47 
48  for (int nodeCounter = 0; nodeCounter < sections.count(); nodeCounter++) {
49  QDomElement elemThis = sections.item(nodeCounter).toElement();
50 
51  if (elemThis.tagName() == QLatin1String("report:group")) {
52  KReportDetailGroupSectionData * dgsd = new KReportDetailGroupSectionData();
53 
54  if ( elemThis.hasAttribute( QLatin1String("report:group-column") ) ) {
55  dgsd->column = elemThis.attribute( QLatin1String("report:group-column") );
56  }
57 
58  if ( elemThis.hasAttribute( QLatin1String("report:group-page-break") ) ) {
59  QString s = elemThis.attribute( QLatin1String("report:group-page-break") );
60  if ( s == QLatin1String("after-footer") ) {
61  dgsd->pagebreak = KReportDetailGroupSectionData::PageBreak::AfterGroupFooter;
62  } else if ( s == QLatin1String("before-header") ) {
63  dgsd->pagebreak = KReportDetailGroupSectionData::PageBreak::BeforeGroupHeader;
64  } else {
65  dgsd->pagebreak = KReportDetailGroupSectionData::PageBreak::None;
66  }
67  }
68 
69  if (elemThis.attribute(QLatin1String("report:group-sort"), QLatin1String("ascending")) == QLatin1String("ascending")) {
70  dgsd->m_sort = Qt::AscendingOrder;
71  } else {
72  dgsd->m_sort = Qt::DescendingOrder;
73  }
74 
75  for ( QDomElement e = elemThis.firstChildElement( QLatin1String("report:section") ); ! e.isNull(); e = e.nextSiblingElement( QLatin1String("report:section") ) ) {
76  const QString s = KReportUtils::readSectionTypeNameAttribute(e);
77  if ( s == QLatin1String("group-header") ) {
78  KReportSectionData * sd = new KReportSectionData(e, report);
79  if (sd->isValid()) {
80  dgsd->groupHeader = sd;
81  } else {
82  delete sd;
83  }
84  } else if ( s == QLatin1String("group-footer") ) {
85  KReportSectionData * sd = new KReportSectionData(e, report);
86  if (sd->isValid()) {
87  dgsd->groupFooter = sd;
88  } else {
89  delete sd;
90  }
91  }
92  }
93  groupList.append(dgsd);
95  s.setField(dgsd->column);
96  s.setOrder(dgsd->m_sort);
97 
98  sortedFields.append(s);
99  } else if (elemThis.tagName() == QLatin1String("report:section")
100  && KReportUtils::readSectionTypeNameAttribute(elemThis)
101  == QLatin1String("detail"))
102  {
103  KReportSectionData *sd = new KReportSectionData(elemThis, report);
104  if (sd->isValid()) {
105  detailSection = sd;
106  } else
107  delete sd;
108  } else {
109  kreportWarning() << "While parsing detail section encountered an unknown element: " << elemThis.tagName();
110  }
111  }
112 
113  m_valid = true;
114 }
115 
116 KReportDetailSectionData::~KReportDetailSectionData()
117 {
118 }
119 
120 KReportDetailGroupSectionData::KReportDetailGroupSectionData()
121 {
122  pagebreak = PageBreak::None;
123  m_sort = Qt::AscendingOrder;
124  groupHeader = nullptr;
125  groupFooter = nullptr;
126 }
127 
int count() const const
QDomElement toElement() const const
QString tagName() const const
bool isNull() const const
Describes sorting for single field, By default the order is ascending.
AscendingOrder
KReportSectionData is used to store the information about a specific report section.
QDomNode item(int index) const const
QDomNodeList childNodes() const const
QDomElement firstChildElement(const QString &tagName) const const
bool hasAttribute(const QString &name) const const
QString attribute(const QString &name, const QString &defValue) const const
Top level report document definition. A KReportDocment defines the design of a document,...
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Feb 7 2023 04:17:37 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.