mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-17 00:04:02 -04:00
fix #4521
This commit is contained in:
parent
db164dfbb7
commit
45474ac7dc
@ -50,14 +50,13 @@ class MarkerErrorGeometry():
|
||||
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:
|
||||
@ -136,18 +135,12 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
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 )
|
||||
@ -160,9 +153,7 @@ class ValidateDialog( QDialog, Ui_Dialog ):
|
||||
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
|
||||
|
@ -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();
|
||||
|
||||
@ -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 )
|
||||
{
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <qgsvectordataprovider.h>
|
||||
#include <qgsvectorlayer.h>
|
||||
#include <qgsfield.h>
|
||||
#include <qgscoordinatetransform.h>
|
||||
|
||||
// Qt includes
|
||||
#include <QPoint>
|
||||
@ -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();
|
||||
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
|
||||
if ( !vlayer )
|
||||
return "";
|
||||
|
||||
// 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 setting for the search radius from user preferences, if it exists
|
||||
QSettings settings;
|
||||
double identifyValue = settings.value( "/Map/identifyRadius", QGis::DEFAULT_IDENTIFY_RADIUS ).toDouble();
|
||||
|
||||
// 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 )
|
||||
{
|
||||
// create the search rectangle
|
||||
double searchRadius = mpMapCanvas->extent().width() * ( identifyValue / 100.0 );
|
||||
|
||||
if ( fields[it.key()].name() == fieldIndex )
|
||||
{
|
||||
maptipText = it->toString();
|
||||
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 );
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
// return the map tip
|
||||
return maptipText;
|
||||
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();
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user