Skip to content

Commit 7079f20

Browse files
committedAug 16, 2012
Add map units, join styles and transp. fill to buffer options in adv labeling
- Preview now shows when interior of buffer is set to transparent - Text size in map units are now not reset to pts when choosing a font - Preview background is now saved with PAL settings per layer - Add groupbox title warning about missmatch of unit type between text and buffer - Preview now does not show buffer if it is in map units and the text is in pts - Preview now shows map units text/buffer visual ratio within reason (looks like map labels) - Preview can now be dynamically scaled between 8 and 152 pts size - Defaults for new setting methods set to match previous defaults (backwards compat.)
1 parent ac4486a commit 7079f20

File tree

7 files changed

+858
-666
lines changed

7 files changed

+858
-666
lines changed
 

‎src/app/qgslabelinggui.cpp

Lines changed: 103 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,18 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
4343
setupUi( this );
4444

4545
mRefFont = lblFontPreview->font();
46-
mPreviewBackgroundBtn->setColor( Qt::white );
47-
connect( mPreviewBackgroundBtn, SIGNAL( clicked() ), this, SLOT( changePreviewBackground( ) ) );
46+
mPreviewSize = 24;
4847

4948
connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
5049
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
50+
connect( mFontSizeUnitComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
51+
connect( mFontTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
5152
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
5253
connect( btnBufferColor, SIGNAL( clicked() ), this, SLOT( changeBufferColor() ) );
5354
connect( spinBufferSize, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ) );
55+
connect( mBufferTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
56+
connect( mBufferJoinStyleComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
57+
connect( mBufferTranspFillChbx, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
5458
connect( btnEngineSettings, SIGNAL( clicked() ), this, SLOT( showEngineConfigDialog() ) );
5559
connect( btnExpression, SIGNAL( clicked() ), this, SLOT( showExpressionDialog() ) );
5660

@@ -146,6 +150,9 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
146150
wrapCharacterEdit->setText( lyr.wrapChar );
147151
chkPreserveRotation->setChecked( lyr.preserveRotation );
148152

153+
mPreviewBackgroundBtn->setColor( lyr.previewBkgrdColor );
154+
setPreviewBackground( lyr.previewBkgrdColor );
155+
149156
bool scaleBased = ( lyr.scaleMin != 0 && lyr.scaleMax != 0 );
150157
chkScaleBasedVisibility->setChecked( scaleBased );
151158
if ( scaleBased )
@@ -157,12 +164,24 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
157164
bool buffer = ( lyr.bufferSize != 0 );
158165
chkBuffer->setChecked( buffer );
159166
if ( buffer )
167+
{
160168
spinBufferSize->setValue( lyr.bufferSize );
169+
if ( lyr.bufferSizeInMapUnits )
170+
{
171+
mBufferUnitComboBox->setCurrentIndex( 1 );
172+
}
173+
else
174+
{
175+
mBufferUnitComboBox->setCurrentIndex( 0 );
176+
}
177+
btnBufferColor->setColor( lyr.bufferColor );
178+
mBufferTranspSpinBox->setValue( lyr.bufferTransp );
179+
mBufferJoinStyleComboBox->setPenJoinStyle( lyr.bufferJoinStyle );
180+
mBufferTranspFillChbx->setChecked( !lyr.bufferNoFill );
181+
}
161182

162183
btnTextColor->setColor( lyr.textColor );
163184
mFontTranspSpinBox->setValue( lyr.textTransp );
164-
btnBufferColor->setColor( lyr.bufferColor );
165-
mBufferTranspSpinBox->setValue( lyr.bufferTransp );
166185

167186
bool formattedNumbers = lyr.formatNumbers;
168187
bool plusSign = lyr.plusSign;
@@ -177,7 +196,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
177196
chkPlusSign->setChecked( plusSign );
178197
}
179198

180-
181199
if ( lyr.fontSizeInMapUnits )
182200
{
183201
mFontSizeUnitComboBox->setCurrentIndex( 1 );
@@ -285,6 +303,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
285303
lyr.textColor = btnTextColor->color();
286304
lyr.textFont = mRefFont;
287305
lyr.textTransp = mFontTranspSpinBox->value();
306+
lyr.previewBkgrdColor = mPreviewBackgroundBtn->color();
288307
lyr.enabled = chkEnableLabeling->isChecked();
289308
lyr.priority = sliderPriority->value();
290309
lyr.obstacle = !chkNoObstacle->isChecked();
@@ -304,6 +323,9 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
304323
lyr.bufferSize = spinBufferSize->value();
305324
lyr.bufferColor = btnBufferColor->color();
306325
lyr.bufferTransp = mBufferTranspSpinBox->value();
326+
lyr.bufferSizeInMapUnits = ( mBufferUnitComboBox->currentIndex() == 1 );
327+
lyr.bufferJoinStyle = mBufferJoinStyleComboBox->penJoinStyle();
328+
lyr.bufferNoFill = !mBufferTranspFillChbx->isChecked();
307329
}
308330
else
309331
{
@@ -438,6 +460,7 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
438460
( *comboIt )->addItem( "", QVariant() );
439461
}
440462

463+
// TODO: don't add field that aren't of appropriate type for the data defined property
441464
const QgsFieldMap& fields = mLayer->dataProvider()->fields();
442465
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); it++ )
443466
{
@@ -471,18 +494,6 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
471494
setCurrentComboValue( mBufferTranspAttributeComboBox, s, QgsPalLayerSettings::BufferTransp );
472495
}
473496

474-
void QgsLabelingGui::changePreviewBackground()
475-
{
476-
QColor color = QColorDialog::getColor( mPreviewBackgroundBtn->color(), this );
477-
if ( !color.isValid() )
478-
return;
479-
480-
mPreviewBackgroundBtn->setColor( color );
481-
scrollArea_mPreview->widget()->setStyleSheet( QString( "background: rgb(%1, %2, %3);" ).arg( QString::number( color.red() ),
482-
QString::number( color.green() ),
483-
QString::number( color.blue() ) ) );
484-
}
485-
486497
void QgsLabelingGui::changeTextColor()
487498
{
488499
QColor color = QColorDialog::getColor( btnTextColor->color(), this );
@@ -504,9 +515,17 @@ void QgsLabelingGui::changeTextFont()
504515
#endif
505516
if ( ok )
506517
{
518+
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
519+
{
520+
// don't override map units size with selected size from font dialog
521+
font.setPointSizeF( mFontSizeSpinBox->value() );
522+
}
523+
else
524+
{
525+
mFontSizeSpinBox->setValue( font.pointSizeF() );
526+
}
507527
updateFont( font );
508528
}
509-
mFontSizeSpinBox->setValue( mRefFont.pointSizeF() );
510529
}
511530

512531
void QgsLabelingGui::updateFont( QFont font )
@@ -517,12 +536,14 @@ void QgsLabelingGui::updateFont( QFont font )
517536
mRefFont = font;
518537
}
519538

