[QGIS Commit] r11522 - in trunk/qgis/src: app core/raster
providers/wms
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Fri Aug 28 10:49:22 EDT 2009
Author: jef
Date: 2009-08-28 10:49:22 -0400 (Fri, 28 Aug 2009)
New Revision: 11522
Modified:
trunk/qgis/src/app/qgsmaptoolidentify.cpp
trunk/qgis/src/app/qgsmaptoolidentify.h
trunk/qgis/src/core/raster/qgsrasterlayer.cpp
trunk/qgis/src/providers/wms/qgswmsprovider.cpp
Log:
- fix #1903
- handle feature info results as utf-8
- fix crash with open identify results, when layer is removed
Modified: trunk/qgis/src/app/qgsmaptoolidentify.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolidentify.cpp 2009-08-28 07:52:58 UTC (rev 11521)
+++ trunk/qgis/src/app/qgsmaptoolidentify.cpp 2009-08-28 14:49:22 UTC (rev 11522)
@@ -41,13 +41,12 @@
QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
: QgsMapTool( canvas ),
mResults( 0 ),
- mRubberBand( 0 )
+ mRubberBand( 0 ),
+ mLayer( 0 )
{
// set cursor
QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
-
- mLayer = 0; // Initialize mLayer, useful in removeLayer SLOT
}
QgsMapToolIdentify::~QgsMapToolIdentify()
@@ -75,55 +74,51 @@
return;
}
- mLayer = mCanvas->currentLayer();
-
// delete rubber band if there was any
delete mRubberBand;
mRubberBand = 0;
+ mLayer = mCanvas->currentLayer();
+
+ if ( !mLayer )
+ {
+ QMessageBox::warning( mCanvas,
+ tr( "No active layer" ),
+ tr( "To identify features, you must choose an active layer by clicking on its name in the legend" ) );
+ return;
+ }
+
+ // cleanup, when layer is removed
+ connect( mLayer, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
+
// call identify method for selected layer
- if ( mLayer )
+ // In the special case of the WMS provider,
+ // coordinates are sent back to the server as pixel coordinates
+ // not the layer's native CRS. So identify on screen coordinates!
+ if ( mLayer->type() == QgsMapLayer::RasterLayer &&
+ dynamic_cast<QgsRasterLayer*>( mLayer )->providerKey() == "wms" )
{
- // In the special case of the WMS provider,
- // coordinates are sent back to the server as pixel coordinates
- // not the layer's native CRS. So identify on screen coordinates!
- if (
- ( mLayer->type() == QgsMapLayer::RasterLayer )
- &&
- ( dynamic_cast<QgsRasterLayer*>( mLayer )->providerKey() == "wms" )
- )
+ identifyRasterWmsLayer( QgsPoint( e->x(), e->y() ) );
+ }
+ else
+ {
+ // convert screen coordinates to map coordinates
+ QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
+
+ if ( mLayer->type() == QgsMapLayer::VectorLayer )
{
- identifyRasterWmsLayer( QgsPoint( e->x(), e->y() ) );
+ identifyVectorLayer( idPoint );
}
+ else if ( mLayer->type() == QgsMapLayer::RasterLayer )
+ {
+ identifyRasterLayer( idPoint );
+ }
else
{
- // convert screen coordinates to map coordinates
- QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
-
- if ( mLayer->type() == QgsMapLayer::VectorLayer )
- {
- identifyVectorLayer( idPoint );
- }
- else if ( mLayer->type() == QgsMapLayer::RasterLayer )
- {
- identifyRasterLayer( idPoint );
- }
- else
- {
- QgsDebugMsg( "unknown layer type!" );
- }
+ QgsDebugMsg( "unknown layer type!" );
}
-
}
- else
- {
- QMessageBox::warning( mCanvas,
- tr( "No active layer" ),
- tr( "To identify features, you must choose an active layer by clicking on its name in the legend" ) );
- }
-
-
}
@@ -131,7 +126,9 @@
{
QgsRasterLayer *layer = dynamic_cast<QgsRasterLayer*>( mLayer );
if ( !layer )
+ {
return;
+ }
QMap<QString, QString> attributes;
layer->identify( point, attributes );
@@ -232,7 +229,9 @@
{
QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
+ {
return;
+ }
// load identify radius from settings
QSettings settings;
@@ -421,9 +420,19 @@
#endif
QgsMessageViewer * mv = new QgsMessageViewer();
- mv->setWindowTitle( mLayer->lastErrorTitle() );
- mv->setMessageAsPlainText( tr( "Could not identify objects on %1 because:\n%2" )
- .arg( mLayer->name() ).arg( mLayer->lastError() ) );
+
+ if ( mLayer )
+ {
+ mv->setWindowTitle( mLayer->lastErrorTitle() );
+ mv->setMessageAsPlainText( tr( "Could not identify objects on %1 because:\n%2" )
+ .arg( mLayer->name() ).arg( mLayer->lastError() ) );
+ }
+ else
+ {
+ mv->setWindowTitle( tr( "Layer was removed" ) );
+ mv->setMessageAsPlainText( tr( "Layer to identify objects on was removed" ) );
+ }
+
mv->exec(); // deletes itself on close
}
@@ -488,12 +497,11 @@
void QgsMapToolIdentify::editFeature( QgsFeature &f )
{
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
- if ( !layer )
+ if ( !layer || !layer->isEditable() )
+ {
return;
+ }
- if ( !layer->isEditable() )
- return;
-
QgsAttributeMap src = f.attributeMap();
layer->beginEditCommand( tr( "Attribute changed" ) );
@@ -519,24 +527,20 @@
mCanvas->refresh();
}
-void QgsMapToolIdentify::removeLayer( QString layerID )
+void QgsMapToolIdentify::layerDestroyed()
{
- if ( mLayer )
+ mLayer = 0;
+
+ if ( mResults )
{
- if ( mLayer->type() == QgsMapLayer::VectorLayer )
- {
- if ( mLayer->getLayerID() == layerID )
- {
- if ( mResults )
- {
- mResults->clear();
- delete mRubberBand;
- mRubberBand = 0;
- }
- mLayer = 0;
- }
- }
+ mResults->clear();
}
+
+ if ( mRubberBand )
+ {
+ delete mRubberBand;
+ mRubberBand = 0;
+ }
}
void QgsMapToolIdentify::convertMeasurement( QgsDistanceArea &calc, double &measure, QGis::UnitType &u, bool isArea )
Modified: trunk/qgis/src/app/qgsmaptoolidentify.h
===================================================================
--- trunk/qgis/src/app/qgsmaptoolidentify.h 2009-08-28 07:52:58 UTC (rev 11521)
+++ trunk/qgis/src/app/qgsmaptoolidentify.h 2009-08-28 14:49:22 UTC (rev 11522)
@@ -117,9 +117,8 @@
// Let us know when the QgsIdentifyResults dialog box has been closed
void resultsDialogGone();
- // Check if the mLayer is removing from canvas to clear the results dialog
- void removeLayer( QString );
-
+ // layer was destroyed
+ void layerDestroyed();
};
#endif
Modified: trunk/qgis/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2009-08-28 07:52:58 UTC (rev 11521)
+++ trunk/qgis/src/core/raster/qgsrasterlayer.cpp 2009-08-28 14:49:22 UTC (rev 11522)
@@ -5438,9 +5438,3 @@
QgsDebugMsg( "All checks failed, returning '" + QSTRING_NOT_SET + "'" );
return TRSTRING_NOT_SET;
}
-
-
-
-
-
-
Modified: trunk/qgis/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2009-08-28 07:52:58 UTC (rev 11521)
+++ trunk/qgis/src/providers/wms/qgswmsprovider.cpp 2009-08-28 14:49:22 UTC (rev 11522)
@@ -455,9 +455,9 @@
url += "FORMAT=" + imageMimeType;
//DPI parameter is accepted by QGIS mapserver (and ignored by the other WMS servers)
- if(mDpi != -1)
+ if ( mDpi != -1 )
{
- url += "&DPI=" + QString::number(mDpi);
+ url += "&DPI=" + QString::number( mDpi );
}
//MH: jpeg does not support transparency and some servers complain if jpg and transparent=true
@@ -2161,13 +2161,12 @@
QString QgsWmsProvider::identifyAsText( const QgsPoint& point )
{
-
QgsDebugMsg( "Entering." );
// Collect which layers to query on
QStringList queryableLayers = QStringList();
- QString text = "";;
+ QString text = "";
// Test for which layers are suitable for querying with
for ( QStringList::const_iterator it = activeSubLayers.begin();
@@ -2187,13 +2186,14 @@
QString layer = QUrl::toPercentEncoding( *it );
//! \todo Need to tie this into the options provided by GetCapabilities
- requestUrl += QString( "&QUERY_LAYERS=%1&INFO_FORMAT=text/plain&X=%2&Y=%3" )
- .arg( layer ).arg( point.x() ).arg( point.y() );
+ requestUrl += QString( "&QUERY_LAYERS=%1" ).arg( layer );
+ requestUrl += QString( "&INFO_FORMAT=text/plain&X=%1&Y=%2" )
+ .arg( point.x() ).arg( point.y() );
// X,Y in WMS 1.1.1; I,J in WMS 1.3.0
// requestUrl += QString( "&I=%1&J=%2" ).arg( point.x() ).arg( point.y() );
- text += "---------------\n" + retrieveUrl( requestUrl );
+ text += "---------------\n" + QString::fromUtf8( retrieveUrl( requestUrl ) );
}
}
}
More information about the QGIS-commit
mailing list