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.)
This commit is contained in:
Larry Shaffer 2012-08-14 19:45:14 -06:00
parent ac4486a7a1
commit 7079f20ebf
7 changed files with 849 additions and 657 deletions

View File

@ -43,14 +43,18 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
setupUi( this );
mRefFont = lblFontPreview->font();
mPreviewBackgroundBtn->setColor( Qt::white );
connect( mPreviewBackgroundBtn, SIGNAL( clicked() ), this, SLOT( changePreviewBackground( ) ) );
mPreviewSize = 24;
connect( btnTextColor, SIGNAL( clicked() ), this, SLOT( changeTextColor() ) );
connect( btnChangeFont, SIGNAL( clicked() ), this, SLOT( changeTextFont() ) );
connect( mFontSizeUnitComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mFontTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
connect( chkBuffer, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
connect( btnBufferColor, SIGNAL( clicked() ), this, SLOT( changeBufferColor() ) );
connect( spinBufferSize, SIGNAL( valueChanged( double ) ), this, SLOT( updatePreview() ) );
connect( mBufferTranspSpinBox, SIGNAL( valueChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mBufferJoinStyleComboBox, SIGNAL( currentIndexChanged( int ) ), this, SLOT( updatePreview() ) );
connect( mBufferTranspFillChbx, SIGNAL( toggled( bool ) ), this, SLOT( updatePreview() ) );
connect( btnEngineSettings, SIGNAL( clicked() ), this, SLOT( showEngineConfigDialog() ) );
connect( btnExpression, SIGNAL( clicked() ), this, SLOT( showExpressionDialog() ) );
@ -146,6 +150,9 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
wrapCharacterEdit->setText( lyr.wrapChar );
chkPreserveRotation->setChecked( lyr.preserveRotation );
mPreviewBackgroundBtn->setColor( lyr.previewBkgrdColor );
setPreviewBackground( lyr.previewBkgrdColor );
bool scaleBased = ( lyr.scaleMin != 0 && lyr.scaleMax != 0 );
chkScaleBasedVisibility->setChecked( scaleBased );
if ( scaleBased )
@ -157,12 +164,24 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
bool buffer = ( lyr.bufferSize != 0 );
chkBuffer->setChecked( buffer );
if ( buffer )
{
spinBufferSize->setValue( lyr.bufferSize );
if ( lyr.bufferSizeInMapUnits )
{
mBufferUnitComboBox->setCurrentIndex( 1 );
}
else
{
mBufferUnitComboBox->setCurrentIndex( 0 );
}
btnBufferColor->setColor( lyr.bufferColor );
mBufferTranspSpinBox->setValue( lyr.bufferTransp );
mBufferJoinStyleComboBox->setPenJoinStyle( lyr.bufferJoinStyle );
mBufferTranspFillChbx->setChecked( !lyr.bufferNoFill );
}
btnTextColor->setColor( lyr.textColor );
mFontTranspSpinBox->setValue( lyr.textTransp );
btnBufferColor->setColor( lyr.bufferColor );
mBufferTranspSpinBox->setValue( lyr.bufferTransp );
bool formattedNumbers = lyr.formatNumbers;
bool plusSign = lyr.plusSign;
@ -177,7 +196,6 @@ QgsLabelingGui::QgsLabelingGui( QgsPalLabeling* lbl, QgsVectorLayer* layer, QgsM
chkPlusSign->setChecked( plusSign );
}
if ( lyr.fontSizeInMapUnits )
{
mFontSizeUnitComboBox->setCurrentIndex( 1 );
@ -285,6 +303,7 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.textColor = btnTextColor->color();
lyr.textFont = mRefFont;
lyr.textTransp = mFontTranspSpinBox->value();
lyr.previewBkgrdColor = mPreviewBackgroundBtn->color();
lyr.enabled = chkEnableLabeling->isChecked();
lyr.priority = sliderPriority->value();
lyr.obstacle = !chkNoObstacle->isChecked();
@ -304,6 +323,9 @@ QgsPalLayerSettings QgsLabelingGui::layerSettings()
lyr.bufferSize = spinBufferSize->value();
lyr.bufferColor = btnBufferColor->color();
lyr.bufferTransp = mBufferTranspSpinBox->value();
lyr.bufferSizeInMapUnits = ( mBufferUnitComboBox->currentIndex() == 1 );
lyr.bufferJoinStyle = mBufferJoinStyleComboBox->penJoinStyle();
lyr.bufferNoFill = !mBufferTranspFillChbx->isChecked();
}
else
{
@ -438,6 +460,7 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
( *comboIt )->addItem( "", QVariant() );
}
// TODO: don't add field that aren't of appropriate type for the data defined property
const QgsFieldMap& fields = mLayer->dataProvider()->fields();
for ( QgsFieldMap::const_iterator it = fields.constBegin(); it != fields.constEnd(); it++ )
{
@ -471,18 +494,6 @@ void QgsLabelingGui::populateDataDefinedCombos( QgsPalLayerSettings& s )
setCurrentComboValue( mBufferTranspAttributeComboBox, s, QgsPalLayerSettings::BufferTransp );
}
void QgsLabelingGui::changePreviewBackground()
{
QColor color = QColorDialog::getColor( mPreviewBackgroundBtn->color(), this );
if ( !color.isValid() )
return;
mPreviewBackgroundBtn->setColor( color );
scrollArea_mPreview->widget()->setStyleSheet( QString( "background: rgb(%1, %2, %3);" ).arg( QString::number( color.red() ),
QString::number( color.green() ),
QString::number( color.blue() ) ) );
}
void QgsLabelingGui::changeTextColor()
{
QColor color = QColorDialog::getColor( btnTextColor->color(), this );
@ -504,9 +515,17 @@ void QgsLabelingGui::changeTextFont()
#endif
if ( ok )
{
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
{
// don't override map units size with selected size from font dialog
font.setPointSizeF( mFontSizeSpinBox->value() );
}
else
{
mFontSizeSpinBox->setValue( font.pointSizeF() );
}
updateFont( font );
}
mFontSizeSpinBox->setValue( mRefFont.pointSizeF() );
}
void QgsLabelingGui::updateFont( QFont font )
@ -517,12 +536,14 @@ void QgsLabelingGui::updateFont( QFont font )
mRefFont = font;
}
QString fontSizeUnitString = tr( "pt" );
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
{
fontSizeUnitString = tr( "map units" );
}
lblFontName->setText( QString( "%1, %2 %3" ).arg( font.family() ).arg( mRefFont.pointSizeF() ).arg( fontSizeUnitString ) );
lblFontName->setText( QString( "%1" ).arg( font.family() ) );
// update font name with font face
// QString dupFont = font.toString();
// QFont lblFont = lblFontName->font();
// lblFont.fromString( dupFont );
// lblFont.setPointSizeF( 14 );
// lblFontName->setFont(lblFont);
updatePreview();
}
@ -532,31 +553,55 @@ void QgsLabelingGui::updatePreview()
scrollPreview();
lblFontPreview->setFont( mRefFont );
QFont previewFont = lblFontPreview->font();
double fontSize = mFontSizeSpinBox->value();
double bufferSize = spinBufferSize->value();
if ( mFontSizeUnitComboBox->currentIndex() == 1 )
{
// TODO: maybe match current map zoom level instead?
previewFont.setPointSize( 24 );
groupBox_mPreview->setTitle( tr( "Sample @ 24 pts (using map units)" ) );
previewFont.setPointSize( mPreviewSize );
mPreviewSizeSlider->setEnabled( true );
if ( mBufferUnitComboBox->currentIndex() == 1 )
{
groupBox_mPreview->setTitle( tr( "Sample @ %1 pts (using map units)" ).arg( mPreviewSize ) );
bufferSize = ( mPreviewSize / fontSize ) * bufferSize / 2.5;
}
else
{
groupBox_mPreview->setTitle( tr( "Sample @ %1 pts (using map units, STROKE IN mm)" ).arg( mPreviewSize ) );
}
}
else
{
previewFont.setPointSize( mFontSizeSpinBox->value() );
groupBox_mPreview->setTitle( tr( "Sample" ) );
mPreviewSizeSlider->setEnabled( false );
if ( mBufferUnitComboBox->currentIndex() == 1 )
{
groupBox_mPreview->setTitle( tr( "Sample (stroke in map units, NOT SHOWN)" ) );
bufferSize = 0;
}
else
{
previewFont.setPointSize( fontSize );
groupBox_mPreview->setTitle( tr( "Sample" ) );
}
}
lblFontPreview->setFont( previewFont );
QColor prevColor = btnTextColor->color();
prevColor.setAlphaF(( 100.0 - ( double )( mFontTranspSpinBox->value() ) ) / 100.0 );
lblFontPreview->setTextColor( prevColor );
bool bufferNoFill = false;
if ( chkBuffer->isChecked() )
{
QColor buffColor = btnBufferColor->color();
buffColor.setAlphaF(( 100.0 - ( double )( mBufferTranspSpinBox->value() ) ) / 100.0 );
lblFontPreview->setBuffer( spinBufferSize->value(), buffColor );
bufferNoFill = !mBufferTranspFillChbx->isChecked();
lblFontPreview->setBuffer( bufferSize, buffColor, mBufferJoinStyleComboBox->penJoinStyle(), bufferNoFill );
}
else
{
lblFontPreview->setBuffer( 0, Qt::white );
lblFontPreview->setBuffer( 0, Qt::white, Qt::BevelJoin, bufferNoFill );
}
}
@ -565,6 +610,13 @@ void QgsLabelingGui::scrollPreview()
scrollArea_mPreview->ensureVisible( 0, 0, 0, 0 );
}
void QgsLabelingGui::setPreviewBackground( QColor color )
{
scrollArea_mPreview->widget()->setStyleSheet( QString( "background: rgb(%1, %2, %3);" ).arg( QString::number( color.red() ),
QString::number( color.green() ),
QString::number( color.blue() ) ) );
}
void QgsLabelingGui::showEngineConfigDialog()
{
QgsLabelEngineConfigDialog dlg( mLBL, this );
@ -593,6 +645,9 @@ void QgsLabelingGui::updateUi()
bool buf = chkBuffer->isChecked();
spinBufferSize->setEnabled( buf );
btnBufferColor->setEnabled( buf );
mBufferUnitComboBox->setEnabled( buf );
mBufferTranspSlider->setEnabled( buf );
mBufferTranspSpinBox->setEnabled( buf );
bool scale = chkScaleBasedVisibility->isChecked();
spinScaleMin->setEnabled( scale );
@ -633,24 +688,18 @@ void QgsLabelingGui::updateOptions()
}
}
void QgsLabelingGui::on_mPreviewSizeSlider_valueChanged( int i )
{
mPreviewSize = i;
updatePreview();
}
void QgsLabelingGui::on_mFontSizeSpinBox_valueChanged( double d )
{
mRefFont.setPointSizeF( d );
updateFont( mRefFont );
}
void QgsLabelingGui::on_mFontSizeUnitComboBox_currentIndexChanged( int index )
{
Q_UNUSED( index );
updateFont( mRefFont );
}
void QgsLabelingGui::on_mFontTranspSpinBox_valueChanged( int i )
{
Q_UNUSED( i );
updateFont( mRefFont );
}
void QgsLabelingGui::on_mFontWordSpacingSpinBox_valueChanged( double spacing )
{
mRefFont.setWordSpacing( spacing );
@ -663,9 +712,10 @@ void QgsLabelingGui::on_mFontLetterSpacingSpinBox_valueChanged( double spacing )
updateFont( mRefFont );
}
void QgsLabelingGui::on_mBufferTranspSpinBox_valueChanged( int i )
void QgsLabelingGui::on_mBufferUnitComboBox_currentIndexChanged( int index )
{
Q_UNUSED( i );
double singleStep = ( index == 1 ) ? 1.0 : 0.1 ; //1.0 for map units, 0.1 for mm
spinBufferSize->setSingleStep( singleStep );
updateFont( mRefFont );
}
@ -705,6 +755,16 @@ void QgsLabelingGui::on_mPreviewTextBtn_clicked()
updatePreview();
}
void QgsLabelingGui::on_mPreviewBackgroundBtn_clicked()
{
QColor color = QColorDialog::getColor( mPreviewBackgroundBtn->color(), this );
if ( !color.isValid() )
return;
mPreviewBackgroundBtn->setColor( color );
setPreviewBackground( color );
}
void QgsLabelingGui::disableDataDefinedAlignment()
{
mHorizontalAlignmentComboBox->setCurrentIndex( mHorizontalAlignmentComboBox->findText( "" ) );

View File

@ -38,7 +38,6 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
public slots:
void apply();
void changePreviewBackground();
void changeTextColor();
void changeTextFont();
void showEngineConfigDialog();
@ -50,17 +49,17 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
void scrollPreview();
void updateOptions();
void on_mPreviewSizeSlider_valueChanged( int i );
void on_mFontSizeSpinBox_valueChanged( double d );
void on_mFontSizeUnitComboBox_currentIndexChanged( int index );
void on_mFontTranspSpinBox_valueChanged( int i );
void on_mFontWordSpacingSpinBox_valueChanged( double spacing );
void on_mFontLetterSpacingSpinBox_valueChanged( double spacing );
void on_mBufferTranspSpinBox_valueChanged( int i );
void on_mBufferUnitComboBox_currentIndexChanged( int index );
void on_mXCoordinateComboBox_currentIndexChanged( const QString & text );
void on_mYCoordinateComboBox_currentIndexChanged( const QString & text );
void on_mPreviewTextEdit_textChanged( const QString & text );
void on_mPreviewTextBtn_clicked();
void on_mPreviewBackgroundBtn_clicked();
protected:
void populatePlacementMethods();
@ -78,6 +77,8 @@ class QgsLabelingGui : public QWidget, private Ui::QgsLabelingGuiBase
// background reference font
QFont mRefFont;
int mPreviewSize;
void setPreviewBackground( QColor color );
void disableDataDefinedAlignment();
void enableDataDefinedAlignment();

View File

@ -30,10 +30,12 @@ void QgsLabelPreview::setTextColor( QColor color )
update();
}
void QgsLabelPreview::setBuffer( double size, QColor color )
void QgsLabelPreview::setBuffer( double size, QColor color, Qt::PenJoinStyle joinStyle, bool noFill )
{
mBufferSize = size * 88 / 25.4; //assume standard dpi for preview
mBufferColor = color;
mBufferJoinStyle = joinStyle;
mBufferNoFill = noFill;
update();
}
@ -45,10 +47,15 @@ void QgsLabelPreview::paintEvent( QPaintEvent *e )
p.setRenderHint( QPainter::Antialiasing );
p.setFont( font() );
QFontMetrics fm( font() );
p.translate( 0, fm.ascent() + 4 );
double xtrans = 0;
if ( mBufferSize != 0 )
xtrans = mBufferSize / 4;
p.translate( xtrans, fm.ascent() + 4 );
if ( mBufferSize != 0 )
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor );
QgsPalLabeling::drawLabelBuffer( &p, text(), font(), mBufferSize, mBufferColor, mBufferJoinStyle, mBufferNoFill );
p.setPen( mTextColor );
p.drawText( 0, 0, text() );