520-
QString fontSizeUnitString = tr( "pt" );
521-
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
522-
{
523-
fontSizeUnitString = tr( "map units" );
524-
}
525-
lblFontName->setText( QString( "%1, %2 %3" ).arg( font.family() ).arg( mRefFont.pointSizeF() ).arg( fontSizeUnitString ) );
539+
lblFontName->setText( QString( "%1" ).arg( font.family() ) );
540+
541+
// update font name with font face
542+
// QString dupFont = font.toString();
543+
// QFont lblFont = lblFontName->font();
544+
// lblFont.fromString( dupFont );
545+
// lblFont.setPointSizeF( 14 );
546+
// lblFontName->setFont(lblFont);
526547

527548
updatePreview();
528549
}
@@ -532,31 +553,55 @@ void QgsLabelingGui::updatePreview()
532553
scrollPreview();
533554
lblFontPreview->setFont( mRefFont );
534555
QFont previewFont = lblFontPreview->font();
556+
double fontSize = mFontSizeSpinBox->value();
557+
double bufferSize = spinBufferSize->value();
535558
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
536559
{
537560
// TODO: maybe match current map zoom level instead?
538-
previewFont.setPointSize( 24 );
539-
groupBox_mPreview->setTitle( tr( "Sample @ 24 pts (using map units)" ) );
561+
previewFont.setPointSize( mPreviewSize );
562+
mPreviewSizeSlider->setEnabled( true );
563+
if ( mBufferUnitComboBox->currentIndex() == 1 )
564+
{
565+
groupBox_mPreview->setTitle( tr( "Sample @ %1 pts (using map units)" ).arg( mPreviewSize ) );
566+
bufferSize = ( mPreviewSize / fontSize ) * bufferSize / 2.5;
567+
}
568+
else
569+
{
570+
groupBox_mPreview->setTitle( tr( "Sample @ %1 pts (using map units, STROKE IN mm)" ).arg( mPreviewSize ) );
571+
}
540572
}
541573
else
542574
{
543-
previewFont.setPointSize( mFontSizeSpinBox->value() );
544-
groupBox_mPreview->setTitle( tr( "Sample" ) );
575+
mPreviewSizeSlider->setEnabled( false );
576+
if ( mBufferUnitComboBox->currentIndex() == 1 )
577+
{
578+
groupBox_mPreview->setTitle( tr( "Sample (stroke in map units, NOT SHOWN)" ) );
579+
bufferSize = 0;
580+
}
581+
else
582+
{
583+
previewFont.setPointSize( fontSize );
584+
groupBox_mPreview->setTitle( tr( "Sample" ) );
585+
}
545586
}
546587
lblFontPreview->setFont( previewFont );
547588

