Skip to content

Commit

Permalink
fix #4521
Browse files Browse the repository at this point in the history
  • Loading branch information
jef-n committed May 25, 2012
1 parent db164df commit 45474ac
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 81 deletions.
21 changes: 6 additions & 15 deletions python/plugins/fTools/tools/doValidate.py
Expand Up @@ -50,14 +50,13 @@ def __createMarker(self, point):
self.__marker.setIconType(gui.QgsVertexMarker.ICON_X)
self.__marker.setPenWidth(3)

def setGeom(self, x, y):
def setGeom(self, p):
if not self.__marker is None:
self.reset()
point = QgsPoint(x, y)
if self.__marker is None:
self.__createMarker(point)
self.__createMarker(p)
else:
self.__marker.setCenter(point)
self.__marker.setCenter(p)

def reset(self):
if not self.__marker is None:
Expand Down Expand Up @@ -136,18 +135,12 @@ def zoomToError(self, curr, prev):
mc = self.iface.mapCanvas()
mc.zoomToPreviousExtent()

if mc.mapRenderer().hasCrsTransformEnabled():
ct = QgsCoordinateTransform( self.vlayer.crs(), mc.mapRenderer().destinationCrs() )
else:
ct = None

e = item.data(Qt.UserRole).toPyObject()

if type(e)==QgsPoint:
if not ct is None:
e = ct.transform( e )
e = mc.mapRenderer().layerToMapCoordinates( self.vlayer, e )

self.marker.setGeom(e.x(), e.y())
self.marker.setGeom(e)

rect = mc.extent()
rect.expand( 0.25, e )
Expand All @@ -160,9 +153,7 @@ def zoomToError(self, curr, prev):
if not ok or not self.vlayer.featureAtId( fid, ft, True):
return

rect = ft.geometry().boundingBox()
if not ct is None:
rect = ct.transformBoundingBox( rect )
rect = mc.mapRenderer().layerExtentToOutputExtent( self.vlayer, ft.geometry().boundingBox() )
rect.expand(1.05)

# Set the extent to our new rectangle
Expand Down
4 changes: 1 addition & 3 deletions src/app/qgisapp.cpp
Expand Up @@ -6176,10 +6176,9 @@ void QgisApp::showStatusMessage( QString theMessage )
statusBar()->showMessage( theMessage );
}

// Show the maptip using tooltip
void QgisApp::showMapTip()

{
/* Show the maptip using tooltip */
// Stop the timer while we look for a maptip
mpMapTipsTimer->stop();

Expand All @@ -6189,7 +6188,6 @@ void QgisApp::showMapTip()
QPoint myPointerPos = mMapCanvas->mouseLastXY();

// Make sure there is an active layer before proceeding

QgsMapLayer* mypLayer = mMapCanvas->currentLayer();
if ( mypLayer )
{
Expand Down
105 changes: 42 additions & 63 deletions src/gui/qgsmaptip.cpp
Expand Up @@ -18,6 +18,7 @@
#include <qgsvectordataprovider.h>
#include <qgsvectorlayer.h>
#include <qgsfield.h>
#include <qgscoordinatetransform.h>

// Qt includes
#include <QPoint>
Expand Down Expand Up @@ -52,79 +53,57 @@ void QgsMapTip::showMapTip( QgsMapLayer * thepLayer,

// Show the maptip on the canvas
QString myTipText = fetchFeature( thepLayer, theMapPosition, thepMapCanvas );
if ( myTipText.length() > 0 )
mMapTipVisible = !myTipText.isEmpty();

if ( mMapTipVisible )
{
mMapTipVisible = true;
QToolTip::showText( thepMapCanvas->mapToGlobal( thePixelPosition ), myTipText, thepMapCanvas );
// store the point so we can use it to clear the maptip later
mLastPosition = thePixelPosition;
}
else
{
mMapTipVisible = false;
}

}

void QgsMapTip::clear( QgsMapCanvas *mpMapCanvas )
{
if ( mMapTipVisible )
{
// set the maptip to blank
QToolTip::showText( mpMapCanvas->mapToGlobal( mLastPosition ), "", mpMapCanvas );
// reset the visible flag
mMapTipVisible = false;
}
if ( !mMapTipVisible )
return;

// set the maptip to blank
QToolTip::showText( mpMapCanvas->mapToGlobal( mLastPosition ), "", mpMapCanvas );
// reset the visible flag
mMapTipVisible = false;
}

QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint & mapPosition, QgsMapCanvas *mpMapCanvas )
QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPoint &mapPosition, QgsMapCanvas *mpMapCanvas )
{
// Default return value
QString maptipText = "";
// Protection just in case we get passed a null layer
if ( layer )
{
// Get the setting for the search radius from user preferences, if it exists
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

// create the search rectangle
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );
QgsRectangle r;
r.setXMinimum( mapPosition.x() - searchRadius );
r.setXMaximum( mapPosition.x() + searchRadius );
r.setYMinimum( mapPosition.y() - searchRadius );
r.setYMaximum( mapPosition.y() + searchRadius );

// Get the data provider
QgsVectorDataProvider* dataProvider = qobject_cast<QgsVectorLayer *>( layer )->dataProvider();
// Fetch the attribute list for the layer
QgsAttributeList allAttributes = dataProvider->attributeIndexes();
// Select all attributes within the search radius
dataProvider->select( allAttributes, r, true, true );
// Feature to hold the results of the fetch
QgsFeature feature;
// Get the field list for the layer
const QgsFieldMap& fields = dataProvider->fields();
// Get the label (display) field for the layer
QString fieldIndex = qobject_cast<QgsVectorLayer *>( layer )->displayField();
if ( dataProvider->nextFeature( feature ) )
{
// if we get a feature, pull out the display field and set the maptip text to its value
QgsAttributeMap attributes = feature.attributeMap();
for ( QgsAttributeMap::const_iterator it = attributes.begin(); it != attributes.end(); ++it )
{

if ( fields[it.key()].name() == fieldIndex )
{
maptipText = it->toString();

}

}
}
}
// return the map tip
return maptipText;
}
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( !vlayer )
return "";

// Get the setting for the search radius from user preferences, if it exists
QSettings settings;
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();

// create the search rectangle
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );

QgsRectangle r;
r.setXMinimum( mapPosition.x() - searchRadius );
r.setYMinimum( mapPosition.y() - searchRadius );
r.setXMaximum( mapPosition.x() + searchRadius );
r.setYMaximum( mapPosition.y() + searchRadius );

r = mpMapCanvas->mapRenderer()->mapToLayerCoordinates( layer, r );

int idx = vlayer->fieldNameIndex( vlayer->displayField() );
if ( idx < 0 )
return "";

QgsFeature feature;

vlayer->select( QgsAttributeList() << idx, r, true, true );
if ( !vlayer->nextFeature( feature ) )
return "";

return feature.attributeMap().value( idx, "" ).toString();
}

0 comments on commit 45474ac

Please sign in to comment.