Skip to content

Commit

Permalink
QSet: Document to/from QVector transformation techniques
Browse files Browse the repository at this point in the history
Change-Id: I2a2ff6332bd6e8ed3d4ba7b4765da0a94a06f133
Fixes: QTBUG-71067
Reviewed-by: Paul Wicking <[email protected]>
Reviewed-by: Mitch Curtis <[email protected]>
  • Loading branch information
sgaist committed Oct 24, 2019
1 parent cffb889 commit c8aadc7
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/corelib/doc/snippets/code/doc_src_containers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,11 @@ int j = *i; // Undefined behavior!
but with QVector this is likely to crash.
*/
//! [24]

//! [25]
QVector<int> vector{1, 2, 3, 4, 4, 5};
QSet<int> set(vector.begin(), vector.end());
/*
Will generate a QSet containing 1, 2, 4, 5.
*/
//! [25]
6 changes: 6 additions & 0 deletions src/corelib/doc/src/containers.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@
Qt also offers a \l{foreach} keyword that make it very
easy to iterate over all the items stored in a container.

\note Since Qt 5.14, range constructors are available for most of the
container classes. QMultiMap is a notable exception. Their use is
encouraged in place of the various from/to methods. For example:

\snippet code/doc_src_containers.cpp 25

\section1 The Container Classes

Qt provides the following sequential containers: QList,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
\note Since Qt 5.14, range constructors are available for Qt's generic
\l{container classes} and should be used in place of this method.
12 changes: 12 additions & 0 deletions src/corelib/tools/qlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,8 @@ void **QListData::erase(void **xi)
\snippet code/src_corelib_tools_qlistdata.cpp 21
\include containers-range-constructor.qdocinc
\sa fromSet(), toVector(), QVector::toList()
*/

Expand All @@ -2025,6 +2027,8 @@ void **QListData::erase(void **xi)
\snippet code/src_corelib_tools_qlistdata.cpp 22
\include containers-range-constructor.qdocinc
\sa toSet(), fromVector(), QVector::fromList()
*/

Expand All @@ -2037,6 +2041,8 @@ void **QListData::erase(void **xi)
\snippet code/src_corelib_tools_qlistdata.cpp 23
\include containers-range-constructor.qdocinc
\sa fromVector(), toSet(), QSet::toList()
*/

Expand All @@ -2050,6 +2056,8 @@ void **QListData::erase(void **xi)
\snippet code/src_corelib_tools_qlistdata.cpp 24
\include containers-range-constructor.qdocinc
\sa toVector(), fromSet(), QSet::fromList()
*/

Expand All @@ -2062,6 +2070,8 @@ void **QListData::erase(void **xi)
\snippet code/src_corelib_tools_qlistdata.cpp 25
\include containers-range-constructor.qdocinc
\sa toStdList(), QVector::fromStdVector()
*/

Expand All @@ -2072,6 +2082,8 @@ void **QListData::erase(void **xi)
\snippet code/src_corelib_tools_qlistdata.cpp 26
\include containers-range-constructor.qdocinc
\sa fromStdList(), QVector::toStdVector()
*/

Expand Down
6 changes: 6 additions & 0 deletions src/corelib/tools/qset.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,8 @@

\snippet code/doc_src_qset.cpp 13

\include containers-range-constructor.qdocinc

\sa fromList(), QList::fromSet()
*/

Expand All @@ -1011,6 +1013,8 @@

This is the same as toList().

\include containers-range-constructor.qdocinc

\sa fromList(), QList::fromSet()
*/

Expand All @@ -1026,6 +1030,8 @@

\snippet code/doc_src_qset.cpp 14

\include containers-range-constructor.qdocinc

\sa toList(), QList::toSet()
*/

Expand Down
8 changes: 8 additions & 0 deletions src/corelib/tools/qvector.qdoc
Original file line number Diff line number Diff line change
Expand Up @@ -1359,6 +1359,8 @@

\snippet code/src_corelib_tools_qvector.cpp 14

\include containers-range-constructor.qdocinc

\sa fromList(), QList::fromVector()
*/

Expand All @@ -1370,6 +1372,8 @@

\snippet code/src_corelib_tools_qvector.cpp 15

\include containers-range-constructor.qdocinc

\sa toList(), QList::toVector()
*/

Expand All @@ -1382,6 +1386,8 @@

\snippet code/src_corelib_tools_qvector.cpp 16

\include containers-range-constructor.qdocinc

\sa toStdVector(), QList::fromStdList()
*/

Expand All @@ -1392,6 +1398,8 @@

\snippet code/src_corelib_tools_qvector.cpp 17

\include containers-range-constructor.qdocinc

\sa fromStdVector(), QList::toStdList()
*/

Expand Down

0 comments on commit c8aadc7

Please sign in to comment.