548589
QColor prevColor = btnTextColor->color();
549590
prevColor.setAlphaF(( 100.0 - ( double )( mFontTranspSpinBox->value() ) ) / 100.0 );
550591
lblFontPreview->setTextColor( prevColor );
592+
593+
bool bufferNoFill = false;
551594
if ( chkBuffer->isChecked() )
552595
{
553596
QColor buffColor = btnBufferColor->color();
554597
buffColor.setAlphaF(( 100.0 - ( double )( mBufferTranspSpinBox->value() ) ) / 100.0 );
555-
lblFontPreview->setBuffer( spinBufferSize->value(), buffColor );
598+
599+
bufferNoFill = !mBufferTranspFillChbx->isChecked();
600+
lblFontPreview->setBuffer( bufferSize, buffColor, mBufferJoinStyleComboBox->penJoinStyle(), bufferNoFill );
556601
}
557602
else
558603
{
559-
lblFontPreview->setBuffer( 0, Qt::white );
604+
lblFontPreview->setBuffer( 0, Qt::white, Qt::BevelJoin, bufferNoFill );
560605
}
561606
}
562607

@@ -565,6 +610,13 @@ void QgsLabelingGui::scrollPreview()
565610
scrollArea_mPreview->ensureVisible( 0, 0, 0, 0 );
566611
}
567612

613+
void QgsLabelingGui::setPreviewBackground( QColor color )
614+
{
615+
scrollArea_mPreview->widget()->setStyleSheet( QString( "background: rgb(%1, %2, %3);" ).arg( QString::number( color.red() ),
616+
QString::number( color.green() ),
617+
QString::number( color.blue() ) ) );
618+
}
619+
568620
void QgsLabelingGui::showEngineConfigDialog()
569621
{
570622
QgsLabelEngineConfigDialog dlg( mLBL, this );
@@ -593,6 +645,9 @@ void QgsLabelingGui::updateUi()
593645
bool buf = chkBuffer->isChecked();
594646
spinBufferSize->setEnabled( buf );
595647
btnBufferColor->setEnabled( buf );
648+
mBufferUnitComboBox->setEnabled( buf );
649+
mBufferTranspSlider->setEnabled( buf );
650+
mBufferTranspSpinBox->setEnabled( buf );
596651

597652
bool scale = chkScaleBasedVisibility->isChecked();
598653
spinScaleMin->setEnabled( scale );
@@ -633,21 +688,15 @@ void QgsLabelingGui::updateOptions()
633688
}
634689
}
635690

636-
void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
637-
{
638-
mRefFont.setPointSizeF( d );
639-
updateFont( mRefFont );
640-
}
641-
642-
void QgsLabelingGui::on_mFontSizeUnitComboBox_currentIndexChanged( int index )
691+
void QgsLabelingGui::on_mPreviewSizeSlider_valueChanged( int i )
643692
{
644-
Q_UNUSED( index );
645-
updateFont( mRefFont );
693+
mPreviewSize = i;
694+
updatePreview();
646695
}
647696

648-
void QgsLabelingGui::on_mFontTranspSpinBox_valueChanged( int i )
697+
void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
649698
{
650-
Q_UNUSED( i );
699+
mRefFont.setPointSizeF( d );
651700
updateFont( mRefFont );
652701
}
653702

@@ -663,9 +712,10 @@ void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
663712
updateFont( mRefFont );
664713
}
665714

