40 #include <QMouseEvent>
50 , mLastMapUnitsPerPixel( -1.0 )
53 QPixmap myIdentifyQPixmap = QPixmap((
const char ** )
identify_cursor );
54 mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
84 return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
89 QList<IdentifyResult> results;
98 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
104 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
107 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
113 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
117 QApplication::setOverrideCursor( Qt::WaitCursor );
119 identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType );
123 QApplication::setOverrideCursor( Qt::WaitCursor );
128 if ( layerList.isEmpty() )
131 layerCount = layerList.count();
134 for (
int i = 0; i < layerCount; i++ )
138 if ( layerList.isEmpty() )
141 layer = layerList.value( i );
146 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
149 if (
identifyLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel, layerType ) )
160 QApplication::restoreOverrideCursor();
179 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
204 QApplication::setOverrideCursor( Qt::WaitCursor );
206 QMap< QString, QString > commonDerivedAttributes;
208 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
210 int featureCount = 0;
242 QgsFeatureList::iterator f_it = featureList.begin();
255 for ( ; f_it != featureList.end(); ++f_it )
257 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
266 derivedAttributes.unite( featureDerivedAttributes( &( *f_it ), layer ) );
268 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
270 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
278 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
280 QApplication::restoreOverrideCursor();
281 return featureCount > 0;
284 QMap< QString, QString > QgsMapToolIdentify::featureDerivedAttributes(
QgsFeature *feature,
QgsMapLayer *layer )
288 QMap< QString, QString > derivedAttributes;
310 convertMeasurement( calc, dist, myDisplayUnits,
false );
311 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
312 derivedAttributes.insert(
tr(
"Length" ), str );
317 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
318 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
319 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
320 derivedAttributes.insert(
tr(
"firstY" ), str );
322 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
323 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
324 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
325 derivedAttributes.insert(
tr(
"lastY" ), str );
333 convertMeasurement( calc, area, myDisplayUnits,
true );
334 QString str = calc.
textUnit( area, 3, myDisplayUnits,
true );
335 derivedAttributes.insert(
tr(
"Area" ), str );
336 convertMeasurement( calc, perimeter, myDisplayUnits,
false );
337 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
338 derivedAttributes.insert(
tr(
"Perimeter" ), str );
345 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
346 derivedAttributes.insert(
"X", str );
347 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
348 derivedAttributes.insert(
"Y", str );
351 return derivedAttributes;
376 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
379 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
384 QMap< QString, QString > attributes, derivedAttributes;
409 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
410 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
411 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
412 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
416 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
432 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
433 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
435 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
436 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
437 QgsDebugMsg( QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
439 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
442 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
444 if ( identifyResult.
isValid() )
446 QMap<int, QVariant> values = identifyResult.
results();
450 foreach (
int bandNo, values.keys() )
453 if ( values.value( bandNo ).isNull() )
455 valueString =
tr(
"no data" );
459 double value = values.value( bandNo ).toDouble();
464 QString label = layer->
name();
465 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
469 foreach (
int i, values.keys() )
471 QVariant value = values.value( i );
472 if ( value.type() == QVariant::Bool && !value.toBool() )
478 if ( value.type() == QVariant::String )
482 QString label = layer->
subLayers().value( i );
484 attributes.insert(
tr(
"Error" ), value.toString() );
486 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
501 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
502 QString featureType = featureStore.
params().value(
"featureType" ).toString();
504 featureType.remove(
"_feature" );
506 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
510 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
512 labels << featureType;
515 QMap< QString, QString > derAttributes = derivedAttributes;
516 derAttributes.unite( featureDerivedAttributes( &feature, layer ) );
518 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join(
" / " ), featureStore.
fields(), feature, derAttributes );
520 identifyResult.mParams.insert(
"getFeatureInfoUrl", featureStore.
params().value(
"getFeatureInfoUrl" ) );
521 results->append( identifyResult );
528 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
529 foreach (
int bandNo, values.keys() )
531 QString value = values.value( bandNo ).toString();
533 attributes.insert(
"", value );
535 QString label = layer->
subLayers().value( bandNo );
536 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
544 attributes.insert(
tr(
"Error" ), value );
545 QString label =
tr(
"Identify error" );
546 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
572 QList<IdentifyResult> results;
573 if (
identifyRasterLayer( &results, layer, mLastPoint, mLastExtent, mLastMapUnitsPerPixel ) )