aboutsummaryrefslogtreecommitdiffstats
path: root/examples/quick
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-08-31 14:59:05 +0200
committerUlf Hermann <ulf.hermann@qt.io>2021-09-07 11:28:07 +0200
commit6a7952022737a6680569f2d6be4efa43825135f5 (patch)
treed108097448e040a4a613e2781056935c6b363ba4 /examples/quick
parenta835cb475bfb1f062454dc235eb75413e38000eb (diff)
Clean up the painteditem example
The way it was before it was unusable. Move the files that belong to the TextBalloon module into their own directory, and add a wrapper application that loads textballoons.qml with the right parameters to actually find the TextBalloon module. Make sure that the qmldir file is copied to the output directory. Change-Id: Ie7407a425a0a95a46de6486f9a28fd1aee07de9f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 79cae5f6522bc259caa27b98031bfe84ef936744)
Diffstat (limited to 'examples/quick')
-rw-r--r--examples/quick/customitems/painteditem/CMakeLists.txt53
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/CMakeLists.txt27
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/plugin.h (renamed from examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h)2
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/qmldir (renamed from examples/quick/customitems/painteditem/TextBalloonPlugin/qmldir)1
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/textballoon.cpp (renamed from examples/quick/customitems/painteditem/textballoon.cpp)0
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/textballoon.h (renamed from examples/quick/customitems/painteditem/textballoon.h)4
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/textballoon.pro28
-rw-r--r--examples/quick/customitems/painteditem/TextBalloon/textballoon.qrc5
-rw-r--r--examples/quick/customitems/painteditem/doc/src/textballoons.qdoc22
-rw-r--r--examples/quick/customitems/painteditem/main.cpp51
-rw-r--r--examples/quick/customitems/painteditem/painteditem.pro31
-rw-r--r--examples/quick/customitems/painteditem/painteditem.qrc1
-rw-r--r--examples/quick/customitems/painteditem/textballoons.qml2
-rw-r--r--examples/quick/customitems/painteditem/textballoonuser.pro10
14 files changed, 152 insertions, 85 deletions
diff --git a/examples/quick/customitems/painteditem/CMakeLists.txt b/examples/quick/customitems/painteditem/CMakeLists.txt
index 9094dfe695..63becfa53d 100644
--- a/examples/quick/customitems/painteditem/CMakeLists.txt
+++ b/examples/quick/customitems/painteditem/CMakeLists.txt
@@ -1,62 +1,37 @@
-# Generated from painteditem.pro.
-
cmake_minimum_required(VERSION 3.16)
-project(qmltextballoonplugin LANGUAGES CXX)
+project(painteditem 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}/quick/customitems/painteditem/TextBalloonPlugin")
-set(QT_QML_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/quick/customitems/painteditem)
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/customitems/painteditem")
+
+find_package(Qt6 COMPONENTS Core Gui Quick Qml)
-find_package(Qt6 COMPONENTS Core)
-find_package(Qt6 COMPONENTS Gui)
-find_package(Qt6 COMPONENTS Qml)
-find_package(Qt6 COMPONENTS Quick)
+add_subdirectory(TextBalloon)
-qt6_add_qml_module(qmltextballoonplugin
+qt_add_executable(painteditemexample WIN32 MACOSX_BUNDLE main.cpp)
+
+qt_add_qml_module(painteditemexample
+ URI painteditem
VERSION 1.0
- URI "TextBalloonPlugin"
- PLUGIN_TARGET qmltextballoonplugin
- QML_FILES textballoons.qml
- RESOURCE_PREFIX "/painteditem"
+ QML_FILES
+ "textballoons.qml"
)
-target_sources(qmltextballoonplugin PRIVATE
- textballoon.cpp textballoon.h
-)
-set_target_properties(qmltextballoonplugin PROPERTIES
- WIN32_EXECUTABLE TRUE
- MACOSX_BUNDLE TRUE
-)
-target_link_libraries(qmltextballoonplugin PUBLIC
+target_link_libraries(painteditemexample PRIVATE
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
+ qmltextballoon
)
-
-# Resources:
-set(painteditem_resource_files
- "textballoon.h"
-)
-
-qt6_add_resources(qmltextballoonplugin "painteditem"
- PREFIX
- "/painteditem"
- FILES
- ${painteditem_resource_files}
-)
-
-install(TARGETS qmltextballoonplugin
+install(TARGETS painteditemexample
RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
diff --git a/examples/quick/customitems/painteditem/TextBalloon/CMakeLists.txt b/examples/quick/customitems/painteditem/TextBalloon/CMakeLists.txt
new file mode 100644
index 0000000000..d651c7de8b
--- /dev/null
+++ b/examples/quick/customitems/painteditem/TextBalloon/CMakeLists.txt
@@ -0,0 +1,27 @@
+set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/quick/customitems/painteditem/TextBalloon")
+
+qt_add_library(qmltextballoon)
+qt_add_qml_module(qmltextballoon
+ VERSION 1.0
+ URI "TextBalloon"
+ PLUGIN_TARGET qmltextballoon
+ SOURCES
+ textballoon.cpp textballoon.h
+)
+
+target_link_libraries(qmltextballoon PUBLIC
+ Qt::Core
+ Qt::Gui
+ Qt::Qml
+ Qt::Quick
+)
+
+install(TARGETS qmltextballoon
+ RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
+ BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
+ LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
+
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qmldir
+ DESTINATION "${INSTALL_EXAMPLEDIR}"
+)
diff --git a/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h b/examples/quick/customitems/painteditem/TextBalloon/plugin.h
index 4abf2cf3dc..6fabbe0b37 100644
--- a/examples/quick/customitems/painteditem/TextBalloonPlugin/plugin.h
+++ b/examples/quick/customitems/painteditem/TextBalloon/plugin.h
@@ -50,7 +50,7 @@
#include <QQmlEngineExtensionPlugin>
-#include "../textballoon.h"
+#include "textballoon.h"
class TextBalloonPlugin : public QQmlEngineExtensionPlugin
{
diff --git a/examples/quick/customitems/painteditem/TextBalloonPlugin/qmldir b/examples/quick/customitems/painteditem/TextBalloon/qmldir
index e8a08ae9d3..3b72e9a44d 100644
--- a/examples/quick/customitems/painteditem/TextBalloonPlugin/qmldir
+++ b/examples/quick/customitems/painteditem/TextBalloon/qmldir
@@ -1 +1,2 @@
+module TextBalloon
plugin qmltextballoonplugin
diff --git a/examples/quick/customitems/painteditem/textballoon.cpp b/examples/quick/customitems/painteditem/TextBalloon/textballoon.cpp
index d3d4246eb2..d3d4246eb2 100644
--- a/examples/quick/customitems/painteditem/textballoon.cpp
+++ b/examples/quick/customitems/painteditem/TextBalloon/textballoon.cpp
diff --git a/examples/quick/customitems/painteditem/textballoon.h b/examples/quick/customitems/painteditem/TextBalloon/textballoon.h
index 129b0f7ee1..520def639e 100644
--- a/examples/quick/customitems/painteditem/textballoon.h
+++ b/examples/quick/customitems/painteditem/TextBalloon/textballoon.h
@@ -61,8 +61,8 @@ class TextBalloon : public QQuickPaintedItem
QML_ELEMENT
public:
- TextBalloon(QQuickItem *parent = 0);
- void paint(QPainter *painter);
+ TextBalloon(QQuickItem *parent = nullptr);
+ void paint(QPainter *painter) override;
bool isRightAligned() const;
void setRightAligned(bool rightAligned);
diff --git a/examples/quick/customitems/painteditem/TextBalloon/textballoon.pro b/examples/quick/customitems/painteditem/TextBalloon/textballoon.pro
new file mode 100644
index 0000000000..7f7662b451
--- /dev/null
+++ b/examples/quick/customitems/painteditem/TextBalloon/textballoon.pro
@@ -0,0 +1,28 @@
+TEMPLATE = lib
+CONFIG += plugin qmltypes
+QT += qml quick
+
+QML_IMPORT_NAME = TextBalloon
+QML_IMPORT_MAJOR_VERSION = 1
+
+TARGET = qmltextballoonplugin
+
+HEADERS += \
+ plugin.h \
+ textballoon.h
+
+SOURCES += textballoon.cpp
+
+RESOURCES += textballoon.qrc
+
+qmldir_output.files = qmldir
+qmldir_output.path = $$OUT_PWD
+COPIES += qmldir_output
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
+qmldir_install.files = qmldir
+qmldir_install.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
+
+INSTALLS += qmldir_install target
+
+CONFIG += install_ok # Do not cargo-cult this!
diff --git a/examples/quick/customitems/painteditem/TextBalloon/textballoon.qrc b/examples/quick/customitems/painteditem/TextBalloon/textballoon.qrc
new file mode 100644
index 0000000000..42c42bd0a6
--- /dev/null
+++ b/examples/quick/customitems/painteditem/TextBalloon/textballoon.qrc
@@ -0,0 +1,5 @@
+<RCC>
+ <qresource prefix="/TextBalloon">
+ <file>qmldir</file>
+ </qresource>
+</RCC>
diff --git a/examples/quick/customitems/painteditem/doc/src/textballoons.qdoc b/examples/quick/customitems/painteditem/doc/src/textballoons.qdoc
index 4541ba0bd9..57ffd0f6b1 100644
--- a/examples/quick/customitems/painteditem/doc/src/textballoons.qdoc
+++ b/examples/quick/customitems/painteditem/doc/src/textballoons.qdoc
@@ -38,16 +38,14 @@
The QQuickPaintedItem class is a class derived from QQuickItem for implementing
custom QML Scene Graph items using the QPainter interfaces.
- The example consists of an item class, a plugin class and a QML file
- to use this plugin. The \c TextBalloon class represents the individual
- text balloons extending QQuickPaintedItem, the \c TextBalloonPlugin class
- represents the skeleton code for a \l {Qt Quick} plugin and the
- \c textballoons.qml file is used to load the plugin and display the text
- balloons.
+ The example consists of an item class and a QML file to use the item. The
+ \c TextBalloon class represents the individual text balloons extending
+ QQuickPaintedItem and the \c textballoons.qml file is used to load the module
+ containing the TextBalloon QML type and display the text balloons.
We will focus on the \c TextBalloon class first and continue with the
- \c textballoons.qml file. For an example on how to implement a \l {Qt Quick}
- plugin please look at \l{Chapter 6: Writing an Extension Plugin}
+ \c textballoons.qml file. For an example on how to implement a plugin for a
+ QML module please look at \l{Chapter 6: Writing an Extension Plugin}
{Writing an Extension Plugin}
\section1 TextBalloon Class Declaration
@@ -56,7 +54,7 @@
is the base class for all QPainter based items in the QML Scene Graph
framework.
- \snippet customitems/painteditem/textballoon.h 0
+ \snippet customitems/painteditem/TextBalloon/textballoon.h 0
To implement a QQuickPaintedItem you must implement QQuickPaintedIem's pure
virtual function \l {QQuickPaintedItem::}{paint()} which implements the
@@ -67,13 +65,13 @@
We have to be sure to initialize the rightAligned property for a
TextBalloon item.
- \snippet customitems/painteditem/textballoon.cpp 0
+ \snippet customitems/painteditem/TextBalloon/textballoon.cpp 0
Then we implement the \c paint() function which is automatically called by
the Scene Graph framework to paint the contents of the item. The function
paints the item in local coordinates.
- \snippet customitems/painteditem/textballoon.cpp 1
+ \snippet customitems/painteditem/TextBalloon/textballoon.cpp 1
We start with setting the pen and brush on the item to define the look of
the item. After that we start drawing. Note that the \l {QQuickPaintedItem::}{contentsBoundingRect()}
@@ -81,7 +79,7 @@
returned by the \l {QQuickPaintedItem::}{contentsBoundingRect()} function is the size
of the item as defined in the QML file.
- \section1 Textballoons.qml File
+ \section1 textballoons.qml File
The Interface consists of two main parts. The scrollable area with the
textballoons and the controls button to add new balloons.
diff --git a/examples/quick/customitems/painteditem/main.cpp b/examples/quick/customitems/painteditem/main.cpp
new file mode 100644
index 0000000000..7f01df3395
--- /dev/null
+++ b/examples/quick/customitems/painteditem/main.cpp
@@ -0,0 +1,51 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the examples 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 "../../shared/shared.h"
+DECLARATIVE_EXAMPLE_MAIN(painteditem/textballoons)
diff --git a/examples/quick/customitems/painteditem/painteditem.pro b/examples/quick/customitems/painteditem/painteditem.pro
index 641833f3aa..7c26304b26 100644
--- a/examples/quick/customitems/painteditem/painteditem.pro
+++ b/examples/quick/customitems/painteditem/painteditem.pro
@@ -1,29 +1,2 @@
-TEMPLATE = lib
-CONFIG += plugin qmltypes
-QT += qml quick
-
-QML_IMPORT_NAME = TextBalloonPlugin
-QML_IMPORT_MAJOR_VERSION = 1
-
-TARGET = qmltextballoonplugin
-
-HEADERS += \
- TextBalloonPlugin/plugin.h \
- textballoon.h
-
-SOURCES += textballoon.cpp
-
-RESOURCES += painteditem.qrc
-
-DESTDIR = $$QML_IMPORT_NAME
-
-target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
-qmldir.files = $$QML_IMPORT_NAME/qmldir
-qmldir.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem/$$QML_IMPORT_NAME
-
-INSTALLS += qmldir target
-
-CONFIG += install_ok # Do not cargo-cult this!
-
-OTHER_FILES += \
- textballoons.qml
+TEMPLATE = subdirs
+SUBDIRS = TextBalloon/textballoon.pro textballoonuser.pro
diff --git a/examples/quick/customitems/painteditem/painteditem.qrc b/examples/quick/customitems/painteditem/painteditem.qrc
index c240be02a1..d436ab32e2 100644
--- a/examples/quick/customitems/painteditem/painteditem.qrc
+++ b/examples/quick/customitems/painteditem/painteditem.qrc
@@ -1,6 +1,5 @@
<RCC>
<qresource prefix="/painteditem">
- <file>textballoon.h</file>
<file>textballoons.qml</file>
</qresource>
</RCC>
diff --git a/examples/quick/customitems/painteditem/textballoons.qml b/examples/quick/customitems/painteditem/textballoons.qml
index 2c749bb440..c520dda271 100644
--- a/examples/quick/customitems/painteditem/textballoons.qml
+++ b/examples/quick/customitems/painteditem/textballoons.qml
@@ -49,7 +49,7 @@
****************************************************************************/
import QtQuick 2.0
-import "TextBalloonPlugin" 1.0
+import TextBalloon 1.0
Item {
height: 480
diff --git a/examples/quick/customitems/painteditem/textballoonuser.pro b/examples/quick/customitems/painteditem/textballoonuser.pro
new file mode 100644
index 0000000000..7504542f4c
--- /dev/null
+++ b/examples/quick/customitems/painteditem/textballoonuser.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+
+QT += qml quick
+
+TARGET = painteditem
+SOURCES += main.cpp
+RESOURCES += painteditem.qrc
+
+target.path = $$[QT_INSTALL_EXAMPLES]/quick/customitems/painteditem
+INSTALLS += target