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
|
\snippet serialization/streambookmarks/mainwindow.cpp 0
|
||||||
|
|
||||||
The \c open() function enables the user to open an XBEL file using
|
A custom menu, triggered when the user right-clicks on a bookmark, provides
|
||||||
QFileDialog. A warning message is displayed along
|
for copying the bookmark as a link or directing a desktop browser to open
|
||||||
with the \c fileName and \c errorString if the file cannot be read or
|
the URL it references. This menu is implemented (when relevant features are
|
||||||
if there is a parse error.
|
enabled) by \c onCustomContextMenuRequested().
|
||||||
|
|
||||||
\snippet serialization/streambookmarks/mainwindow.cpp 1
|
\snippet serialization/streambookmarks/mainwindow.cpp 1
|
||||||
|
|
||||||
The \c saveAs() function displays a QFileDialog, prompting the user for
|
In order to implement the \c open(), \c saveAs(), \c exit(), \c about() and
|
||||||
a \c fileName. Similar to the
|
\c aboutQt() functions, \c createMenus() connects them to QAction objects
|
||||||
\c open() function, this function also displays a warning message if
|
and adds them to the \c fileMenu and \c helpMenu. The connections are as
|
||||||
the file cannot be written to.
|
shown below:
|
||||||
|
|
||||||
\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
|
|
||||||
|
|
||||||
The \c createMenus() function creates the \c fileMenu and \c helpMenu
|
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
|
and adds the QAction objects to them in order to create the menu shown
|
||||||
@ -157,6 +143,25 @@
|
|||||||
\li \inlineimage helpmenu.png
|
\li \inlineimage helpmenu.png
|
||||||
\endtable
|
\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
|
\snippet serialization/streambookmarks/mainwindow.cpp 5
|
||||||
|
|
||||||
\section1 \c{main()} Function
|
\section1 \c{main()} Function
|
||||||
|
@ -45,6 +45,7 @@ MainWindow::MainWindow()
|
|||||||
}
|
}
|
||||||
//! [0]
|
//! [0]
|
||||||
|
|
||||||
|
//! [1]
|
||||||
#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
|
#if QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
|
||||||
void MainWindow::onCustomContextMenuRequested(const QPoint &pos)
|
void MainWindow::onCustomContextMenuRequested(const QPoint &pos)
|
||||||
{
|
{
|
||||||
@ -62,8 +63,9 @@ void MainWindow::onCustomContextMenuRequested(const QPoint &pos)
|
|||||||
QDesktopServices::openUrl(QUrl(url));
|
QDesktopServices::openUrl(QUrl(url));
|
||||||
}
|
}
|
||||||
#endif // QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
|
#endif // QT_CONFIG(clipboard) && QT_CONFIG(contextmenu)
|
||||||
|
//! [1]
|
||||||
|
|
||||||
//! [5]
|
//! [2]
|
||||||
void MainWindow::createMenus()
|
void MainWindow::createMenus()
|
||||||
{
|
{
|
||||||
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
QMenu *fileMenu = menuBar()->addMenu(tr("&File"));
|
||||||
@ -82,9 +84,9 @@ void MainWindow::createMenus()
|
|||||||
helpMenu->addAction(tr("&About"), this, &MainWindow::about);
|
helpMenu->addAction(tr("&About"), this, &MainWindow::about);
|
||||||
helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
|
helpMenu->addAction(tr("About &Qt"), qApp, &QApplication::aboutQt);
|
||||||
}
|
}
|
||||||
//! [5]
|
//! [2]
|
||||||
|
|
||||||
//! [1]
|
//! [3]
|
||||||
void MainWindow::open()
|
void MainWindow::open()
|
||||||
{
|
{
|
||||||
QFileDialog fileDialog(this, tr("Open Bookmark File"), QDir::currentPath());
|
QFileDialog fileDialog(this, tr("Open Bookmark File"), QDir::currentPath());
|
||||||
@ -115,9 +117,9 @@ void MainWindow::open()
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
//! [1]
|
//! [3]
|
||||||
|
|
||||||
//! [2]
|
//! [4]
|
||||||
void MainWindow::saveAs()
|
void MainWindow::saveAs()
|
||||||
{
|
{
|
||||||
QFileDialog fileDialog(this, tr("Save Bookmark File"), QDir::currentPath());
|
QFileDialog fileDialog(this, tr("Save Bookmark File"), QDir::currentPath());
|
||||||
@ -141,13 +143,13 @@ void MainWindow::saveAs()
|
|||||||
if (writer.writeFile(&file))
|
if (writer.writeFile(&file))
|
||||||
statusBar()->showMessage(tr("File saved"), 2000);
|
statusBar()->showMessage(tr("File saved"), 2000);
|
||||||
}
|
}
|
||||||
//! [2]
|
//! [4]
|
||||||
|
|
||||||
//! [3]
|
//! [5]
|
||||||
void MainWindow::about()
|
void MainWindow::about()
|
||||||
{
|
{
|
||||||
QMessageBox::about(this, tr("About QXmlStream Bookmarks"),
|
QMessageBox::about(this, tr("About QXmlStream Bookmarks"),
|
||||||
tr("The <b>QXmlStream Bookmarks</b> example demonstrates how to use Qt's "
|
tr("The <b>QXmlStream Bookmarks</b> example demonstrates how to use Qt's "
|
||||||
"QXmlStream classes to read and write XML documents."));
|
"QXmlStream classes to read and write XML documents."));
|
||||||
}
|
}
|
||||||
//! [3]
|
//! [5]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user