aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2023-05-02 16:56:50 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2023-05-03 13:51:46 +0000
commit0ab282f3c38a7bc65d39a42c53e01548a173c04e (patch)
treef9e84da49e80fe1e80fb861e84ad00da08dd69d2 /examples
parent863ce8310e0d0d5a2bf8a33fb7101dec4e332941 (diff)
QML reference examples: Add notify signals and final attribute to properties
Task-number: PYSIDE-2206 Task-number: QTBUG-111033 Change-Id: I0541a3bbb4e5696962802da7f91ab79682700124 Reviewed-by: Christian Tismer <tismer@stackless.com> (cherry picked from commit 2388ac63d3784e59b416f993e123241cfb7f2ffa) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'examples')
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py15
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py13
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.py13
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.py13
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.py13
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py4
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.py41
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.py20
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py13
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.py27
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.py18
-rw-r--r--examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.py13
-rw-r--r--examples/qml/tutorials/extending-qml/chapter1-basics/basics.py4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter2-methods/methods.py4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter3-bindings/bindings.py4
-rw-r--r--examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py6
-rw-r--r--examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py10
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.py2
-rw-r--r--examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.py6
19 files changed, 157 insertions, 82 deletions
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
index 47dddc85d..764815175 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/birthdayparty.py
@@ -1,7 +1,7 @@
-# Copyright (C) 2022 The Qt Company Ltd.
+# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtQml import QmlElement, ListProperty
from person import Person
@@ -15,19 +15,23 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
class BirthdayParty(QObject):
+ host_changed = Signal()
+ guests_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._host = None
self._guests = []
- @Property(Person)
+ @Property(Person, notify=host_changed, final=True)
def host(self):
return self._host
@host.setter
def host(self, h):
- self._host = h
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
def guest(self, n):
return self._guests[n]
@@ -37,5 +41,6 @@ class BirthdayParty(QObject):
def appendGuest(self, guest):
self._guests.append(guest)
+ self.guests_changed.emit()
- guests = ListProperty(Person, appendGuest)
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py
index 189f2573e..57e73e6f5 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced2-Inheritance-and-coercion/person.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtQml import QmlElement, QmlUncreatable
# To be used on the @QmlElement decorator
@@ -13,20 +13,25 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
@QmlUncreatable("Person is an abstract base class.")
class Person(QObject):
+ name_changed = Signal()
+ shoe_size_changed = Signal()
+
def __init__(self, parent=None):
super().__init__(parent)
self._name = ''
self._shoe_size = 0
- @Property(str)
+ @Property(str, notify=name_changed, final=True)
def name(self):
return self._name
@name.setter
def name(self, n):
- self._name = n
+ if self._name != n:
+ self._name = n
+ self.name_changed.emit()
- @Property(int)
+ @Property(int, notify=shoe_size_changed, final=True)
def shoe_size(self):
return self._shoe_size
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.py
index 8c6f7e8fb..3f6102c66 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/birthdayparty.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, ClassInfo, Property
+from PySide6.QtCore import QObject, ClassInfo, Property, Signal
from PySide6.QtQml import QmlElement, ListProperty
from person import Person
@@ -16,19 +16,23 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
@ClassInfo(DefaultProperty="guests")
class BirthdayParty(QObject):
+ host_changed = Signal()
+ guests_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._host = None
self._guests = []
- @Property(Person)
+ @Property(Person, notify=host_changed, final=True)
def host(self):
return self._host
@host.setter
def host(self, h):
- self._host = h
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
def guest(self, n):
return self._guests[n]
@@ -38,5 +42,6 @@ class BirthdayParty(QObject):
def appendGuest(self, guest):
self._guests.append(guest)
+ self.guests_changed.emit()
- guests = ListProperty(Person, appendGuest)
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.py
index 89844c87f..503aaf65e 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced3-Default-properties/person.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtQml import QmlAnonymous, QmlElement
# To be used on the @QmlElement decorator
@@ -12,20 +12,25 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
class Person(QObject):
+ name_changed = Signal()
+ shoe_size_changed = Signal()
+
def __init__(self, parent=None):
super().__init__(parent)
self._name = ''
self._shoe_size = 0
- @Property(str)
+ @Property(str, notify=name_changed, final=True)
def name(self):
return self._name
@name.setter
def name(self, n):
- self._name = n
+ if self._name != n:
+ self._name = n
+ self.name_changed.emit()
- @Property(int)
+ @Property(int, notify=shoe_size_changed, final=True)
def shoe_size(self):
return self._shoe_size
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.py
index 8c6f7e8fb..3f6102c66 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/birthdayparty.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, ClassInfo, Property
+from PySide6.QtCore import QObject, ClassInfo, Property, Signal
from PySide6.QtQml import QmlElement, ListProperty
from person import Person
@@ -16,19 +16,23 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
@ClassInfo(DefaultProperty="guests")
class BirthdayParty(QObject):
+ host_changed = Signal()
+ guests_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._host = None
self._guests = []
- @Property(Person)
+ @Property(Person, notify=host_changed, final=True)
def host(self):
return self._host
@host.setter
def host(self, h):
- self._host = h
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
def guest(self, n):
return self._guests[n]
@@ -38,5 +42,6 @@ class BirthdayParty(QObject):
def appendGuest(self, guest):
self._guests.append(guest)
+ self.guests_changed.emit()
- guests = ListProperty(Person, appendGuest)
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py
index 657ce272b..3cdddbd06 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/main.py
@@ -37,8 +37,8 @@ if __name__ == '__main__':
name = guest.name
print(f" {name}")
if not best_shoe or best_shoe.shoe.price < guest.shoe.price:
- best_shoe = guest;
+ best_shoe = guest
if best_shoe:
- print(f"{best_shoe.name} is wearing the best shoes!");
+ print(f"{best_shoe.name} is wearing the best shoes!")
del engine
sys.exit(0)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.py
index 42434fffa..ccd439e88 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced4-Grouped-properties/person.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtGui import QColor
from PySide6.QtQml import QmlAnonymous, QmlElement
@@ -13,6 +13,11 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
class ShoeDescription(QObject):
+ brand_changed = Signal()
+ size_changed = Signal()
+ price_changed = Signal()
+ color_changed = Signal()
+
def __init__(self, parent=None):
super().__init__(parent)
self._brand = ''
@@ -20,55 +25,67 @@ class ShoeDescription(QObject):
self._price = 0
self._color = QColor()
- @Property(str)
+ @Property(str, notify=brand_changed, final=True)
def brand(self):
return self._brand
@brand.setter
def brand(self, b):
- self._brand = b
+ if self._brand != b:
+ self._brand = b
+ self.brand_changed.emit()
- @Property(int)
+ @Property(int, notify=size_changed, final=True)
def size(self):
return self._size
@size.setter
def size(self, s):
- self._size = s
+ if self._size != s:
+ self._size = s
+ self.size_changed.emit()
- @Property(float)
+ @Property(float, notify=price_changed, final=True)
def price(self):
return self._price
@price.setter
def price(self, p):
- self._price = p
+ if self._price != p:
+ self._price = p
+ self.price_changed.emit()
- @Property(QColor)
+ @Property(QColor, notify=color_changed, final=True)
def color(self):
return self._color
@color.setter
def color(self, c):
- self._color = c
+ if self._color != c:
+ self._color = c
+ self.color_changed.emit()
@QmlAnonymous
class Person(QObject):
+ name_changed = Signal()
+
def __init__(self, parent=None):
super().__init__(parent)
self._name = ''
self._shoe = ShoeDescription()
- @Property(str)
+ @Property(str, notify=name_changed, final=True)
def name(self):
return self._name
@name.setter
def name(self, n):
- self._name = n
+ if self._name != n:
+ self._name = n
+ self.name_changed.emit()
- @Property(ShoeDescription)
+ @Property(ShoeDescription, final=True)
def shoe(self):
return self._shoe
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.py
index 63e86c3e0..f38bfd305 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/birthdayparty.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QDate, QObject, ClassInfo, Property
+from PySide6.QtCore import QDate, QObject, ClassInfo, Property, Signal
from PySide6.QtQml import QmlAnonymous, QmlAttached, QmlElement, ListProperty
from person import Person
@@ -15,37 +15,44 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
class BirthdayPartyAttached(QObject):
+ rsvp_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._rsvp = QDate()
- @Property(QDate)
+ @Property(QDate, notify=rsvp_changed, final=True)
def rsvp(self):
return self._rsvp
@rsvp.setter
def rsvp(self, d):
- self._rsvp = d
+ if self._rsvp != d:
+ self._rsvp = d
+ self.rsvp_changed.emit()
@QmlElement
@ClassInfo(DefaultProperty="guests")
@QmlAttached(BirthdayPartyAttached)
class BirthdayParty(QObject):
+ host_changed = Signal()
+ guests_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._host = None
self._guests = []
- @Property(Person)
+ @Property(Person, notify=host_changed, final=True)
def host(self):
return self._host
@host.setter
def host(self, h):
- self._host = h
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
def guest(self, n):
return self._guests[n]
@@ -55,9 +62,10 @@ class BirthdayParty(QObject):
def appendGuest(self, guest):
self._guests.append(guest)
+ self.guests_changed.emit()
@staticmethod
def qmlAttachedProperties(self, o):
return BirthdayPartyAttached(o)
- guests = ListProperty(Person, appendGuest)
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py
index 89844c87f..503aaf65e 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced5-Attached-properties/person.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtQml import QmlAnonymous, QmlElement
# To be used on the @QmlElement decorator
@@ -12,20 +12,25 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
class Person(QObject):
+ name_changed = Signal()
+ shoe_size_changed = Signal()
+
def __init__(self, parent=None):
super().__init__(parent)
self._name = ''
self._shoe_size = 0
- @Property(str)
+ @Property(str, notify=name_changed, final=True)
def name(self):
return self._name
@name.setter
def name(self, n):
- self._name = n
+ if self._name != n:
+ self._name = n
+ self.name_changed.emit()
- @Property(int)
+ @Property(int, notify=shoe_size_changed, final=True)
def shoe_size(self):
return self._shoe_size
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.py b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.py
index 52af2fe97..eacb5201d 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/birthdayparty.py
@@ -15,18 +15,21 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
class BirthdayPartyAttached(QObject):
+ rsvp_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self._rsvp = QDate()
- @Property(QDate)
+ @Property(QDate, notify=rsvp_changed, final=True)
def rsvp(self):
return self._rsvp
@rsvp.setter
def rsvp(self, d):
- self._rsvp = d
+ if self._rsvp != d:
+ self._rsvp = d
+ self.rsvp_changed.emit()
@QmlElement
@@ -34,30 +37,39 @@ class BirthdayPartyAttached(QObject):
@QmlAttached(BirthdayPartyAttached)
class BirthdayParty(QObject):
+ announcement_changed = Signal()
+ host_changed = Signal()
+ guests_changed = Signal()
partyStarted = Signal(QTime)
def __init__(self, parent=None):
super().__init__(parent)
+ self._announcement = ""
self._host = None
self._guests = []
def startParty(self):
self.partyStarted.emit(QTime.currentTime())
- @Property(Person)
+ @Property(Person, notify=host_changed, final=True)
def host(self):
return self._host
@host.setter
def host(self, h):
- self._host = h
+ if self._host != h:
+ self._host = h
+ self.host_changed.emit()
- @Property(str)
+ @Property(str, notify=announcement_changed, final=True)
def announcement(self):
- return ""
+ return self._announcement
@announcement.setter
def announcement(self, a):
+ if self._announcement != a:
+ self._announcement = a
+ self.announcement_changed.emit()
print(a)
def guest(self, n):
@@ -68,9 +80,10 @@ class BirthdayParty(QObject):
def appendGuest(self, guest):
self._guests.append(guest)
+ self.guests_changed.emit()
@staticmethod
def qmlAttachedProperties(self, o):
return BirthdayPartyAttached(o)
- guests = ListProperty(Person, appendGuest)
+ guests = ListProperty(Person, appendGuest, notify=guests_changed, final=True)
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.py b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.py
index 59ebfe4c6..c35f9bffa 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/happybirthdaysong.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QTimer, Property, Slot
+from PySide6.QtCore import QTimer, Property, Signal, Slot
from PySide6.QtQml import QmlElement, QPyQmlPropertyValueSource
# To be used on the @QmlElement decorator
@@ -12,6 +12,7 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlElement
class HappyBirthdaySong(QPyQmlPropertyValueSource):
+ name_changed = Signal()
def __init__(self, parent=None):
super().__init__(parent)
@@ -28,18 +29,19 @@ class HappyBirthdaySong(QPyQmlPropertyValueSource):
def setTarget(self, property):
self.m_target = property
- @Property(str)
+ @Property(str, notify=name_changed, final=True)
def name(self):
return self.m_name
@name.setter
def name(self, n):
- self.m_name = n
- self.m_lyrics = ["Happy birthday to you,",
- "Happy birthday to you,",
- f"Happy birthday dear {self.m_name},",
- "Happy birthday to you!",
- ""]
+ if self.m_name != n:
+ self.m_name = n
+ self.m_lyrics = ["Happy birthday to you,",
+ "Happy birthday to you,",
+ f"Happy birthday dear {self.m_name},",
+ "Happy birthday to you!",
+ ""]
@Slot()
def advance(self):
diff --git a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.py b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.py
index 89844c87f..503aaf65e 100644
--- a/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.py
+++ b/examples/qml/tutorials/extending-qml-advanced/advanced6-Property-value-source/person.py
@@ -1,7 +1,7 @@
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
-from PySide6.QtCore import QObject, Property
+from PySide6.QtCore import QObject, Property, Signal
from PySide6.QtQml import QmlAnonymous, QmlElement
# To be used on the @QmlElement decorator
@@ -12,20 +12,25 @@ QML_IMPORT_MAJOR_VERSION = 1
@QmlAnonymous
class Person(QObject):
+ name_changed = Signal()
+ shoe_size_changed = Signal()
+
def __init__(self, parent=None):
super().__init__(parent)
self._name = ''
self._shoe_size = 0
- @Property(str)
+ @Property(str, notify=name_changed, final=True)
def name(self):
return self._name
@name.setter
def name(self, n):
- self._name = n
+ if self._name != n:
+ self._name = n
+ self.name_changed.emit()
- @Property(int)
+ @Property(int, notify=shoe_size_changed, final=True)
def shoe_size(self):
return self._shoe_size
diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/basics.py b/examples/qml/tutorials/extending-qml/chapter1-basics/basics.py
index f76183705..47d0a0e0c 100644
--- a/examples/qml/tutorials/extending-qml/chapter1-basics/basics.py
+++ b/examples/qml/tutorials/extending-qml/chapter1-basics/basics.py
@@ -34,7 +34,7 @@ class PieChart (QQuickPaintedItem):
painter.setRenderHints(QPainter.Antialiasing, True)
painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16)
- @Property(QColor)
+ @Property(QColor, final=True)
def color(self):
return self._color
@@ -42,7 +42,7 @@ class PieChart (QQuickPaintedItem):
def color(self, value):
self._color = value
- @Property(str, notify=nameChanged)
+ @Property(str, notify=nameChanged, final=True)
def name(self):
return self._name
diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/methods.py b/examples/qml/tutorials/extending-qml/chapter2-methods/methods.py
index f8241db72..d455c317b 100644
--- a/examples/qml/tutorials/extending-qml/chapter2-methods/methods.py
+++ b/examples/qml/tutorials/extending-qml/chapter2-methods/methods.py
@@ -35,7 +35,7 @@ class PieChart(QQuickPaintedItem):
painter.setRenderHints(QPainter.Antialiasing, True)
painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16)
- @Property(QColor)
+ @Property(QColor, final=True)
def color(self):
return self._color
@@ -43,7 +43,7 @@ class PieChart(QQuickPaintedItem):
def color(self, value):
self._color = value
- @Property(str, notify=nameChanged)
+ @Property(str, notify=nameChanged, final=True)
def name(self):
return self._name
diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/bindings.py b/examples/qml/tutorials/extending-qml/chapter3-bindings/bindings.py
index e50f08397..a9b61e7f1 100644
--- a/examples/qml/tutorials/extending-qml/chapter3-bindings/bindings.py
+++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/bindings.py
@@ -36,7 +36,7 @@ class PieChart (QQuickPaintedItem):
painter.setRenderHints(QPainter.Antialiasing, True)
painter.drawPie(self.boundingRect().adjusted(1, 1, -1, -1), 90 * 16, 290 * 16)
- @Property(QColor, notify=colorChanged)
+ @Property(QColor, notify=colorChanged, final=True)
def color(self):
return self._color
@@ -47,7 +47,7 @@ class PieChart (QQuickPaintedItem):
self.update()
self.colorChanged.emit()
- @Property(str, notify=nameChanged)
+ @Property(str, notify=nameChanged, final=True)
def name(self):
return self._name
diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py
index ee10f0894..c70d7fc42 100644
--- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py
+++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/customPropertyTypes.py
@@ -25,7 +25,7 @@ class PieSlice (QQuickPaintedItem):
QQuickPaintedItem.__init__(self, parent)
self._color = QColor()
- @Property(QColor)
+ @Property(QColor, final=True)
def color(self):
return self._color
@@ -47,7 +47,7 @@ class PieChart (QQuickItem):
self._name = None
self._pieSlice = None
- @Property(str)
+ @Property(str, final=True)
def name(self):
return self._name
@@ -55,7 +55,7 @@ class PieChart (QQuickItem):
def name(self, value):
self._name = value
- @Property(PieSlice)
+ @Property(PieSlice, final=True)
def pieSlice(self):
return self._pieSlice
diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py b/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py
index 95a393fa3..236c487f9 100644
--- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py
+++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/listproperties.py
@@ -26,7 +26,7 @@ class PieSlice (QQuickPaintedItem):
self._fromAngle = 0
self._angleSpan = 0
- @Property(QColor)
+ @Property(QColor, final=True)
def color(self):
return self._color
@@ -34,7 +34,7 @@ class PieSlice (QQuickPaintedItem):
def color(self, value):
self._color = value
- @Property(int)
+ @Property(int, final=True)
def fromAngle(self):
return self._angle
@@ -42,7 +42,7 @@ class PieSlice (QQuickPaintedItem):
def fromAngle(self, value):
self._fromAngle = value
- @Property(int)
+ @Property(int, final=True)
def angleSpan(self):
return self._angleSpan
@@ -64,7 +64,7 @@ class PieChart (QQuickItem):
self._name = u''
self._slices = []
- @Property(str)
+ @Property(str, final=True)
def name(self):
return self._name
@@ -76,7 +76,7 @@ class PieChart (QQuickItem):
_slice.setParentItem(self)
self._slices.append(_slice)
- slices = ListProperty(PieSlice, appendSlice)
+ slices = ListProperty(PieSlice, appendSlice, final=True)
if __name__ == '__main__':
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.py b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.py
index b721a7130..6a7e80ccb 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.py
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.py
@@ -19,7 +19,7 @@ class PieChart(QQuickItem):
self._slices = []
self._name = ''
- @Property(str)
+ @Property(str, final=True)
def name(self):
return self._name
diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.py b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.py
index 7945eff12..67242a967 100644
--- a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.py
+++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.py
@@ -20,7 +20,7 @@ class PieSlice(QQuickPaintedItem):
self._from_angle = 0
self._angle_span = 0
- @Property(QColor)
+ @Property(QColor, final=True)
def color(self):
return self._color
@@ -28,7 +28,7 @@ class PieSlice(QQuickPaintedItem):
def color(self, color):
self._color = QColor(color)
- @Property(int)
+ @Property(int, final=True)
def fromAngle(self):
return self._from_angle
@@ -36,7 +36,7 @@ class PieSlice(QQuickPaintedItem):
def fromAngle(self, fromAngle):
self._from_angle = fromAngle
- @Property(int)
+ @Property(int, final=True)
def angleSpan(self):
return self._angle_span