666-
void QgsLabelingGui::on_mBufferTranspSpinBox_valueChanged( int i )
715+
void QgsLabelingGui::on_mBufferUnitComboBox_currentIndexChanged( int index )
667716
{
668-
Q_UNUSED( i );
717+
double singleStep = ( index == 1 ) ? 1.0 : 0.1 ; //1.0 for map units, 0.1 for mm
718+
spinBufferSize->setSingleStep( singleStep );
669719
updateFont( mRefFont );
670720
}
671721

@@ -705,6 +755,16 @@ void QgsLabelingGui::on_mPreviewTextBtn_clicked()
705755
updatePreview();
706756
}
707757

758+
void QgsLabelingGui::on_mPreviewBackgroundBtn_clicked()
759+
{
760+
QColor color = QColorDialog::getColor( mPreviewBackgroundBtn->color(), this );
761+
if ( !color.isValid() )
762+
return;
763+
764+
mPreviewBackgroundBtn->setColor( color );
765+
setPreviewBackground( color );
766+
}
767+
708768
void QgsLabelingGui::disableDataDefinedAlignment()
709769
{
710770
mHorizontalAlignmentComboBox->setCurrentIndex( mHorizontalAlignmentComboBox->findText( "" ) );

‎src/app/qgslabelinggui.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
3838

3939
public slots:
4040
void apply();
41-
void changePreviewBackground();
4241
void changeTextColor();
4342
void changeTextFont();
4443
void showEngineConfigDialog();
@@ -50,17 +49,17 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
5049
void scrollPreview();
5150
void updateOptions();
5251

52+
void on_mPreviewSizeSlider_valueChanged( int i );
5353
void on_mFontSizeSpinBox_valueChanged( double d );
54-
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
55-
void on_mFontTranspSpinBox_valueChanged( int i );
5654
void on_mFontWordSpacingSpinBox_valueChanged( double spacing );
5755
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
58-
void on_mBufferTranspSpinBox_valueChanged( int i );
56+
void on_mBufferUnitComboBox_currentIndexChanged( int index );
5957
void on_mXCoordinateComboBox_currentIndexChanged( const QString & text );
6058
void on_mYCoordinateComboBox_currentIndexChanged( const QString & text );
6159

6260
void on_mPreviewTextEdit_textChanged( const QString & text );
6361
void on_mPreviewTextBtn_clicked();
62+
void on_mPreviewBackgroundBtn_clicked();
6463

6564
protected:
6665
void populatePlacementMethods();
@@ -78,6 +77,8 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
7877

7978
// background reference font
8079
QFont mRefFont;
80+
int mPreviewSize;
81+
void setPreviewBackground( QColor color );
8182

8283
void disableDataDefinedAlignment();
8384
void enableDataDefinedAlignment();

‎src/app/qgslabelpreview.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ void QgsLabelPreview::setTextColor( QColor color )
3030
update();
3131
}
3232

33-
void QgsLabelPreview::setBuffer( double size, QColor color )
33+
void QgsLabelPreview::setBuffer( double size, QColor color, Qt::PenJoinStyle joinStyle, bool noFill )
3434
{
3535
mBufferSize = size * 88 / 25.4; //assume standard dpi for preview
3636
mBufferColor = color;
37+
mBufferJoinStyle = joinStyle;
38+
mBufferNoFill = noFill;
3739
update();
3840
}
3941

@@ -45,10 +47,15 @@ void QgsLabelPreview::paintEvent( QPaintEvent *e )
4547
p.setRenderHint( QPainter::Antialiasing );
4648
p.setFont( font() );
4749
QFontMetrics fm( font() );
48-
p.translate( 0, fm.ascent() + 4 );
4950

51+
double xtrans = 0;
5052
if ( mBufferSize != 0 )
51-
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor );
53+
xtrans = mBufferSize / 4;
54+
55+
p.translate( xtrans, fm.ascent() + 4 );
56+
57+
if ( mBufferSize != 0 )
58+
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor, mBufferJoinStyle, mBufferNoFill );
5259

5360
p.setPen( mTextColor );
5461
p.drawText( 0, 0, text() );

‎src/app/qgslabelpreview.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class QgsLabelPreview : public QLabel
2424

2525
void setTextColor( QColor color );
2626

27-
void setBuffer( double size, QColor color );
27+
void setBuffer( double size, QColor color, Qt::PenJoinStyle joinStyle, bool noFill = false );
2828

