Skip to content
Permalink
Browse files

Update label gui and rendering with QgsFontUtils functions

  • Loading branch information
dakcarto committed Jun 10, 2013
1 parent 04c4db1 commit 44d89a4708c72deb5441e3078d3999b65e9e32ec
Showing with 19 additions and 77 deletions.
  1. +3 −43 src/app/qgslabelinggui.cpp
  2. +0 −1 src/app/qgslabelinggui.h
  3. +16 −31 src/core/qgspallabeling.cpp
  4. +0 −2 src/core/qgspallabeling.h
@@ -26,6 +26,7 @@
#include "qgslabelengineconfigdialog.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpression.h"
#include "qgsfontutils.h"
#include "qgisapp.h"
#include "qgsmaprenderer.h"
#include "qgsproject.h"
@@ -362,7 +363,7 @@ void QgsLabelingGui::init()
mFontWordSpacingSpinBox->setValue( lyr.textFont.wordSpacing() );
mFontLetterSpacingSpinBox->setValue( lyr.textFont.letterSpacing() );

updateFontViaStyle( lyr.textNamedStyle );
QgsFontUtils::updateFontViaStyle( mRefFont, lyr.textNamedStyle );
updateFont( mRefFont );

// shape background
@@ -1053,47 +1054,6 @@ void QgsLabelingGui::changeTextFont()
}
}

void QgsLabelingGui::updateFontViaStyle( const QString & fontstyle )
{
QFont styledfont;
bool foundmatch = false;
int fontSize = 12; // QFontDatabase::font() needs an integer for size
if ( !fontstyle.isEmpty() )
{
styledfont = mFontDB.font( mRefFont.family(), fontstyle, fontSize );
styledfont.setPointSizeF( mRefFont.pointSizeF() );
if ( QApplication::font().toString() != styledfont.toString() )
{
foundmatch = true;
}
}
if ( !foundmatch )
{
foreach ( const QString &style, mFontDB.styles( mRefFont.family() ) )
{
styledfont = mFontDB.font( mRefFont.family(), style, fontSize );
styledfont.setPointSizeF( mRefFont.pointSizeF() );
styledfont = styledfont.resolve( mRefFont );
if ( mRefFont.toString() == styledfont.toString() )
{
foundmatch = true;
break;
}
}
}
if ( foundmatch )
{
// styledfont.setPointSizeF( mRefFont.pointSizeF() );
styledfont.setCapitalization( mRefFont.capitalization() );
styledfont.setUnderline( mRefFont.underline() );
styledfont.setStrikeOut( mRefFont.strikeOut() );
styledfont.setWordSpacing( mRefFont.wordSpacing() );
styledfont.setLetterSpacing( QFont::AbsoluteSpacing, mRefFont.letterSpacing() );
mRefFont = styledfont;
}
// if no match, style combobox will be left blank, which should not affect engine labeling
}

void QgsLabelingGui::updateFont( QFont font )
{
// update background reference font
@@ -1397,7 +1357,7 @@ void QgsLabelingGui::on_mFontCapitalsComboBox_currentIndexChanged( int index )

void QgsLabelingGui::on_mFontStyleComboBox_currentIndexChanged( const QString & text )
{
updateFontViaStyle( text );
QgsFontUtils::updateFontViaStyle( mRefFont, text );
updateFont( mRefFont );
}

@@ -85,7 +85,6 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void blockInitSignals( bool block );
void blockFontChangeSignals( bool blk );
void setPreviewBackground( QColor color );
void updateFontViaStyle( const QString & fontstyle );
void syncDefinedCheckboxFrame( QgsDataDefinedButton* ddBtn, QCheckBox* chkBx, QFrame* f );
void populateFontCapitalsComboBox();
void populateFontStyleComboBox();
@@ -40,6 +40,7 @@

#include "diagram/qgsdiagram.h"
#include "qgsdiagramrendererv2.h"
#include "qgsfontutils.h"
#include "qgslabelsearchtree.h"
#include "qgsexpression.h"
#include "qgsdatadefined.h"
@@ -783,27 +784,6 @@ void QgsPalLayerSettings::readDataDefinedProperty( QgsVectorLayer* layer,
}
}

void QgsPalLayerSettings::updateFontViaStyle( QFont& font, const QString & fontstyle )
{
if ( !fontstyle.isEmpty() )
{
QFont styledfont = mFontDB.font( font.family(), fontstyle, 12 );
if ( QApplication::font().toString() != styledfont.toString() )
{
if ( font.pointSizeF() != -1 )
{
styledfont.setPointSizeF( font.pointSizeF() );
}
else if ( font.pixelSize() != -1 )
{
styledfont.setPixelSize( font.pixelSize() );
}

font = styledfont;
}
}
}

void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
{
if ( layer->customProperty( "labeling" ).toString() != QString( "pal" ) )
@@ -824,7 +804,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
textFont = QFont( fontFamily, fontSize, fontWeight, fontItalic );
textFont.setPointSizeF( fontSize ); //double precision needed because of map units
textNamedStyle = layer->customProperty( "labeling/namedStyle", QVariant( "" ) ).toString();
updateFontViaStyle( textFont, textNamedStyle ); // must come after textFont.setPointSizeF()
QgsFontUtils::updateFontViaStyle( textFont, textNamedStyle ); // must come after textFont.setPointSizeF()
textFont.setCapitalization(( QFont::Capitalization )layer->customProperty( "labeling/fontCapitals", QVariant( 0 ) ).toUInt() );
textFont.setUnderline( layer->customProperty( "labeling/fontUnderline" ).toBool() );
textFont.setStrikeOut( layer->customProperty( "labeling/fontStrikeout" ).toBool() );
@@ -2319,12 +2299,14 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
QString family = exprVal.toString().trimmed();
QgsDebugMsgLevel( QString( "exprVal Font family:%1" ).arg( family ), 4 );

// testing for mFontDB.families().contains( ddFontFamily ) doesn't always work,
// because the families list needs looped to test for 'family [foundry]'
// which could bring unnecessary overhead, so fall back to default font instead
if ( labelFont.family() != family )
{
ddFontFamily = family;
// testing for ddFontFamily in QFontDatabase.families() may be slow to do for every feature
// (i.e. don't use QgsFontUtils::fontFamilyMatchOnSystem( family ) here)
if ( QgsFontUtils::fontFamilyOnSystem( family ) )
{
ddFontFamily = family;
}
}
}

@@ -2355,7 +2337,10 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
ddItalic = italic;
}

// TODO: update when pref for how to resolve missing family (use matching algorithm or just default font) is implemented
// (currently defaults to what has been read in from layer settings)
QFont newFont;
QFont appFont = QApplication::font();
bool newFontBuilt = false;
if ( ddBold || ddItalic )
{
@@ -2371,24 +2356,24 @@ void QgsPalLayerSettings::parseTextStyle( QFont& labelFont,
if ( !ddFontFamily.isEmpty() )
{
// both family and style are different, build font from database
QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, 12 );
if ( QApplication::font().toString() != styledfont.toString() )
QFont styledfont = mFontDB.font( ddFontFamily, ddFontStyle, appFont.pointSize() );
if ( appFont != styledfont )
{
newFont = styledfont;
newFontBuilt = true;
}
}

// update the font face style
updateFontViaStyle( newFontBuilt ? newFont : labelFont, ddFontStyle );
QgsFontUtils::updateFontViaStyle( newFontBuilt ? newFont : labelFont, ddFontStyle );
}
else if ( !ddFontFamily.isEmpty() )
{
if ( ddFontStyle.compare( "Ignore", Qt::CaseInsensitive ) != 0 )
{
// just family is different, build font from database
QFont styledfont = mFontDB.font( ddFontFamily, textNamedStyle, 12 );
if ( QApplication::font().toString() != styledfont.toString() )
QFont styledfont = mFontDB.font( ddFontFamily, textNamedStyle, appFont.pointSize() );
if ( appFont != styledfont )
{
newFont = styledfont;
newFontBuilt = true;
@@ -546,8 +546,6 @@ class CORE_EXPORT QgsPalLayerSettings
QMap<QgsPalLayerSettings::DataDefinedProperties, QPair<QString, int> > mDataDefinedNames;

QFontDatabase mFontDB;
/**Updates font with named style */
void updateFontViaStyle( QFont& font, const QString & fontstyle );
};

class CORE_EXPORT QgsLabelCandidate

0 comments on commit 44d89a4

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