File indexing completed on 2024-04-28 04:42:10
0001 /* This file is part of the KDE project 0002 * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) 0003 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) 0004 * 0005 * This library is free software; you can redistribute it and/or 0006 * modify it under the terms of the GNU Lesser General Public 0007 * License as published by the Free Software Foundation; either 0008 * version 2.1 of the License, or (at your option) any later version. 0009 * 0010 * This library is distributed in the hope that it will be useful, 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0013 * Lesser General Public License for more details. 0014 * 0015 * You should have received a copy of the GNU Lesser General Public 0016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 0019 #include "KReportDesignerSectionDetailGroup.h" 0020 #include "KReportDesigner.h" 0021 #include "KReportDesignerSection.h" 0022 #include "KReportDesignerSectionDetail.h" 0023 #include "KReportUtils.h" 0024 #include "kreport_debug.h" 0025 0026 #include <QDomElement> 0027 #include <QDomDocument> 0028 0029 //! @internal 0030 class Q_DECL_HIDDEN KReportDesignerSectionDetailGroup::Private 0031 { 0032 public: 0033 explicit Private() {} 0034 0035 ~Private() 0036 { 0037 //Delete these here so that there are no widgets 0038 //left floating around 0039 delete groupHeader; 0040 delete groupFooter; 0041 } 0042 0043 QString column; 0044 KReportDesignerSection *groupHeader; 0045 KReportDesignerSection *groupFooter; 0046 KReportDesignerSectionDetail * reportSectionDetail; 0047 KReportDesignerSectionDetailGroup::PageBreak pageBreak = KReportDesignerSectionDetailGroup::PageBreak::None; 0048 Qt::SortOrder sort = Qt::AscendingOrder; 0049 }; 0050 0051 KReportDesignerSectionDetailGroup::KReportDesignerSectionDetailGroup(const QString & column, KReportDesignerSectionDetail * rsd, 0052 QWidget * parent) 0053 : QObject(parent) 0054 , d(new Private()) 0055 { 0056 Q_ASSERT(rsd); 0057 d->reportSectionDetail = rsd; 0058 if (!d->reportSectionDetail) { 0059 kreportWarning() << "Error: ReportSectionDetail is null"; 0060 return; 0061 } 0062 KReportDesigner * rd = rsd->reportDesigner(); 0063 d->groupHeader = rd->createSection(); 0064 d->groupFooter = rd->createSection(); 0065 setGroupHeaderVisible(false); 0066 setGroupFooterVisible(false); 0067 setColumn(column); 0068 } 0069 0070 KReportDesignerSectionDetailGroup::~KReportDesignerSectionDetailGroup() 0071 { 0072 delete d; 0073 } 0074 0075 void KReportDesignerSectionDetailGroup::buildXML(QDomDocument *doc, QDomElement *section) const 0076 { 0077 QDomElement grp = doc->createElement(QLatin1String("report:group")); 0078 0079 grp.setAttribute(QLatin1String("report:group-column"), column()); 0080 if (pageBreak() == KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter) { 0081 grp.setAttribute(QLatin1String("report:group-page-break"), QLatin1String("after-footer")); 0082 } else if (pageBreak() == KReportDesignerSectionDetailGroup::PageBreak::BeforeGroupHeader) { 0083 grp.setAttribute(QLatin1String("report:group-page-break"), QLatin1String("before-header")); 0084 } 0085 0086 if (d->sort == Qt::AscendingOrder) { 0087 grp.setAttribute(QLatin1String("report:group-sort"), QLatin1String("ascending")); 0088 } 0089 else { 0090 grp.setAttribute(QLatin1String("report:group-sort"), QLatin1String("descending")); 0091 } 0092 0093 //group head 0094 if (groupHeaderVisible()) { 0095 QDomElement gheader = doc->createElement(QLatin1String("report:section")); 0096 gheader.setAttribute(QLatin1String("report:section-type"), QLatin1String("group-header")); 0097 groupHeader()->buildXML(doc, &gheader); 0098 grp.appendChild(gheader); 0099 } 0100 // group foot 0101 if (groupFooterVisible()) { 0102 QDomElement gfooter = doc->createElement(QLatin1String("report:section")); 0103 gfooter.setAttribute(QLatin1String("report:section-type"), QLatin1String("group-footer")); 0104 groupFooter()->buildXML(doc, &gfooter); 0105 grp.appendChild(gfooter); 0106 } 0107 section->appendChild(grp); 0108 } 0109 0110 void KReportDesignerSectionDetailGroup::initFromXML( const QDomElement &element ) 0111 { 0112 if ( element.hasAttribute(QLatin1String("report:group-column") ) ) { 0113 setColumn( element.attribute( QLatin1String("report:group-column") ) ); 0114 } 0115 0116 if ( element.hasAttribute( QLatin1String("report:group-page-break") ) ) { 0117 QString s = element.attribute( QLatin1String("report:group-page-break") ); 0118 if ( s == QLatin1String("after-footer") ) { 0119 setPageBreak( KReportDesignerSectionDetailGroup::PageBreak::AfterGroupFooter ); 0120 } else if ( s == QLatin1String("before-header") ) { 0121 setPageBreak( KReportDesignerSectionDetailGroup::PageBreak::BeforeGroupHeader ); 0122 } 0123 } 0124 0125 if (element.attribute(QLatin1String("report:group-sort"), QLatin1String("ascending")) == QLatin1String("ascending")) { 0126 setSort(Qt::AscendingOrder); 0127 } 0128 else { 0129 setSort(Qt::DescendingOrder); 0130 } 0131 0132 for ( QDomElement e = element.firstChildElement( QLatin1String("report:section") ); ! e.isNull(); e = e.nextSiblingElement( QLatin1String("report:section") ) ) { 0133 const QString s = KReportUtils::readSectionTypeNameAttribute(e); 0134 if ( s == QLatin1String("group-header") ) { 0135 setGroupHeaderVisible( true ); 0136 d->groupHeader->initFromXML( e ); 0137 } else if ( s == QLatin1String("group-footer") ) { 0138 setGroupFooterVisible( true ); 0139 d->groupFooter->initFromXML( e ); 0140 } 0141 } 0142 } 0143 0144 void KReportDesignerSectionDetailGroup::setGroupHeaderVisible(bool visible) 0145 { 0146 if (groupHeaderVisible() != visible) { 0147 if (d->reportSectionDetail && d->reportSectionDetail->reportDesigner()) { 0148 d->reportSectionDetail->reportDesigner()->setModified(true); 0149 } 0150 } 0151 d->groupHeader->setVisible(visible); 0152 if (d->reportSectionDetail) { 0153 d->reportSectionDetail->adjustSize(); 0154 } 0155 } 0156 0157 void KReportDesignerSectionDetailGroup::setGroupFooterVisible(bool visible) 0158 { 0159 if (groupFooterVisible() != visible) { 0160 if (d->reportSectionDetail && d->reportSectionDetail->reportDesigner()) { 0161 d->reportSectionDetail->reportDesigner()->setModified(true); 0162 } 0163 } 0164 d->groupFooter->setVisible(visible); 0165 if (d->reportSectionDetail) { 0166 d->reportSectionDetail->adjustSize(); 0167 } 0168 } 0169 0170 void KReportDesignerSectionDetailGroup::setPageBreak(KReportDesignerSectionDetailGroup::PageBreak pb) 0171 { 0172 d->pageBreak = pb; 0173 } 0174 0175 void KReportDesignerSectionDetailGroup::setSort(Qt::SortOrder s) 0176 { 0177 d->sort = s; 0178 } 0179 0180 Qt::SortOrder KReportDesignerSectionDetailGroup::sort() 0181 { 0182 return d->sort; 0183 } 0184 0185 0186 bool KReportDesignerSectionDetailGroup::groupHeaderVisible() const 0187 { 0188 // Check *explicitly* hidden 0189 return ! d->groupHeader->isHidden(); 0190 } 0191 bool KReportDesignerSectionDetailGroup::groupFooterVisible() const 0192 { 0193 // Check *explicitly* hidden 0194 return ! d->groupFooter->isHidden(); 0195 } 0196 KReportDesignerSectionDetailGroup::PageBreak KReportDesignerSectionDetailGroup::pageBreak() const 0197 { 0198 return d->pageBreak; 0199 } 0200 0201 QString KReportDesignerSectionDetailGroup::column() const 0202 { 0203 return d->column; 0204 } 0205 void KReportDesignerSectionDetailGroup::setColumn(const QString & s) 0206 { 0207 if (d->column != s) { 0208 d->column = s; 0209 if (d->reportSectionDetail && d->reportSectionDetail->reportDesigner()) d->reportSectionDetail->reportDesigner()->setModified(true); 0210 } 0211 0212 d->groupHeader->setTitle(d->column + QLatin1String(" Group Header")); 0213 d->groupFooter->setTitle(d->column + QLatin1String(" Group Footer")); 0214 } 0215 0216 KReportDesignerSection * KReportDesignerSectionDetailGroup::groupHeader() const 0217 { 0218 return d->groupHeader; 0219 } 0220 KReportDesignerSection * KReportDesignerSectionDetailGroup::groupFooter() const 0221 { 0222 return d->groupFooter; 0223 }