Skip to content

Commit

Permalink
- fix #1903
Browse files Browse the repository at this point in the history
- 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@11522 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Aug 28, 2009
1 parent 56146bb commit 4702b90
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 77 deletions.
126 changes: 65 additions & 61 deletions src/app/qgsmaptoolidentify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -75,63 +74,61 @@ void QgsMapToolIdentify::canvasReleaseEvent( QMouseEvent * e )
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" )
{
identifyRasterWmsLayer( QgsPoint( e->x(), e->y() ) );
}
else
{
// 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" )
)
// 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" ) );
}


}


void QgsMapToolIdentify::identifyRasterLayer( const QgsPoint& point )
{
QgsRasterLayer *layer = dynamic_cast<QgsRasterLayer*>( mLayer );
if ( !layer )
{
return;
}

QMap<QString, QString> attributes;
layer->identify( point, attributes );
Expand Down Expand Up @@ -232,7 +229,9 @@ void QgsMapToolIdentify::identifyVectorLayer( const QgsPoint& point )
{
QgsVectorLayer *layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
{
return;
}

// load identify radius from settings
QSettings settings;
Expand Down Expand Up @@ -421,9 +420,19 @@ void QgsMapToolIdentify::showError()
#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
}

Expand Down Expand Up @@ -488,11 +497,10 @@ void QgsMapToolIdentify::editFeature( int featureId )
void QgsMapToolIdentify::editFeature( QgsFeature &f )
{
QgsVectorLayer* layer = dynamic_cast<QgsVectorLayer*>( mLayer );
if ( !layer )
return;

if ( !layer->isEditable() )
if ( !layer || !layer->isEditable() )
{
return;
}

QgsAttributeMap src = f.attributeMap();

Expand All @@ -519,23 +527,19 @@ void QgsMapToolIdentify::editFeature( QgsFeature &f )
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;
}
}

Expand Down
5 changes: 2 additions & 3 deletions src/app/qgsmaptoolidentify.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ class QgsMapToolIdentify : public QgsMapTool
// 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
6 changes: 0 additions & 6 deletions src/core/raster/qgsrasterlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5438,9 +5438,3 @@ QString QgsRasterLayer::validateBandName( QString const & theBandName )
QgsDebugMsg( "All checks failed, returning '" + QSTRING_NOT_SET + "'" );
return TRSTRING_NOT_SET;
}






14 changes: 7 additions & 7 deletions src/providers/wms/qgswmsprovider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ QImage* QgsWmsProvider::draw( QgsRectangle const & viewExtent, int pixelWidth,
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
Expand Down Expand Up @@ -2161,13 +2161,12 @@ QString QgsWmsProvider::metadata()

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();
Expand All @@ -2187,13 +2186,14 @@ QString QgsWmsProvider::identifyAsText( const QgsPoint& point )
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 ) );
}
}
}
Expand Down

0 comments on commit 4702b90

Please sign in to comment.