diff --git a/doc/api_break.dox b/doc/api_break.dox index fccdca2c69f..8c45436b9bf 100644 --- a/doc/api_break.dox +++ b/doc/api_break.dox @@ -610,6 +610,13 @@ QgsComposerObject::dataDefinedProperty instead. QgsComposerObject::setDataDefinedProperty() instead. - updatePictureExpression() was removed. +QgsComposerScaleBar {#qgis_api_break_3_0_QgsComposerScaleBar} +------------------- + +- setBrush() was removed. Use setFillColor() instead. +- setBrush2() was removed. Use setFillColor2() instead. +- setPen() was removed. Use setLineColor() and setLineWidth() instead. + QgsComposerTable {#qgis_api_break_3_0_QgsComposerTable} ---------------- diff --git a/python/core/composer/qgscomposerscalebar.sip b/python/core/composer/qgscomposerscalebar.sip index 7cff2addd36..c4109f1fd8b 100644 --- a/python/core/composer/qgscomposerscalebar.sip +++ b/python/core/composer/qgscomposerscalebar.sip @@ -134,6 +134,58 @@ class QgsComposerScaleBar: QgsComposerItem */ void setFontColor( const QColor& c ); + /** Returns the color used for fills in the scalebar. + * @see setFillColor() + * @see fillColor2() + * @note added in QGIS 3.0 + */ + QColor fillColor() const; + + /** Sets the color used for fills in the scalebar. + * @see fillColor() + * @see setFillColor2() + * @note added in QGIS 3.0 + */ + void setFillColor( const QColor& color ); + + /** Returns the secondary color used for fills in the scalebar. + * @see setFillColor2() + * @see fillColor() + * @note added in QGIS 3.0 + */ + QColor fillColor2() const; + + /** Sets the secondary color used for fills in the scalebar. + * @see fillColor2() + * @see setFillColor2() + * @note added in QGIS 3.0 + */ + void setFillColor2( const QColor& color ); + + /** Returns the color used for lines in the scalebar. + * @see setLineColor() + * @note added in QGIS 3.0 + */ + QColor lineColor() const; + + /** Sets the color used for lines in the scalebar. + * @see lineColor() + * @note added in QGIS 3.0 + */ + void setLineColor( const QColor& color ); + + /** Returns the line width in millimeters for lines in the scalebar. + * @see setLineWidth() + * @note added in QGIS 3.0 + */ + double lineWidth() const; + + /** Sets the line width in millimeters for lines in the scalebar. + * @see lineWidth() + * @note added in QGIS 3.0 + */ + void setLineWidth( double width ); + /** Returns the pen used for drawing the scalebar. * @returns QPen used for drawing the scalebar outlines. * @see setPen @@ -141,13 +193,6 @@ class QgsComposerScaleBar: QgsComposerItem */ QPen pen() const; - /** Sets the pen used for drawing the scalebar. - * @param pen QPen to use for drawing the scalebar outlines. - * @see pen - * @see setBrush - */ - void setPen( const QPen& pen ); - /** Returns the primary brush for the scalebar. * @returns QBrush used for filling the scalebar * @see setBrush @@ -156,14 +201,6 @@ class QgsComposerScaleBar: QgsComposerItem */ QBrush brush() const; - /** Sets primary brush for the scalebar. - * @param brush QBrush to use for filling the scalebar - * @see brush - * @see setBrush2 - * @see setPen - */ - void setBrush( const QBrush& brush ); - /** Returns the secondary brush for the scalebar. This is used for alternating color style scalebars, such * as single and double box styles. * @returns QBrush used for secondary color areas @@ -172,14 +209,6 @@ class QgsComposerScaleBar: QgsComposerItem */ QBrush brush2() const; - /** Sets secondary brush for the scalebar. This is used for alternating color style scalebars, such - * as single and double box styles. - * @param brush QBrush to use for secondary color areas - * @see brush2 - * @see setBrush - */ - void setBrush2( const QBrush& brush ); - double height() const; void setHeight( double h ); diff --git a/src/app/composer/qgscomposerscalebarwidget.cpp b/src/app/composer/qgscomposerscalebarwidget.cpp index d205b041bd3..39bd117580a 100644 --- a/src/app/composer/qgscomposerscalebarwidget.cpp +++ b/src/app/composer/qgscomposerscalebarwidget.cpp @@ -91,6 +91,15 @@ QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scale connect( mMapItemComboBox, SIGNAL( itemChanged( QgsComposerItem* ) ), this, SLOT( composerMapChanged( QgsComposerItem* ) ) ); + registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::ScalebarFillColor, + QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() ); + registerDataDefinedButton( mFillColor2DDBtn, QgsComposerObject::ScalebarFillColor2, + QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() ); + registerDataDefinedButton( mLineColorDDBtn, QgsComposerObject::ScalebarLineColor, + QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() ); + registerDataDefinedButton( mLineWidthDDBtn, QgsComposerObject::ScalebarLineWidth, + QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() ); + blockMemberSignals( false ); setGuiElements(); //set the GUI elements to the state of scaleBar } @@ -111,7 +120,7 @@ void QgsComposerScaleBarWidget::setGuiElements() mNumberOfSegmentsSpinBox->setValue( mComposerScaleBar->numSegments() ); mSegmentsLeftSpinBox->setValue( mComposerScaleBar->numSegmentsLeft() ); mSegmentSizeSpinBox->setValue( mComposerScaleBar->numUnitsPerSegment() ); - mLineWidthSpinBox->setValue( mComposerScaleBar->pen().widthF() ); + mLineWidthSpinBox->setValue( mComposerScaleBar->lineWidth() ); mHeightSpinBox->setValue( mComposerScaleBar->height() ); mMapUnitsPerBarUnitSpinBox->setValue( mComposerScaleBar->numMapUnitsPerScaleBarUnit() ); mLabelBarSpaceSpinBox->setValue( mComposerScaleBar->labelBarSpace() ); @@ -120,9 +129,9 @@ void QgsComposerScaleBarWidget::setGuiElements() mLineJoinStyleCombo->setPenJoinStyle( mComposerScaleBar->lineJoinStyle() ); mLineCapStyleCombo->setPenCapStyle( mComposerScaleBar->lineCapStyle() ); mFontColorButton->setColor( mComposerScaleBar->fontColor() ); - mFillColorButton->setColor( mComposerScaleBar->brush().color() ); - mFillColor2Button->setColor( mComposerScaleBar->brush2().color() ); - mStrokeColorButton->setColor( mComposerScaleBar->pen().color() ); + mFillColorButton->setColor( mComposerScaleBar->fillColor() ); + mFillColor2Button->setColor( mComposerScaleBar->fillColor2() ); + mStrokeColorButton->setColor( mComposerScaleBar->lineColor() ); //map combo box mMapItemComboBox->setItem( mComposerScaleBar->composerMap() ); @@ -154,7 +163,10 @@ void QgsComposerScaleBarWidget::setGuiElements() } mMinWidthSpinBox->setValue( mComposerScaleBar->minBarWidth() ); mMaxWidthSpinBox->setValue( mComposerScaleBar->maxBarWidth() ); - + updateDataDefinedButton( mFillColorDDBtn ); + updateDataDefinedButton( mFillColor2DDBtn ); + updateDataDefinedButton( mLineColorDDBtn ); + updateDataDefinedButton( mLineWidthDDBtn ); blockMemberSignals( false ); } @@ -169,9 +181,7 @@ void QgsComposerScaleBarWidget::on_mLineWidthSpinBox_valueChanged( double d ) mComposerScaleBar->beginCommand( tr( "Scalebar line width" ), QgsComposerMergeCommand::ScaleBarLineWidth ); disconnectUpdateSignal(); - QPen newPen = mComposerScaleBar->pen(); - newPen.setWidthF( d ); - mComposerScaleBar->setPen( newPen ); + mComposerScaleBar->setLineWidth( d ); mComposerScaleBar->update(); connectUpdateSignal(); mComposerScaleBar->endCommand(); @@ -280,9 +290,7 @@ void QgsComposerScaleBarWidget::on_mFillColorButton_colorChanged( const QColor& mComposerScaleBar->beginCommand( tr( "Scalebar color changed" ), QgsComposerMergeCommand::ScaleBarFillColor ); disconnectUpdateSignal(); - QBrush newBrush = mComposerScaleBar->brush(); - newBrush.setColor( newColor ); - mComposerScaleBar->setBrush( newBrush ); + mComposerScaleBar->setFillColor( newColor ); mComposerScaleBar->update(); connectUpdateSignal(); mComposerScaleBar->endCommand(); @@ -297,9 +305,7 @@ void QgsComposerScaleBarWidget::on_mFillColor2Button_colorChanged( const QColor mComposerScaleBar->beginCommand( tr( "Scalebar secondary color changed" ), QgsComposerMergeCommand::ScaleBarFill2Color ); disconnectUpdateSignal(); - QBrush newBrush = mComposerScaleBar->brush2(); - newBrush.setColor( newColor ); - mComposerScaleBar->setBrush2( newBrush ); + mComposerScaleBar->setFillColor2( newColor ); mComposerScaleBar->update(); connectUpdateSignal(); mComposerScaleBar->endCommand(); @@ -314,9 +320,7 @@ void QgsComposerScaleBarWidget::on_mStrokeColorButton_colorChanged( const QColor mComposerScaleBar->beginCommand( tr( "Scalebar line color changed" ), QgsComposerMergeCommand::ScaleBarStrokeColor ); disconnectUpdateSignal(); - QPen newPen = mComposerScaleBar->pen(); - newPen.setColor( newColor ); - mComposerScaleBar->setPen( newPen ); + mComposerScaleBar->setLineColor( newColor ); mComposerScaleBar->update(); connectUpdateSignal(); mComposerScaleBar->endCommand(); diff --git a/src/core/composer/qgscomposerobject.cpp b/src/core/composer/qgscomposerobject.cpp index 7b85dd619cb..15d27e942f3 100644 --- a/src/core/composer/qgscomposerobject.cpp +++ b/src/core/composer/qgscomposerobject.cpp @@ -63,6 +63,10 @@ const QgsPropertyDefinition QgsComposerObject::sPropertyNameMap { QgsComposerObject::PictureSvgOutlineWidth, "dataDefinedSvgOutlineWidth" }, { QgsComposerObject::LegendTitle, "dataDefinedLegendTitle" }, { QgsComposerObject::LegendColumnCount, "dataDefinedLegendColumns" }, + { QgsComposerObject::ScalebarFillColor, "dataDefinedScalebarFill" }, + { QgsComposerObject::ScalebarFillColor2, "dataDefinedScalebarFill2" }, + { QgsComposerObject::ScalebarLineColor, "dataDefinedScalebarLineColor" }, + { QgsComposerObject::ScalebarLineWidth, "dataDefinedScalebarLineWidth" }, }; diff --git a/src/core/composer/qgscomposerobject.h b/src/core/composer/qgscomposerobject.h index a4774f5c55e..29649a2a84f 100644 --- a/src/core/composer/qgscomposerobject.h +++ b/src/core/composer/qgscomposerobject.h @@ -81,6 +81,11 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext //legend item LegendTitle, //!< Legend title LegendColumnCount, //!< Legend column count + //scalebar item + ScalebarFillColor, //!< Scalebar fill color + ScalebarFillColor2, //!< Scalebar secondary fill color + ScalebarLineColor, //!< Scalebar line color + ScalebarLineWidth, //!< Scalebar line width }; static const QgsPropertyDefinition sPropertyNameMap; diff --git a/src/core/composer/qgscomposerscalebar.cpp b/src/core/composer/qgscomposerscalebar.cpp index 83c5db173f9..21ca9551bd5 100644 --- a/src/core/composer/qgscomposerscalebar.cpp +++ b/src/core/composer/qgscomposerscalebar.cpp @@ -225,6 +225,41 @@ void QgsComposerScaleBar::invalidateCurrentMap() mComposerMap = nullptr; } +void QgsComposerScaleBar::refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property, const QgsExpressionContext* context ) +{ + QgsExpressionContext scopedContext = createExpressionContext(); + const QgsExpressionContext* evalContext = context ? context : &scopedContext; + + bool forceUpdate = false; + //updates data defined properties and redraws item to match + if ( property == QgsComposerObject::ScalebarFillColor || property == QgsComposerObject::AllProperties ) + { + mBrush.setColor( mProperties.valueAsColor( QgsComposerObject::ScalebarFillColor, *evalContext, mFillColor ) ); + forceUpdate = true; + } + if ( property == QgsComposerObject::ScalebarFillColor2 || property == QgsComposerObject::AllProperties ) + { + mBrush2.setColor( mProperties.valueAsColor( QgsComposerObject::ScalebarFillColor2, *evalContext, mFillColor2 ) ); + forceUpdate = true; + } + if ( property == QgsComposerObject::ScalebarLineColor || property == QgsComposerObject::AllProperties ) + { + mPen.setColor( mProperties.valueAsColor( QgsComposerObject::ScalebarLineColor, *evalContext, mLineColor ) ); + forceUpdate = true; + } + if ( property == QgsComposerObject::ScalebarLineWidth || property == QgsComposerObject::AllProperties ) + { + mPen.setWidthF( mProperties.valueAsDouble( QgsComposerObject::ScalebarLineWidth, *evalContext, mLineWidth ) ); + forceUpdate = true; + } + if ( forceUpdate ) + { + update(); + } + + QgsComposerObject::refreshDataDefinedProperty( property, context ); +} + // nextNiceNumber(4573.23, d) = 5000 (d=1) -> 4600 (d=10) -> 4580 (d=100) -> 4574 (d=1000) -> etc inline double nextNiceNumber( double a, double d = 1 ) { @@ -385,15 +420,15 @@ void QgsComposerScaleBar::applyDefaultSettings() //default to no background setBackgroundEnabled( false ); - mPen = QPen( Qt::black ); + mPen = QPen( mLineColor ); mPen.setJoinStyle( mLineJoinStyle ); mPen.setCapStyle( mLineCapStyle ); - mPen.setWidthF( 0.3 ); + mPen.setWidthF( mLineWidth ); - mBrush.setColor( Qt::black ); + mBrush.setColor( mFillColor ); mBrush.setStyle( Qt::SolidPattern ); - mBrush2.setColor( Qt::white ); + mBrush2.setColor( mFillColor2 ); mBrush2.setStyle( Qt::SolidPattern ); //get default composer font from settings @@ -681,7 +716,7 @@ bool QgsComposerScaleBar::writeXml( QDomElement& elem, QDomDocument & doc ) cons composerScaleBarElem.setAttribute( QStringLiteral( "segmentMillimeters" ), QString::number( mSegmentMillimeters ) ); composerScaleBarElem.setAttribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QString::number( mNumMapUnitsPerScaleBarUnit ) ); composerScaleBarElem.appendChild( QgsFontUtils::toXmlElement( mFont, doc, QStringLiteral( "scaleBarFont" ) ) ); - composerScaleBarElem.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mPen.widthF() ) ); + composerScaleBarElem.setAttribute( QStringLiteral( "outlineWidth" ), QString::number( mLineWidth ) ); composerScaleBarElem.setAttribute( QStringLiteral( "unitLabel" ), mUnitLabeling ); composerScaleBarElem.setAttribute( QStringLiteral( "units" ), mUnits ); composerScaleBarElem.setAttribute( QStringLiteral( "lineJoinStyle" ), QgsSymbolLayerUtils::encodePenJoinStyle( mLineJoinStyle ) ); @@ -703,29 +738,26 @@ bool QgsComposerScaleBar::writeXml( QDomElement& elem, QDomDocument & doc ) cons //fill color QDomElement fillColorElem = doc.createElement( QStringLiteral( "fillColor" ) ); - QColor fillColor = mBrush.color(); - fillColorElem.setAttribute( QStringLiteral( "red" ), QString::number( fillColor.red() ) ); - fillColorElem.setAttribute( QStringLiteral( "green" ), QString::number( fillColor.green() ) ); - fillColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( fillColor.blue() ) ); - fillColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( fillColor.alpha() ) ); + fillColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mFillColor.red() ) ); + fillColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mFillColor.green() ) ); + fillColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mFillColor.blue() ) ); + fillColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mFillColor.alpha() ) ); composerScaleBarElem.appendChild( fillColorElem ); //fill color 2 QDomElement fillColor2Elem = doc.createElement( QStringLiteral( "fillColor2" ) ); - QColor fillColor2 = mBrush2.color(); - fillColor2Elem.setAttribute( QStringLiteral( "red" ), QString::number( fillColor2.red() ) ); - fillColor2Elem.setAttribute( QStringLiteral( "green" ), QString::number( fillColor2.green() ) ); - fillColor2Elem.setAttribute( QStringLiteral( "blue" ), QString::number( fillColor2.blue() ) ); - fillColor2Elem.setAttribute( QStringLiteral( "alpha" ), QString::number( fillColor2.alpha() ) ); + fillColor2Elem.setAttribute( QStringLiteral( "red" ), QString::number( mFillColor2.red() ) ); + fillColor2Elem.setAttribute( QStringLiteral( "green" ), QString::number( mFillColor2.green() ) ); + fillColor2Elem.setAttribute( QStringLiteral( "blue" ), QString::number( mFillColor2.blue() ) ); + fillColor2Elem.setAttribute( QStringLiteral( "alpha" ), QString::number( mFillColor2.alpha() ) ); composerScaleBarElem.appendChild( fillColor2Elem ); //pen color QDomElement strokeColorElem = doc.createElement( QStringLiteral( "strokeColor" ) ); - QColor strokeColor = mPen.color(); - strokeColorElem.setAttribute( QStringLiteral( "red" ), QString::number( strokeColor.red() ) ); - strokeColorElem.setAttribute( QStringLiteral( "green" ), QString::number( strokeColor.green() ) ); - strokeColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( strokeColor.blue() ) ); - strokeColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( strokeColor.alpha() ) ); + strokeColorElem.setAttribute( QStringLiteral( "red" ), QString::number( mLineColor.red() ) ); + strokeColorElem.setAttribute( QStringLiteral( "green" ), QString::number( mLineColor.green() ) ); + strokeColorElem.setAttribute( QStringLiteral( "blue" ), QString::number( mLineColor.blue() ) ); + strokeColorElem.setAttribute( QStringLiteral( "alpha" ), QString::number( mLineColor.alpha() ) ); composerScaleBarElem.appendChild( strokeColorElem ); //font color @@ -761,7 +793,8 @@ bool QgsComposerScaleBar::readXml( const QDomElement& itemElem, const QDomDocume mMaxBarWidth = itemElem.attribute( QStringLiteral( "maxBarWidth" ), QStringLiteral( "150" ) ).toInt(); mSegmentMillimeters = itemElem.attribute( QStringLiteral( "segmentMillimeters" ), QStringLiteral( "0.0" ) ).toDouble(); mNumMapUnitsPerScaleBarUnit = itemElem.attribute( QStringLiteral( "numMapUnitsPerScaleBarUnit" ), QStringLiteral( "1.0" ) ).toDouble(); - mPen.setWidthF( itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble() ); + mLineWidth = itemElem.attribute( QStringLiteral( "outlineWidth" ), QStringLiteral( "0.3" ) ).toDouble(); + mPen.setWidthF( mLineWidth ); mUnitLabeling = itemElem.attribute( QStringLiteral( "unitLabel" ) ); mLineJoinStyle = QgsSymbolLayerUtils::decodePenJoinStyle( itemElem.attribute( QStringLiteral( "lineJoinStyle" ), QStringLiteral( "miter" ) ) ); mPen.setJoinStyle( mLineJoinStyle ); @@ -788,12 +821,14 @@ bool QgsComposerScaleBar::readXml( const QDomElement& itemElem, const QDomDocume if ( redOk && greenOk && blueOk && alphaOk ) { - mBrush.setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) ); + mFillColor = QColor( fillRed, fillGreen, fillBlue, fillAlpha ); + mBrush.setColor( mFillColor ); } } else { - mBrush.setColor( QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ) ); + mFillColor = QColor( itemElem.attribute( QStringLiteral( "brushColor" ), QStringLiteral( "#000000" ) ) ); + mBrush.setColor( mFillColor ); } //fill color 2 @@ -811,12 +846,14 @@ bool QgsComposerScaleBar::readXml( const QDomElement& itemElem, const QDomDocume if ( redOk && greenOk && blueOk && alphaOk ) { - mBrush2.setColor( QColor( fillRed, fillGreen, fillBlue, fillAlpha ) ); + mFillColor2 = QColor( fillRed, fillGreen, fillBlue, fillAlpha ); + mBrush2.setColor( mFillColor2 ); } } else { - mBrush2.setColor( QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ) ); + mFillColor2 = QColor( itemElem.attribute( QStringLiteral( "brush2Color" ), QStringLiteral( "#ffffff" ) ) ); + mBrush2.setColor( mFillColor2 ); } //stroke color @@ -834,12 +871,14 @@ bool QgsComposerScaleBar::readXml( const QDomElement& itemElem, const QDomDocume if ( redOk && greenOk && blueOk && alphaOk ) { - mPen.setColor( QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ) ); + mLineColor = QColor( strokeRed, strokeGreen, strokeBlue, strokeAlpha ); + mPen.setColor( mLineColor ); } } else { - mPen.setColor( QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ) ); + mLineColor = QColor( itemElem.attribute( QStringLiteral( "penColor" ), QStringLiteral( "#000000" ) ) ); + mPen.setColor( mLineColor ); } //font color diff --git a/src/core/composer/qgscomposerscalebar.h b/src/core/composer/qgscomposerscalebar.h index 5402d5a3181..f8c54b02d4a 100644 --- a/src/core/composer/qgscomposerscalebar.h +++ b/src/core/composer/qgscomposerscalebar.h @@ -159,6 +159,58 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem */ void setFontColor( const QColor& c ) {mFontColor = c;} + /** Returns the color used for fills in the scalebar. + * @see setFillColor() + * @see fillColor2() + * @note added in QGIS 3.0 + */ + QColor fillColor() const {return mFillColor;} + + /** Sets the color used for fills in the scalebar. + * @see fillColor() + * @see setFillColor2() + * @note added in QGIS 3.0 + */ + void setFillColor( const QColor& color ) {mFillColor = color; mBrush.setColor( color ); } + + /** Returns the secondary color used for fills in the scalebar. + * @see setFillColor2() + * @see fillColor() + * @note added in QGIS 3.0 + */ + QColor fillColor2() const {return mFillColor2;} + + /** Sets the secondary color used for fills in the scalebar. + * @see fillColor2() + * @see setFillColor2() + * @note added in QGIS 3.0 + */ + void setFillColor2( const QColor& color ) {mFillColor2 = color; mBrush2.setColor( color ); } + + /** Returns the color used for lines in the scalebar. + * @see setLineColor() + * @note added in QGIS 3.0 + */ + QColor lineColor() const {return mLineColor;} + + /** Sets the color used for lines in the scalebar. + * @see lineColor() + * @note added in QGIS 3.0 + */ + void setLineColor( const QColor& color ) { mLineColor = color; mPen.setColor( mLineColor ); } + + /** Returns the line width in millimeters for lines in the scalebar. + * @see setLineWidth() + * @note added in QGIS 3.0 + */ + double lineWidth() const {return mLineWidth;} + + /** Sets the line width in millimeters for lines in the scalebar. + * @see lineWidth() + * @note added in QGIS 3.0 + */ + void setLineWidth( double width ) { mLineWidth = width; mPen.setWidthF( width ); } + /** Returns the pen used for drawing the scalebar. * @returns QPen used for drawing the scalebar outlines. * @see setPen @@ -166,13 +218,6 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem */ QPen pen() const {return mPen;} - /** Sets the pen used for drawing the scalebar. - * @param pen QPen to use for drawing the scalebar outlines. - * @see pen - * @see setBrush - */ - void setPen( const QPen& pen ) {mPen = pen;} - /** Returns the primary brush for the scalebar. * @returns QBrush used for filling the scalebar * @see setBrush @@ -181,14 +226,6 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem */ QBrush brush() const {return mBrush;} - /** Sets primary brush for the scalebar. - * @param brush QBrush to use for filling the scalebar - * @see brush - * @see setBrush2 - * @see setPen - */ - void setBrush( const QBrush& brush ) {mBrush = brush;} - /** Returns the secondary brush for the scalebar. This is used for alternating color style scalebars, such * as single and double box styles. * @returns QBrush used for secondary color areas @@ -197,14 +234,6 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem */ QBrush brush2() const {return mBrush2;} - /** Sets secondary brush for the scalebar. This is used for alternating color style scalebars, such - * as single and double box styles. - * @param brush QBrush to use for secondary color areas - * @see brush2 - * @see setBrush - */ - void setBrush2( const QBrush& brush ) {mBrush2 = brush;} - double height() const {return mHeight;} void setHeight( double h ) {mHeight = h;} @@ -307,6 +336,7 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem void updateSegmentSize(); //! Sets mCompositionMap to 0 if the map is deleted void invalidateCurrentMap(); + virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties, const QgsExpressionContext* context = nullptr ) override; protected: @@ -332,6 +362,14 @@ class CORE_EXPORT QgsComposerScaleBar: public QgsComposerItem //! Font QFont mFont; QColor mFontColor; + //! Fill color + QColor mFillColor = QColor( 0, 0, 0 ); + //! Secondary fill color + QColor mFillColor2 = QColor( 255, 255, 255 ); + //! Line color + QColor mLineColor = QColor( 0, 0, 0 ); + //! Line width + double mLineWidth = 0.3; //! Outline QPen mPen; //! Fill diff --git a/src/ui/composer/qgscomposerscalebarwidgetbase.ui b/src/ui/composer/qgscomposerscalebarwidgetbase.ui index a54e17f5811..226c285bc4f 100644 --- a/src/ui/composer/qgscomposerscalebarwidgetbase.ui +++ b/src/ui/composer/qgscomposerscalebarwidgetbase.ui @@ -60,9 +60,9 @@ 0 - 0 - 437 - 768 + -213 + 440 + 855 @@ -350,48 +350,7 @@ true - - - - - Box margin - - - - - - - - - - mm - - - - - - - Labels margin - - - - - - - - - - mm - - - - - - - Line width - - - + @@ -420,26 +379,13 @@ - - + + - Join style + Box margin - - - - - - - Cap style - - - - - - @@ -447,7 +393,68 @@ - + + + + Labels margin + + + + + + + Line width + + + + + + + Cap style + + + + + + + Join style + + + + + + + ... + + + + + + + + + + mm + + + + + + + + + + mm + + + + + + + + + + @@ -467,14 +474,7 @@ true - - - - - Font color - - - + @@ -511,96 +511,23 @@ - - + + + + + 0 + 0 + + - Fill color + Font... - - - - - - - 120 - 0 - - - - - 120 - 16777215 - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - + + - Secondary fill color - - - - - - - - - - 120 - 0 - - - - - 120 - 16777215 - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Line color + Font color @@ -625,6 +552,13 @@ + + + + ... + + + @@ -640,19 +574,113 @@ - - - - - 0 - 0 - - + + - Font... + Secondary fill color + + + + Fill color + + + + + + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + + + + + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Line color + + + + + + + + + + 120 + 0 + + + + + 120 + 16777215 + + + + + + + + + + + ... + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + @@ -670,26 +698,26 @@
qgscolorbutton.h
1 + + QgsDataDefinedButtonV2 + QToolButton +
qgsdatadefinedbuttonv2.h
+
QgsDoubleSpinBox QDoubleSpinBox
qgsdoublespinbox.h
- - QgsPenJoinStyleComboBox - QComboBox -
qgspenstylecombobox.h
-
- - QgsPenCapStyleComboBox - QComboBox -
qgspenstylecombobox.h
-
QgsSpinBox QSpinBox
qgsspinbox.h
+ + QgsPenJoinStyleComboBox + QComboBox +
qgspenstylecombobox.h
+
QgsCollapsibleGroupBoxBasic QGroupBox @@ -701,6 +729,11 @@ QComboBox
qgscomposeritemcombobox.h
+ + QgsPenCapStyleComboBox + QComboBox +
qgspenstylecombobox.h
+
scrollArea @@ -724,6 +757,7 @@ mBoxSizeSpinBox mLabelBarSpaceSpinBox mLineWidthSpinBox + mLineWidthDDBtn mLineJoinStyleCombo mLineCapStyleCombo mAlignmentComboBox @@ -731,8 +765,11 @@ mFontButton mFontColorButton mFillColorButton + mFillColorDDBtn mFillColor2Button + mFillColor2DDBtn mStrokeColorButton + mLineColorDDBtn diff --git a/tests/src/core/testqgscomposerscalebar.cpp b/tests/src/core/testqgscomposerscalebar.cpp index efa220412a2..23c77308212 100644 --- a/tests/src/core/testqgscomposerscalebar.cpp +++ b/tests/src/core/testqgscomposerscalebar.cpp @@ -24,6 +24,7 @@ #include "qgsrasterlayer.h" #include "qgsrasterdataprovider.h" #include "qgsfontutils.h" +#include "qgsproperty.h" #include "qgsproject.h" #include @@ -53,6 +54,7 @@ class TestQgsComposerScaleBar : public QObject void doubleBox(); void numeric(); void tick(); + void dataDefined(); private: QgsComposition* mComposition; @@ -61,7 +63,6 @@ class TestQgsComposerScaleBar : public QObject QgsRasterLayer* mRasterLayer; QgsMapSettings *mMapSettings; QString mReport; - QPen mPrevPen; }; void TestQgsComposerScaleBar::initTestCase() @@ -110,9 +111,7 @@ void TestQgsComposerScaleBar::initTestCase() mComposerScaleBar->setNumSegmentsLeft( 0 ); mComposerScaleBar->setNumSegments( 2 ); mComposerScaleBar->setHeight( 5 ); - QPen scalePen = mComposerScaleBar->pen(); - scalePen.setWidthF( 1.0 ); - mComposerScaleBar->setPen( scalePen ); + mComposerScaleBar->setLineWidth( 1.0 ); qWarning() << "scalebar font: " << mComposerScaleBar->font().toString() << " exactMatch:" << mComposerScaleBar->font().exactMatch(); @@ -158,12 +157,9 @@ void TestQgsComposerScaleBar::singleBox() void TestQgsComposerScaleBar::singleBoxAlpha() { mComposerScaleBar->setStyle( QStringLiteral( "Single Box" ) ); - mComposerScaleBar->setBrush( QBrush( QColor( 255, 0, 0, 100 ) ) ); - mComposerScaleBar->setBrush2( QBrush( QColor( 0, 255, 0, 50 ) ) ); - mPrevPen = mComposerScaleBar->pen(); - QPen newPen = mPrevPen; - newPen.setColor( QColor( 0, 0, 255, 150 ) ); - mComposerScaleBar->setPen( newPen ); + mComposerScaleBar->setFillColor( QColor( 255, 0, 0, 100 ) ); + mComposerScaleBar->setFillColor2( QColor( 0, 255, 0, 50 ) ); + mComposerScaleBar->setLineColor( QColor( 0, 0, 255, 150 ) ); mComposerScaleBar->setFontColor( QColor( 255, 0, 255, 100 ) ); QgsCompositionChecker checker( QStringLiteral( "composerscalebar_singlebox_alpha" ), mComposition ); checker.setControlPathPrefix( QStringLiteral( "composer_scalebar" ) ); @@ -173,9 +169,10 @@ void TestQgsComposerScaleBar::singleBoxAlpha() void TestQgsComposerScaleBar::doubleBox() { // cleanup singleBoxAlpha - mComposerScaleBar->setBrush( QBrush( Qt::black ) ); - mComposerScaleBar->setBrush2( QBrush( Qt::white ) ); - mComposerScaleBar->setPen( mPrevPen ); + mComposerScaleBar->setFillColor( Qt::black ); + mComposerScaleBar->setFillColor2( Qt::white ); + mComposerScaleBar->setLineColor( Qt::black ); + mComposerScaleBar->setLineWidth( 0.3 ); mComposerScaleBar->setFontColor( Qt::black ); mComposerScaleBar->setStyle( QStringLiteral( "Double Box" ) ); @@ -201,5 +198,19 @@ void TestQgsComposerScaleBar::tick() QVERIFY( checker.testComposition( mReport, 0, 0 ) ); } +void TestQgsComposerScaleBar::dataDefined() +{ + mComposerScaleBar->dataDefinedProperties().setProperty( QgsComposerObject::ScalebarFillColor, new QgsExpressionBasedProperty( "'red'" ) ); + mComposerScaleBar->dataDefinedProperties().setProperty( QgsComposerObject::ScalebarFillColor2, new QgsExpressionBasedProperty( "'blue'" ) ); + mComposerScaleBar->dataDefinedProperties().setProperty( QgsComposerObject::ScalebarLineColor, new QgsExpressionBasedProperty( "'yellow'" ) ); + mComposerScaleBar->dataDefinedProperties().setProperty( QgsComposerObject::ScalebarLineWidth, new QgsExpressionBasedProperty( "1.2" ) ); + mComposerScaleBar->refreshDataDefinedProperty(); + QCOMPARE( mComposerScaleBar->brush().color().name(), QColor( 255, 0, 0 ).name() ); + QCOMPARE( mComposerScaleBar->brush2().color().name(), QColor( 0, 0, 255 ).name() ); + QCOMPARE( mComposerScaleBar->pen().color().name(), QColor( 255, 255, 0 ).name() ); + QCOMPARE( mComposerScaleBar->pen().widthF(), 1.2 ); + mComposerScaleBar->setDataDefinedProperties( QgsPropertyCollection() ); +} + QGSTEST_MAIN( TestQgsComposerScaleBar ) #include "testqgscomposerscalebar.moc"