Debian Codegraph @

examples/xml/dombookmarks/doc/src/dombookmarks.qdoc

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4 /*!
5 \example dombookmarks
6 \title DOM Bookmarks Application
7 \examplecategory {Data Processing & I/O}
8 \ingroup xml-examples
9 \meta tag {xml}
10 \brief Provides a reader for XML Bookmark Exchange Language files.
11
12 The DOM Bookmarks Application provides a reader for XML Bookmark Exchange
13 Language (XBEL) files that uses Qt's DOM-based XML API to read and parse
14 the files. The \l {QXmlStream Bookmarks Example} provides an alternative
15 way to read this type of file.
16
17 \image screenshot.png
18
19 \section1 The XbelTree Class Definition
20
21 The XbelTree class has functions for reading and writing to the filesystem.
22 It inherits from the QTreeWidget class, contains the model for the
23 displaying of the bookmarks, and allows it to be edited.
24
25 \snippet dombookmarks/xbeltree.h 0
26
27 \section1 The XbelTree Class Implementation
28
29 The \c XbelTree constructor accepts a QWidget within which it is placed.
30 The \c folderIcon is set to QIcon::Normal mode where the pixmap is only
31 displayed when the user is not interacting with the icon. The
32 QStyle::SP_DirClosedIcon, QStyle::SP_DirOpenIcon, and QStyle::SP_FileIcon
33 correspond to standard pixmaps that follow the style of your GUI.
34
35 \snippet dombookmarks/xbeltree.cpp 0
36
37 The \c read() function opens the given QIODevice using
38 QDomDocument::setContent. If it succeeds opening the file and the top
39 level headers are verified, the contents of the class is cleared before
40 the file contents is parsed by iterating all the top level XML nodes and
41 calling \c parseFolderElement() on each of them.
42
43 \snippet dombookmarks/xbeltree.cpp 1
44
45 The \c parseFolderElement() function handles the different element types
46 and calls itself recursively if the element is a subfolder.
47
48 \snippet dombookmarks/xbeltree.cpp 3
49
50 The \c write() function saves the domDocument to the given QIODevice using
51 QDomDocument::save.
52
53 \snippet dombookmarks/xbeltree.cpp 2
54
55 \section1 The MainWindow Class Definition
56
57 The \c MainWindow class is a subclass of QMainWindow, with a
58 \c File menu and a \c Help menu.
59
60 \snippet dombookmarks/mainwindow.h 0
61
62 \section1 The MainWindow Class Implementation
63
64 The \c MainWindow constructor instantiates the member XbelTree object,
65 and sets its header with a QStringList object, \c labels.
66 The constructor also invokes \c createMenus() to set up the menus.
67 The \c statusBar() is used to display the message "Ready".
68
69 \snippet dombookmarks/mainwindow.cpp 0
70
71 The \c createMenus() function populates the menus and sets keyboard
72 shortcuts.
73
74 \snippet dombookmarks/mainwindow.cpp 4
75
76 The \c open() function enables the user to open an XBEL file using
77 QFileDialog. A warning message is displayed along
78 with the \c fileName and \c errorString if the file cannot be read or
79 if there is a parse error. If it succeeds it calls \c XbelTree::read().
80
81 \snippet dombookmarks/mainwindow.cpp 1
82
83 The \c saveAs() function displays a QFileDialog, prompting the user for
84 a \c fileName. Similar to the \c open() function, this function also
85 displays a warning message if the file cannot be written to. If this
86 succeeds it calls \c XbelTree::write().
87
88 \snippet dombookmarks/mainwindow.cpp 2
89
90 The \c about() function displays a QMessageBox with a brief description
91 of the example.
92
93 \snippet dombookmarks/mainwindow.cpp 3
94
95 See the \l{http://pyxml.sourceforge.net/topics/xbel/}{XML Bookmark Exchange Language
96 Resource Page} for more information about XBEL files.
97 */