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;
96 mode =
static_cast<IdentifyMode>( settings.value(
"/Map/identifyMode", 0 ).toInt() );
104 QList<IdentifyResult>::const_iterator it = idResult.constBegin();
105 for ( ; it != idResult.constEnd(); ++it )
121 QMenu layerSelectionMenu;
122 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator resultIt =
mLayerIdResults.constBegin();
125 QAction*
action =
new QAction( QString(
"%1 (%2)" ).arg( resultIt.key()->name() ).arg( resultIt.value().size() ), 0 );
126 action->setData( resultIt.key()->id() );
150 connect( action, SIGNAL( hovered() ),
this, SLOT(
handleMenuHover() ) );
151 layerSelectionMenu.addAction( action );
154 QAction *
action =
new QAction(
tr(
"All (%1)" ).arg( idResult.size() ), 0 );
155 connect( action, SIGNAL( hovered() ),
this, SLOT(
handleMenuHover() ) );
156 layerSelectionMenu.addAction( action );
159 QPoint globalPos =
mCanvas->mapToGlobal( QPoint( x + 5, y + 5 ) );
160 QAction* selectedAction = layerSelectionMenu.exec( globalPos );
161 if ( selectedAction )
163 if ( selectedAction->data().toString().isEmpty() )
170 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator sIt =
mLayerIdResults.find( selectedLayer );
173 results = sIt.value();
185 else if ( mode ==
ActiveLayer && layerList.isEmpty() )
191 emit
identifyMessage(
tr(
"No active layer. To identify features, you must choose an active layer." ) );
195 QApplication::setOverrideCursor( Qt::WaitCursor );
201 QApplication::setOverrideCursor( Qt::WaitCursor );
206 if ( layerList.isEmpty() )
209 layerCount = layerList.count();
212 for (
int i = 0; i < layerCount; i++ )
216 if ( layerList.isEmpty() )
219 layer = layerList.value( i );
224 if ( noIdentifyLayerIdList.contains( layer->
id() ) )
238 QApplication::restoreOverrideCursor();
257 return identifyRasterLayer( results, qobject_cast<QgsRasterLayer *>( layer ), point, viewExtent, mapUnitsPerPixel );
282 QMap< QString, QString > commonDerivedAttributes;
284 commonDerivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
286 int featureCount = 0;
318 QgsFeatureList::iterator f_it = featureList.begin();
331 for ( ; f_it != featureList.end(); ++f_it )
333 QMap< QString, QString > derivedAttributes = commonDerivedAttributes;
344 derivedAttributes.insert(
tr(
"feature id" ), fid < 0 ?
tr(
"new feature" ) :
FID_TO_STRING( fid ) );
346 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), *f_it, derivedAttributes ) );
354 QgsDebugMsg(
"Feature count on identify: " + QString::number( featureCount ) );
356 return featureCount > 0;
363 QMap< QString, QString > derivedAttributes;
386 QString str = calc.
textUnit( dist, 3, myDisplayUnits,
false );
387 derivedAttributes.insert(
tr(
"Length" ), str );
392 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
393 derivedAttributes.insert(
tr(
"firstX",
"attributes get sorted; translation for lastX should be lexically larger than this one" ), str );
394 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
395 derivedAttributes.insert(
tr(
"firstY" ), str );
397 str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
398 derivedAttributes.insert(
tr(
"lastX",
"attributes get sorted; translation for firstX should be lexically smaller than this one" ), str );
399 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
400 derivedAttributes.insert(
tr(
"lastY" ), str );
409 QString str = calc.
textUnit( area, 3, myDisplayUnits,
true );
410 derivedAttributes.insert(
tr(
"Area" ), str );
412 str = calc.
textUnit( perimeter, 3, myDisplayUnits,
false );
413 derivedAttributes.insert(
tr(
"Perimeter" ), str );
420 QString str = QLocale::system().
toString( pnt.
x(),
'g', 10 );
421 derivedAttributes.insert(
"X", str );
422 str = QLocale::system().toString( pnt.
y(),
'g', 10 );
423 derivedAttributes.insert(
"Y", str );
426 return derivedAttributes;
448 QgsDebugMsg( QString(
"coordinate not reprojectable: %1" ).arg( cse.
what() ) );
451 QgsDebugMsg( QString(
"point = %1 %2" ).arg( point.
x() ).arg( point.
y() ) );
455 QMap< QString, QString > attributes, derivedAttributes;
480 r.
setXMinimum( pointInCanvasCrs.
x() - mapUnitsPerPixel / 2. );
481 r.
setXMaximum( pointInCanvasCrs.
x() + mapUnitsPerPixel / 2. );
482 r.
setYMinimum( pointInCanvasCrs.
y() - mapUnitsPerPixel / 2. );
483 r.
setYMaximum( pointInCanvasCrs.
y() + mapUnitsPerPixel / 2. );
487 identifyResult = dprovider->
identify( point, format, r, 1, 1 );
503 int width = qRound( viewExtent.
width() / mapUnitsPerPixel );
504 int height = qRound( viewExtent.
height() / mapUnitsPerPixel );
506 QgsDebugMsg( QString(
"viewExtent.width = %1 viewExtent.height = %2" ).arg( viewExtent.
width() ).arg( viewExtent.
height() ) );
507 QgsDebugMsg( QString(
"width = %1 height = %2" ).arg( width ).arg( height ) );
508 QgsDebugMsg( QString(
"xRes = %1 yRes = %2 mapUnitsPerPixel = %3" ).arg( viewExtent.
width() / width ).arg( viewExtent.
height() / height ).arg( mapUnitsPerPixel ) );
510 identifyResult = dprovider->
identify( point, format, viewExtent, width, height );
513 derivedAttributes.insert(
tr(
"(clicked coordinate)" ), point.
toString() );
515 if ( identifyResult.
isValid() )
517 QMap<int, QVariant> values = identifyResult.
results();
521 foreach (
int bandNo, values.keys() )
524 if ( values.value( bandNo ).isNull() )
526 valueString =
tr(
"no data" );
530 double value = values.value( bandNo ).toDouble();
535 QString label = layer->
name();
536 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
540 foreach (
int i, values.keys() )
542 QVariant value = values.value( i );
543 if ( value.type() == QVariant::Bool && !value.toBool() )
549 if ( value.type() == QVariant::String )
553 QString label = layer->
subLayers().value( i );
555 attributes.insert(
tr(
"Error" ), value.toString() );
557 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
572 QString sublayer = featureStore.
params().value(
"sublayer" ).toString();
573 QString featureType = featureStore.
params().value(
"featureType" ).toString();
575 featureType.remove(
"_feature" );
577 if ( sublayer.compare( layer->
name(), Qt::CaseInsensitive ) != 0 )
581 if ( featureType.compare( sublayer, Qt::CaseInsensitive ) != 0 || labels.isEmpty() )
583 labels << featureType;
586 QMap< QString, QString > derAttributes = derivedAttributes;
589 IdentifyResult identifyResult( qobject_cast<QgsMapLayer *>( layer ), labels.join(
" / " ), featureStore.
fields(), feature, derAttributes );
591 identifyResult.
mParams.insert(
"getFeatureInfoUrl", featureStore.
params().value(
"getFeatureInfoUrl" ) );
592 results->append( identifyResult );
599 QgsDebugMsg( QString(
"%1 html or text values" ).arg( values.size() ) );
600 foreach (
int bandNo, values.keys() )
602 QString value = values.value( bandNo ).toString();
604 attributes.insert(
"", value );
606 QString label = layer->
subLayers().value( bandNo );
607 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
615 attributes.insert(
tr(
"Error" ), value );
616 QString label =
tr(
"Identify error" );
617 results->append(
IdentifyResult( qobject_cast<QgsMapLayer *>( layer ), label, attributes, derivedAttributes ) );
643 QList<IdentifyResult> results;
658 QAction* senderAction = qobject_cast<QAction*>( sender() );
664 QMap< QgsMapLayer*, QList<IdentifyResult> >::const_iterator lIt =
mLayerIdResults.find( vl );
667 const QList<IdentifyResult>& idList = lIt.value();
668 QList<IdentifyResult>::const_iterator idListIt = idList.constBegin();
669 for ( ; idListIt != idList.constEnd(); ++idListIt )
672 hl->
setColor( QColor( 255, 0, 0 ) );
675 connect( vl, SIGNAL( destroyed() ),
this, SLOT(
layerDestroyed() ) );
683 const QList<IdentifyResult>& idList = lIt.value();
684 QList<IdentifyResult>::const_iterator idListIt = idList.constBegin();
685 for ( ; idListIt != idList.constEnd(); ++idListIt )
688 hl->
setColor( QColor( 255, 0, 0 ) );
691 connect( lIt.key(), SIGNAL( destroyed() ),
this, SLOT(
layerDestroyed() ) );
700 QList<QgsHighlight*>::const_iterator it =
mRubberBands.constBegin();
708 QList<QgsHighlight*>::iterator it =
mRubberBands.begin();
711 if (( *it )->layer() == sender() )
bool isValid() const
Returns true if valid.
Wrapper for iterator of features from vector data provider or vector layer.
QMap< QString, QVariant > mParams
Additional params (e.g.
Container for features with the same fields and crs.
QgsFeatureRendererV2 * rendererV2()
Return renderer V2.
virtual bool willRenderFeature(QgsFeature &feat)
return whether the renderer will render a feature or not.
A rectangle specified with double values.
Base class for all map layer types.
QgsPoint layerToMapCoordinates(QgsMapLayer *theLayer, QgsPoint point) const
transform point coordinates from layer's CRS to output CRS
QgsMapLayer::LayerType type() const
Get the type of the layer.
static QString printValue(double value)
Print double value with all necessary significant digits.
double scale() const
Return the calculated scale of the map.
double mapUnitsPerPixel() const
Returns the mapUnitsPerPixel (map units per pixel) for the canvas.
int layerCount() const
return number of layers on the map
void setXMaximum(double x)
Set the maximum x value.
Use exact geometry intersection (slower) instead of bounding boxes.
virtual QgsCoordinateReferenceSystem crs()=0
This class provides qgis with the ability to render raster datasets onto the mapcanvas.
QList< QgsFeatureStore > QgsFeatureStoreList
QList< QgsFeature > QgsFeatureList
void setSourceCrs(long srsid)
sets source spatial reference system (by QGIS CRS)
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
static QIcon getThemeIcon(const QString &theName)
Helper to get a theme icon.
QgsGeometry * geometry() const
Get the geometry object associated with this feature.
bool contains(const QgsRectangle &rect) const
return true when rectangle contains other rectangle
float minimumScale() const
bool hasCrsTransformEnabled()
A simple helper method to find out if on the fly projections are enabled or not.
#define FID_TO_STRING(fid)
QGis::GeometryType type()
Returns type of the vector.
static Capability identifyFormatToCapability(QgsRaster::IdentifyFormat format)
const QgsMapSettings & mapSettings() const
Get access to properties used for map rendering.
WkbType
Used for symbology operations.
bool setEllipsoid(const QString &ellipsoid)
sets ellipsoid by its acronym
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Map canvas is a class for displaying all GIS data types on a canvas.
QMap< int, QVariant > results() const
Get results.
virtual void startRender(QgsRenderContext &context, const QgsFields &fields)=0
virtual void stopRender(QgsRenderContext &context)=0
Raster identify results container.
const QString & name() const
Get the display name of the layer.
virtual QgsRasterIdentifyResult identify(const QgsPoint &thePoint, QgsRaster::IdentifyFormat theFormat, const QgsRectangle &theExtent=QgsRectangle(), int theWidth=0, int theHeight=0)
Identify raster value(s) found on the point position.
QStringList readListEntry(const QString &scope, const QString &key, QStringList def=QStringList(), bool *ok=0) const
key value accessors
virtual QStringList subLayers() const
Returns the sublayers of this layer - Useful for providers that manage their own layers, such as WMS.
bool hasScaleBasedVisibility() const
double measurePerimeter(QgsGeometry *geometry)
measures perimeter of polygon
double measure(QgsGeometry *geometry)
general measurement (line distance or polygon area)
float maximumScale() const
const QgsCoordinateReferenceSystem & destinationCrs() const
returns CRS of destination coordinate reference system
void setYMinimum(double y)
Set the minimum y value.
A class for highlight features on the map.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QString toString() const
String representation of the point (x,y)
QString id() const
Get this layer's unique ID, this ID is used to access this layer from map layer registry.
virtual QString generateBandName(int theBandNumber) const
helper function to create zero padded band names
QGis::WkbType wkbType() const
Returns type of wkb (point / linestring / polygon etc.)
QGis::GeometryType geometryType() const
Returns point, line or polygon.
QGis::UnitType mapUnits() const
Get the current canvas map units.
QVariant customProperty(const QString &value, const QVariant &defaultValue=QVariant()) const
Read a custom property from layer.
QString message(QgsErrorMessage::Format theFormat=QgsErrorMessage::Html) const
Full error messages description.
A class to represent a point geometry.
virtual int capabilities() const
Returns a bitmask containing the supported capabilities.
QgsMapLayer * currentLayer()
returns current layer (set by legend widget)
QgsPoint toMapCoordinates(int x, int y) const
static QString textUnit(double value, int decimals, QGis::UnitType u, bool isArea, bool keepBaseUnit=false)
General purpose distance and area calculator.
QgsPolyline asPolyline() const
return contents of the geometry as a polyline if wkbType is WKBLineString, otherwise an empty list ...
bool hasGeometryType() const
Returns true if this is a geometry layer and false in case of NoGeometry (table only) or UnknownGeome...
Contains information about the context of a rendering operation.
QString readEntry(const QString &scope, const QString &key, const QString &def=QString::null, bool *ok=0) const
static QgsMapLayerRegistry * instance()
Returns the instance pointer, creating the object on the first call.
void setColor(const QColor &color)
Set line/outline to color, polygon fill to color with alpha = 63.
void setYMaximum(double y)
Set the maximum y value.
static QgsRenderContext fromMapSettings(const QgsMapSettings &mapSettings)
create initialized QgsRenderContext instance from given QgsMapSettings
static QgsProject * instance()
access to canonical QgsProject instance
const CORE_EXPORT QString GEO_NONE
Constant that holds the string representation for "No ellips/No CRS".
UnitType
Map units that qgis supports.
const QgsMapToPixel * getCoordinateTransform()
Get the current coordinate transform.
const QgsCoordinateReferenceSystem & crs() const
Returns layer's spatial reference system.
QgsFields & fields()
Get fields list.
QgsMapLayer * mapLayer(QString theLayerId)
Retrieve a pointer to a loaded layer by id.
void convertMeasurement(double &measure, QGis::UnitType &measureUnits, QGis::UnitType displayUnits, bool isArea)
Helper for conversion between physical units.
static QgsRaster::IdentifyFormat identifyFormatFromName(QString formatName)
QgsRasterDataProvider * dataProvider()
Returns the data provider.
QgsRectangle extent() const
Returns the current zoom exent of the map canvas.
Custom exception class for Coordinate Reference System related exceptions.
const QgsFields & pendingFields() const
returns field list in the to-be-committed state
const char * identify_cursor[]
virtual int capabilities()
returns bitwise OR-ed capabilities of the renderer
bool nextFeature(QgsFeature &f)
double width() const
Width of the rectangle.
QgsPoint asPoint() const
return contents of the geometry as a point if wkbType is WKBPoint, otherwise returns [0...
QgsError error() const
Get error.
virtual QgsRectangle extent()
Return the extent of the layer.
Represents a vector layer which manages a vector based data sets.
QMap< QString, QVariant > params() const
Get map of optional parameters.
QgsFeatureList & features()
Get features list reference.
QgsMapLayer * layer(int index)
return the map layer at position index in the layer stack
void setXMinimum(double x)
Set the minimum x value.
void setEllipsoidalMode(bool flag)
sets whether coordinates must be projected to ellipsoid before measuring
double height() const
Height of the rectangle.
Base class for raster data providers.
void setWidth(int width)
Set width.