|
20 | 20 | #include "qgsconfigparserutils.h"
|
21 | 21 | #include "qgslogger.h"
|
22 | 22 | #include "qgsmaplayer.h"
|
| 23 | +#include "qgsmaplayerregistry.h" |
23 | 24 | #include "qgsmaplayerstylemanager.h"
|
24 | 25 | #include "qgsmapserviceexception.h"
|
25 | 26 | #include "qgspallabeling.h"
|
|
38 | 39 | #include "qgscomposerscalebar.h"
|
39 | 40 | #include "qgscomposershape.h"
|
40 | 41 | #include "qgslayertreegroup.h"
|
| 42 | +#include "qgslayertreelayer.h" |
41 | 43 |
|
42 | 44 | #include <QFileInfo>
|
43 | 45 | #include <QTextDocument>
|
@@ -442,17 +444,52 @@ QgsComposition* QgsWMSProjectParser::initComposition( const QString& composerTem
|
442 | 444 | QgsComposerLegend* legend = dynamic_cast< QgsComposerLegend *>( *itemIt );
|
443 | 445 | if ( legend )
|
444 | 446 | {
|
445 |
| -#if 0 |
446 | 447 | QgsLegendModelV2* model = legend->modelV2();
|
| 448 | +#if 0 |
447 | 449 | QgsLayerTreeGroup* root = model->rootGroup();
|
448 | 450 | QStringList layerIds = root->findLayerIds();
|
449 | 451 | throw QgsMapServiceException( "Error", "Composer legend layerIds " + layerIds.join( " ," ) );
|
450 | 452 | #endif
|
451 | 453 | if ( legend->autoUpdateModel() )
|
452 | 454 | {
|
453 |
| - QgsLegendModelV2* model = legend->modelV2(); |
454 | 455 | model->setRootGroup( projectLayerTreeGroup() );
|
455 | 456 | }
|
| 457 | + // if the legend has no map |
| 458 | + // we will load all layers |
| 459 | + const QgsComposerMap* map = legend->composerMap(); |
| 460 | + if ( !map ) |
| 461 | + { |
| 462 | + QgsLayerTreeGroup* root = model->rootGroup(); |
| 463 | + QStringList layerIds = root->findLayerIds(); |
| 464 | + // foreach layer find in the layer tree |
| 465 | + // load it if the layer id is not QgsMapLayerRegistry |
| 466 | + foreach ( QString layerId, layerIds ) |
| 467 | + { |
| 468 | + QgsMapLayer * layer = QgsMapLayerRegistry::instance()->mapLayer( layerId ); |
| 469 | + if ( layer ) |
| 470 | + { |
| 471 | + continue; |
| 472 | + } |
| 473 | + |
| 474 | + QgsLayerTreeLayer* nodeLayer = root->findLayer( layerId ); |
| 475 | + if ( !nodeLayer ) |
| 476 | + { |
| 477 | + continue; |
| 478 | + } |
| 479 | + layer = nodeLayer->layer(); |
| 480 | + if ( !layer ) |
| 481 | + { |
| 482 | + const QHash< QString, QDomElement > &projectLayerElements = mProjectParser->projectLayerElementsById(); |
| 483 | + QHash< QString, QDomElement >::const_iterator layerElemIt = projectLayerElements.find( layerId ); |
| 484 | + if ( layerElemIt != projectLayerElements.constEnd() ) |
| 485 | + { |
| 486 | + layer = mProjectParser->createLayerFromElement( layerElemIt.value(), true ); |
| 487 | + } |
| 488 | + } |
| 489 | + QgsMapLayerRegistry::instance()->addMapLayer( layer ); |
| 490 | + } |
| 491 | + legend->updateLegend(); |
| 492 | + } |
456 | 493 | legendList.push_back( legend );
|
457 | 494 | continue;
|
458 | 495 | }
|
|
0 commit comments