Quantum GIS API Documentation  1.7.4
src/core/composer/qgslegendmodel.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002                          qgslegendmodel.cpp  -  description
00003                          ------------------
00004     begin                : June 2008
00005     copyright            : (C) 2008 by Marco Hugentobler
00006     email                : marco dot hugentobler at karto dot baug dot ethz dot ch
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "qgslegendmodel.h"
00019 #include "qgscomposerlegenditem.h"
00020 #include "qgsfield.h"
00021 #include "qgsmaplayer.h"
00022 #include "qgsmaplayerregistry.h"
00023 #include "qgsrasterlayer.h"
00024 #include "qgsrenderer.h"
00025 #include "qgsrendererv2.h"
00026 #include "qgssymbollayerv2utils.h"
00027 #include "qgssymbol.h"
00028 #include "qgsvectordataprovider.h"
00029 #include "qgsvectorlayer.h"
00030 #include <QApplication>
00031 #include <QDomDocument>
00032 #include <QDomElement>
00033 #include <QMimeData>
00034 #include <QSettings>
00035 #include <QMessageBox>
00036 
00037 QgsLegendModel::QgsLegendModel(): QStandardItemModel(), mAutoUpdate( true )
00038 {
00039   if ( QgsMapLayerRegistry::instance() )
00040   {
00041     connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
00042     connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
00043   }
00044   setItemPrototype( new QgsComposerSymbolItem() );
00045 
00046   QWidgetList topLevelWidgets = QApplication::topLevelWidgets();
00047   mHasTopLevelWindow = ( topLevelWidgets.size() > 0 );
00048 }
00049 
00050 QgsLegendModel::~QgsLegendModel()
00051 {
00052 }
00053 
00054 void QgsLegendModel::setLayerSetAndGroups( const QStringList& layerIds, const QList< GroupLayerInfo >& groupInfo )
00055 {
00056   setLayerSet( layerIds );
00057 
00058   QStandardItem* currentItem = 0;
00059   QStandardItem* currentGroupItem = 0;
00060   int i = 0;
00061 
00062   QList< GroupLayerInfo >::const_iterator infoIt = groupInfo.constBegin();
00063   for ( ; infoIt != groupInfo.constEnd() && i < invisibleRootItem()->rowCount(); )
00064   {
00065     currentItem = invisibleRootItem()->child( i, 0 );
00066     QString infoKey = infoIt->first;
00067     if ( infoKey.isNull() ) //a toplevel layer
00068     {
00069       ++i;
00070     }
00071     else //a group
00072     {
00073       currentGroupItem = addGroup( infoKey, i );
00074       ++i;
00075       QList<QString> layerList = infoIt->second;
00076       QList<QString>::const_iterator groupLayerIt = layerList.constBegin();
00077       for ( ; currentItem && ( groupLayerIt != layerList.constEnd() ); ++groupLayerIt )
00078       {
00079         //check if current item is contained in this group
00080         QgsComposerLayerItem* layerItem = dynamic_cast<QgsComposerLayerItem*>( currentItem );
00081         if ( !layerItem )
00082         {
00083           return; //should never happen
00084         }
00085         //QString layerID = currentItem->data(Qt::UserRole + 2).toString();
00086         QString layerID = layerItem->layerID();
00087         if ( layerList.contains( layerID ) )
00088         {
00089           takeRow( i );
00090           currentGroupItem->setChild( currentGroupItem->rowCount(), 0, currentItem );
00091         }
00092         else
00093         {
00094           ++i;
00095         }
00096         currentItem = invisibleRootItem()->child( i, 0 );
00097       }
00098     }
00099     ++infoIt;
00100   }
00101 }
00102 
00103 void QgsLegendModel::setLayerSet( const QStringList& layerIds )
00104 {
00105   mLayerIds = layerIds;
00106 
00107   //for now clear the model and add the new entries
00108   clear();
00109 
00110   QStringList::const_iterator idIter = mLayerIds.constBegin();
00111   QgsMapLayer* currentLayer = 0;
00112 
00113   for ( ; idIter != mLayerIds.constEnd(); ++idIter )
00114   {
00115     currentLayer = QgsMapLayerRegistry::instance()->mapLayer( *idIter );
00116     addLayer( currentLayer );
00117   }
00118 }
00119 
00120 QStandardItem* QgsLegendModel::addGroup( QString text, int position )
00121 {
00122   QgsComposerGroupItem* groupItem = new QgsComposerGroupItem( text );
00123   if ( position == -1 )
00124   {
00125     invisibleRootItem()->insertRow( invisibleRootItem()->rowCount(), groupItem );
00126   }
00127   else
00128   {
00129     invisibleRootItem()->insertRow( position, groupItem );
00130   }
00131   return groupItem;
00132 }
00133 
00134 int QgsLegendModel::addVectorLayerItemsV2( QStandardItem* layerItem, QgsVectorLayer* vlayer )
00135 {
00136   if ( !layerItem || !vlayer )
00137   {
00138     return 1;
00139   }
00140 
00141   QgsFeatureRendererV2* renderer = vlayer->rendererV2();
00142   if ( !renderer )
00143   {
00144     return 2;
00145   }
00146 
00147   QgsLegendSymbolList lst = renderer->legendSymbolItems();
00148   QgsLegendSymbolList::const_iterator symbolIt = lst.constBegin();
00149   for ( ; symbolIt != lst.constEnd(); ++symbolIt )
00150   {
00151     QgsComposerSymbolV2Item* currentSymbolItem = new QgsComposerSymbolV2Item( symbolIt->first );
00152     currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
00153     if ( symbolIt->second )
00154     {
00155       if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
00156       {
00157         currentSymbolItem->setIcon( QgsSymbolLayerV2Utils::symbolPreviewIcon( symbolIt->second, QSize( 30, 30 ) ) );
00158       }
00159       currentSymbolItem->setSymbolV2( symbolIt->second->clone() );
00160     }
00161     layerItem->setChild( layerItem->rowCount(), 0, currentSymbolItem );
00162   }
00163 
00164   return 0;
00165 }
00166 
00167 int QgsLegendModel::addVectorLayerItems( QStandardItem* layerItem, QgsVectorLayer* vlayer )
00168 {
00169   if ( !layerItem || !vlayer )
00170   {
00171     return 1;
00172   }
00173 
00174   int opacity = vlayer->getTransparency();
00175 
00176   const QgsRenderer* vectorRenderer = vlayer->renderer();
00177   if ( !vectorRenderer )
00178   {
00179     return 3;
00180   }
00181 
00182   //text field that describes classification attribute?
00183   QSettings settings;
00184   if ( settings.value( "/qgis/showLegendClassifiers", false ).toBool() )
00185   {
00186     QgsFieldMap layerFields = vlayer->pendingFields();
00187     QgsAttributeList attributes = vectorRenderer->classificationAttributes();
00188     QgsAttributeList::const_iterator att_it = attributes.constBegin();
00189     for ( ; att_it != attributes.constEnd(); ++att_it )
00190     {
00191       QgsFieldMap::const_iterator fieldIt = layerFields.find( *att_it );
00192       if ( fieldIt != layerFields.constEnd() )
00193       {
00194         QString attributeName = vlayer->attributeDisplayName( fieldIt.key() );
00195         QStandardItem* attributeItem = new QStandardItem( attributeName );
00196         attributeItem->setData( QgsLegendModel::ClassificationItem, Qt::UserRole + 1 ); //first user data stores the item type
00197         attributeItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
00198         layerItem->setChild( layerItem->rowCount(), 0, attributeItem );
00199       }
00200     }
00201   }
00202 
00203   const QList<QgsSymbol*> vectorSymbols = vectorRenderer->symbols();
00204   QList<QgsSymbol*>::const_iterator symbolIt = vectorSymbols.constBegin();
00205 
00206   for ( ; symbolIt != vectorSymbols.constEnd(); ++symbolIt )
00207   {
00208     if ( !( *symbolIt ) )
00209     {
00210       continue;
00211     }
00212 
00213     QStandardItem* currentSymbolItem = itemFromSymbol( *symbolIt, opacity, vlayer->id() );
00214     if ( !currentSymbolItem )
00215     {
00216       continue;
00217     }
00218 
00219     layerItem->setChild( layerItem->rowCount(), 0, currentSymbolItem );
00220 
00221   }
00222 
00223   return 0;
00224 }
00225 
00226 int QgsLegendModel::addRasterLayerItem( QStandardItem* layerItem, QgsMapLayer* rlayer )
00227 {
00228   if ( !layerItem || !rlayer )
00229   {
00230     return 1;
00231   }
00232 
00233   QgsRasterLayer* rasterLayer = qobject_cast<QgsRasterLayer *>( rlayer );
00234   if ( !rasterLayer )
00235   {
00236     return 2;
00237   }
00238 
00239   QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem();
00240   //use a vector symbol item without symbol
00241   if ( mHasTopLevelWindow ) //only use QIcon / QPixmap if we have a running x-server
00242   {
00243     currentSymbolItem->setIcon( QIcon( rasterLayer->legendAsPixmap( true ) ) );
00244   }
00245   currentSymbolItem->setLayerID( rasterLayer->id() );
00246   int currentRowCount = layerItem->rowCount();
00247   layerItem->setChild( currentRowCount, 0, currentSymbolItem );
00248 
00249   return 0;
00250 }
00251 
00252 void QgsLegendModel::updateItem( QStandardItem* item )
00253 {
00254   if ( !item )
00255   {
00256     return;
00257   }
00258 
00259   //only layer items are supported for update
00260   QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );
00261   if ( ! cItem )
00262   {
00263     return;
00264   }
00265 
00266   QgsComposerLegendItem::ItemType type = cItem->itemType();
00267   if ( type == QgsComposerLegendItem::LayerItem )
00268   {
00269     updateLayer( cItem );
00270   }
00271 }
00272 
00273 void QgsLegendModel::updateLayer( QStandardItem* layerItem )
00274 {
00275   QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem );
00276   if ( lItem )
00277   {
00278     QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() );
00279     if ( mapLayer )
00280     {
00281       //delete all the entries under layer item
00282       int currentRowCount = lItem->rowCount();
00283       for ( int i = currentRowCount - 1; i >= 0; --i )
00284       {
00285         lItem->removeRow( i );
00286       }
00287 
00288       //set layer name as item text
00289       layerItem->setText( mapLayer->name() );
00290 
00291       QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer );
00292       if ( vLayer )
00293       {
00294         if ( vLayer->isUsingRendererV2() )
00295         {
00296           addVectorLayerItemsV2( lItem, vLayer );
00297         }
00298         else
00299         {
00300           addVectorLayerItems( lItem, vLayer );
00301         }
00302       }
00303 
00304       QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( mapLayer );
00305       if ( rLayer )
00306       {
00307         addRasterLayerItem( lItem, rLayer );
00308       }
00309     }
00310   }
00311 }
00312 
00313 void QgsLegendModel::removeLayer( const QString& layerId )
00314 {
00315   int numRootItems = rowCount();
00316   for ( int i = 0; i < numRootItems ; ++i )
00317   {
00318     QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( item( i ) );
00319     if ( !lItem )
00320     {
00321       continue;
00322     }
00323 
00324     if ( layerId == lItem->layerID() )
00325     {
00326       removeRow( i ); //todo: also remove the subitems and their symbols...
00327       emit layersChanged();
00328       return;
00329     }
00330   }
00331 }
00332 
00333 void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer )
00334 {
00335   if ( !theMapLayer )
00336   {
00337     return;
00338   }
00339 
00340   QgsComposerLayerItem* layerItem = new QgsComposerLayerItem( theMapLayer->name() );
00341   layerItem->setLayerID( theMapLayer->id() );
00342   layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
00343 
00344   invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), layerItem );
00345 
00346   switch ( theMapLayer->type() )
00347   {
00348     case QgsMapLayer::VectorLayer:
00349     {
00350       QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( theMapLayer );
00351       if ( vl )
00352       {
00353         if ( vl->isUsingRendererV2() )
00354         {
00355           addVectorLayerItemsV2( layerItem, vl );
00356         }
00357         else
00358         {
00359           addVectorLayerItems( layerItem, vl );
00360         }
00361       }
00362       break;
00363     }
00364     case QgsMapLayer::RasterLayer:
00365       addRasterLayerItem( layerItem, theMapLayer );
00366       break;
00367     default:
00368       break;
00369   }
00370   emit layersChanged();
00371 }
00372 
00373 QStandardItem* QgsLegendModel::itemFromSymbol( QgsSymbol* s, int opacity, const QString& layerID )
00374 {
00375   QgsComposerSymbolItem* currentSymbolItem = 0;
00376 
00377   //label
00378   QString itemText;
00379   QString label;
00380 
00381   QString lowerValue = s->lowerValue();
00382   QString upperValue = s->upperValue();
00383 
00384   label = s->label();
00385 
00386   //Take the label as item text if it is there
00387   if ( !label.isEmpty() )
00388   {
00389     itemText = label;
00390   }
00391   //take single value
00392   else if ( lowerValue == upperValue || upperValue.isEmpty() )
00393   {
00394     itemText = lowerValue;
00395   }
00396   else //or value range
00397   {
00398     itemText = lowerValue + " - " + upperValue;
00399   }
00400 
00401   //icon item
00402   QImage symbolImage;
00403   switch ( s->type() )
00404   {
00405     case QGis::Point:
00406       symbolImage =  s->getPointSymbolAsImage();
00407       break;
00408     case QGis::Line:
00409       symbolImage = s->getLineSymbolAsImage();
00410       break;
00411     case QGis::Polygon:
00412       symbolImage = s->getPolygonSymbolAsImage();
00413       break;
00414     default:
00415       return 0;
00416   }
00417 
00418   if ( opacity != 255 )
00419   {
00420     //todo: manipulate image pixel by pixel...
00421     QRgb oldColor;
00422     for ( int i = 0; i < symbolImage.height(); ++i )
00423     {
00424       QRgb* scanLineBuffer = ( QRgb* ) symbolImage.scanLine( i );
00425       for ( int j = 0; j < symbolImage.width(); ++j )
00426       {
00427         oldColor = symbolImage.pixel( j, i );
00428         scanLineBuffer[j] = qRgba( qRed( oldColor ), qGreen( oldColor ), qBlue( oldColor ), opacity );
00429       }
00430     }
00431   }
00432 
00433   currentSymbolItem = new QgsComposerSymbolItem( itemText );
00434   if ( mHasTopLevelWindow )//only use QIcon / QPixmap if we have a running x-server
00435   {
00436     currentSymbolItem->setIcon( QIcon( QPixmap::fromImage( symbolImage ) ) );
00437   }
00438 
00439   if ( !currentSymbolItem )
00440   {
00441     return 0;
00442   }
00443 
00444   //Pass deep copy of QgsSymbol as user data. Cast to void* necessary such that QMetaType handles it
00445   QgsSymbol* symbolCopy = new QgsSymbol( *s );
00446   currentSymbolItem->setSymbol( symbolCopy );
00447   currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable );
00448   currentSymbolItem ->setLayerID( layerID );
00449   return currentSymbolItem;
00450 }
00451 
00452 bool QgsLegendModel::writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const
00453 {
00454   if ( composerLegendElem.isNull() )
00455   {
00456     return false;
00457   }
00458 
00459   QDomElement legendModelElem = doc.createElement( "Model" );
00460   legendModelElem.setAttribute( "autoUpdate", mAutoUpdate );
00461   int nTopLevelItems = invisibleRootItem()->rowCount();
00462   QStandardItem* currentItem = 0;
00463   QgsComposerLegendItem* currentLegendItem = 0;
00464 
00465   for ( int i = 0; i < nTopLevelItems; ++i )
00466   {
00467     currentItem = invisibleRootItem()->child( i, 0 );
00468     currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentItem );
00469     if ( currentLegendItem )
00470     {
00471       currentLegendItem->writeXML( legendModelElem, doc );
00472     }
00473   }
00474 
00475   composerLegendElem.appendChild( legendModelElem );
00476   return true;
00477 }
00478 
00479 bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocument& doc )
00480 {
00481   if ( legendModelElem.isNull() )
00482   {
00483     return false;
00484   }
00485 
00486   clear();
00487 
00488   QDomNodeList topLevelItemList = legendModelElem.childNodes();
00489   QDomElement currentElem;
00490   QgsComposerLegendItem* currentItem = 0;
00491 
00492   int nTopLevelItems =  topLevelItemList.size();
00493   for ( int i = 0; i < nTopLevelItems; ++i )
00494   {
00495     currentElem = topLevelItemList.at( i ).toElement();
00496     if ( currentElem.isNull() )
00497     {
00498       continue;
00499     }
00500 
00501     //toplevel items can be groups or layers
00502     if ( currentElem.tagName() == "LayerItem" )
00503     {
00504       currentItem = new QgsComposerLayerItem();
00505     }
00506     else if ( currentElem.tagName() == "GroupItem" )
00507     {
00508       currentItem = new QgsComposerGroupItem();
00509     }
00510     currentItem->readXML( currentElem, mHasTopLevelWindow );
00511     appendRow( currentItem );
00512   }
00513 
00514   setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() );
00515   return true;
00516 }
00517 
00518 Qt::DropActions QgsLegendModel::supportedDropActions() const
00519 {
00520   return Qt::MoveAction;
00521 }
00522 
00523 Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const
00524 {
00525   Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable;
00526   if ( !index.isValid() )
00527   {
00528     flags |= Qt::ItemIsDropEnabled;
00529     return flags;
00530   }
00531 
00532   QStandardItem* item = itemFromIndex( index );
00533   QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item );
00534 
00535   if ( cItem )
00536   {
00537     QgsComposerLegendItem::ItemType type = cItem->itemType();
00538     if ( type == QgsComposerLegendItem::GroupItem )
00539     {
00540       flags |= Qt::ItemIsDragEnabled;
00541       flags |= Qt::ItemIsDropEnabled;
00542     }
00543     else if ( type == QgsComposerLegendItem::LayerItem )
00544     {
00545       flags |= Qt::ItemIsDragEnabled;
00546     }
00547   }
00548   return flags;
00549 }
00550 
00551 bool QgsLegendModel::removeRows( int row, int count, const QModelIndex & parent )
00552 {
00553   if ( count < 1 )
00554   {
00555     return false;
00556   }
00557 
00558   if ( parent.isValid() )
00559   {
00560     for ( int i = row + count - 1; i >= row; --i )
00561     {
00562       QStandardItem* item = itemFromIndex( parent );
00563       if ( item )
00564       {
00565         item->takeRow( i );
00566       }
00567     }
00568   }
00569   else
00570   {
00571     for ( int i = row + count - 1; i >= row; --i )
00572     {
00573       takeRow( i );
00574     }
00575   }
00576   return true;
00577 }
00578 
00579 QMimeData* QgsLegendModel::mimeData( const QModelIndexList &indexes ) const
00580 {
00581   QMimeData* mimeData = new QMimeData();
00582   QByteArray encodedData;
00583   QDomDocument xmlDoc;
00584   QDomElement xmlRootElement = xmlDoc.createElement( "LegendModelDragData" );
00585   xmlDoc.appendChild( xmlRootElement );
00586 
00587   QModelIndexList::const_iterator indexIt = indexes.constBegin();
00588   for ( ; indexIt != indexes.constEnd(); ++indexIt )
00589   {
00590     QStandardItem* sItem = itemFromIndex( *indexIt );
00591     if ( sItem )
00592     {
00593       QgsComposerLegendItem* mItem = dynamic_cast<QgsComposerLegendItem*>( sItem );
00594       if ( mItem )
00595       {
00596         mItem->writeXML( xmlRootElement, xmlDoc );
00597       }
00598     }
00599   }
00600   mimeData->setData( "text/xml", xmlDoc.toByteArray() );
00601   return mimeData;
00602 }
00603 
00604 QStringList QgsLegendModel::mimeTypes() const
00605 {
00606   QStringList types;
00607   types << "text/xml";
00608   return types;
00609 }
00610 
00611 bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent )
00612 {
00613   if ( !data->hasFormat( "text/xml" ) )
00614   {
00615     return false;
00616   }
00617 
00618   QStandardItem* dropIntoItem = 0;
00619   if ( parent.isValid() )
00620   {
00621     dropIntoItem = itemFromIndex( parent );
00622   }
00623   else
00624   {
00625     dropIntoItem = invisibleRootItem();
00626   }
00627 
00628   //get XML doc
00629   QByteArray encodedData = data->data( "text/xml" );
00630   QDomDocument xmlDoc;
00631   xmlDoc.setContent( encodedData );
00632 
00633   QDomElement dragDataElem = xmlDoc.documentElement();
00634   if ( dragDataElem.tagName() != "LegendModelDragData" )
00635   {
00636     return false;
00637   }
00638 
00639   QDomNodeList nodeList = dragDataElem.childNodes();
00640   int nChildNodes = nodeList.size();
00641   QDomElement currentElem;
00642   QString currentTagName;
00643   QgsComposerLegendItem* currentItem = 0;
00644 
00645   for ( int i = 0; i < nChildNodes; ++i )
00646   {
00647     currentElem = nodeList.at( i ).toElement();
00648     if ( currentElem.isNull() )
00649     {
00650       continue;
00651     }
00652     currentTagName = currentElem.tagName();
00653     if ( currentTagName == "LayerItem" )
00654     {
00655       currentItem = new QgsComposerLayerItem();
00656     }
00657     else if ( currentTagName == "GroupItem" )
00658     {
00659       currentItem = new QgsComposerGroupItem();
00660     }
00661     else
00662     {
00663       continue;
00664     }
00665     currentItem->readXML( currentElem );
00666     if ( row < 0 )
00667     {
00668       dropIntoItem->insertRow( dropIntoItem->rowCount(), currentItem );
00669     }
00670     else
00671     {
00672       dropIntoItem->insertRow( row + i, currentItem );
00673     }
00674   }
00675   emit layersChanged();
00676   return true;
00677 }
00678 
00679 void QgsLegendModel::setAutoUpdate( bool autoUpdate )
00680 {
00681   if ( mAutoUpdate == autoUpdate ) //prevent multiple signal/slot connections
00682   {
00683     return;
00684   }
00685 
00686   mAutoUpdate = autoUpdate;
00687   if ( autoUpdate )
00688   {
00689     if ( QgsMapLayerRegistry::instance() )
00690     {
00691       connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
00692       connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
00693     }
00694   }
00695   else
00696   {
00697     if ( QgsMapLayerRegistry::instance() )
00698     {
00699       disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) );
00700       disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) );
00701     }
00702   }
00703 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines