|
47 | 47 | #include "qgsmarkersymbol.h"
|
48 | 48 | #include "qgslinesymbol.h"
|
49 | 49 | #include "qgsfillsymbol.h"
|
| 50 | +#include "qgsmarkersymbollayer.h" |
50 | 51 |
|
51 | 52 | static bool _initWidgetFunction( const QString &name, QgsSymbolLayerWidgetFunc f )
|
52 | 53 | {
|
@@ -389,6 +390,48 @@ void QgsLayerPropertiesWidget::layerTypeChanged()
|
389 | 390 | }
|
390 | 391 | }
|
391 | 392 |
|
| 393 | + // special logic for when NEW symbol layers are created from GUI only... |
| 394 | + // TODO: find a nicer generic way to handle this! |
| 395 | + if ( QgsFontMarkerSymbolLayer *fontMarker = dynamic_cast< QgsFontMarkerSymbolLayer * >( newLayer ) ) |
| 396 | + { |
| 397 | + const QString defaultFont = fontMarker->fontFamily(); |
| 398 | + const QFontDatabase fontDb; |
| 399 | + if ( !fontDb.hasFamily( defaultFont ) ) |
| 400 | + { |
| 401 | + // default font marker font choice doesn't exist on system, so just use first available symbol font |
| 402 | + const QStringList candidates = fontDb.families( QFontDatabase::WritingSystem::Symbol ); |
| 403 | + bool foundGoodCandidate = false; |
| 404 | + for ( const QString &candidate : candidates ) |
| 405 | + { |
| 406 | + if ( fontDb.writingSystems( candidate ).size() == 1 ) |
| 407 | + { |
| 408 | + // family ONLY offers symbol writing systems, so it's a good candidate! |
| 409 | + fontMarker->setFontFamily( candidate ); |
| 410 | + foundGoodCandidate = true; |
| 411 | + break; |
| 412 | + } |
| 413 | + } |
| 414 | + if ( !foundGoodCandidate && !candidates.empty() ) |
| 415 | + { |
| 416 | + // fallback to first available family which advertises symbol writing system |
| 417 | + QString candidate = candidates.at( 0 ); |
| 418 | + fontMarker->setFontFamily( candidate ); |
| 419 | + } |
| 420 | + } |
| 421 | + |
| 422 | + // search (briefly!!) for a unicode character which actually exists in the font |
| 423 | + const QFontMetrics fontMetrics( fontMarker->fontFamily() ); |
| 424 | + ushort character = fontMarker->character().at( 0 ).unicode(); |
| 425 | + for ( ; character < 1000; ++character ) |
| 426 | + { |
| 427 | + if ( fontMetrics.inFont( QChar( character ) ) ) |
| 428 | + { |
| 429 | + fontMarker->setCharacter( QChar( character ) ); |
| 430 | + break; |
| 431 | + } |
| 432 | + } |
| 433 | + } |
| 434 | + |
392 | 435 | updateSymbolLayerWidget( newLayer );
|
393 | 436 | emit changeLayer( newLayer );
|
394 | 437 | }
|
|
0 commit comments