summaryrefslogtreecommitdiffstats
path: root/src/corelib/doc/snippets
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2025-07-22 11:20:57 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2025-07-22 21:12:39 +0200
commit1a0246c1f5cb6ac745f546fb3fca020b57d1bd2e (patch)
tree44a883f5411d360d080868f4d2a220e9fc585db5 /src/corelib/doc/snippets
parentd5c221c4fc381702922db412dc02486ed19b4dcc (diff)
QRM: remove the SingleColumn wrapper type
The RowOptions template gives us a better mechanism of declaring a type with metaobject as a multi-role item in a list. The SingleColumn alias of a single-element tuple is not as transparent as it should be, and operating on a list of types wrapped this way becomes quite cumbersome (using std::get<0>, extra braces for initialization). Adjust the documentation to focus on the RowOptions mechanism, and replace relevant test cases with a single-element tuple, which can still be used for situations where specializing RowOptions is not applicable, such as for row types that don't have a meta object. If we see a clearer use case for a wrapper-based solution, then we can try to add a transparent SingleColumn wrapper type for which we specialize row_traits explicitly, without the complexity of the tuple protocol. Pick-to: 6.10 Change-Id: I515d9cb5c5129bd639fa9b20004be9a4101469eb Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
-rw-r--r--src/corelib/doc/snippets/qrangemodel/main.cpp70
1 files changed, 41 insertions, 29 deletions
diff --git a/src/corelib/doc/snippets/qrangemodel/main.cpp b/src/corelib/doc/snippets/qrangemodel/main.cpp
index a2f3f7c13e7..1415d962109 100644
--- a/src/corelib/doc/snippets/qrangemodel/main.cpp
+++ b/src/corelib/doc/snippets/qrangemodel/main.cpp
@@ -223,36 +223,48 @@ private:
void vector_of_objects()
{
- {
- //! [vector_of_objects_0]
- std::vector<std::shared_ptr<Entry>> entries = {
- //! [vector_of_objects_0]
- std::make_shared<Entry>(),
- //! [vector_of_objects_1]
- };
- //! [vector_of_objects_1]
-
- //! [vector_of_objects_2]
- QRangeModel model(std::ref(entries));
- QListView listView;
- listView.setModel(&model);
- //! [vector_of_objects_2]
- }
+ //! [vector_of_objects_0]
+ std::vector<std::shared_ptr<Entry>> entries = {
+ //! [vector_of_objects_0]
+ std::make_shared<Entry>(),
+ //! [vector_of_objects_1]
+ };
+ //! [vector_of_objects_1]
- {
- //! [vector_of_multirole_objects_0]
- std::vector<QRangeModel::SingleColumn<std::shared_ptr<Entry>>> entries = {
- //! [vector_of_multirole_objects_0]
- {std::make_shared<Entry>()},
- //! [vector_of_multirole_objects_1]
- };
- //! [vector_of_multirole_objects_1]
-
- //! [vector_of_multirole_objects_2]
- QRangeModel model(std::ref(entries));
- //! [vector_of_multirole_objects_2]
- }
+ //! [vector_of_objects_2]
+ QRangeModel model(std::ref(entries));
+ QListView listView;
+ listView.setModel(&model);
+ //! [vector_of_objects_2]
}
+
+} // namespace object
+
+using Entry = Object::Entry;
+//! [vector_of_multirole_objects_0]
+template <>
+struct QRangeModel::RowOptions<Entry>
+{
+ static constexpr auto rowCategory = QRangeModel::RowCategory::MultiRoleItem;
+};
+//! [vector_of_multirole_objects_0]
+
+namespace Object
+{
+
+void vector_of_multirole_objects()
+{
+ //! [vector_of_multirole_objects_1]
+ std::vector<std::shared_ptr<Entry>> entries = {
+ std::make_shared<Entry>(),
+ //! [vector_of_multirole_objects_1]
+ //! [vector_of_multirole_objects_2]
+ };
+
+ QRangeModel model(std::ref(entries));
+ //! [vector_of_multirole_objects_2]
+}
+
} // namespace object
namespace tree_protocol
@@ -538,7 +550,7 @@ void color_list_multi_role() {
void color_list_single_column() {
//! [color_gadget_single_column]
const QStringList colorNames = QColor::colorNames();
- QList<QRangeModel::SingleColumn<ColorEntry>> colors;
+ QList<std::tuple<ColorEntry>> colors;
// ...