QGIS API Documentation 3.99.0-Master (e9821da5c6b)
Loading...
Searching...
No Matches
QgsGuiUtils Namespace Reference

The QgsGuiUtils namespace contains constants and helper functions used throughout the QGIS GUI. More...

Functions

QString createFileFilter_ (QString const &format)
 Create file filters suitable for use with QFileDialog.
QString createFileFilter_ (QString const &longName, QString const &glob)
 Convenience function for readily creating file filters.
QString createWidgetKey (QWidget *widget, const QString &keyName=QString())
 Creates a key for the given widget that can be used to store related data in settings.
QString displayValueWithMaximumDecimals (const Qgis::DataType dataType, const double value, bool displayTrailingZeroes=false)
 Returns a localized string representation of the value with the appropriate number of decimals supported by the dataType.
QFont getFont (bool &ok, const QFont &initial, const QString &title=QString())
 Show font selection dialog.
QPair< QString, QString > GUI_EXPORT getSaveAsImageName (QWidget *parent, const QString &message, const QString &defaultFilename=QString())
 A helper function to get an image name from the user.
QSize iconSize (bool dockableToolbar=false)
 Returns the user-preferred size of a window's toolbar icons.
bool isNonStandardGeoPackageGeometryType (Qgis::WkbType wkbType)
 Returns true if the given wkbType is a non-standard GeoPackage geometry type (PolyhedralSurface, TIN, or Triangle).
bool GUI_EXPORT openFilesRememberingFilter (QString const &filterName, QString const &filters, QStringList &selectedFiles, QString &enc, QString &title, bool cancelAll=false)
 Open files, preferring to have the default file selector be the last one used, if any; also, prefer to start in the last directory associated with filterName.
QSize panelIconSize (QSize size)
 Returns dockable panel toolbar icon width based on the provided window toolbar width.
bool restoreGeometry (QWidget *widget, const QString &keyName=QString())
 Restore the wigget geometry from settings.
void saveGeometry (QWidget *widget, const QString &keyName=QString())
 Save the wigget geometry into settings.
int scaleIconSize (int standardSize)
 Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly, whilst still resulting in pixel-perfect sizes for low-dpi displays.
int significantDigits (const Qgis::DataType rasterDataType)
 Returns the maximum number of significant digits a for the given rasterDataType.
bool warnAboutNonStandardGeoPackageGeometryType (Qgis::WkbType wkbType, QWidget *parent, const QString &dialogTitle, bool showDialog=true, bool *isNonStandard=nullptr)
 Checks if the given wkbType is a non-standard GeoPackage geometry type (PolyhedralSurface, TIN, or Triangle) and displays a warning message box asking the user if they want to continue.

Variables

constexpr double CANVAS_MAGNIFICATION_MAX = 16.0
 Maximum magnification level allowed in map canvases.
constexpr double CANVAS_MAGNIFICATION_MIN = 0.1
 Minimum magnification level allowed in map canvases.

Detailed Description

The QgsGuiUtils namespace contains constants and helper functions used throughout the QGIS GUI.

Note
not available in Python bindings

Function Documentation

◆ createFileFilter_() [1/2]

QString GUI_EXPORT QgsGuiUtils::createFileFilter_ ( QString const & format)

Create file filters suitable for use with QFileDialog.

Parameters
formatextension e.g. "png"
Returns
QString e.g. "PNG format (*.png, *.PNG)"

Definition at line 208 of file qgsguiutils.cpp.

◆ createFileFilter_() [2/2]

QString GUI_EXPORT QgsGuiUtils::createFileFilter_ ( QString const & longName,
QString const & glob )

Convenience function for readily creating file filters.

Given a long name for a file filter and a regular expression, return a file filter string suitable for use in a QFileDialog::OpenFiles() call. The regular express, glob, will have both all lower and upper case versions added.

Definition at line 203 of file qgsguiutils.cpp.

