Skip to content

Commit 08a9bcb

Browse files
committed
Unify scale widgets API
Flip all scale based widgets to use scale denominators instead of actual scales (ie 100.0 instead of 0.01 for 1:100). This is done for consistency with the rest of the API, which predominantly uses scale denominators. It also helps precision loss as a result of multiple 1.0 / scale conversions throughout the code. Refs #15337
1 parent 9f71156 commit 08a9bcb

28 files changed

+648
-269
lines changed

doc/api_break.dox

+26
Original file line numberDiff line numberDiff line change
@@ -2010,6 +2010,32 @@ QgsScaleBarStyle {#qgis_api_break_3_0_QgsScaleBarStyle}
20102010
- The interface for QgsScaleBarStyle has been completely rewritten - any code using QgsScaleBarStyle or subclasses will need to update
20112011
to the new draw() and calculateBoxSize() methods.
20122012

2013+
2014+
QgsScaleComboBox {#qgis_api_break_3_0_QgsScaleComboBox}
2015+
----------------
2016+
2017+
- All numeric scales reported and used by QgsScaleComboBox now represent the scale denominator (i.e. 2345 for a scale "1:2345"), for consistency with other scale use throughout the API.
2018+
2019+
2020+
QgsScaleRangeWidget {#qgis_api_break_3_0_QgsScaleRangeWidget}
2021+
-------------------
2022+
2023+
- All numeric scales reported and used by QgsScaleRangeWidget now represent the scale denominator (i.e. 2345 for a scale "1:2345"), for consistency with other scale use throughout the API.
2024+
- minimumScaleDenom() and maximumScaleDenom() were removed. Now minimumScale() and maximumScale() report the scale denominator.
2025+
2026+
2027+
QgsScaleVisibilityDialog {#qgis_api_break_3_0_QgsScaleVisibilityDialog}
2028+
------------------------
2029+
2030+
- All numeric scales reported and used by QgsScaleVisibilityDialog now represent the scale denominator (i.e. 2345 for a scale "1:2345"), for consistency with other scale use throughout the API.
2031+
2032+
2033+
QgsScaleWidget {#qgis_api_break_3_0_QgsScaleWidget}
2034+
--------------
2035+
2036+
- All numeric scales reported and used by QgsScaleWidget now represent the scale denominator (i.e. 2345 for a scale "1:2345"), for consistency with other scale use throughout the API.
2037+
2038+
20132039
QgsServer {#qgis_api_break_3_0_QgsServer}
20142040
----------
20152041

python/auto_sip.blacklist

-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,6 @@ gui/qgsrasterformatsaveoptionswidget.sip
5050
gui/qgsrasterlayersaveasdialog.sip
5151
gui/qgsrasterpyramidsoptionswidget.sip
5252
gui/qgsrubberband.sip
53-
gui/qgsscalerangewidget.sip
54-
gui/qgsscalevisibilitydialog.sip
5553
gui/qgsscrollarea.sip
5654
gui/qgssearchquerybuilder.sip
5755
gui/qgsshortcutsmanager.sip

python/gui/qgsscalecombobox.sip

+49-16
Original file line numberDiff line numberDiff line change
@@ -21,57 +21,90 @@ class QgsScaleComboBox : QComboBox
2121
#include "qgsscalecombobox.h"
2222
%End
2323
public:
24+
2425
QgsScaleComboBox( QWidget *parent /TransferThis/ = 0 );
26+
%Docstring
27+
Constructor for QgsScaleComboBox.
28+
%End
2529

26-
QString scaleString();
30+
QString scaleString() const;
2731
%Docstring
28-
Function to read the selected scale as text
32+
Returns the selected scale as a string, e.g. "1:150".
33+
.. seealso:: setScaleString()
2934
:rtype: str
3035
%End
31-
bool setScaleString( const QString &scaleTxt );
36+
37+
bool setScaleString( const QString &string );
3238
%Docstring
33-
Function to set the selected scale from text
39+
Set the selected scale from a ``string``, e.g. "1:150".
40+
.. seealso:: scaleString()
3441
:rtype: bool
3542
%End
43+
3644
double scale() const;
3745
%Docstring
38-
Function to read the selected scale as double
46+
Returns the selected scale as a double.
47+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
48+
.. seealso:: setScale()
3949
:rtype: float
4050
%End
41-
void setScale( double scale );
42-
%Docstring
43-
Function to set the selected scale from double
44-
%End
51+
4552
double minScale() const;
4653
%Docstring
47-
Function to read the min scale
54+
Returns the minimum scale, or 0 if no minimum scale set.
55+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
56+
Any scale lower than the minimum scale will automatically be converted to the minimum scale.
57+
Except for 0 which is always allowed.
4858
:rtype: float
4959
%End
5060

5161
static QString toString( double scale );
5262
%Docstring
63+
Helper function to convert a ``scale`` double to scale string.
64+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
65+
66+
The returned string will be rounded (e.g. 1:1000, not 1:1000.345).
67+
.. seealso:: toDouble()
5368
:rtype: str
5469
%End
55-
static double toDouble( const QString &scaleString, bool *ok = 0 );
70+
71+
static double toDouble( const QString &string, bool *ok = 0 );
5672
%Docstring
57-
Helper function to convert a scale string to double
73+
Helper function to convert a scale ``string`` to double.
74+
The returned value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
75+
If specified, ``ok`` will be set to true if the string was successfully interpreted as a scale.
76+
.. seealso:: toString()
5877
:rtype: float
5978
%End
6079

6180
signals:
81+
6282
void scaleChanged( double scale );
6383
%Docstring
64-
Signal is emitted when *user* has finished editing/selecting a new scale.
84+
Emitted when *user* has finished editing/selecting a new scale.
85+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
6586
%End
6687

6788
public slots:
89+
6890
void updateScales( const QStringList &scales = QStringList() );
91+
%Docstring
92+
Sets the list of predefined ``scales`` to show in the combobox. List elements
93+
are expected to be valid scale strings, such as "1:1000000".
94+
%End
95+
96+
void setScale( double scale );
97+
%Docstring
98+
Set the selected scale from a double.
99+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
100+
.. seealso:: scale()
101+
%End
69102

70103
void setMinScale( double scale );
71104
%Docstring
72-
Set the minimum allowed scale.
73-
Anything scale lower than the minimum scale will automatically
74-
be converted to the minimum scale.
105+
Set the minimum allowed ``scale``. Set to 0 to disable the minimum scale.
106+
The ``scale`` value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
107+
Any scale lower than the minimum scale will automatically be converted to the minimum scale.
75108
Except for 0 which is always allowed.
76109
%End
77110

python/gui/qgsscalerangewidget.sip

+79-24
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,104 @@
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/qgsscalerangewidget.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
111

212
class QgsScaleRangeWidget : QWidget
313
{
14+
%Docstring
15+
A widget allowing entry of a range of map scales, e.g. minimum scale and maximum scale.
16+
%End
17+
418
%TypeHeaderCode
519
#include "qgsscalerangewidget.h"
620
%End
7-
821
public:
9-
explicit QgsScaleRangeWidget( QWidget *parent /TransferThis/ = 0 );
10-
~QgsScaleRangeWidget();
11-
12-
//! set the map canvas which will be used for the current scale buttons
13-
/**
14-
* @brief setMapCanvas set the map canvas which will be used for the current scale buttons
15-
* if not set, the buttons are hidden.
16-
*/
17-
void setMapCanvas( QgsMapCanvas *mapCanvas );
1822

19-
//! return the minimum scale
20-
double minimumScale();
23+
explicit QgsScaleRangeWidget( QWidget *parent /TransferThis/ = 0 );
24+
%Docstring
25+
Constructor for QgsScaleRangeWidget.
26+
%End
2127

22-
//! return the maximum scale
23-
double maximumScale();
28+
void setMapCanvas( QgsMapCanvas *canvas );
29+
%Docstring
30+
Sets the map ``canvas`` which will be used for the current scale buttons.
31+
If not set, the buttons are hidden.
32+
%End
2433

25-
//! return the minimum scale denominator ( = 1 / maximum scale )
26-
double minimumScaleDenom();
34+
double minimumScale() const;
35+
%Docstring
36+
Returns the selected minimum scale, or 0 if minimum scale is not set.
37+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
38+
.. seealso:: maximumScale()
39+
.. seealso:: setMinimumScale()
40+
:rtype: float
41+
%End
2742

28-
//! return the maximum scale denominator ( = 1 / minimum scale )
29-
double maximumScaleDenom();
43+
double maximumScale() const;
44+
%Docstring
45+
Returns the selected maximum scale, or 0 if maximum scale is not set.
46+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
47+
.. seealso:: minimumScale()
48+
.. seealso:: setMaximumScale()
49+
:rtype: float
50+
%End
3051

31-
//! call to reload the project scales and apply them to the 2 scales combo boxes
3252
void reloadProjectScales();
53+
%Docstring
54+
Call to reload the preset scales from the current project and apply them to the 2 scales combo boxes.
55+
%End
3356

3457
public slots:
58+
3559
void setMinimumScale( double scale );
60+
%Docstring
61+
Set the minimum ``scale``, or 0 to indicate the minimum is not set.
62+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
63+
.. seealso:: minimumScale()
64+
.. seealso:: setMaximumScale()
65+
.. seealso:: setScaleRange()
66+
%End
3667

3768
void setMaximumScale( double scale );
69+
%Docstring
70+
Set the maximum ``scale``, or 0 to indicate the minimum is not set.
71+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
72+
.. seealso:: maximumScale()
73+
.. seealso:: setMinimumScale()
74+
.. seealso:: setScaleRange()
75+
%End
3876

3977
void setScaleRange( double min, double max );
78+
%Docstring
79+
Sets the scale range, from ``min`` scale to ``max`` scale.
80+
The scale values indicates the scale denominator, e.g. 1000.0 for a 1:1000 map,
81+
or 0 to indicate not set.
82+
.. seealso:: setMinimumScale()
83+
.. seealso:: setMaximumScale()
84+
%End
4085

4186
signals:
4287

43-
/** Emitted when the scale range set in the widget is changed.
44-
* @param min minimum scale
45-
* @param max maximum scale
46-
* @note added in QGIS 2.16
47-
*/
4888
void rangeChanged( double min, double max );
89+
%Docstring
90+
Emitted when the scale range set in the widget is changed.
91+
The scale values indicates the scale denominator, e.g. 1000.0 for a 1:1000 map,
92+
or 0 to indicate not set.
93+
.. versionadded:: 2.16
94+
%End
95+
4996
};
97+
98+
/************************************************************************
99+
* This file has been generated automatically from *
100+
* *
101+
* src/gui/qgsscalerangewidget.h *
102+
* *
103+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
104+
************************************************************************/
+72-15
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,87 @@
1-
class QgsScaleVisibilityDialog : QObject
1+
/************************************************************************
2+
* This file has been generated automatically from *
3+
* *
4+
* src/gui/qgsscalevisibilitydialog.h *
5+
* *
6+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
7+
************************************************************************/
8+
9+
10+
11+
12+
class QgsScaleVisibilityDialog : QDialog
213
{
3-
%TypeHeaderCode
4-
#include <qgsscalevisibilitydialog.h>
14+
%Docstring
15+
A dialog allowing users to enter a scale visibility range.
516
%End
617

18+
%TypeHeaderCode
19+
#include "qgsscalevisibilitydialog.h"
20+
%End
721
public:
8-
explicit QgsScaleVisibilityDialog( QWidget *parent /TransferThis/ = 0, const QString &title = QString(), QgsMapCanvas *mapCanvas = 0 );
922

10-
//! return if scale visibilty is enabled
11-
bool hasScaleVisibility();
23+
explicit QgsScaleVisibilityDialog( QWidget *parent /TransferThis/ = 0, const QString &title = QString(), QgsMapCanvas *mapCanvas = 0 );
24+
%Docstring
25+
Constructor for QgsScaleVisibilityDialog, with specified dialog ``title``. The ``mapCanvas`` argument
26+
can be used to associate the dialog with a map canvas, allowing use of the current map scale
27+
within the dialog.
28+
%End
1229

13-
//! return minimum scale (true scale, not scale denominator)
14-
double minimumScale();
30+
bool hasScaleVisibility() const;
31+
%Docstring
32+
Return true if scale based visibilty is enabled.
33+
:rtype: bool
34+
%End
1535

16-
//! return maximum scale (true scale, not scale denominator)
17-
double maximumScale();
36+
double minimumScale() const;
37+
%Docstring
38+
Returns the selected minimum scale, or 0 if minimum scale is not set.
39+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
40+
.. seealso:: maximumScale()
41+
.. seealso:: setMinimumScale()
42+
:rtype: float
43+
%End
1844

45+
double maximumScale() const;
46+
%Docstring
47+
Returns the selected maximum scale, or 0 if maximum scale is not set.
48+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
49+
.. seealso:: minimumScale()
50+
.. seealso:: setMaximumScale())
51+
:rtype: float
52+
%End
1953

2054
public slots:
21-
//! set if scale visibility is enabled
55+
2256
void setScaleVisiblity( bool hasScaleVisibility );
57+
%Docstring
58+
Set whether scale based visibility is enabled.
59+
.. seealso:: hasScaleVisibility()
60+
%End
2361

24-
//! set minimum scale (true scale, not scale denominator)
25-
void setMinimumScale( double minScale );
62+
void setMinimumScale( double scale );
63+
%Docstring
64+
Set the minimum ``scale``, or 0 to indicate the minimum is not set.
65+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
66+
.. seealso:: minimumScale()
67+
.. seealso:: setMaximumScale()
68+
%End
69+
70+
void setMaximumScale( double scale );
71+
%Docstring
72+
Set the maximum ``scale``, or 0 to indicate the minimum is not set.
73+
The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
74+
.. seealso:: maximumScale()
75+
.. seealso:: setMinimumScale()
76+
%End
2677

27-
//! set maximum scale (true scale, not scale denominator)
28-
void setMaximumScale( double maxScale );
2978

3079
};
80+
81+
/************************************************************************
82+
* This file has been generated automatically from *
83+
* *
84+
* src/gui/qgsscalevisibilitydialog.h *
85+
* *
86+
* Do not edit manually ! Edit header and run scripts/sipify.pl again *
87+
************************************************************************/

0 commit comments

Comments
 (0)