38 #include <QMessageBox>
39 #include <QMouseEvent>
49 QPixmap myIdentifyQPixmap = QPixmap((
const char ** )
identify_cursor );
50 mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
79 return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
84 QList<IdentifyResult> results;
98 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
107 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
111 QApplication::setOverrideCursor( Qt::WaitCursor );
117 QApplication::setOverrideCursor( Qt::WaitCursor );
122 if ( layerList.isEmpty() )
125 layerCount = layerList.count();
128 for (
int i = 0; i < layerCount; i++ )
132 if ( layerList.isEmpty() )
135 layer = layerList.value( i );
140 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
154 QApplication::restoreOverrideCursor();
173 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
198 QMap< QString, QString > commonDerivedAttributes;
200 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
206 if ( identifyValue <= 0.0 )
209 int featureCount = 0;
241 QgsFeatureList::iterator f_it = featureList.begin();
253 for ( ; f_it != featureList.end(); ++f_it )
255 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
266 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
268 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
276 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
278 return featureCount > 0;
285 QMap< QString, QString > derivedAttributes;
308 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
309 derivedAttributes.insert(
tr(
"Length" ), str );
314 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
315 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
316 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
317 derivedAttributes.insert(
tr(
"firstY" ), str );
319 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
320 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
321 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
322 derivedAttributes.insert(
tr(
"lastY" ), str );
331 QString str = calc.
textUnit( area, 3, myDisplayUnits,
true );
332 derivedAttributes.insert(
tr(
"Area" ), str );
334 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
335 derivedAttributes.insert(
tr(
"Perimeter" ), str );
342 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
343 derivedAttributes.insert(
"X", str );
344 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
345 derivedAttributes.insert(
"Y", str );
348 return derivedAttributes;
354 if ( !layer )
return false;
370 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
373 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
377 QMap< QString, QString > attributes, derivedAttributes;
379 QMap<int, QVariant> values;
414 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
415 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
417 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
418 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
419 QgsDebugMsg( QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
421 values = dprovider->
identify( point, format, viewExtent, width, height ).
results();
424 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
430 foreach (
int bandNo, values.keys() )
433 if ( values.value( bandNo ).isNull() )
435 valueString =
tr(
"no data" );
439 double value = values.value( bandNo ).toDouble();
444 QString label = layer->
name();
445 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
449 foreach (
int i, values.keys() )
451 QVariant value = values.value( i );
452 if ( value.type() == QVariant::Bool && !value.toBool() )
458 if ( value.type() == QVariant::String )
462 QString label = layer->
subLayers().value( i );
464 attributes.insert(
tr(
"Error" ), value.toString() );
466 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
481 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
482 QString featureType = featureStore.
params().value(
"featureType" ).toString();
484 featureType.remove(
"_feature" );
486 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
490 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
492 labels << featureType;
497 QMap< QString, QString > derAttributes = derivedAttributes;
500 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join(
" / " ), featureStore.
fields(), feature, derAttributes );
502 identifyResult.
mParams.insert(
"getFeatureInfoUrl", featureStore.
params().value(
"getFeatureInfoUrl" ) );
503 results->append( identifyResult );
510 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
511 foreach (
int bandNo, values.keys() )
513 QString value = values.value( bandNo ).toString();
515 attributes.insert(
"", value );
517 QString label = layer->
subLayers().value( bandNo );
518 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
545 QList<IdentifyResult> results;