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). Pick-to: 6.6 6.5 Task-number: QTBUG-111228 Change-Id: If0fbcadfa058fc12cbd74ba1897646113bd016b0 Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
This commit is contained in:
parent
bb69def7d1
commit
98765cab97
@ -121,31 +121,17 @@
|
||||
|
||||
\snippet serialization/streambookmarks/mainwindow.cpp 0
|
||||
|
||||
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.
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
@ -157,6 +143,25 @@
|
||||
\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 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 4
|
||||
|
||||
The \c about() function displays a QMessageBox with a brief description
|
||||
of the example.
|
||||
|
||||
\snippet serialization/streambookmarks/mainwindow.cpp 5
|
||||
|
||||
\section1 \c{main()} Function
|
||||
|
@ -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]
|
||||
|
Loading…
x
Reference in New Issue
Block a user