Skip to content
Permalink
Browse files

Fix label map tool crashes and rotation point calc

  • Loading branch information
dakcarto committed Mar 12, 2014
1 parent 77c06b1 commit 621dcce4d956b8b7bc51a7353e91953cd807dbd4
Showing with 19 additions and 24 deletions.
  1. +19 −24 src/app/qgsmaptoollabel.cpp
@@ -131,14 +131,16 @@ QgsPalLayerSettings& QgsMapToolLabel::currentLabelSettings( bool* ok )
QgsVectorLayer* vlayer = currentLayer();
if ( vlayer )
{
if ( vlayer == mCurrentLayer )
return mCurrentSettings;

mCurrentLayer = vlayer;
mCurrentSettings = QgsPalLayerSettings::fromLayer( vlayer );
if ( vlayer != mCurrentLayer )
{
mCurrentLayer = vlayer;
mCurrentSettings = QgsPalLayerSettings::fromLayer( vlayer );
}

if ( ok )
{
*ok = true;
}

return mCurrentSettings;
}
@@ -337,11 +339,11 @@ bool QgsMapToolLabel::rotationPoint( QgsPoint& pos, bool ignoreUpsideDown, bool

if ( mCurrentLabelPos.upsideDown && !ignoreUpsideDown )
{
pos = mCurrentLabelPos.cornerPoints.at( 2 );
pos = cornerPoints.at( 2 );
}
else
{
pos = mCurrentLabelPos.cornerPoints.at( 0 );
pos = cornerPoints.at( 0 );
}

//alignment always center/center and rotation 0 for diagrams
@@ -366,23 +368,16 @@ bool QgsMapToolLabel::rotationPoint( QgsPoint& pos, bool ignoreUpsideDown, bool
// QFont labelFont = labelFontCurrentFeature();
QFontMetricsF labelFontMetrics( mCurrentLabelPos.labelFont );

//label text?
QString labelText = currentLabelText();

bool labelSettingsOk;
QgsPalLayerSettings& labelSettings = currentLabelSettings( &labelSettingsOk );
if ( !labelSettingsOk )
{
return false;
}

double labelSizeX, labelSizeY;
QgsFeature f;
if ( !currentFeature( f ) )
{
return false;
}
labelSettings.calculateLabelSize( &labelFontMetrics, labelText, labelSizeX, labelSizeY, &f );
// NOTE: this assumes the label corner points comprise a rectangle and that the
// CRS supports equidistant measurements to accurately determine hypotenuse
QgsPoint cp_0 = cornerPoints.at( 0 );
QgsPoint cp_1 = cornerPoints.at( 1 );
QgsPoint cp_3 = cornerPoints.at( 3 );
// QgsDebugMsg( QString( "cp_0: x=%1, y=%2" ).arg( cp_0.x() ).arg( cp_0.y() ) );
// QgsDebugMsg( QString( "cp_1: x=%1, y=%2" ).arg( cp_1.x() ).arg( cp_1.y() ) );
// QgsDebugMsg( QString( "cp_3: x=%1, y=%2" ).arg( cp_3.x() ).arg( cp_3.y() ) );
double labelSizeX = qSqrt( cp_0.sqrDist( cp_1 ) );
double labelSizeY = qSqrt( cp_0.sqrDist( cp_3 ) );

double xdiff = 0;
double ydiff = 0;

0 comments on commit 621dcce

Please sign in to comment.
You can’t perform that action at this time.