Skip to content
Permalink
Browse files

Add quadrant, offset, rotation for points/centroids in adv labeling

- Possible fix for #4634, #5256, #6162
- Uses GEOS to convert centroids to points before PAL solution

- Implements #3492, #6285
- Convert PAL layer types 'over point/centroid' to 'offset from point/centroid'
- Add quadrant offsets (above/below/right, etc. like in old labeling)
- Add x and y offset, in mm or map unit, in addition to quadrant
- Default for offset is set to map units (mm scales oddly with zoom)

- Implements #4517, #6118; updates fix for #4317
- Rotation is independent of data defined columns
- Rotation bounding box included in offset calculation
- GUI spin box range set from -360 to +360 for initial dev testing

- Keep from scaling letter/word spacing if set to 0
  • Loading branch information
dakcarto committed Sep 3, 2012
1 parent 5a0d2f5 commit 61a50225ee196bb1c70ab15cc041bcbd25b7d03a
Showing with 456 additions and 20 deletions.
  1. +65 −1 src/app/qgslabelinggui.cpp
  2. +5 −0 src/app/qgslabelinggui.h
  3. +171 −5 src/core/qgspallabeling.cpp
  4. +6 −0 src/core/qgspallabeling.h
  5. +209 −14 src/ui/qgslabelingguibase.ui
@@ -97,18 +97,36 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM

// placement
int distUnitIndex = lyr.distInMapUnits ? 1 : 0;
mXQuadOffset = lyr.xQuadOffset;
mYQuadOffset = lyr.yQuadOffset;
switch ( lyr.placement )
{
case QgsPalLayerSettings::AroundPoint:
radAroundPoint->setChecked( true );
radAroundCentroid->setChecked( true );
spinDistPoint->setValue( lyr.dist );
mPointDistanceUnitComboBox->setCurrentIndex( distUnitIndex );
//spinAngle->setValue(lyr.angle);
//spinAngle->setValue( lyr.angle );
break;
case QgsPalLayerSettings::OverPoint:
radOverPoint->setChecked( true );
radOverCentroid->setChecked( true );

mPointOffsetRadioAboveLeft->setChecked( mXQuadOffset == -1 && mYQuadOffset == 1 );
mPointOffsetRadioAbove->setChecked( mXQuadOffset == 0 && mYQuadOffset == 1 );
mPointOffsetRadioAboveRight->setChecked( mXQuadOffset == 1 && mYQuadOffset == 1 );
mPointOffsetRadioLeft->setChecked( mXQuadOffset == -1 && mYQuadOffset == 0 );
mPointOffsetRadioOver->setChecked( mXQuadOffset == 0 && mYQuadOffset == 0 );
mPointOffsetRadioRight->setChecked( mXQuadOffset == 1 && mYQuadOffset == 0 );
mPointOffsetRadioBelowLeft->setChecked( mXQuadOffset == -1 && mYQuadOffset == -1 );
mPointOffsetRadioBelow->setChecked( mXQuadOffset == 0 && mYQuadOffset == -1 );
mPointOffsetRadioBelowRight->setChecked( mXQuadOffset == 1 && mYQuadOffset == -1 );

mPointOffsetXOffsetSpinBox->setValue( lyr.xOffset );
mPointOffsetYOffsetSpinBox->setValue( lyr.yOffset );
mPointOffsetUnitsComboBox->setCurrentIndex( lyr.labelOffsetInMapUnits ? 1 : 0 );
mPointOffsetAngleSpinBox->setValue( lyr.angleOffset );

break;
case QgsPalLayerSettings::Line:
radLineParallel->setChecked( true );
@@ -231,6 +249,18 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
{
connect( placementRadios[i], SIGNAL( toggled( bool ) ), this, SLOT( updateOptions() ) );
}

// setup connections for label quadrant offsets
QRadioButton* quadrantRadios[] =
{
mPointOffsetRadioAboveLeft, mPointOffsetRadioAbove, mPointOffsetRadioAboveRight,
mPointOffsetRadioLeft, mPointOffsetRadioOver, mPointOffsetRadioRight,
mPointOffsetRadioBelowLeft, mPointOffsetRadioBelow, mPointOffsetRadioBelowRight
};
for ( unsigned int i = 0; i < sizeof( quadrantRadios ) / sizeof( QRadioButton* ); i++ )
{
connect( quadrantRadios[i], SIGNAL( toggled( bool ) ), this, SLOT( updateQuadrant() ) );
}
}

