Skip to content

Commit 0732754

Browse files
authoredJan 10, 2018
Merge pull request #6031 from elpaso/layouts-server
[layouts][server] Composition -> layout
2 parents 880d853 + f61a5f2 commit 0732754

File tree

36 files changed

+297
-275
lines changed

36 files changed

+297
-275
lines changed
 

‎.ci/travis/linux/blacklist.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,3 @@ PyQgsAuthManagerPKIPostgresTest
3838
PyQgsAuthManagerPasswordPostgresTest
3939
PyQgsAuthManagerOgrPostgresTest
4040

41-
# temporary disable for composition -> layout transition
42-
PyQgsServerWMS
43-
PyQgsServerWMSGetPrint

‎python/core/layout/qgslayoutmanager.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ Removes and deletes all layouts from the manager.
8484
Returns a list of all layouts contained in the manager.
8585
%End
8686

87+
QList< QgsPrintLayout * > printLayouts() const;
88+
%Docstring
89+
Returns a list of all print layouts contained in the manager.
90+
%End
91+
8792

8893
QgsMasterLayoutInterface *layoutByName( const QString &name ) const;
8994
%Docstring

‎src/core/layout/qgscompositionconverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ bool QgsCompositionConverter::readMapXml( QgsLayoutItemMap *layoutItem, const QD
782782
}
783783
else
784784
{
785-
layoutItem->setKeepLayerSet( true );
785+
layoutItem->setKeepLayerSet( false );
786786
}
787787

788788
QString drawCanvasItemsFlag = itemElem.attribute( QStringLiteral( "drawCanvasItems" ), QStringLiteral( "true" ) );

‎src/core/layout/qgslayoutmanager.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,19 @@ QList<QgsMasterLayoutInterface *> QgsLayoutManager::layouts() const
140140
return mLayouts;
141141
}
142142