2929
void setFont( QFont f ) { mFont = f; }
3030
QFont font() { return mFont; }
@@ -34,6 +34,8 @@ class QgsLabelPreview : public QLabel
3434
private:
3535
int mBufferSize;
3636
QColor mBufferColor;
37+
Qt::PenJoinStyle mBufferJoinStyle;
38+
bool mBufferNoFill;
3739
QColor mTextColor;
3840
QFont mFont;
3941
};

‎src/core/qgspallabeling.cpp

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
144144
//textFont = QFont();
145145
textColor = Qt::black;
146146
textTransp = 0;
147+
previewBkgrdColor = Qt::white;
147148
enabled = false;
148149
priority = 5;
149150
obstacle = true;
@@ -153,6 +154,8 @@ QgsPalLayerSettings::QgsPalLayerSettings()
153154
bufferSize = 1;
154155
bufferColor = Qt::white;
155156
bufferTransp = 0;
157+
bufferNoFill = false;
158+
bufferJoinStyle = Qt::BevelJoin;
156159
formatNumbers = false;
157160
decimals = 3;
158161
plusSign = false;
@@ -163,6 +166,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
163166
rasterCompressFactor = 1.0;
164167
addDirectionSymbol = false;
165168
fontSizeInMapUnits = false;
169+
bufferSizeInMapUnits = false;
166170
distInMapUnits = false;
167171
wrapChar = "";
168172
preserveRotation = true;
@@ -178,6 +182,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
178182
textFont = s.textFont;
179183
textColor = s.textColor;
180184
textTransp = s.textTransp;
185+
previewBkgrdColor = s.previewBkgrdColor;
181186
enabled = s.enabled;
182187
priority = s.priority;
183188
obstacle = s.obstacle;
@@ -187,6 +192,8 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
187192
bufferSize = s.bufferSize;
188193
bufferColor = s.bufferColor;
189194
bufferTransp = s.bufferTransp;
195+
bufferJoinStyle = s.bufferJoinStyle;
196+
bufferNoFill = s.bufferNoFill;
190197
formatNumbers = s.formatNumbers;
191198
decimals = s.decimals;
192199
plusSign = s.plusSign;
@@ -197,6 +204,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
197204
rasterCompressFactor = s.rasterCompressFactor;
198205
addDirectionSymbol = s.addDirectionSymbol;
199206
fontSizeInMapUnits = s.fontSizeInMapUnits;
207+
bufferSizeInMapUnits = s.bufferSizeInMapUnits;
200208
distInMapUnits = s.distInMapUnits;
201209
wrapChar = s.wrapChar;
202210
preserveRotation = s.preserveRotation;
@@ -330,6 +338,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
330338
textFont.setPointSizeF( fontSize ); //double precision needed because of map units
331339
textColor = _readColor( layer, "labeling/textColor" );
332340
textTransp = layer->customProperty( "labeling/textTransp" ).toInt();
341+
previewBkgrdColor = QColor( layer->customProperty( "labeling/previewBkgrdColor", "#ffffff" ).toString() );
333342
enabled = layer->customProperty( "labeling/enabled" ).toBool();
334343
priority = layer->customProperty( "labeling/priority" ).toInt();
335344
obstacle = layer->customProperty( "labeling/obstacle" ).toBool();
@@ -339,6 +348,8 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
339348
bufferSize = layer->customProperty( "labeling/bufferSize" ).toDouble();
340349
bufferColor = _readColor( layer, "labeling/bufferColor" );
341350
bufferTransp = layer->customProperty( "labeling/bufferTransp" ).toInt();
351+
bufferJoinStyle = ( Qt::PenJoinStyle ) layer->customProperty( "labeling/bufferJoinStyle", QVariant( Qt::BevelJoin ) ).toUInt();
352+
bufferNoFill = layer->customProperty( "labeling/bufferNoFill", QVariant( false ) ).toBool();
342353
formatNumbers = layer->customProperty( "labeling/formatNumbers" ).toBool();
343354
decimals = layer->customProperty( "labeling/decimals" ).toInt();
344355
plusSign = layer->customProperty( "labeling/plussign" ).toInt();
@@ -347,6 +358,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
347358
addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
348359
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
349360
fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
361+
bufferSizeInMapUnits = layer->customProperty( "labeling/bufferSizeInMapUnits" ).toBool();
350362
distInMapUnits = layer->customProperty( "labeling/distInMapUnits" ).toBool();
351363
wrapChar = layer->customProperty( "labeling/wrapChar" ).toString();
352364
preserveRotation = layer->customProperty( "labeling/preserveRotation", QVariant( true ) ).toBool();
@@ -372,6 +384,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
372384

