Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qrangemodeladapter.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
// Qt-Security score:insignificant reason:default
4
5
#
include
<
QtCore
/
qrangemodeladapter
.
h
>
6
7
/*!
8
\class QRangeModelAdapter
9
\inmodule QtCore
10
\since 6.11
11
\preliminary
12
\ingroup model-view
13
\brief QRangeModelAdapter provides QAbstractItemModel-compliant access to any C++ range.
14
\compares equality
15
\compareswith equality Range
16
\endcompareswith
17
18
QRangeModelAdapter provides a type-safe and structure-aware C++ API around
19
a C++ range and a QRangeModel. Modifications made to the C++ range using
20
the adapter will inform clients of the QRangeModel about the changes. This
21
makes sure that item views are updated, caches are cleaned, and persistent
22
item indexes are invalidated and adapted correctly.
23
24
\section1 Construction and model ownership
25
26
QRangeModelAdapter has to be constructed from a C++ range. As with
27
QRangeModel, the range can be provided by lvalue or rvalue reference, as a
28
reference wrapper, and as a raw or smart pointer.
29
30
\snippet qrangemodeladapter/main.cpp construct
31
32
The exact type that gets constructed is deducted by the compiler based on
33
the constructor argument(s), and the differences between value categories
34
can result in different behavior. Therefore, you should not explicitly
35
specify the template parameters. C++ however does not allow class template
36
argument deduction for non-static class data members. To make
37
QRangeModelAdapter a data member of a class, use the following pattern:
38
39
\snippet qrangemodeladapter/main.cpp class-member-rvalue
40
41
This creates a QRangeModelAdapter operating on an unnamed (i.e. rvalue
42
reference) vector of Books. To make the adapter operate on a reference
43
wrapper to a list of Books, use this instead:
44
45
\snippet qrangemodeladapter/main.cpp class-member-refwrapper
46
47
Constructing the adapter from a range implicitly constructs a QRangeModel
48
instance from that same range. Use model() to get it, and pass it to Qt
49
Widgets or Qt Quick item views as usual.
50
51
\snippet qrangemodeladapter/main.cpp use-model
52
53
The adapter owns the model. QRangeModelAdapter is a value type, so it can be
54
copied and moved. All copies share the same QRangeModel, which will be
55
destroyed when the last copy of the adapter is destroyed.
56
57
If the adapter was created from an lvalue or rvalue reference, then the
58
adapter and model will operate on a copy of the original range object.
59
Otherwise, modifications made through the adapter or model will be written
60
to the original range object. To access the updated range, use range():
61
62
\snippet qrangemodeladapter/main.cpp get-range
63
64
To replace the entire range data with data from another (compatible) range,
65
use the assign() function, or the assignment operator.
66
67
\snippet qrangemodeladapter/main.cpp assign
68
69
\section1 Accessing item data
70
71
The QRangeModelAdapter API provides type-safe read and write access to the
72
range that the model operates on. The adapter API is based on the typical
73
API for C++ containers and ranges, including iterators. To access
74
individual rows and items, use at(), the corresponding subscript
75
\l{QRangeModelAdapter::operator[]()}{operator[]}, or data().
76
Which overloads of those functions are available depends on the range for
77
which the adapter was constructed.
78
79
\section2 Reading item data as a QVariant
80
81
The data() function always returns a QVariant with the value stored at the
82
specified position and role. In a list, an item can be accessed by a single
83
integer value specifying the row:
84
85
\snippet qrangemodeladapter/main.cpp list-data
86
87
If the range is a table, then items are specified by row and column:
88
89
\snippet qrangemodeladapter/main.cpp table-data
90
91
If the range is a tree, then items are located using a path of rows, and a
92
single column value:
93
94
\snippet qrangemodeladapter/main.cpp tree-data
95
96
Using a single integer as the row provides access to the toplevel tree
97
items.
98
99
\snippet qrangemodeladapter/main.cpp multirole-data
100
101
If no role is specified, then the QVariant will hold the entire item at the
102
position. Use the \l{QVariant::fromValue()} template function to retrieve a
103
copy of the item.
104
105
\section2 Reading and writing using at()
106
107
That the data() function returns a QVariant makes it flexible, but removes
108
type safety. For ranges where all items are of the same type, the at()
109
function provides a type-safe alternative that is more compatible with
110
regular C++ containers. As with data(), at() overloads exist to access an
111
item at a row for lists, at a row/column pair for table, and a path/column
112
pair for trees. However, at() always returns the whole item at the
113
specified position; it is not possible to read individual role values of
114
an item.
115
116
As expected from a C++ container API, the const overloads of at() (and the
117
corresponding subscript \l{operator[]()}) provide immutable access to the
118
value, while the mutable overloads return a reference object that a new
119
value can be assigned to. Note that a QRangeModelAdapter operating on a
120
const range behaves in that respect like a const QRangeModelAdapter. The
121
mutable overloads are removed from the overload set, so the compiler will
122
always select the const version. Trying to call a function that modifies a
123
range will result in a compiler error, even if the adapter itself is
124
mutable:
125
126
\snippet qrangemodeladapter/main.cpp read-only
127
128
The returned reference objects are wrappers that convert implicitly to the
129
underlying type, have a \l{QRangeModelAdapter::DataReference::}{get()}
130
function to explicitly access the underlying value, and an
131
\l{QRangeModelAdapter::DataReference::}{operator->()} that provides direct
132
access to const member functions. However, to prevent accidental data
133
changes that would bypass the QAbstractItemModel notification protocol,
134
those reference objects prevent direct modifications of the items.
135
136
\note Accessing the reference object always makes a call to the model to get
137
a copy of the value. This can be expensive; for performance critical access
138
to data, store a copy.
139
140
\section3 Item access
141
142
If the range is represented as a list, then only the overloads taking a row
143
are available.
144
145
\snippet qrangemodeladapter/main.cpp list-access
146
147
The const overload returns the item at that row, while the mutable overload
148
returns a wrapper that implicitly converts to and from the value type of the
149
list.
150
151
\snippet qrangemodeladapter/main.cpp list-access-multirole
152
153
Assign a value to the wrapper to modify the data in the list. The model will
154
emit \l{QAbstractItemModel::}{dataChanged()} for all roles.
155
156
When using the mutable overloads, you can also access the item type's const
157
members using the overloaded arrow operator.
158
159
\snippet qrangemodeladapter/main.cpp list-access-multirole-member-access
160
161
It is not possible to access non-const members of the item. Such
162
modifications would bypass the adapter, which couldn't notify the model
163
about the changes. To modify the value stored in the model, make a copy,
164
modify the properties of the copy, and then write that copy back.
165
166
\snippet qrangemodeladapter/main.cpp list-access-multirole-write-back
167
168
This will make the model emit \l{QAbstractItemModel::}{dataChanged()} for
169
this item, and for all roles.
170
171
If the range is represented as a table, then you can access an individual
172
item by row and column, using the \l{at(int, int)}{at(row, column)}
173
overload. For trees, that overload gives access to top-level items, while
174
the \l{at(QSpan<const int>, int)}{at(path, column)} overload provides
175
access to items nested within the tree.
176
177
Accessing an individual item in a table or tree is equivalent to accessing
178
an item in a list.
179
180
\snippet qrangemodeladapter/main.cpp table-item-access
181
182
If the range doesn't store all columns using the same data type, then
183
\c{at(row,column)} returns a (reference wrapper with a) QVariant holding
184
the item.
185
186
\snippet qrangemodeladapter/main.cpp table-mixed-type-access
187
188
\section2 Accessing rows in tables and trees
189
190
For tables and trees, the overloads of at() and subscript \l{operator[]()}
191
without the column parameter provide access to the entire row. The value
192
returned by the const overloads will be a reference type that gives access
193
to the row data. If that row holds pointers, then that reference type will
194
be a view of the row, giving access to pointers to const items.
195
196
\section3 Table row access
197
198
The \l{at(int)} overload is still available, but it returns the entire table
199
row. This makes it possible to work with all the values in the row at once.
200
201
\snippet qrangemodeladapter/main.cpp table-row-const-access
202
203
As with items, the const overload provides direct access to the row type,
204
while the mutable overload returns a wrapper that acts as a reference to the
205
row. The wrapper provides access to const member functions using the
206
overloaded arrow operator. To modify the values, write a modified row type
207
back.
208
209
\snippet qrangemodeladapter/main.cpp table-row-access
210
211
When assigning a new value to the row, then the model emits the
212
\l{QAbstractItemModel::}{dataChanged()} signal for all items in the row,
213
and for all roles.
214
215
\note When using a row type with runtime sizes, such as a \c{std::vector} or
216
a QList, make sure that the new row has the correct size.
217
218
\section3 Tree row access
219
220
Rows in trees are specified by a sequence of integers, one entry for each
221
level in the tree. Note that in the following snippets, the Tree is a range
222
holding raw row pointers, and that the adapter is created with an rvalue
223
reference of that range. This gives the QRangeModel ownership over the row
224
data.
225
226
\snippet qrangemodeladapter/main.cpp tree-row-access
227
228
The overload of \l{at(int)}{at()} taking a single row value provides
229
access to the top-level rows, or items in the top-level rows.
230
231
\snippet qrangemodeladapter/main.cpp tree-item-access
232
233
The basic pattern for accessing rows and items in a tree is identical to
234
accessing rows and items in a table. However, the adapter will make sure
235
that the tree structure is maintained when modifying entire rows.
236
237
\snippet qrangemodeladapter/main.cpp tree-row-write
238
239
In this example, a new row object is created, and assigned to the first
240
child of the first top-level item.
241
242
\section1 Iterator API
243
244
Use begin() and end() to get iterators over the rows of the model, or use
245
ranged-for. If the range is a list of items, dereferencing the iterator
246
will give access to item data.
247
248
\snippet qrangemodeladapter/main.cpp ranged-for-const-list
249
250
As with the const and mutable overloads of at(), a mutable iterator will
251
dereference to a wrapper.
252
253
\snippet qrangemodeladapter/main.cpp ranged-for-mutable-list
254
255
Use the overloaded arrow operator to access const members of the item type,
256
and assign to the wrapper to replace the value.
257
258
It the range is a table or tree, then iterating over the model will give
259
access to the rows.
260
261
\snippet qrangemodeladapter/main.cpp ranged-for-const-table
262
263
Both the const and the mutable iterator will dereference to a wrapper type
264
for the row. This makes sure that we can consistently iterate over each
265
item in the row, even if the underlying row type is not a range (e.g. it
266
might be a tuple or gadget).
267
268
\snippet qrangemodeladapter/main.cpp ranged-for-const-table-items
269
270
When iterating over a mutable table we can overwrite the entire row.
271
272
\snippet qrangemodeladapter/main.cpp ranged-for-mutable-table
273
274
The model emits the \l{QAbstractItemModel::}{dataChanged()} signal for
275
all items in all row, and for all roles.
276
277
\snippet qrangemodeladapter/main.cpp ranged-for-mutable-table-items
278
279
Iterating over the mutable rows allows us to modify individual items.
280
281
When iterating over a tree, the row wrapper has two additional member
282
functions, hasChildren() and children(), that allow us to traverse the
283
entire tree using iterators.
284
285
\snippet qrangemodeladapter/main.cpp ranged-for-tree
286
287
The object returned by children() is a QRangeModelAdapter operating on
288
the same model as the callee, but all operations will use the source row
289
index as the parent index.
290
291
\sa QRangeModel
292
*/
293
294
/*!
295
\typedef QRangeModelAdapter::range_type
296
*/
297
298
/*!
299
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::QRangeModelAdapter(Range &&range, Protocol &&protocol)
300
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::QRangeModelAdapter(Range &&range)
301
302
Constructs a QRangeModelAdapter that operates on \a range. For tree ranges,
303
the optional \a protocol will be used for tree traversal.
304
305
See the \l{QRangeModel::}{QRangeModel} constructor documentation for details
306
on the requirements to \a Range, and how the value category of \a range
307
changes the interaction between adapter, model, and range.
308
309
\sa QRangeModel
310
*/
311
312
/*!
313
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::operator==(const QRangeModelAdapter &lhs, const QRangeModelAdapter &rhs)
314
315
\return whether \a lhs is equal to \a rhs. Two adapters are equal if they
316
both hold the same \l{model()}{model} instance.
317
*/
318
319
/*!
320
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::operator!=(const QRangeModelAdapter &lhs, const QRangeModelAdapter &rhs)
321
322
\return whether \a lhs is not equal to \a rhs. Two adapters are equal if
323
they both hold the same \l{model()}{model} instance.
324
*/
325
326
/*!
327
\fn template <typename Range, typename Protocol, typename Model> Model *QRangeModelAdapter<Range, Protocol, Model>::model() const
328
329
\return the QRangeModel instance created by this adapter.
330
331
\sa range(), at()
332
*/
333
334
/*!
335
\fn template <typename Range, typename Protocol, typename Model> const QRangeModelAdapter<Range, Protocol, Model>::range_type &QRangeModelAdapter<Range, Protocol, Model>::range() const
336
337
\return a const reference to the range that the model adapter operates on.
338
339
\sa assign(), at(), model()
340
*/
341
342
/*!
343
\fn template <typename Range, typename Protocol, typename Model> template <typename NewRange, QRangeModelAdapter<Range, Protocol, Model>::if_assignable_range<NewRange>> void QRangeModelAdapter<Range, Protocol, Model>::assign(NewRange &&newRange)
344
\fn template <typename Range, typename Protocol, typename Model> template <typename NewRange, QRangeModelAdapter<Range, Protocol, Model>::if_assignable_range<NewRange>, QRangeModelAdapter<Range, Protocol, Model>::unless_adapter<NewRange>> QRangeModelAdapter &QRangeModelAdapter<Range, Protocol, Model>::operator=(NewRange &&newRange)
345
346
Replaces the contents of the model with the rows in \a newRange, possibly
347
using move semantics.
348
349
This function makes the model() emit the \l{QAbstractItemModel::}{modelAboutToBeReset()}
350
and \l{QAbstractItemModel::}{modelReset()} signals.
351
352
\constraints \c Range is mutable, and \a newRange is of a type that can be
353
assigned to \c Range, but not a QRangeModelAdapter.
354
355
\sa range(), at(), model(), assign()
356
*/
357
358
/*!
359
\fn template <typename Range, typename Protocol, typename Model> template <typename Row, QRangeModelAdapter<Range, Protocol, Model>::if_assignable_range<std::initializer_list<Row>>> QRangeModelAdapter &QRangeModelAdapter<Range, Protocol, Model>::assign(std::initializer_list<Row> newRange)
360
\fn template <typename Range, typename Protocol, typename Model> template <typename Row, QRangeModelAdapter<Range, Protocol, Model>::if_assignable_range<std::initializer_list<Row>>> QRangeModelAdapter &QRangeModelAdapter<Range, Protocol, Model>::operator=(std::initializer_list<Row> newRange)
361
362
Replaces the contents of the model with the rows in \a newRange.
363
364
\constraints \c Range is mutable, and \a newRange can be assigned to \c Range.
365
366
\sa range(), at, model()
367
*/
368
369
/*!
370
\fn template <typename Range, typename Protocol, typename Model> template <typename InputIterator, typename Sentinel, typename I = Impl, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> void QRangeModelAdapter<Range, Protocol, Model>::assign(InputIterator first, Sentinel last)
371
372
Replaces the contents of the models with the rows in the range [\a first, \a last).
373
374
\sa range(), at, model()
375
*/
376
377
/*!
378
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>> QModelIndex QRangeModelAdapter<Range, Protocol, Model>::index(int row) const
379
\overload
380
381
Returns the QModelIndex for \a row.
382
383
\constraints \c Range is a one-dimensional list.
384
*/
385
386
/*!
387
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> QModelIndex QRangeModelAdapter<Range, Protocol, Model>::index(int row, int column) const
388
\overload
389
390
Returns the QModelIndex for the item at \a row, \a column.
391
392
\constraints \c Range is a table or tree.
393
*/
394
395
/*!
396
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> QModelIndex QRangeModelAdapter<Range, Protocol, Model>::index(QSpan<const int> path, int column) const
397
\overload
398
399
Returns the QModelIndex for the item at \a column for the row in the tree
400
specified by \a path.
401
402
\constraints \c Range is a tree.
403
*/
404
405
/*!
406
\fn template <typename Range, typename Protocol, typename Model> int QRangeModelAdapter<Range, Protocol, Model>::columnCount() const
407
408
\return the number of columns. This will be one if the \c Range represents a
409
list, otherwise this returns be the number of elements in each row.
410
*/
411
412
/*!
413
\fn template <typename Range, typename Protocol, typename Model> int QRangeModelAdapter<Range, Protocol, Model>::rowCount() const
414
\overload
415
416
\return the number of rows. If the \c Range represents a list or table, then
417
this is the number of rows. For trees, this is the number of top-level rows.
418
*/
419
420
/*!
421
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> int QRangeModelAdapter<Range, Protocol, Model>::rowCount(int row) const
422
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> int QRangeModelAdapter<Range, Protocol, Model>::rowCount(QSpan<const int> row) const
423
\overload
424
425
\return the number of rows under \a row.
426
\constraints \c Range is a tree.
427
*/
428
429
/*!
430
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> int QRangeModelAdapter<Range, Protocol, Model>::hasChildren(int row) const
431
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> int QRangeModelAdapter<Range, Protocol, Model>::hasChildren(QSpan<const int> row) const
432
\overload
433
434
\return whether there are any rows under \a row.
435
\constraints \c Range is a tree.
436
*/
437
438
/*!
439
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(int row) const
440
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(int row, int role) const
441
442
\return a QVariant holding the data stored under the given \a role for the
443
item at \a row, or an invalid QVariant if there is no item. If \a role is
444
not specified, then returns a QVariant holding the complete item.
445
446
\constraints \c Range is a list.
447
448
\sa setData(), at()
449
*/
450
451
/*!
452
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> bool QRangeModelAdapter<Range, Protocol, Model>::setData(int row, const QVariant &value, int role)
453
454
Sets the \a role data for the item at \a row to \a value.
455
456
Returns \c{true} if successful; otherwise returns \c{false}.
457
458
\constraints \c Range is a mutable list.
459
460
\sa data(), at()
461
*/
462
463
/*!
464
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(int row, int column) const
465
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(int row, int column, int role) const
466
467
\return a QVariant holding the data stored under the given \a role for the
468
item referred to by a \a row and \a column, or an invalid QVariant if there
469
is no data stored for that position or role. If \a role is not specified,
470
then returns a QVariant holding the complete item.
471
472
\constraints \c Range is a table or tree.
473
474
\sa setData(), at()
475
*/
476
477
/*!
478
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> bool QRangeModelAdapter<Range, Protocol, Model>::setData(int row, int column, const QVariant &value, int role)
479
480
Sets the \a role data for the item referred to by \a row and \a column to
481
\a value.
482
483
Returns \c{true} if successful; otherwise returns \c{false}.
484
485
\constraints \c Range is mutable, and not a list.
486
487
\sa data(), at()
488
*/
489
490
/*!
491
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(QSpan<const int> path, int column) const
492
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(QSpan<const int> path, int column, int role) const
493
494
\return a QVariant holding the data stored under the given \a role for the
495
item referred to by \a path and \a column, or an invalid QVariant if there
496
is no data stored for that position or role. If \a role is not specified,
497
then returns a QVariant holding the complete item.
498
499
\constraints \c Range is a tree.
500
501
\sa setData(), at()
502
*/
503
504
/*!
505
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> bool QRangeModelAdapter<Range, Protocol, Model>::setData(QSpan<const int> path, int column, const QVariant &value, int role)
506
507
Sets the \a role data for the item referred to by \a path and \a column to
508
\a value.
509
510
Returns \c{true} if successful; otherwise returns \c{false}.
511
512
\constraints \c Range is a mutable tree.
513
514
\sa data(), at()
515
*/
516
517
/*!
518
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row) const
519
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row) const
520
521
\return the value at \a row as the type stored in \c Range.
522
523
\constraints \c Range is a list.
524
*/
525
526
/*!
527
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row)
528
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_list<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row)
529
530
\return a \l{DataReference}{mutable reference} to the value stored in
531
\c Range.
532
533
//! [data-ref]
534
\note Modifications to the range will invalidate that reference. To modify
535
the reference, assign a new value to it. Unless the value stored in the
536
\c Range is a pointer, it is not possible to access individual members of
537
the stored value.
538
//! [data-ref]
539
540
\constraints \c Range is a mutable list.
541
*/
542
543
/*!
544
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::at(int row) const
545
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::operator[](int row) const
546
547
\return a constant reference to the row at \a row, as stored in \c Range.
548
549
\constraints \c Range is a table or tree.
550
*/
551
552
/*!
553
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_table<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row)
554
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_table<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row)
555
556
\return a \l{QRangeModelAdapter::RowReference}{reference wrapper} to the row
557
at \a row, as stored in \c Range.
558
559
\constraints \c Range is a mutable table, but not a tree.
560
*/
561
562
/*!
563
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row)
564
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row)
565
566
\return a \l{QRangeModelAdapter::RowReference}{reference wrapper} to the row
567
at \a row, as stored in \c Range.
568
569
//! [treerow-ref]
570
To modify the tree row, assign a new value to it. Assigning a new tree row
571
will set the parent the new tree row to be the parent of the old tree row.
572
However, neither the old nor the new tree row must have any child rows. To
573
access the tree row, dereferencing the wrapper using \c{operator*()}, or use
574
\c{operator->()} to access tree row members.
575
576
\note Modifications to the range will invalidate the wrapper.
577
//! [treerow-ref]
578
579
\constraints \c Range is a tree.
580
*/
581
582
/*!
583
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row, int column) const
584
\omit
585
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row, int column) const
586
\endomit
587
588
\return a copy of the value stored as the item specified by \a row and
589
\a column. If the item is a multi-role item, then this returns a copy of
590
the entire item. If the rows in the \c Range store different types at
591
different columns, then the return type will be a QVariant.
592
593
\constraints \c Range is a table or tree.
594
*/
595
596
/*!
597
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(int row, int column)
598
\omit
599
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::unless_list<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](int row, int column)
600
\endomit
601
602
\return a \l{DataReference}{mutable reference} to the value stored as the
603
item specified by \a row and \a column. If the item is a multi-role item,
604
then this will be a reference to the entire item.
605
606
\include qrangemodeladapter.qdoc data-ref
607
608
\constraints \c Range is a mutable table.
609
*/
610
611
/*!
612
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::at(QSpan<const int> path) const
613
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::operator[](QSpan<const int> path) const
614
615
\return a constant reference to the row specified by \a path, as stored in
616
\c Range.
617
618
\constraints \c Range is a tree.
619
*/
620
621
/*!
622
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(QSpan<const int> path)
623
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](QSpan<const int> path)
624
625
\return a \l{RowReference}{mutable wrapper} holding a reference to the tree
626
row specified by \a path.
627
628
\include qrangemodeladapter.qdoc treerow-ref
629
630
\constraints \c Range is a tree.
631
*/
632
633
/*!
634
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(QSpan<const int> path, int column) const
635
\omit
636
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](QSpan<const int> path, int column) const
637
\endomit
638
639
\return a copy of the value stored as the item specified by \a path and
640
\a column. If the item is a multi-role item, then this returns a copy of
641
the entire item. If the rows in the \c Range store different types at
642
different columns, then the return type will be a QVariant.
643
644
\constraints \c Range is a tree.
645
*/
646
647
/*!
648
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(QSpan<const int> path, int column)
649
\omit
650
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::operator[](QSpan<const int> path, int column)
651
\endomit
652
653
\return a \l{DataReference}{mutable reference} to the value stored as the
654
item specified by \a path and \a column. If the item is a multi-role item,
655
then this will be a reference to the entire item. If the rows in the \c
656
Range store different types at different columns, then the return type will
657
be a QVariant.
658
659
\include qrangemodeladapter.qdoc data-ref
660
661
\constraints \c Range is a mutable tree.
662
*/
663
664
/*!
665
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> bool QRangeModelAdapter<Range, Protocol, Model>::insertRow(int before)
666
\overload
667
668
Inserts a single empty row before the row at \a before, and returns whether
669
the insertion was successful.
670
//! [insert-row-appends]
671
If \a before is the same value as rowCount(), then the new row will be appended.
672
//! [insert-row-appends]
673
674
\constraints \c Range supports insertion of elements.
675
676
\sa insertRows(), removeRow(), insertColumn()
677
*/
678
679
/*!
680
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::insertRow(QSpan<const int> before)
681
\overload
682
683
Inserts a single empty row before the row at the path specified by \a before,
684
and returns whether the insertion was successful.
685
\include qrangemodeladapter.qdoc insert-row-appends
686
687
\constraints \c Range is a tree that supports insertion of elements.
688
689
\sa insertRows(), removeRow(), insertColumn()
690
*/
691
692
/*!
693
\fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_row<D>> bool QRangeModelAdapter<Range, Protocol, Model>::insertRow(int before, D &&data)
694
\overload
695
696
Inserts a single row constructed from \a data before the row at \a before,
697
and returns whether the insertion was successful.
698
\include qrangemodeladapter.qdoc insert-row-appends
699
700
\constraints \c Range supports insertion of elements, and if
701
a row can be constructed from \a data.
702
703
\sa insertRows(), removeRow(), insertColumn()
704
*/
705
706
/*!
707
\fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_row<D>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::insertRow(QSpan<const int> before, D &&data)
708
\overload
709
710
Inserts a single row constructed from \a data before the row at \a before,
711
and returns whether the insertion was successful.
712
\include qrangemodeladapter.qdoc insert-row-appends
713
714
\constraints \c Range is a tree that supports insertion of elements, and if
715
a row can be constructed from \a data.
716
717
\sa insertRows(), removeRow(), insertColumn()
718
*/
719
720
/*!
721
\fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_row_range<C>> bool QRangeModelAdapter<Range, Protocol, Model>::insertRows(int before, C &&data)
722
\overload
723
724
Inserts rows constructed from the elements in \a data before the row at
725
\a before, and returns whether the insertion was successful.
726
\include qrangemodeladapter.qdoc insert-row-appends
727
728
\constraints \c Range supports insertion of elements, and if
729
rows can be constructed from the elements in \a data.
730
731
\sa insertRow(), removeRows(), insertColumns()
732
*/
733
734
/*!
735
\fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_row_range<C>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::insertRows(QSpan<const int> before, C &&data)
736
\overload
737
738
Inserts rows constructed from the elements in \a data before the row at
739
\a before, and returns whether the insertion was successful.
740
\include qrangemodeladapter.qdoc insert-row-appends
741
742
\constraints \c Range is a tree that supports insertion of elements, and if
743
rows can be constructed from the elements in \a data.
744
745
\sa insertRow(), removeRows(), insertColumns()
746
*/
747
748
/*!
749
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> bool QRangeModelAdapter<Range, Protocol, Model>::removeRow(int row)
750
\overload
751
752
Removes the given \a row and returns whether the removal was successful.
753
754
\constraints \c Range supports the removal of elements.
755
756
\sa removeRows(), removeColumn(), insertRow()
757
*/
758
759
/*!
760
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::removeRow(QSpan<const int> path)
761
\overload
762
763
Removes the row at the given \a path, including all children of that row,
764
and returns whether the removal was successful.
765
766
\constraints \c Range is a tree that supports the removal of elements.
767
768
\sa removeRows(), removeColumn(), insertRow()
769
*/
770
771
/*!
772
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> bool QRangeModelAdapter<Range, Protocol, Model>::removeRows(int row, int count)
773
\overload
774
775
Removes \a count rows starting at \a row, and returns whether the removal
776
was successful.
777
778
\constraints \c Range supports the removal of elements.
779
780
\sa removeRow(), removeColumns(), insertRows()
781
*/
782
783
/*!
784
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::removeRows(QSpan<const int> path, int count)
785
\overload
786
787
Removes \a count rows starting at the row specified by \a path, and returns
788
whether the removal was successful.
789
790
\constraints \c Range is a tree that supports the removal of elements.
791
792
\sa removeRow(), removeColumns(), insertRows()
793
*/
794
795
/*!
796
\fn template <typename Range, typename Protocol, typename Model> template <typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>> bool QRangeModelAdapter<Range, Protocol, Model>::moveRow(int source, int destination)
797
\overload
798
799
Moves the row at \a source to the position at \a destination, and returns
800
whether the row was successfully moved.
801
802
\constraints \c Range supports moving of elements.
803
804
\sa insertRow(), removeRow(), moveColumn()
805
*/
806
807
/*!
808
\fn template <typename Range, typename Protocol, typename Model> template <typename I, typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::moveRow(QSpan<const int> source, QSpan<const int> destination)
809
\overload
810
811
Moves the tree branch at \a source to the position at \a destination, and
812
returns whether the branch was successfully moved.
813
814
\constraints \c Range is a tree that supports moving of elements.
815
816
\sa insertRow(), removeRow(), moveColumn()
817
*/
818
819
/*!
820
\fn template <typename Range, typename Protocol, typename Model> template <typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>> bool QRangeModelAdapter<Range, Protocol, Model>::moveRows(int source, int count, int destination)
821
\overload
822
823
Moves \a count rows starting at \a source to the position at \a destination,
824
and returns whether the rows were successfully moved.
825
826
\constraints \c Range supports moving of elements.
827
828
\sa insertRows(), removeRows(), moveColumns()
829
*/
830
831
/*!
832
\fn template <typename Range, typename Protocol, typename Model> template <typename I, typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::moveRows(QSpan<const int> source, int count, QSpan<const int> destination)
833
\overload
834
835
Moves \a count tree branches starting at \a source to the position at
836
\a destination, and returns whether the rows were successfully moved.
837
838
\constraints \c Range is a tree that supports moving of elements.
839
840
\sa insertRows(), removeRows(), moveColumns()
841
*/
842
843
/*!
844
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumn(int before)
845
\overload
846
847
Inserts a single empty column before the column specified by \a before into
848
all rows, and returns whether the insertion was successful.
849
//! [insert-column-appends]
850
If \a before is the same value as columnCount(), then the column will be
851
appended to each row.
852
//! [insert-column-appends]
853
854
\constraints \c Range has rows that support insertion of elements.
855
856
\sa removeColumn(), insertColumns(), insertRow()
857
*/
858
859
/*!
860
\fn template <typename Range, typename Protocol, typename Model> template <typename D, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_column_data<D>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumn(int before, D &&data)
861
\overload
862
863
Inserts a single column constructed from \a data before the column specified
864
by \a before into all rows, and returns whether the insertion was successful.
865
//! [insert-column-appends]
866
If \a before is the same value as columnCount(), then the column will be
867
appended to each row.
868
//! [insert-column-appends]
869
870
If \a data is a single value, then the new entry in all rows will be constructed
871
from that single value.
872
873
If \a data is a container, then the elements in that container will be used
874
sequentially to construct the column for each subsequent row. If there are
875
fewer elements in \a data than there are rows, then function wraps around
876
and starts again from the first element.
877
878
\code
879
\endcode
880
881
\constraints \c Range has rows that support insertion of elements, and the
882
elements can be constructed from the entries in \a data.
883
884
\sa removeColumn(), insertColumns(), insertRow()
885
*/
886
887
/*!
888
\fn template <typename Range, typename Protocol, typename Model> template <typename C, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertColumns<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_column_range<C>> bool QRangeModelAdapter<Range, Protocol, Model>::insertColumns(int before, C &&data)
889
890
Inserts columns constructed from the elements in \a data before the column
891
specified by \a before into all rows, and returns whether the insertion was
892
successful.
893
//! [insert-column-appends]
894
If \a before is the same value as columnCount(), then the column will be
895
appended to each row.
896
//! [insert-column-appends]
897
898
If the elements in \a data are values, then the new entries in all rows will
899
be constructed from those values.
900
901
If the elements in \a data are containers, then the entries in the outer
902
container will be used sequentially to construct the new entries for each
903
subsequent row. If there are fewer elements in \a data than there are rows,
904
then the function wraps around and starts again from the first element.
905
906
\code
907
\endcode
908
909
\constraints \c Range has rows that support insertion of elements, and the
910
elements can be constructed from the entries in \a data.
911
912
\sa removeColumns(), insertColumn(), insertRows()
913
*/
914
915
/*!
916
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveColumns<I>> bool QRangeModelAdapter<Range, Protocol, Model>::removeColumn(int column)
917
918
Removes the given \a column from each row, and returns whether the removal
919
was successful.
920
921
\constraints \c Range has rows that support removal of elements.
922
923
\sa insertColumn(), removeColumns(), removeRow()
924
*/
925
926
/*!
927
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveColumns<I>> bool QRangeModelAdapter<Range, Protocol, Model>::removeColumns(int column, int count)
928
929
Removes \a count columns starting by the given \a column from each row, and
930
returns whether the removal was successful.
931
932
\constraints \c Range has rows that support removal of elements.
933
934
\sa insertColumns(), removeColumn(), removeRow()
935
*/
936
937
/*!
938
\fn template <typename Range, typename Protocol, typename Model> template <typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>> bool QRangeModelAdapter<Range, Protocol, Model>::moveColumn(int from, int to)
939
940
Moves the column at \a from to the column at \a to, and returns whether the
941
column was successfully moved.
942
943
\constraints \c Range has rows that support moving of elements.
944
945
\sa insertColumn(), removeColumn(), moveColumns(), moveRow()
946
*/
947
948
/*!
949
\fn template <typename Range, typename Protocol, typename Model> template <typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>> bool QRangeModelAdapter<Range, Protocol, Model>::moveColumns(int from, int count, int to)
950
951
Moves \a count columns starting at \a from to the position at \a to, and
952
returns whether the columns were successfully moved.
953
954
\constraints \c Range has rows that support moving of elements.
955
956
\sa insertColumns(), removeColumns(), moveColumn(), moveRows()
957
*/
958
959
/*!
960
\fn template <typename Range, typename Protocol, typename Model> template <typename I, typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::moveColumn(QSpan<const int> source, int to)
961
\internal Not possible to create a tree from a row type that can rotate/splice?
962
*/
963
964
/*!
965
\fn template <typename Range, typename Protocol, typename Model> template <typename I, typename F, QRangeModelAdapter<Range, Protocol, Model>::if_canMoveItems<F>, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::moveColumns(QSpan<const int> source, int count, int to)
966
\internal Not possible to create a tree from a row type that can rotate/splice?
967
*/
968
969
/*!
970
\class QRangeModelAdapter::DataReference
971
\inmodule QtCore
972
\since 6.11
973
\preliminary
974
\ingroup model-view
975
\brief DataReference is a reference wrapper around an item in a QRangeModel.
976
977
Accessing an item in the model using the non-const overloads of at(),
978
subscript \l{QRangeModelAdapter::operator[]()}{operator[]}, or
979
dereferencing a non-const \l{QRangeModelAdapter::RowIterator}{iterator},
980
returns a DataReference wrapper around the item in the model.
981
982
Assigning to that reference wrapper changes the data in the model using
983
QAbstractItemModel API.
984
985
\code
986
adapter[0] = newValue;
987
\endcode
988
989
A const version of the value itself can be accessed using get() or
990
operator->().
991
992
\code
993
QRangeModelAdapter adapter(QList<Gadget>{ ~~~ });
994
auto value = adapter[0]->value();
995
// adapter[0]->setValue(); // not allowed - would not emit dataChanged()
996
\endcode
997
998
In contrast to \c{std::reference_wrapper}, assigning one DataReference to
999
another does not rebind the reference, but sets the value using copy-
1000
semantics.
1001
1002
\code
1003
adapter[0] = adapter[1]; // items at row 0 and row 1 now have the same value
1004
\endcode
1005
1006
\sa RowReference, ConstRowReference
1007
*/
1008
1009
/*!
1010
\typedef QRangeModelAdapter::DataReference::value_type
1011
1012
An alias for the type of the items stored in the underlying range.
1013
If different columns in the model hold different types, then this is an
1014
alias to QVariant.
1015
*/
1016
1017
/*!
1018
\typedef QRangeModelAdapter::DataReference::const_value_type
1019
1020
An alias for the const type of the items stored in the underlying range.
1021
If different columns in the model hold different types, then this is an
1022
alias to \c{const QVariant}.
1023
*/
1024
1025
/*!
1026
\typedef QRangeModelAdapter::DataReference::pointer
1027
1028
An alias for the pointer type returned by operator->().
1029
*/
1030
1031
/*!
1032
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::DataReference(const QModelIndex &index) noexcept
1033
1034
Constructs a DataReference wrapper for the item at \a index.
1035
*/
1036
1037
/*!
1038
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::DataReference(const DataReference &other)
1039
1040
Constructs a copy of \a other.
1041
*/
1042
1043
/*!
1044
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::DataReference(DataReference &&other)
1045
1046
Constructs a DataReference by moving from \a other.
1047
*/
1048
1049
/*!
1050
\fn template <typename Range, typename Protocol, typename Model> QDataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(const DataReference &other)
1051
1052
Assigns the item value referred to by \a other to the value referenced by this wrapper.
1053
*/
1054
1055
/*!
1056
\fn template <typename Range, typename Protocol, typename Model> DataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(DataReference &&other)
1057
1058
Moves the value reference by \a other into the value referenced by this wrapper.
1059
*/
1060
1061
/*!
1062
\fn template <typename Range, typename Protocol, typename Model> DataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(const value_type &value)
1063
1064
Assigns \a value to the underlying model item.
1065
*/
1066
1067
/*!
1068
\fn template <typename Range, typename Protocol, typename Model> DataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(value_type &&value)
1069
1070
Move-assigns \a value to the underlying model item.
1071
*/
1072
1073
/*!
1074
\fn template <typename Range, typename Protocol, typename Model> const_value_type QRangeModelAdapter<Range, Protocol, Model>::DataReference::get() const
1075
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator const_value_type() const
1076
\return the item value referred to by this DataReference as a const value.
1077
*/
1078
1079
/*!
1080
\fn template <typename Range, typename Protocol, typename Model> pointer QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator->() const
1081
\return a pointer to the value referred to by this DataReference.
1082
*/
1083
1084
/*!
1085
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::DataReference::isValid() const
1086
\return true if this DataReference refers to a valid model index.
1087
*/
1088
1089
/*!
1090
\class QRangeModelAdapter::RowReferenceBase
1091
\inmodule QtCore
1092
\since 6.11
1093
\preliminary
1094
\ingroup model-view
1095
\brief RowReferenceBase provides common API for RowReference and ConstRowReference.
1096
1097
For models that are tables or trees, accessing a row of an adapter using
1098
\l{QRangeModelAdapter::}{at()}, subscript \l{QRangeModelAdapter::operator[]()}
1099
{operator[]}, or dereferencing a RowIterator, returns a RowReference or
1100
ConstRowReference to the specified row.
1101
1102
\sa DataReference
1103
*/
1104
1105
/*!
1106
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> template <typename I = Impl, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::hasChildren() const
1107
1108
\return true if the referenced row has one or more child rows, otherwise false.
1109
1110
\constraints \c Range is a tree.
1111
*/
1112
1113
/*!
1114
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> template <typename I = Impl, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> auto QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::children() const
1115
1116
\return a QRangeModelAdapter operating on the same range and model as this adapter, and with
1117
this row as the root index.
1118
1119
\constraints \c Range is a tree.
1120
*/
1121
1122
/*!
1123
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::cbegin() const
1124
1125
\return a ConstColumnIterator pointing to the first column of this row.
1126
*/
1127
1128
/*!
1129
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::begin() const
1130
1131
\return a ConstColumnIterator pointing to the first column of this row.
1132
*/
1133
1134
/*!
1135
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::cend() const
1136
1137
\return a ConstColumnIterator pointing just after the last column of this row.
1138
*/
1139
1140
/*!
1141
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::end() const
1142
1143
\return a ConstColumnIterator pointing just after the last column of this row.
1144
*/
1145
1146
/*!
1147
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> size_type QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::size() const
1148
1149
\return the number of columns in the model.
1150
1151
This returns the same value for all rows in the model.
1152
*/
1153
1154
/*!
1155
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> auto QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::at(int column) const
1156
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> auto QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::operator[](int column) const
1157
1158
\return a reference wrapper to the item at \a column of this row.
1159
1160
Depending on the data structure the adapter operates on, the returned value
1161
is a const reference wrapper, a pointer to a const object, or a QVariant.
1162
*/
1163
1164
/*!
1165
\class QRangeModelAdapter::RowReference
1166
\inmodule QtCore
1167
\since 6.11
1168
\preliminary
1169
\ingroup model-view
1170
\brief RowReference is a reference wrapper around a row in a QRangeModel.
1171
1172
For ranges that are tables or trees, accessing a row of a QRangeModelAdapter
1173
using the non-const overloads of \l{QRangeModelAdapter::}{at()} or subscript
1174
\l{QRangeModelAdapter::operator[]()}{operator[]}, or by dereferencing a
1175
RowIterator, returns a RowReference for the specified row.
1176
1177
\sa ConstRowReference, DataReference
1178
*/
1179
1180
/*!
1181
\typedef QRangeModelAdapter::RowReference::row_type
1182
1183
An alias for the type of the rows in the underlying range.
1184
*/
1185
1186
/*!
1187
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(const RowReference &other)
1188
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(const ConstRowReference &other)
1189
1190
Assigns the row referenced by \a other to the row referenced by this, emitting
1191
dataChanged for all items in the row.
1192
1193
//! [rowref-assign]
1194
If the model is a tree, and the referenced row has children, then those children
1195
are removed from the model. If the row referenced by \a other has children,
1196
then those children are inserted into the model.
1197
//! [rowref-assign]
1198
*/
1199
1200
/*!
1201
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(const row_type &other)
1202
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(row_type &&other)
1203
1204
Assigns the row \a other to the row referenced by this, emitting dataChanged
1205
for all items in the row.
1206
1207
\include qrangemodeladapter.qdoc rowref-assign
1208
*/
1209
1210
/*!
1211
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator ConstRowReference() const
1212
1213
\return a ConstRowReference referencing the same row as this.
1214
*/
1215
1216
/*!
1217
\fn template <typename Range, typename Protocol, typename Model> template <typename I = Impl, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> auto QRangeModelAdapter<Range, Protocol, Model>::RowReference::children()
1218
1219
\return a QRangeModelAdapter operating on the same range and model as this adapter, and with
1220
this row as the root index.
1221
1222
\constraints \c Range is a tree.
1223
*/
1224
1225
/*!
1226
\fn template <typename Range, typename Protocol, typename Model> ColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReference::begin()
1227
1228
\return a ColumnIterator pointing to the first column of this row.
1229
*/
1230
1231
/*!
1232
\fn template <typename Range, typename Protocol, typename Model> ColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReference::end()
1233
1234
\return a ColumnIterator pointing just after the last column of this row.
1235
*/
1236
1237
/*!
1238
\fn template <typename Range, typename Protocol, typename Model> auto QRangeModelAdapter<Range, Protocol, Model>::RowReference::at(int column)
1239
\fn template <typename Range, typename Protocol, typename Model> auto QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator[](int column)
1240
1241
\return a reference wrapper to the item at \a column of this row.
1242
*/
1243
1244
1245
/*!
1246
\class QRangeModelAdapter::ConstRowReference
1247
\inmodule QtCore
1248
\since 6.11
1249
\preliminary
1250
\ingroup model-view
1251
\brief ConstRowReference is a reference wrapper around a const row in a QRangeModel.
1252
1253
For ranges that are tables or trees, accessing a row of a QRangeModelAdapter
1254
using the const overloads of \l{QRangeModelAdapter::}{at()} or subscript
1255
\l{QRangeModelAdapter::operator[]()}{operator[]}, or by dereferencing a
1256
ConstRowIterator, returns a ConstRowReference for the specified row.
1257
1258
\sa RowReference, DataReference
1259
*/
1260
1261
/*!
1262
\class QRangeModelAdapter::RowIterator
1263
\inmodule QtCore
1264
\since 6.11
1265
\preliminary
1266
\ingroup model-view
1267
\brief Provides an STL-style non-const iterator over the rows of a model.
1268
1269
The iterator models \c{std::random_access_iterator}. If the model is a list,
1270
then dereferencing the iterator returns a DataReference wrapper for the
1271
pointed-to item in the model.
1272
1273
For tables and trees, dereferencing the iterator returns a RowReference for
1274
the pointed-to row.
1275
*/
1276
1277
/*!
1278
\class QRangeModelAdapter::ConstRowIterator
1279
\inmodule QtCore
1280
\since 6.11
1281
\preliminary
1282
\ingroup model-view
1283
\brief Provides an STL-style const iterator over the rows of a model.
1284
1285
The iterator models \c{std::random_access_iterator}. If the model is a list,
1286
then dereferencing the iterator returns the pointed-to item in the model.
1287
1288
For tables and trees, dereferencing the iterator returns a ConstRowReference
1289
for the pointed-to row.
1290
*/
1291
1292
/*!
1293
\class QRangeModelAdapter::ColumnIterator
1294
\inmodule QtCore
1295
\since 6.11
1296
\preliminary
1297
\ingroup model-view
1298
\brief Provides an STL-style non-const iterator over the columns in a model row.
1299
1300
The iterator models \c{std::random_access_iterator}. Dereferencing the iterator
1301
returns a DataReference wrapper for the value at the pointed-to item in
1302
the model.
1303
*/
1304
1305
/*!
1306
\class QRangeModelAdapter::ConstColumnIterator
1307
\inmodule QtCore
1308
\since 6.11
1309
\preliminary
1310
\ingroup model-view
1311
\brief Provides an STL-style non-const iterator over the columns in a model row.
1312
1313
The iterator models \c{std::random_access_iterator}. Dereferencing the iterator
1314
returns the const value at the pointed-to item in the model.
1315
*/
qtbase
src
corelib
itemmodels
qrangemodeladapter.qdoc
Generated on
for Qt by
1.16.1