From 7079f20ebf2c0ba10b1669b5e084ca2f06d3eee2 Mon Sep 17 00:00:00 2001 From: Larry Shaffer Date: Tue, 14 Aug 2012 19:45:14 -0600 Subject: [PATCH] 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.) --- src/app/qgslabelinggui.cpp | 148 ++-- src/app/qgslabelinggui.h | 9 +- src/app/qgslabelpreview.cpp | 13 +- src/app/qgslabelpreview.h | 4 +- src/core/qgspallabeling.cpp | 51 +- src/core/qgspallabeling.h | 9 +- src/ui/qgslabelingguibase.ui | 1272 ++++++++++++++++++---------------- 7 files changed, 849 insertions(+), 657 deletions(-) diff --git a/src/app/qgslabelinggui.cpp b/src/app/qgslabelinggui.cpp index e2425329c39..f042196a685 100644 --- a/src/app/qgslabelinggui.cpp +++ b/src/app/qgslabelinggui.cpp @@ -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( "" ) ); diff --git a/src/app/qgslabelinggui.h b/src/app/qgslabelinggui.h index 11631238b37..708ae37181a 100644 --- a/src/app/qgslabelinggui.h +++ b/src/app/qgslabelinggui.h @@ -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(); diff --git a/src/app/qgslabelpreview.cpp b/src/app/qgslabelpreview.cpp index 18339c14daa..e517d8d6afa 100644 --- a/src/app/qgslabelpreview.cpp +++ b/src/app/qgslabelpreview.cpp @@ -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() ); diff --git a/src/app/qgslabelpreview.h b/src/app/qgslabelpreview.h index 98ada57d5b1..e95ef3b0265 100644 --- a/src/app/qgslabelpreview.h +++ b/src/app/qgslabelpreview.h @@ -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; }; diff --git a/src/core/qgspallabeling.cpp b/src/core/qgspallabeling.cpp index c07d42f4489..6143085ec11 100644 --- a/src/core/qgspallabeling.cpp +++ b/src/core/qgspallabeling.cpp @@ -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 ); } diff --git a/src/core/qgspallabeling.h b/src/core/qgspallabeling.h index 04ce9af18eb..46fc397f6f0 100644 --- a/src/core/qgspallabeling.h +++ b/src/core/qgspallabeling.h @@ -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: diff --git a/src/ui/qgslabelingguibase.ui b/src/ui/qgslabelingguibase.ui index 67dd8204b62..53d4aba89b4 100644 --- a/src/ui/qgslabelingguibase.ui +++ b/src/ui/qgslabelingguibase.ui @@ -172,7 +172,7 @@ 0 0 686 - 654 + 706 @@ -335,186 +335,219 @@ true - - - - - - 16777215 - 16777215 - + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + 4 + + + 999999999.000000000000000 + + + 0.100000000000000 + + + + + + + true + + + + 0 + 0 + + + + + mm + + + + + map units + + + + + + + + + + Qt::Vertical + + + + + + + + + Pen Join style + + + + + + + + 0 + 0 + + + + + + + + + 0 + 0 + + + + Color area inside of pen stroke + + + true + + + + + + + + + + + + 0 + 0 + + + + + 32 + 0 + + + + ... + + + + + + + true + + + Transparency + + + + + + + true + + + + 0 + 0 + + + + + 100 + 0 + + + + + 16777215 + 16777215 + + + + 100 + + + Qt::Horizontal + + + + + + + true + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + % + + + 100 + + + + + + + + + + 0 + 0 + + + + Size + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Color + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 0 - - - - - - 0 - 0 - - - - Size - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - 2 - - - 0.100000000000000 - - - - - - - false - - - - 0 - 0 - - - - - mm - - - - - map units - - - - - - - - Qt::Vertical - - - - - - - - 0 - 0 - - - - Color - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 32 - 0 - - - - ... - - - - - - - true - - - Transparency - - - - - - - true - - - - 0 - 0 - - - - - 100 - 0 - - - - - 16777215 - 16777215 - - - - 100 - - - Qt::Horizontal - - - - - - - true - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - % - - - 100 - - - - @@ -690,6 +723,56 @@ + + + + Qt::Horizontal + + + QSizePolicy::Fixed + + + + 6 + 20 + + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + 8 + + + 152 + + + 4 + + + 24 + + + Qt::Horizontal + + + 4 + + + @@ -728,217 +811,6 @@ 0 - - - - false - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - line - - - 0.000000000000000 - - - 10.000000000000000 - - - 0.100000000000000 - - - 1.000000000000000 - - - - - - - false - - - - 0 - 0 - - - - - Left - - - - - Center - - - - - Right - - - - - - - - false - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - px - - - 1 - - - -100.000000000000000 - - - - - - - false - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - px - - - 1 - - - -100.000000000000000 - - - 0.100000000000000 - - - - - - - - 0 - 0 - - - - Multi-line align - - - - - - - - 0 - 0 - - - - Line height - - - - - - - - 0 - 0 - - - - Letter spacing - - - - - - - false - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - % - - - - - - 1 - - - 1000 - - - 1 - - - 100 - - - - - - - - 0 - 0 - - - - Word spacing - - - - - - - - 0 - 0 - - - - Character width - - - @@ -972,72 +844,192 @@ - - - - QLayout::SetDefaultConstraint - - - + + + + - + 0 0 - - - 32 - 0 - + + Multi-line align + + + + + + + + 0 + 0 + - ... + Word spacing - - - - true + + + + + 0 + 0 + - Transparency + Letter spacing - - - - true + + + + + 0 + 0 + - - - 100 - 0 - - - - - 16777215 - 16777215 - - - - 100 - - - Qt::Horizontal + + Line height - - + + - true + false - + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + line + + + 0.000000000000000 + + + 10.000000000000000 + + + 0.100000000000000 + + + 1.000000000000000 + + + + + + + false + + + + 0 + 0 + + + + + Left + + + + + Center + + + + + Right + + + + + + + + false + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + px + + + 1 + + + -100.000000000000000 + + + 0.100000000000000 + + + + + + + false + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + px + + + 1 + + + -100.000000000000000 + + + + + + + + 0 + 0 + + + + Character width + + + + + + + false + + + 0 0 @@ -1048,152 +1040,25 @@ % + + + + + 1 + + 1000 + + + 1 + + 100 - - - - false - - - - 16777215 - 16777215 - - - - - Mixed Case - - - - - All Uppercase - - - - - All Lowercase - - - - - Small Caps - - - - - Capitalize - - - - - - - - - 0 - 0 - - - - Style - - - - - - - - 0 - 0 - - - - Color - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - Size - - - - - - - QLayout::SetDefaultConstraint - - - - - - 0 - 0 - - - - - 100 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - 4 - - - 999999999.000000000000000 - - - - - - - - 0 - 0 - - - - - points - - - - - map units - - - - - - - - - - Qt::Vertical - - - @@ -1347,6 +1212,228 @@ + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 100 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + 4 + + + 999999999.000000000000000 + + + + + + + + 0 + 0 + + + + + points + + + + + map units + + + + + + + + + + Qt::Vertical + + + + + + + + 0 + 0 + + + + Color + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + Size + + + + + + + + 0 + 0 + + + + Style + + + + + + + false + + + + 16777215 + 16777215 + + + + + Mixed Case + + + + + All Uppercase + + + + + All Lowercase + + + + + Small Caps + + + + + Capitalize + + + + + + + + QLayout::SetDefaultConstraint + + + + + + 0 + 0 + + + + + 32 + 0 + + + + ... + + + + + + + true + + + Transparency + + + + + + + true + + + + 100 + 0 + + + + + 16777215 + 16777215 + + + + 100 + + + Qt::Horizontal + + + + + + + true + + + + 0 + 0 + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + % + + + 100 + + + + + @@ -2345,6 +2432,11 @@ QLabel
qgslabelpreview.h
+ + QgsPenJoinStyleComboBox + QComboBox +
qgspenstylecombobox.h
+
@@ -2405,12 +2497,12 @@ setValue(int) - 330 - 360 + 341 + 286 - 403 - 357 + 415 + 288 @@ -2421,12 +2513,12 @@ setValue(int) - 552 - 516 + 325 + 499 - 646 - 516 + 397 + 500 @@ -2437,12 +2529,12 @@ setValue(int) - 647 - 528 + 397 + 500 - 568 - 517 + 325 + 499 @@ -2453,12 +2545,12 @@ setValue(int) - 408 - 366 + 415 + 288 - 316 - 358 + 341 + 286