summaryrefslogtreecommitdiffstats
path: root/examples/widgets/doc/src
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@qt.io>2016-07-05 13:26:53 +0200
committerFriedemann Kleint <Friedemann.Kleint@qt.io>2016-08-03 11:53:55 +0000
commitd1a30be5abcc2d5e5340866434b2691275a135a6 (patch)
tree968a76a1716a7cec5438dfa45dc41021c326db7b /examples/widgets/doc/src
parentd5be0d30588f6ccd971f73a3c030f9c10d8a6b4e (diff)
Polish the findfiles example to be actually useful
- Simplify the code, remove unused members - Fix the translations of plurals to use %n - Add tooltip displaying full paths in list - Add context menu allowing to copy the name and open - Display the correct slashes on Windows - Connect the returnPressed() signals of the line edits - Make the search recursive - Do not search binary files by checking the mime type Change-Id: I3663799c88931db1f58c03ea35211e7ab03737ec Reviewed-by: Topi Reiniƶ <topi.reinio@theqtcompany.com>
Diffstat (limited to 'examples/widgets/doc/src')
-rw-r--r--examples/widgets/doc/src/findfiles.qdoc38
1 files changed, 29 insertions, 9 deletions
diff --git a/examples/widgets/doc/src/findfiles.qdoc b/examples/widgets/doc/src/findfiles.qdoc
index dd06ed8bb4..df2ef40768 100644
--- a/examples/widgets/doc/src/findfiles.qdoc
+++ b/examples/widgets/doc/src/findfiles.qdoc
@@ -120,10 +120,12 @@
\snippet dialogs/findfiles/window.cpp 4
We use the directory's path to create a QDir; the QDir class
- provides access to directory structures and their contents. We
- create a list of the files (contained in the newly created QDir)
- that match the specified file name. If the file name is empty
- the list will contain all the files in the directory.
+ provides access to directory structures and their contents.
+
+ \snippet dialogs/findfiles/window.cpp 13
+
+ We recursively create a list of the files (contained in the newl
+ created QDir) that match the specified file name.
Then we search through all the files in the list, using the private
\c findFiles() function, eliminating the ones that don't contain
@@ -173,9 +175,7 @@
\snippet dialogs/findfiles/window.cpp 7
- After updating the QProgressDialog, we create a QFile using the
- QDir::absoluteFilePath() function which returns the absolute path
- name of a file in the directory. We open the file in read-only
+ After updating the QProgressDialog, we open the file in read-only
mode, and read one line at a time using QTextStream.
The QTextStream class provides a convenient interface for reading
@@ -194,9 +194,18 @@
Both the \c findFiles() and \c showFiles() functions are called from
the \c find() slot. In the \c showFiles() function we run through
- the provided list of file names, adding each file name to the
+ the provided list of file names, adding each relative file name to the
first column in the table widget and retrieving the file's size using
- QFile and QFileInfo for the second column.
+ QFileInfo for the second column. For later use, we set
+ the absolute path as a data on the QTableWidget using the
+ the role absoluteFileNameRole defined to be Qt::UserRole + 1.
+
+ \snippet dialogs/findfiles/window.cpp 17
+
+ This allows for retrieving the name of an item using a
+ convenience function:
+
+ \snippet dialogs/findfiles/window.cpp 18
We also update the total number of files found.
@@ -236,8 +245,19 @@
\snippet dialogs/findfiles/window.cpp 12
+ \snippet dialogs/findfiles/window.cpp 14
+
The \c openFileOfItem() slot is invoked when the user double
clicks on a cell in the table. The QDesktopServices::openUrl()
knows how to open a file given the file name.
+
+ \snippet dialogs/findfiles/window.cpp 15
+ \snippet dialogs/findfiles/window.cpp 16
+
+ We set the context menu policy to of the table view to Qt::CustomContextMenu
+ and connect a slot contextMenu() to its signal
+ customContextMenuRequested(). We retrieve the absolute file name
+ from the data of the QTableWidgetItem and populate the context menu
+ with actions offering to copy the file name and to open the file.
*/