|
@@ -17,6 +17,8 @@ |
|
|
#include "qgsabstractreportsection.h" |
|
|
#include "qgslayout.h" |
|
|
#include "qgsreport.h" |
|
|
#include "qgsreportsectionfieldgroup.h" |
|
|
#include "qgsreportsectionlayout.h" |
|
|
|
|
|
///@cond NOT_STABLE |
|
|
|
|
@@ -54,6 +56,95 @@ void QgsAbstractReportSection::setContext( const QgsReportSectionContext &contex |
|
|
} |
|
|
} |
|
|
|
|
|
bool QgsAbstractReportSection::writeXml( QDomElement &parentElement, QDomDocument &doc, const QgsReadWriteContext &context ) const |
|
|
{ |
|
|
QDomElement element = doc.createElement( QStringLiteral( "Section" ) ); |
|
|
element.setAttribute( QStringLiteral( "type" ), type() ); |
|
|
|
|
|
element.setAttribute( QStringLiteral( "headerEnabled" ), mHeaderEnabled ? "1" : "0" ); |
|
|
if ( mHeader ) |
|
|
{ |
|
|
QDomElement headerElement = doc.createElement( QStringLiteral( "header" ) ); |
|
|
headerElement.appendChild( mHeader->writeXml( doc, context ) ); |
|
|
element.appendChild( headerElement ); |
|
|
} |
|
|
element.setAttribute( QStringLiteral( "footerEnabled" ), mFooterEnabled ? "1" : "0" ); |
|
|
if ( mFooter ) |
|
|
{ |
|
|
QDomElement footerElement = doc.createElement( QStringLiteral( "footer" ) ); |
|
|
footerElement.appendChild( mFooter->writeXml( doc, context ) ); |
|
|
element.appendChild( footerElement ); |
|
|
} |
|
|
|
|
|
for ( QgsAbstractReportSection *section : mChildren ) |
|
|
{ |
|
|
section->writeXml( element, doc, context ); |
|
|
} |
|
|
|
|
|
writePropertiesToElement( element, doc, context ); |
|
|
|
|
|
parentElement.appendChild( element ); |
|
|
return true; |
|
|
} |
|
|
|
|
|
bool QgsAbstractReportSection::readXml( const QDomElement &element, const QDomDocument &doc, const QgsReadWriteContext &context ) |
|
|
{ |
|
|
if ( element.nodeName() != QStringLiteral( "Section" ) ) |
|
|
{ |
|
|
return false; |
|
|
} |
|
|
|
|
|
mHeaderEnabled = element.attribute( QStringLiteral( "headerEnabled" ), "0" ).toInt(); |
|
|
mFooterEnabled = element.attribute( QStringLiteral( "footerEnabled" ), "0" ).toInt(); |
|
|
const QDomElement headerElement = element.firstChildElement( QStringLiteral( "header" ) ); |
|
|
if ( !headerElement.isNull() ) |
|
|
{ |
|
|
const QDomElement headerLayoutElem = headerElement.firstChild().toElement(); |
|
|
std::unique_ptr< QgsLayout > header = qgis::make_unique< QgsLayout >( project() ); |
|
|
header->readXml( headerLayoutElem, doc, context ); |
|
|
mHeader = std::move( header ); |
|
|
} |
|
|
const QDomElement footerElement = element.firstChildElement( QStringLiteral( "footer" ) ); |
|
|
if ( !footerElement.isNull() ) |
|
|
{ |
|
|
const QDomElement footerLayoutElem = footerElement.firstChild().toElement(); |
|
|
std::unique_ptr< QgsLayout > footer = qgis::make_unique< QgsLayout >( project() ); |
|
|
footer->readXml( footerLayoutElem, doc, context ); |
|
|
mFooter = std::move( footer ); |
|
|
} |
|
|
|
|
|
const QDomNodeList sectionItemList = element.childNodes(); |
|
|
for ( int i = 0; i < sectionItemList.size(); ++i ) |
|
|
{ |
|
|
const QDomElement currentSectionElem = sectionItemList.at( i ).toElement(); |
|
|
if ( currentSectionElem.nodeName() != QStringLiteral( "Section" ) ) |
|
|
continue; |
|
|
|
|
|
const QString sectionType = currentSectionElem.attribute( QStringLiteral( "type" ) ); |
|
|
|
|
|
//TODO - eventually move this to a registry when there's enough subclasses to warrant it |
|
|
std::unique_ptr< QgsAbstractReportSection > section; |
|
|
if ( sectionType == QLatin1String( "SectionFieldGroup" ) ) |
|
|
{ |
|
|
section = qgis::make_unique< QgsReportSectionFieldGroup >(); |
|
|
} |
|
|
else if ( sectionType == QLatin1String( "SectionLayout" ) ) |
|
|
{ |
|
|
section = qgis::make_unique< QgsReportSectionLayout >(); |
|
|
} |
|
|
|
|
|
if ( section ) |
|
|
{ |
|
|
appendChild( section.get() ); |
|
|
section->readXml( currentSectionElem, doc, context ); |
|
|
( void )section.release(); //ownership was transferred already |
|
|
} |
|
|
} |
|
|
|
|
|
bool result = readPropertiesFromElement( element, doc, context ); |
|
|
return result; |
|
|
} |
|
|
|
|
|
QString QgsAbstractReportSection::filePath( const QString &baseFilePath, const QString &extension ) |
|
|
{ |
|
|
QString base = QStringLiteral( "%1_%2" ).arg( baseFilePath ).arg( mSectionNumber, 4, 10, QChar( '0' ) ); |
|
@@ -235,13 +326,13 @@ QgsAbstractReportSection *QgsAbstractReportSection::childSection( int index ) |
|
|
|
|
|
void QgsAbstractReportSection::appendChild( QgsAbstractReportSection *section ) |
|
|
{ |
|
|
section->setParent( this ); |
|
|
section->setParentSection( this ); |
|
|
mChildren.append( section ); |
|
|
} |
|
|
|
|
|
void QgsAbstractReportSection::insertChild( int index, QgsAbstractReportSection *section ) |
|
|
{ |
|
|
section->setParent( this ); |
|
|
section->setParentSection( this ); |
|
|
index = std::max( 0, index ); |
|
|
index = std::min( index, mChildren.count() ); |
|
|
mChildren.insert( index, section ); |
|
@@ -285,5 +376,15 @@ void QgsAbstractReportSection::copyCommonProperties( QgsAbstractReportSection *d |
|
|
} |
|
|
} |
|
|
|
|
|
bool QgsAbstractReportSection::writePropertiesToElement( QDomElement &, QDomDocument &, const QgsReadWriteContext & ) const |
|
|
{ |
|
|
return true; |
|
|
} |
|
|
|
|
|
bool QgsAbstractReportSection::readPropertiesFromElement( const QDomElement &, const QDomDocument &, const QgsReadWriteContext & ) |
|
|
{ |
|
|
return true; |
|
|
} |
|
|
|
|
|
///@endcond |
|
|
|