Skip to content
Permalink
Browse files

Remove some more redundant tests, add sip subclassing

  • Loading branch information
nyalldawson committed Jan 8, 2018
1 parent 56f1c20 commit d372799b87c0847f6a82712a19b678dc9322605e
@@ -139,13 +139,6 @@ Returns a DOM element representing the state of the manager.
%Docstring
Saves the composition with matching ``name`` in template format.
Returns true if save was successful.
%End

QgsComposition *duplicateComposition( const QString &name, const QString &newName );
%Docstring
Duplicates an existing composition from the manager. The new
composition will automatically be stored in the manager.
Returns new composition if duplication was successful.
%End

QgsMasterLayoutInterface *duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName );
@@ -7,6 +7,11 @@
************************************************************************/


%ModuleHeaderCode
#include "qgsprintlayout.h"
#include "qgsreport.h"
%End

class QgsMasterLayoutInterface
{
%Docstring
@@ -17,6 +22,21 @@ class QgsMasterLayoutInterface

%TypeHeaderCode
#include "qgsmasterlayoutinterface.h"
%End
%ConvertToSubClassCode
switch ( sipCpp->layoutType() )
{
case QgsMasterLayoutInterface::PrintLayout:
sipType = sipType_QgsPrintLayout;
*sipCppRet = static_cast<QgsPrintLayout *>( sipCpp );
break;
case QgsMasterLayoutInterface::Report:
*sipCppRet = static_cast<QgsReport *>( sipCpp );
sipType = sipType_QgsReport;
break;
default:
sipType = NULL;
}
%End
public:

@@ -285,40 +285,11 @@ bool QgsLayoutManager::saveAsTemplate( const QString &name, QDomDocument &doc )
return true;
}

QgsComposition *QgsLayoutManager::duplicateComposition( const QString &name, const QString &newName )
QgsMasterLayoutInterface *QgsLayoutManager::duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName )
{
QDomDocument currentDoc;
if ( !saveAsTemplate( name, currentDoc ) )
return nullptr;

QDomElement compositionElem = currentDoc.documentElement().firstChildElement( QStringLiteral( "Composition" ) );
if ( compositionElem.isNull() )
{
QgsDebugMsg( "selected composer could not be stored as temporary template" );
return nullptr;
}

QgsComposition *newComposition( new QgsComposition( mProject ) );
if ( !newComposition->loadFromTemplate( currentDoc, nullptr, false, true ) )
{
delete newComposition;
return nullptr;
}

newComposition->setName( newName );
if ( !addComposition( newComposition ) )
{
delete newComposition;
if ( !layout )
return nullptr;
}
else
{
return newComposition;
}
}

QgsMasterLayoutInterface *QgsLayoutManager::duplicateLayout( const QgsMasterLayoutInterface *layout, const QString &newName )
{
std::unique_ptr< QgsMasterLayoutInterface > newLayout( layout->clone() );
if ( !newLayout )
{
@@ -140,13 +140,6 @@ class CORE_EXPORT QgsLayoutManager : public QObject
*/
bool saveAsTemplate( const QString &name, QDomDocument &doc ) const;

/**
* Duplicates an existing composition from the manager. The new
* composition will automatically be stored in the manager.
* Returns new composition if duplication was successful.
*/
QgsComposition *duplicateComposition( const QString &name, const QString &newName );

/**
* Duplicates an existing \a layout from the manager. The new
* layout will automatically be stored in the manager.
@@ -21,6 +21,13 @@
#include <QString>
#include <QIcon>

#ifdef SIP_RUN
% ModuleHeaderCode
#include "qgsprintlayout.h"
#include "qgsreport.h"
% End
#endif

/**
* \ingroup core
* \class QgsMasterLayoutInterface
@@ -30,6 +37,24 @@
class CORE_EXPORT QgsMasterLayoutInterface
{

#ifdef SIP_RUN
SIP_CONVERT_TO_SUBCLASS_CODE
switch ( sipCpp->layoutType() )
{
case QgsMasterLayoutInterface::PrintLayout:
sipType = sipType_QgsPrintLayout;
*sipCppRet = static_cast<QgsPrintLayout *>( sipCpp );
break;
case QgsMasterLayoutInterface::Report:
*sipCppRet = static_cast<QgsReport *>( sipCpp );
sipType = sipType_QgsReport;
break;
default:
sipType = NULL;
}
SIP_END
#endif

public:

//! Master layout type

This file was deleted.

0 comments on commit d372799

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