Subgroup: other

Class: QgsSettings

class qgis.core.QgsSettings(organization: str, application: str = '', parent: QObject = None)

Bases: PyQt5.QtCore.QObject

Construct a QgsSettings object for accessing settings of the application called application from the organization called organization, and with parent parent.

QgsSettings(scope: QSettings.Scope, organization: str, application: str = ‘’, parent: QObject = None) Construct a QgsSettings object for accessing settings of the application called application from the organization called organization, and with parent parent. If scope is QSettings.UserScope, the QSettings object searches user-specific settings first, before it searches system-wide settings as a fallback. If scope is QSettings.SystemScope, the QSettings object ignores user-specific settings and provides access to system-wide settings.

The storage format is set to QSettings.NativeFormat (i.e. calling setDefaultFormat() before calling this constructor has no effect).

If no application name is given, the QSettings object will only access the organization-wide locations.

QgsSettings(format: QSettings.Format, scope: QSettings.Scope, organization: str, application: str = ‘’, parent: QObject = None) Construct a QgsSettings object for accessing settings of the application called application from the organization called organization, and with parent parent. If scope is QSettings.UserScope, the QSettings object searches user-specific settings first, before it searches system-wide settings as a fallback. If scope is QSettings.SystemScope, the QSettings object ignores user-specific settings and provides access to system-wide settings. If format is QSettings.NativeFormat, the native API is used for storing settings. If format is QSettings.IniFormat, the INI format is used.

If no application name is given, the QSettings object will only access the organization-wide locations.

QgsSettings(fileName: str, format: QSettings.Format, parent: QObject = None) Construct a QgsSettings object for accessing the settings stored in the file called fileName, with parent parent. If the file doesn’t already exist, it is created.

If format is QSettings.NativeFormat, the meaning of fileName depends on the platform. On Unix, fileName is the name of an INI file. On macOS and iOS, fileName is the name of a .plist file. On Windows, fileName is a path in the system registry.

If format is QSettings.IniFormat, fileName is the name of an INI file.

Warning: This function is provided for convenience. It works well for accessing INI or .plist files generated by Qt, but might fail on some syntaxes found in such files originated by other programs. In particular, be aware of the following limitations: - QgsSettings provides no way of reading INI “path” entries, i.e., entries with unescaped slash characters. (This is because these entries are ambiguous and cannot be resolved automatically.) - In INI files, QSettings uses the @ character as a metacharacter in some contexts, to encode Qt-specific data types (e.g., @Rect), and might therefore misinterpret it when it occurs in pure INI files.

QgsSettings(parent: QObject = None) Constructs a QgsSettings object for accessing settings of the application and organization set previously with a call to QCoreApplication.setOrganizationName(), QCoreApplication.setOrganizationDomain(), and QCoreApplication.setApplicationName().

The scope is QSettings.UserScope and the format is defaultFormat() (QSettings.NativeFormat by default). Use setDefaultFormat() before calling this constructor to change the default format used by this constructor.

This class is a composition of two QSettings instances: - the main QSettings instance is the standard User Settings and - the second one (Global Settings) is meant to provide read-only pre-configuration and defaults to the first one.

For a given settings key, the function call to value(key, default) will return the first existing setting in the order specified below: - User Settings - Global Settings - Default Value

The path to the Global Settings storage can be set before constructing the QgsSettings objects, with a static call to: static bool setGlobalSettingsPath( QString path );

QgsSettings provides some shortcuts to get/set namespaced settings from/to a specific section: - Core - Gui - Server - Plugins - Auth - App - Providers - Misc

New in version 3: Methods

