QGIS API Documentation 3.41.0-Master (092dc69654e)
Loading...
Searching...
No Matches
Public Slots | Signals | Public Member Functions | Static Public Member Functions | Properties | List of all members
QgsScaleWidget Class Reference

A combobox which lets the user select map scale from predefined list and highlights nearest to current scale value. More...

#include <qgsscalewidget.h>

Inheritance diagram for QgsScaleWidget:
Inheritance graph
[legend]

Public Slots

void setMinScale (double scale)
 Set the minimum allowed scale.
 
void setNull ()
 Sets the widget to the null value.
 
void setScale (double scale)
 Set the selected scale from a double.
 
void setScaleFromCanvas ()
 Assigns the current scale from the map canvas, if set.
 
void updateScales (const QStringList &scales=QStringList())
 Sets the list of predefined scales to show in the widget.
 

Signals

void scaleChanged (double scale)
 Emitted when user has finished editing/selecting a new scale.
 

Public Member Functions

 QgsScaleWidget (QWidget *parent=nullptr)
 QgsScaleWidget creates a combobox which lets the user select map scale from predefined list and highlights nearest to current scale value.
 
bool allowNull () const
 Returns true if the widget can be set to a NULL value.
 
bool isNull () const
 Returns true if the widget is currently set to a "null" value.
 
double minScale () const
 Returns the minimum scale, or 0 if no minimum scale set.
 
double scale () const
 Returns the selected scale as a double.
 
QString scaleString () const
 Returns the selected scale as a string, e.g.
 
void setAllowNull (bool allowNull)
 Sets whether the scale widget can be set to a NULL value.
 
void setMapCanvas (QgsMapCanvas *canvas)
 Set the map canvas associated to the current button.
 
void setPredefinedScales (const QVector< double > &scales)
 Sets the list of predefined scales to show in the widget.
 
bool setScaleString (const QString &string)
 Set the selected scale from a string, e.g.
 
void setShowCurrentScaleButton (bool showCurrentScaleButton)
 Sets whether to show a button to set the scale to the current scale of the map canvas next to the combobox.
 
bool showCurrentScaleButton ()
 Returns whether a button to set the scale from map canvas is shown or not.
 

Static Public Member Functions

static double toDouble (const QString &scaleString, bool *ok=nullptr)
 Helper function to convert a scale string to double.
 
static QString toString (double scale)
 Helper function to convert a scale double to scale string.
 

Properties

bool minScale
 
bool scale
 
bool showCurrentScaleButton
 

Detailed Description

A combobox which lets the user select map scale from predefined list and highlights nearest to current scale value.

Definition at line 34 of file qgsscalewidget.h.

Constructor & Destructor Documentation

◆ QgsScaleWidget()

QgsScaleWidget::QgsScaleWidget ( QWidget *  parent = nullptr)
explicit

QgsScaleWidget creates a combobox which lets the user select map scale from predefined list and highlights nearest to current scale value.

Definition at line 29 of file qgsscalewidget.cpp.

Member Function Documentation

◆ allowNull()

bool QgsScaleWidget::allowNull ( ) const

Returns true if the widget can be set to a NULL value.

See also
setAllowNull()
isNull()
setNull()
Since
QGIS 3.8

Definition at line 77 of file qgsscalewidget.cpp.

◆ isNull()

bool QgsScaleWidget::isNull ( ) const

Returns true if the widget is currently set to a "null" value.

See also
setAllowNull()
setNull()
Since
QGIS 3.8

Definition at line 67 of file qgsscalewidget.cpp.

◆ minScale()

double QgsScaleWidget::minScale ( ) const
inline

Returns the minimum scale, or 0 if no minimum scale set.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Any scale lower than the minimum scale will automatically be converted to the minimum scale. Except for 0 which is always allowed.

Definition at line 102 of file qgsscalewidget.h.

◆ scale()

double QgsScaleWidget::scale ( ) const
inline

Returns the selected scale as a double.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also
setScale()

Definition at line 85 of file qgsscalewidget.h.

◆ scaleChanged

void QgsScaleWidget::scaleChanged ( double  scale)
signal

Emitted when user has finished editing/selecting a new scale.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

◆ scaleString()

QString QgsScaleWidget::scaleString ( ) const
inline

Returns the selected scale as a string, e.g.

