Skip to content
Permalink
Browse files
[FEATURE][composer] Data defined scalebar colors and line width
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent ec9ba9c commit 6c53ba25e372eec66d2af512da06844864f37ef3
@@ -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}
----------------
@@ -134,20 +134,65 @@ 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
* @see brush
*/
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 );

@@ -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();
@@ -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" },
};


@@ -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;

0 comments on commit 6c53ba2

Please sign in to comment.