Skip to content

MonotonicListValidator

Qt Base Class: QValidator

Signature: QValidator(self, parent: Optional[PySide6.QtCore.QObject] = None) -> None

Base classes

Name Children Inherits
Validator
prettyqt.gui.validator

⋔ Inheritance diagram

graph TD
  1473296397408["validators.MonotonicListValidator"]
  1473245568976["gui.Validator"]
  1473245536768["gui.ValidatorMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473289208592["QtGui.QValidator"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473245568976 --> 1473296397408
  1473245536768 --> 1473245568976
  1473299815024 --> 1473245536768
  140713234304496 --> 1473299815024
  1473289208592 --> 1473245568976
  1473288842240 --> 1473289208592
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208

🛈 DocStrings

Bases: Validator

Validator which checks whether given string contains a monotonic list.

Source code in prettyqt\validators\monotoniclistvalidator.py
class MonotonicListValidator(gui.Validator):
    """Validator which checks whether given string contains a monotonic list."""

    ID = "monotonic"

    def __init__(self, kind: str = "increasing", parent=None):
        super().__init__(parent)
        self._kind = kind

    def __eq__(self, other: object):
        return isinstance(other, MonotonicListValidator) and other._kind == self._kind

    def validate(self, string: str, pos: int) -> tuple[gui.Validator.State, str, int]:
        if self._kind != "increasing":
            string = string[::-1]
        for i, c in enumerate(string, start=1):
            if c not in "+-., 0123456789":
                return self.State.Invalid, string, i
        if pos == len(string) >= 2 and string[-1] == " " and string[-2].isdigit():
            string = f"{string[:-1]}, "
            pos += 1
        prev = None
        for valuestr in re_custom_sep.split(string.strip()):
            try:
                value = float(valuestr)
            except ValueError:  # noqa: PERF203
                return self.State.Intermediate, string, pos
            if prev is not None and value <= prev:
                return self.State.Intermediate, string, pos
            prev = value
        return self.State.Acceptable, string, pos

⌗ Property table

Qt Property Type Doc
objectName QString

Validator ID: monotonic