From 9e1d2a0eb15487f8f2acb4d91b281568897fb4e1 Mon Sep 17 00:00:00 2001 From: Craig Scott Date: Mon, 23 Aug 2021 16:29:18 +1000 Subject: Update qml examples for improved target path handling Some examples were still using the old "add as ordinary resources" approach for QML modules, others needed adjustment to the subdirectory structure to better reflect the URI structure of the QML modules involved. Task-number: QTBUG-95144 Pick-to: 6.2 Change-Id: Ie3399410cf6df491eb1e7b4a589ca26c577d82a0 Reviewed-by: Fabian Kosmale Reviewed-by: Alexandru Croitor --- examples/qml/.prev_CMakeLists.txt | 12 --- .../qml/networkaccessmanagerfactory/CMakeLists.txt | 16 ++-- examples/qml/qmlextensionplugins/CMakeLists.txt | 30 +++---- .../qml/referenceexamples/adding/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/attached/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/binding/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/coercion/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/default/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/extended/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/grouped/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/methods/CMakeLists.txt | 23 ++---- .../referenceexamples/properties/CMakeLists.txt | 23 ++---- .../qml/referenceexamples/signal/CMakeLists.txt | 23 ++---- .../referenceexamples/valuesource/CMakeLists.txt | 23 ++---- .../tutorials/extending-qml/.prev_CMakeLists.txt | 8 -- .../extending-qml/chapter1-basics/CMakeLists.txt | 23 ++---- .../extending-qml/chapter2-methods/CMakeLists.txt | 23 ++---- .../extending-qml/chapter3-bindings/CMakeLists.txt | 23 ++---- .../chapter4-customPropertyTypes/CMakeLists.txt | 23 ++---- .../chapter5-listproperties/CMakeLists.txt | 23 ++---- .../chapter6-plugins/.prev_CMakeLists.txt | 51 ------------ .../extending-qml/chapter6-plugins/CMakeLists.txt | 19 ++--- .../chapter6-plugins/Charts/CMakeLists.txt | 48 +++++++++++ .../chapter6-plugins/Charts/Charts.pro | 32 ++++++++ .../chapter6-plugins/Charts/chartsplugin.h | 64 +++++++++++++++ .../chapter6-plugins/Charts/piechart.cpp | 81 ++++++++++++++++++ .../chapter6-plugins/Charts/piechart.h | 80 ++++++++++++++++++ .../chapter6-plugins/Charts/pieslice.cpp | 96 ++++++++++++++++++++++ .../chapter6-plugins/Charts/pieslice.h | 85 +++++++++++++++++++ .../extending-qml/chapter6-plugins/Charts/qmldir | 2 + .../chapter6-plugins/chapter6-plugins.pro | 2 +- .../chapter6-plugins/import/CMakeLists.txt | 48 ----------- .../chapter6-plugins/import/chartsplugin.h | 64 --------------- .../chapter6-plugins/import/import.pro | 36 -------- .../chapter6-plugins/import/piechart.cpp | 81 ------------------ .../chapter6-plugins/import/piechart.h | 80 ------------------ .../chapter6-plugins/import/pieslice.cpp | 96 ---------------------- .../chapter6-plugins/import/pieslice.h | 85 ------------------- .../extending-qml/chapter6-plugins/import/qmldir | 2 - examples/qml/xmlhttprequest/CMakeLists.txt | 27 +++--- 40 files changed, 609 insertions(+), 904 deletions(-) delete mode 100644 examples/qml/.prev_CMakeLists.txt delete mode 100644 examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/Charts.pro create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/chartsplugin.h create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.cpp create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.cpp create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h create mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.cpp delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h delete mode 100644 examples/qml/tutorials/extending-qml/chapter6-plugins/import/qmldir (limited to 'examples') diff --git a/examples/qml/.prev_CMakeLists.txt b/examples/qml/.prev_CMakeLists.txt deleted file mode 100644 index 0ec4c9b39d..0000000000 --- a/examples/qml/.prev_CMakeLists.txt +++ /dev/null @@ -1,12 +0,0 @@ -# Generated from qml.pro. - -add_subdirectory(referenceexamples) -add_subdirectory(tutorials) -add_subdirectory(shell) -if(TARGET Qt::Quick) - add_subdirectory(qmlextensionplugins) - add_subdirectory(xmlhttprequest) -endif() -if(QT_FEATURE_qml_network AND TARGET Qt::Quick) - add_subdirectory(networkaccessmanagerfactory) -endif() diff --git a/examples/qml/networkaccessmanagerfactory/CMakeLists.txt b/examples/qml/networkaccessmanagerfactory/CMakeLists.txt index 90afa4b5a1..fd4444a99b 100644 --- a/examples/qml/networkaccessmanagerfactory/CMakeLists.txt +++ b/examples/qml/networkaccessmanagerfactory/CMakeLists.txt @@ -36,17 +36,11 @@ target_link_libraries(networkaccessmanagerfactory PUBLIC Qt::Quick ) - -# Resources: -set(networkaccessmanagerfactory_resource_files - "view.qml" -) - -qt6_add_resources(networkaccessmanagerfactory "networkaccessmanagerfactory" - PREFIX - "/" - FILES - ${networkaccessmanagerfactory_resource_files} +qt_add_qml_module(networkaccessmanagerfactory + URI Example + VERSION 1.0 + QML_FILES view.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS networkaccessmanagerfactory diff --git a/examples/qml/qmlextensionplugins/CMakeLists.txt b/examples/qml/qmlextensionplugins/CMakeLists.txt index 62a92e6033..8156f23eb1 100644 --- a/examples/qml/qmlextensionplugins/CMakeLists.txt +++ b/examples/qml/qmlextensionplugins/CMakeLists.txt @@ -14,20 +14,32 @@ if(NOT DEFINED INSTALL_EXAMPLESDIR) endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/qmlextensionplugins/imports/TimeExample") -set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/qml/qmlextensionplugins/imports) find_package(Qt6 COMPONENTS Core) find_package(Qt6 COMPONENTS Gui) find_package(Qt6 COMPONENTS Qml) -set_source_files_properties(imports/TimeExample/Clock.qml PROPERTIES - QT_RESOURCE_ALIAS Clock.qml +set(qml_files + imports/TimeExample/Clock.qml ) +set(images + imports/TimeExample/center.png + imports/TimeExample/clock.png + imports/TimeExample/hour.png + imports/TimeExample/minute.png +) +foreach(file IN LISTS qml_files images) + get_filename_component(filename ${file} NAME) + set_source_files_properties(${file} PROPERTIES QT_RESOURCE_ALIAS ${filename}) +endforeach() + qt6_add_qml_module(qmlqtimeexample + OUTPUT_DIRECTORY TimeExample VERSION 1.0 URI "TimeExample" SOURCES timemodel.cpp timemodel.h - QML_FILES imports/TimeExample/Clock.qml + QML_FILES ${qml_files} + RESOURCES ${images} ) set_target_properties(qmlqtimeexample PROPERTIES WIN32_EXECUTABLE TRUE @@ -39,16 +51,6 @@ target_link_libraries(qmlqtimeexample PUBLIC Qt::Qml ) -qt6_add_resources(qmlqtimeexample example_images - PREFIX "/TimeExample" - BASE imports/TimeExample - FILES - imports/TimeExample/center.png - imports/TimeExample/clock.png - imports/TimeExample/hour.png - imports/TimeExample/minute.png -) - install(TARGETS qmlqtimeexample RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" diff --git a/examples/qml/referenceexamples/adding/CMakeLists.txt b/examples/qml/referenceexamples/adding/CMakeLists.txt index b90a7f6c36..b86d90a4c3 100644 --- a/examples/qml/referenceexamples/adding/CMakeLists.txt +++ b/examples/qml/referenceexamples/adding/CMakeLists.txt @@ -31,17 +31,11 @@ target_link_libraries(adding PUBLIC Qt::Qml ) - -# Resources: -set(adding_resource_files - "example.qml" -) - -qt6_add_resources(adding "adding" - PREFIX - "/" - FILES - ${adding_resource_files} +qt_add_qml_module(adding + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS adding @@ -49,10 +43,3 @@ install(TARGETS adding BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(adding PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(adding) diff --git a/examples/qml/referenceexamples/attached/CMakeLists.txt b/examples/qml/referenceexamples/attached/CMakeLists.txt index 684db88a95..4d49cc5663 100644 --- a/examples/qml/referenceexamples/attached/CMakeLists.txt +++ b/examples/qml/referenceexamples/attached/CMakeLists.txt @@ -34,17 +34,11 @@ target_link_libraries(attached PUBLIC Qt::Qml ) - -# Resources: -set(attached_resource_files - "example.qml" -) - -qt6_add_resources(attached "attached" - PREFIX - "/" - FILES - ${attached_resource_files} +qt_add_qml_module(attached + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS attached @@ -52,10 +46,3 @@ install(TARGETS attached BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(attached PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(attached) diff --git a/examples/qml/referenceexamples/binding/CMakeLists.txt b/examples/qml/referenceexamples/binding/CMakeLists.txt index fc733922bb..2a2d6575c0 100644 --- a/examples/qml/referenceexamples/binding/CMakeLists.txt +++ b/examples/qml/referenceexamples/binding/CMakeLists.txt @@ -35,17 +35,11 @@ target_link_libraries(binding PUBLIC Qt::Qml ) - -# Resources: -set(binding_resource_files - "example.qml" -) - -qt6_add_resources(binding "binding" - PREFIX - "/" - FILES - ${binding_resource_files} +qt_add_qml_module(binding + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS binding @@ -53,10 +47,3 @@ install(TARGETS binding BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(binding PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(binding) diff --git a/examples/qml/referenceexamples/coercion/CMakeLists.txt b/examples/qml/referenceexamples/coercion/CMakeLists.txt index cd93fa4883..b9613de116 100644 --- a/examples/qml/referenceexamples/coercion/CMakeLists.txt +++ b/examples/qml/referenceexamples/coercion/CMakeLists.txt @@ -32,17 +32,11 @@ target_link_libraries(coercion PUBLIC Qt::Qml ) - -# Resources: -set(coercion_resource_files - "example.qml" -) - -qt6_add_resources(coercion "coercion" - PREFIX - "/" - FILES - ${coercion_resource_files} +qt_add_qml_module(coercion + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS coercion @@ -50,10 +44,3 @@ install(TARGETS coercion BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(coercion PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(coercion) diff --git a/examples/qml/referenceexamples/default/CMakeLists.txt b/examples/qml/referenceexamples/default/CMakeLists.txt index 429fcb86ad..419b14d464 100644 --- a/examples/qml/referenceexamples/default/CMakeLists.txt +++ b/examples/qml/referenceexamples/default/CMakeLists.txt @@ -32,17 +32,11 @@ target_link_libraries(default PUBLIC Qt::Qml ) - -# Resources: -set(default_resource_files - "example.qml" -) - -qt6_add_resources(default "default" - PREFIX - "/" - FILES - ${default_resource_files} +qt_add_qml_module(default + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS default @@ -50,10 +44,3 @@ install(TARGETS default BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(default PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(default) diff --git a/examples/qml/referenceexamples/extended/CMakeLists.txt b/examples/qml/referenceexamples/extended/CMakeLists.txt index 87c750bea1..ea659e5f71 100644 --- a/examples/qml/referenceexamples/extended/CMakeLists.txt +++ b/examples/qml/referenceexamples/extended/CMakeLists.txt @@ -35,17 +35,11 @@ target_link_libraries(extended PUBLIC Qt::Widgets ) - -# Resources: -set(extended_resource_files - "example.qml" -) - -qt6_add_resources(extended "extended" - PREFIX - "/" - FILES - ${extended_resource_files} +qt_add_qml_module(extended + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS extended @@ -53,10 +47,3 @@ install(TARGETS extended BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(extended PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(extended) diff --git a/examples/qml/referenceexamples/grouped/CMakeLists.txt b/examples/qml/referenceexamples/grouped/CMakeLists.txt index c46d1beeb8..f7a31d9c1e 100644 --- a/examples/qml/referenceexamples/grouped/CMakeLists.txt +++ b/examples/qml/referenceexamples/grouped/CMakeLists.txt @@ -34,17 +34,11 @@ target_link_libraries(grouped PUBLIC Qt::Qml ) - -# Resources: -set(grouped_resource_files - "example.qml" -) - -qt6_add_resources(grouped "grouped" - PREFIX - "/" - FILES - ${grouped_resource_files} +qt_add_qml_module(grouped + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS grouped @@ -52,10 +46,3 @@ install(TARGETS grouped BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(grouped PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(grouped) diff --git a/examples/qml/referenceexamples/methods/CMakeLists.txt b/examples/qml/referenceexamples/methods/CMakeLists.txt index 0fc043fb8b..304aa3082a 100644 --- a/examples/qml/referenceexamples/methods/CMakeLists.txt +++ b/examples/qml/referenceexamples/methods/CMakeLists.txt @@ -32,17 +32,11 @@ target_link_libraries(methods PUBLIC Qt::Qml ) - -# Resources: -set(methods_resource_files - "example.qml" -) - -qt6_add_resources(methods "methods" - PREFIX - "/" - FILES - ${methods_resource_files} +qt_add_qml_module(methods + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS methods @@ -50,10 +44,3 @@ install(TARGETS methods BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(methods PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(methods) diff --git a/examples/qml/referenceexamples/properties/CMakeLists.txt b/examples/qml/referenceexamples/properties/CMakeLists.txt index 1f36559066..11f70f337f 100644 --- a/examples/qml/referenceexamples/properties/CMakeLists.txt +++ b/examples/qml/referenceexamples/properties/CMakeLists.txt @@ -32,17 +32,11 @@ target_link_libraries(properties PUBLIC Qt::Qml ) - -# Resources: -set(properties_resource_files - "example.qml" -) - -qt6_add_resources(properties "properties" - PREFIX - "/" - FILES - ${properties_resource_files} +qt_add_qml_module(properties + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS properties @@ -50,10 +44,3 @@ install(TARGETS properties BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(properties PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(properties) diff --git a/examples/qml/referenceexamples/signal/CMakeLists.txt b/examples/qml/referenceexamples/signal/CMakeLists.txt index 8e4cac00ce..23e494f7c9 100644 --- a/examples/qml/referenceexamples/signal/CMakeLists.txt +++ b/examples/qml/referenceexamples/signal/CMakeLists.txt @@ -34,17 +34,11 @@ target_link_libraries(signal PUBLIC Qt::Qml ) - -# Resources: -set(signal_resource_files - "example.qml" -) - -qt6_add_resources(signal "signal" - PREFIX - "/" - FILES - ${signal_resource_files} +qt_add_qml_module(signal + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS signal @@ -52,10 +46,3 @@ install(TARGETS signal BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(signal PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(signal) diff --git a/examples/qml/referenceexamples/valuesource/CMakeLists.txt b/examples/qml/referenceexamples/valuesource/CMakeLists.txt index f3653ac4e2..3e997bb8f8 100644 --- a/examples/qml/referenceexamples/valuesource/CMakeLists.txt +++ b/examples/qml/referenceexamples/valuesource/CMakeLists.txt @@ -35,17 +35,11 @@ target_link_libraries(valuesource PUBLIC Qt::Qml ) - -# Resources: -set(valuesource_resource_files - "example.qml" -) - -qt6_add_resources(valuesource "valuesource" - PREFIX - "/" - FILES - ${valuesource_resource_files} +qt_add_qml_module(valuesource + URI People + VERSION 1.0 + QML_FILES example.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS valuesource @@ -53,10 +47,3 @@ install(TARGETS valuesource BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(valuesource PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI People -) - -qt6_qml_type_registration(valuesource) diff --git a/examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt b/examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt deleted file mode 100644 index 8e41f3d77d..0000000000 --- a/examples/qml/tutorials/extending-qml/.prev_CMakeLists.txt +++ /dev/null @@ -1,8 +0,0 @@ -# Generated from extending-qml.pro. - -add_subdirectory(chapter1-basics) -add_subdirectory(chapter2-methods) -add_subdirectory(chapter3-bindings) -add_subdirectory(chapter4-customPropertyTypes) -add_subdirectory(chapter5-listproperties) -add_subdirectory(chapter6-plugins) diff --git a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt index 34e6c08fad..c04b465254 100644 --- a/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter1-basics/CMakeLists.txt @@ -35,17 +35,11 @@ target_link_libraries(chapter1-basics PUBLIC Qt::Quick ) - -# Resources: -set(chapter1-basics_resource_files - "app.qml" -) - -qt6_add_resources(chapter1-basics "chapter1-basics" - PREFIX - "/" - FILES - ${chapter1-basics_resource_files} +qt_add_qml_module(chapter1-basics + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter1-basics @@ -53,10 +47,3 @@ install(TARGETS chapter1-basics BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter1-basics PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter1-basics) diff --git a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt index 794c898741..993c235965 100644 --- a/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter2-methods/CMakeLists.txt @@ -35,17 +35,11 @@ target_link_libraries(chapter2-methods PUBLIC Qt::Quick ) - -# Resources: -set(chapter2-methods_resource_files - "app.qml" -) - -qt6_add_resources(chapter2-methods "chapter2-methods" - PREFIX - "/" - FILES - ${chapter2-methods_resource_files} +qt_add_qml_module(chapter2-methods + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter2-methods @@ -53,10 +47,3 @@ install(TARGETS chapter2-methods BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter2-methods PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter2-methods) diff --git a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt index d5d92ca13e..f600ae5389 100644 --- a/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter3-bindings/CMakeLists.txt @@ -35,17 +35,11 @@ target_link_libraries(chapter3-bindings PUBLIC Qt::Quick ) - -# Resources: -set(chapter3-bindings_resource_files - "app.qml" -) - -qt6_add_resources(chapter3-bindings "chapter3-bindings" - PREFIX - "/" - FILES - ${chapter3-bindings_resource_files} +qt_add_qml_module(chapter3-bindings + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter3-bindings @@ -53,10 +47,3 @@ install(TARGETS chapter3-bindings BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter3-bindings PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter3-bindings) diff --git a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt index 7011d39dfd..50e231bb7d 100644 --- a/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter4-customPropertyTypes/CMakeLists.txt @@ -36,17 +36,11 @@ target_link_libraries(chapter4-customPropertyTypes PUBLIC Qt::Quick ) - -# Resources: -set(chapter4-customPropertyTypes_resource_files - "app.qml" -) - -qt6_add_resources(chapter4-customPropertyTypes "chapter4-customPropertyTypes" - PREFIX - "/" - FILES - ${chapter4-customPropertyTypes_resource_files} +qt_add_qml_module(chapter4-customPropertyTypes + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter4-customPropertyTypes @@ -54,10 +48,3 @@ install(TARGETS chapter4-customPropertyTypes BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter4-customPropertyTypes PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter4-customPropertyTypes) diff --git a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt index 4fa74097e7..1891bc34d5 100644 --- a/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter5-listproperties/CMakeLists.txt @@ -36,17 +36,11 @@ target_link_libraries(chapter5-listproperties PUBLIC Qt::Quick ) - -# Resources: -set(chapter5-listproperties_resource_files - "app.qml" -) - -qt6_add_resources(chapter5-listproperties "chapter5-listproperties" - PREFIX - "/" - FILES - ${chapter5-listproperties_resource_files} +qt_add_qml_module(chapter5-listproperties + URI Charts + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter5-listproperties @@ -54,10 +48,3 @@ install(TARGETS chapter5-listproperties BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) - -set_target_properties(chapter5-listproperties PROPERTIES - QT_QML_MODULE_VERSION 1.0 - QT_QML_MODULE_URI Charts -) - -qt6_qml_type_registration(chapter5-listproperties) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt deleted file mode 100644 index 0d68df497a..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/.prev_CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -# Generated from chapter6-plugins.pro. - -cmake_minimum_required(VERSION 3.14) -project(chapter6-plugins LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins") - -find_package(Qt6 COMPONENTS Qml) -find_package(Qt6 COMPONENTS Quick) - -qt_add_executable(chapter6-plugins - main.cpp -) -set_target_properties(chapter6-plugins PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(chapter6-plugins PUBLIC - Qt::Qml - Qt::Quick -) - - -# Resources: -set(app_resource_files - "app.qml" -) - -qt6_add_resources(chapter6-plugins "app" - PREFIX - "/" - FILES - ${app_resource_files} -) - -install(TARGETS chapter6-plugins - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) -add_subdirectory(import) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt index a85121d2f1..cf3d218c57 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/CMakeLists.txt @@ -14,7 +14,6 @@ if(NOT DEFINED INSTALL_EXAMPLESDIR) endif() set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins") -set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) find_package(Qt6 COMPONENTS Qml) find_package(Qt6 COMPONENTS Quick) @@ -31,17 +30,11 @@ target_link_libraries(chapter6-plugins PUBLIC Qt::Quick ) - -# Resources: -set(app_resource_files - "app.qml" -) - -qt6_add_resources(chapter6-plugins "app" - PREFIX - "/" - FILES - ${app_resource_files} +qt_add_qml_module(chapter6-plugins + URI ChartsApp + VERSION 1.0 + QML_FILES app.qml + NO_RESOURCE_TARGET_PATH ) install(TARGETS chapter6-plugins @@ -50,4 +43,4 @@ install(TARGETS chapter6-plugins LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" ) -add_subdirectory(import) +add_subdirectory(Charts) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt new file mode 100644 index 0000000000..15f6dcc2c2 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/CMakeLists.txt @@ -0,0 +1,48 @@ +# Generated from import.pro. + +cmake_minimum_required(VERSION 3.16) +project(chartsplugin LANGUAGES CXX) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) + +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTORCC ON) +set(CMAKE_AUTOUIC ON) + +if(NOT DEFINED INSTALL_EXAMPLESDIR) + set(INSTALL_EXAMPLESDIR "examples") +endif() + +set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins/Charts") + +find_package(Qt6 COMPONENTS Core) +find_package(Qt6 COMPONENTS Gui) +find_package(Qt6 COMPONENTS Qml) +find_package(Qt6 COMPONENTS Quick) + +qt6_add_qml_module(chartsplugin + VERSION 1.0 + URI "Charts" + PLUGIN_TARGET chartsplugin +) + +target_sources(chartsplugin PRIVATE + piechart.cpp piechart.h + pieslice.cpp pieslice.h +) +set_target_properties(chartsplugin PROPERTIES + WIN32_EXECUTABLE TRUE + MACOSX_BUNDLE TRUE +) +target_link_libraries(chartsplugin PUBLIC + Qt::Core + Qt::Gui + Qt::Qml + Qt::Quick +) + +install(TARGETS chartsplugin + RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" + BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" + LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" +) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/Charts.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/Charts.pro new file mode 100644 index 0000000000..054ed06606 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/Charts.pro @@ -0,0 +1,32 @@ +TEMPLATE = lib +CONFIG += plugin qmltypes +QT += qml quick + +QML_IMPORT_NAME = Charts +QML_IMPORT_MAJOR_VERSION = 1 + +DESTDIR = ../$$QML_IMPORT_NAME +TARGET = $$qtLibraryTarget(chartsplugin) + +HEADERS += piechart.h \ + pieslice.h \ + chartsplugin.h + +SOURCES += piechart.cpp \ + pieslice.cpp + +DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/$$QML_IMPORT_NAME + +target.path=$$DESTPATH +qmldir.files=$$PWD/qmldir +qmldir.path=$$DESTPATH +INSTALLS += target qmldir + +CONFIG += install_ok # Do not cargo-cult this! + +OTHER_FILES += qmldir + +# Copy the qmldir file to the same folder as the plugin binary +cpqmldir.files = qmldir +cpqmldir.path = $$DESTDIR +COPIES += cpqmldir diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/chartsplugin.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/chartsplugin.h new file mode 100644 index 0000000000..780bb3a8f3 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/chartsplugin.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef CHARTSPLUGIN_H +#define CHARTSPLUGIN_H + +//![0] +#include + +class ChartsPlugin : public QQmlEngineExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) +}; +//![0] + +#endif + diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.cpp new file mode 100644 index 0000000000..536c0e16ae --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "piechart.h" +#include "pieslice.h" + +PieChart::PieChart(QQuickItem *parent) + : QQuickItem(parent) +{ +} + +QString PieChart::name() const +{ + return m_name; +} + +void PieChart::setName(const QString &name) +{ + m_name = name; +} + +QQmlListProperty PieChart::slices() +{ + return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, + nullptr, nullptr, nullptr, nullptr); +} + +void PieChart::append_slice(QQmlListProperty *list, PieSlice *slice) +{ + PieChart *chart = qobject_cast(list->object); + if (chart) { + slice->setParentItem(chart); + chart->m_slices.append(slice); + } +} diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h new file mode 100644 index 0000000000..fbded1e3a2 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/piechart.h @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIECHART_H +#define PIECHART_H + +#include + +class PieSlice; + +class PieChart : public QQuickItem +{ + Q_OBJECT + Q_PROPERTY(QQmlListProperty slices READ slices) + Q_PROPERTY(QString name READ name WRITE setName) + QML_ELEMENT + +public: + PieChart(QQuickItem *parent = nullptr); + + QString name() const; + void setName(const QString &name); + + QQmlListProperty slices(); + +private: + static void append_slice(QQmlListProperty *list, PieSlice *slice); + + QString m_name; + QList m_slices; +}; + +#endif + diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.cpp new file mode 100644 index 0000000000..1d30036929 --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "pieslice.h" + +#include + +PieSlice::PieSlice(QQuickItem *parent) + : QQuickPaintedItem(parent) +{ +} + +QColor PieSlice::color() const +{ + return m_color; +} + +void PieSlice::setColor(const QColor &color) +{ + m_color = color; +} + +int PieSlice::fromAngle() const +{ + return m_fromAngle; +} + +void PieSlice::setFromAngle(int angle) +{ + m_fromAngle = angle; +} + +int PieSlice::angleSpan() const +{ + return m_angleSpan; +} + +void PieSlice::setAngleSpan(int angle) +{ + m_angleSpan = angle; +} + +void PieSlice::paint(QPainter *painter) +{ + QPen pen(m_color, 2); + painter->setPen(pen); + painter->setRenderHints(QPainter::Antialiasing, true); + painter->drawPie(boundingRect().adjusted(1, 1, -1, -1), m_fromAngle * 16, m_angleSpan * 16); +} + diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h new file mode 100644 index 0000000000..86602afe8f --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/pieslice.h @@ -0,0 +1,85 @@ +/**************************************************************************** +** +** Copyright (C) 2017 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef PIESLICE_H +#define PIESLICE_H + +#include +#include + +class PieSlice : public QQuickPaintedItem +{ + Q_OBJECT + Q_PROPERTY(QColor color READ color WRITE setColor) + Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) + Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) + QML_ELEMENT + +public: + PieSlice(QQuickItem *parent = nullptr); + + QColor color() const; + void setColor(const QColor &color); + + int fromAngle() const; + void setFromAngle(int angle); + + int angleSpan() const; + void setAngleSpan(int span); + + void paint(QPainter *painter) override; + +private: + QColor m_color; + int m_fromAngle; + int m_angleSpan; +}; + +#endif + diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir new file mode 100644 index 0000000000..d9e8471b3c --- /dev/null +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/Charts/qmldir @@ -0,0 +1,2 @@ +module Charts +plugin chartsplugin diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro index f858c80876..2d78235454 100644 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro +++ b/examples/qml/tutorials/extending-qml/chapter6-plugins/chapter6-plugins.pro @@ -1,5 +1,5 @@ TEMPLATE = subdirs CONFIG += ordered SUBDIRS = \ - import \ + Charts \ app.pro diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt deleted file mode 100644 index 15f6dcc2c2..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/CMakeLists.txt +++ /dev/null @@ -1,48 +0,0 @@ -# Generated from import.pro. - -cmake_minimum_required(VERSION 3.16) -project(chartsplugin LANGUAGES CXX) - -set(CMAKE_INCLUDE_CURRENT_DIR ON) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_AUTORCC ON) -set(CMAKE_AUTOUIC ON) - -if(NOT DEFINED INSTALL_EXAMPLESDIR) - set(INSTALL_EXAMPLESDIR "examples") -endif() - -set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/qml/tutorials/extending-qml/chapter6-plugins/Charts") - -find_package(Qt6 COMPONENTS Core) -find_package(Qt6 COMPONENTS Gui) -find_package(Qt6 COMPONENTS Qml) -find_package(Qt6 COMPONENTS Quick) - -qt6_add_qml_module(chartsplugin - VERSION 1.0 - URI "Charts" - PLUGIN_TARGET chartsplugin -) - -target_sources(chartsplugin PRIVATE - piechart.cpp piechart.h - pieslice.cpp pieslice.h -) -set_target_properties(chartsplugin PROPERTIES - WIN32_EXECUTABLE TRUE - MACOSX_BUNDLE TRUE -) -target_link_libraries(chartsplugin PUBLIC - Qt::Core - Qt::Gui - Qt::Qml - Qt::Quick -) - -install(TARGETS chartsplugin - RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}" - BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}" - LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}" -) diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h deleted file mode 100644 index 780bb3a8f3..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/chartsplugin.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef CHARTSPLUGIN_H -#define CHARTSPLUGIN_H - -//![0] -#include - -class ChartsPlugin : public QQmlEngineExtensionPlugin -{ - Q_OBJECT - Q_PLUGIN_METADATA(IID QQmlEngineExtensionInterface_iid) -}; -//![0] - -#endif - diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro deleted file mode 100644 index c37cd1fdee..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/import.pro +++ /dev/null @@ -1,36 +0,0 @@ -TEMPLATE = lib -CONFIG += plugin qmltypes -QT += qml quick - -QML_IMPORT_NAME = Charts -QML_IMPORT_MAJOR_VERSION = 1 - -DESTDIR = ../$$QML_IMPORT_NAME -TARGET = $$qtLibraryTarget(chartsplugin) - -HEADERS += piechart.h \ - pieslice.h \ - chartsplugin.h - -SOURCES += piechart.cpp \ - pieslice.cpp - -DESTPATH=$$[QT_INSTALL_EXAMPLES]/qml/tutorials/extending-qml/chapter6-plugins/$$QML_IMPORT_NAME - -copy_qmltypes.files = $$OUT_PWD/plugins.qmltypes -copy_qmltypes.path = $$DESTDIR -COPIES += copy_qmltypes - -target.path=$$DESTPATH -qmldir.files=$$PWD/qmldir -qmldir.path=$$DESTPATH -INSTALLS += target qmldir - -CONFIG += install_ok # Do not cargo-cult this! - -OTHER_FILES += qmldir - -# Copy the qmldir file to the same folder as the plugin binary -cpqmldir.files = qmldir -cpqmldir.path = $$DESTDIR -COPIES += cpqmldir diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp deleted file mode 100644 index 536c0e16ae..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.cpp +++ /dev/null @@ -1,81 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "piechart.h" -#include "pieslice.h" - -PieChart::PieChart(QQuickItem *parent) - : QQuickItem(parent) -{ -} - -QString PieChart::name() const -{ - return m_name; -} - -void PieChart::setName(const QString &name) -{ - m_name = name; -} - -QQmlListProperty PieChart::slices() -{ - return QQmlListProperty(this, nullptr, &PieChart::append_slice, nullptr, - nullptr, nullptr, nullptr, nullptr); -} - -void PieChart::append_slice(QQmlListProperty *list, PieSlice *slice) -{ - PieChart *chart = qobject_cast(list->object); - if (chart) { - slice->setParentItem(chart); - chart->m_slices.append(slice); - } -} diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h deleted file mode 100644 index fbded1e3a2..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/piechart.h +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef PIECHART_H -#define PIECHART_H - -#include - -class PieSlice; - -class PieChart : public QQuickItem -{ - Q_OBJECT - Q_PROPERTY(QQmlListProperty slices READ slices) - Q_PROPERTY(QString name READ name WRITE setName) - QML_ELEMENT - -public: - PieChart(QQuickItem *parent = nullptr); - - QString name() const; - void setName(const QString &name); - - QQmlListProperty slices(); - -private: - static void append_slice(QQmlListProperty *list, PieSlice *slice); - - QString m_name; - QList m_slices; -}; - -#endif - diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.cpp b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.cpp deleted file mode 100644 index 1d30036929..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include "pieslice.h" - -#include - -PieSlice::PieSlice(QQuickItem *parent) - : QQuickPaintedItem(parent) -{ -} - -QColor PieSlice::color() const -{ - return m_color; -} - -void PieSlice::setColor(const QColor &color) -{ - m_color = color; -} - -int PieSlice::fromAngle() const -{ - return m_fromAngle; -} - -void PieSlice::setFromAngle(int angle) -{ - m_fromAngle = angle; -} - -int PieSlice::angleSpan() const -{ - return m_angleSpan; -} - -void PieSlice::setAngleSpan(int angle) -{ - m_angleSpan = angle; -} - -void PieSlice::paint(QPainter *painter) -{ - QPen pen(m_color, 2); - painter->setPen(pen); - painter->setRenderHints(QPainter::Antialiasing, true); - painter->drawPie(boundingRect().adjusted(1, 1, -1, -1), m_fromAngle * 16, m_angleSpan * 16); -} - diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h deleted file mode 100644 index 86602afe8f..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/pieslice.h +++ /dev/null @@ -1,85 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the documentation of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:BSD$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** BSD License Usage -** Alternatively, you may use this file under the terms of the BSD license -** as follows: -** -** "Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are -** met: -** * Redistributions of source code must retain the above copyright -** notice, this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright -** notice, this list of conditions and the following disclaimer in -** the documentation and/or other materials provided with the -** distribution. -** * Neither the name of The Qt Company Ltd nor the names of its -** contributors may be used to endorse or promote products derived -** from this software without specific prior written permission. -** -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#ifndef PIESLICE_H -#define PIESLICE_H - -#include -#include - -class PieSlice : public QQuickPaintedItem -{ - Q_OBJECT - Q_PROPERTY(QColor color READ color WRITE setColor) - Q_PROPERTY(int fromAngle READ fromAngle WRITE setFromAngle) - Q_PROPERTY(int angleSpan READ angleSpan WRITE setAngleSpan) - QML_ELEMENT - -public: - PieSlice(QQuickItem *parent = nullptr); - - QColor color() const; - void setColor(const QColor &color); - - int fromAngle() const; - void setFromAngle(int angle); - - int angleSpan() const; - void setAngleSpan(int span); - - void paint(QPainter *painter) override; - -private: - QColor m_color; - int m_fromAngle; - int m_angleSpan; -}; - -#endif - diff --git a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/qmldir b/examples/qml/tutorials/extending-qml/chapter6-plugins/import/qmldir deleted file mode 100644 index d9e8471b3c..0000000000 --- a/examples/qml/tutorials/extending-qml/chapter6-plugins/import/qmldir +++ /dev/null @@ -1,2 +0,0 @@ -module Charts -plugin chartsplugin diff --git a/examples/qml/xmlhttprequest/CMakeLists.txt b/examples/qml/xmlhttprequest/CMakeLists.txt index 8dc77d613c..71a33e7264 100644 --- a/examples/qml/xmlhttprequest/CMakeLists.txt +++ b/examples/qml/xmlhttprequest/CMakeLists.txt @@ -34,22 +34,21 @@ target_link_libraries(xmlhttprequest PUBLIC Qt::Quick ) - -# Resources: -set(xmlhttprequest_resource_files - "Get.qml" - "GetForm.ui.qml" - "data.xml" - "methods.js" - "xmlhttprequest.qml" +set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/qml) +qt_add_qml_module(xmlhttprequest + URI xmlhttprequest + VERSION 1.0 + QML_FILES + Get.qml + GetForm.ui.qml + methods.js + xmlhttprequest.qml + RESOURCES + data.xml + RESOURCE_PREFIX /qml ) -qt6_add_resources(xmlhttprequest "xmlhttprequest" - PREFIX - "/qml/xmlhttprequest" - FILES - ${xmlhttprequest_resource_files} -) +# These files live outside of the QML module, so add them separately set(quick_shared_resource_files "../../quick/shared/Button.qml" "../../quick/shared/CheckBox.qml" -- cgit v1.2.3