Class: QgsNewNameDialog

New name, for example new layer name dialog. If existing names are provided, the dialog warns users if an entered name already exists.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsNewNameDialog

Base classes

QgsDialog

A generic dialog with layout and button box

QDialog

QWidget

QObject

QPaintDevice

Methods

allowEmptyName

Returns True if the widget can be left empty (no name filled).

conflictingNameWarning

Returns the string used for warning users if a conflicting name exists.

highlightText

List of names with extensions

hintString

Returns the hint string for the dialog (the text shown above the name input box).

name

Name entered by user.

nameChanged

overwriteEnabled

Returns whether users are permitted to overwrite existing names.

setAllowEmptyName

Sets whether users are permitted to leave the widget empty.

setConflictingNameWarning

Sets the string used for warning users if a conflicting name exists.

setHintString

Sets the hint string for the dialog (the text shown above the name input box).

setOverwriteEnabled

Sets whether users are permitted to overwrite existing names.

setRegularExpression

Sets a regular expression to use for validating user-entered names in the dialog.

Static Methods

exists

Test if name or name with at least one extension exists.

fullNames

matching

Signals

newNameChanged

Emitted when the name is changed in the dialog.

class qgis.gui.QgsNewNameDialog[source]

Bases: QgsDialog

__init__(source: str | None = '', initial: str | None = '', extensions: Iterable[str | None] = [], existing: Iterable[str | None] = [], cs: Qt.CaseSensitivity = Qt.CaseSensitive, parent: QWidget | None = None, flags: Qt.WindowFlags | Qt.WindowType = QgsGuiUtils.ModalDialogFlags)

New dialog constructor.

Parameters:
  • source (Optional[str] = '') – original data source name, e.g. original layer name of the layer to be copied

  • initial (Optional[str] = '') – initial name

  • extensions (Iterable[Optional[str]] = []) – base name extensions, e.g. raster base name band extensions or vector layer type extensions

  • existing (Iterable[Optional[str]] = []) – existing names

  • cs (Qt.CaseSensitivity = Qt.CaseSensitive) – case sensitivity for new name to existing names comparison

  • parent (Optional[QWidget] = None) – parent widget

  • flags (Union[Qt.WindowFlags, Qt.WindowType] = QgsGuiUtils.ModalDialogFlags) – window flags

Note

Earlier versions had a similar constructor but with extra arguments for regexp which were removed in QGIS 3.22 as they relied on the deprecated QRegExp class. Use setRegularExpression() instead.

Added in version 3.22.

allowEmptyName(self) bool[source]

Returns True if the widget can be left empty (no name filled).

Added in version 3.14.

Return type:

bool

conflictingNameWarning(self) str[source]

Returns the string used for warning users if a conflicting name exists.

Return type:

str

static exists(name: str | None, extensions: Iterable[str | None], existing: Iterable[str | None], cs: Qt.CaseSensitivity = Qt.CaseSensitive) bool[source]

Test if name or name with at least one extension exists.

Parameters:
  • name (Optional[str]) – name or base name

  • extensions (Iterable[Optional[str]]) – base name extensions

  • existing (Iterable[Optional[str]]) – existing names

  • cs (Qt.CaseSensitivity = Qt.CaseSensitive) – case sensitivity for new name to existing names comparison

Return type:

bool

Returns:

True if name exists

static fullNames(name: str | None, extensions: Iterable[str | None]) List[str][source]
Parameters:
  • name (Optional[str])

  • extensions (Iterable[Optional[str]])

Return type:

List[str]

highlightText(self, text: str | None) str[source]

List of names with extensions

Parameters:

text (Optional[str])

Return type:

str

hintString(self) str[source]

Returns the hint string for the dialog (the text shown above the name input box).

See also

setHintString()

Return type:

str

static matching(newNames: Iterable[str | None], existingNames: Iterable[str | None], cs: Qt.CaseSensitivity = Qt.CaseSensitive) List[str][source]
Parameters:
  • newNames (Iterable[Optional[str]])

  • existingNames (Iterable[Optional[str]])

  • cs (Qt.CaseSensitivity = Qt.CaseSensitive)

Return type:

List[str]

name(self) str[source]

Name entered by user.

Return type:

str

Returns:

new name

See also

newNameChanged()

nameChanged(self)[source]
signal newNameChanged[source]

Emitted when the name is changed in the dialog.

Added in version 3.2.

overwriteEnabled(self) bool[source]

Returns whether users are permitted to overwrite existing names.

Return type:

bool

setAllowEmptyName(self, allowed: bool)[source]

Sets whether users are permitted to leave the widget empty. If True, the dialog will accept an empty name value.

See also

allowEmptyName()

Added in version 3.14.

Parameters:

allowed (bool)

setConflictingNameWarning(self, string: str | None)[source]

Sets the string used for warning users if a conflicting name exists.

Parameters:

string (Optional[str]) – warning string. If empty a default warning string will be used.

setHintString(self, hintString: str | None)[source]

Sets the hint string for the dialog (the text shown above the name input box).

Parameters:

hintString (Optional[str]) – hint text

See also

hintString()

setOverwriteEnabled(self, enabled: bool)[source]

Sets whether users are permitted to overwrite existing names. If True, then the dialog will reflect that the new name will overwrite an existing name. If False, then the dialog will not accept names which already exist.

Parameters:

enabled (bool)

setRegularExpression(self, expression: str | None)[source]

Sets a regular expression to use for validating user-entered names in the dialog.

Added in version 3.22.

Parameters:

expression (Optional[str])