Skip to content

Commit 3e6fb20

Browse files
author
jef
committedMay 11, 2010
[FEATURE] (re-?)add identifyAsHtml to raster layer and use it in identify
git-svn-id: http://svn.osgeo.org/qgis/trunk@13467 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 0bb64e5 commit 3e6fb20

11 files changed

+215
-53
lines changed
 

‎python/core/qgsrasterdataprovider.sip

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,23 @@ public:
9898
*/
9999
virtual QString identifyAsText(const QgsPoint& point) = 0;
100100

101+
/**
102+
* \brief Identify details from a server (e.g. WMS) from the last screen update
103+
*
104+
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
105+
*
106+
* \return A text document containing the return from the WMS server
107+
*
108+
* \note WMS Servers prefer to receive coordinates in image space, therefore
109+
* this function expects coordinates in that format.
110+
*
111+
* \note The arbitraryness of the returned document is enforced by WMS standards
112+
* up to at least v1.3.0
113+
*
114+
* \note added in 1.5
115+
*/
116+
virtual QString identifyAsHtml(const QgsPoint& point) = 0;
117+
101118
/**
102119
* \brief Returns the caption error text for the last error in this provider
103120
*

‎python/core/qgsrasterlayer.sip

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,11 @@ public:
322322
/** \brief Identify arbitrary details from the WMS server found on the point position */
323323
QString identifyAsText( const QgsPoint & point );
324324

325+
/** \brief Identify arbitrary details from the WMS server found on the point position
326+
* @added in 1.5
327+
*/
328+
QString identifyAsHtml( const QgsPoint & point );
329+
325330
/** \brief Currently returns always false */
326331
bool isEditable() const;
327332

‎src/app/qgsidentifyresults.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "qgisapp.h"
2323
#include "qgsmaplayer.h"
2424
#include "qgsvectorlayer.h"
25+
#include "qgsrasterlayer.h"
2526
#include "qgsrubberband.h"
2627
#include "qgsgeometry.h"
2728
#include "qgsattributedialog.h"
@@ -39,6 +40,7 @@
3940
#include <QDockWidget>
4041
#include <QMenuBar>
4142
#include <QPushButton>
43+
#include <QTextBrowser>
4244

4345
#include "qgslogger.h"
4446

@@ -154,6 +156,7 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
154156
{
155157
QTreeWidgetItem *layItem = layerItem( layer );
156158
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
159+
QgsRasterLayer *rlayer = qobject_cast<QgsRasterLayer *>( layer );
157160

158161
if ( layItem == 0 )
159162
{
@@ -179,15 +182,28 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
179182

180183
QTreeWidgetItem *featItem = new QTreeWidgetItem( QStringList() << displayField << displayValue );
181184
featItem->setData( 0, Qt::UserRole, fid );
185+
layItem->addChild( featItem );
182186

183-
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
187+
if ( !rlayer || rlayer->providerKey() != "wms" )
184188
{
185-
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << it.key() << it.value() );
186-
if ( vlayer )
189+
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
187190
{
188-
attrItem->setData( 0, Qt::UserRole, vlayer->fieldNameIndex( it.key() ) );
191+
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << it.key() << it.value() );
192+
if ( vlayer )
193+
{
194+
attrItem->setData( 0, Qt::UserRole, vlayer->fieldNameIndex( it.key() ) );
195+
}
196+
featItem->addChild( attrItem );
189197
}
198+
}
199+
else
200+
{
201+
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << attributes.begin().key() << "" );
190202
featItem->addChild( attrItem );
203+
204+
QTextBrowser *tb = new QTextBrowser( attrItem->treeWidget() );
205+
tb->setHtml( attributes.begin().value() );
206+
attrItem->treeWidget()->setItemWidget( attrItem, 1, tb );
191207
}
192208

193209
if ( derivedAttributes.size() >= 0 )
@@ -228,8 +244,6 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
228244
}
229245
}
230246

231-
layItem->addChild( featItem );
232-
233247
highlightFeature( featItem );
234248
}
235249

‎src/app/qgsmaptoolidentify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, int x, int
373373
yMaxView > yMaxLayer ? floor( y - ( yMaxView - yMaxLayer ) / mapUnitsPerPixel ) : y
374374
);
375375

