qgis-sublayers-1.patch
src/app/ogr/qgsogrsublayersdialog.cpp | ||
---|---|---|
55 | 55 |
QString line = theList.at( i ); |
56 | 56 |
QStringList elements = line.split( delim ); |
57 | 57 |
QStringList item = QStringList(); |
58 |
item << elements.at( 0 ) << elements.at( 1 ) << elements.at( 2 ) << elements.at( 3 ); |
|
58 |
for ( int j=0; j < elements.size(); j++ ) |
|
59 |
item << elements.at( j ); |
|
59 | 60 |
layersTable->addTopLevelItem( new QTreeWidgetItem( item ) ); |
60 | 61 |
} |
62 |
/* resize columns */ |
|
63 |
for ( int j = 0; j < layersTable->columnCount(); j++ ) |
|
64 |
layersTable->resizeColumnToContents( j ); |
|
65 |
layersTable->setColumnWidth( 1, layersTable->columnWidth(1) + 10 ); |
|
61 | 66 |
} |
src/app/qgisapp.cpp | ||
---|---|---|
2270 | 2270 |
} |
2271 | 2271 |
} |
2272 | 2272 | |
2273 |
bool shouldAskUserForGdalSublayers( QgsRasterLayer *layer ) |
|
2274 |
{ |
|
2275 |
// return false if layer is empty or raster has no sublayers |
|
2276 |
if ( !layer ) |
|
2277 |
return false; |
|
2278 | ||
2279 |
if ( layer->subLayers().size() <= 0 ) |
|
2280 |
return false; |
|
2281 | ||
2282 |
QSettings settings; |
|
2283 |
int promptLayers = settings.value( "/qgis/promptForRasterSublayers", "if_need" ).toInt(); |
|
2284 |
// 0 = Always -> always ask (if there are existing sublayers) |
|
2285 |
// 1 = If needed -> ask if layer has no bands but has sublayers |
|
2286 |
// 2 = Never |
|
2287 | ||
2288 |
if ( (promptLayers == 0) || |
|
2289 |
( (promptLayers == 1) && (layer->bandCount() == 0) ) ) |
|
2290 |
return true; |
|
2291 |
else //TODO log a message informing that the layer was not loaded because of prompLayers value |
|
2292 |
return false; |
|
2293 |
} |
|
2294 | ||
2295 | ||
2273 | 2296 |
// This method is the method that does the real job. If the layer given in |
2274 | 2297 |
// parameter is NULL, then the method tries to act on the activeLayer. |
2275 | 2298 |
void QgisApp::askUserForOGRSublayers( QgsVectorLayer *layer ) |
... | ... | |
6472 | 6495 |
QgsRasterLayer *layer = |
6473 | 6496 |
new QgsRasterLayer( rasterFile, baseName ); // fi.completeBaseName()); |
6474 | 6497 | |
6475 |
if ( !addRasterLayer( layer ) ) |
|
6498 |
bool bOK = false; |
|
6499 | ||
6500 |
if ( shouldAskUserForGdalSublayers( layer ) ) |
|
6501 |
{ |
|
6502 |
askUserForGDALSublayers( layer ); |
|
6503 |
bOK = TRUE; |
|
6504 |
// The first layer loaded is not useful in that case. The user can select it in |
|
6505 |
// the list if he wants to load it. |
|
6506 |
delete layer; |
|
6507 |
} |
|
6508 |
else |
|
6509 |
{ |
|
6510 |
bOK = addRasterLayer( layer ); |
|
6511 |
} |
|
6512 | ||
6513 |
if ( ! bOK ) |
|
6476 | 6514 |
{ |
6477 | 6515 |
mMapCanvas->freeze( false ); |
6478 | 6516 |
QApplication::restoreOverrideCursor(); |
... | ... | |
6556 | 6594 | |
6557 | 6595 |
QgsDebugMsg( "Constructed new layer." ); |
6558 | 6596 | |
6559 |
if ( layer && layer->isValid() ) |
|
6597 |
if ( layer && shouldAskUserForGdalSublayers( layer ) ) |
|
6598 |
{ |
|
6599 |
askUserForGDALSublayers( layer ); |
|
6600 | ||
6601 |
// The first layer loaded is not useful in that case. The user can select it in |
|
6602 |
// the list if he wants to load it. |
|
6603 |
delete layer; |
|
6604 |
} |
|
6605 |
else if ( layer && layer->isValid() ) |
|
6560 | 6606 |
{ |
6561 | 6607 |
addRasterLayer( layer ); |
6562 | 6608 | |
... | ... | |
6582 | 6628 |
} // QgisApp::addRasterLayer |
6583 | 6629 | |
6584 | 6630 | |
6585 | ||
6586 | 6631 |
//create a raster layer object and delegate to addRasterLayer(QgsRasterLayer *) |
6587 | 6632 |
bool QgisApp::addRasterLayers( QStringList const &theFileNameQStringList, bool guiWarning ) |
6588 | 6633 |
{ |
... | ... | |
6627 | 6672 | |
6628 | 6673 |
// create the layer |
6629 | 6674 |
QgsRasterLayer *layer = new QgsRasterLayer( *myIterator, myBaseNameQString ); |
6630 |
QStringList sublayers = layer->subLayers(); |
|
6631 | 6675 | |
6632 |
if ( sublayers.size() > 0 )
|
|
6676 |
if ( shouldAskUserForGdalSublayers( layer ) )
|
|
6633 | 6677 |
{ |
6634 | 6678 |
askUserForGDALSublayers( layer ); |
6635 | 6679 |
src/app/qgsbrowserdockwidget.cpp | ||
---|---|---|
129 | 129 |
QgsMapLayer* layer = NULL; |
130 | 130 |
if ( type == QgsMapLayer::VectorLayer ) |
131 | 131 |
{ |
132 |
layer = new QgsVectorLayer( uri, layerItem->name(), providerKey );
|
|
133 |
} |
|
132 |
layer = QgisApp::instance()->addVectorLayer( uri, layerItem->name(), providerKey );
|
|
133 |
}
|
|
134 | 134 |
if ( type == QgsMapLayer::RasterLayer ) |
135 | 135 |
{ |
136 | 136 |
// This should go to WMS provider |
... | ... | |
159 | 159 |
QgsDebugMsg( "rasterLayerPath = " + rasterLayerPath ); |
160 | 160 |
QgsDebugMsg( "layers = " + layers.join( " " ) ); |
161 | 161 | |
162 |
layer = new QgsRasterLayer( 0, rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs ); |
|
163 |
} |
|
164 | ||
165 |
if ( !layer || !layer->isValid() ) |
|
166 |
{ |
|
167 |
qDebug( "No layer" ); |
|
168 |
delete layer; |
|
169 |
return; |
|
162 |
layer = QgisApp::instance()->addRasterLayer( rasterLayerPath, layerItem->name(), providerKey, layers, styles, format, crs ); |
|
170 | 163 |
} |
171 | ||
172 |
// add layer to the application |
|
173 |
QgsMapLayerRegistry::instance()->addMapLayer( layer ); |
|
174 | 164 |
} |
175 | 165 | |
176 | 166 |
void QgsBrowserDockWidget::showContextMenu( const QPoint & pt ) |
src/app/qgsoptions.cpp | ||
---|---|---|
184 | 184 | |
185 | 185 |
spinBoxAttrTableRowCache->setValue( settings.value( "/qgis/attributeTableRowCache", 10000 ).toInt() ); |
186 | 186 | |
187 |
// set the prompt for raster sublayers |
|
188 |
cmbPromptRasterSublayers->clear(); |
|
189 |
cmbPromptRasterSublayers->addItem( tr( "Always" ) ); |
|
190 |
cmbPromptRasterSublayers->addItem( tr( "If needed" ) ); //this means, prompt if there are sublayers but no band in the main dataset |
|
191 |
cmbPromptRasterSublayers->addItem( tr( "Never" ) ); |
|
192 |
cmbPromptRasterSublayers->setCurrentIndex( settings.value( "/qgis/promptForRasterSublayers", 0 ).toInt() ); |
|
193 | ||
187 | 194 |
// set the display update threshold |
188 | 195 |
spinBoxUpdateThreshold->setValue( settings.value( "/Map/updateThreshold" ).toInt() ); |
189 | 196 |
//set the default projection behaviour radio buttongs |
... | ... | |
600 | 607 |
settings.setValue( "/qgis/dockAttributeTable", cbxAttributeTableDocked->isChecked() ); |
601 | 608 |
settings.setValue( "/qgis/attributeTableBehaviour", cmbAttrTableBehaviour->currentIndex() ); |
602 | 609 |
settings.setValue( "/qgis/attributeTableRowCache", spinBoxAttrTableRowCache->value() ); |
610 |
settings.setValue( "/qgis/promptForRasterSublayers", cmbPromptRasterSublayers->currentIndex() ); |
|
603 | 611 |
settings.setValue( "/qgis/dockIdentifyResults", cbxIdentifyResultsDocked->isChecked() ); |
604 | 612 |
settings.setValue( "/qgis/dockSnapping", cbxSnappingOptionsDocked->isChecked() ); |
605 | 613 |
settings.setValue( "/qgis/addPostgisDC", cbxAddPostgisDC->isChecked() ); |
src/providers/gdal/qgsgdalprovider.cpp | ||
---|---|---|
172 | 172 |
GDALRasterBandH myGDALBand = GDALGetRasterBand( mGdalDataset, 1 ); //just use the first band |
173 | 173 |
if ( myGDALBand == NULL ) |
174 | 174 |
{ |
175 |
QMessageBox::warning( 0, QObject::tr( "Warning" ), |
|
176 |
QObject::tr( "Cannot get GDAL raster band: %1" ).arg( QString::fromUtf8( CPLGetLastErrorMsg() ) ) ); |
|
177 | ||
178 |
GDALDereferenceDataset( mGdalBaseDataset ); |
|
179 |
mGdalBaseDataset = NULL; |
|
175 |
QString msg= QString::fromUtf8( CPLGetLastErrorMsg() ); |
|
176 |
QStringList layers = subLayers(); |
|
180 | 177 | |
181 |
GDALClose( mGdalDataset ); |
|
182 |
mGdalDataset = NULL; |
|
183 |
return; |
|
178 |
/* if there are no subdatasets, then close the dataset */ |
|
179 |
if ( layers.size() == 0 ) |
|
180 |
{ |
|
181 |
QMessageBox::warning( 0, QObject::tr( "Warning" ), |
|
182 |
QObject::tr( "Cannot get GDAL raster band: %1" ).arg( msg ) ); |
|
183 |
|
|
184 |
GDALDereferenceDataset( mGdalBaseDataset ); |
|
185 |
mGdalBaseDataset = NULL; |
|
186 |
|
|
187 |
GDALClose( mGdalDataset ); |
|
188 |
mGdalDataset = NULL; |
|
189 |
return; |
|
190 |
} |
|
191 |
/* if there are subdatasets, leave the dataset open for subsequent queries */ |
|
192 |
else |
|
193 |
{ |
|
194 |
QgsDebugMsg( QObject::tr( "Cannot get GDAL raster band: %1" ).arg( msg ) + |
|
195 |
QString(" but dataset has %1 subdatasets").arg( layers.size() ) ); |
|
196 |
return; |
|
197 |
} |
|
184 | 198 |
} |
185 | 199 | |
186 | 200 |
mHasPyramids = GDALGetOverviewCount( myGDALBand ) > 0; |
... | ... | |
1231 | 1245 |
QStringList subLayers_( GDALDatasetH dataset ) |
1232 | 1246 |
{ |
1233 | 1247 |
QStringList subLayers; |
1248 |
char **metadata = NULL; |
|
1249 | ||
1250 |
if ( dataset == NULL ) |
|
1251 |
QgsDebugMsg( "QgsGdalProvider subLayers_(), dataset is NULL" ); |
|
1252 |
else |
|
1253 |
metadata = GDALGetMetadata( dataset, "SUBDATASETS" ); |
|
1234 | 1254 | |
1235 |
char **metadata = GDALGetMetadata( dataset, "SUBDATASETS" ); |
|
1236 | 1255 |
if ( metadata ) |
1237 | 1256 |
{ |
1238 | 1257 |
for ( int i = 0; metadata[i] != NULL; i++ ) |
src/ui/qgsoptionsbase.ui | ||
---|---|---|
553 | 553 |
</item> |
554 | 554 |
</layout> |
555 | 555 |
</item> |
556 |
<item> |
|
557 |
<layout class="QHBoxLayout" name="horizontalLayout_12"> |
|
558 |
<item> |
|
559 |
<widget class="QLabel" name="textLabel1_13"> |
|
560 |
<property name="sizePolicy"> |
|
561 |
<sizepolicy hsizetype="Fixed" vsizetype="Fixed"> |
|
562 |
<horstretch>0</horstretch> |
|
563 |
<verstretch>0</verstretch> |
|
564 |
</sizepolicy> |
|
565 |
</property> |
|
566 |
<property name="text"> |
|
567 |
<string>Prompt for Raster sublayers</string> |
|
568 |
</property> |
|
569 |
</widget> |
|
570 |
</item> |
|
571 |
<item> |
|
572 |
<spacer name="horizontalSpacer_10"> |
|
573 |
<property name="orientation"> |
|
574 |
<enum>Qt::Horizontal</enum> |
|
575 |
</property> |
|
576 |
<property name="sizeHint" stdset="0"> |
|
577 |
<size> |
|
578 |
<width>40</width> |
|
579 |
<height>20</height> |
|
580 |
</size> |
|
581 |
</property> |
|
582 |
</spacer> |
|
583 |
</item> |
|
584 |
<item> |
|
585 |
<widget class="QComboBox" name="cmbPromptRasterSublayers"> |
|
586 |
<property name="duplicatesEnabled"> |
|
587 |
<bool>false</bool> |
|
588 |
</property> |
|
589 |
<item> |
|
590 |
<property name="text"> |
|
591 |
<string/> |
|
592 |
</property> |
|
593 |
</item> |
|
594 |
</widget> |
|
595 |
</item> |
|
596 |
</layout> |
|
597 |
</item> |
|
556 | 598 |
</layout> |
557 | 599 |
</widget> |
558 | 600 |
</item> |