File indexing completed on 2024-04-28 04:41:56
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 "KReportDetailSectionData.h" 0020 #include "KReportSectionData.h" 0021 #include "KReportDocument.h" 0022 #include "KReportUtils.h" 0023 0024 #include "kreport_debug.h" 0025 #include <QDomElement> 0026 0027 KReportDetailSectionData::KReportDetailSectionData(QObject *parent) 0028 : QObject(parent) 0029 { 0030 pageBreak = PageBreak::None; 0031 detailSection = nullptr; 0032 m_valid = true; 0033 } 0034 0035 KReportDetailSectionData::KReportDetailSectionData(const QDomElement &elemSource, KReportDocument *report) 0036 : QObject(report) 0037 { 0038 pageBreak = PageBreak::None; 0039 detailSection = nullptr; 0040 m_valid = false; 0041 //kreportDebug() << elemSource.tagName(); 0042 if (elemSource.tagName() != QLatin1String("report:detail")) { 0043 return; 0044 } 0045 0046 QDomNodeList sections = elemSource.childNodes(); 0047 0048 for (int nodeCounter = 0; nodeCounter < sections.count(); nodeCounter++) { 0049 QDomElement elemThis = sections.item(nodeCounter).toElement(); 0050 0051 if (elemThis.tagName() == QLatin1String("report:group")) { 0052 KReportDetailGroupSectionData * dgsd = new KReportDetailGroupSectionData(); 0053 0054 if ( elemThis.hasAttribute( QLatin1String("report:group-column") ) ) { 0055 dgsd->column = elemThis.attribute( QLatin1String("report:group-column") ); 0056 } 0057 0058 if ( elemThis.hasAttribute( QLatin1String("report:group-page-break") ) ) { 0059 QString s = elemThis.attribute( QLatin1String("report:group-page-break") ); 0060 if ( s == QLatin1String("after-footer") ) { 0061 dgsd->pagebreak = KReportDetailGroupSectionData::PageBreak::AfterGroupFooter; 0062 } else if ( s == QLatin1String("before-header") ) { 0063 dgsd->pagebreak = KReportDetailGroupSectionData::PageBreak::BeforeGroupHeader; 0064 } else { 0065 dgsd->pagebreak = KReportDetailGroupSectionData::PageBreak::None; 0066 } 0067 } 0068 0069 if (elemThis.attribute(QLatin1String("report:group-sort"), QLatin1String("ascending")) == QLatin1String("ascending")) { 0070 dgsd->m_sort = Qt::AscendingOrder; 0071 } else { 0072 dgsd->m_sort = Qt::DescendingOrder; 0073 } 0074 0075 for ( QDomElement e = elemThis.firstChildElement( QLatin1String("report:section") ); ! e.isNull(); e = e.nextSiblingElement( QLatin1String("report:section") ) ) { 0076 const QString s = KReportUtils::readSectionTypeNameAttribute(e); 0077 if ( s == QLatin1String("group-header") ) { 0078 KReportSectionData * sd = new KReportSectionData(e, report); 0079 if (sd->isValid()) { 0080 dgsd->groupHeader = sd; 0081 } else { 0082 delete sd; 0083 } 0084 } else if ( s == QLatin1String("group-footer") ) { 0085 KReportSectionData * sd = new KReportSectionData(e, report); 0086 if (sd->isValid()) { 0087 dgsd->groupFooter = sd; 0088 } else { 0089 delete sd; 0090 } 0091 } 0092 } 0093 groupList.append(dgsd); 0094 KReportDataSource::SortedField s; 0095 s.setField(dgsd->column); 0096 s.setOrder(dgsd->m_sort); 0097 0098 sortedFields.append(s); 0099 } else if (elemThis.tagName() == QLatin1String("report:section") 0100 && KReportUtils::readSectionTypeNameAttribute(elemThis) 0101 == QLatin1String("detail")) 0102 { 0103 KReportSectionData *sd = new KReportSectionData(elemThis, report); 0104 if (sd->isValid()) { 0105 detailSection = sd; 0106 } else 0107 delete sd; 0108 } else { 0109 kreportWarning() << "While parsing detail section encountered an unknown element: " << elemThis.tagName(); 0110 } 0111 } 0112 0113 m_valid = true; 0114 } 0115 0116 KReportDetailSectionData::~KReportDetailSectionData() 0117 { 0118 } 0119 0120 KReportDetailGroupSectionData::KReportDetailGroupSectionData() 0121 { 0122 pagebreak = PageBreak::None; 0123 m_sort = Qt::AscendingOrder; 0124 groupHeader = nullptr; 0125 groupFooter = nullptr; 0126 } 0127