143+
QList<QgsPrintLayout *> QgsLayoutManager::printLayouts() const
144+
{
145+
QList<QgsPrintLayout *> result;
146+
const QList<QgsMasterLayoutInterface *> _layouts( mLayouts );
147+
for ( const auto &layout : _layouts )
148+
{
149+
QgsPrintLayout *_item( dynamic_cast<QgsPrintLayout *>( layout ) );
150+
if ( _item )
151+
result.push_back( _item );
152+
}
153+
return result;
154+
}
155+
143156
QgsComposition *QgsLayoutManager::compositionByName( const QString &name ) const
144157
{
145158
Q_FOREACH ( QgsComposition *c, mCompositions )

‎src/core/layout/qgslayoutmanager.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include <QObject>
2424

2525
class QgsProject;
26+
class QgsPrintLayout;
2627

2728
/**
2829
* \ingroup core
@@ -110,6 +111,11 @@ class CORE_EXPORT QgsLayoutManager : public QObject
110111
*/
111112
QList< QgsMasterLayoutInterface * > layouts() const;
112113

114+
/**
115+
* Returns a list of all print layouts contained in the manager.
116+
*/
117+
QList< QgsPrintLayout * > printLayouts() const;
118+
113119
/**
114120
* Returns the composition with a matching name, or nullptr if no matching compositions
115121
* were found.

‎src/server/services/wms/qgswmsgetcapabilities.cpp

Lines changed: 40 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@
2323
#include "qgsserverprojectutils.h"
2424

2525
#include "qgslayoutmanager.h"
26-
#include "qgscomposition.h"
27-
#include "qgscomposermap.h"
28-
#include "qgscomposerlabel.h"
29-
#include "qgscomposerhtml.h"
30-
#include "qgscomposerframe.h"
26+
#include "qgsprintlayout.h"
27+
#include "qgslayoutitemmap.h"
28+
#include "qgslayoutitemlabel.h"
29+
#include "qgslayoutitemhtml.h"
30+
#include "qgslayoutframe.h"
31+
#include "qgslayoutpagecollection.h"
3132

3233
#include "qgslayertreenode.h"
3334
#include "qgslayertreegroup.h"
@@ -624,48 +625,61 @@ namespace QgsWms
624625

625626
QDomElement getComposerTemplatesElement( QDomDocument &doc, const QgsProject *project )
626627
{
627-
QList<QgsComposition *> projectComposers = project->layoutManager()->compositions();
628+
QList< QgsPrintLayout * > projectComposers = project->layoutManager()->printLayouts();
628629
if ( projectComposers.size() == 0 )
629630
return QDomElement();
630631

631632
QStringList restrictedComposers = QgsServerProjectUtils::wmsRestrictedComposers( *project );
632633

633634
QDomElement composerTemplatesElem = doc.createElement( QStringLiteral( "ComposerTemplates" ) );
634-
QList<QgsComposition *>::const_iterator cIt = projectComposers.constBegin();
635+
QList<QgsPrintLayout *>::const_iterator cIt = projectComposers.constBegin();
635636
for ( ; cIt != projectComposers.constEnd(); ++cIt )
636637
{
637-
QgsComposition *composer = *cIt;
638-
if ( restrictedComposers.contains( composer->name() ) )
638+
QgsPrintLayout *layout = *cIt;
639+
if ( restrictedComposers.contains( layout->name() ) )
639640
continue;
640641

642+
// Check that we have at least one page
643+
if ( layout->pageCollection()->pageCount() < 1 )
644+
continue;
645+
646+
// Get width and height from first page of the collection
647+
QgsLayoutSize layoutSize( layout->pageCollection()->page( 0 )->sizeWithUnits() );
648+
QgsLayoutMeasurement width( layout->convertFromLayoutUnits( layoutSize.width(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
649+
QgsLayoutMeasurement height( layout->convertFromLayoutUnits( layoutSize.height(), QgsUnitTypes::LayoutUnit::LayoutMillimeters ) );
650+
641651
QDomElement composerTemplateElem = doc.createElement( QStringLiteral( "ComposerTemplate" ) );
642-
composerTemplateElem.setAttribute( QStringLiteral( "name" ), composer->name() );
652+
composerTemplateElem.setAttribute( QStringLiteral( "name" ), layout->name() );
643653

644-
//get paper width and hight in mm from composition
645-
composerTemplateElem.setAttribute( QStringLiteral( "width" ), composer->paperWidth() );
646-
composerTemplateElem.setAttribute( QStringLiteral( "height" ), composer->paperHeight() );
654+
//get paper width and height in mm from composition
655+
composerTemplateElem.setAttribute( QStringLiteral( "width" ), width.length() );
656+
composerTemplateElem.setAttribute( QStringLiteral( "height" ), height.length() );
647657

648658
//add available composer maps and their size in mm
649-
QList<const QgsComposerMap *> composerMapList = composer->composerMapItems();
650-
QList<const QgsComposerMap *>::const_iterator cmIt = composerMapList.constBegin();
651-
for ( ; cmIt != composerMapList.constEnd(); ++cmIt )
659+
QList<QgsLayoutItemMap *> layoutMapList;
660+
layout->layoutItems<QgsLayoutItemMap>( layoutMapList );
661+
QList<QgsLayoutItemMap *>::const_iterator cmIt = layoutMapList.constBegin();
662+
// Add map id
663+
int mapId = 0;
664+
for ( ; cmIt != layoutMapList.constEnd(); ++cmIt )
652665
{
653-
const QgsComposerMap *composerMap = *cmIt;
666+
const QgsLayoutItemMap *composerMap = *cmIt;
654667

655668
QDomElement composerMapElem = doc.createElement( QStringLiteral( "ComposerMap" ) );
656-
composerMapElem.setAttribute( QStringLiteral( "name" ), QStringLiteral( "map%1" ).arg( composerMap->id() ) );
669+
composerMapElem.setAttribute( QStringLiteral( "name" ), QStringLiteral( "map%1" ).arg( mapId ) );
670+
mapId++;
657671
composerMapElem.setAttribute( QStringLiteral( "width" ), composerMap->rect().width() );
658672
composerMapElem.setAttribute( QStringLiteral( "height" ), composerMap->rect().height() );
659673
composerTemplateElem.appendChild( composerMapElem );
660674
}
661675

662676
//add available composer labels
663-
QList<QgsComposerLabel *> composerLabelList;
664-
composer->composerItems( composerLabelList );
665-
QList<QgsComposerLabel *>::const_iterator clIt = composerLabelList.constBegin();
677+
QList<QgsLayoutItemLabel *> composerLabelList;
678+
layout->layoutItems<QgsLayoutItemLabel>( composerLabelList );
679+
QList<QgsLayoutItemLabel *>::const_iterator clIt = composerLabelList.constBegin();
666680
for ( ; clIt != composerLabelList.constEnd(); ++clIt )
667681
{
668-
QgsComposerLabel *composerLabel = *clIt;
682+
QgsLayoutItemLabel *composerLabel = *clIt;
669683
QString id = composerLabel->id();
670684
if ( id.isEmpty() )
671685
continue;
@@ -676,12 +690,12 @@ namespace QgsWms
676690
}
677691

678692
//add available composer HTML
679-
QList<QgsComposerHtml *> composerHtmlList;
680-
composer->composerItems( composerHtmlList );
681-
QList<QgsComposerHtml *>::const_iterator chIt = composerHtmlList.constBegin();
693+
QList<QgsLayoutItemHtml *> composerHtmlList;
694+
layout->layoutObjects<QgsLayoutItemHtml>( composerHtmlList );
695+
QList<QgsLayoutItemHtml *>::const_iterator chIt = composerHtmlList.constBegin();
682696
for ( ; chIt != composerHtmlList.constEnd(); ++chIt )
683697
{
684-
QgsComposerHtml *composerHtml = *chIt;
698+
QgsLayoutItemHtml *composerHtml = *chIt;
685699
if ( composerHtml->frameCount() == 0 )
686700
continue;
687701

0 commit comments

Comments
 (0)
Please sign in to comment.