Skip to content

Commit 5fe1ea8

Browse files
authoredMar 28, 2018
[needs-docs] Use QgsScaleBarRenderer to power up scale bar decoration (#6689)
Main short-term benefit: scale bar font size and family can be customized.
1 parent 14c057a commit 5fe1ea8

File tree

6 files changed

+290
-368
lines changed

6 files changed

+290
-368
lines changed
 

‎python/core/scalebar/qgsscalebarrenderer.sip.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ custom labeling.
2727

2828
struct ScaleBarContext
2929
{
30+
3031
double segmentWidth;
3132

3233
QSizeF size;

‎src/app/qgsdecorationscalebar.cpp

Lines changed: 225 additions & 359 deletions
Large diffs are not rendered by default.

‎src/app/qgsdecorationscalebar.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ email : sbr00pwb@users.sourceforge.net
2323

2424
#include "qgis.h"
2525
#include "qgsdecorationitem.h"
26+
#include "scalebar/qgsscalebarsettings.h"
27+
#include "scalebar/qgsscalebarrenderer.h"
2628

2729
class QPainter;
2830

@@ -41,11 +43,12 @@ class APP_EXPORT QgsDecorationScaleBar: public QgsDecorationItem
4143
void projectRead() override;
4244
//! save values to the project
4345
void saveToProject() override;
44-
4546
//! this does the meaty bit of the work
4647
void render( const QgsMapSettings &mapSettings, QgsRenderContext &context ) override;
4748
//! Show the dialog box
4849
void run() override;
50+
//! Setup the QgsScaleBarSettings object
51+
void setupScaleBar();
4952

5053
private:
5154

@@ -61,6 +64,13 @@ class APP_EXPORT QgsDecorationScaleBar: public QgsDecorationItem
6164
QColor mColor;
6265
//! The scale bar otuline color
6366
QColor mOutlineColor;
67+
//! The scale bar font
68+
QFont mFont;
69+
70+
QgsScaleBarSettings mSettings;
71+
72+
//! Scalebar style
73+
std::unique_ptr< QgsScaleBarRenderer > mStyle;
6474

6575
//! Margin percentage values
6676
int mMarginHorizontal = 0;

‎src/app/qgsdecorationscalebardialog.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ QgsDecorationScaleBarDialog::QgsDecorationScaleBarDialog( QgsDecorationScaleBar
8383
pbnChangeOutlineColor->setColor( mDeco.mOutlineColor );
8484
pbnChangeOutlineColor->setContext( QStringLiteral( "gui" ) );
8585
pbnChangeOutlineColor->setColorDialogTitle( tr( "Select Scale Bar Outline Color" ) );
86+
87+
mButtonFontStyle->setMode( QgsFontButton::ModeQFont );
88+
mButtonFontStyle->setCurrentFont( mDeco.mFont );
8689
}
8790

8891
QgsDecorationScaleBarDialog::~QgsDecorationScaleBarDialog()
@@ -108,6 +111,8 @@ void QgsDecorationScaleBarDialog::apply()
108111
mDeco.mStyleIndex = cboStyle->currentIndex();
109112
mDeco.mColor = pbnChangeColor->color();
110113
mDeco.mOutlineColor = pbnChangeOutlineColor->color();
114+
mDeco.mFont = mButtonFontStyle->currentFont();
115+
mDeco.setupScaleBar();
111116
mDeco.update();
112117
}
113118

‎src/core/scalebar/qgsscalebarrenderer.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ class CORE_EXPORT QgsScaleBarRenderer
4040

4141
/**
4242
* Contains parameters regarding scalebar calculations.
43+
* \note The need to attribute the parameters vary depending on the targeted scalebar.
4344
*/
4445
struct ScaleBarContext
4546
{
46-
//! Width of each individual segment (in millimeters)
47+
48+
/**
49+
* The width, in millimeters, of each individual segment drawn.
50+
* \note The number of map units per segment needs to be set via QgsScaleBarSettings::setUnitsPerSegment.
51+
*/
4752
double segmentWidth { 0.0 };
4853

4954
/**

‎src/ui/qgsdecorationscalebardialog.ui

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>565</width>
10-
<height>271</height>
10+
<height>279</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -124,7 +124,7 @@
124124
</property>
125125
</widget>
126126
</item>
127-
<item row="4" column="0">
127+
<item row="5" column="0">
128128
<widget class="QLabel" name="textLabel1_3">
129129
<property name="sizePolicy">
130130
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
@@ -186,7 +186,36 @@
186186
</property>
187187
</widget>
188188
</item>
189+
<item row="4" column="0">
190+
<widget class="QLabel" name="textLabel1_3_22">
191+
<property name="sizePolicy">
192+
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
193+
<horstretch>0</horstretch>
194+
<verstretch>0</verstretch>
195+
</sizepolicy>
196+
</property>
197+
<property name="text">
198+
<string>Font of bar</string>
199+
</property>
200+
</widget>
201+
</item>
189202
<item row="4" column="1">
203+
<widget class="QgsFontButton" name="mButtonFontStyle">
204+
<property name="enabled">
205+
<bool>true</bool>
206+
</property>
207+
<property name="sizePolicy">
208+
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
209+
<horstretch>0</horstretch>
210+
<verstretch>0</verstretch>
211+
</sizepolicy>
212+
</property>
213+
<property name="text">
214+
<string>Font</string>
215+
</property>
216+
</widget>
217+
</item>
218+
<item row="5" column="1">
190219
<layout class="QHBoxLayout" name="horizontalLayout_3">
191220
<item>
192221
<widget class="QgsSpinBox" name="spnSize">
@@ -219,7 +248,7 @@
219248
</item>
220249
</layout>
221250
</item>
222-
<item row="7" column="1">
251+
<item row="8" column="1">
223252
<layout class="QHBoxLayout" name="hlytMargin" stretch="0,0,0,0,0">
224253
<property name="spacing">
225254
<number>10</number>
@@ -336,7 +365,7 @@
336365
</item>
337366
</layout>
338367
</item>
339-
<item row="6" column="1">
368+
<item row="7" column="1">
340369
<widget class="QComboBox" name="cboPlacement">
341370
<property name="sizePolicy">
342371
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -346,7 +375,7 @@
346375
</property>
347376
</widget>
348377
</item>
349-
<item row="7" column="0">
378+
<item row="8" column="0">
350379
<widget class="QLabel" name="lblMargin">
351380
<property name="minimumSize">
352381
<size>
@@ -359,7 +388,7 @@
359388
</property>
360389
</widget>
361390
</item>
362-
<item row="6" column="0">
391+
<item row="7" column="0">
363392
<widget class="QLabel" name="lblLocation">
364393
<property name="sizePolicy">
365394
<sizepolicy hsizetype="Preferred" vsizetype="Minimum">
@@ -375,7 +404,7 @@
375404
</property>
376405
</widget>
377406
</item>
378-
<item row="5" column="0" colspan="2">
407+
<item row="6" column="0" colspan="2">
379408
<widget class="QCheckBox" name="chkSnapping">
380409
<property name="sizePolicy">
381410
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
@@ -404,6 +433,11 @@
404433
<header>qgscolorbutton.h</header>
405434
<container>1</container>
406435
</customwidget>
436+
<customwidget>
437+
<class>QgsFontButton</class>
438+
<extends>QToolButton</extends>
439+
<header>qgsfontbutton.h</header>
440+
</customwidget>
407441
<customwidget>
408442
<class>QgsSpinBox</class>
409443
<extends>QSpinBox</extends>
@@ -420,6 +454,7 @@
420454
<tabstop>grpEnable</tabstop>
421455
<tabstop>cboStyle</tabstop>
422456
<tabstop>pbnChangeColor</tabstop>
457+
<tabstop>pbnChangeOutlineColor</tabstop>
423458
<tabstop>spnSize</tabstop>
424459
<tabstop>chkSnapping</tabstop>
425460
<tabstop>cboPlacement</tabstop>

0 commit comments

Comments
 (0)
Please sign in to comment.