mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Don't limit label distances to postive values
Sometimes it's useful to have negative distances, as a 0 distance can still be quite far from line features for some font families.
This commit is contained in:
parent
0458e08c99
commit
3cb3676329
@ -192,7 +192,7 @@ void QgsPalLayerSettings::initPropertyDefinitions()
|
||||
},
|
||||
{ QgsPalLayerSettings::OffsetXY, QgsPropertyDefinition( "OffsetXY", QObject::tr( "Offset" ), QgsPropertyDefinition::Offset, origin ) },
|
||||
{ QgsPalLayerSettings::OffsetUnits, QgsPropertyDefinition( "OffsetUnits", QObject::tr( "Offset units" ), QgsPropertyDefinition::RenderUnits, origin ) },
|
||||
{ QgsPalLayerSettings::LabelDistance, QgsPropertyDefinition( "LabelDistance", QObject::tr( "Label distance" ), QgsPropertyDefinition::DoublePositive, origin ) },
|
||||
{ QgsPalLayerSettings::LabelDistance, QgsPropertyDefinition( "LabelDistance", QObject::tr( "Label distance" ), QgsPropertyDefinition::Double, origin ) },
|
||||
{ QgsPalLayerSettings::DistanceUnits, QgsPropertyDefinition( "DistanceUnits", QObject::tr( "Label distance units" ), QgsPropertyDefinition::RenderUnits, origin ) },
|
||||
{ QgsPalLayerSettings::OffsetRotation, QgsPropertyDefinition( "OffsetRotation", QObject::tr( "Offset rotation" ), QgsPropertyDefinition::Rotation, origin ) },
|
||||
{ QgsPalLayerSettings::CurvedCharAngleInOut, QgsPropertyDefinition( "CurvedCharAngleInOut", QgsPropertyDefinition::DataTypeString, QObject::tr( "Curved character angles" ), QObject::tr( "double coord [<b>in,out</b> as 20.0-60.0,20.0-95.0]" ), origin ) },
|
||||
@ -2069,7 +2069,7 @@ void QgsPalLayerSettings::registerFeature( const QgsFeature &f, QgsRenderContext
|
||||
// candidates are created just offset from a border and avoids candidates being incorrectly flagged as colliding with neighbours
|
||||
if ( placement == QgsPalLayerSettings::Line || placement == QgsPalLayerSettings::Curved || placement == QgsPalLayerSettings::PerimeterCurved )
|
||||
{
|
||||
distance = std::max( distance, 1.0 );
|
||||
distance = ( distance < 0 ? -1 : 1 ) * std::max( std::fabs( distance ), 1.0 );
|
||||
}
|
||||
|
||||
if ( !qgsDoubleNear( distance, 0.0 ) )
|
||||
|
@ -150,6 +150,7 @@ void QgsTextFormatWidget::initWidget()
|
||||
mFontLetterSpacingSpinBox->setClearValue( 0.0 );
|
||||
mFontWordSpacingSpinBox->setClearValue( 0.0 );
|
||||
mZIndexSpinBox->setClearValue( 0.0 );
|
||||
mLineDistanceSpnBx->setClearValue( 0.0 );
|
||||
|
||||
mObstacleTypeComboBox->addItem( tr( "Over the feature's interior" ), QgsPalLayerSettings::PolygonInterior );
|
||||
mObstacleTypeComboBox->addItem( tr( "Over the feature's boundary" ), QgsPalLayerSettings::PolygonBoundary );
|
||||
|
@ -4142,6 +4142,9 @@ font-style: italic;</string>
|
||||
<property name="decimals">
|
||||
<number>4</number>
|
||||
</property>
|
||||
<property name="minimum">
|
||||
<double>-999999999.000000000000000</double>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<double>999999999.000000000000000</double>
|
||||
</property>
|
||||
|
@ -57,6 +57,7 @@ class TestQgsLabelingEngine : public QObject
|
||||
void testMergingLinesWithForks();
|
||||
void testCurvedLabelsWithTinySegments();
|
||||
void testCurvedLabelCorrectLinePlacement();
|
||||
void testCurvedLabelNegativeDistance();
|
||||
void testLabelBoundary();
|
||||
void testLabelBlockingRegion();
|
||||
void testLabelRotationWithReprojection();
|
||||
@ -1104,6 +1105,58 @@ void TestQgsLabelingEngine::testCurvedLabelCorrectLinePlacement()
|
||||
QVERIFY( imageCheck( QStringLiteral( "label_curved_label_below_1" ), img, 20 ) );
|
||||
}
|
||||
|
||||
void TestQgsLabelingEngine::testCurvedLabelNegativeDistance()
|
||||
{
|
||||
// test line label rendering with negative distance
|
||||
QgsPalLayerSettings settings;
|
||||
setDefaultLabelParams( settings );
|
||||
|
||||
QgsTextFormat format = settings.format();
|
||||
format.setSize( 20 );
|
||||
format.setColor( QColor( 0, 0, 0 ) );
|
||||
settings.setFormat( format );
|
||||
|
||||
settings.fieldName = QStringLiteral( "'XXXXXXXXXXXXXXXXXXXXXXXXXX'" );
|
||||
settings.isExpression = true;
|
||||
settings.placement = QgsPalLayerSettings::Curved;
|
||||
settings.labelPerPart = false;
|
||||
settings.dist = -5;
|
||||
|
||||
std::unique_ptr< QgsVectorLayer> vl2( new QgsVectorLayer( QStringLiteral( "LineString?crs=epsg:3946&field=id:integer" ), QStringLiteral( "vl" ), QStringLiteral( "memory" ) ) );
|
||||
vl2->setRenderer( new QgsNullSymbolRenderer() );
|
||||
|
||||
QgsFeature f;
|
||||
f.setAttributes( QgsAttributes() << 1 );
|
||||
f.setGeometry( QgsGeometry::fromWkt( QStringLiteral( "LineString (190000 5000010, 190100 5000000, 190200 5000000)" ) ) );
|
||||
QVERIFY( vl2->dataProvider()->addFeature( f ) );
|
||||
|
||||
vl2->setLabeling( new QgsVectorLayerSimpleLabeling( settings ) ); // TODO: this should not be necessary!
|
||||
vl2->setLabelsEnabled( true );
|
||||
|
||||
// make a fake render context
|
||||
QSize size( 640, 480 );
|
||||
QgsMapSettings mapSettings;
|
||||
mapSettings.setDestinationCrs( vl2->crs() );
|
||||
|
||||
mapSettings.setOutputSize( size );
|
||||
mapSettings.setExtent( f.geometry().boundingBox() );
|
||||
mapSettings.setLayers( QList<QgsMapLayer *>() << vl2.get() );
|
||||
mapSettings.setOutputDpi( 96 );
|
||||
|
||||
QgsLabelingEngineSettings engineSettings = mapSettings.labelingEngineSettings();
|
||||
engineSettings.setFlag( QgsLabelingEngineSettings::UsePartialCandidates, false );
|
||||
engineSettings.setFlag( QgsLabelingEngineSettings::DrawLabelRectOnly, true );
|
||||
//engineSettings.setFlag( QgsLabelingEngineSettings::DrawCandidates, true );
|
||||
mapSettings.setLabelingEngineSettings( engineSettings );
|
||||
|
||||
QgsMapRendererSequentialJob job( mapSettings );
|
||||
job.start();
|
||||
job.waitForFinished();
|
||||
|
||||
QImage img = job.renderedImage();
|
||||
QVERIFY( imageCheck( QStringLiteral( "label_curved_negative_distance" ), img, 20 ) );
|
||||
}
|
||||
|
||||
void TestQgsLabelingEngine::testLabelBoundary()
|
||||
{
|
||||
// test that no labels are drawn outside of the specified label boundary
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Loading…
x
Reference in New Issue
Block a user