diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2023-06-14 16:43:29 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2023-07-13 17:07:28 +0200 |
commit | 1beb9335b429a3bf143fc41c8d64d1d25bbd3ec2 (patch) | |
tree | 08ae042e5a9c65a2acb6f09397e94be8b4c94971 /examples | |
parent | 9dcff27fcf9a389bbcded1ff02f32ba4c015f936 (diff) |
XBEL streaming: shuffle mainwindow parts into more pedagogic order
Renumber the code fragments to match their order, while adding a
number for the previously undocumented custom method. Add a brief
description of it. Move the createMenus() part up to after it, combine
the createActions() with its (as createActions() is long gone, fused
into it and sharing its snippet number).
Task-number: QTBUG-111228
Change-Id: If0fbcadfa058fc12cbd74ba1897646113bd016b0
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
(cherry picked from commit 98765cab974d02ccd364355a44dfeb8e8ef969d5)
Diffstat (limited to 'examples')
-rw-r--r-- | examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc | 47 | ||||
-rw-r--r-- | examples/corelib/serialization/streambookmarks/mainwindow.cpp | 18 |
2 files changed, 36 insertions, 29 deletions
diff --git a/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc b/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc index 5fb62c8a68..4659a103cf 100644 --- a/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc +++ b/examples/corelib/serialization/streambookmarks/doc/src/qxmlstreambookmarks.qdoc @@ -121,42 +121,47 @@ \snippet serialization/streambookmarks/mainwindow.cpp 0 + A custom menu, triggered when the user right-clicks on a bookmark, provides + for copying the bookmark as a link or directing a desktop browser to open + the URL it references. This menu is implemented (when relevant features are + enabled) by \c onCustomContextMenuRequested(). + + \snippet serialization/streambookmarks/mainwindow.cpp 1 + + In order to implement the \c open(), \c saveAs(), \c exit(), \c about() and + \c aboutQt() functions, \c createMenus() connects them to QAction objects + and adds them to the \c fileMenu and \c helpMenu. The connections are as + shown below: + + The \c createMenus() function creates the \c fileMenu and \c helpMenu + and adds the QAction objects to them in order to create the menu shown + in the screenshot below: + + \table + \row + \li \inlineimage filemenu.png + \li \inlineimage helpmenu.png + \endtable + + \snippet serialization/streambookmarks/mainwindow.cpp 2 + The \c open() function enables the user to open an XBEL file using QFileDialog. A warning message is displayed along with the \c fileName and \c errorString if the file cannot be read or if there is a parse error. - \snippet serialization/streambookmarks/mainwindow.cpp 1 + \snippet serialization/streambookmarks/mainwindow.cpp 3 The \c saveAs() function displays a QFileDialog, prompting the user for a \c fileName. Similar to the \c open() function, this function also displays a warning message if the file cannot be written to. - \snippet serialization/streambookmarks/mainwindow.cpp 2 + \snippet serialization/streambookmarks/mainwindow.cpp 4 The \c about() function displays a QMessageBox with a brief description of the example. - \snippet serialization/streambookmarks/mainwindow.cpp 3 - - In order to implement the \c open(), \c saveAs(), \c exit(), \c about() - and \c aboutQt() functions, we connect them to QAction objects and - add them to the \c fileMenu and \c helpMenu. The connections are as shown - below: - - \snippet serialization/streambookmarks/mainwindow.cpp 5 - - The \c createMenus() function creates the \c fileMenu and \c helpMenu - and adds the QAction objects to them in order to create the menu shown - in the screenshot below: - - \table - \row - \li \inlineimage filemenu.png - \li \inlineimage helpmenu.png - \endtable - \snippet serialization/streambookmarks/mainwindow.cpp 5 \section1 \c{main()} Function diff --git a/examples/corelib/serialization/streambookmarks/mainwindow.cpp b/examples/corelib/serialization/streambookmarks/mainwindow.cpp index b45b348cf0..e84e8634b1 100644 --- a/examples/corelib/serialization/streambookmarks/mainwindow.cpp +++ b/examples/corelib/serialization/streambookmarks/mainwindow.cpp @@ -45,6 +45,7 @@ MainWindow::MainWindow() } //! [0] +//! [1] #if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu) void MainWindow::onCustomContextMenuRequested(const QPoint &pos) { @@ -62,8 +63,9 @@ void MainWindow::onCustomContextMenuRequested(const QPoint &pos) QDesktopServices::openUrl(QUrl(url)); } #endif // QT_CONFIG(clipboard) && QT_CONFIG(contextmenu) +//! [1] -//! [5] +//! [2] void MainWindow::createMenus() { QMenu *fileMenu = menuBar()->addMenu(tr("&File")); @@ -82,9 +84,9 @@ void MainWindow::createMenus() helpMenu->addAction(tr("&About"), this, &MainWindow::about); helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt); } -//! [5] +//! [2] -//! [1] +//! [3] void MainWindow::open() { QFileDialog fileDialog(this, tr("Open Bookmark File"), QDir::currentPath()); @@ -115,9 +117,9 @@ void MainWindow::open() } } -//! [1] +//! [3] -//! [2] +//! [4] void MainWindow::saveAs() { QFileDialog fileDialog(this, tr("Save Bookmark File"), QDir::currentPath()); @@ -141,13 +143,13 @@ void MainWindow::saveAs() if (writer.writeFile(&file)) statusBar()->showMessage(tr("File saved"), 2000); } -//! [2] +//! [4] -//! [3] +//! [5] void MainWindow::about() { QMessageBox::about(this, tr("About QXmlStream Bookmarks"), tr("The <b>QXmlStream Bookmarks</b> example demonstrates how to use Qt's " "QXmlStream classes to read and write XML documents.")); } -//! [3] +//! [5] |