376-
attributes.insert( tr( "Feature info" ), layer->identifyAsText( idPoint ) );
376+
attributes.insert( tr( "Feature info" ), layer->identifyAsHtml( idPoint ) );
377377
}
378378
else
379379
{

‎src/core/qgsrasterdataprovider.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
133133
*/
134134
virtual QString identifyAsText( const QgsPoint& point ) = 0;
135135

136+
/**
137+
* \brief Identify details from a server (e.g. WMS) from the last screen update
138+
*
139+
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
140+
*
141+
* \return A html document containing the return from the WMS server
142+
*
143+
* \note WMS Servers prefer to receive coordinates in image space, therefore
144+
* this function expects coordinates in that format.
145+
*
146+
* \note The arbitraryness of the returned document is enforced by WMS standards
147+
* up to at least v1.3.0
148+
*
149+
* \note added in 1.5
150+
*/
151+
virtual QString identifyAsHtml( const QgsPoint& point ) = 0;
152+
136153
/**
137154
* \brief Returns the caption error text for the last error in this provider
138155
*

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,24 @@ QString QgsRasterLayer::identifyAsText( const QgsPoint& thePoint )
19691969
return QString();
19701970
}
19711971

1972-
return ( mDataProvider->identifyAsText( thePoint ) );
1972+
return mDataProvider->identifyAsText( thePoint );
1973+
}
1974+
1975+
/**
1976+
* @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0
1977+
*
1978+
* @param thePoint an image pixel coordinate in the last requested extent of layer.
1979+
* @return A html document containing the return from the WMS server
1980+
*/
1981+
QString QgsRasterLayer::identifyAsHtml( const QgsPoint& thePoint )
1982+
{
1983+
if ( mProviderKey != "wms" )
1984+
{
1985+
// Currently no meaning for anything other than OGC WMS layers
1986+
return QString();
1987+
}
1988+
1989+
return mDataProvider->identifyAsHtml( thePoint );
19731990
}
19741991

19751992
/**

‎src/core/raster/qgsrasterlayer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
488488
/** \brief Identify arbitrary details from the WMS server found on the point position */
489489
QString identifyAsText( const QgsPoint & point );
490490

491+
/** \brief Identify arbitrary details from the WMS server found on the point position
492+
* @added in 1.5
493+
*/
494+
QString identifyAsHtml( const QgsPoint & point );
495+
491496
/** \brief Currently returns always false */
492497
bool isEditable() const;
493498

‎src/providers/grass/qgsgrassrasterprovider.cpp

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ static QString PROVIDER_KEY = "grassraster";
4242
static QString PROVIDER_DESCRIPTION = "GRASS raster provider";
4343

4444
QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
45-
: QgsRasterDataProvider( uri ), mValid(true)
45+
: QgsRasterDataProvider( uri ), mValid( true )
4646
{
4747
QgsDebugMsg( "QgsGrassRasterProvider: constructing with uri '" + uri + "'." );
4848

4949
// Parse URI, it is the same like using GDAL, i.e. path to raster cellhd, i.e.
5050
// /path/to/gisdbase/location/mapset/cellhd/map
51-
QFileInfo fileInfo ( uri );
51+
QFileInfo fileInfo( uri );
5252
mValid = fileInfo.exists(); // then we keep it valid forever
5353
mMapName = fileInfo.fileName();
5454
QDir dir = fileInfo.dir();
5555
QString element = dir.dirName();
56-
if ( element != "cellhd" )
56+
if ( element != "cellhd" )
5757
{
58-
QMessageBox::warning( 0, QObject::tr( "Warning" ),
59-
QObject::tr( "Groups not yet supported" ) + " (GRASS " + uri + ")" );
58+
QMessageBox::warning( 0, QObject::tr( "Warning" ),
59+
QObject::tr( "Groups not yet supported" ) + " (GRASS " + uri + ")" );
6060

6161
mValid = false;
6262
return;
@@ -72,8 +72,8 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
7272
QgsDebugMsg( QString( "location: %1" ).arg( mLocation ) );
7373
QgsDebugMsg( QString( "mapset: %1" ).arg( mMapset ) );
7474
QgsDebugMsg( QString( "mapName: %1" ).arg( mMapName ) );
75-
76-
mCrs = QgsGrass::crs ( mGisdbase, mLocation );
75+
76+
mCrs = QgsGrass::crs( mGisdbase, mLocation );
7777
}
7878

7979
QgsGrassRasterProvider::~QgsGrassRasterProvider()
@@ -88,37 +88,37 @@ QImage* QgsGrassRasterProvider::draw( QgsRectangle const & viewExtent, int pixe
8888
QgsDebugMsg( "viewExtent: " + viewExtent.toString() );
8989

9090
QImage *image = new QImage( pixelWidth, pixelHeight, QImage::Format_ARGB32 );
91-
image->fill ( QColor(Qt::gray).rgb() );
91+
image->fill( QColor( Qt::gray ).rgb() );
9292

9393
QStringList arguments;
9494
arguments.append( "map=" + mMapName + "@" + mMapset );
95-
96-
arguments.append( (QString("window=%1,%2,%3,%4,%5,%6")
97-
.arg(viewExtent.xMinimum()).arg(viewExtent.yMinimum())
98-
.arg(viewExtent.xMaximum()).arg(viewExtent.yMaximum())
99-
.arg(pixelWidth).arg(pixelHeight)) );
95+
96+
arguments.append(( QString( "window=%1,%2,%3,%4,%5,%6" )
97+
.arg( viewExtent.xMinimum() ).arg( viewExtent.yMinimum() )
98+
.arg( viewExtent.xMaximum() ).arg( viewExtent.yMaximum() )
99+
.arg( pixelWidth ).arg( pixelHeight ) ) );
100100
QProcess process( this );
101101
QString cmd = QgsApplication::pkgDataPath() + "/grass/modules/qgis.d.rast";
102102
QByteArray data;
103-
try
103+
try
104104
{
105-
data = QgsGrass::runModule ( mGisdbase, mLocation, cmd, arguments );
105+
data = QgsGrass::runModule( mGisdbase, mLocation, cmd, arguments );
106106
}
107107
catch ( QgsGrass::Exception &e )
108108
{
109109
QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Cannot draw raster" ) + "\n"
110-
+ e.what() );
110+
+ e.what() );
111111

112112
// We don't set mValid to false, because the raster can be recreated and work next time
113113
return image;
114114
}
115-
QgsDebugMsg( QString("%1 bytes read from modules stdout").arg(data.size()) );
115+
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
116116
uchar * ptr = image->bits( ) ;
117117
// byteCount() in Qt >= 4.6
118118
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
119-
int size = pixelWidth*pixelHeight*4 < data.size() ? pixelWidth*pixelHeight*4 : data.size();
120-
memcpy ( ptr, data.data(), size );
121-
119+
int size = pixelWidth * pixelHeight * 4 < data.size() ? pixelWidth * pixelHeight * 4 : data.size();
120+
memcpy( ptr, data.data(), size );
121+
122122
return image;
123123
}
124124

