qgis-sublayers-4.patch

Etienne Tourigny, 2012-02-18 11:29 AM

Download (3.45 KB)

View differences:

src/app/qgisapp.cpp
2258 2258

  
2259 2259
  if ( chooseSublayersDialog.exec() )
2260 2260
  {
2261
    foreach( QString layer, chooseSublayersDialog.getSelection() )
2261
    foreach( QString layerFullName, chooseSublayersDialog.getSelection() )
2262 2262
    {
2263
      QgsRasterLayer *rlayer = new QgsRasterLayer( layer, layer );
2263
      // shorten file name that will be displayed
2264
      QFileInfo info( layer->source() );
2265
      QString layerBaseName = layerFullName;
2266
      layerBaseName.replace( layer->source(), info.completeBaseName() );
2267
      QgsRasterLayer *rlayer = new QgsRasterLayer( layerFullName, layerBaseName );
2264 2268
      if ( rlayer && rlayer->isValid() )
2265 2269
      {
2266 2270
        addRasterLayer( rlayer );
src/app/qgsbrowserdockwidget.cpp
126 126
  QString providerKey = layerItem->providerKey();
127 127

  
128 128
  QgsDebugMsg( providerKey + " : " + uri );
129
  QgsMapLayer* layer = NULL;
130 129
  if ( type == QgsMapLayer::VectorLayer )
131 130
  {
132
    layer = QgisApp::instance()->addVectorLayer( uri, layerItem->name(), providerKey );
131
    QgisApp::instance()->addVectorLayer( uri, layerItem->name(), providerKey );
133 132
  }
134 133
  if ( type == QgsMapLayer::RasterLayer )
135 134
  {
......
159 158
    QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath );
160 159
    QgsDebugMsg( "layers = " + layers.join( " " ) );
161 160

  
162
    layer = QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
161
    QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs );
163 162
  }
164 163
}
165 164

  
src/providers/gdal/qgsgdaldataitems.cpp
114 114

  
115 115
    QgsDataItem * childItem = NULL;
116 116
    GDALDatasetH hChildDS = NULL;
117
    QString childPath;
117 118

  
118 119
    if ( item && sublayers.count() > 1 )
119 120
    {
120 121
      QgsDebugMsg( QString( "dataItem() got %1 sublayers" ).arg( sublayers.count() ) );
121
      for ( int i = 0; i < sublayers.count(); i++ )
122
      for ( int i=0; i<sublayers.count(); i++ )
122 123
      {
123
        hChildDS = GDALOpen( TO8F( sublayers[i] ), GA_ReadOnly );
124
        childPath = sublayers[i];
125
        hChildDS = GDALOpen( TO8F( childPath ), GA_ReadOnly );
124 126
        if ( hChildDS )
125 127
        {
126 128
          GDALClose( hChildDS );
127
          QgsDebugMsg( QString( "add child #%1 - %2" ).arg( i ).arg( sublayers[i] ) );
128
          childItem = new QgsGdalLayerItem( item, sublayers[i], thePath + "/" + sublayers[i], sublayers[i] );
129
          QgsDebugMsg( QString( "add child #%1 - %2" ).arg( i ).arg( childPath ) );
130
          // shorten file name that will be displayed
131
          name = childPath;
132
          name.replace( thePath, info.completeBaseName() );
133
          uri = childPath;
134
          childItem = new QgsGdalLayerItem( item, name, childPath, uri );
129 135
          if ( childItem )
130 136
            item->addChildItem( childItem );
131 137
        }