summaryrefslogtreecommitdiffstats
path: root/examples/demos/photoviewer
diff options
context:
space:
mode:
authorDoris Verria <doris.verria@qt.io>2020-11-01 22:43:55 +0100
committerDoris Verria <doris.verria@qt.io>2020-11-05 12:20:36 +0100
commitaf4d9a658e2bc337856f71a2c9729204daa611a4 (patch)
treedfd359e2a09483ac15cfc58934cf1820c27f1b7b /examples/demos/photoviewer
parent2216c740976ea7a552229f0d001f81fc73e59167 (diff)
Port photoviewer's XmlListModel away from QtXmlPatterns
Remove the qtxmlpatterns dependendency of photoviewer demo and reimplement XmlListModel class to use QXmlStreamReader instead of XPath/XQuery to query Xml. Fixes: QTBUG-88058 Change-Id: If21f3f361c8154bc56d94f37263801b33af8906f Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'examples/demos/photoviewer')
-rw-r--r--examples/demos/photoviewer/CMakeLists.txt16
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/AlbumDelegate.qml6
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/BusyIndicator.qml2
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/Button.qml2
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/EditableButton.qml2
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/PhotoDelegate.qml10
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/ProgressBar.qml2
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/RssModel.qml13
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/Tag.qml2
-rw-r--r--examples/demos/photoviewer/PhotoViewerCore/script/script.mjs14
-rw-r--r--examples/demos/photoviewer/doc/src/photoviewer.qdoc69
-rw-r--r--examples/demos/photoviewer/main.qml5
-rw-r--r--examples/demos/photoviewer/photoviewer.pro13
13 files changed, 101 insertions, 55 deletions
diff --git a/examples/demos/photoviewer/CMakeLists.txt b/examples/demos/photoviewer/CMakeLists.txt
index 993cb2cdc..15cdb5d0d 100644
--- a/examples/demos/photoviewer/CMakeLists.txt
+++ b/examples/demos/photoviewer/CMakeLists.txt
@@ -19,23 +19,35 @@ find_package(Qt6 COMPONENTS Core)
find_package(Qt6 COMPONENTS Gui)
find_package(Qt6 COMPONENTS Qml)
find_package(Qt6 COMPONENTS Quick)
-find_package(Qt6 COMPONENTS XmlPatterns)
+find_package(Qt6 COMPONENTS QuickControls2 REQUIRED)
+find_package(Qt6 COMPONENTS Network)
qt_add_executable(photoviewer
main.cpp
+ ../shared/xmllistmodel.cpp
+ ../shared/xmllistmodel.h
)
+
set_target_properties(photoviewer PROPERTIES
WIN32_EXECUTABLE TRUE
MACOSX_BUNDLE TRUE
+ QT_QML_MODULE_VERSION 1.0
+ QT_QML_MODULE_URI XmlListModel
)
+qt6_qml_type_registration(photoviewer)
+
target_link_libraries(photoviewer PUBLIC
Qt::Core
Qt::Gui
Qt::Qml
Qt::Quick
- Qt::XmlPatterns
+ Qt::Network
+ Qt::QuickControls2
)
+target_include_directories(photoviewer PUBLIC
+ ../shared
+)
# Resources:
set(qmake_immediate_resource_files
diff --git a/examples/demos/photoviewer/PhotoViewerCore/AlbumDelegate.qml b/examples/demos/photoviewer/PhotoViewerCore/AlbumDelegate.qml
index 6b654377a..0d9d52828 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/AlbumDelegate.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/AlbumDelegate.qml
@@ -48,9 +48,9 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtQuick.XmlListModel 2.0
-import QtQml.Models 2.1
+import QtQuick
+import XmlListModel
+import QtQml.Models
Component {
id: albumDelegate
diff --git a/examples/demos/photoviewer/PhotoViewerCore/BusyIndicator.qml b/examples/demos/photoviewer/PhotoViewerCore/BusyIndicator.qml
index 17a7b0d8d..f60cca8c8 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/BusyIndicator.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/BusyIndicator.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
Image {
id: container
diff --git a/examples/demos/photoviewer/PhotoViewerCore/Button.qml b/examples/demos/photoviewer/PhotoViewerCore/Button.qml
index 8744dc2e7..401c35c7d 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/Button.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/Button.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
Item {
id: container
diff --git a/examples/demos/photoviewer/PhotoViewerCore/EditableButton.qml b/examples/demos/photoviewer/PhotoViewerCore/EditableButton.qml
index 2df47c063..82f1679de 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/EditableButton.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/EditableButton.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
Item {
id: container
diff --git a/examples/demos/photoviewer/PhotoViewerCore/PhotoDelegate.qml b/examples/demos/photoviewer/PhotoViewerCore/PhotoDelegate.qml
index b3652701e..6d02e8708 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/PhotoDelegate.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/PhotoDelegate.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
import "script/script.mjs" as Script
Package {
@@ -79,8 +79,8 @@ Package {
Rectangle {
id: placeHolder
- property int w: Script.getWidth(content)
- property int h: Script.getHeight(content)
+ property int w: 400
+ property int h: 400
property double s: Script.calculateScale(w, h, photoWrapper.width)
color: 'white'; anchors.centerIn: parent; antialiasing: true
@@ -98,7 +98,7 @@ Package {
BusyIndicator { anchors.centerIn: parent; on: originalImage.status != Image.Ready }
Image {
id: originalImage; antialiasing: true;
- source: "http://" + Script.getImagePath(content); cache: false
+ source: link; cache: false
fillMode: Image.PreserveAspectFit; width: photoWrapper.width; height: photoWrapper.height
}
Image {
@@ -143,7 +143,7 @@ Package {
width: mainWindow.width; height: mainWindow.height
}
PropertyChanges { target: border; opacity: 0 }
- PropertyChanges { target: hqImage; source: listItem.ListView.isCurrentItem ? hq : ""; visible: true }
+ PropertyChanges { target: hqImage; source: listItem.ListView.isCurrentItem ? link : ""; visible: true }
}
]
diff --git a/examples/demos/photoviewer/PhotoViewerCore/ProgressBar.qml b/examples/demos/photoviewer/PhotoViewerCore/ProgressBar.qml
index ee21eb6fc..4b0a5dc73 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/ProgressBar.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/ProgressBar.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
Item {
id: container
diff --git a/examples/demos/photoviewer/PhotoViewerCore/RssModel.qml b/examples/demos/photoviewer/PhotoViewerCore/RssModel.qml
index c19888a40..5fb1cce4e 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/RssModel.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/RssModel.qml
@@ -48,8 +48,8 @@
**
****************************************************************************/
-import QtQuick 2.0
-import QtQuick.XmlListModel 2.0
+import QtQuick
+import XmlListModel
XmlListModel {
property string tags : ""
@@ -57,10 +57,11 @@ XmlListModel {
function encodeTags(x) { return encodeURIComponent(x.replace(' ',',')); }
source: "http://api.flickr.com/services/feeds/photos_public.gne?"+(tags ? "tags="+encodeTags(tags)+"&" : "")
+
query: "/feed/entry"
- namespaceDeclarations: "declare default element namespace 'http://www.w3.org/2005/Atom';"
- XmlRole { name: "title"; query: "title/string()" }
- XmlRole { name: "content"; query: "content/string()" }
- XmlRole { name: "hq"; query: "link[@rel='enclosure']/@href/string()" }
+ roles: [
+ XmlListModelRole { elementName: "title"; attributeName: "" },
+ XmlListModelRole { elementName: "link"; attributeName: "href" }
+ ]
}
diff --git a/examples/demos/photoviewer/PhotoViewerCore/Tag.qml b/examples/demos/photoviewer/PhotoViewerCore/Tag.qml
index bc12d81a9..bdeb02135 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/Tag.qml
+++ b/examples/demos/photoviewer/PhotoViewerCore/Tag.qml
@@ -48,7 +48,7 @@
**
****************************************************************************/
-import QtQuick 2.0
+import QtQuick
Flipable {
id: flipable
diff --git a/examples/demos/photoviewer/PhotoViewerCore/script/script.mjs b/examples/demos/photoviewer/PhotoViewerCore/script/script.mjs
index a1822197b..0a33a725d 100644
--- a/examples/demos/photoviewer/PhotoViewerCore/script/script.mjs
+++ b/examples/demos/photoviewer/PhotoViewerCore/script/script.mjs
@@ -48,20 +48,6 @@
**
****************************************************************************/
-export function getWidth(string) {
- return (string.match(/width=\"([0-9]+)\"/))[1]
-}
-
-export function getHeight(string) {
- return (string.match(/height=\"([0-9]+)\"/))[1]
-}
-
-export function getImagePath(string) {
- var pattern = /src=\"https?:\/\/(\S+)\"/
- var match = string.match(pattern)
- return match ? match[1] : ""
-}
-
export function calculateScale(width, height, cellSize) {
var widthScale = (cellSize * 1.0) / width
var heightScale = (cellSize * 1.0) / height
diff --git a/examples/demos/photoviewer/doc/src/photoviewer.qdoc b/examples/demos/photoviewer/doc/src/photoviewer.qdoc
index bebeb9b52..8f4742460 100644
--- a/examples/demos/photoviewer/doc/src/photoviewer.qdoc
+++ b/examples/demos/photoviewer/doc/src/photoviewer.qdoc
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2017 The Qt Company Ltd.
+** Copyright (C) 2020 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the documentation of the Qt Toolkit.
@@ -29,19 +29,20 @@
\title Qt Quick Demo - Photo Viewer
\ingroup qtquickdemos
\example demos/photoviewer
- \brief A QML photo viewer that that uses XmlListModel and XmlRole to
- download Flickr feeds, and Package to display the photos in different views.
+ \brief A QML photo viewer that uses XmlListModel and XmlListModelRole
+ custom QML types to download Flickr feeds, and Package to display the photos
+ in different views.
\image qtquick-demo-photoviewer-small.png
\e{Photo Viewer} demonstrates the following \l{Qt Quick} features:
\list
- \li Using custom types to create screens and screen controls.
+ \li Using custom QML types.
\li Using Qt Quick Controls 1 to create an application window.
\li Using the \l Package type with a \l DelegateModel to provide
delegates with a shared context to multiple views.
- \li Using XML list models to download Flickr feeds.
+ \li Using custom types to download Flickr feeds.
\li Using the \l Flipable type to create labels with different text on
the front and back.
\li Using the PathView, \l Path, PathAttribute, and PathLine types to
@@ -76,11 +77,55 @@
\skipto PhotoViewerCore
\printuntil "
+ We also use the following custom types that are defined in C++:
+
+ \list
+ \li \c XmlListModel
+ \li \c XmlListModelRole
+ \endlist
+
+ To register QML types from C++ we add the QML_ELEMENT macro to the QObject
+ derived classes' definitions like this:
+
+ \quotefromfile demos/shared/xmllistmodel.h
+ \skipto XmlListModelRole
+ \printuntil QML_ELEMENT
+
+ In addition we need to add the following to the CMakeLists.txt file of the
+ example:
+
+ \quotefromfile demos/photoviewer/CMakeLists.txt
+ \skipto set_target_properties
+ \printuntil PROPERTIES
+ \skipto QT_QML_MODULE_VERSION 1.0
+ \printuntil qt6_qml_type_registration(photoviewer)
+
+ To build with qmake, we add \c CONFIG += qmltypes, \c QML_IMPORT_NAME, and
+ \c QML_IMPORT_MAJOR_VERSION to the project file:
+
+ \quotefromfile demos/photoviewer/photoviewer.pro
+ \skipto CONFIG
+ \printuntil qmltypes
+ \skipto QML_IMPORT_NAME
+ \printuntil QML_IMPORT_MAJOR_VERSION
+
+ For more information on defining QML types from C++ see the
+ \l {Defining QML Types from C++} documentation.
+
+ To use the new types, we add an import statement that imports them to the QML
+ files that use the types:
+
+ \quotefromfile demos/photoviewer/PhotoViewerCore/AlbumDelegate.qml
+ \skipto XmlListModel
+ \printuntil import
+
\section1 Creating the Main Window
In main.qml, we use the ApplicationWindow Qt Quick Control to create the app
main window:
+ \quotefromfile demos/photoviewer/main.qml
+ \skipto ApplicationWindow
\printuntil visible
We use a ListModel type with \l ListElement types to display photo albums:
@@ -156,7 +201,7 @@
\printuntil RssModel
\printuntil }
- In RssModel.qml, we use an XmlListModel type as a data source for
+ In RssModel.qml, we use the XmlListModel custom type as a data source for
\l Package objects to download photos from the selected feeds:
\quotefromfile demos/photoviewer/PhotoViewerCore/RssModel.qml
@@ -170,20 +215,16 @@
We use the \c source property to fetch photos that have the specified tags
attached from public Flickr feeds:
- \printuntil namespaceDeclarations
+ \printuntil query
The \c query property specifies that the XmlListModel generates a model item
for each feed entry.
- The \c namespaceDeclarations property specifies that the requested document
- uses the namespace \c{http://www.w3.org/2005/Atom}, which is declared as the
- default namespace.
-
- We use the XmlRole type to specify the model item attributes. Each model
- item has the \c title, \c content, and \c hq attributes that match the
+ We use the XmlListModelRole custom type to specify the model item attributes.
+ Each model item has the \c title and \c link attributes that match the
values of the corresponding feed entry:
- \printuntil hq
+ \printuntil link
\section1 Creating Flipable Labels
diff --git a/examples/demos/photoviewer/main.qml b/examples/demos/photoviewer/main.qml
index 8ed77ad2a..2b9651402 100644
--- a/examples/demos/photoviewer/main.qml
+++ b/examples/demos/photoviewer/main.qml
@@ -48,9 +48,8 @@
**
****************************************************************************/
-import QtQuick 2.2
-import QtQuick.Controls 1.1
-import QtQml.Models 2.1
+import QtQuick
+import QtQuick.Controls
import "PhotoViewerCore"
ApplicationWindow {
diff --git a/examples/demos/photoviewer/photoviewer.pro b/examples/demos/photoviewer/photoviewer.pro
index 234318057..2d3d34aff 100644
--- a/examples/demos/photoviewer/photoviewer.pro
+++ b/examples/demos/photoviewer/photoviewer.pro
@@ -1,9 +1,16 @@
TEMPLATE = app
-QT += qml quick xmlpatterns
-CONFIG += lrelease embed_translations
+QT += qml quick
+CONFIG += lrelease embed_translations qmltypes
-SOURCES += main.cpp
+INCLUDEPATH += ../shared
+
+HEADERS += ../shared/xmllistmodel.h
+SOURCES += main.cpp \
+ ../shared/xmllistmodel.cpp
+
+QML_IMPORT_NAME = XmlListModel
+QML_IMPORT_MAJOR_VERSION = 1
lupdate_only {
SOURCES = *.qml \