Skip to content
Permalink
Browse files

Port more tests to layouts, drop more QgsCompositions use

  • Loading branch information
nyalldawson committed Jan 16, 2018
1 parent fe48aec commit 58047453267cc15eb0cff2ebb7959cf106681e43
@@ -19,7 +19,7 @@ class QgsLayoutManager : QObject
Manages storage of a set of layouts.

QgsLayoutManager handles the storage, serializing and deserializing
of QgsLayouts. Usually this class is not constructed directly, but
of print layouts and reports. Usually this class is not constructed directly, but
rather accessed through a QgsProject via :py:func:`QgsProject.layoutManager()`

QgsLayoutManager retains ownership of all the layouts contained
@@ -43,7 +43,6 @@ manager.

~QgsLayoutManager();


bool addLayout( QgsMasterLayoutInterface *layout /Transfer/ );
%Docstring
Adds a ``layout`` to the manager. Ownership of the layout is transferred to the manager.
@@ -55,7 +54,6 @@ as a result of a duplicate layout name).
.. seealso:: :py:func:`layoutAdded`
%End


bool removeLayout( QgsMasterLayoutInterface *layout );
%Docstring
Removes a ``layout`` from the manager. The layout is deleted.
@@ -78,7 +76,6 @@ Removes and deletes all layouts from the manager.
.. seealso:: :py:func:`removeLayout`
%End


QList< QgsMasterLayoutInterface * > layouts() const;
%Docstring
Returns a list of all layouts contained in the manager.
@@ -89,7 +86,6 @@ Returns a list of all layouts contained in the manager.
Returns a list of all print layouts contained in the manager.
%End


QgsMasterLayoutInterface *layoutByName( const QString &name ) const;
%Docstring
Returns the layout with a matching name, or None if no matching layouts
@@ -109,12 +105,6 @@ present in the XML document.
Returns a DOM element representing the state of the manager.

.. seealso:: :py:func:`readXml`
%End

bool saveAsTemplate( const QString &name, QDomDocument &doc ) const;
%Docstring
Saves the composition with matching ``name`` in template format.
Returns true if save was successful.
%End

QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
@@ -139,7 +139,6 @@ without requiring a transparent background for the image
%If (TESTS)



class QgsLayoutChecker : QgsMultiRenderChecker
{
%Docstring
@@ -61,6 +61,7 @@
#include "qgslayoutpagecollection.h"
#include "qgsreport.h"
#include "qgsreportorganizerwidget.h"
#include "qgsreadwritecontext.h"
#include "ui_qgssvgexportoptions.h"
#include <QShortcut>
#include <QComboBox>
@@ -28,6 +28,7 @@
#include "qgsgui.h"
#include "qgsprintlayout.h"
#include "qgsreport.h"
#include "qgsreadwritecontext.h"

#include <QDesktopServices>
#include <QDialog>
@@ -21,6 +21,7 @@
#include "qgsprintlayout.h"
#include "qgsreport.h"
#include "qgscompositionconverter.h"
#include "qgsreadwritecontext.h"

QgsLayoutManager::QgsLayoutManager( QgsProject *project )
: QObject( project )
@@ -34,23 +35,6 @@ QgsLayoutManager::~QgsLayoutManager()
clear();
}

bool QgsLayoutManager::addComposition( QgsComposition *composition )
{
if ( !composition )
return false;

// check for duplicate name
Q_FOREACH ( QgsComposition *c, mCompositions )
{
if ( c->name() == composition->name() )
return false;
}

mCompositions << composition;
mProject->setDirty( true );
return true;
}

bool QgsLayoutManager::addLayout( QgsMasterLayoutInterface *layout )
{
if ( !layout )
@@ -86,20 +70,6 @@ bool QgsLayoutManager::addLayout( QgsMasterLayoutInterface *layout )
return true;
}

bool QgsLayoutManager::removeComposition( QgsComposition *composition )
{
if ( !composition )
return false;

if ( !mCompositions.contains( composition ) )
return false;

mCompositions.removeAll( composition );
delete composition;
mProject->setDirty( true );
return true;
}

