Skip to content

Commit 54f3321

Browse files
author
mhugent
committed
Fix label and diagram editing if otf reprojection is enabled (ticket #3685)
git-svn-id: http://svn.osgeo.org/qgis/trunk@15692 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent afa4214 commit 54f3321

5 files changed

+62
-7
lines changed

src/app/qgsmaptoollabel.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@ void QgsMapToolLabel::createRubberBands( )
9090
QgsPoint fixPoint;
9191
if ( rotationPoint( fixPoint ) )
9292
{
93+
if ( mCanvas )
94+
{
95+
QgsMapRenderer* r = mCanvas->mapRenderer();
96+
if ( r && r->hasCrsTransformEnabled() )
97+
{
98+
fixPoint = r->mapToLayerCoordinates( vlayer, fixPoint );
99+
}
100+
}
101+
93102
QgsGeometry* pointGeom = QgsGeometry::fromPoint( fixPoint );
94103
mFixPointRubberBand = new QgsRubberBand( mCanvas, false );
95104
mFixPointRubberBand->setColor( Qt::blue );

src/app/qgsmaptoolmovelabel.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,30 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
125125
}
126126
else
127127
{
128+
//transform to map crs first, because xdiff,ydiff are in map coordinates
129+
QgsMapRenderer* r = mCanvas->mapRenderer();
130+
if ( r && r->hasCrsTransformEnabled() )
131+
{
132+
QgsPoint transformedPoint = r->layerToMapCoordinates( vlayer, QgsPoint( xPosOrig, yPosOrig ) );
133+
xPosOrig = transformedPoint.x();
134+
yPosOrig = transformedPoint.y();
135+
}
128136
xPosNew = xPosOrig + xdiff;
129137
yPosNew = yPosOrig + ydiff;
130138
}
131139

140+
//transform back to layer crs
141+
if ( mCanvas )
142+
{
143+
QgsMapRenderer* r = mCanvas->mapRenderer();
144+
if ( r && r->hasCrsTransformEnabled() )
145+
{
146+
QgsPoint transformedPoint = r->mapToLayerCoordinates( vlayer, QgsPoint( xPosNew, yPosNew ) );
147+
xPosNew = transformedPoint.x();
148+
yPosNew = transformedPoint.y();
149+
}
150+
}
151+
132152
vlayer->beginEditCommand( tr( "Label moved" ) );
133153
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, xCol, xPosNew, false );
134154
vlayer->changeAttributeValue( mCurrentLabelPos.featureId, yCol, yPosNew, false );

src/core/qgslabelsearchtree.cpp

+15-5
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,22 @@ QgsLabelSearchTree::~QgsLabelSearchTree()
1919

2020
void QgsLabelSearchTree::label( const QgsPoint& p, QList<QgsLabelPosition*>& posList )
2121
{
22-
double c_min[2]; c_min[0] = p.x() - 1; c_min[1] = p.y() - 1;
23-
double c_max[2]; c_max[0] = p.x() + 1; c_max[1] = p.y() + 1;
22+
double c_min[2]; c_min[0] = p.x() - 0.1; c_min[1] = p.y() - 0.1;
23+
double c_max[2]; c_max[0] = p.x() + 0.1; c_max[1] = p.y() + 0.1;
2424

25-
mSearchResults.clear();
26-
mSpatialIndex.Search( c_min, c_max, searchCallback, &mSearchResults );
27-
posList = mSearchResults;
25+
QList<QgsLabelPosition*> searchResults;
26+
mSpatialIndex.Search( c_min, c_max, searchCallback, &searchResults );
27+
28+
//tolerance +-0.1 could be high in case of degree crs, so check if p is really contained in the results
29+
posList.clear();
30+
QList<QgsLabelPosition*>::const_iterator resultIt = searchResults.constBegin();
31+
for ( ; resultIt != searchResults.constEnd(); ++resultIt )
32+
{
33+
if (( *resultIt )->labelRect.contains( p ) )
34+
{
35+
posList.push_back( *resultIt );
36+
}
37+
}
2838
}
2939

3040
bool QgsLabelSearchTree::insertLabel( LabelPosition* labelPos, int featureId, const QString& layerName, bool diagram )

src/core/qgslabelsearchtree.h

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ class CORE_EXPORT QgsLabelSearchTree
4848

4949
private:
5050
RTree<QgsLabelPosition*, double, 2, double> mSpatialIndex;
51-
QList<QgsLabelPosition*> mSearchResults;
5251
};
5352

5453
#endif // QGSLABELTREE_H

src/core/qgspallabeling.cpp

+18-1
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,16 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
548548
ydiff = yd;
549549
}
550550

551+
//project xPos and yPos from layer to map CRS
552+
double z = 0;
553+
if ( ct )
554+
{
555+
ct->transformInPlace( xPos, yPos, z );
556+
}
557+
551558
yPos += ydiff;
552559
xPos += xdiff;
560+
553561
}
554562
}
555563
}
@@ -786,7 +794,7 @@ void QgsPalLabeling::registerDiagramFeature( QgsVectorLayer* layer, QgsFeature&
786794
//convert geom to geos
787795
QgsGeometry* geom = feat.geometry();
788796

789-
if ( layerIt.value().ct ) // reproject the geometry if necessary
797+
if ( layerIt.value().ct && !willUseLayer( layer ) ) // reproject the geometry if feature not already transformed for labeling
790798
{
791799
geom->transform( *( layerIt.value().ct ) );
792800
}
@@ -841,6 +849,15 @@ void QgsPalLabeling::registerDiagramFeature( QgsVectorLayer* layer, QgsFeature&
841849
{
842850
ddPos = false;
843851
}
852+
else
853+
{
854+
const QgsCoordinateTransform* ct = layerIt.value().ct;
855+
if ( ct )
856+
{
857+
double z = 0;
858+
ct->transformInPlace( ddPosX, ddPosY, z );
859+
}
860+
}
844861
}
845862

846863
try

0 commit comments

Comments
 (0)