Skip to content

Commit

Permalink
Remove some more redundant tests, add sip subclassing
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 8, 2018
1 parent 56f1c20 commit d372799
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 285 deletions.
7 changes: 0 additions & 7 deletions python/core/composer/qgslayoutmanager.sip
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
20 changes: 20 additions & 0 deletions python/core/layout/qgsmasterlayoutinterface.sip
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
************************************************************************/


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

class QgsMasterLayoutInterface
{
%Docstring
Expand All @@ -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:

Expand Down
33 changes: 2 additions & 31 deletions src/core/composer/qgslayoutmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down
7 changes: 0 additions & 7 deletions src/core/composer/qgslayoutmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 25 additions & 0 deletions src/core/layout/qgsmasterlayoutinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
#include <QString>
#include <QIcon>

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

/**
* \ingroup core
* \class QgsMasterLayoutInterface
Expand All @@ -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
Expand Down
61 changes: 0 additions & 61 deletions tests/src/python/qgscompositionchecker.py

This file was deleted.

Loading

0 comments on commit d372799

Please sign in to comment.