QgsQuickScaleBarKit class

The class QgsQuickScaleBarKit encapsulates the utilies to calculate scale bar properties.

It requires connection to mapSettings of the active canvas to automatically update text and width

From preferred width in pixel, it calculates the width (pixel) of scalebar distance in meters or kilometers (int) rounded to "nice" number (e.g. 72.4 to 100) and units text (e.g. km)

System of measurement for result could be set too, so for example the resulting scalebar can show results in the imperial units.

Constructors, destructors, conversion operators

QgsQuickScaleBarKit(QObject* parent = nullptr) explicit
create new scale bar kit

Public functions

auto distance() const -> int
Units of distance (e.g.
void setMapSettings(QgsQuickMapSettings* mapSettings)
Associated map settings.
auto units() const -> QString
Units of distance (e.g.
auto width() const -> int
Calculated width of scalebar in pixels representing distance + units.

Signals

void mapSettingsChanged()
Associated map settings.
void preferredWidthChanged()
Preferred width of scalebar in pixels.
void scaleBarChanged()
width, distance and/or units changed
void systemOfMeasurementChanged()
Preferred system of measurement for the result.

Public slots

void updateScaleBar()
recalculate width, distance and units.

Function documentation

int QgsQuickScaleBarKit::distance() const

Units of distance (e.g.

km or m) of result in desired systemOfMeasurement Read-only (result).

void QgsQuickScaleBarKit::setMapSettings(QgsQuickMapSettings* mapSettings)

Associated map settings.

Should be initialized before the first use from mapcanvas map settings.

QString QgsQuickScaleBarKit::units() const

Units of distance (e.g.

km or m) of result in desired systemOfMeasurement Read-only (result).

int QgsQuickScaleBarKit::width() const

Calculated width of scalebar in pixels representing distance + units.

Differs minimum possible from preferredWidth to Gets "nice" distance number.

void QgsQuickScaleBarKit::mapSettingsChanged() signal

Associated map settings.

Should be initialized before the first use from mapcanvas map settings.

void QgsQuickScaleBarKit::preferredWidthChanged() signal

Preferred width of scalebar in pixels.

Default set to 300.