Skip to content

Commit 11119f3

Browse files
author
jef
committed
- fix #1903
- handle feature info results as utf-8 - fix crash with open identify results, when layer is removed git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11522 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 2efd7da commit 11119f3

File tree

4 files changed

+74
-77
lines changed

4 files changed

+74
-77
lines changed

src/app/qgsmaptoolidentify.cpp

Lines changed: 65 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,12 @@
4141
QgsMapToolIdentify::QgsMapToolIdentify( QgsMapCanvas* canvas )
4242
: QgsMapTool( canvas ),
4343
mResults( 0 ),
44-
mRubberBand( 0 )
44+
mRubberBand( 0 ),
45+
mLayer( 0 )
4546
{
4647
// set cursor
4748
QPixmap myIdentifyQPixmap = QPixmap(( const char ** ) identify_cursor );
4849
mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
49-
50-
mLayer = 0; // Initialize mLayer, useful in removeLayer SLOT
5150
}
5251

5352
QgsMapToolIdentify::~QgsMapToolIdentify()
@@ -75,63 +74,61 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
7574
return;
7675
}
7776

78-
mLayer = mCanvas->currentLayer();
79-
8077
// delete rubber band if there was any
8178
delete mRubberBand;
8279
mRubberBand = 0;
8380

81+
mLayer = mCanvas->currentLayer();
82+
83+
if ( !mLayer )
84+
{
85+
QMessageBox::warning( mCanvas,
86+
tr( "No active layer" ),
87+
tr( "To identify features, you must choose an active layer by clicking on its name in the legend" ) );
88+
return;
89+
}
90+
91+
// cleanup, when layer is removed
92+
connect( mLayer, SIGNAL( destroyed() ), this, SLOT( layerDestroyed() ) );
93+
8494
// call identify method for selected layer
8595

86-
if ( mLayer )
96+
// In the special case of the WMS provider,
97+
// coordinates are sent back to the server as pixel coordinates
98+
// not the layer's native CRS. So identify on screen coordinates!
99+
if ( mLayer->type() == QgsMapLayer::RasterLayer &&
100+
dynamic_cast<QgsRasterLayer*>( mLayer )->providerKey() == "wms" )
101+
{
102+
identifyRasterWmsLayer( QgsPoint( e->x(), e->y() ) );
103+
}
104+
else
87105
{
88-
// In the special case of the WMS provider,
89-
// coordinates are sent back to the server as pixel coordinates
90-
// not the layer's native CRS. So identify on screen coordinates!
91-
if (
92-
( mLayer->type() == QgsMapLayer::RasterLayer )
93-
&&
94-
( dynamic_cast<QgsRasterLayer*>( mLayer )->providerKey() == "wms" )
95-
)
106+
// convert screen coordinates to map coordinates
107+
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
108+
109+
if ( mLayer->type() == QgsMapLayer::VectorLayer )
96110
{
97-
identifyRasterWmsLayer( QgsPoint( e->x(), e->y() ) );
111+
identifyVectorLayer( idPoint );
112+
}
113+
else if ( mLayer->type() == QgsMapLayer::RasterLayer )
114+
{
115+
identifyRasterLayer( idPoint );
98116
}
99117
else
100118
{
101-
// convert screen coordinates to map coordinates
102-
QgsPoint idPoint = mCanvas->getCoordinateTransform()->toMapCoordinates( e->x(), e->y() );
103-
104-
if ( mLayer->type() == QgsMapLayer::VectorLayer )
105-
{
106-
identifyVectorLayer( idPoint );
107-
}
108-
else if ( mLayer->type() == QgsMapLayer::RasterLayer )
109-
{
110-
identifyRasterLayer( idPoint );
111-
}
112-
else
113-
{
114-
QgsDebugMsg( "unknown layer type!" );
115-
}
119+
QgsDebugMsg( "unknown layer type!" );
116120
}
117-
118121
}
119-
else
120-
{
121-
QMessageBox::warning( mCanvas,
122-
tr( "No active layer" ),
123-
tr( "To identify features, you must choose an active layer by clicking on its name in the legend" ) );
124-
}
125-
126-
127122
}
128123

129124

