Skip to content
Permalink
Browse files
Fix label and diagram editing if otf reprojection is enabled (ticket #…
…3685)

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@15692 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 11, 2011
1 parent 534d1e3 commit 8bc07a5fbdbd6f56f27af9ddcff545b84fd9445b
@@ -90,6 +90,15 @@ void QgsMapToolLabel::createRubberBands( )
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 );
@@ -125,10 +125,30 @@ void QgsMapToolMoveLabel::canvasReleaseEvent( QMouseEvent * e )
}
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 );
@@ -19,12 +19,22 @@ QgsLabelSearchTree::~QgsLabelSearchTree()

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 )
@@ -48,7 +48,6 @@ class CORE_EXPORT QgsLabelSearchTree

private:
RTree<QgsLabelPosition*, double, 2, double> mSpatialIndex;
QList<QgsLabelPosition*> mSearchResults;
};

#endif // QGSLABELTREE_H
@@ -548,8 +548,16 @@ void QgsPalLayerSettings::registerFeature( QgsFeature& f, const QgsRenderContext
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 @@ void QgsPalLabeling::registerDiagramFeature( QgsVectorLayer* layer, QgsFeature&
//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 @@ void QgsPalLabeling::registerDiagramFeature( QgsVectorLayer* layer, QgsFeature&
{
ddPos = false;
}
else
{
const QgsCoordinateTransform* ct = layerIt.value().ct;
if ( ct )
{
double z = 0;
ct->transformInPlace( ddPosX, ddPosY, z );
}
}
}

try

0 comments on commit 8bc07a5

Please sign in to comment.