View File

@ -24,7 +24,7 @@ class QgsLabelPreview : public QLabel
void setTextColor( QColor color );
void setBuffer( double size, QColor color );
void setBuffer( double size, QColor color, Qt::PenJoinStyle joinStyle, bool noFill = false );
void setFont( QFont f ) { mFont = f; }
QFont font() { return mFont; }
@ -34,6 +34,8 @@ class QgsLabelPreview : public QLabel
private:
int mBufferSize;
QColor mBufferColor;
Qt::PenJoinStyle mBufferJoinStyle;
bool mBufferNoFill;
QColor mTextColor;
QFont mFont;
};

View File

@ -144,6 +144,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
//textFont = QFont();
textColor = Qt::black;
textTransp = 0;
previewBkgrdColor = Qt::white;
enabled = false;
priority = 5;
obstacle = true;
@ -153,6 +154,8 @@ QgsPalLayerSettings::QgsPalLayerSettings()
bufferSize = 1;
bufferColor = Qt::white;
bufferTransp = 0;
bufferNoFill = false;
bufferJoinStyle = Qt::BevelJoin;
formatNumbers = false;
decimals = 3;
plusSign = false;
@ -163,6 +166,7 @@ QgsPalLayerSettings::QgsPalLayerSettings()
rasterCompressFactor = 1.0;
addDirectionSymbol = false;
fontSizeInMapUnits = false;
bufferSizeInMapUnits = false;
distInMapUnits = false;
wrapChar = "";
preserveRotation = true;
@ -178,6 +182,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
textFont = s.textFont;
textColor = s.textColor;
textTransp = s.textTransp;
previewBkgrdColor = s.previewBkgrdColor;
enabled = s.enabled;
priority = s.priority;
obstacle = s.obstacle;
@ -187,6 +192,8 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
bufferSize = s.bufferSize;
bufferColor = s.bufferColor;
bufferTransp = s.bufferTransp;
bufferJoinStyle = s.bufferJoinStyle;
bufferNoFill = s.bufferNoFill;
formatNumbers = s.formatNumbers;
decimals = s.decimals;
plusSign = s.plusSign;
@ -197,6 +204,7 @@ QgsPalLayerSettings::QgsPalLayerSettings( const QgsPalLayerSettings& s )
rasterCompressFactor = s.rasterCompressFactor;
addDirectionSymbol = s.addDirectionSymbol;
fontSizeInMapUnits = s.fontSizeInMapUnits;
bufferSizeInMapUnits = s.bufferSizeInMapUnits;
distInMapUnits = s.distInMapUnits;
wrapChar = s.wrapChar;
preserveRotation = s.preserveRotation;
@ -330,6 +338,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
textFont.setPointSizeF( fontSize ); //double precision needed because of map units
textColor = _readColor( layer, "labeling/textColor" );
textTransp = layer->customProperty( "labeling/textTransp" ).toInt();
previewBkgrdColor = QColor( layer->customProperty( "labeling/previewBkgrdColor", "#ffffff" ).toString() );
enabled = layer->customProperty( "labeling/enabled" ).toBool();
priority = layer->customProperty( "labeling/priority" ).toInt();
obstacle = layer->customProperty( "labeling/obstacle" ).toBool();
@ -339,6 +348,8 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
bufferSize = layer->customProperty( "labeling/bufferSize" ).toDouble();
bufferColor = _readColor( layer, "labeling/bufferColor" );
bufferTransp = layer->customProperty( "labeling/bufferTransp" ).toInt();
bufferJoinStyle = ( Qt::PenJoinStyle ) layer->customProperty( "labeling/bufferJoinStyle", QVariant( Qt::BevelJoin ) ).toUInt();
bufferNoFill = layer->customProperty( "labeling/bufferNoFill", QVariant( false ) ).toBool();
formatNumbers = layer->customProperty( "labeling/formatNumbers" ).toBool();
decimals = layer->customProperty( "labeling/decimals" ).toInt();
plusSign = layer->customProperty( "labeling/plussign" ).toInt();
@ -347,6 +358,7 @@ void QgsPalLayerSettings::readFromLayer( QgsVectorLayer* layer )
addDirectionSymbol = layer->customProperty( "labeling/addDirectionSymbol" ).toBool();
minFeatureSize = layer->customProperty( "labeling/minFeatureSize" ).toDouble();
fontSizeInMapUnits = layer->customProperty( "labeling/fontSizeInMapUnits" ).toBool();
bufferSizeInMapUnits = layer->customProperty( "labeling/bufferSizeInMapUnits" ).toBool();
distInMapUnits = layer->customProperty( "labeling/distInMapUnits" ).toBool();
wrapChar = layer->customProperty( "labeling/wrapChar" ).toString();
preserveRotation = layer->customProperty( "labeling/preserveRotation", QVariant( true ) ).toBool();
@ -372,6 +384,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
_writeColor( layer, "labeling/textColor", textColor );
layer->setCustomProperty( "labeling/textTransp", textTransp );
layer->setCustomProperty( "labeling/previewBkgrdColor", previewBkgrdColor.name() );
layer->setCustomProperty( "labeling/enabled", enabled );
layer->setCustomProperty( "labeling/priority", priority );
layer->setCustomProperty( "labeling/obstacle", obstacle );
@ -381,6 +394,8 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/bufferSize", bufferSize );
_writeColor( layer, "labeling/bufferColor", bufferColor );
layer->setCustomProperty( "labeling/bufferTransp", bufferTransp );
layer->setCustomProperty( "labeling/bufferJoinStyle", ( unsigned int )bufferJoinStyle );
layer->setCustomProperty( "labeling/bufferNoFill", bufferNoFill );
layer->setCustomProperty( "labeling/formatNumbers", formatNumbers );
layer->setCustomProperty( "labeling/decimals", decimals );
layer->setCustomProperty( "labeling/plussign", plusSign );
@ -389,6 +404,7 @@ void QgsPalLayerSettings::writeToLayer( QgsVectorLayer* layer )
layer->setCustomProperty( "labeling/addDirectionSymbol", addDirectionSymbol );
layer->setCustomProperty( "labeling/minFeatureSize", minFeatureSize );
layer->setCustomProperty( "labeling/fontSizeInMapUnits", fontSizeInMapUnits );
layer->setCustomProperty( "labeling/bufferSizeInMapUnits", bufferSizeInMapUnits );
layer->setCustomProperty( "labeling/distInMapUnits", distInMapUnits );
layer->setCustomProperty( "labeling/wrapChar", wrapChar );
layer->setCustomProperty( "labeling/preserveRotation", preserveRotation );
@ -508,7 +524,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
bool conversionOk;
int minScale = minScaleValue.toInt( &conversionOk );
// TODO: occasional floating point issues?
if ( conversionOk && int( context.rendererScale() ) < minScale )
if ( conversionOk && ( int )( context.rendererScale() ) < minScale )
{
return;
}
@ -525,7 +541,7 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
bool conversionOk;
int maxScale = maxScaleValue.toInt( &conversionOk );
// TODO: occasional floating point issues?
if ( conversionOk && int( context.rendererScale() ) > maxScale )
if ( conversionOk && ( int )( context.rendererScale() ) > maxScale )
{
return;
}
@ -782,17 +798,18 @@ void QgsPalLayerSettings::registerFeature( QgsVectorLayer* layer, QgsFeature& f
lbl->setIsPinned( dataDefinedPosition );
}
int QgsPalLayerSettings::sizeToPixel( double size, const QgsRenderContext& c ) const
int QgsPalLayerSettings::sizeToPixel( double size, const QgsRenderContext& c, bool buffer ) const
{
double pixelSize;
if ( fontSizeInMapUnits )
if (( !buffer && fontSizeInMapUnits ) || ( buffer && bufferSizeInMapUnits ) )
{
pixelSize = size / c.mapToPixel().mapUnitsPerPixel() * c.rasterScaleFactor();
}
else //font size in points
else //font size in points, or buffer in mm
{
double ptsTomm = buffer ? 1 : 0.3527;
// set font size from points to output size
pixelSize = 0.3527 * size * c.scaleFactor() * c.rasterScaleFactor();
pixelSize = ptsTomm * size * c.scaleFactor() * c.rasterScaleFactor();
}
return ( int )( pixelSize + 0.5 );
}
@ -1329,7 +1346,10 @@ void QgsPalLabeling::drawLabeling( QgsRenderContext& context )
bufferColor.setAlphaF(( 100.0 - ( double )( bufferTransp ) ) / 100.0 );
if ( lyr.bufferSize != 0 )
drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferSize, bufferColor, true );
{
int bufferPixelSize = lyr.sizeToPixel( bufferSize, context, true );
drawLabel( *it, painter, fontForLabel, fontColor, xform, bufferPixelSize, bufferColor, true );
}
drawLabel( *it, painter, fontForLabel, fontColor, xform );
@ -1448,7 +1468,7 @@ void QgsPalLabeling::drawLabelCandidateRect( pal::LabelPosition* lp, QPainter* p
drawLabelCandidateRect( lp->getNextPart(), painter, xform );
}
void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferSize,
void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferPixelSize,
const QColor& bufferColor, bool drawBuffer )
{
QgsPoint outPt = xform->transform( label->getX(), label->getY() );
@ -1496,7 +1516,8 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
if ( drawBuffer )
{
// we're drawing buffer
drawLabelBuffer( painter, multiLineList.at( i ), f, bufferSize * lyr.vectorScaleFactor * lyr.rasterCompressFactor , bufferColor );
//drawLabelBuffer( painter, multiLineList.at( i ), f, bufferSize * lyr.vectorScaleFactor * lyr.rasterCompressFactor , bufferColor );
drawLabelBuffer( painter, multiLineList.at( i ), f, bufferPixelSize , bufferColor, lyr.bufferJoinStyle, lyr.bufferNoFill );
}
else
{
@ -1510,20 +1531,24 @@ void QgsPalLabeling::drawLabel( pal::LabelPosition* label, QPainter* painter, co
painter->restore();
if ( label->getNextPart() )
drawLabel( label->getNextPart(), painter, f, c, xform, bufferSize, bufferColor, drawBuffer );
drawLabel( label->getNextPart(), painter, f, c, xform, bufferPixelSize, bufferColor, drawBuffer );
}
}
void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color )
void QgsPalLabeling::drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color, Qt::PenJoinStyle joinstyle, bool noFill )
{
QPainterPath path;
path.addText( 0, 0, font, text );
QPen pen( color );
pen.setWidthF( size );
pen.setJoinStyle( joinstyle );
p->setPen( pen );
// TODO: make pref for whether to fill buffer
// color.setAlpha( 0 );
// honor pref for whether to fill buffer
if ( noFill )
{
color.setAlpha( 0 );
}
p->setBrush( color );
p->drawPath( path );
}

