Navigation Menu

Skip to content

Commit

Permalink
Merge pull request #8781 from mhugent/get_atlas_print
Browse files Browse the repository at this point in the history
[server][needs-docs] Get atlas print
  • Loading branch information
mhugent committed Jan 7, 2019
2 parents 0c71e72 + f1d2239 commit 54a5fae
Show file tree
Hide file tree
Showing 13 changed files with 512 additions and 242 deletions.
9 changes: 9 additions & 0 deletions python/server/auto_generated/qgsserverprojectutils.sip.in
Expand Up @@ -152,6 +152,15 @@ Returns the quality for WMS images defined in a QGIS project.
:param project: the QGIS project

:return: quality if defined in project, -1 otherwise.
%End

int wmsMaxAtlasFeatures( const QgsProject &project );
%Docstring
Returns the maximum number of atlas features which can be printed in a request

:param project: the QGIS project

:return: the number of atlas features
%End

bool wmsUseLayerIds( const QgsProject &project );
Expand Down
5 changes: 5 additions & 0 deletions src/app/qgsprojectproperties.cpp
Expand Up @@ -637,6 +637,8 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mWMSImageQualitySpinBox->setValue( imageQuality );
}

mWMSMaxAtlasFeaturesSpinBox->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 ) );

mWMTSUrlLineEdit->setText( QgsProject::instance()->readEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), QString() ) );
mWMTSMinScaleLineEdit->setValue( QgsProject::instance()->readNumEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), 5000 ) );

Expand Down Expand Up @@ -1260,6 +1262,9 @@ void QgsProjectProperties::apply()
QgsProject::instance()->writeEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), imageQualityValue );
}

int maxAtlasFeatures = mWMSMaxAtlasFeaturesSpinBox->value();
QgsProject::instance()->writeEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), maxAtlasFeatures );

QgsProject::instance()->writeEntry( QStringLiteral( "WMTSUrl" ), QStringLiteral( "/" ), mWMTSUrlLineEdit->text() );
QgsProject::instance()->writeEntry( QStringLiteral( "WMTSMinScale" ), QStringLiteral( "/" ), mWMTSMinScaleLineEdit->value() );
bool wmtsProject = false;
Expand Down
5 changes: 5 additions & 0 deletions src/server/qgsserverprojectutils.cpp
Expand Up @@ -111,6 +111,11 @@ int QgsServerProjectUtils::wmsImageQuality( const QgsProject &project )
return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
}

int QgsServerProjectUtils::wmsMaxAtlasFeatures( const QgsProject &project )
{
return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 );
}

