@@ -43,14 +43,18 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
43
43
setupUi ( this );
44
44
45
45
mRefFont = lblFontPreview->font ();
46
- mPreviewBackgroundBtn ->setColor ( Qt::white );
47
- connect ( mPreviewBackgroundBtn , SIGNAL ( clicked () ), this , SLOT ( changePreviewBackground ( ) ) );
46
+ mPreviewSize = 24 ;
48
47
49
48
connect ( btnTextColor, SIGNAL ( clicked () ), this , SLOT ( changeTextColor () ) );
50
49
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 () ) );
51
52
connect ( chkBuffer, SIGNAL ( toggled ( bool ) ), this , SLOT ( updatePreview () ) );
52
53
connect ( btnBufferColor, SIGNAL ( clicked () ), this , SLOT ( changeBufferColor () ) );
53
54
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 () ) );
54
58
connect ( btnEngineSettings, SIGNAL ( clicked () ), this , SLOT ( showEngineConfigDialog () ) );
55
59
connect ( btnExpression, SIGNAL ( clicked () ), this , SLOT ( showExpressionDialog () ) );
56
60
@@ -146,6 +150,9 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
146
150
wrapCharacterEdit->setText ( lyr.wrapChar );
147
151
chkPreserveRotation->setChecked ( lyr.preserveRotation );
148
152
153
+ mPreviewBackgroundBtn ->setColor ( lyr.previewBkgrdColor );
154
+ setPreviewBackground ( lyr.previewBkgrdColor );
155
+
149
156
bool scaleBased = ( lyr.scaleMin != 0 && lyr.scaleMax != 0 );
150
157
chkScaleBasedVisibility->setChecked ( scaleBased );
151
158
if ( scaleBased )
@@ -157,12 +164,24 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
157
164
bool buffer = ( lyr.bufferSize != 0 );
158
165
chkBuffer->setChecked ( buffer );
159
166
if ( buffer )
167
+ {
160
168
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
+ }
161
182
162
183
btnTextColor->setColor ( lyr.textColor );
163
184
mFontTranspSpinBox ->setValue ( lyr.textTransp );
164
- btnBufferColor->setColor ( lyr.bufferColor );
165
- mBufferTranspSpinBox ->setValue ( lyr.bufferTransp );
166
185
167
186
bool formattedNumbers = lyr.formatNumbers ;
168
187
bool plusSign = lyr.plusSign ;
@@ -177,7 +196,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
177
196
chkPlusSign->setChecked ( plusSign );
178
197
}
179
198
180
-
181
199
if ( lyr.fontSizeInMapUnits )
182
200
{
183
201
mFontSizeUnitComboBox ->setCurrentIndex ( 1 );
@@ -285,6 +303,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
285
303
lyr.textColor = btnTextColor->color ();
286
304
lyr.textFont = mRefFont ;
287
305
lyr.textTransp = mFontTranspSpinBox ->value ();
306
+ lyr.previewBkgrdColor = mPreviewBackgroundBtn ->color ();
288
307
lyr.enabled = chkEnableLabeling->isChecked ();
289
308
lyr.priority = sliderPriority->value ();
290
309
lyr.obstacle = !chkNoObstacle->isChecked ();
@@ -304,6 +323,9 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
304
323
lyr.bufferSize = spinBufferSize->value ();
305
324
lyr.bufferColor = btnBufferColor->color ();
306
325
lyr.bufferTransp = mBufferTranspSpinBox ->value ();
326
+ lyr.bufferSizeInMapUnits = ( mBufferUnitComboBox ->currentIndex () == 1 );
327
+ lyr.bufferJoinStyle = mBufferJoinStyleComboBox ->penJoinStyle ();
328
+ lyr.bufferNoFill = !mBufferTranspFillChbx ->isChecked ();
307
329
}
308
330
else
309
331
{
@@ -438,6 +460,7 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
438
460
( *comboIt )->addItem ( " " , QVariant () );
439
461
}
440
462
463
+ // TODO: don't add field that aren't of appropriate type for the data defined property
441
464
const QgsFieldMap& fields = mLayer ->dataProvider ()->fields ();
442
465
for ( QgsFieldMap::const_iterator it = fields.constBegin (); it != fields.constEnd (); it++ )
443
466
{
@@ -471,18 +494,6 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
471
494
setCurrentComboValue ( mBufferTranspAttributeComboBox , s, QgsPalLayerSettings::BufferTransp );
472
495
}
473
496
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
-
486
497
void QgsLabelingGui::changeTextColor ()
487
498
{
488
499
QColor color = QColorDialog::getColor ( btnTextColor->color (), this );
@@ -504,9 +515,17 @@ void QgsLabelingGui::changeTextFont()
504
515
#endif
505
516
if ( ok )
506
517
{
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
+ }
507
527
updateFont ( font );
508
528
}
509
- mFontSizeSpinBox ->setValue ( mRefFont .pointSizeF () );
510
529
}
511
530
512
531
void QgsLabelingGui::updateFont ( QFont font )
@@ -517,12 +536,14 @@ void QgsLabelingGui::updateFont( QFont font )
517
536
mRefFont = font;
518
537
}
519
538
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);
526
547
527
548
updatePreview ();
528
549
}
@@ -532,31 +553,55 @@ void QgsLabelingGui::updatePreview()
532
553
scrollPreview ();
533
554
lblFontPreview->setFont ( mRefFont );
534
555
QFont previewFont = lblFontPreview->font ();
556
+ double fontSize = mFontSizeSpinBox ->value ();
557
+ double bufferSize = spinBufferSize->value ();
535
558
if ( mFontSizeUnitComboBox ->currentIndex () == 1 )
536
559
{
537
560
// 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
+ }
540
572
}
541
573
else
542
574
{
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
+ }
545
586
}
546
587
lblFontPreview->setFont ( previewFont );
547
588
548
589
QColor prevColor = btnTextColor->color ();
549
590
prevColor.setAlphaF (( 100.0 - ( double )( mFontTranspSpinBox ->value () ) ) / 100.0 );
550
591
lblFontPreview->setTextColor ( prevColor );
592
+
593
+ bool bufferNoFill = false ;
551
594
if ( chkBuffer->isChecked () )
552
595
{
553
596
QColor buffColor = btnBufferColor->color ();
554
597
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 );
556
601
}
557
602
else
558
603
{
559
- lblFontPreview->setBuffer ( 0 , Qt::white );
604
+ lblFontPreview->setBuffer ( 0 , Qt::white, Qt::BevelJoin, bufferNoFill );
560
605
}
561
606
}
562
607
@@ -565,6 +610,13 @@ void QgsLabelingGui::scrollPreview()
565
610
scrollArea_mPreview->ensureVisible ( 0 , 0 , 0 , 0 );
566
611
}
567
612
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
+
568
620
void QgsLabelingGui::showEngineConfigDialog ()
569
621
{
570
622
QgsLabelEngineConfigDialog dlg ( mLBL , this );
@@ -593,6 +645,9 @@ void QgsLabelingGui::updateUi()
593
645
bool buf = chkBuffer->isChecked ();
594
646
spinBufferSize->setEnabled ( buf );
595
647
btnBufferColor->setEnabled ( buf );
648
+ mBufferUnitComboBox ->setEnabled ( buf );
649
+ mBufferTranspSlider ->setEnabled ( buf );
650
+ mBufferTranspSpinBox ->setEnabled ( buf );
596
651
597
652
bool scale = chkScaleBasedVisibility->isChecked ();
598
653
spinScaleMin->setEnabled ( scale );
@@ -633,21 +688,15 @@ void QgsLabelingGui::updateOptions()
633
688
}
634
689
}
635
690
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 )
643
692
{
644
- Q_UNUSED ( index ) ;
645
- updateFont ( mRefFont );
693
+ mPreviewSize = i ;
694
+ updatePreview ( );
646
695
}
647
696
648
- void QgsLabelingGui::on_mFontTranspSpinBox_valueChanged ( int i )
697
+ void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged ( double d )
649
698
{
650
- Q_UNUSED ( i );
699
+ mRefFont . setPointSizeF ( d );
651
700
updateFont ( mRefFont );
652
701
}
653
702
@@ -663,9 +712,10 @@ void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
663
712
updateFont ( mRefFont );
664
713
}
665
714
666
- void QgsLabelingGui::on_mBufferTranspSpinBox_valueChanged ( int i )
715
+ void QgsLabelingGui::on_mBufferUnitComboBox_currentIndexChanged ( int index )
667
716
{
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 );
669
719
updateFont ( mRefFont );
670
720
}
671
721
@@ -705,6 +755,16 @@ void QgsLabelingGui::on_mPreviewTextBtn_clicked()
705
755
updatePreview ();
706
756
}
707
757
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
+
708
768
void QgsLabelingGui::disableDataDefinedAlignment ()
709
769
{
710
770
mHorizontalAlignmentComboBox ->setCurrentIndex ( mHorizontalAlignmentComboBox ->findText ( " " ) );
0 commit comments