130125
void QgsMapToolIdentify::identifyRasterLayer( const QgsPoint& point )
131126
{
132127
QgsRasterLayer *layer = dynamic_cast<QgsRasterLayer*>( mLayer );
133128
if ( !layer )
129+
{
134130
return;
131+
}
135132

136133
QMap<QString, QString> attributes;
137134
layer->identify( point, attributes );
@@ -232,7 +229,9 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
232229
{
233230
QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer*>( mLayer );
234231
if ( !layer )
232+
{
235233
return;
234+
}
236235

237236
// load identify radius from settings
238237
QSettings settings;
@@ -421,9 +420,19 @@ void QgsMapToolIdentify::showError()
421420
#endif
422421

423422
QgsMessageViewer * mv = new QgsMessageViewer();
424-
mv->setWindowTitle( mLayer->lastErrorTitle() );
425-
mv->setMessageAsPlainText( tr( "Could not identify objects on %1 because:\n%2" )
426-
.arg( mLayer->name() ).arg( mLayer->lastError() ) );
423+
424+
if ( mLayer )
425+
{
426+
mv->setWindowTitle( mLayer->lastErrorTitle() );
427+
mv->setMessageAsPlainText( tr( "Could not identify objects on %1 because:\n%2" )
428+
.arg( mLayer->name() ).arg( mLayer->lastError() ) );
429+
}
430+
else
431+
{
432+
mv->setWindowTitle( tr( "Layer was removed" ) );
433+
mv->setMessageAsPlainText( tr( "Layer to identify objects on was removed" ) );
434+
}
435+
427436
mv->exec(); // deletes itself on close
428437
}
429438

@@ -488,11 +497,10 @@ void QgsMapToolIdentify::editFeature( int featureId )
488497
void QgsMapToolIdentify::editFeature( QgsFeature &f )
489498
{
490499
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
491-
if ( !layer )
492-
return;
493-
494-
if ( !layer->isEditable() )
500+
if ( !layer || !layer->isEditable() )
501+
{
495502
return;
503+
}
496504

497505
QgsAttributeMap src = f.attributeMap();
498506

@@ -519,23 +527,19 @@ void QgsMapToolIdentify::editFeature( QgsFeature &f )
519527
mCanvas->refresh();
520528
}
521529

522-
void QgsMapToolIdentify::removeLayer( QString layerID )
530+
void QgsMapToolIdentify::layerDestroyed()
523531
{
524-
if ( mLayer )
532+
mLayer = 0;
533+
534+
if ( mResults )
525535
{
526-
if ( mLayer->type() == QgsMapLayer::VectorLayer )
527-
{
528-
if ( mLayer->getLayerID() == layerID )
529-
{
530-
if ( mResults )
531-
{
532-
mResults->clear();
533-
delete mRubberBand;
534-
mRubberBand = 0;
535-
}
536-
mLayer = 0;
537-
}
538-
}
536+
mResults->clear();
537+
}
538+
539+
if ( mRubberBand )
540+
{
541+
delete mRubberBand;
542+
mRubberBand = 0;
539543
}
540544
}
541545

src/app/qgsmaptoolidentify.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ class QgsMapToolIdentify : public QgsMapTool
117117
// Let us know when the QgsIdentifyResults dialog box has been closed
118118
void resultsDialogGone();
119119

120-
// Check if the mLayer is removing from canvas to clear the results dialog
121-
void removeLayer( QString );
122-
120+
// layer was destroyed
121+
void layerDestroyed();
123122
};
124123

125124
#endif

src/core/raster/qgsrasterlayer.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5438,9 +5438,3 @@ QString QgsRasterLayer::validateBandName( QString const & theBandName )
54385438
QgsDebugMsg( "All checks failed, returning '" + QSTRING_NOT_SET + "'" );
54395439
return TRSTRING_NOT_SET;
54405440
}
5441-
5442-
5443-
5444-
5445-
5446-

src/providers/wms/qgswmsprovider.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ QImage* QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
455455
url += "FORMAT=" + imageMimeType;
456456

457457
//DPI parameter is accepted by QGIS mapserver (and ignored by the other WMS servers)
458-
if(mDpi != -1)
458+
if ( mDpi != -1 )
459459
{
460-
url += "&DPI=" + QString::number(mDpi);
460+
url += "&DPI=" + QString::number( mDpi );
461461
}
462462

463463
//MH: jpeg does not support transparency and some servers complain if jpg and transparent=true
@@ -2161,13 +2161,12 @@ QString QgsWmsProvider::metadata()
21612161

21622162
QString QgsWmsProvider::identifyAsText( const QgsPoint& point )
21632163
{
2164-
21652164
QgsDebugMsg( "Entering." );
21662165

21672166
// Collect which layers to query on
21682167

21692168
QStringList queryableLayers = QStringList();
2170-
QString text = "";;
2169+
QString text = "";
21712170

21722171
// Test for which layers are suitable for querying with
21732172
for ( QStringList::const_iterator it = activeSubLayers.begin();
@@ -2187,13 +2186,14 @@ QString QgsWmsProvider::identifyAsText( const QgsPoint& point )
21872186
QString layer = QUrl::toPercentEncoding( *it );
21882187

21892188
//! \todo Need to tie this into the options provided by GetCapabilities
2190-
requestUrl += QString( "&QUERY_LAYERS=%1&INFO_FORMAT=text/plain&X=%2&Y=%3" )
2191-
.arg( layer ).arg( point.x() ).arg( point.y() );
2189+
requestUrl += QString( "&QUERY_LAYERS=%1" ).arg( layer );
2190+
requestUrl += QString( "&INFO_FORMAT=text/plain&X=%1&Y=%2" )
2191+
.arg( point.x() ).arg( point.y() );
21922192

21932193
// X,Y in WMS 1.1.1; I,J in WMS 1.3.0
21942194
// requestUrl += QString( "&I=%1&J=%2" ).arg( point.x() ).arg( point.y() );
21952195

2196-
text += "---------------\n" + retrieveUrl( requestUrl );
2196+
text += "---------------\n" + QString::fromUtf8( retrieveUrl( requestUrl ) );
21972197
}
21982198
}
21992199
}

0 commit comments

Comments
 (0)