Skip to content

Commit 6c53ba2

Browse files
committed
[FEATURE][composer] Data defined scalebar colors and line width
1 parent ec9ba9c commit 6c53ba2

9 files changed

+374
-200
lines changed

doc/api_break.dox

+7
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,13 @@ QgsComposerObject::dataDefinedProperty instead.
610610
QgsComposerObject::setDataDefinedProperty() instead.
611611
- updatePictureExpression() was removed.
612612

613+
QgsComposerScaleBar {#qgis_api_break_3_0_QgsComposerScaleBar}
614+
-------------------
615+
616+
- setBrush() was removed. Use setFillColor() instead.
617+
- setBrush2() was removed. Use setFillColor2() instead.
618+
- setPen() was removed. Use setLineColor() and setLineWidth() instead.
619+
613620

614621
QgsComposerTable {#qgis_api_break_3_0_QgsComposerTable}
615622
----------------

python/core/composer/qgscomposerscalebar.sip

+52-23
Original file line numberDiff line numberDiff line change
@@ -134,20 +134,65 @@ class QgsComposerScaleBar: QgsComposerItem
134134
*/
135135
void setFontColor( const QColor& c );
136136

137+
/** Returns the color used for fills in the scalebar.
138+
* @see setFillColor()
139+
* @see fillColor2()
140+
* @note added in QGIS 3.0
141+
*/
142+
QColor fillColor() const;
143+
144+
/** Sets the color used for fills in the scalebar.
145+
* @see fillColor()
146+
* @see setFillColor2()
147+
* @note added in QGIS 3.0
148+
*/
149+
void setFillColor( const QColor& color );
150+
151+
/** Returns the secondary color used for fills in the scalebar.
152+
* @see setFillColor2()
153+
* @see fillColor()
154+
* @note added in QGIS 3.0
155+
*/
156+
QColor fillColor2() const;
157+
158+
/** Sets the secondary color used for fills in the scalebar.
159+
* @see fillColor2()
160+
* @see setFillColor2()
161+
* @note added in QGIS 3.0
162+
*/
163+
void setFillColor2( const QColor& color );
164+
165+
/** Returns the color used for lines in the scalebar.
166+
* @see setLineColor()
167+
* @note added in QGIS 3.0
168+
*/
169+
QColor lineColor() const;
170+
171+
/** Sets the color used for lines in the scalebar.
172+
* @see lineColor()
173+
* @note added in QGIS 3.0
174+
*/
175+
void setLineColor( const QColor& color );
176+
177+
/** Returns the line width in millimeters for lines in the scalebar.
178+
* @see setLineWidth()
179+
* @note added in QGIS 3.0
180+
*/
181+
double lineWidth() const;
182+
183+
/** Sets the line width in millimeters for lines in the scalebar.
184+
* @see lineWidth()
185+
* @note added in QGIS 3.0
186+
*/
187+
void setLineWidth( double width );
188+
137189
/** Returns the pen used for drawing the scalebar.
138190
* @returns QPen used for drawing the scalebar outlines.
139191
* @see setPen
140192
* @see brush
141193
*/
142194
QPen pen() const;
143195

144-
/** Sets the pen used for drawing the scalebar.
145-
* @param pen QPen to use for drawing the scalebar outlines.
146-
* @see pen
147-
* @see setBrush
148-
*/
149-
void setPen( const QPen& pen );
150-
151196
/** Returns the primary brush for the scalebar.
152197
* @returns QBrush used for filling the scalebar
153198
* @see setBrush
@@ -156,14 +201,6 @@ class QgsComposerScaleBar: QgsComposerItem
156201
*/
157202
QBrush brush() const;
158203

159-
/** Sets primary brush for the scalebar.
160-
* @param brush QBrush to use for filling the scalebar
161-
* @see brush
162-
* @see setBrush2
163-
* @see setPen
164-
*/
165-
void setBrush( const QBrush& brush );
166-
167204
/** Returns the secondary brush for the scalebar. This is used for alternating color style scalebars, such
168205
* as single and double box styles.
169206
* @returns QBrush used for secondary color areas
@@ -172,14 +209,6 @@ class QgsComposerScaleBar: QgsComposerItem
172209
*/
173210
QBrush brush2() const;
174211

175-
/** Sets secondary brush for the scalebar. This is used for alternating color style scalebars, such
176-
* as single and double box styles.
177-
* @param brush QBrush to use for secondary color areas
178-
* @see brush2
179-
* @see setBrush
180-
*/
181-
void setBrush2( const QBrush& brush );
182-
183212
double height() const;
184213
void setHeight( double h );
185214

src/app/composer/qgscomposerscalebarwidget.cpp

+21-17
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ QgsComposerScaleBarWidget::QgsComposerScaleBarWidget( QgsComposerScaleBar* scale
9191

9292
connect( mMapItemComboBox, SIGNAL( itemChanged( QgsComposerItem* ) ), this, SLOT( composerMapChanged( QgsComposerItem* ) ) );
9393

94+
registerDataDefinedButton( mFillColorDDBtn, QgsComposerObject::ScalebarFillColor,
95+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
96+
registerDataDefinedButton( mFillColor2DDBtn, QgsComposerObject::ScalebarFillColor2,
97+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
98+
registerDataDefinedButton( mLineColorDDBtn, QgsComposerObject::ScalebarLineColor,
99+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::colorAlphaDesc() );
100+
registerDataDefinedButton( mLineWidthDDBtn, QgsComposerObject::ScalebarLineWidth,
101+
QgsDataDefinedButtonV2::AnyType, QgsDataDefinedButtonV2::doublePosDesc() );
102+
94103
blockMemberSignals( false );
95104
setGuiElements(); //set the GUI elements to the state of scaleBar
96105
}
@@ -111,7 +120,7 @@ void QgsComposerScaleBarWidget::setGuiElements()
111120
mNumberOfSegmentsSpinBox->setValue( mComposerScaleBar->numSegments() );
112121
mSegmentsLeftSpinBox->setValue( mComposerScaleBar->numSegmentsLeft() );
113122
mSegmentSizeSpinBox->setValue( mComposerScaleBar->numUnitsPerSegment() );
114-
mLineWidthSpinBox->setValue( mComposerScaleBar->pen().widthF() );
123+
mLineWidthSpinBox->setValue( mComposerScaleBar->lineWidth() );
115124
mHeightSpinBox->setValue( mComposerScaleBar->height() );
116125
mMapUnitsPerBarUnitSpinBox->setValue( mComposerScaleBar->numMapUnitsPerScaleBarUnit() );
117126
mLabelBarSpaceSpinBox->setValue( mComposerScaleBar->labelBarSpace() );
@@ -120,9 +129,9 @@ void QgsComposerScaleBarWidget::setGuiElements()
120129
mLineJoinStyleCombo->setPenJoinStyle( mComposerScaleBar->lineJoinStyle() );
121130
mLineCapStyleCombo->setPenCapStyle( mComposerScaleBar->lineCapStyle() );
122131
mFontColorButton->setColor( mComposerScaleBar->fontColor() );
123-
mFillColorButton->setColor( mComposerScaleBar->brush().color() );
124-
mFillColor2Button->setColor( mComposerScaleBar->brush2().color() );
125-
mStrokeColorButton->setColor( mComposerScaleBar->pen().color() );
132+
mFillColorButton->setColor( mComposerScaleBar->fillColor() );
133+
mFillColor2Button->setColor( mComposerScaleBar->fillColor2() );
134+
mStrokeColorButton->setColor( mComposerScaleBar->lineColor() );
126135

127136
//map combo box
128137
mMapItemComboBox->setItem( mComposerScaleBar->composerMap() );
@@ -154,7 +163,10 @@ void QgsComposerScaleBarWidget::setGuiElements()
154163
}
155164
mMinWidthSpinBox->setValue( mComposerScaleBar->minBarWidth() );
156165
mMaxWidthSpinBox->setValue( mComposerScaleBar->maxBarWidth() );
157-
166+
updateDataDefinedButton( mFillColorDDBtn );
167+
updateDataDefinedButton( mFillColor2DDBtn );
168+
updateDataDefinedButton( mLineColorDDBtn );
169+
updateDataDefinedButton( mLineWidthDDBtn );
158170
blockMemberSignals( false );
159171
}
160172

@@ -169,9 +181,7 @@ void QgsComposerScaleBarWidget::on_mLineWidthSpinBox_valueChanged( double d )
169181

170182
mComposerScaleBar->beginCommand( tr( "Scalebar line width" ), QgsComposerMergeCommand::ScaleBarLineWidth );
171183
disconnectUpdateSignal();
172-
QPen newPen = mComposerScaleBar->pen();
173-
newPen.setWidthF( d );
174-
mComposerScaleBar->setPen( newPen );
184+
mComposerScaleBar->setLineWidth( d );
175185
mComposerScaleBar->update();
176186
connectUpdateSignal();
177187
mComposerScaleBar->endCommand();
@@ -280,9 +290,7 @@ void QgsComposerScaleBarWidget::on_mFillColorButton_colorChanged( const QColor&
280290

281291
mComposerScaleBar->beginCommand( tr( "Scalebar color changed" ), QgsComposerMergeCommand::ScaleBarFillColor );
282292
disconnectUpdateSignal();
283-
QBrush newBrush = mComposerScaleBar->brush();
284-
newBrush.setColor( newColor );
285-
mComposerScaleBar->setBrush( newBrush );
293+
mComposerScaleBar->setFillColor( newColor );
286294
mComposerScaleBar->update();
287295
connectUpdateSignal();
288296
mComposerScaleBar->endCommand();
@@ -297,9 +305,7 @@ void QgsComposerScaleBarWidget::on_mFillColor2Button_colorChanged( const QColor
297305

298306
mComposerScaleBar->beginCommand( tr( "Scalebar secondary color changed" ), QgsComposerMergeCommand::ScaleBarFill2Color );
299307
disconnectUpdateSignal();
300-
QBrush newBrush = mComposerScaleBar->brush2();
301-
newBrush.setColor( newColor );
302-
mComposerScaleBar->setBrush2( newBrush );
308+
mComposerScaleBar->setFillColor2( newColor );
303309
mComposerScaleBar->update();
304310
connectUpdateSignal();
305311
mComposerScaleBar->endCommand();
@@ -314,9 +320,7 @@ void QgsComposerScaleBarWidget::on_mStrokeColorButton_colorChanged( const QColor
314320

315321
mComposerScaleBar->beginCommand( tr( "Scalebar line color changed" ), QgsComposerMergeCommand::ScaleBarStrokeColor );
316322
disconnectUpdateSignal();
317-
QPen newPen = mComposerScaleBar->pen();
318-
newPen.setColor( newColor );
319-
mComposerScaleBar->setPen( newPen );
323+
mComposerScaleBar->setLineColor( newColor );
320324
mComposerScaleBar->update();
321325
connectUpdateSignal();
322326
mComposerScaleBar->endCommand();

src/core/composer/qgscomposerobject.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ const QgsPropertyDefinition QgsComposerObject::sPropertyNameMap
6363
{ QgsComposerObject::PictureSvgOutlineWidth, "dataDefinedSvgOutlineWidth" },
6464
{ QgsComposerObject::LegendTitle, "dataDefinedLegendTitle" },
6565
{ QgsComposerObject::LegendColumnCount, "dataDefinedLegendColumns" },
66+
{ QgsComposerObject::ScalebarFillColor, "dataDefinedScalebarFill" },
67+
{ QgsComposerObject::ScalebarFillColor2, "dataDefinedScalebarFill2" },
68+
{ QgsComposerObject::ScalebarLineColor, "dataDefinedScalebarLineColor" },
69+
{ QgsComposerObject::ScalebarLineWidth, "dataDefinedScalebarLineWidth" },
6670
};
6771

6872

src/core/composer/qgscomposerobject.h

+5
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ class CORE_EXPORT QgsComposerObject: public QObject, public QgsExpressionContext
8181
//legend item
8282
LegendTitle, //!< Legend title
8383
LegendColumnCount, //!< Legend column count
84+
//scalebar item
85+
ScalebarFillColor, //!< Scalebar fill color
86+
ScalebarFillColor2, //!< Scalebar secondary fill color
87+
ScalebarLineColor, //!< Scalebar line color
88+
ScalebarLineWidth, //!< Scalebar line width
8489
};
8590

8691
static const QgsPropertyDefinition sPropertyNameMap;

0 commit comments

Comments
 (0)