@@ -396,61 +396,79 @@ namespace QgsWms
396
396
QStringLiteral ( " The atlas has no coverage layer" ) );
397
397
}
398
398
399
- QgsAttributeList pkIndexes = cLayer->primaryKeyAttributes ();
400
- if ( pkIndexes.size () < 1 )
401
- {
402
- throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
403
- QStringLiteral ( " An error occurred during the Atlas print" ) );
404
- }
405
- QStringList pkAttributeNames;
406
- for ( int i = 0 ; i < pkIndexes.size (); ++i )
399
+ int maxAtlasFeatures = QgsServerProjectUtils::wmsMaxAtlasFeatures ( *mProject );
400
+ if ( atlasPk.size () == 1 && atlasPk.at ( 0 ) == QStringLiteral ( " *" ) )
407
401
{
408
- pkAttributeNames.append ( cLayer->fields ()[pkIndexes.at ( i )].name () );
402
+ atlas->setFilterFeatures ( false );
403
+ atlas->updateFeatures ();
404
+ if ( atlas->count () > maxAtlasFeatures )
405
+ {
406
+ throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
407
+ QString ( " The project configuration allows to print maximum %1 atlas features at a time" ).arg ( maxAtlasFeatures ) );
408
+ }
409
409
}
410
-
411
- int nAtlasFeatures = atlasPk.size () / pkIndexes.size ();
412
- if ( nAtlasFeatures * pkIndexes.size () != atlasPk.size () ) // Test is atlasPk.size() is a multiple of pkIndexes.size(). Bail out if not
410
+ else
413
411
{
414
- throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
415
- QStringLiteral ( " Wrong number of ATLAS_PK parameters" ) );
416
- }
417
-
418
- // number of atlas features might be restricted
419
- int maxAtlasFeatures = QgsServerProjectUtils::wmsMaxAtlasFeatures ( *mProject );
420
- nAtlasFeatures = std::min ( nAtlasFeatures, maxAtlasFeatures );
412
+ QgsAttributeList pkIndexes = cLayer->primaryKeyAttributes ();
413
+ if ( pkIndexes.size () < 1 )
414
+ {
415
+ throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
416
+ QStringLiteral ( " An error occurred during the Atlas print" ) );
417
+ }
418
+ QStringList pkAttributeNames;
419
+ for ( int i = 0 ; i < pkIndexes.size (); ++i )
420
+ {
421
+ pkAttributeNames.append ( cLayer->fields ()[pkIndexes.at ( i )].name () );
422
+ }
421
423
422
- QString filterString;
423
- int currentAtlasPk = 0 ;
424
+ int nAtlasFeatures = atlasPk.size () / pkIndexes.size ();
425
+ if ( nAtlasFeatures * pkIndexes.size () != atlasPk.size () ) // Test is atlasPk.size() is a multiple of pkIndexes.size(). Bail out if not
426
+ {
427
+ throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
428
+ QStringLiteral ( " Wrong number of ATLAS_PK parameters" ) );
429
+ }
424
430
425
- for ( int i = 0 ; i < nAtlasFeatures; ++i )
426
- {
427
- if ( i > 0 )
431
+ // number of atlas features might be restricted
432
+ if ( nAtlasFeatures > maxAtlasFeatures )
428
433
{
429
- filterString.append ( " OR " );
434
+ throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
435
+ QString ( " %1 atlas features have been requestet, but the project configuration only allows to print %2 atlas features at a time" )
436
+ .arg ( nAtlasFeatures ).arg ( maxAtlasFeatures ) );
430
437
}
431
438
432
- filterString.append ( " ( " );
439
+ QString filterString;
440
+ int currentAtlasPk = 0 ;
433
441
434
- for ( int j = 0 ; j < pkIndexes. size () ; ++j )
442
+ for ( int i = 0 ; i < nAtlasFeatures ; ++i )
435
443
{
436
- if ( j > 0 )
444
+ if ( i > 0 )
437
445
{
438
- filterString.append ( " AND " );
446
+ filterString.append ( " OR " );
439
447
}
440
- filterString.append ( QString ( " \" %1\" = %2" ).arg ( pkAttributeNames.at ( j ) ).arg ( atlasPk.at ( currentAtlasPk ) ) );
441
- ++currentAtlasPk;
442
- }
443
448
444
- filterString.append ( " )" );
445
- }
449
+ filterString.append ( " ( " );
446
450
447
- atlas->setFilterFeatures ( true );
448
- QString errorString;
449
- atlas->setFilterExpression ( filterString, errorString );
450
- if ( !errorString.isEmpty () )
451
- {
452
- throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
453
- QStringLiteral ( " An error occurred during the Atlas print" ) );
451
+ for ( int j = 0 ; j < pkIndexes.size (); ++j )
452
+ {
453
+ if ( j > 0 )
454
+ {
455
+ filterString.append ( " AND " );
456
+ }
457
+ filterString.append ( QString ( " \" %1\" = %2" ).arg ( pkAttributeNames.at ( j ) ).arg ( atlasPk.at ( currentAtlasPk ) ) );
458
+ ++currentAtlasPk;
459
+ }
460
+
461
+ filterString.append ( " )" );
462
+ }
463
+
464
+ atlas->setFilterFeatures ( true );
465
+ QString errorString;
466
+ atlas->setFilterExpression ( filterString, errorString );
467
+ if ( !errorString.isEmpty () )
468
+ {
469
+ throw QgsBadRequestException ( QStringLiteral ( " AtlasPrintError" ),
470
+ QStringLiteral ( " An error occurred during the Atlas print" ) );
471
+ }
454
472
}
455
473
}
456
474
0 commit comments