QgsLabelingGui::~QgsLabelingGui()
@@ -270,6 +300,13 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
|| ( stackedPlacement->currentWidget() == pagePolygon && radOverCentroid->isChecked() ) )
{
lyr.placement = QgsPalLayerSettings::OverPoint;

lyr.xQuadOffset = mXQuadOffset;
lyr.yQuadOffset = mYQuadOffset;
lyr.xOffset = mPointOffsetXOffsetSpinBox->value();
lyr.yOffset = mPointOffsetYOffsetSpinBox->value();
lyr.labelOffsetInMapUnits = ( mPointOffsetUnitsComboBox->currentIndex() == 1 );
lyr.angleOffset = mPointOffsetAngleSpinBox->value();
}
else if (( stackedPlacement->currentWidget() == pageLine && radLineParallel->isChecked() )
|| ( stackedPlacement->currentWidget() == pagePolygon && radPolygonPerimeter->isChecked() )
@@ -779,6 +816,11 @@ void QgsLabelingGui::updateOptions()
{
stackedOptions->setCurrentWidget( pageOptionsPoint );
}
else if (( stackedPlacement->currentWidget() == pagePoint && radOverPoint->isChecked() )
|| ( stackedPlacement->currentWidget() == pagePolygon && radOverCentroid->isChecked() ) )
{
stackedOptions->setCurrentWidget( pageOptionsPointOffset );
}
else if (( stackedPlacement->currentWidget() == pageLine && radLineParallel->isChecked() )
|| ( stackedPlacement->currentWidget() == pagePolygon && radPolygonPerimeter->isChecked() )
|| ( stackedPlacement->currentWidget() == pageLine && radLineCurved->isChecked() ) )
@@ -791,6 +833,21 @@ void QgsLabelingGui::updateOptions()
}
}

void QgsLabelingGui::updateQuadrant()
{
if ( mPointOffsetRadioAboveLeft->isChecked() ) { mXQuadOffset = -1; mYQuadOffset = 1; };
if ( mPointOffsetRadioAbove->isChecked() ) { mXQuadOffset = 0; mYQuadOffset = 1; };
if ( mPointOffsetRadioAboveRight->isChecked() ) { mXQuadOffset = 1; mYQuadOffset = 1; };

if ( mPointOffsetRadioLeft->isChecked() ) { mXQuadOffset = -1; mYQuadOffset = 0; };
if ( mPointOffsetRadioOver->isChecked() ) { mXQuadOffset = 0; mYQuadOffset = 0; };
if ( mPointOffsetRadioRight->isChecked() ) { mXQuadOffset = 1; mYQuadOffset = 0; };

if ( mPointOffsetRadioBelowLeft->isChecked() ) { mXQuadOffset = -1; mYQuadOffset = -1; };
if ( mPointOffsetRadioBelow->isChecked() ) { mXQuadOffset = 0; mYQuadOffset = -1; };
if ( mPointOffsetRadioBelowRight->isChecked() ) { mXQuadOffset = 1; mYQuadOffset = -1; };
}

void QgsLabelingGui::populateFontCapitalsComboBox()
{
mFontCapitalsComboBox->addItem( tr( "Mixed Case" ), QVariant( 0 ) );
@@ -877,6 +934,13 @@ void QgsLabelingGui::on_mBufferUnitComboBox_currentIndexChanged( int index )
updateFont( mRefFont );
}

void QgsLabelingGui::on_mPointOffsetUnitsComboBox_currentIndexChanged( int index )
{
double singleStep = ( index == 1 ) ? 1.0 : 0.1 ; //1.0 for map units, 0.1 for mm
mPointOffsetXOffsetSpinBox->setSingleStep( singleStep );
mPointOffsetYOffsetSpinBox->setSingleStep( singleStep );
}

void QgsLabelingGui::on_mXCoordinateComboBox_currentIndexChanged( const QString & text )
{
if ( text.isEmpty() ) //no data defined alignment without data defined position
@@ -49,6 +49,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void updatePreview();
void scrollPreview();
void updateOptions();
void updateQuadrant();

void on_mPreviewSizeSlider_valueChanged( int i );
void on_mFontSizeSpinBox_valueChanged( double d );
@@ -60,6 +61,7 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
void on_mBufferUnitComboBox_currentIndexChanged( int index );
void on_mPointOffsetUnitsComboBox_currentIndexChanged( int index );
void on_mXCoordinateComboBox_currentIndexChanged( const QString & text );
void on_mYCoordinateComboBox_currentIndexChanged( const QString & text );

@@ -91,6 +93,9 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
QFont mRefFont;
int mPreviewSize;

int mXQuadOffset;
int mYQuadOffset;

void disableDataDefinedAlignment();
void enableDataDefinedAlignment();
};

0 comments on commit 61a5022

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