Skip to content

Commit

Permalink
Fix label map tool crashes and rotation point calc
Browse files Browse the repository at this point in the history
  • Loading branch information
dakcarto committed Mar 12, 2014
1 parent 77c06b1 commit 621dcce
Showing 1 changed file with 19 additions and 24 deletions.
43 changes: 19 additions & 24 deletions src/app/qgsmaptoollabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down

0 comments on commit 621dcce

Please sign in to comment.