diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-09-15 13:21:53 +0200 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2022-09-16 10:30:36 +0200 |
commit | cf32b66adbfb489cd6e5d5c0bf3f741b59ba204c (patch) | |
tree | 44be69c9487f5d4db1092d061a555bd6001c1ab4 /examples/declarative/referenceexamples/adding | |
parent | b20d6f6906f91f9df608d7800f4e27f7a7160abe (diff) |
Move examples around
Change the directory structure to closer match that of Qt.
Task-number: PYSIDE-841
Change-Id: I87aca346b6654aafe94dd1fb83c184c182ceb2e6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Cristian Maureira-Fredes <cristian.maureira-fredes@qt.io>
Diffstat (limited to 'examples/declarative/referenceexamples/adding')
5 files changed, 0 insertions, 146 deletions
diff --git a/examples/declarative/referenceexamples/adding/adding.pyproject b/examples/declarative/referenceexamples/adding/adding.pyproject deleted file mode 100644 index 46df4b253..000000000 --- a/examples/declarative/referenceexamples/adding/adding.pyproject +++ /dev/null @@ -1,5 +0,0 @@ -{ - "files": ["example.qml", - "main.py", - "person.py"] -} diff --git a/examples/declarative/referenceexamples/adding/doc/adding.rst b/examples/declarative/referenceexamples/adding/doc/adding.rst deleted file mode 100644 index 55f6105b7..000000000 --- a/examples/declarative/referenceexamples/adding/doc/adding.rst +++ /dev/null @@ -1,67 +0,0 @@ -.. _qml-adding-types-example: - -Extending QML - Adding Types Example -==================================== - -The Adding Types Example shows how to add a new object type, ``Person``, to QML. -The ``Person`` type can be used from QML like this: - -.. code-block:: javascript - - import examples.adding.people - - Person { - name: "Bob Jones" - shoe_size: 12 - } - -Declare the Person Class ------------------------- - -All QML types map to C++ types. Here we declare a basic C++ Person class -with the two properties we want accessible on the QML type - name and shoeSize. -Although in this example we use the same name for the C++ class as the QML -type, the C++ class can be named differently, or appear in a namespace. - -The Person class implementation is quite basic. The property accessors simply -return members of the object instance. - -.. code-block:: python - - from PySide6.QtCore import QObject, Property - from PySide6.QtQml import QmlElement - - # To be used on the @QmlElement decorator - # (QML_IMPORT_MINOR_VERSION is optional) - QML_IMPORT_NAME = "examples.adding.people" - QML_IMPORT_MAJOR_VERSION = 1 - - - @QmlElement - class Person(QObject): - def __init__(self, parent=None): - super().__init__(parent) - self._name = '' - self._shoe_size = 0 - - @Property(str) - def name(self): - return self._name - - @name.setter - def name(self, n): - self._name = n - - @Property(int) - def shoe_size(self): - return self._shoe_size - - @shoe_size.setter - def shoe_size(self, s): - self._shoe_size = s - -Running the Example -------------------- - -The main.py file in the example includes a simple shell application that -loads and runs the QML snippet shown at the beginning of this page. diff --git a/examples/declarative/referenceexamples/adding/example.qml b/examples/declarative/referenceexamples/adding/example.qml deleted file mode 100644 index 42d47dea9..000000000 --- a/examples/declarative/referenceexamples/adding/example.qml +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (C) 2017 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -import examples.adding.people - -Person { - name: "Bob Jones" - shoe_size: 12 -} diff --git a/examples/declarative/referenceexamples/adding/main.py b/examples/declarative/referenceexamples/adding/main.py deleted file mode 100644 index f10b77bc1..000000000 --- a/examples/declarative/referenceexamples/adding/main.py +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -"""PySide6 port of the qml/examples/qml/referenceexamples/adding example from Qt v6.x""" - -from pathlib import Path -import sys - -from PySide6.QtCore import QCoreApplication, QUrl -from PySide6.QtQml import QQmlComponent, QQmlEngine - -from person import Person - - -if __name__ == '__main__': - app = QCoreApplication(sys.argv) - - qml_file = Path(__file__).parent / "example.qml" - url = QUrl.fromLocalFile(qml_file) - engine = QQmlEngine() - component = QQmlComponent(engine, url) - - person = component.create() - if person: - print(f"The person's name is {person.name}") - print(f"They wear a {person.shoe_size} sized shoe") - else: - print(component.errors()) - del engine - sys.exit(0) diff --git a/examples/declarative/referenceexamples/adding/person.py b/examples/declarative/referenceexamples/adding/person.py deleted file mode 100644 index 0c2b5b124..000000000 --- a/examples/declarative/referenceexamples/adding/person.py +++ /dev/null @@ -1,35 +0,0 @@ -# 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.QtQml import QmlElement - -# To be used on the @QmlElement decorator -# (QML_IMPORT_MINOR_VERSION is optional) -QML_IMPORT_NAME = "examples.adding.people" -QML_IMPORT_MAJOR_VERSION = 1 - - -@QmlElement -class Person(QObject): - def __init__(self, parent=None): - super().__init__(parent) - self._name = '' - self._shoe_size = 0 - - @Property(str) - def name(self): - return self._name - - @name.setter - def name(self, n): - self._name = n - - @Property(int) - def shoe_size(self): - return self._shoe_size - - @shoe_size.setter - def shoe_size(self, s): - self._shoe_size = s - |