◆ createWidgetKey()

QString QgsGuiUtils::createWidgetKey ( QWidget * widget,
const QString & keyName = QString() )

Creates a key for the given widget that can be used to store related data in settings.

Will use objectName() or class name if objectName() is not set. Can be overridden using keyName.

Parameters
widgetThe widget to make the key from.
keyNameOverride for objectName() if needed. If not set will use objectName()
Returns
A key name that can be used for the widget in settings.

Definition at line 245 of file qgsguiutils.cpp.

◆ displayValueWithMaximumDecimals()

QString GUI_EXPORT QgsGuiUtils::displayValueWithMaximumDecimals ( const Qgis::DataType dataType,
const double value,
bool displayTrailingZeroes = false )

Returns a localized string representation of the value with the appropriate number of decimals supported by the dataType.

Trailing zeroes after decimal separator are not show unless displayTrailingZeroes is set. Note that for floating point types the number of decimals may exceed the actual internal precision because the precision is always calculated on the mantissa and the conversion to string interprets the precision as decimal places.

Since
QGIS 3.16

Definition at line 297 of file qgsguiutils.cpp.

◆ getFont()

QFont GUI_EXPORT QgsGuiUtils::getFont ( bool & ok,
const QFont & initial,
const QString & title = QString() )

Show font selection dialog.

It is strongly recommended that you do not use this method, and instead use the standard QgsFontButton widget to allow users consistent font selection behavior.

Parameters
oktrue on ok, false on cancel
initialinitial font
titleoptional dialog title
Returns
QFont the selected fon

Definition at line 215 of file qgsguiutils.cpp.

◆ getSaveAsImageName()

QPair< QString, QString > GUI_EXPORT QgsGuiUtils::getSaveAsImageName ( QWidget * parent,
const QString & message,
const QString & defaultFilename = QString() )

A helper function to get an image name from the user.

It will nicely provide filters with all available writable image formats.

Parameters
parentwidget that should act as the parent for the file dialog
messagethe message to display to the user
defaultFilenamedefault file name (empty by default)
Returns
QPair<QString, QString> where first is the file name and second is the file type

Definition at line 93 of file qgsguiutils.cpp.

◆ iconSize()

QSize GUI_EXPORT QgsGuiUtils::iconSize ( bool dockableToolbar = false)

Returns the user-preferred size of a window's toolbar icons.

Parameters
dockableToolbarIf set to true, the icon size will be returned for dockable window panel's toolbars.
Returns
a QSize object representing an icon's width and height.
Since
QGIS 3.8

Definition at line 269 of file qgsguiutils.cpp.

◆ isNonStandardGeoPackageGeometryType()

bool GUI_EXPORT QgsGuiUtils::isNonStandardGeoPackageGeometryType ( Qgis::WkbType wkbType)

Returns true if the given wkbType is a non-standard GeoPackage geometry type (PolyhedralSurface, TIN, or Triangle).

Parameters
wkbTypethe geometry type to check
Returns
true if the geometry type is non-standard for GeoPackage
Since
QGIS 4.0

Definition at line 351 of file qgsguiutils.cpp.

◆ openFilesRememberingFilter()

bool GUI_EXPORT QgsGuiUtils::openFilesRememberingFilter ( QString const & filterName,
QString const & filters,
QStringList & selectedFiles,
QString & enc,
QString & title,
bool cancelAll = false )

Open files, preferring to have the default file selector be the last one used, if any; also, prefer to start in the last directory associated with filterName.

Parameters
filterNamethe name of the filter; used for persistent store key
filtersthe file filters used for QFileDialog
selectedFilesstring list of selected files; will be empty if none selected
encencoding?
titlethe title for the dialog
cancelAlladd button to cancel further requests
Note
Stores persistent settings under /UI/. The sub-keys will be filterName and filterName + "Dir".

Opens dialog on last directory associated with the filter name, or the current working directory if this is the first time invoked with the current filter name.

