[QGIS Commit] r15692 - in trunk/qgis/src: app core
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Apr 11 16:01:17 EDT 2011
Author: mhugent
Date: 2011-04-11 13:01:17 -0700 (Mon, 11 Apr 2011)
New Revision: 15692
Modified:
trunk/qgis/src/app/qgsmaptoollabel.cpp
trunk/qgis/src/app/qgsmaptoolmovelabel.cpp
trunk/qgis/src/core/qgslabelsearchtree.cpp
trunk/qgis/src/core/qgslabelsearchtree.h
trunk/qgis/src/core/qgspallabeling.cpp
Log:
Fix label and diagram editing if otf reprojection is enabled (ticket #3685)
Modified: trunk/qgis/src/app/qgsmaptoollabel.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoollabel.cpp 2011-04-10 00:56:17 UTC (rev 15691)
+++ trunk/qgis/src/app/qgsmaptoollabel.cpp 2011-04-11 20:01:17 UTC (rev 15692)
@@ -90,6 +90,15 @@
QgsPoint fixPoint;
if ( rotationPoint( fixPoint ) )
{
+ if ( mCanvas )
+ {
+ QgsMapRenderer* r = mCanvas->mapRenderer();
+ if ( r && r->hasCrsTransformEnabled() )
+ {
+ fixPoint = r->mapToLayerCoordinates( vlayer, fixPoint );
+ }
+ }
+
QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint );
mFixPointRubberBand = new QgsRubberBand( mCanvas, false );
mFixPointRubberBand->setColor( Qt::blue );
Modified: trunk/qgis/src/app/qgsmaptoolmovelabel.cpp
===================================================================
--- trunk/qgis/src/app/qgsmaptoolmovelabel.cpp 2011-04-10 00:56:17 UTC (rev 15691)
+++ trunk/qgis/src/app/qgsmaptoolmovelabel.cpp 2011-04-11 20:01:17 UTC (rev 15692)
@@ -125,10 +125,30 @@
}
else
{
+ //transform to map crs first, because xdiff,ydiff are in map coordinates
+ QgsMapRenderer* r = mCanvas->mapRenderer();
+ if ( r && r->hasCrsTransformEnabled() )
+ {
+ QgsPoint transformedPoint = r->layerToMapCoordinates( vlayer, QgsPoint( xPosOrig, yPosOrig ) );
+ xPosOrig = transformedPoint.x();
+ yPosOrig = transformedPoint.y();
+ }
xPosNew = xPosOrig + xdiff;
yPosNew = yPosOrig + ydiff;
}
+ //transform back to layer crs
+ if ( mCanvas )
+ {
+ QgsMapRenderer* r = mCanvas->mapRenderer();
+ if ( r && r->hasCrsTransformEnabled() )
+ {
+ QgsPoint transformedPoint = r->mapToLayerCoordinates( vlayer, QgsPoint( xPosNew, yPosNew ) );
+ xPosNew = transformedPoint.x();
+ yPosNew = transformedPoint.y();
+ }
+ }
+
vlayer->beginEditCommand( tr( "Label moved" ) );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew, false );
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew, false );
Modified: trunk/qgis/src/core/qgslabelsearchtree.cpp
===================================================================
--- trunk/qgis/src/core/qgslabelsearchtree.cpp 2011-04-10 00:56:17 UTC (rev 15691)
+++ trunk/qgis/src/core/qgslabelsearchtree.cpp 2011-04-11 20:01:17 UTC (rev 15692)
@@ -19,12 +19,22 @@
void QgsLabelSearchTree::label( const QgsPoint& p, QList<QgsLabelPosition*>& posList )
{
- double c_min[2]; c_min[0] = p.x() - 1; c_min[1] = p.y() - 1;
- double c_max[2]; c_max[0] = p.x() + 1; c_max[1] = p.y() + 1;
+ double c_min[2]; c_min[0] = p.x() - 0.1; c_min[1] = p.y() - 0.1;
+ double c_max[2]; c_max[0] = p.x() + 0.1; c_max[1] = p.y() + 0.1;
- mSearchResults.clear();
- mSpatialIndex.Search( c_min, c_max, searchCallback, &mSearchResults );
- posList = mSearchResults;
+ QList<QgsLabelPosition*> searchResults;
+ mSpatialIndex.Search( c_min, c_max, searchCallback, &searchResults );
+
+ //tolerance +-0.1 could be high in case of degree crs, so check if p is really contained in the results
+ posList.clear();
+ QList<QgsLabelPosition*>::const_iterator resultIt = searchResults.constBegin();
+ for ( ; resultIt != searchResults.constEnd(); ++resultIt )
+ {
+ if (( *resultIt )->labelRect.contains( p ) )
+ {
+ posList.push_back( *resultIt );
+ }
+ }
}
bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram )
Modified: trunk/qgis/src/core/qgslabelsearchtree.h
===================================================================
--- trunk/qgis/src/core/qgslabelsearchtree.h 2011-04-10 00:56:17 UTC (rev 15691)
+++ trunk/qgis/src/core/qgslabelsearchtree.h 2011-04-11 20:01:17 UTC (rev 15692)
@@ -48,7 +48,6 @@
private:
RTree<QgsLabelPosition*, double, 2, double> mSpatialIndex;
- QList<QgsLabelPosition*> mSearchResults;
};
#endif // QGSLABELTREE_H
Modified: trunk/qgis/src/core/qgspallabeling.cpp
===================================================================
--- trunk/qgis/src/core/qgspallabeling.cpp 2011-04-10 00:56:17 UTC (rev 15691)
+++ trunk/qgis/src/core/qgspallabeling.cpp 2011-04-11 20:01:17 UTC (rev 15692)
@@ -548,8 +548,16 @@
ydiff = yd;
}
+ //project xPos and yPos from layer to map CRS
+ double z = 0;
+ if ( ct )
+ {
+ ct->transformInPlace( xPos, yPos, z );
+ }
+
yPos += ydiff;
xPos += xdiff;
+
}
}
}
@@ -786,7 +794,7 @@
//convert geom to geos
QgsGeometry* geom = feat.geometry();
- if ( layerIt.value().ct ) // reproject the geometry if necessary
+ if ( layerIt.value().ct && !willUseLayer( layer ) ) // reproject the geometry if feature not already transformed for labeling
{
geom->transform( *( layerIt.value().ct ) );
}
@@ -841,6 +849,15 @@
{
ddPos = false;
}
+ else
+ {
+ const QgsCoordinateTransform* ct = layerIt.value().ct;
+ if ( ct )
+ {
+ double z = 0;
+ ct->transformInPlace( ddPosX, ddPosY, z );
+ }
+ }
}
try
More information about the QGIS-commit
mailing list