Skip to content

Commit

Permalink
[FEATURE][composer] Data defined scalebar colors and line width
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 23, 2017
1 parent ec9ba9c commit 6c53ba2
Show file tree
Hide file tree
Showing 9 changed files with 374 additions and 200 deletions.
7 changes: 7 additions & 0 deletions doc/api_break.dox
Expand Up @@ -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}
----------------
Expand Down
75 changes: 52 additions & 23 deletions python/core/composer/qgscomposerscalebar.sip
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 );

Expand Down
38 changes: 21 additions & 17 deletions src/app/composer/qgscomposerscalebarwidget.cpp
Expand Up @@ -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
}
Expand All @@ -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() );
Expand All @@ -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() );
Expand Down Expand Up @@ -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 );
}

Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/core/composer/qgscomposerobject.cpp
Expand Up @@ -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" },
};


Expand Down
5 changes: 5 additions & 0 deletions src/core/composer/qgscomposerobject.h
Expand Up @@ -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;
Expand Down

0 comments on commit 6c53ba2

Please sign in to comment.