373385
_writeColor( layer, "labeling/textColor", textColor );
374386
layer->setCustomProperty( "labeling/textTransp", textTransp );
387+
layer->setCustomProperty( "labeling/previewBkgrdColor", previewBkgrdColor.name() );
375388
layer->setCustomProperty( "labeling/enabled", enabled );
376389
layer->setCustomProperty( "labeling/priority", priority );
377390
layer->setCustomProperty( "labeling/obstacle", obstacle );
@@ -381,6 +394,8 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
381394
layer->setCustomProperty( "labeling/bufferSize", bufferSize );
382395
_writeColor( layer, "labeling/bufferColor", bufferColor );
383396
layer->setCustomProperty( "labeling/bufferTransp", bufferTransp );
397+
layer->setCustomProperty( "labeling/bufferJoinStyle", ( unsigned int )bufferJoinStyle );
398+
layer->setCustomProperty( "labeling/bufferNoFill", bufferNoFill );
384399
layer->setCustomProperty( "labeling/formatNumbers", formatNumbers );
385400
layer->setCustomProperty( "labeling/decimals", decimals );
386401
layer->setCustomProperty( "labeling/plussign", plusSign );
@@ -389,6 +404,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
389404
layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
390405
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
391406
layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
407+
layer->setCustomProperty( "labeling/bufferSizeInMapUnits", bufferSizeInMapUnits );
392408
layer->setCustomProperty( "labeling/distInMapUnits", distInMapUnits );
393409
layer->setCustomProperty( "labeling/wrapChar", wrapChar );
394410
layer->setCustomProperty( "labeling/preserveRotation", preserveRotation );
@@ -508,7 +524,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
508524
bool conversionOk;
509525
int minScale = minScaleValue.toInt( &conversionOk );
510526
// TODO: occasional floating point issues?
511-
if ( conversionOk && int( context.rendererScale() ) < minScale )
527+
if ( conversionOk && ( int )( context.rendererScale() ) < minScale )
512528
{
513529
return;
514530
}
@@ -525,7 +541,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
525541
bool conversionOk;
526542
int maxScale = maxScaleValue.toInt( &conversionOk );
527543
// TODO: occasional floating point issues?
528-
if ( conversionOk && int( context.rendererScale() ) > maxScale )
544+
if ( conversionOk && ( int )( context.rendererScale() ) > maxScale )
529545
{
530546
return;
531547
}
@@ -782,17 +798,18 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
782798
lbl->setIsPinned( dataDefinedPosition );
783799
}
784800

785-
int QgsPalLayerSettings::sizeToPixel( double size, const QgsRenderContext& c ) const
801+
int QgsPalLayerSettings::sizeToPixel( double size, const QgsRenderContext& c, bool buffer ) const
786802
{
787803
double pixelSize;
788-
if ( fontSizeInMapUnits )
804+
if (( !buffer && fontSizeInMapUnits ) || ( buffer && bufferSizeInMapUnits ) )
789805
{
790806
pixelSize = size / c.mapToPixel().mapUnitsPerPixel() * c.rasterScaleFactor();
791807
}
792-
else //font size in points
808+
else //font size in points, or buffer in mm
793809
{
810+
double ptsTomm = buffer ? 1 : 0.3527;
794811
// set font size from points to output size
795-
pixelSize = 0.3527 * size * c.scaleFactor() * c.rasterScaleFactor();
812+
pixelSize = ptsTomm * size * c.scaleFactor() * c.rasterScaleFactor();
796813
}
797814
return ( int )( pixelSize + 0.5 );
798815
}
@@ -1329,7 +1346,10 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
13291346
bufferColor.setAlphaF(( 100.0 - ( double )( bufferTransp ) ) / 100.0 );
13301347

13311348
if ( lyr.bufferSize != 0 )
1332-
drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferSize, bufferColor, true );
1349+
{
1350+
int bufferPixelSize = lyr.sizeToPixel( bufferSize, context, true );
1351+
drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferPixelSize, bufferColor, true );
1352+
}
13331353

13341354
drawLabel( *it, painter, fontForLabel, fontColor, xform );
13351355

@@ -1448,7 +1468,7 @@ void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* p
14481468
drawLabelCandidateRect( lp->getNextPart(), painter, xform );
14491469
}
14501470

