Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
qgscomposerlegend.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgscomposerlegend.cpp - description
3  ---------------------
4  begin : June 2008
5  copyright : (C) 2008 by Marco Hugentobler
6  email : marco dot hugentobler at karto dot baug dot ethz dot ch
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "qgscomposerlegend.h"
19 #include "qgscomposerlegenditem.h"
20 #include "qgscomposermap.h"
21 #include "qgsmaplayer.h"
22 #include "qgsmaplayerregistry.h"
23 #include "qgsmaprenderer.h"
24 #include "qgsrenderer.h" //for brush scaling
25 #include "qgssymbol.h"
26 #include "qgssymbolv2.h"
27 #include <QDomDocument>
28 #include <QDomElement>
29 #include <QPainter>
30 
32  : QgsComposerItem( composition )
33  , mTitle( tr( "Legend" ) )
34  , mBoxSpace( 2 )
35  , mLayerSpace( 2 )
36  , mSymbolSpace( 2 )
37  , mIconLabelSpace( 2 ), mComposerMap( 0 )
38 {
39  //QStringList idList = layerIdList();
40  //mLegendModel.setLayerSet( idList );
41 
42  mTitleFont.setPointSizeF( 16.0 );
43  mGroupFont.setPointSizeF( 14.0 );
44  mLayerFont.setPointSizeF( 12.0 );
45  mItemFont.setPointSizeF( 12.0 );
46 
47  mSymbolWidth = 7;
48  mSymbolHeight = 4;
49  adjustBoxSize();
50 
51  connect( &mLegendModel, SIGNAL( layersChanged() ), this, SLOT( synchronizeWithModel() ) );
52 }
53 
55 {
56 
57 }
58 
60 {
61 
62 }
63 
64 void QgsComposerLegend::paint( QPainter* painter, const QStyleOptionGraphicsItem* itemStyle, QWidget* pWidget )
65 {
66  paintAndDetermineSize( painter );
67 }
68 
69 QSizeF QgsComposerLegend::paintAndDetermineSize( QPainter* painter )
70 {
71  QSizeF size;
72  double maxXCoord = 0;
73 
74 
75 
76  //go through model...
77  QStandardItem* rootItem = mLegendModel.invisibleRootItem();
78  if ( !rootItem )
79  {
80  return size;
81  }
82 
83 
84  if ( painter )
85  {
86  painter->save();
87  drawBackground( painter );
88  painter->setPen( QPen( QColor( 0, 0, 0 ) ) );
89  }
90 
91  int numLayerItems = rootItem->rowCount();
92  QStandardItem* currentLayerItem = 0;
93  double currentYCoordinate = mBoxSpace;
94 
95  //font metrics
96 
97  //draw title
98  currentYCoordinate += fontAscentMillimeters( mTitleFont );
99  if ( painter )
100  {
101  painter->setPen( QColor( 0, 0, 0 ) );
102  drawText( painter, mBoxSpace, currentYCoordinate, mTitle, mTitleFont );
103  }
104 
105  maxXCoord = 2 * mBoxSpace + textWidthMillimeters( mTitleFont, mTitle );
106 
107  double currentItemMaxX = 0; //maximum x-coordinate for current item
108  for ( int i = 0; i < numLayerItems; ++i )
109  {
110  currentLayerItem = rootItem->child( i );
111  QgsComposerLegendItem* currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentLayerItem );
112  if ( currentLegendItem )
113  {
114  QgsComposerLegendItem::ItemType type = currentLegendItem->itemType();
115  if ( type == QgsComposerLegendItem::GroupItem )
116  {
117  drawGroupItem( painter, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
118  maxXCoord = qMax( maxXCoord, currentItemMaxX );
119  }
120  else if ( type == QgsComposerLegendItem::LayerItem )
121  {
122  drawLayerItem( painter, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoordinate, currentItemMaxX );
123  maxXCoord = qMax( maxXCoord, currentItemMaxX );
124  }
125  }
126  }
127 
128  currentYCoordinate += mBoxSpace;
129 
130  size.setHeight( currentYCoordinate );
131  size.setWidth( maxXCoord );
132 
133  //adjust box if width or height is to small
134  if ( painter && currentYCoordinate > rect().height() )
135  {
136  setSceneRect( QRectF( transform().dx(), transform().dy(), rect().width(), currentYCoordinate ) );
137  }
138  if ( painter && maxXCoord > rect().width() )
139  {
140  setSceneRect( QRectF( transform().dx(), transform().dy(), maxXCoord, rect().height() ) );
141  }
142 
143  if ( painter )
144  {
145  painter->restore();
146 
147  //draw frame and selection boxes if necessary
148  drawFrame( painter );
149  if ( isSelected() )
150  {
151  drawSelectionBoxes( painter );
152  }
153  }
154 
155  return size;
156 }
157 
158 void QgsComposerLegend::drawGroupItem( QPainter* p, QgsComposerGroupItem* groupItem, double& currentYCoord, double& maxXCoord )
159 {
160  if ( !p || !groupItem )
161  {
162  return;
163  }
164 
165  currentYCoord += mLayerSpace;
166  currentYCoord += fontAscentMillimeters( mGroupFont );
167 
168  p->setPen( QColor( 0, 0, 0 ) );
169  drawText( p, mBoxSpace, currentYCoord, groupItem->text(), mGroupFont );
170 
171  //maximum x-coordinate of current item
172  double currentMaxXCoord = 2 * mBoxSpace + textWidthMillimeters( mGroupFont, groupItem->text() );
173  maxXCoord = qMax( currentMaxXCoord, maxXCoord );
174 
175  //children can be other group items or layer items
176  int numChildItems = groupItem->rowCount();
177  QStandardItem* currentChildItem = 0;
178 
179  for ( int i = 0; i < numChildItems; ++i )
180  {
181  currentChildItem = groupItem->child( i );
182  QgsComposerLegendItem* currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentChildItem );
183  QgsComposerLegendItem::ItemType type = currentLegendItem->itemType();
184  if ( type == QgsComposerLegendItem::GroupItem )
185  {
186  drawGroupItem( p, dynamic_cast<QgsComposerGroupItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
187  maxXCoord = qMax( currentMaxXCoord, maxXCoord );
188  }
189  else if ( type == QgsComposerLegendItem::LayerItem )
190  {
191  drawLayerItem( p, dynamic_cast<QgsComposerLayerItem*>( currentLegendItem ), currentYCoord, currentMaxXCoord );
192  maxXCoord = qMax( currentMaxXCoord, maxXCoord );
193  }
194  }
195 }
196 
197 void QgsComposerLegend::drawLayerItem( QPainter* p, QgsComposerLayerItem* layerItem, double& currentYCoord, double& maxXCoord )
198 {
199  if ( !layerItem )
200  {
201  return;
202  }
203 
204  int opacity = 255;
205  QgsMapLayer* currentLayer = QgsMapLayerRegistry::instance()->mapLayer( layerItem->layerID() );
206  if ( currentLayer )
207  {
208  opacity = currentLayer->getTransparency();
209  }
210 
211  //Let the user omit the layer title item by having an empty layer title string
212  if ( !layerItem->text().isEmpty() )
213  {
214  currentYCoord += mLayerSpace;
215  currentYCoord += fontAscentMillimeters( mLayerFont );
216 
217  //draw layer Item
218  if ( p )
219  {
220  p->setPen( QColor( 0, 0, 0 ) );
221  drawText( p, mBoxSpace, currentYCoord, layerItem->text(), mLayerFont );
222  }
223 
224  maxXCoord = qMax( maxXCoord, 2 * mBoxSpace + textWidthMillimeters( mLayerFont, layerItem->text() ) );
225  }
226  else //layer title omited
227  {
228  //symbol space will be added before the item later
229  currentYCoord += ( mLayerSpace - mSymbolSpace );
230  }
231 
232  //and child items
233  drawLayerChildItems( p, layerItem, currentYCoord, maxXCoord, opacity );
234 }
235 
237 {
238  QSizeF size = paintAndDetermineSize( 0 );
239  if ( size.isValid() )
240  {
241  setSceneRect( QRectF( transform().dx(), transform().dy(), size.width(), size.height() ) );
242  }
243 }
244 
245 void QgsComposerLegend::drawLayerChildItems( QPainter* p, QStandardItem* layerItem, double& currentYCoord, double& maxXCoord, int layerOpacity )
246 {
247  if ( !layerItem )
248  {
249  return;
250  }
251 
252  //Draw all symbols first and the texts after (to find out the x coordinate to have the text aligned)
253  QList<double> childYCoords;
254  QList<double> realItemHeights;
255 
256  double textHeight = fontHeightCharacterMM( mItemFont, QChar( '0' ) );
257  double itemHeight = qMax( mSymbolHeight, textHeight );
258 
259  double textAlignCoord = 0; //alignment for legend text
260 
261  QStandardItem* currentItem;
262 
263  int numChildren = layerItem->rowCount();
264 
265  for ( int i = 0; i < numChildren; ++i )
266  {
267  //real symbol height. Can be different from standard height in case of point symbols
268  double realSymbolHeight;
269  double realItemHeight = itemHeight; //will be adjusted if realSymbolHeight turns out to be larger
270 
271  currentYCoord += mSymbolSpace;
272  double currentXCoord = mBoxSpace;
273 
274  currentItem = layerItem->child( i, 0 );
275 
276  if ( !currentItem )
277  {
278  continue;
279  }
280 
281  QgsSymbol* symbol = 0;
282  QgsComposerSymbolItem* symbolItem = dynamic_cast<QgsComposerSymbolItem*>( currentItem );
283  if ( symbolItem )
284  {
285  symbol = symbolItem->symbol();
286  }
287 
288  QgsSymbolV2* symbolNg = 0;
289  QgsComposerSymbolV2Item* symbolV2Item = dynamic_cast<QgsComposerSymbolV2Item*>( currentItem );
290  if ( symbolV2Item )
291  {
292  symbolNg = symbolV2Item->symbolV2();
293  }
294  QgsComposerRasterSymbolItem* rasterItem = dynamic_cast<QgsComposerRasterSymbolItem*>( currentItem );
295 
296  if ( symbol ) //item with symbol?
297  {
298  //draw symbol
299  drawSymbol( p, symbol, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, currentXCoord, realSymbolHeight, layerOpacity );
300  realItemHeight = qMax( realSymbolHeight, itemHeight );
301  currentXCoord += mIconLabelSpace;
302  }
303  else if ( symbolNg ) //item with symbol NG?
304  {
305  drawSymbolV2( p, symbolNg, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, currentXCoord, realSymbolHeight, layerOpacity );
306  realItemHeight = qMax( realSymbolHeight, itemHeight );
307  currentXCoord += mIconLabelSpace;
308  }
309  else if ( rasterItem )
310  {
311  if ( p )
312  {
313  p->setBrush( rasterItem->color() );
314  p->drawRect( QRectF( currentXCoord, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, mSymbolWidth, mSymbolHeight ) );
315  }
316  currentXCoord += mSymbolWidth;
317  currentXCoord += mIconLabelSpace;
318  }
319  else //item with icon?
320  {
321  QIcon symbolIcon = currentItem->icon();
322  if ( !symbolIcon.isNull() && p )
323  {
324  symbolIcon.paint( p, currentXCoord, currentYCoord + ( itemHeight - mSymbolHeight ) / 2, mSymbolWidth, mSymbolHeight );
325  currentXCoord += mSymbolWidth;
326  currentXCoord += mIconLabelSpace;
327  }
328  }
329 
330  childYCoords.push_back( currentYCoord );
331  realItemHeights.push_back( realItemHeight );
332  currentYCoord += realItemHeight;
333  textAlignCoord = qMax( currentXCoord, textAlignCoord );
334  }
335 
336  maxXCoord = qMax( maxXCoord, textAlignCoord );
337  for ( int i = 0; i < numChildren; ++i )
338  {
339  if ( p )
340  {
341  p->setPen( QColor( 0, 0, 0 ) );
342  drawText( p, textAlignCoord, childYCoords.at( i ) + textHeight + ( realItemHeights.at( i ) - textHeight ) / 2, layerItem->child( i, 0 )->text(), mItemFont );
343  maxXCoord = qMax( maxXCoord, textAlignCoord + mBoxSpace + textWidthMillimeters( mItemFont, layerItem->child( i, 0 )->text() ) );
344  }
345  }
346 }
347 
348 void QgsComposerLegend::drawSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity ) const
349 {
350  if ( !s )
351  {
352  return;
353  }
354 
355  QGis::GeometryType symbolType = s->type();
356  switch ( symbolType )
357  {
358  case QGis::Point:
359  drawPointSymbol( p, s, currentYCoord, currentXPosition, symbolHeight, layerOpacity );
360  break;
361  case QGis::Line:
362  drawLineSymbol( p, s, currentYCoord, currentXPosition, layerOpacity );
363  symbolHeight = mSymbolHeight;
364  break;
365  case QGis::Polygon:
366  drawPolygonSymbol( p, s, currentYCoord, currentXPosition, layerOpacity );
367  symbolHeight = mSymbolHeight;
368  break;
370  case QGis::NoGeometry:
371  // shouldn't occur
372  break;
373  }
374 }
375 
376 void QgsComposerLegend::drawSymbolV2( QPainter* p, QgsSymbolV2* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int layerOpacity ) const
377 {
378  if ( !p || !s )
379  {
380  return;
381  }
382 
383  double rasterScaleFactor = 1.0;
384  if ( p )
385  {
386  QPaintDevice* paintDevice = p->device();
387  if ( !paintDevice )
388  {
389  return;
390  }
391  rasterScaleFactor = ( paintDevice->logicalDpiX() + paintDevice->logicalDpiY() ) / 2.0 / 25.4;
392  }
393 
394  //consider relation to composer map for symbol sizes in mm
395  bool sizeInMapUnits = s->outputUnit() == QgsSymbolV2::MapUnit;
396  double mmPerMapUnit = 1;
397  if ( mComposerMap )
398  {
399  mmPerMapUnit = mComposerMap->mapUnitsToMM();
400  }
401  QgsMarkerSymbolV2* markerSymbol = dynamic_cast<QgsMarkerSymbolV2*>( s );
402 
403  //Consider symbol size for point markers
404  double height = mSymbolHeight;
405  double width = mSymbolWidth;
406  double size = 0;
407  //Center small marker symbols
408  double widthOffset = 0;
409  double heightOffset = 0;
410 
411  if ( markerSymbol )
412  {
413  size = markerSymbol->size();
414  height = size;
415  width = size;
416  if ( mComposerMap && sizeInMapUnits )
417  {
418  height *= mmPerMapUnit;
419  width *= mmPerMapUnit;
420  markerSymbol->setSize( width );
421  }
422  if ( width < mSymbolWidth )
423  {
424  widthOffset = ( mSymbolWidth - width ) / 2.0;
425  }
426  if ( height < mSymbolHeight )
427  {
428  heightOffset = ( mSymbolHeight - height ) / 2.0;
429  }
430  }
431 
432  p->save();
433  p->translate( currentXPosition + widthOffset, currentYCoord + heightOffset );
434  p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
435 
436  if ( markerSymbol && sizeInMapUnits )
437  {
439  }
440  s->drawPreviewIcon( p, QSize( width * rasterScaleFactor, height * rasterScaleFactor ) );
441 
442  if ( markerSymbol && sizeInMapUnits )
443  {
445  markerSymbol->setSize( size );
446  }
447 
448  p->restore();
449  currentXPosition += width;
450  currentXPosition += 2 * widthOffset;
451  symbolHeight = height + 2 * heightOffset;
452 }
453 
454 void QgsComposerLegend::drawPointSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, double& symbolHeight, int opacity ) const
455 {
456  if ( !s )
457  {
458  return;
459  }
460 
461  QImage pointImage;
462  double rasterScaleFactor = 1.0;
463  if ( p )
464  {
465  QPaintDevice* paintDevice = p->device();
466  if ( !paintDevice )
467  {
468  return;
469  }
470 
471  rasterScaleFactor = ( paintDevice->logicalDpiX() + paintDevice->logicalDpiY() ) / 2.0 / 25.4;
472  }
473 
474  //width scale is 1.0
475  pointImage = s->getPointSymbolAsImage( 1.0, false, Qt::yellow, 1.0, 0.0, rasterScaleFactor, opacity / 255.0 );
476 
477  if ( p )
478  {
479  p->save();
480  p->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
481 
482  QPointF imageTopLeft( currentXPosition * rasterScaleFactor, currentYCoord * rasterScaleFactor );
483  p->drawImage( imageTopLeft, pointImage );
484  p->restore();
485  }
486 
487  currentXPosition += s->pointSize(); //pointImage.width() / rasterScaleFactor;
488  symbolHeight = s->pointSize(); //pointImage.height() / rasterScaleFactor;
489 }
490 
491 void QgsComposerLegend::drawLineSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity ) const
492 {
493  if ( !s )
494  {
495  return;
496  }
497 
498  double yCoord = currentYCoord + mSymbolHeight / 2;
499 
500  if ( p )
501  {
502  p->save();
503  QPen symbolPen = s->pen();
504  QColor penColor = symbolPen.color();
505  penColor.setAlpha( opacity );
506  symbolPen.setColor( penColor );
507  symbolPen.setCapStyle( Qt::FlatCap );
508  p->setPen( symbolPen );
509  p->drawLine( QPointF( currentXPosition, yCoord ), QPointF( currentXPosition + mSymbolWidth, yCoord ) );
510  p->restore();
511  }
512 
513  currentXPosition += mSymbolWidth;
514 }
515 
516 void QgsComposerLegend::drawPolygonSymbol( QPainter* p, QgsSymbol* s, double currentYCoord, double& currentXPosition, int opacity ) const
517 {
518  if ( !s )
519  {
520  return;
521  }
522 
523  if ( p )
524  {
525  //scale brush and set transparencies
526  QBrush symbolBrush = s->brush();
527  QColor brushColor = symbolBrush.color();
528  brushColor.setAlpha( opacity );
529  symbolBrush.setColor( brushColor );
530  QPaintDevice* paintDevice = p->device();
531  if ( paintDevice )
532  {
533  double rasterScaleFactor = ( paintDevice->logicalDpiX() + paintDevice->logicalDpiY() ) / 2.0 / 25.4;
534  QgsRenderer::scaleBrush( symbolBrush, rasterScaleFactor );
535  }
536  p->setBrush( symbolBrush );
537 
538  QPen symbolPen = s->pen();
539  QColor penColor = symbolPen.color();
540  penColor.setAlpha( opacity );
541  symbolPen.setColor( penColor );
542  p->setPen( symbolPen );
543 
544  p->drawRect( QRectF( currentXPosition, currentYCoord, mSymbolWidth, mSymbolHeight ) );
545  }
546 
547  currentXPosition += mSymbolWidth;
548 }
549 
551 {
552  //take layer list from map renderer (to have legend order)
553  if ( mComposition )
554  {
556  if ( r )
557  {
558  return r->layerSet();
559  }
560  }
561  return QStringList();
562 }
563 
565 {
566  adjustBoxSize();
567  update();
568 }
569 
570 void QgsComposerLegend::setTitleFont( const QFont& f )
571 {
572  mTitleFont = f;
573  adjustBoxSize();
574  update();
575 }
576 
577 void QgsComposerLegend::setGroupFont( const QFont& f )
578 {
579  mGroupFont = f;
580  adjustBoxSize();
581  update();
582 }
583 
584 void QgsComposerLegend::setLayerFont( const QFont& f )
585 {
586  mLayerFont = f;
587  adjustBoxSize();
588  update();
589 }
590 
591 void QgsComposerLegend::setItemFont( const QFont& f )
592 {
593  mItemFont = f;
594  adjustBoxSize();
595  update();
596 }
597 
599 {
600  return mTitleFont;
601 }
602 
604 {
605  return mGroupFont;
606 }
607 
609 {
610  return mLayerFont;
611 }
612 
614 {
615  return mItemFont;
616 }
617 
619 {
621  adjustBoxSize();
622  update();
623 }
624 
625 bool QgsComposerLegend::writeXML( QDomElement& elem, QDomDocument & doc ) const
626 {
627  if ( elem.isNull() )
628  {
629  return false;
630  }
631 
632  QDomElement composerLegendElem = doc.createElement( "ComposerLegend" );
633 
634  //write general properties
635  composerLegendElem.setAttribute( "title", mTitle );
636  composerLegendElem.setAttribute( "titleFont", mTitleFont.toString() );
637  composerLegendElem.setAttribute( "groupFont", mGroupFont.toString() );
638  composerLegendElem.setAttribute( "layerFont", mLayerFont.toString() );
639  composerLegendElem.setAttribute( "itemFont", mItemFont.toString() );
640  composerLegendElem.setAttribute( "boxSpace", QString::number( mBoxSpace ) );
641  composerLegendElem.setAttribute( "layerSpace", QString::number( mLayerSpace ) );
642  composerLegendElem.setAttribute( "symbolSpace", QString::number( mSymbolSpace ) );
643  composerLegendElem.setAttribute( "iconLabelSpace", QString::number( mIconLabelSpace ) );
644  composerLegendElem.setAttribute( "symbolWidth", mSymbolWidth );
645  composerLegendElem.setAttribute( "symbolHeight", mSymbolHeight );
646 
647  if ( mComposerMap )
648  {
649  composerLegendElem.setAttribute( "map", mComposerMap->id() );
650  }
651 
652  //write model properties
653  mLegendModel.writeXML( composerLegendElem, doc );
654 
655  elem.appendChild( composerLegendElem );
656  return _writeXML( composerLegendElem, doc );
657 }
658 
659 bool QgsComposerLegend::readXML( const QDomElement& itemElem, const QDomDocument& doc )
660 {
661  if ( itemElem.isNull() )
662  {
663  return false;
664  }
665 
666  //read general properties
667  mTitle = itemElem.attribute( "title" );
668  //title font
669  QString titleFontString = itemElem.attribute( "titleFont" );
670  if ( !titleFontString.isEmpty() )
671  {
672  mTitleFont.fromString( titleFontString );
673  }
674  //group font
675  QString groupFontString = itemElem.attribute( "groupFont" );
676  if ( !groupFontString.isEmpty() )
677  {
678  mGroupFont.fromString( groupFontString );
679  }
680 
681  //layer font
682  QString layerFontString = itemElem.attribute( "layerFont" );
683  if ( !layerFontString.isEmpty() )
684  {
685  mLayerFont.fromString( layerFontString );
686  }
687  //item font
688  QString itemFontString = itemElem.attribute( "itemFont" );
689  if ( !itemFontString.isEmpty() )
690  {
691  mItemFont.fromString( itemFontString );
692  }
693 
694  //spaces
695  mBoxSpace = itemElem.attribute( "boxSpace", "2.0" ).toDouble();
696  mLayerSpace = itemElem.attribute( "layerSpace", "3.0" ).toDouble();
697  mSymbolSpace = itemElem.attribute( "symbolSpace", "2.0" ).toDouble();
698  mIconLabelSpace = itemElem.attribute( "iconLabelSpace", "2.0" ).toDouble();
699  mSymbolWidth = itemElem.attribute( "symbolWidth", "7.0" ).toDouble();
700  mSymbolHeight = itemElem.attribute( "symbolHeight", "14.0" ).toDouble();
701 
702  //composer map
703  if ( !itemElem.attribute( "map" ).isEmpty() )
704  {
705  mComposerMap = mComposition->getComposerMapById( itemElem.attribute( "map" ).toInt() );
706  }
707 
708  //read model properties
709  QDomNodeList modelNodeList = itemElem.elementsByTagName( "Model" );
710  if ( modelNodeList.size() > 0 )
711  {
712  QDomElement modelElem = modelNodeList.at( 0 ).toElement();
713  mLegendModel.readXML( modelElem, doc );
714  }
715 
716  //restore general composer item properties
717  QDomNodeList composerItemList = itemElem.elementsByTagName( "ComposerItem" );
718  if ( composerItemList.size() > 0 )
719  {
720  QDomElement composerItemElem = composerItemList.at( 0 ).toElement();
721  _readXML( composerItemElem, doc );
722  }
723 
724  emit itemChanged();
725  return true;
726 }
727 
729 {
730  mComposerMap = map;
731  QObject::connect( map, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
732 }
733 
735 {
736  disconnect( mComposerMap, SIGNAL( destroyed( QObject* ) ), this, SLOT( invalidateCurrentMap() ) );
737  mComposerMap = 0;
738 }