Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[FEATURE] (re-?)add identifyAsHtml to raster layer and use it in iden…
…tify

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@13467 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed May 11, 2010
1 parent 40f72f6 commit 7cd2c8b
Show file tree
Hide file tree
Showing 11 changed files with 215 additions and 53 deletions.
17 changes: 17 additions & 0 deletions python/core/qgsrasterdataprovider.sip
Expand Up @@ -98,6 +98,23 @@ public:
*/
virtual QString identifyAsText(const QgsPoint& point) = 0;

/**
* \brief Identify details from a server (e.g. WMS) from the last screen update
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \return A text document containing the return from the WMS server
*
* \note WMS Servers prefer to receive coordinates in image space, therefore
* this function expects coordinates in that format.
*
* \note The arbitraryness of the returned document is enforced by WMS standards
* up to at least v1.3.0
*
* \note added in 1.5
*/
virtual QString identifyAsHtml(const QgsPoint& point) = 0;

/**
* \brief Returns the caption error text for the last error in this provider
*
Expand Down
5 changes: 5 additions & 0 deletions python/core/qgsrasterlayer.sip
Expand Up @@ -322,6 +322,11 @@ public:
/** \brief Identify arbitrary details from the WMS server found on the point position */
QString identifyAsText( const QgsPoint & point );

/** \brief Identify arbitrary details from the WMS server found on the point position
* @added in 1.5
*/
QString identifyAsHtml( const QgsPoint & point );

/** \brief Currently returns always false */
bool isEditable() const;

Expand Down
26 changes: 20 additions & 6 deletions src/app/qgsidentifyresults.cpp
Expand Up @@ -22,6 +22,7 @@
#include "qgisapp.h"
#include "qgsmaplayer.h"
#include "qgsvectorlayer.h"
#include "qgsrasterlayer.h"
#include "qgsrubberband.h"
#include "qgsgeometry.h"
#include "qgsattributedialog.h"
Expand All @@ -39,6 +40,7 @@
#include <QDockWidget>
#include <QMenuBar>
#include <QPushButton>
#include <QTextBrowser>

#include "qgslogger.h"

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

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

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

for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
if ( !rlayer || rlayer->providerKey() != "wms" )
{
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << it.key() << it.value() );
if ( vlayer )
for ( QMap<QString, QString>::const_iterator it = attributes.begin(); it != attributes.end(); it++ )
{
attrItem->setData( 0, Qt::UserRole, vlayer->fieldNameIndex( it.key() ) );
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << it.key() << it.value() );
if ( vlayer )
{
attrItem->setData( 0, Qt::UserRole, vlayer->fieldNameIndex( it.key() ) );
}
featItem->addChild( attrItem );
}
}
else
{
QTreeWidgetItem *attrItem = new QTreeWidgetItem( QStringList() << attributes.begin().key() << "" );
featItem->addChild( attrItem );

QTextBrowser *tb = new QTextBrowser( attrItem->treeWidget() );
tb->setHtml( attributes.begin().value() );
attrItem->treeWidget()->setItemWidget( attrItem, 1, tb );
}

if ( derivedAttributes.size() >= 0 )
Expand Down Expand Up @@ -228,8 +244,6 @@ void QgsIdentifyResults::addFeature( QgsMapLayer *layer, int fid,
}
}

layItem->addChild( featItem );

highlightFeature( featItem );
}

Expand Down
2 changes: 1 addition & 1 deletion src/app/qgsmaptoolidentify.cpp
Expand Up @@ -373,7 +373,7 @@ bool QgsMapToolIdentify::identifyRasterLayer( QgsRasterLayer *layer, int x, int
yMaxView > yMaxLayer ? floor( y - ( yMaxView - yMaxLayer ) / mapUnitsPerPixel ) : y
);

