@@ -73,7 +73,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
73
73
74
74
// preview and basic option connections
75
75
connect ( btnTextColor, SIGNAL ( colorChanged ( const QColor& ) ), this , SLOT ( changeTextColor ( const QColor& ) ) );
76
- connect ( btnChangeFont, SIGNAL ( clicked () ), this , SLOT ( changeTextFont () ) );
77
76
connect ( mFontTranspSpinBox , SIGNAL ( valueChanged ( int ) ), this , SLOT ( updatePreview () ) );
78
77
connect ( mBufferDrawChkBx , SIGNAL ( toggled ( bool ) ), this , SLOT ( updatePreview () ) );
79
78
connect ( btnBufferColor, SIGNAL ( colorChanged ( const QColor& ) ), this , SLOT ( changeBufferColor ( const QColor& ) ) );
@@ -366,6 +365,22 @@ void QgsLabelingGui::init()
366
365
QgsFontUtils::updateFontViaStyle ( mRefFont , lyr.textNamedStyle );
367
366
updateFont ( mRefFont );
368
367
368
+ // show 'font not found' if substitution has occurred (should come after updateFont())
369
+ if ( !lyr.mTextFontFound )
370
+ {
371
+ mFontMissingLabel ->setVisible ( true );
372
+ QString missingTxt = tr ( " %1 not found. Default substituted." );
373
+ QString txtPrepend = tr ( " Chosen font" );
374
+ if ( !lyr.mTextFontFamily .isEmpty () )
375
+ {
376
+ txtPrepend = QString ( " '%1'" ).arg ( lyr.mTextFontFamily );
377
+ }
378
+ mFontMissingLabel ->setText ( missingTxt.arg ( txtPrepend ) );
379
+
380
+ // ensure user is sent to 'Text style' section to see notice
381
+ mLabelingOptionsListWidget ->setCurrentRow ( 0 );
382
+ }
383
+
369
384
// shape background
370
385
mShapeDrawChkBx ->setChecked ( lyr.shapeDraw );
371
386
mShapeTypeCmbBx ->blockSignals ( true );
@@ -474,6 +489,7 @@ void QgsLabelingGui::collapseSample( bool collapse )
474
489
void QgsLabelingGui::apply ()
475
490
{
476
491
writeSettingsToLayer ();
492
+ mFontMissingLabel ->setVisible ( false );
477
493
QgisApp::instance ()->markDirty ();
478
494
// trigger refresh
479
495
if ( mMapCanvas )
@@ -1019,41 +1035,6 @@ void QgsLabelingGui::changeTextColor( const QColor &color )
1019
1035
updatePreview ();
1020
1036
}
1021
1037
1022
- void QgsLabelingGui::changeTextFont ()
1023
- {
1024
- // store properties of QFont that might be stripped by font dialog
1025
- QFont::Capitalization captials = mRefFont .capitalization ();
1026
- double wordspacing = mRefFont .wordSpacing ();
1027
- double letterspacing = mRefFont .letterSpacing ();
1028
-
1029
- bool ok;
1030
- #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA)
1031
- // Native Mac dialog works only for Qt Carbon
1032
- QFont font = QFontDialog::getFont ( &ok, mRefFont , 0 , QString (), QFontDialog::DontUseNativeDialog );
1033
- #else
1034
- QFont font = QFontDialog::getFont ( &ok, mRefFont );
1035
- #endif
1036
- if ( ok )
1037
- {
1038
- if ( mFontSizeUnitComboBox ->currentIndex () == 1 )
1039
- {
1040
- // don't override map units size with selected size from font dialog
1041
- font.setPointSizeF ( mFontSizeSpinBox ->value () );
1042
- }
1043
- else
1044
- {
1045
- mFontSizeSpinBox ->setValue ( font.pointSizeF () );
1046
- }
1047
-
1048
- // reassign possibly stripped QFont properties
1049
- font.setCapitalization ( captials );
1050
- font.setWordSpacing ( wordspacing );
1051
- font.setLetterSpacing ( QFont::AbsoluteSpacing, letterspacing );
1052
-
1053
- updateFont ( font );
1054
- }
1055
- }
1056
-
1057
1038
void QgsLabelingGui::updateFont ( QFont font )
1058
1039
{
1059
1040
// update background reference font
@@ -1063,31 +1044,13 @@ void QgsLabelingGui::updateFont( QFont font )
1063
1044
}
1064
1045
1065
1046
// test if font is actually available
1066
- QString missingtxt = QString ( " " );
1067
- bool missing = false ;
1068
- if ( QApplication::font ().toString () != mRefFont .toString () )
1069
- {
1070
- QFont testfont = mFontDB .font ( mRefFont .family (), mFontDB .styleString ( mRefFont ), 12 );
1071
- if ( QApplication::font ().toString () == testfont.toString () )
1072
- {
1073
- missing = true ;
1074
- }
1075
- }
1076
- if ( missing )
1077
- {
1078
- missingtxt = tr ( " (not found!)" );
1079
- lblFontName->setStyleSheet ( " color: #990000;" );
1080
- }
1081
- else
1082
- {
1083
- lblFontName->setStyleSheet ( " color: #000000;" );
1084
- }
1047
+ mFontMissingLabel ->setVisible ( QgsFontUtils::fontMatchOnSystem ( mRefFont ) );
1085
1048
1086
- lblFontName->setText ( QString ( " %1%2" ).arg ( mRefFont .family () ).arg ( missingtxt ) );
1087
1049
mDirectSymbLeftLineEdit ->setFont ( mRefFont );
1088
1050
mDirectSymbRightLineEdit ->setFont ( mRefFont );
1089
1051
1090
1052
blockFontChangeSignals ( true );
1053
+ mFontFamilyCmbBx ->setCurrentFont ( mRefFont );
1091
1054
populateFontStyleComboBox ();
1092
1055
int idx = mFontCapitalsComboBox ->findData ( QVariant (( unsigned int ) mRefFont .capitalization () ) );
1093
1056
mFontCapitalsComboBox ->setCurrentIndex ( idx == -1 ? 0 : idx );
@@ -1097,13 +1060,13 @@ void QgsLabelingGui::updateFont( QFont font )
1097
1060
1098
1061
// update font name with font face
1099
1062
// font.setPixelSize( 24 );
1100
- // lblFontName->setFont( QFont( font ) );
1101
1063
1102
1064
updatePreview ();
1103
1065
}
1104
1066
1105
1067
void QgsLabelingGui::blockFontChangeSignals ( bool blk )
1106
1068
{
1069
+ mFontFamilyCmbBx ->blockSignals ( blk );
1107
1070
mFontStyleComboBox ->blockSignals ( blk );
1108
1071
mFontCapitalsComboBox ->blockSignals ( blk );
1109
1072
mFontUnderlineBtn ->blockSignals ( blk );
@@ -1333,7 +1296,15 @@ void QgsLabelingGui::populateFontStyleComboBox()
1333
1296
{
1334
1297
mFontStyleComboBox ->addItem ( style );
1335
1298
}
1336
- mFontStyleComboBox ->setCurrentIndex ( mFontStyleComboBox ->findText ( mFontDB .styleString ( mRefFont ) ) );
1299
+
1300
+ int curIndx = 0 ;
1301
+ int stylIndx = mFontStyleComboBox ->findText ( mFontDB .styleString ( mRefFont ) );
1302
+ if ( stylIndx > -1 )
1303
+ {
1304
+ curIndx = stylIndx;
1305
+ }
1306
+
1307
+ mFontStyleComboBox ->setCurrentIndex ( curIndx );
1337
1308
}
1338
1309
1339
1310
void QgsLabelingGui::on_mPreviewSizeSlider_valueChanged ( int i )
@@ -1355,6 +1326,12 @@ void QgsLabelingGui::on_mFontCapitalsComboBox_currentIndexChanged( int index )
1355
1326
updateFont ( mRefFont );
1356
1327
}
1357
1328
1329
+ void QgsLabelingGui::on_mFontFamilyCmbBx_currentFontChanged ( const QFont& f )
1330
+ {
1331
+ mRefFont .setFamily ( f.family () );
1332
+ updateFont ( mRefFont );
1333
+ }
1334
+
1358
1335
void QgsLabelingGui::on_mFontStyleComboBox_currentIndexChanged ( const QString & text )
1359
1336
{
1360
1337
QgsFontUtils::updateFontViaStyle ( mRefFont , text );
0 commit comments