This method returns true if cancel all was clicked, otherwise false

Definition at line 37 of file qgsguiutils.cpp.

◆ panelIconSize()

QSize GUI_EXPORT QgsGuiUtils::panelIconSize ( QSize size)

Returns dockable panel toolbar icon width based on the provided window toolbar width.

Parameters
sizeIcon size from which the output size will be derived from.
Returns
a QSize object representing an icon's width and height.
Since
QGIS 3.8

Definition at line 283 of file qgsguiutils.cpp.

◆ restoreGeometry()

bool GUI_EXPORT QgsGuiUtils::restoreGeometry ( QWidget * widget,
const QString & keyName = QString() )

Restore the wigget geometry from settings.

Will use the objectName() of the widget and if empty, or keyName is set, will use keyName to save state into settings.

Parameters
widgetThe widget to restore.
keyNameOverride for objectName() if needed.
Returns
true if the geometry was restored.

Definition at line 238 of file qgsguiutils.cpp.

◆ saveGeometry()

void GUI_EXPORT QgsGuiUtils::saveGeometry ( QWidget * widget,
const QString & keyName = QString() )

Save the wigget geometry into settings.

Will use the objectName() of the widget and if empty, or keyName is set, will use keyName to save state into settings.

Parameters
widgetThe widget to save.
keyNameOverride for objectName() if needed.

Definition at line 231 of file qgsguiutils.cpp.

◆ scaleIconSize()

int GUI_EXPORT QgsGuiUtils::scaleIconSize ( int standardSize)

Scales an icon size to compensate for display pixel density, making the icon size hi-dpi friendly, whilst still resulting in pixel-perfect sizes for low-dpi displays.

standardSize should be set to a standard icon size, e.g. 16, 24, 48, etc.

Since
QGIS 3.6

Definition at line 264 of file qgsguiutils.cpp.

◆ significantDigits()

int GUI_EXPORT QgsGuiUtils::significantDigits ( const Qgis::DataType rasterDataType)

Returns the maximum number of significant digits a for the given rasterDataType.

Since
QGIS 3.16

Definition at line 316 of file qgsguiutils.cpp.

◆ warnAboutNonStandardGeoPackageGeometryType()

bool GUI_EXPORT QgsGuiUtils::warnAboutNonStandardGeoPackageGeometryType ( Qgis::WkbType wkbType,
QWidget * parent,
const QString & dialogTitle,
bool showDialog = true,
bool * isNonStandard = nullptr )

Checks if the given wkbType is a non-standard GeoPackage geometry type (PolyhedralSurface, TIN, or Triangle) and displays a warning message box asking the user if they want to continue.

Parameters
wkbTypethe geometry type to check
parentthe parent widget for the message box (can be nullptr)
dialogTitlethe title for the warning dialog
showDialogif false, the dialog will not be shown and the function will return true for non-standard types (useful for automated testing)
isNonStandardif not nullptr, will be set to true if the geometry type is non-standard for GeoPackage, false otherwise
Returns
true if the geometry type is standard, or if non-standard and the user chose to continue; false if non-standard and the user chose to cancel
Since
QGIS 4.0

Definition at line 357 of file qgsguiutils.cpp.

Variable Documentation

◆ CANVAS_MAGNIFICATION_MAX

double QgsGuiUtils::CANVAS_MAGNIFICATION_MAX = 16.0
constexpr

Maximum magnification level allowed in map canvases.

See also
CANVAS_MAGNIFICATION_MAX

Definition at line 69 of file qgsguiutils.h.

◆ CANVAS_MAGNIFICATION_MIN

double QgsGuiUtils::CANVAS_MAGNIFICATION_MIN = 0.1
constexpr

Minimum magnification level allowed in map canvases.

See also
CANVAS_MAGNIFICATION_MAX

Definition at line 62 of file qgsguiutils.h.