Class: QgsNewNameDialog

A dialog for prompting users for a 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

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]

static highlightText(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]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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])

setShowExistingNamesCompleter(self, show: bool)[source]

Sets whether a completer for existing names should be used in the line edit.

This is not shown by default. If the dialog is expected to be used in a context where overwriting is permitted, consider enabling this so that users can more easily enter an existing name.

Added in version 3.44.

Parameters:

show (bool)