"1:150".

See also
setScaleString()

Definition at line 72 of file qgsscalewidget.h.

◆ setAllowNull()

void QgsScaleWidget::setAllowNull ( bool  allowNull)

Sets whether the scale widget can be set to a NULL value.

See also
allowNull()
isNull()
setNull()
Since
QGIS 3.8

Definition at line 72 of file qgsscalewidget.cpp.

◆ setMapCanvas()

void QgsScaleWidget::setMapCanvas ( QgsMapCanvas canvas)

Set the map canvas associated to the current button.

Definition at line 61 of file qgsscalewidget.cpp.

◆ setMinScale

void QgsScaleWidget::setMinScale ( double  scale)
inlineslot

Set the minimum allowed scale.

Set to 0 to disable the minimum scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Any scale lower than the minimum scale will automatically be converted to the minimum scale. Except for 0 which is always allowed.

Definition at line 176 of file qgsscalewidget.h.

◆ setNull

void QgsScaleWidget::setNull ( )
slot

Sets the widget to the null value.

This only has an effect if allowNull() is true.

See also
allowNull()
isNull()
Since
QGIS 3.8

Definition at line 95 of file qgsscalewidget.cpp.

◆ setPredefinedScales()

void QgsScaleWidget::setPredefinedScales ( const QVector< double > &  scales)

Sets the list of predefined scales to show in the widget.

List elements are expected to be scale denominators, e.g. 1000.0 for a 1:1000 map.

If scales is empty then the default user scale options will be used instead.

Since
QGIS 3.38

Definition at line 82 of file qgsscalewidget.cpp.

◆ setScale

void QgsScaleWidget::setScale ( double  scale)
slot

Set the selected scale from a double.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also
scale()

Definition at line 100 of file qgsscalewidget.cpp.

◆ setScaleFromCanvas

void QgsScaleWidget::setScaleFromCanvas ( )
slot

Assigns the current scale from the map canvas, if set.

See also
setMapCanvas()

Definition at line 87 of file qgsscalewidget.cpp.

◆ setScaleString()

bool QgsScaleWidget::setScaleString ( const QString &  string)
inline

Set the selected scale from a string, e.g.

"1:150".

See also
scaleString()

Definition at line 78 of file qgsscalewidget.h.

◆ setShowCurrentScaleButton()

void QgsScaleWidget::setShowCurrentScaleButton ( bool  showCurrentScaleButton)

Sets whether to show a button to set the scale to the current scale of the map canvas next to the combobox.

Note
the map canvas must be defined to show the button
See also
showCurrentScaleButton()
setMapCanvas()

Definition at line 55 of file qgsscalewidget.cpp.

◆ showCurrentScaleButton()

bool QgsScaleWidget::showCurrentScaleButton ( )
inline

Returns whether a button to set the scale from map canvas is shown or not.

See also
setShowCurrentScaleButton()

Definition at line 61 of file qgsscalewidget.h.

◆ toDouble()

static double QgsScaleWidget::toDouble ( const QString &  scaleString,
bool *  ok = nullptr 
)
inlinestatic

Helper function to convert a scale string to double.

The returned value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. If specified, ok will be set to true if the string was successfully interpreted as a scale.

See also
toString()

Definition at line 119 of file qgsscalewidget.h.

◆ toString()

static QString QgsScaleWidget::toString ( double  scale)
inlinestatic

Helper function to convert a scale double to scale string.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

The returned string will be rounded (e.g. 1:1000, not 1:1000.345).

See also
toDouble()

Definition at line 111 of file qgsscalewidget.h.

◆ updateScales

void QgsScaleWidget::updateScales ( const QStringList &  scales = QStringList())
inlineslot

Sets the list of predefined scales to show in the widget.

List elements are expected to be valid scale strings, such as "1:1000000".

Definition at line 162 of file qgsscalewidget.h.

Property Documentation

◆ minScale

bool QgsScaleWidget::minScale
readwrite

Definition at line 39 of file qgsscalewidget.h.

◆ scale

bool QgsScaleWidget::scale
readwrite

Definition at line 38 of file qgsscalewidget.h.

◆ showCurrentScaleButton

bool QgsScaleWidget::showCurrentScaleButton
readwrite

Definition at line 37 of file qgsscalewidget.h.


The documentation for this class was generated from the following files: