Quantum GIS API Documentation
1.8
|
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::addRasterLayerItems( 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 QList< QPair< QString, QColor > > rasterItemList = rasterLayer->legendSymbologyItems(); 00240 QList< QPair< QString, QColor > >::const_iterator itemIt = rasterItemList.constBegin(); 00241 for ( ; itemIt != rasterItemList.constEnd(); ++itemIt ) 00242 { 00243 QgsComposerRasterSymbolItem* currentSymbolItem = new QgsComposerRasterSymbolItem( itemIt->first ); 00244 if ( mHasTopLevelWindow ) 00245 { 00246 QPixmap itemPixmap( 20, 20 ); 00247 itemPixmap.fill( itemIt->second ); 00248 currentSymbolItem->setIcon( QIcon( itemPixmap ) ); 00249 } 00250 currentSymbolItem->setLayerID( rasterLayer->id() ); 00251 currentSymbolItem->setColor( itemIt->second ); 00252 int currentRowCount = layerItem->rowCount(); 00253 layerItem->setChild( currentRowCount, 0, currentSymbolItem ); 00254 } 00255 00256 return 0; 00257 } 00258 00259 void QgsLegendModel::updateItem( QStandardItem* item ) 00260 { 00261 if ( !item ) 00262 { 00263 return; 00264 } 00265 00266 //only layer items are supported for update 00267 QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item ); 00268 if ( ! cItem ) 00269 { 00270 return; 00271 } 00272 00273 QgsComposerLegendItem::ItemType type = cItem->itemType(); 00274 if ( type == QgsComposerLegendItem::LayerItem ) 00275 { 00276 updateLayer( cItem ); 00277 } 00278 } 00279 00280 void QgsLegendModel::updateLayer( QStandardItem* layerItem ) 00281 { 00282 QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( layerItem ); 00283 if ( lItem ) 00284 { 00285 QgsMapLayer* mapLayer = QgsMapLayerRegistry::instance()->mapLayer( lItem->layerID() ); 00286 if ( mapLayer ) 00287 { 00288 //delete all the entries under layer item 00289 int currentRowCount = lItem->rowCount(); 00290 for ( int i = currentRowCount - 1; i >= 0; --i ) 00291 { 00292 lItem->removeRow( i ); 00293 } 00294 00295 //set layer name as item text 00296 layerItem->setText( mapLayer->name() ); 00297 00298 QgsVectorLayer* vLayer = qobject_cast<QgsVectorLayer*>( mapLayer ); 00299 if ( vLayer ) 00300 { 00301 if ( vLayer->isUsingRendererV2() ) 00302 { 00303 addVectorLayerItemsV2( lItem, vLayer ); 00304 } 00305 else 00306 { 00307 addVectorLayerItems( lItem, vLayer ); 00308 } 00309 } 00310 00311 QgsRasterLayer* rLayer = qobject_cast<QgsRasterLayer*>( mapLayer ); 00312 if ( rLayer ) 00313 { 00314 addRasterLayerItems( lItem, rLayer ); 00315 } 00316 } 00317 } 00318 } 00319 00320 void QgsLegendModel::removeLayer( const QString& layerId ) 00321 { 00322 int numRootItems = rowCount(); 00323 for ( int i = 0; i < numRootItems ; ++i ) 00324 { 00325 QgsComposerLayerItem* lItem = dynamic_cast<QgsComposerLayerItem*>( item( i ) ); 00326 if ( !lItem ) 00327 { 00328 continue; 00329 } 00330 00331 if ( layerId == lItem->layerID() ) 00332 { 00333 removeRow( i ); //todo: also remove the subitems and their symbols... 00334 emit layersChanged(); 00335 return; 00336 } 00337 } 00338 } 00339 00340 void QgsLegendModel::addLayer( QgsMapLayer* theMapLayer ) 00341 { 00342 if ( !theMapLayer ) 00343 { 00344 return; 00345 } 00346 00347 QgsComposerLayerItem* layerItem = new QgsComposerLayerItem( theMapLayer->name() ); 00348 layerItem->setLayerID( theMapLayer->id() ); 00349 layerItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); 00350 00351 invisibleRootItem()->setChild( invisibleRootItem()->rowCount(), layerItem ); 00352 00353 switch ( theMapLayer->type() ) 00354 { 00355 case QgsMapLayer::VectorLayer: 00356 { 00357 QgsVectorLayer* vl = dynamic_cast<QgsVectorLayer*>( theMapLayer ); 00358 if ( vl ) 00359 { 00360 if ( vl->isUsingRendererV2() ) 00361 { 00362 addVectorLayerItemsV2( layerItem, vl ); 00363 } 00364 else 00365 { 00366 addVectorLayerItems( layerItem, vl ); 00367 } 00368 } 00369 break; 00370 } 00371 case QgsMapLayer::RasterLayer: 00372 addRasterLayerItems( layerItem, theMapLayer ); 00373 break; 00374 default: 00375 break; 00376 } 00377 emit layersChanged(); 00378 } 00379 00380 QStandardItem* QgsLegendModel::itemFromSymbol( QgsSymbol* s, int opacity, const QString& layerID ) 00381 { 00382 QgsComposerSymbolItem* currentSymbolItem = 0; 00383 00384 //label 00385 QString itemText; 00386 QString label; 00387 00388 QString lowerValue = s->lowerValue(); 00389 QString upperValue = s->upperValue(); 00390 00391 label = s->label(); 00392 00393 //Take the label as item text if it is there 00394 if ( !label.isEmpty() ) 00395 { 00396 itemText = label; 00397 } 00398 //take single value 00399 else if ( lowerValue == upperValue || upperValue.isEmpty() ) 00400 { 00401 itemText = lowerValue; 00402 } 00403 else //or value range 00404 { 00405 itemText = lowerValue + " - " + upperValue; 00406 } 00407 00408 //icon item 00409 QImage symbolImage; 00410 switch ( s->type() ) 00411 { 00412 case QGis::Point: 00413 symbolImage = s->getPointSymbolAsImage(); 00414 break; 00415 case QGis::Line: 00416 symbolImage = s->getLineSymbolAsImage(); 00417 break; 00418 case QGis::Polygon: 00419 symbolImage = s->getPolygonSymbolAsImage(); 00420 break; 00421 default: 00422 return 0; 00423 } 00424 00425 if ( opacity != 255 ) 00426 { 00427 //todo: manipulate image pixel by pixel... 00428 QRgb oldColor; 00429 for ( int i = 0; i < symbolImage.height(); ++i ) 00430 { 00431 QRgb* scanLineBuffer = ( QRgb* ) symbolImage.scanLine( i ); 00432 for ( int j = 0; j < symbolImage.width(); ++j ) 00433 { 00434 oldColor = symbolImage.pixel( j, i ); 00435 scanLineBuffer[j] = qRgba( qRed( oldColor ), qGreen( oldColor ), qBlue( oldColor ), opacity ); 00436 } 00437 } 00438 } 00439 00440 currentSymbolItem = new QgsComposerSymbolItem( itemText ); 00441 if ( mHasTopLevelWindow )//only use QIcon / QPixmap if we have a running x-server 00442 { 00443 currentSymbolItem->setIcon( QIcon( QPixmap::fromImage( symbolImage ) ) ); 00444 } 00445 00446 if ( !currentSymbolItem ) 00447 { 00448 return 0; 00449 } 00450 00451 //Pass deep copy of QgsSymbol as user data. Cast to void* necessary such that QMetaType handles it 00452 QgsSymbol* symbolCopy = new QgsSymbol( *s ); 00453 currentSymbolItem->setSymbol( symbolCopy ); 00454 currentSymbolItem->setFlags( Qt::ItemIsEnabled | Qt::ItemIsSelectable ); 00455 currentSymbolItem ->setLayerID( layerID ); 00456 return currentSymbolItem; 00457 } 00458 00459 bool QgsLegendModel::writeXML( QDomElement& composerLegendElem, QDomDocument& doc ) const 00460 { 00461 if ( composerLegendElem.isNull() ) 00462 { 00463 return false; 00464 } 00465 00466 QDomElement legendModelElem = doc.createElement( "Model" ); 00467 legendModelElem.setAttribute( "autoUpdate", mAutoUpdate ); 00468 int nTopLevelItems = invisibleRootItem()->rowCount(); 00469 QStandardItem* currentItem = 0; 00470 QgsComposerLegendItem* currentLegendItem = 0; 00471 00472 for ( int i = 0; i < nTopLevelItems; ++i ) 00473 { 00474 currentItem = invisibleRootItem()->child( i, 0 ); 00475 currentLegendItem = dynamic_cast<QgsComposerLegendItem*>( currentItem ); 00476 if ( currentLegendItem ) 00477 { 00478 currentLegendItem->writeXML( legendModelElem, doc ); 00479 } 00480 } 00481 00482 composerLegendElem.appendChild( legendModelElem ); 00483 return true; 00484 } 00485 00486 bool QgsLegendModel::readXML( const QDomElement& legendModelElem, const QDomDocument& doc ) 00487 { 00488 Q_UNUSED( doc ); 00489 00490 if ( legendModelElem.isNull() ) 00491 { 00492 return false; 00493 } 00494 00495 clear(); 00496 00497 QDomNodeList topLevelItemList = legendModelElem.childNodes(); 00498 QDomElement currentElem; 00499 QgsComposerLegendItem* currentItem = 0; 00500 00501 int nTopLevelItems = topLevelItemList.size(); 00502 for ( int i = 0; i < nTopLevelItems; ++i ) 00503 { 00504 currentElem = topLevelItemList.at( i ).toElement(); 00505 if ( currentElem.isNull() ) 00506 { 00507 continue; 00508 } 00509 00510 //toplevel items can be groups or layers 00511 if ( currentElem.tagName() == "LayerItem" ) 00512 { 00513 currentItem = new QgsComposerLayerItem(); 00514 } 00515 else if ( currentElem.tagName() == "GroupItem" ) 00516 { 00517 currentItem = new QgsComposerGroupItem(); 00518 } 00519 currentItem->readXML( currentElem, mHasTopLevelWindow ); 00520 appendRow( currentItem ); 00521 } 00522 00523 setAutoUpdate( legendModelElem.attribute( "autoUpdate", "1" ).toInt() ); 00524 return true; 00525 } 00526 00527 Qt::DropActions QgsLegendModel::supportedDropActions() const 00528 { 00529 return Qt::MoveAction; 00530 } 00531 00532 Qt::ItemFlags QgsLegendModel::flags( const QModelIndex &index ) const 00533 { 00534 Qt::ItemFlags flags = Qt::ItemIsEnabled | Qt::ItemIsSelectable; 00535 if ( !index.isValid() ) 00536 { 00537 flags |= Qt::ItemIsDropEnabled; 00538 return flags; 00539 } 00540 00541 QStandardItem* item = itemFromIndex( index ); 00542 QgsComposerLegendItem* cItem = dynamic_cast<QgsComposerLegendItem*>( item ); 00543 00544 if ( cItem ) 00545 { 00546 QgsComposerLegendItem::ItemType type = cItem->itemType(); 00547 if ( type == QgsComposerLegendItem::GroupItem ) 00548 { 00549 flags |= Qt::ItemIsDragEnabled; 00550 flags |= Qt::ItemIsDropEnabled; 00551 } 00552 else if ( type == QgsComposerLegendItem::LayerItem ) 00553 { 00554 flags |= Qt::ItemIsDragEnabled; 00555 } 00556 } 00557 return flags; 00558 } 00559 00560 bool QgsLegendModel::removeRows( int row, int count, const QModelIndex & parent ) 00561 { 00562 if ( count < 1 ) 00563 { 00564 return false; 00565 } 00566 00567 if ( parent.isValid() ) 00568 { 00569 for ( int i = row + count - 1; i >= row; --i ) 00570 { 00571 QStandardItem* item = itemFromIndex( parent ); 00572 if ( item ) 00573 { 00574 item->takeRow( i ); 00575 } 00576 } 00577 } 00578 else 00579 { 00580 for ( int i = row + count - 1; i >= row; --i ) 00581 { 00582 takeRow( i ); 00583 } 00584 } 00585 return true; 00586 } 00587 00588 QMimeData* QgsLegendModel::mimeData( const QModelIndexList &indexes ) const 00589 { 00590 QMimeData* mimeData = new QMimeData(); 00591 QByteArray encodedData; 00592 QDomDocument xmlDoc; 00593 QDomElement xmlRootElement = xmlDoc.createElement( "LegendModelDragData" ); 00594 xmlDoc.appendChild( xmlRootElement ); 00595 00596 QModelIndexList::const_iterator indexIt = indexes.constBegin(); 00597 for ( ; indexIt != indexes.constEnd(); ++indexIt ) 00598 { 00599 QStandardItem* sItem = itemFromIndex( *indexIt ); 00600 if ( sItem ) 00601 { 00602 QgsComposerLegendItem* mItem = dynamic_cast<QgsComposerLegendItem*>( sItem ); 00603 if ( mItem ) 00604 { 00605 mItem->writeXML( xmlRootElement, xmlDoc ); 00606 } 00607 } 00608 } 00609 mimeData->setData( "text/xml", xmlDoc.toByteArray() ); 00610 return mimeData; 00611 } 00612 00613 QStringList QgsLegendModel::mimeTypes() const 00614 { 00615 QStringList types; 00616 types << "text/xml"; 00617 return types; 00618 } 00619 00620 bool QgsLegendModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) 00621 { 00622 Q_UNUSED( action ); 00623 Q_UNUSED( column ); 00624 00625 if ( !data->hasFormat( "text/xml" ) ) 00626 { 00627 return false; 00628 } 00629 00630 QStandardItem* dropIntoItem = 0; 00631 if ( parent.isValid() ) 00632 { 00633 dropIntoItem = itemFromIndex( parent ); 00634 } 00635 else 00636 { 00637 dropIntoItem = invisibleRootItem(); 00638 } 00639 00640 //get XML doc 00641 QByteArray encodedData = data->data( "text/xml" ); 00642 QDomDocument xmlDoc; 00643 xmlDoc.setContent( encodedData ); 00644 00645 QDomElement dragDataElem = xmlDoc.documentElement(); 00646 if ( dragDataElem.tagName() != "LegendModelDragData" ) 00647 { 00648 return false; 00649 } 00650 00651 QDomNodeList nodeList = dragDataElem.childNodes(); 00652 int nChildNodes = nodeList.size(); 00653 QDomElement currentElem; 00654 QString currentTagName; 00655 QgsComposerLegendItem* currentItem = 0; 00656 00657 for ( int i = 0; i < nChildNodes; ++i ) 00658 { 00659 currentElem = nodeList.at( i ).toElement(); 00660 if ( currentElem.isNull() ) 00661 { 00662 continue; 00663 } 00664 currentTagName = currentElem.tagName(); 00665 if ( currentTagName == "LayerItem" ) 00666 { 00667 currentItem = new QgsComposerLayerItem(); 00668 } 00669 else if ( currentTagName == "GroupItem" ) 00670 { 00671 currentItem = new QgsComposerGroupItem(); 00672 } 00673 else 00674 { 00675 continue; 00676 } 00677 currentItem->readXML( currentElem ); 00678 if ( row < 0 ) 00679 { 00680 dropIntoItem->insertRow( dropIntoItem->rowCount(), currentItem ); 00681 } 00682 else 00683 { 00684 dropIntoItem->insertRow( row + i, currentItem ); 00685 } 00686 } 00687 emit layersChanged(); 00688 return true; 00689 } 00690 00691 void QgsLegendModel::setAutoUpdate( bool autoUpdate ) 00692 { 00693 if ( mAutoUpdate == autoUpdate ) //prevent multiple signal/slot connections 00694 { 00695 return; 00696 } 00697 00698 mAutoUpdate = autoUpdate; 00699 if ( autoUpdate ) 00700 { 00701 if ( QgsMapLayerRegistry::instance() ) 00702 { 00703 connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) ); 00704 connect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) ); 00705 } 00706 } 00707 else 00708 { 00709 if ( QgsMapLayerRegistry::instance() ) 00710 { 00711 disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( removeLayer( const QString& ) ) ); 00712 disconnect( QgsMapLayerRegistry::instance(), SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( addLayer( QgsMapLayer* ) ) ); 00713 } 00714 } 00715 }