source: trunk/doc/src/examples/qxmlstreambookmarks.qdoc

Last change on this file was 846, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 7.6 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the documentation of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:FDL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in a
14** written agreement between you and Nokia.
15**
16** GNU Free Documentation License
17** Alternatively, this file may be used under the terms of the GNU Free
18** Documentation License version 1.3 as published by the Free Software
19** Foundation and appearing in the file included in the packaging of this
20** file.
21**
22** If you have questions regarding the use of this file, please contact
23** Nokia at [email protected].
24** $QT_END_LICENSE$
25**
26****************************************************************************/
27
28/*!
29 \example xml/streambookmarks
30 \title QXmlStream Bookmarks Example
31
32 The QXmlStream Bookmarks example provides a reader for XML Bookmark
33 Exchange Language (XBEL) files using Qt's QXmlStreamReader class
34 for reading, and QXmlStreamWriter class for writing the files.
35
36 \image xmlstreamexample-screenshot.png
37
38 \section1 XbelWriter Class Definition
39
40 The \c XbelWriter class contains a private instance of QXmlStreamWriter,
41 which provides an XML writer with a streaming API. \c XbelWriter also
42 has a reference to the QTreeWidget instance where the bookmark hierarchy
43 is stored.
44
45 \snippet examples/xml/streambookmarks/xbelwriter.h 0
46
47 \section1 XbelWriter Class Implementation
48
49 The \c XbelWriter constructor accepts a \a treeWidget to initialize within
50 its definition. We enable \l{QXmlStreamWriter}'s auto-formatting property
51 to ensure line-breaks and indentations are added automatically to empty
52 sections between elements, increasing readability as the data is split into
53 several lines.
54
55 \snippet examples/xml/streambookmarks/xbelwriter.cpp 0
56
57 The \c writeFile() function accepts a QIODevice object and sets it using
58 \c setDevice(). This function then writes the document type
59 definition(DTD), the start element, the version, and \c{treeWidget}'s
60 top-level items.
61
62 \snippet examples/xml/streambookmarks/xbelwriter.cpp 1
63
64 The \c writeItem() function accepts a QTreeWidgetItem object and writes it
65 to the stream, depending on its \c tagName, which can either be a "folder",
66 "bookmark", or "separator".
67
68 \snippet examples/xml/streambookmarks/xbelwriter.cpp 2
69
70 \section1 XbelReader Class Definition
71
72 The \c XbelReader contains a private instance of QXmlStreamReader, the
73 companion class to QXmlStreamWriter. \c XbelReader also contains a
74 reference to the QTreeWidget that is used to group the bookmarks according
75 to their hierarchy.
76