Skip to content

Commit 621dcce

Browse files
committed
Fix label map tool crashes and rotation point calc
1 parent 77c06b1 commit 621dcce

File tree

1 file changed

+19
-24
lines changed

1 file changed

+19
-24
lines changed

src/app/qgsmaptoollabel.cpp

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,16 @@ QgsPalLayerSettings& QgsMapToolLabel::currentLabelSettings( bool* ok )
131131
QgsVectorLayer* vlayer = currentLayer();
132132
if ( vlayer )
133133
{
134-
if ( vlayer == mCurrentLayer )
135-
return mCurrentSettings;
136-
137-
mCurrentLayer = vlayer;
138-
mCurrentSettings = QgsPalLayerSettings::fromLayer( vlayer );
134+
if ( vlayer != mCurrentLayer )
135+
{
136+
mCurrentLayer = vlayer;
137+
mCurrentSettings = QgsPalLayerSettings::fromLayer( vlayer );
138+
}
139139

140140
if ( ok )
141+
{
141142
*ok = true;
143+
}
142144

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

338340
if ( mCurrentLabelPos.upsideDown && !ignoreUpsideDown )
339341
{
340-
pos = mCurrentLabelPos.cornerPoints.at( 2 );
342+
pos = cornerPoints.at( 2 );
341343
}
342344
else
343345
{
344-
pos = mCurrentLabelPos.cornerPoints.at( 0 );
346+
pos = cornerPoints.at( 0 );
345347
}
346348

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

369-
//label text?
370-
QString labelText = currentLabelText();
371-
372-
bool labelSettingsOk;
373-
QgsPalLayerSettings& labelSettings = currentLabelSettings( &labelSettingsOk );
374-
if ( !labelSettingsOk )
375-
{
376-
return false;
377-
}
378-
379-
double labelSizeX, labelSizeY;
380-
QgsFeature f;
381-
if ( !currentFeature( f ) )
382-
{
383-
return false;
384-
}
385-
labelSettings.calculateLabelSize( &labelFontMetrics, labelText, labelSizeX, labelSizeY, &f );
371+
// NOTE: this assumes the label corner points comprise a rectangle and that the
372+
// CRS supports equidistant measurements to accurately determine hypotenuse
373+
QgsPoint cp_0 = cornerPoints.at( 0 );
374+
QgsPoint cp_1 = cornerPoints.at( 1 );
375+
QgsPoint cp_3 = cornerPoints.at( 3 );
376+
// QgsDebugMsg( QString( "cp_0: x=%1, y=%2" ).arg( cp_0.x() ).arg( cp_0.y() ) );
377+
// QgsDebugMsg( QString( "cp_1: x=%1, y=%2" ).arg( cp_1.x() ).arg( cp_1.y() ) );
378+
// QgsDebugMsg( QString( "cp_3: x=%1, y=%2" ).arg( cp_3.x() ).arg( cp_3.y() ) );
379+
double labelSizeX = qSqrt( cp_0.sqrDist( cp_1 ) );
380+
double labelSizeY = qSqrt( cp_0.sqrDist( cp_3 ) );
386381

387382
double xdiff = 0;
388383
double ydiff = 0;

0 commit comments

Comments
 (0)