mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Fix label map tool crashes and rotation point calc
This commit is contained in:
parent
77c06b1d7e
commit
621dcce4d9
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user