summaryrefslogtreecommitdiffstats
path: root/examples/nfc/corkboard/doc/src/corkboard.qdoc
blob: ac21187b09059a303612d7c3a125ef21a1334110 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/****************************************************************************
**
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the examples of the QtNfc module.
**
** $QT_BEGIN_LICENSE:FDL$
** 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.
**
** GNU Free Documentation License Usage
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of
** this file. Please review the following information to ensure
** the GNU Free Documentation License version 1.3 requirements
** will be met: https://www.gnu.org/licenses/fdl-1.3.html.
** $QT_END_LICENSE$
**
****************************************************************************/

/*!
\example corkboard
\title QML CorkBoard Example
\brief A QML example about displaying NFC Data Exchange Format (NDEF) messages.

The QML corkboard example displays the contents of NDEF messages read
from an NFC Tag. Each newly detected NDEF message is added to the
corkboard and can be dragged into an arbitrary position on the
board. The corkboard has a \e Personal and \e Work space. The
workspace can be changed by sliding left or right.


\image corkboard.png

\section1 Implementation details
In the corkboard example, we use the following .qml files:
    \list
        \li corkboards.qml
        \li Mode.qml
    \endlist

The main.cpp holds the application logic to load the main view stored
in the corkboards.qml file.

\snippet corkboard/main.cpp 0

\section1 corkboards.qml details
There are two basic QML components in this file:
    \list
        \li NearField
        \li ListView
    \endlist

The first time the NearField QML type is instantiated, the
Component.onCompleted handler will start the NFC polling process. The
\l [Qml] {NearField} {onMessageRecordsChanged} handler parses NFC
Messages that are detected by the NearField component and builds up a
data model that is passed into the ListView. Additionally, every time the
NearField manager stops the polling process, the onPollingChanged
handler restarts it.

\quotefromfile corkboard/corkboards.qml
\skipto NearField
\printuntil onMessageRecordsChanged
\dots 8
\skipuntil }
\skipto onPollingChanged
\printuntil onPollingChanged
\dots 8
\skipuntil }
\skipto Component
\printuntil Component
\dots 8
\skipuntil }
\printline }
\skipto ListModel
\printto ListModel

The ListView component takes a ListModel as parameter (built from the
NFC records). The view of each of the items of the model is defined by
the Mode component (its implementation details can be found in the
file Mode.qml). The data model consists of a list of corkboards. Each
corkboard can display multiple NFC text message records.

\quotefromfile corkboard/corkboards.qml
\skipto ListView
\printuntil id
\dots 8
\skipto model
\printuntil model
\dots 8
\skipto delegate
\printuntil delegate
\skipto }
\printline }

\section1 Mode.qml details

A corkboard title is displayed for each of the items that form part
of the data model:

\quotefromfile corkboard/Mode.qml
\skipto Text
\printuntil }
\printuntil }

Every text record that was read from an NFC message, is represented by
a sticky note with its own position on the display. Initially the
position is set randomly. The text on the sticky note is set on a
TextField.

\quotefromfile corkboard/Mode.qml
\skipto Repeater
\printuntil y:
\skipto Item
\dots 16
\printuntil sticky
\dots 20
\skipto TextEdit
\printuntil noteText
\dots 24
\skipto }
\printuntil }
\dots 20

\include examples-run.qdocinc

\sa {Qt NFC}

*/