KReport

KReportDesignerSectionDetailGroup.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-2008 by Adam Pigg (adam@piggz.co.uk)
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 "KReportDesignerSectionDetailGroup.h"
20#include "KReportDesigner.h"
21#include "KReportDesignerSection.h"
22#include "KReportDesignerSectionDetail.h"
23#include "KReportUtils.h"
24#include "kreport_debug.h"
25
26#include <QDomElement>
27#include <QDomDocument>
28
29//! @internal
30class Q_DECL_HIDDEN KReportDesignerSectionDetailGroup::Private
31{
32public:
33 explicit Private() {}
34
35 ~Private()
36 {
37 //Delete these here so that there are no widgets
38 //left floating around
39 delete groupHeader;
40 delete groupFooter;
41 }
42
43 QString column;
44 KReportDesignerSection *groupHeader;
45 KReportDesignerSection *groupFooter;
46 KReportDesignerSectionDetail * reportSectionDetail;
47 KReportDesignerSectionDetailGroup::PageBreak pageBreak = KReportDesignerSectionDetailGroup::PageBreak::None;
49};
50
51KReportDesignerSectionDetailGroup::KReportDesignerSectionDetailGroup(const QString & column, KReportDesignerSectionDetail * rsd,
52 QWidget * parent)
53 : QObject(parent)
54 , d(new Private())
55{
56 Q_ASSERT(rsd);
57 d->reportSectionDetail = rsd;
58 if (!d->reportSectionDetail) {
59 kreportWarning() << "Error: ReportSectionDetail is null";
60 return;
61 }
62 KReportDesigner * rd = rsd->reportDesigner();
63 d->groupHeader = rd->createSection();
64 d->groupFooter = rd->createSection();
65 setGroupHeaderVisible(false);
66 setGroupFooterVisible(false);
67 setColumn(column);
68}
69
70KReportDesignerSectionDetailGroup::~KReportDesignerSectionDetailGroup()
71{
72 delete d;
73}
74
75void KReportDesignerSectionDetailGroup::buildXML(QDomDocument *doc, QDomElement *section) const
76{
77 QDomElement grp = doc->createElement(QLatin1String("report:group"));
78
79 grp.setAttribute(QLatin1String("report:group-column"), column());
80 if (pageBreak() == KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter) {
81 grp.setAttribute(QLatin1String("report:group-page-break"), QLatin1String("after-footer"));
82 } else if (pageBreak() == KReportDesignerSectionDetailGroup::PageBreak::BeforeGroupHeader) {
83 grp.setAttribute(QLatin1String("report:group-page-break"), QLatin1String("before-header"));
84 }
85
86 if (d->sort == Qt::AscendingOrder) {
87 grp.setAttribute(QLatin1String("report:group-sort"), QLatin1String("ascending"));
88 }
89 else {
90 grp.setAttribute(QLatin1String("report:group-sort"), QLatin1String("descending"));
91 }
92
93 //group head
94 if (groupHeaderVisible()) {
95 QDomElement gheader = doc->createElement(QLatin1String("report:section"));
96 gheader.setAttribute(QLatin1String("report:section-type"), QLatin1String("group-header"));
97 groupHeader()->buildXML(doc, &gheader);
98 grp.appendChild(gheader);
99 }
100 // group foot
101 if (groupFooterVisible()) {
102 QDomElement gfooter = doc->createElement(QLatin1String("report:section"));
103 gfooter.setAttribute(QLatin1String("report:section-type"), QLatin1String("group-footer"));
104 groupFooter()->buildXML(doc, &gfooter);
105 grp.appendChild(gfooter);
106 }
107 section->appendChild(grp);
108}
109
110void KReportDesignerSectionDetailGroup::initFromXML( const QDomElement &element )
111{
112 if ( element.hasAttribute(QLatin1String("report:group-column") ) ) {
113 setColumn( element.attribute( QLatin1String("report:group-column") ) );
114 }
115
116 if ( element.hasAttribute( QLatin1String("report:group-page-break") ) ) {
117 QString s = element.attribute( QLatin1String("report:group-page-break") );
118 if ( s == QLatin1String("after-footer") ) {
119 setPageBreak( KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter );
120 } else if ( s == QLatin1String("before-header") ) {
121 setPageBreak( KReportDesignerSectionDetailGroup::PageBreak::BeforeGroupHeader );
122 }
123 }
124
125 if (element.attribute(QLatin1String("report:group-sort"), QLatin1String("ascending")) == QLatin1String("ascending")) {
126 setSort(Qt::AscendingOrder);
127 }
128 else {
129 setSort(Qt::DescendingOrder);
130 }
131
132 for ( QDomElement e = element.firstChildElement( QLatin1String("report:section") ); ! e.isNull(); e = e.nextSiblingElement( QLatin1String("report:section") ) ) {
133 const QString s = KReportUtils::readSectionTypeNameAttribute(e);
134 if ( s == QLatin1String("group-header") ) {
135 setGroupHeaderVisible( true );
136 d->groupHeader->initFromXML( e );
137 } else if ( s == QLatin1String("group-footer") ) {
138 setGroupFooterVisible( true );
139 d->groupFooter->initFromXML( e );
140 }
141 }
142}
143
144void KReportDesignerSectionDetailGroup::setGroupHeaderVisible(bool visible)
145{
146 if (groupHeaderVisible() != visible) {
147 if (d->reportSectionDetail && d->reportSectionDetail->reportDesigner()) {
148 d->reportSectionDetail->reportDesigner()->setModified(true);
149 }
150 }
151 d->groupHeader->setVisible(visible);
152 if (d->reportSectionDetail) {
153 d->reportSectionDetail->adjustSize();
154 }
155}
156
157void KReportDesignerSectionDetailGroup::setGroupFooterVisible(bool visible)
158{
159 if (groupFooterVisible() != visible) {
160 if (d->reportSectionDetail && d->reportSectionDetail->reportDesigner()) {
161 d->reportSectionDetail->reportDesigner()->setModified(true);
162 }
163 }
164 d->groupFooter->setVisible(visible);
165 if (d->reportSectionDetail) {
166 d->reportSectionDetail->adjustSize();
167 }
168}
169
170void KReportDesignerSectionDetailGroup::setPageBreak(KReportDesignerSectionDetailGroup::PageBreak pb)
171{
172 d->pageBreak = pb;
173}
174
175void KReportDesignerSectionDetailGroup::setSort(Qt::SortOrder s)
176{
177 d->sort = s;
178}
179
180Qt::SortOrder KReportDesignerSectionDetailGroup::sort()
181{
182 return d->sort;
183}
184
185
186bool KReportDesignerSectionDetailGroup::groupHeaderVisible() const
187{
188 // Check *explicitly* hidden
189 return ! d->groupHeader->isHidden();
190}
191bool KReportDesignerSectionDetailGroup::groupFooterVisible() const
192{
193 // Check *explicitly* hidden
194 return ! d->groupFooter->isHidden();
195}
196KReportDesignerSectionDetailGroup::PageBreak KReportDesignerSectionDetailGroup::pageBreak() const
197{
198 return d->pageBreak;
199}
200
201QString KReportDesignerSectionDetailGroup::column() const
202{
203 return d->column;
204}
205void KReportDesignerSectionDetailGroup::setColumn(const QString & s)
206{
207 if (d->column != s) {
208 d->column = s;
209 if (d->reportSectionDetail && d->reportSectionDetail->reportDesigner()) d->reportSectionDetail->reportDesigner()->setModified(true);
210 }
211
212 d->groupHeader->setTitle(d->column + QLatin1String(" Group Header"));
213 d->groupFooter->setTitle(d->column + QLatin1String(" Group Footer"));
214}
215
216KReportDesignerSection * KReportDesignerSectionDetailGroup::groupHeader() const
217{
218 return d->groupHeader;
219}
220KReportDesignerSection * KReportDesignerSectionDetailGroup::groupFooter() const
221{
222 return d->groupFooter;
223}
A section group allows a header and footer to be used for a particular report field.
The central detail section which contains the bulk of the report.
This class is the base to all Report Section's visual representation.
void initFromXML(const QDomNode &section)
The ReportDesigner is the main widget for designing a report.
void setModified(bool modified)
Sets the modified status, defaulting to true for modified.
KReportDesignerSection * createSection()
Creates new section.
QDomElement createElement(const QString &tagName)
QString attribute(const QString &name, const QString &defValue) const const
bool hasAttribute(const QString &name) const const
void setAttribute(const QString &name, const QString &value)
QDomNode appendChild(const QDomNode &newChild)
QDomElement firstChildElement(const QString &tagName, const QString &namespaceURI) const const
bool isNull() const const
SortOrder
void adjustSize()
bool isHidden() const const
virtual void setVisible(bool visible)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Oct 11 2024 12:16:25 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.