bool QgsLayoutManager::removeLayout( QgsMasterLayoutInterface *layout )
{
if ( !layout )
@@ -119,22 +89,13 @@ bool QgsLayoutManager::removeLayout( QgsMasterLayoutInterface *layout )

void QgsLayoutManager::clear()
{
Q_FOREACH ( QgsComposition *c, mCompositions )
{
removeComposition( c );
}
const QList< QgsMasterLayoutInterface * > layouts = mLayouts;
for ( QgsMasterLayoutInterface *l : layouts )
{
removeLayout( l );
}
}

QList<QgsComposition *> QgsLayoutManager::compositions() const
{
return mCompositions;
}

QList<QgsMasterLayoutInterface *> QgsLayoutManager::layouts() const
{
return mLayouts;
@@ -153,16 +114,6 @@ QList<QgsPrintLayout *> QgsLayoutManager::printLayouts() const
return result;
}

QgsComposition *QgsLayoutManager::compositionByName( const QString &name ) const
{
Q_FOREACH ( QgsComposition *c, mCompositions )
{
if ( c->name() == name )
return c;
}
return nullptr;
}

QgsMasterLayoutInterface *QgsLayoutManager::layoutByName( const QString &name ) const
{
for ( QgsMasterLayoutInterface *l : mLayouts )
@@ -261,15 +212,6 @@ bool QgsLayoutManager::readXml( const QDomElement &element, const QDomDocument &
QDomElement QgsLayoutManager::writeXml( QDomDocument &doc ) const
{
QDomElement layoutsElem = doc.createElement( QStringLiteral( "Layouts" ) );
Q_FOREACH ( QgsComposition *c, mCompositions )
{
QDomElement composerElem = doc.createElement( QStringLiteral( "Composer" ) );

layoutsElem.appendChild( composerElem );

c->writeXml( composerElem, doc );
c->atlasComposition().writeXml( composerElem, doc );
}

QgsReadWriteContext context;
context.setPathResolver( mProject->pathResolver() );
@@ -281,19 +223,6 @@ QDomElement QgsLayoutManager::writeXml( QDomDocument &doc ) const
return layoutsElem;
}

bool QgsLayoutManager::saveAsTemplate( const QString &name, QDomDocument &doc ) const
{
QgsComposition *c = compositionByName( name );
if ( !c )
return false;

QDomElement composerElem = doc.createElement( QStringLiteral( "Composer" ) );
doc.appendChild( composerElem );
c->writeXml( composerElem, doc );
c->atlasComposition().writeXml( composerElem, doc );
return true;
}

QgsMasterLayoutInterface *QgsLayoutManager::duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName )
{
if ( !layout )
@@ -343,32 +272,3 @@ QString QgsLayoutManager::generateUniqueTitle( QgsMasterLayoutInterface::Type ty
return name;
}

QgsComposition *QgsLayoutManager::createCompositionFromXml( const QDomElement &element, const QDomDocument &doc ) const
{
QDomNodeList compositionNodeList = element.elementsByTagName( QStringLiteral( "Composition" ) );

if ( compositionNodeList.size() > 0 )
{
std::unique_ptr< QgsComposition > c( new QgsComposition( mProject ) );
QDomElement compositionElem = compositionNodeList.at( 0 ).toElement();
if ( !c->readXml( compositionElem, doc ) )
{
return nullptr;
}

// read atlas parameters - must be done before adding items
QDomElement atlasElem = element.firstChildElement( QStringLiteral( "Atlas" ) );
c->atlasComposition().readXml( atlasElem, doc );

//read and restore all the items
c->addItemsFromXml( element, doc );

//make sure z values are consistent
c->refreshZList();
return c.release();
}
else
{
return nullptr;
}
}
@@ -19,7 +19,6 @@
#include "qgis_core.h"
#include "qgis.h"
#include "qgsmasterlayoutinterface.h"
#include "qgscomposition.h"
#include <QObject>

class QgsProject;
@@ -33,7 +32,7 @@ class QgsPrintLayout;
* \brief Manages storage of a set of layouts.
*
* QgsLayoutManager handles the storage, serializing and deserializing
* of QgsLayouts. Usually this class is not constructed directly, but
* of print layouts and reports. Usually this class is not constructed directly, but
* rather accessed through a QgsProject via QgsProject::layoutManager().
*
* QgsLayoutManager retains ownership of all the layouts contained
@@ -55,15 +54,6 @@ class CORE_EXPORT QgsLayoutManager : public QObject

~QgsLayoutManager() override;

/**
* Adds a composition to the manager. Ownership of the composition is transferred to the manager.
* Returns true if the addition was successful, or false if the composition could not be added (eg
* as a result of a duplicate composition name).
* \see removeComposition()
* \see compositionAdded()
*/
bool addComposition( QgsComposition *composition SIP_TRANSFER ) SIP_SKIP;

/**
* Adds a \a layout to the manager. Ownership of the layout is transferred to the manager.
* Returns true if the addition was successful, or false if the layout could not be added (eg
@@ -73,17 +63,6 @@ class CORE_EXPORT QgsLayoutManager : public QObject
*/
bool addLayout( QgsMasterLayoutInterface *layout SIP_TRANSFER );

/**
* Removes a composition from the manager. The composition is deleted.
* Returns true if the removal was successful, or false if the removal failed (eg as a result
* of removing a composition which is not contained in the manager).
* \see addComposition()
* \see compositionRemoved()
* \see compositionAboutToBeRemoved()
* \see clear()
*/
bool removeComposition( QgsComposition *composition ) SIP_SKIP;

/**
* Removes a \a layout from the manager. The layout is deleted.
* Returns true if the removal was successful, or false if the removal failed (eg as a result
@@ -101,11 +80,6 @@ class CORE_EXPORT QgsLayoutManager : public QObject
*/
void clear();

/**
* Returns a list of all compositions contained in the manager.
*/
QList< QgsComposition * > compositions() const SIP_SKIP;

/**
* Returns a list of all layouts contained in the manager.
*/
@@ -116,12 +90,6 @@ class CORE_EXPORT QgsLayoutManager : public QObject
*/
QList< QgsPrintLayout * > printLayouts() const;

/**
* Returns the composition with a matching name, or nullptr if no matching compositions
* were found.
*/
QgsComposition *compositionByName( const QString &name ) const SIP_SKIP;

/**
* Returns the layout with a matching name, or nullptr if no matching layouts
* were found.
@@ -141,12 +109,6 @@ class CORE_EXPORT QgsLayoutManager : public QObject
*/
QDomElement writeXml( QDomDocument &doc ) const;

/**
* Saves the composition with matching \a name in template format.
* Returns true if save was successful.
*/
bool saveAsTemplate( const QString &name, QDomDocument &doc ) const;

/**
* Duplicates an existing \a layout from the manager. The new
* layout will automatically be stored in the manager.
@@ -181,11 +143,8 @@ class CORE_EXPORT QgsLayoutManager : public QObject

QgsProject *mProject = nullptr;

QList< QgsComposition * > mCompositions;
QList< QgsMasterLayoutInterface * > mLayouts;

QgsComposition *createCompositionFromXml( const QDomElement &element, const QDomDocument &doc ) const;

};

#endif // QGSLAYOUTMANAGER_H

0 comments on commit 5804745

Please sign in to comment.
You can’t perform that action at this time.