bool QgsServerProjectUtils::wmsInfoFormatSia2045( const QgsProject &project )
{
QString sia2045 = project.readEntry( QStringLiteral( "WMSInfoFormatSIA2045" ), QStringLiteral( "/" ), "" );
Expand Down
7 changes: 7 additions & 0 deletions src/server/qgsserverprojectutils.h
Expand Up @@ -147,6 +147,13 @@ namespace QgsServerProjectUtils
*/
SERVER_EXPORT int wmsImageQuality( const QgsProject &project );

/**
* Returns the maximum number of atlas features which can be printed in a request
* \param project the QGIS project
* \return the number of atlas features
*/
SERVER_EXPORT int wmsMaxAtlasFeatures( const QgsProject &project );

/**
* Returns if layer ids are used as name in WMS.
* \param project the QGIS project
Expand Down
38 changes: 38 additions & 0 deletions src/server/services/wms/qgswmsgetcapabilities.cpp
Expand Up @@ -23,6 +23,7 @@
#include "qgsserverprojectutils.h"

#include "qgslayoutmanager.h"
#include "qgslayoutatlas.h"
#include "qgsprintlayout.h"
#include "qgslayoutitemmap.h"
#include "qgslayoutitemlabel.h"
Expand Down Expand Up @@ -680,6 +681,27 @@ namespace QgsWms
composerTemplateElem.setAttribute( QStringLiteral( "width" ), width.length() );
composerTemplateElem.setAttribute( QStringLiteral( "height" ), height.length() );

//atlas enabled and atlas covering layer
QgsLayoutAtlas *atlas = layout->atlas();
if ( atlas && atlas->enabled() )
{
composerTemplateElem.setAttribute( QStringLiteral( "atlasEnabled" ), QStringLiteral( "1" ) );
QgsVectorLayer *cLayer = atlas->coverageLayer();
if ( cLayer )
{
QString layerName = cLayer->shortName();
if ( QgsServerProjectUtils::wmsUseLayerIds( *project ) )
{
layerName = cLayer->id();
}
else if ( layerName.isEmpty() )
{
layerName = cLayer->name();
}
composerTemplateElem.setAttribute( QStringLiteral( "atlasCoverageLayer" ), layerName );
}
}

//add available composer maps and their size in mm
QList<QgsLayoutItemMap *> layoutMapList;
layout->layoutItems<QgsLayoutItemMap>( layoutMapList );
Expand Down Expand Up @@ -1739,6 +1761,22 @@ namespace QgsWms
//displayfield
layerElem.setAttribute( QStringLiteral( "displayField" ), displayField );

//primary key
QgsAttributeList pkAttributes = vLayer->primaryKeyAttributes();
if ( pkAttributes.size() > 0 )
{
QDomElement pkElem = doc.createElement( QStringLiteral( "PrimaryKey" ) );
QgsAttributeList::const_iterator pkIt = pkAttributes.constBegin();
for ( ; pkIt != pkAttributes.constEnd(); ++pkIt )
{
QDomElement pkAttributeElem = doc.createElement( QStringLiteral( "PrimaryKeyAttribute" ) );
QDomText pkAttName = doc.createTextNode( layerFields.at( *pkIt ).name() );
pkAttributeElem.appendChild( pkAttName );
pkElem.appendChild( pkAttributeElem );
}
layerElem.appendChild( pkElem );
}

//geometry type
layerElem.setAttribute( QStringLiteral( "geometryType" ), QgsWkbTypes::displayString( vLayer->wkbType() ) );

Expand Down
9 changes: 9 additions & 0 deletions src/server/services/wms/qgswmsparameters.cpp
Expand Up @@ -498,6 +498,10 @@ namespace QgsWms

const QgsWmsParameter pWmtver( QgsWmsParameter::WMTVER );
save( pWmtver );

const QgsWmsParameter pAtlasPk( QgsWmsParameter::ATLAS_PK,
QVariant::StringList );
save( pAtlasPk );
}

QgsWmsParameters::QgsWmsParameters( const QgsServerParameters &parameters )
Expand Down Expand Up @@ -1134,6 +1138,11 @@ namespace QgsWms
return label;
}

QStringList QgsWmsParameters::atlasPk() const
{
return mWmsParameters[ QgsWmsParameter::ATLAS_PK ].toStringList();
}

QStringList QgsWmsParameters::highlightLabelString() const
{
return mWmsParameters[ QgsWmsParameter::HIGHLIGHT_LABELSTRING ].toStringList( ';' );
Expand Down
10 changes: 9 additions & 1 deletion src/server/services/wms/qgswmsparameters.h
Expand Up @@ -168,7 +168,8 @@ namespace QgsWms
GRID_INTERVAL_Y,
WITH_GEOMETRY,
WITH_MAPTIP,
WMTVER
WMTVER,
ATLAS_PK
};
Q_ENUM( Name )

Expand Down Expand Up @@ -1148,6 +1149,13 @@ namespace QgsWms
*/
QString layoutParameter( const QString &id, bool &ok ) const;

/**
* Returns the ATLAS_PK parameter
* \returns The ATLAS_PK parameter
* \since QGIS 3.6
*/
QStringList atlasPk() const;

private:
bool loadParameter( const QString &name, const QString &value ) override;

Expand Down

0 comments on commit 54a5fae

Please sign in to comment.