allKeys Returns a list of all keys, including subkeys, that can be read using the QSettings object.
beginGroup Appends prefix to the current group.
beginReadArray Adds prefix to the current group and starts reading from an array.
beginWriteArray Adds prefix to the current group and starts writing an array of size size.
childEvent
childGroups Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.
childKeys Returns a list of all top-level keys that can be read using the QSettings object.
clear Removes all entries in the user settings
connectNotify
contains Returns true if there exists a setting called key; returns false otherwise.
customEvent
disconnectNotify
endArray Closes the array that was started using beginReadArray() or beginWriteArray().
endGroup Resets the group to what it was before the corresponding beginGroup() call.
fileName Returns the path where settings written using this QSettings object are stored.
globalChildGroups Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.
globalSettingsPath Return the path to the Global Settings QSettings storage file
isSignalConnected
prefixedKey Return the sanitized and prefixed key
receivers
remove Removes the setting key and any sub-settings of key in a section.
sender
senderSignalIndex
setArrayIndex Sets the current array index to i.
setGlobalSettingsPath Set the Global Settings QSettings storage file
setValue Sets the value of setting key to value.
sync Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application.
timerEvent
value Returns the value for setting key.

Signals

Attributes

App
Auth
Core
Gui
Misc
NoSection
Plugins
Providers
Server
App = 6
Auth = 5
Core = 1
Gui = 2
Misc = 8
NoSection = 0
Plugins = 4
Providers = 7
class Section

Bases: int

Server = 3
allKeys(self) → List[str]

Returns a list of all keys, including subkeys, that can be read using the QSettings object.

beginGroup(self, prefix: str, section: QgsSettings.Section = QgsSettings.NoSection)

Appends prefix to the current group. The current group is automatically prepended to all keys specified to QSettings. In addition, query functions such as childGroups(), childKeys(), and allKeys() are based on the group. By default, no group is set.

beginReadArray(self, prefix: str) → int

Adds prefix to the current group and starts reading from an array. Returns the size of the array.

beginWriteArray(self, prefix: str, size: int = -1)

Adds prefix to the current group and starts writing an array of size size. If size is -1 (the default), it is automatically determined based on the indexes of the entries written.

Note

This will completely shadow any existing array with the same name in the global settings

childEvent()
childGroups(self) → List[str]

Returns a list of all key top-level groups that contain keys that can be read using the QSettings object.

childKeys(self) → List[str]

Returns a list of all top-level keys that can be read using the QSettings object.

clear(self)

Removes all entries in the user settings

connectNotify()
contains(self, key: str, section: QgsSettings.Section = QgsSettings.NoSection) → bool

Returns true if there exists a setting called key; returns false otherwise. If a group is set using beginGroup(), key is taken to be relative to that group.

customEvent()
disconnectNotify()
endArray(self)

Closes the array that was started using beginReadArray() or beginWriteArray().

endGroup(self)

Resets the group to what it was before the corresponding beginGroup() call.

fileName(self) → str

Returns the path where settings written using this QSettings object are stored.

globalChildGroups(self) → List[str]

Returns a list of all key top-level groups (same as childGroups) but only for groups defined in global settings.

globalSettingsPath() → str

Return the path to the Global Settings QSettings storage file

isSignalConnected()
prefixedKey(self, key: str, section: QgsSettings.Section) → str

Return the sanitized and prefixed key

receivers()
remove(self, key: str, section: QgsSettings.Section = QgsSettings.NoSection)

Removes the setting key and any sub-settings of key in a section.

sender()
senderSignalIndex()
setArrayIndex(self, i: int)

Sets the current array index to i. Calls to functions such as setValue(), value(), remove(), and contains() will operate on the array entry at that index.

setGlobalSettingsPath(path: str) → bool

Set the Global Settings QSettings storage file

setValue(self, key: str, value: Any, section: QgsSettings.Section = QgsSettings.NoSection)

Sets the value of setting key to value. If the key already exists, the previous value is overwritten. An optional Section argument can be used to set a value to a specific Section.

sync(self)

Writes any unsaved changes to permanent storage, and reloads any settings that have been changed in the meantime by another application. This function is called automatically from QSettings’s destructor and by the event loop at regular intervals, so you normally don’t need to call it yourself.

timerEvent()
value(self, key: str, defaultValue: Any = None, type: object = 0, section: QgsSettings.Section = QgsSettings.NoSection) → object

Returns the value for setting key. If the setting doesn’t exist, it will be searched in the Global Settings and if not found, returns defaultValue. If no default value is specified, a default QVariant is returned. An optional Section argument can be used to get a value from a specific Section.