1451-
void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferSize,
1471+
void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferPixelSize,
14521472
const QColor& bufferColor, bool drawBuffer )
14531473
{
14541474
QgsPoint outPt = xform->transform( label->getX(), label->getY() );
@@ -1496,7 +1516,8 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
14961516
if ( drawBuffer )
14971517
{
14981518
// we're drawing buffer
1499-
drawLabelBuffer( painter, multiLineList.at( i ), f, bufferSize * lyr.vectorScaleFactor * lyr.rasterCompressFactor , bufferColor );
1519+
//drawLabelBuffer( painter, multiLineList.at( i ), f, bufferSize * lyr.vectorScaleFactor * lyr.rasterCompressFactor , bufferColor );
1520+
drawLabelBuffer( painter, multiLineList.at( i ), f, bufferPixelSize , bufferColor, lyr.bufferJoinStyle, lyr.bufferNoFill );
15001521
}
15011522
else
15021523
{
@@ -1510,20 +1531,24 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
15101531
painter->restore();
15111532

15121533
if ( label->getNextPart() )
1513-
drawLabel( label->getNextPart(), painter, f, c, xform, bufferSize, bufferColor, drawBuffer );
1534+
drawLabel( label->getNextPart(), painter, f, c, xform, bufferPixelSize, bufferColor, drawBuffer );
15141535
}
15151536
}
15161537

15171538

1518-
void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color )
1539+
void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color, Qt::PenJoinStyle joinstyle, bool noFill )
15191540
{
15201541
QPainterPath path;
15211542
path.addText( 0, 0, font, text );
15221543
QPen pen( color );
15231544
pen.setWidthF( size );
1545+
pen.setJoinStyle( joinstyle );
15241546
p->setPen( pen );
1525-
// TODO: make pref for whether to fill buffer
1526-
// color.setAlpha( 0 );
1547+
// honor pref for whether to fill buffer
1548+
if ( noFill )
1549+
{
1550+
color.setAlpha( 0 );
1551+
}
15271552
p->setBrush( color );
15281553
p->drawPath( path );
15291554
}

‎src/core/qgspallabeling.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ class CORE_EXPORT QgsPalLayerSettings
120120
QFont textFont;
121121
QColor textColor;
122122
int textTransp;
123+
QColor previewBkgrdColor;
123124
bool enabled;
124125
int priority; // 0 = low, 10 = high
125126
bool obstacle; // whether it's an obstacle
@@ -130,6 +131,8 @@ class CORE_EXPORT QgsPalLayerSettings
130131
double bufferSize; //buffer size (in mm)
131132
QColor bufferColor;
132133
int bufferTransp;
134+
Qt::PenJoinStyle bufferJoinStyle;
135+
bool bufferNoFill; //set interior of buffer to 100% transparent
133136
bool formatNumbers;
134137
int decimals;
135138
bool plusSign;
@@ -140,6 +143,7 @@ class CORE_EXPORT QgsPalLayerSettings
140143
// Works only if Placement == Line
141144
bool addDirectionSymbol;
142145
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
146+
bool bufferSizeInMapUnits; //true if buffer is in map units (otherwise in mm)
143147
bool distInMapUnits; //true if distance is in map units (otherwise in mm)
144148
QString wrapChar;
145149
// called from register feature hook
@@ -174,8 +178,9 @@ class CORE_EXPORT QgsPalLayerSettings
174178
/**Calculates pixel size (considering output size should be in pixel or map units, scale factors and oversampling)
175179
@param size size to convert
176180
@param c rendercontext
181+
@param buffer whether it buffer size being calculated
177182
@return font pixel size*/
178-
int sizeToPixel( double size, const QgsRenderContext& c ) const;
183+
int sizeToPixel( double size, const QgsRenderContext& c , bool buffer = false ) const;
179184

180185
private:
181186
/**Checks if a feature is larger than a minimum size (in mm)
@@ -245,7 +250,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
245250
//!drawLabel
246251
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferSize = -1,
247252
const QColor& bufferColor = QColor( 255, 255, 255 ), bool drawBuffer = false );
248-
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color );
253+
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color , Qt::PenJoinStyle joinstyle = Qt::BevelJoin, bool noFill = false );
249254

250255
protected:
251256

‎src/ui/qgslabelingguibase.ui

Lines changed: 692 additions & 600 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.