@@ -134,15 +134,15 @@ QgsRectangle QgsGrassRasterProvider::extent()
134134
// we should save mExtent and mLastModified and check if the map was modified
135135

136136
QgsRectangle rect;
137-
rect = QgsGrass::extent ( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster );
137+
rect = QgsGrass::extent( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster );
138138
return rect;
139139
}
140140

141141
bool QgsGrassRasterProvider::identify( const QgsPoint& thePoint, QMap<QString, QString>& theResults )
142142
{
143143
QgsDebugMsg( "Entered" );
144144
//theResults["Error"] = tr( "Out of extent" );
145-
theResults = QgsGrass::query ( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster, thePoint.x(), thePoint.y() );
145+
theResults = QgsGrass::query( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster, thePoint.x(), thePoint.y() );
146146
return true;
147147
}
148148

@@ -159,23 +159,28 @@ bool QgsGrassRasterProvider::isValid()
159159

160160
QString QgsGrassRasterProvider::identifyAsText( const QgsPoint& point )
161161
{
162-
return QString ("Not implemented");
162+
return QString( "Not implemented" );
163+
}
164+
165+
QString QgsGrassRasterProvider::identifyAsHtml( const QgsPoint& point )
166+
{
167+
return QString( "Not implemented" );
163168
}
164169

165170
QString QgsGrassRasterProvider::lastErrorTitle()
166171
{
167-
return QString ("Not implemented");
172+
return QString( "Not implemented" );
168173
}
169174

170175
QString QgsGrassRasterProvider::lastError()
171176
{
172-
return QString ("Not implemented");
177+
return QString( "Not implemented" );
173178
}
174179

175180
QString QgsGrassRasterProvider::name() const
176181
{
177182
return PROVIDER_KEY;
178-
}
183+
}
179184

180185
QString QgsGrassRasterProvider::description() const
181186
{

‎src/providers/grass/qgsgrassrasterprovider.h

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,23 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
126126
*/
127127
QString identifyAsText( const QgsPoint& point );
128128

129+
/**
130+
* \brief Identify details from a WMS Server from the last screen update
131+
*
132+
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
133+
*
134+
* \return A text document containing the return from the WMS server
135+
*
136+
* \note WMS Servers prefer to receive coordinates in image space, therefore
137+
* this function expects coordinates in that format.
138+
*
139+
* \note The arbitraryness of the returned document is enforced by WMS standards
140+
* up to at least v1.3.0
141+
*
142+
* \note added in 1.5
143+
*/
144+
QString identifyAsHtml( const QgsPoint& point );
145+
129146
/**
130147
* \brief Returns the caption error text for the last error in this provider
131148
*
@@ -160,12 +177,12 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
160177
*/
161178
QString metadata() { return QString(); }
162179

163-
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
180+
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
164181
void addLayers( QStringList const & layers, QStringList const & styles = QStringList() ) {}
165-
QStringList supportedImageEncodings() { return QStringList();}
182+
QStringList supportedImageEncodings() { return QStringList();}
166183
QString imageEncoding() const { return QString(); }
167184
void setImageEncoding( QString const & mimeType ) {}
168-
void setImageCrs( QString const & crs ) {}
185+
void setImageCrs( QString const & crs ) {}
169186

170187
private:
171188

@@ -177,8 +194,8 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
177194
QString mGisdbase; // map gisdabase
178195
QString mLocation; // map location name (not path!)
179196
QString mMapset; // map mapset
180-
QString mMapName; // map name
181-
197+
QString mMapName; // map name
198+
182199
QgsCoordinateReferenceSystem mCrs;
183200
};
184201

0 commit comments

Comments
 (0)
Please sign in to comment.