mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-19 00:04:52 -04:00
Trivial clean-up of QGisApp::addRasterLayer() :
- s/Erdas/ERDAS/ - s/Usgs/USGS/ - s/Sdts/SDTS/ - s/Lyr/Layer/ - use QStringList::empty() instead of QStringList::length() == 0 - now unfreeze mapCanvas if user didn't select files - use more intuitive and safer for() instead of while() - prettified code - added XXX comment regarding possible initContextMenu() invocation even if layer is invalid git-svn-id: http://svn.osgeo.org/qgis/trunk@602 c8812cc2-4d05-0410-92ff-de0c093fc19c
This commit is contained in:
parent
e8a904f025
commit
409d73805f
102
src/qgisapp.cpp
102
src/qgisapp.cpp
@ -375,31 +375,39 @@ void QgisApp::addLayer()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QgisApp::addRasterLayer()
|
|
||||||
|
void
|
||||||
|
QgisApp::addRasterLayer()
|
||||||
{
|
{
|
||||||
|
// insure that the map canvas temporarily suspends event processing
|
||||||
|
// until we've loaded the raster
|
||||||
|
|
||||||
mapCanvas->freeze();
|
mapCanvas->freeze();
|
||||||
|
|
||||||
QString myFileTypeQString;
|
QString myFileTypeQString;
|
||||||
|
|
||||||
QString myArcInfoBinaryGridFilterString="Arc Info Binary Grid (*.adf)";
|
QString myArcInfoBinaryGridFilterString="Arc Info Binary Grid (*.adf)";
|
||||||
QString myArcInfoAsciiGridFilterString="Arc Info Ascii Grid (*.asc;*.grd)";
|
QString myArcInfoAsciiGridFilterString="Arc Info Ascii Grid (*.asc;*.grd)";
|
||||||
QString myErdasFilterString="Erdas Imagine (*.img)";
|
QString myERDASFilterString="ERDAS Imagine (*.img)";
|
||||||
QString myGeoTiffFilterString="Geo tiff (*.tif)";
|
QString myGeoTiffFilterString="Geo tiff (*.tif)";
|
||||||
QString myUsgsAsciiDemFilterString="Usgs Ascii DEM (*.dem)";
|
QString myUSGSAsciiDemFilterString="USGS Ascii DEM (*.dem)";
|
||||||
QString myGrassFilterString="Grass raster (*.*)";
|
QString myGrassFilterString="Grass raster (*.*)";
|
||||||
QString mySdtsFilterString="Sdts (*CATD*.DDF)";
|
QString mySDTSFilterString="SDTS (*CATD*.DDF)";
|
||||||
QString myAllRasterFormats = "All Rasters (*.asc;*.grd;*.img;*.tif;*.png;*.jpg;*.dem;*.DDF)";
|
QString myAllRasterFormats = "All Rasters (*.asc;*.grd;*.img;*.tif;*.png;*.jpg;*.dem;*.DDF)";
|
||||||
//QString myBilFilterString="Band Interleaved by Line (*.bil)";
|
//QString myBilFilterString="Band Interleaved by Line (*.bil)";
|
||||||
//QString myJpgFilterString="Geo jpg (*.jpg)";
|
//QString myJpgFilterString="Geo jpg (*.jpg)";
|
||||||
|
|
||||||
QStringList myFileNameQStringList = QFileDialog::getOpenFileNames(
|
QStringList myFileNameQStringList = QFileDialog::getOpenFileNames(
|
||||||
myAllRasterFormats + ";;" +
|
myAllRasterFormats + ";;" +
|
||||||
myArcInfoBinaryGridFilterString + ";;" +
|
myArcInfoBinaryGridFilterString + ";;" +
|
||||||
myArcInfoAsciiGridFilterString + ";;" +
|
myArcInfoAsciiGridFilterString + ";;" +
|
||||||
myErdasFilterString + ";;" +
|
myERDASFilterString + ";;" +
|
||||||
//myBilFilterString + ";;" +
|
//myBilFilterString + ";;" +
|
||||||
//myJpgFilterString + ";;" +
|
//myJpgFilterString + ";;" +
|
||||||
myGeoTiffFilterString + ";;" +
|
myGeoTiffFilterString + ";;" +
|
||||||
myGrassFilterString + ";;" +
|
myGrassFilterString + ";;" +
|
||||||
myUsgsAsciiDemFilterString + ";;" +
|
myUSGSAsciiDemFilterString + ";;" +
|
||||||
mySdtsFilterString, //filters to select
|
mySDTSFilterString, //filters to select
|
||||||
"" , //initial dir
|
"" , //initial dir
|
||||||
this , //parent dialog
|
this , //parent dialog
|
||||||
"OpenFileDialog" , //QFileDialog qt object name
|
"OpenFileDialog" , //QFileDialog qt object name
|
||||||
@ -407,65 +415,89 @@ void QgisApp::addRasterLayer()
|
|||||||
&myFileTypeQString //the pointer to store selected filter
|
&myFileTypeQString //the pointer to store selected filter
|
||||||
);
|
);
|
||||||
//cout << "Selected filetype filter is : " << myFileTypeQString << endl;
|
//cout << "Selected filetype filter is : " << myFileTypeQString << endl;
|
||||||
if (myFileNameQStringList.size()==0) return; //no files selected so bail out
|
|
||||||
|
if ( myFileNameQStringList.empty() )
|
||||||
|
{ // no files selected so bail out, but
|
||||||
|
// allow mapCanvas to handle events
|
||||||
|
// first
|
||||||
|
mapCanvas->freeze( false );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
QApplication::setOverrideCursor(Qt::WaitCursor);
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
||||||
|
|
||||||
if (myFileTypeQString==myArcInfoBinaryGridFilterString)
|
// handle ArcInfo rasters
|
||||||
|
if ( myArcInfoBinaryGridFilterString == myFileTypeQString )
|
||||||
{
|
{
|
||||||
//if multiple file were selected ignore the others because currently we
|
//if multiple file were selected ignore the others because currently we
|
||||||
//can only select one AI Binary Grid dir at a time
|
//can only select one AI Binary Grid dir at a time
|
||||||
|
|
||||||
QStringList::Iterator it = myFileNameQStringList.begin();
|
QStringList::Iterator it = myFileNameQStringList.begin();
|
||||||
QFileInfo fi(*it);
|
QFileInfo fi(*it);
|
||||||
QString base = fi.dirPath(); //get the directory the .adf file was in
|
QString base = fi.dirPath(); //get the directory the .adf file was in
|
||||||
|
|
||||||
// create the layer
|
// create the layer
|
||||||
QgsRasterLayer *lyr = new QgsRasterLayer(*it, base);
|
QgsRasterLayer *layer = new QgsRasterLayer(*it, base);
|
||||||
QObject::connect(lyr,SIGNAL(repaintRequested()),mapCanvas,SLOT(refresh()));
|
QObject::connect(layer,SIGNAL(repaintRequested()),mapCanvas,SLOT(refresh()));
|
||||||
|
|
||||||
if (lyr->isValid()) {
|
if ( layer->isValid() )
|
||||||
|
{
|
||||||
// add it to the mapcanvas collection
|
// add it to the mapcanvas collection
|
||||||
mapCanvas->addLayer(lyr);
|
mapCanvas->addLayer( layer );
|
||||||
} else {
|
} else
|
||||||
QString msg = *it;
|
{
|
||||||
msg += " is not a valid or recognized raster data source";
|
QString msg( *it + " is not a valid or recognized raster data source" );
|
||||||
QMessageBox::critical(this, "Invalid Data Source", msg);
|
QMessageBox::critical( this, "Invalid Data Source", msg );
|
||||||
}
|
}
|
||||||
// init the context menu so it can connect to slots in main app
|
// init the context menu so it can connect to slots in main app
|
||||||
lyr->initContextMenu(this);
|
layer->initContextMenu( this );
|
||||||
}
|
}
|
||||||
else // Any other gdal type
|
else // Any other GDAL type
|
||||||
|
{
|
||||||
|
for ( QStringList::Iterator it = myFileNameQStringList.begin();
|
||||||
|
it != myFileNameQStringList.end();
|
||||||
|
++it )
|
||||||
{
|
{
|
||||||
QStringList::Iterator it = myFileNameQStringList.begin();
|
|
||||||
while (it != myFileNameQStringList.end()) {
|
|
||||||
QFileInfo fi(*it);
|
QFileInfo fi(*it);
|
||||||
QString base = fi.baseName();
|
QString baseName = fi.baseName();
|
||||||
|
|
||||||
// create the layer
|
// create the layer
|
||||||
QgsRasterLayer *lyr = new QgsRasterLayer(*it, base);
|
QgsRasterLayer *layer = new QgsRasterLayer(*it, baseName);
|
||||||
QObject::connect(lyr,SIGNAL(repaintRequested()),mapCanvas,SLOT(refresh()));
|
QObject::connect( layer, SIGNAL(repaintRequested()), mapCanvas, SLOT(refresh()) );
|
||||||
|
|
||||||
if (lyr->isValid()) {
|
if ( layer->isValid() )
|
||||||
// add it to the mapcanvas collection
|
{// add it to the mapcanvas collection
|
||||||
mapCanvas->addLayer(lyr);
|
mapCanvas->addLayer( layer );
|
||||||
} else {
|
} else
|
||||||
QString msg = *it;
|
{
|
||||||
msg += " is not a valid or recognized raster data source";
|
QString msg( *it + " is not a valid or recognized raster data source" );
|
||||||
QMessageBox::critical(this, "Invalid Data Source", msg);
|
QMessageBox::critical( this, "Invalid Data Source", msg );
|
||||||
}
|
}
|
||||||
|
|
||||||
// init the context menu so it can connect to slots in main app
|
// init the context menu so it can connect to slots in main app
|
||||||
lyr->initContextMenu(this);
|
// XXX Yes, but what if the layer is invalid? Should we still be doing this?
|
||||||
++it;
|
layer->initContextMenu( this );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mapLegend->update();
|
mapLegend->update();
|
||||||
|
|
||||||
qApp->processEvents();
|
qApp->processEvents();
|
||||||
|
|
||||||
mapCanvas->freeze(false);
|
mapCanvas->freeze(false);
|
||||||
|
|
||||||
mapCanvas->render2();
|
mapCanvas->render2();
|
||||||
|
|
||||||
QApplication::restoreOverrideCursor();
|
QApplication::restoreOverrideCursor();
|
||||||
statusBar()->message(mapCanvas->extent().stringRep());
|
|
||||||
}
|
statusBar()->message( mapCanvas->extent().stringRep() );
|
||||||
|
|
||||||
|
} // QgisApp::addRasterLayer()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef POSTGRESQL
|
#ifdef POSTGRESQL
|
||||||
void QgisApp::addDatabaseLayer()
|
void QgisApp::addDatabaseLayer()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user