View File

@ -120,6 +120,7 @@ class CORE_EXPORT QgsPalLayerSettings
QFont textFont;
QColor textColor;
int textTransp;
QColor previewBkgrdColor;
bool enabled;
int priority; // 0 = low, 10 = high
bool obstacle; // whether it's an obstacle
@ -130,6 +131,8 @@ class CORE_EXPORT QgsPalLayerSettings
double bufferSize; //buffer size (in mm)
QColor bufferColor;
int bufferTransp;
Qt::PenJoinStyle bufferJoinStyle;
bool bufferNoFill; //set interior of buffer to 100% transparent
bool formatNumbers;
int decimals;
bool plusSign;
@ -140,6 +143,7 @@ class CORE_EXPORT QgsPalLayerSettings
// Works only if Placement == Line
bool addDirectionSymbol;
bool fontSizeInMapUnits; //true if font size is in map units (otherwise in points)
bool bufferSizeInMapUnits; //true if buffer is in map units (otherwise in mm)
bool distInMapUnits; //true if distance is in map units (otherwise in mm)
QString wrapChar;
// called from register feature hook
@ -174,8 +178,9 @@ class CORE_EXPORT QgsPalLayerSettings
/**Calculates pixel size (considering output size should be in pixel or map units, scale factors and oversampling)
@param size size to convert
@param c rendercontext
@param buffer whether it buffer size being calculated
@return font pixel size*/
int sizeToPixel( double size, const QgsRenderContext& c ) const;
int sizeToPixel( double size, const QgsRenderContext& c , bool buffer = false ) const;
private:
/**Checks if a feature is larger than a minimum size (in mm)
@ -245,7 +250,7 @@ class CORE_EXPORT QgsPalLabeling : public QgsLabelingEngineInterface
//!drawLabel
void drawLabel( pal::LabelPosition* label, QPainter* painter, const QFont& f, const QColor& c, const QgsMapToPixel* xform, double bufferSize = -1,
const QColor& bufferColor = QColor( 255, 255, 255 ), bool drawBuffer = false );
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color );
static void drawLabelBuffer( QPainter* p, QString text, const QFont& font, double size, QColor color , Qt::PenJoinStyle joinstyle = Qt::BevelJoin, bool noFill = false );
protected:

File diff suppressed because it is too large Load Diff