40 #include <QMessageBox>
41 #include <QMouseEvent>
52 QPixmap myIdentifyQPixmap = QPixmap((
const char ** )
identify_cursor );
53 mCursor = QCursor( myIdentifyQPixmap, 1, 1 );
82 return identify( x, y, mode, QList<QgsMapLayer*>(), layerType );
87 QList<IdentifyResult> results;
101 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
109 QList<IdentifyResult>::const_iterator it = idResult.constBegin();
110 for ( ; it != idResult.constEnd(); ++it )
124 QMenu layerSelectionMenu;
125 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator resultIt =
mLayerIdResults.constBegin();
128 QAction*
action =
new QAction( resultIt.key()->name(), 0 );
129 action->setData( resultIt.key()->id() );
153 QObject::connect( action, SIGNAL( hovered() ),
this, SLOT(
handleMenuHover() ) );
154 layerSelectionMenu.addAction( action );
158 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
159 QAction* selectedAction = layerSelectionMenu.exec( globalPos );
160 if ( selectedAction )
163 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator sIt =
mLayerIdResults.find( selectedLayer );
166 results = sIt.value();
172 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
178 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
182 QApplication::setOverrideCursor( Qt::WaitCursor );
188 QApplication::setOverrideCursor( Qt::WaitCursor );
193 if ( layerList.isEmpty() )
196 layerCount = layerList.count();
199 for (
int i = 0; i < layerCount; i++ )
203 if ( layerList.isEmpty() )
206 layer = layerList.value( i );
211 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
225 QApplication::restoreOverrideCursor();
244 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
269 QMap< QString, QString > commonDerivedAttributes;
271 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
277 if ( identifyValue <= 0.0 )
280 int featureCount = 0;
312 QgsFeatureList::iterator f_it = featureList.begin();
324 for ( ; f_it != featureList.end(); ++f_it )
326 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
337 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
339 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
347 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
349 return featureCount > 0;
356 QMap< QString, QString > derivedAttributes;
379 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
380 derivedAttributes.insert(
tr(
"Length" ), str );
385 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
386 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
387 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
388 derivedAttributes.insert(
tr(
"firstY" ), str );
390 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
391 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
392 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
393 derivedAttributes.insert(
tr(
"lastY" ), str );
402 QString str = calc.
textUnit( area, 3, myDisplayUnits,
true );
403 derivedAttributes.insert(
tr(
"Area" ), str );
405 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
406 derivedAttributes.insert(
tr(
"Perimeter" ), str );
413 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
414 derivedAttributes.insert(
"X", str );
415 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
416 derivedAttributes.insert(
"Y", str );
419 return derivedAttributes;
425 if ( !layer )
return false;
442 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
445 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
449 QMap< QString, QString > attributes, derivedAttributes;
474 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
475 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
476 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
477 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
481 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
497 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
498 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
500 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
501 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
502 QgsDebugMsg( QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
504 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
507 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
509 if ( identifyResult.
isValid() )
511 QMap<int, QVariant> values = identifyResult.
results();
515 foreach (
int bandNo, values.keys() )
518 if ( values.value( bandNo ).isNull() )
520 valueString =
tr(
"no data" );
524 double value = values.value( bandNo ).toDouble();
529 QString label = layer->
name();
530 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
534 foreach (
int i, values.keys() )
536 QVariant value = values.value( i );
537 if ( value.type() == QVariant::Bool && !value.toBool() )
543 if ( value.type() == QVariant::String )
547 QString label = layer->
subLayers().value( i );
549 attributes.insert(
tr(
"Error" ), value.toString() );
551 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
566 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
567 QString featureType = featureStore.
params().value(
"featureType" ).toString();
569 featureType.remove(
"_feature" );
571 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
575 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
577 labels << featureType;
582 QMap< QString, QString > derAttributes = derivedAttributes;
585 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join(
" / " ), featureStore.
fields(), feature, derAttributes );
587 identifyResult.
mParams.insert(
"getFeatureInfoUrl", featureStore.
params().value(
"getFeatureInfoUrl" ) );
588 results->append( identifyResult );
595 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
596 foreach (
int bandNo, values.keys() )
598 QString value = values.value( bandNo ).toString();
600 attributes.insert(
"", value );
602 QString label = layer->
subLayers().value( bandNo );
603 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
611 attributes.insert(
tr(
"Error" ), value );
612 QString label =
tr(
"Identify error" );
613 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
639 QList<IdentifyResult> results;
654 QAction* senderAction = qobject_cast<QAction*>( sender() );
660 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator lIt =
mLayerIdResults.find( vl );
663 const QList<IdentifyResult>& idList = lIt.value();
664 QList<IdentifyResult>::const_iterator idListIt = idList.constBegin();
665 for ( ; idListIt != idList.constEnd(); ++idListIt )
668 hl->
setColor( QColor( 255, 0, 0 ) );
679 QList<QgsHighlight*>::const_iterator it =
mRubberBands.constBegin();