attributes.insert( tr( "Feature info" ), layer->identifyAsText( idPoint ) );
attributes.insert( tr( "Feature info" ), layer->identifyAsHtml( idPoint ) );
}
else
{
Expand Down
17 changes: 17 additions & 0 deletions src/core/qgsrasterdataprovider.h
Expand Up @@ -133,6 +133,23 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider
*/
virtual QString identifyAsText( const QgsPoint& point ) = 0;

/**
* \brief Identify details from a server (e.g. WMS) from the last screen update
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \return A html document containing the return from the WMS server
*
* \note WMS Servers prefer to receive coordinates in image space, therefore
* this function expects coordinates in that format.
*
* \note The arbitraryness of the returned document is enforced by WMS standards
* up to at least v1.3.0
*
* \note added in 1.5
*/
virtual QString identifyAsHtml( const QgsPoint& point ) = 0;

/**
* \brief Returns the caption error text for the last error in this provider
*
Expand Down
19 changes: 18 additions & 1 deletion src/core/raster/qgsrasterlayer.cpp
Expand Up @@ -1969,7 +1969,24 @@ QString QgsRasterLayer::identifyAsText( const QgsPoint& thePoint )
return QString();
}

return ( mDataProvider->identifyAsText( thePoint ) );
return mDataProvider->identifyAsText( thePoint );
}

/**
* @note The arbitraryness of the returned document is enforced by WMS standards up to at least v1.3.0
*
* @param thePoint an image pixel coordinate in the last requested extent of layer.
* @return A html document containing the return from the WMS server
*/
QString QgsRasterLayer::identifyAsHtml( const QgsPoint& thePoint )
{
if ( mProviderKey != "wms" )
{
// Currently no meaning for anything other than OGC WMS layers
return QString();
}

return mDataProvider->identifyAsHtml( thePoint );
}

/**
Expand Down
5 changes: 5 additions & 0 deletions src/core/raster/qgsrasterlayer.h
Expand Up @@ -488,6 +488,11 @@ class CORE_EXPORT QgsRasterLayer : public QgsMapLayer
/** \brief Identify arbitrary details from the WMS server found on the point position */
QString identifyAsText( const QgsPoint & point );

/** \brief Identify arbitrary details from the WMS server found on the point position
* @added in 1.5
*/
QString identifyAsHtml( const QgsPoint & point );

/** \brief Currently returns always false */
bool isEditable() const;

Expand Down
57 changes: 31 additions & 26 deletions src/providers/grass/qgsgrassrasterprovider.cpp
Expand Up @@ -42,21 +42,21 @@ static QString PROVIDER_KEY = "grassraster";
static QString PROVIDER_DESCRIPTION = "GRASS raster provider";

QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
: QgsRasterDataProvider( uri ), mValid(true)
: QgsRasterDataProvider( uri ), mValid( true )
{
QgsDebugMsg( "QgsGrassRasterProvider: constructing with uri '" + uri + "'." );

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

mValid = false;
return;
Expand All @@ -72,8 +72,8 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
QgsDebugMsg( QString( "location: %1" ).arg( mLocation ) );
QgsDebugMsg( QString( "mapset: %1" ).arg( mMapset ) );
QgsDebugMsg( QString( "mapName: %1" ).arg( mMapName ) );
mCrs = QgsGrass::crs ( mGisdbase, mLocation );

mCrs = QgsGrass::crs( mGisdbase, mLocation );
}

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

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

QStringList arguments;
arguments.append( "map=" + mMapName + "@" + mMapset );
arguments.append( (QString("window=%1,%2,%3,%4,%5,%6")
.arg(viewExtent.xMinimum()).arg(viewExtent.yMinimum())
.arg(viewExtent.xMaximum()).arg(viewExtent.yMaximum())
.arg(pixelWidth).arg(pixelHeight)) );

arguments.append(( QString( "window=%1,%2,%3,%4,%5,%6" )
.arg( viewExtent.xMinimum() ).arg( viewExtent.yMinimum() )
.arg( viewExtent.xMaximum() ).arg( viewExtent.yMaximum() )
.arg( pixelWidth ).arg( pixelHeight ) ) );
QProcess process( this );
QString cmd = QgsApplication::pkgDataPath() + "/grass/modules/qgis.d.rast";
QByteArray data;
try
try
{
data = QgsGrass::runModule ( mGisdbase, mLocation, cmd, arguments );
data = QgsGrass::runModule( mGisdbase, mLocation, cmd, arguments );
}
catch ( QgsGrass::Exception &e )
{
QMessageBox::warning( 0, QObject::tr( "Warning" ), QObject::tr( "Cannot draw raster" ) + "\n"
+ e.what() );
+ e.what() );

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

return image;
}

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

QgsRectangle rect;
rect = QgsGrass::extent ( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster );
rect = QgsGrass::extent( mGisdbase, mLocation, mMapset, mMapName, QgsGrass::Raster );
return rect;
}

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

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

QString QgsGrassRasterProvider::identifyAsText( const QgsPoint& point )
{
return QString ("Not implemented");
return QString( "Not implemented" );
}

QString QgsGrassRasterProvider::identifyAsHtml( const QgsPoint& point )
{
return QString( "Not implemented" );
}

QString QgsGrassRasterProvider::lastErrorTitle()
{
return QString ("Not implemented");
return QString( "Not implemented" );
}

QString QgsGrassRasterProvider::lastError()
{
return QString ("Not implemented");
return QString( "Not implemented" );
}

QString QgsGrassRasterProvider::name() const
{
return PROVIDER_KEY;
}
}

QString QgsGrassRasterProvider::description() const
{
Expand Down
27 changes: 22 additions & 5 deletions src/providers/grass/qgsgrassrasterprovider.h
Expand Up @@ -126,6 +126,23 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
*/
QString identifyAsText( const QgsPoint& point );

/**
* \brief Identify details from a WMS Server from the last screen update
*
* \param point[in] The pixel coordinate (as it was displayed locally on screen)
*
* \return A text document containing the return from the WMS server
*
* \note WMS Servers prefer to receive coordinates in image space, therefore
* this function expects coordinates in that format.
*
* \note The arbitraryness of the returned document is enforced by WMS standards
* up to at least v1.3.0
*
* \note added in 1.5
*/
QString identifyAsHtml( const QgsPoint& point );

/**
* \brief Returns the caption error text for the last error in this provider
*
Expand Down Expand Up @@ -160,12 +177,12 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
*/
QString metadata() { return QString(); }

// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
// Following methods specific for WMS are not used at all in this provider and should be removed IMO from qgsdataprovider.h
void addLayers( QStringList const & layers, QStringList const & styles = QStringList() ) {}
QStringList supportedImageEncodings() { return QStringList();}
QStringList supportedImageEncodings() { return QStringList();}
QString imageEncoding() const { return QString(); }
void setImageEncoding( QString const & mimeType ) {}
void setImageCrs( QString const & crs ) {}
void setImageCrs( QString const & crs ) {}

private:

Expand All @@ -177,8 +194,8 @@ class QgsGrassRasterProvider : public QgsRasterDataProvider
QString mGisdbase; // map gisdabase
QString mLocation; // map location name (not path!)
QString mMapset; // map mapset
QString mMapName; // map name
QString mMapName; // map name

QgsCoordinateReferenceSystem mCrs;
};

Expand Down

0 comments on commit 7cd2c8b

Please sign in to comment.