Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
Don't use standard algorithms that reorder elements with the iterators.
286
Such algorithms would reorder the rows by writing the data of each row, so
287
the model would emit \l{QAbstractItemModel::}{dataChanged()} for each row,
288
and persistent model indexes would not follow the moved items. The
289
wrappers that the iterators dereference to can't be swapped, so
290
algorithms that reorder elements by swapping them, such as
291
\c{std::sort()}, \c{std::reverse()}, or \c{std::rotate()}, don't compile.
292
Algorithms that reorder elements only by assigning values, such as the
293
heap algorithms, \c{std::unique()}, or \c{std::remove_if()}, might
294
compile, but have the same problems.
295
Use sort() to sort the rows, and moveRows() to move rows.
296
297
\snippet qrangemodeladapter/main.cpp ranged-for-tree
298
299
The object returned by children() is a QRangeModelAdapter operating on
300
the same model as the callee, but all operations will use the source row
301
index as the parent index.
302
303
\sa QRangeModel
304
*/
305
306
/*!
307
\typedef QRangeModelAdapter::range_type
308
*/
309
310
/*!
311
\typedef QRangeModelAdapter::iterator
312
\since 6.13
313
314
Synonym for \l{QRangeModelAdapter::}{RowIterator}, provided for
315
STL compatibility.
316
317
//! [random-access-iterator]
318
The iterators of the adapter provide random-access semantics, even if the
319
iterators of \c Range don't, as is the case for \c{std::list}. They refer
320
to rows by row number, so moving an iterator with operators such as
321
\c{+}, \c{+=}, or \c{-}, and computing the distance between two
322
iterators, take constant time. If \c Range doesn't provide random access,
323
then accessing the row, by dereferencing the iterator or with
324
\c{operator[]()}, takes linear time.
325
//! [random-access-iterator]
326
*/
327
328
/*!
329
\typedef QRangeModelAdapter::const_iterator
330
\since 6.13
331
332
Synonym for \l{QRangeModelAdapter::}{ConstRowIterator}, provided for
333
STL compatibility.
334
335
\include qrangemodeladapter.qdoc random-access-iterator
336
*/
337
338
/*!
339
\typedef QRangeModelAdapter::reverse_iterator
340
\since 6.13
341
342
The \c{std::reverse_iterator} for \l{QRangeModelAdapter::}{iterator},
343
provided for STL compatibility.
344
345
\sa rbegin(), rend()
346
*/
347
348
/*!
349
\typedef QRangeModelAdapter::const_reverse_iterator
350
\since 6.13
351
352
The \c{std::reverse_iterator} for \l{QRangeModelAdapter::}{const_iterator},
353
provided for STL compatibility.
354
355
\sa crbegin(), crend()
356
*/
357
358
/*!
359
\typedef QRangeModelAdapter::value_type
360
\since 6.13
361
362
The type of the rows stored in \c Range, without any \c const qualification.
363
For a list, this is the type of the items in the list. For tables and trees,
364
this is the type of the row.
365
366
Provided for STL compatibility.
367
*/
368
369
/*!
370
\typedef QRangeModelAdapter::reference
371
\since 6.13
372
373
The type returned when dereferencing an \l{QRangeModelAdapter::}{iterator}.
374
For a list, this is a \l{QRangeModelAdapter::}{DataReference}; for tables
375
and trees, this is a \l{QRangeModelAdapter::}{RowReference}.
376
377
Provided for STL compatibility.
378
*/
379
380
/*!
381
\typedef QRangeModelAdapter::const_reference
382
\since 6.13
383
384
The type returned when dereferencing a \l{QRangeModelAdapter::}{const_iterator}.
385
For a list, this is the const item type; for tables and trees, this is a
386
\l{QRangeModelAdapter::}{ConstRowReference}.
387
388
Provided for STL compatibility.
389
*/
390
391
/*!
392
\typedef QRangeModelAdapter::size_type
393
\since 6.13
394
395
Typedef for \c int. Provided for STL compatibility.
396
*/
397
398
/*!
399
\typedef QRangeModelAdapter::difference_type
400
\since 6.13
401
402
Typedef for \c int. Provided for STL compatibility.
403
*/
404
405
/*!
406
\fn template <typename Range, typename Protocol, typename Model> template <typename R, typename P, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_model_params<R, P>> QRangeModelAdapter<Range, Protocol, Model>::QRangeModelAdapter(R &&range, P &&protocol)
407
\fn template <typename Range, typename Protocol, typename Model> template <typename R, typename P, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_model_params<R, P>, QRangeModelAdapter<Range, Protocol, Model>::unless_adapter<R>> QRangeModelAdapter<Range, Protocol, Model>::QRangeModelAdapter(R &&range)
408
409
Constructs a QRangeModelAdapter that operates on \a range. For tree ranges,
410
the optional \a protocol will be used for tree traversal.
411
412
See the \l{QRangeModel::}{QRangeModel} constructor documentation for details
413
on the requirements to \a Range, and how the value category of \a range
414
changes the interaction between adapter, model, and range.
415
416
\sa QRangeModel
417
*/
418
419
/*!
420
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::operator==(const QRangeModelAdapter &lhs, const QRangeModelAdapter &rhs)
421
422
\return whether \a lhs is equal to \a rhs. Two adapters are equal if they
423
both hold the same \l{model()}{model} instance.
424
*/
425
426
/*!
427
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::operator!=(const QRangeModelAdapter &lhs, const QRangeModelAdapter &rhs)
428
429
\return whether \a lhs is not equal to \a rhs. Two adapters are equal if
430
they both hold the same \l{model()}{model} instance.
431
*/
432
433
/*!
434
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canSort<I>> void QRangeModelAdapter<Range, Protocol, Model>::sort(int column, Qt::SortOrder order)
435
\since 6.13
436
437
Sorts the rows of the model by the values in \a column, in the given
438
\a order. This is the same as calling \l{QRangeModel::sort()}{sort()} on
439
the model(), which compares the data for the
440
\l{QRangeModel::}{sortRole} of the items, using the
441
\l{QRangeModel::}{sortCollator} if set, and keeps the relative order of
442
rows that compare equal. If the model is a tree, then the children of all
443
rows are sorted as well; this is also the case if this adapter operates on
444
the children of a tree row.
445
446
The model() emits the \l{QAbstractItemModel::}{layoutAboutToBeChanged()}
447
and \l{QAbstractItemModel::}{layoutChanged()} signals, and updates the
448
persistent model indexes so that they keep referring to the same items.
449
450
Don't use standard algorithms such as \c{std::sort()} to sort the rows
451
through the \l{Iterator API}{iterators} of the adapter.
452
453
\constraints \c Range is mutable, and its rows can be swapped.
454
455
\sa QRangeModel::sort()
456
*/
457
458
/*!
459
\fn template <typename Range, typename Protocol, typename Model> Model *QRangeModelAdapter<Range, Protocol, Model>::model() const
460
461
\return the QRangeModel instance created by this adapter.
462
463
\sa range(), at()
464
*/
465
466
/*!
467
\fn template <typename Range, typename Protocol, typename Model> const QRangeModelAdapter<Range, Protocol, Model>::range_type &QRangeModelAdapter<Range, Protocol, Model>::range() const
468
469
\return a const reference to the range that the model adapter operates on.
470
471
\sa assign(), at(), model()
472
*/
473
474
/*!
475
\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)
476
\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)
477
478
Replaces the contents of the model with the rows in \a newRange, possibly
479
using move semantics.
480
481
This function makes the model() emit the \l{QAbstractItemModel::}{modelAboutToBeReset()}
482
and \l{QAbstractItemModel::}{modelReset()} signals.
483
484
\constraints \c Range is mutable, and \a newRange is of a type that can be
485
assigned to \c Range, but not a QRangeModelAdapter.
486
487
\sa range(), at(), model(), assign()
488
*/
489
490
/*!
491
\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)
492
\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)
493
494
Replaces the contents of the model with the rows in \a newRange.
495
496
\constraints \c Range is mutable, and \a newRange can be assigned to \c Range.
497
498
\sa range(), at, model()
499
*/
500
501
/*!
502
\fn template <typename Range, typename Protocol, typename Model> template <typename InputIterator, typename Sentinel, typename I = Impl, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_row_iterator<InputIterator>> void QRangeModelAdapter<Range, Protocol, Model>::assign(InputIterator first, Sentinel last)
503
504
Replaces the contents of the models with the rows in the range [\a first, \a last).
505
506
\constraints \c Range is mutable, and \c InputIterator is at least a
507
forward iterator that dereferences to a type that is convertible to a row.
508
509
\sa range(), at, model()
510
*/
511
512
/*!
513
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canAssignCopies<I>> void QRangeModelAdapter<Range, Protocol, Model>::assign(size_type count, const value_type &value)
514
\since 6.13
515
\overload
516
517
Replaces the contents of the model with \a count copies of \a value.
518
519
If the adapter operates on the entire model, then the model() emits the
520
\l{QAbstractItemModel::}{modelAboutToBeReset()} and
521
\l{QAbstractItemModel::}{modelReset()} signals. If the adapter operates
522
on the children of a tree row, then the old rows are removed and the new
523
rows are inserted, with the corresponding signals.
524
525
\constraints \c Range is mutable, and has either an \c{assign(count, value)}
526
member function, or \c{insert(pos, count, value)} and \c{erase(first, last)}
527
member functions; and the row type is copyable, but not a raw pointer.
528
529
\sa resize(), range(), model()
530
*/
531
532
/*!
533
\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 listRow) const
534
\overload
535
536
Returns the QModelIndex for \a listRow.
537
538
\constraints \c Range is a one-dimensional list.
539
*/
540
541
/*!
542
\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 tableRow, int column) const
543
\overload
544
545
Returns the QModelIndex for the item at \a tableRow, \a column.
546
547
\constraints \c Range is a table or tree.
548
*/
549
550
/*!
551
\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
552
\overload
553
554
Returns the QModelIndex for the item at \a column for the row in the tree
555
specified by \a path.
556
557
\constraints \c Range is a tree.
558
*/
559
560
/*!
561
\fn template <typename Range, typename Protocol, typename Model> int QRangeModelAdapter<Range, Protocol, Model>::columnCount() const
562
563
\return the number of columns. This will be one if the \c Range represents a
564
list, otherwise this returns be the number of elements in each row.
565
*/
566
567
/*!
568
\fn template <typename Range, typename Protocol, typename Model> int QRangeModelAdapter<Range, Protocol, Model>::rowCount() const
569
\overload
570
571
\return the number of rows. If the \c Range represents a list or table, then
572
this is the number of rows. For trees, this is the number of top-level rows.
573
*/
574
575
/*!
576
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::isEmpty() const
577
\since 6.13
578
579
\return whether the model has no rows. If the \c Range represents a tree,
580
then this returns whether there are no top-level rows. If the adapter
581
operates on the children of a tree row, then this returns whether that row
582
has no children.
583
584
\sa rowCount()
585
*/
586
587
/*!
588
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::empty() const
589
\since 6.13
590
591
This function is provided for STL compatibility. It is equivalent to
592
isEmpty(), returning \c true if the model has no rows; otherwise it
593
returns \c false.
594
595
\sa isEmpty(), rowCount()
596
*/
597
598
/*!
599
\fn template <typename Range, typename Protocol, typename Model> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::front() const
600
\since 6.13
601
602
\return the first row. This is the same as calling \c{at(0)}.
603
604
\include qrangemodeladapter.qdoc front-back-empty
605
606
\sa back(), at(), isEmpty()
607
*/
608
609
/*!
610
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::front()
611
\since 6.13
612
\overload
613
614
\return a reference wrapper for the first row. This is the same as calling
615
\c{at(0)}.
616
617
//! [front-back-empty]
618
\note The model must not be empty.
619
//! [front-back-empty]
620
621
\constraints \c Range is mutable.
622
623
\sa back(), at(), isEmpty()
624
*/
625
626
/*!
627
\fn template <typename Range, typename Protocol, typename Model> decltype(auto) QRangeModelAdapter<Range, Protocol, Model>::back() const
628
\since 6.13
629
630
\return the last row. This is the same as calling \c{at(size() - 1)}.
631
632
\include qrangemodeladapter.qdoc front-back-empty
633
634
\sa front(), at(), isEmpty()
635
*/
636
637
/*!
638
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::back()
639
\since 6.13
640
\overload
641
642
\return a reference wrapper for the last row. This is the same as calling
643
\c{at(size() - 1)}.
644
645
\include qrangemodeladapter.qdoc front-back-empty
646
647
\constraints \c Range is mutable.
648
649
\sa front(), at(), isEmpty()
650
*/
651
652
/*!
653
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::const_reverse_iterator QRangeModelAdapter<Range, Protocol, Model>::crbegin() const
654
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::const_reverse_iterator QRangeModelAdapter<Range, Protocol, Model>::rbegin() const
655
\since 6.13
656
657
\return a const reverse iterator pointing to the last row, i.e. the first
658
row when iterating in reverse order.
659
660
\sa crend(), {Iterator API}
661
*/
662
663
/*!
664
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::const_reverse_iterator QRangeModelAdapter<Range, Protocol, Model>::crend() const
665
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::const_reverse_iterator QRangeModelAdapter<Range, Protocol, Model>::rend() const
666
\since 6.13
667
668
\return a const reverse iterator pointing to the position before the first
669
row, i.e. past the last row when iterating in reverse order.
670
671
\sa crbegin(), {Iterator API}
672
*/
673
674
/*!
675
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> QRangeModelAdapter<Range, Protocol, Model>::reverse_iterator QRangeModelAdapter<Range, Protocol, Model>::rbegin()
676
\since 6.13
677
\overload
678
679
\return a reverse iterator pointing to the last row, i.e. the first row
680
when iterating in reverse order.
681
682
\constraints \c Range is mutable.
683
684
\sa rend(), {Iterator API}
685
*/
686
687
/*!
688
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> QRangeModelAdapter<Range, Protocol, Model>::reverse_iterator QRangeModelAdapter<Range, Protocol, Model>::rend()
689
\since 6.13
690
\overload
691
692
\return a reverse iterator pointing to the position before the first row,
693
i.e. past the last row when iterating in reverse order.
694
695
\constraints \c Range is mutable.
696
697
\sa rbegin(), {Iterator API}
698
*/
699
700
/*!
701
\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
702
\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
703
\overload
704
705
\return the number of rows under \a row.
706
\constraints \c Range is a tree.
707
*/
708
709
/*!
710
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> int QRangeModelAdapter<Range, Protocol, Model>::rowCount(const QModelIndex &index) const
711
\overload
712
\since 6.12
713
714
\return the number of rows under \a index.
715
\constraints \c Range is a tree.
716
*/
717
718
/*!
719
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::hasChildren(int row) const
720
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::hasChildren(QSpan<const int> row) const
721
\overload
722
723
\return whether there are any rows under \a row.
724
\constraints \c Range is a tree.
725
*/
726
727
/*!
728
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_tree<I>> bool QRangeModelAdapter<Range, Protocol, Model>::hasChildren(const QModelIndex &index) const
729
\overload
730
\since 6.12
731
732
\return whether there are any rows under \a index.
733
\constraints \c Range is a tree.
734
*/
735
736
/*!
737
\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 listRow) const
738
\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 listRow, int role) const
739
740
\return a QVariant holding the data stored under the given \a role for the
741
item at \a listRow, or an invalid QVariant if there is no item. If \a role is
742
not specified, then returns a QVariant holding the complete item.
743
744
\constraints \c Range is a list.
745
746
\sa setData(), at()
747
*/
748
749
/*!
750
\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 listRow, const QVariant &value, int role)
751
752
Sets the \a role data for the item at \a listRow to \a value.
753
754
Returns \c{true} if successful; otherwise returns \c{false}.
755
756
\constraints \c Range is a mutable list.
757
758
\sa data(), at()
759
*/
760
761
/*!
762
\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 tableRow, int column) const
763
\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 tableRow, int column, int role) const
764
765
\return a QVariant holding the data stored under the given \a role for the
766
item referred to by a \a tableRow and \a column, or an invalid QVariant if there
767
is no data stored for that position or role. If \a role is not specified,
768
then returns a QVariant holding the complete item.
769
770
\constraints \c Range is a table or tree.
771
772
\sa setData(), at()
773
*/
774
775
/*!
776
\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 tableRow, int column, const QVariant &value, int role)
777
778
Sets the \a role data for the item referred to by \a tableRow and \a column to
779
\a value.
780
781
Returns \c{true} if successful; otherwise returns \c{false}.
782
783
\constraints \c Range is mutable, and not a list.
784
785
\sa data(), at()
786
*/
787
788
/*!
789
\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
790
\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
791
792
\return a QVariant holding the data stored under the given \a role for the
793
item referred to by \a path and \a column, or an invalid QVariant if there
794
is no data stored for that position or role. If \a role is not specified,
795
then returns a QVariant holding the complete item.
796
797
\constraints \c Range is a tree.
798
799
\sa setData(), at()
800
*/
801
802
/*!
803
\fn template <typename Range, typename Protocol, typename Model> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(const QModelIndex &index) const
804
\fn template <typename Range, typename Protocol, typename Model> QVariant QRangeModelAdapter<Range, Protocol, Model>::data(const QModelIndex &index, int role) const
805
\overload
806
\since 6.12
807
808
\return a QVariant holding the data stored under the given \a role for the
809
item at \a index, or an invalid QVariant if there is no data stored for
810
that position or role. If \a role is not specified, then returns a QVariant
811
holding the complete item.
812
813
\sa setData(), at()
814
*/
815
816
/*!
817
\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)
818
819
Sets the \a role data for the item referred to by \a path and \a column to
820
\a value.
821
822
Returns \c{true} if successful; otherwise returns \c{false}.
823
824
\constraints \c Range is a mutable tree.
825
826
\sa data(), at()
827
*/
828
829
/*!
830
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> bool QRangeModelAdapter<Range, Protocol, Model>::setData(const QModelIndex &index, const QVariant &value, int role)
831
\overload
832
\since 6.12
833
834
Sets the \a role data for the item at \a index to \a value.
835
836
Returns \c{true} if successful; otherwise returns \c{false}.
837
838
\constraints \c Range is not read-only.
839
840
\sa data(), at()
841
*/
842
843
/*!
844
\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 listRow) const
845
\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 listRow) const
846
847
\return the value at \a listRow as the type stored in \c Range.
848
849
\constraints \c Range is a list.
850
*/
851
852
/*!
853
\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 listRow)
854
\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 listRow)
855
856
\return a \l{DataReference}{mutable reference} to the value stored in
857
\c Range.
858
859
//! [data-ref]
860
\note Modifications to the range will invalidate that reference. To modify
861
the reference, assign a new value to it. Unless the value stored in the
862
\c Range is a pointer, it is not possible to access individual members of
863
the stored value.
864
//! [data-ref]
865
866
\constraints \c Range is a mutable list.
867
*/
868
869
/*!
870
\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 tableRow) const
871
\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 tableRow) const
872
873
\return a constant reference to the row at \a tableRow, as stored in \c Range.
874
875
\constraints \c Range is a table or tree.
876
*/
877
878
/*!
879
\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 tableRow)
880
\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 tableRow)
881
882
\return a \l{QRangeModelAdapter::RowReference}{reference wrapper} to the row
883
at \a tableRow, as stored in \c Range.
884
885
\constraints \c Range is a mutable table, but not a tree.
886
*/
887
888
/*!
889
\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 treeRow)
890
\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 treeRow)
891
892
\return a \l{QRangeModelAdapter::RowReference}{reference wrapper} to the row
893
at \a treeRow, as stored in \c Range.
894
895
//! [treerow-ref]
896
To modify the tree row, assign a new value to it. Assigning a new tree row
897
will set the parent the new tree row to be the parent of the old tree row.
898
However, neither the old nor the new tree row must have any child rows. To
899
access the tree row, dereferencing the wrapper using \c{operator*()}, or use
900
\c{operator->()} to access tree row members.
901
902
\note Modifications to the range will invalidate the wrapper.
903
//! [treerow-ref]
904
905
\constraints \c Range is a tree.
906
*/
907
908
/*!
909
\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 tableRow, int column) const
910
\omit
911
\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 tableRow, int column) const
912
\endomit
913
914
\return a copy of the value stored as the item specified by \a tableRow and
915
\a column. If the item is a multi-role item, then this returns a copy of
916
the entire item. If the rows in the \c Range store different types at
917
different columns, then the return type will be a QVariant.
918
919
\constraints \c Range is a table or tree.
920
*/
921
922
/*!
923
\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 tableRow, int column)
924
\omit
925
\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 tableRow, int column)
926
\endomit
927
928
\return a \l{DataReference}{mutable reference} to the value stored as the
929
item specified by \a tableRow and \a column. If the item is a multi-role item,
930
then this will be a reference to the entire item.
931
932
\include qrangemodeladapter.qdoc data-ref
933
934
\constraints \c Range is a mutable table.
935
*/
936
937
/*!
938
\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
939
\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
940
941
\return a constant reference to the row specified by \a path, as stored in
942
\c Range.
943
944
\constraints \c Range is a tree.
945
*/
946
947
/*!
948
\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)
949
\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)
950
951
\return a \l{RowReference}{mutable wrapper} holding a reference to the tree
952
row specified by \a path.
953
954
\include qrangemodeladapter.qdoc treerow-ref
955
956
\constraints \c Range is a tree.
957
*/
958
959
/*!
960
\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
961
\omit
962
\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
963
\endomit
964
965
\return a copy of the value stored as the item specified by \a path and
966
\a column. If the item is a multi-role item, then this returns a copy of
967
the entire item. If the rows in the \c Range store different types at
968
different columns, then the return type will be a QVariant.
969
970
\constraints \c Range is a tree.
971
*/
972
973
/*!
974
\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)
975
\omit
976
\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)
977
\endomit
978
979
\return a \l{DataReference}{mutable reference} to the value stored as the
980
item specified by \a path and \a column. If the item is a multi-role item,
981
then this will be a reference to the entire item. If the rows in the \c
982
Range store different types at different columns, then the return type will
983
be a QVariant.
984
985
\include qrangemodeladapter.qdoc data-ref
986
987
\constraints \c Range is a mutable tree.
988
*/
989
990
/*!
991
\fn template <typename Range, typename Protocol, typename Model> auto QRangeModelAdapter<Range, Protocol, Model>::at(const QModelIndex &index) const
992
\overload
993
\since 6.12
994
995
\return a copy of the value stored as the item at \a index. If the item is
996
a multi-role item, then this returns a copy of the entire item. If the rows
997
in the \c Range store different types at different columns, then the return
998
type will be a QVariant.
999
*/
1000
1001
/*!
1002
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_writable<I>> auto QRangeModelAdapter<Range, Protocol, Model>::at(const QModelIndex &index)
1003
\overload
1004
\since 6.12
1005
1006
\return a \l{DataReference}{mutable reference} to the value stored as the
1007
item at \a index. If the item is a multi-role item, then this will be a
1008
reference to the entire item. If the rows in the \c Range store different
1009
types at different columns, then the return type will be a QVariant.
1010
1011
\include qrangemodeladapter.qdoc data-ref
1012
1013
\constraints \c Range is not read-only.
1014
*/
1015
1016
/*!
1017
\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)
1018
\overload
1019
1020
Inserts a single empty row before the row at \a before, and returns whether
1021
the insertion was successful.
1022
//! [insert-row-appends]
1023
If \a before is the same value as rowCount(), then the new row will be appended.
1024
//! [insert-row-appends]
1025
1026
\constraints \c Range supports insertion of elements.
1027
1028
\sa insertRows(), removeRow(), insertColumn()
1029
*/
1030
1031
/*!
1032
\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)
1033
\overload
1034
1035
Inserts a single empty row before the row at the path specified by \a before,
1036
and returns whether the insertion was successful.
1037
\include qrangemodeladapter.qdoc insert-row-appends
1038
1039
\constraints \c Range is a tree that supports insertion of elements.
1040
1041
\sa insertRows(), removeRow(), insertColumn()
1042
*/
1043
1044
/*!
1045
\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(int before, const QModelIndex &parent)
1046
\overload
1047
1048
Inserts a single empty row before the row at \a before in the specified
1049
\a parent, and returns whether the insertion was successful.
1050
\include qrangemodeladapter.qdoc insert-row-appends
1051
1052
\constraints \c Range is a tree that supports insertion of elements.
1053
1054
\sa insertRows(), removeRow(), insertColumn()
1055
*/
1056
1057
/*!
1058
\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)
1059
\overload
1060
1061
Inserts a single row constructed from \a data before the row at \a before,
1062
and returns whether the insertion was successful.
1063
\include qrangemodeladapter.qdoc insert-row-appends
1064
1065
\constraints \c Range supports insertion of elements, and if
1066
a row can be constructed from \a data.
1067
1068
\sa insertRows(), removeRow(), insertColumn()
1069
*/
1070
1071
/*!
1072
\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)
1073
\overload
1074
1075
Inserts a single row constructed from \a data before the row at \a before,
1076
and returns whether the insertion was successful.
1077
\include qrangemodeladapter.qdoc insert-row-appends
1078
1079
\constraints \c Range is a tree that supports insertion of elements, and if
1080
a row can be constructed from \a data.
1081
1082
\sa insertRows(), removeRow(), insertColumn()
1083
*/
1084
1085
/*!
1086
\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(int before, const QModelIndex &parent, D &&data)
1087
\overload
1088
1089
Inserts a single row constructed from \a data before the row at \a before
1090
in the specified \a parent, and returns whether the insertion was successful.
1091
\include qrangemodeladapter.qdoc insert-row-appends
1092
1093
\constraints \c Range is a tree that supports insertion of elements, and if
1094
a row can be constructed from \a data.
1095
1096
\sa insertRows(), removeRow(), insertColumn()
1097
*/
1098
1099
/*!
1100
\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)
1101
\overload
1102
1103
Inserts rows constructed from the elements in \a data before the row at
1104
\a before, and returns whether the insertion was successful.
1105
\include qrangemodeladapter.qdoc insert-row-appends
1106
1107
\constraints \c Range supports insertion of elements, and if
1108
rows can be constructed from the elements in \a data.
1109
1110
\sa insertRow(), removeRows(), insertColumns()
1111
*/
1112
1113
/*!
1114
\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)
1115
\overload
1116
1117
Inserts rows constructed from the elements in \a data before the row at
1118
\a before, and returns whether the insertion was successful.
1119
\include qrangemodeladapter.qdoc insert-row-appends
1120
1121
\constraints \c Range is a tree that supports insertion of elements, and if
1122
rows can be constructed from the elements in \a data.
1123
1124
\sa insertRow(), removeRows(), insertColumns()
1125
*/
1126
1127
/*!
1128
\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(int before, const QModelIndex &parent, C &&data)
1129
\overload
1130
1131
Inserts rows constructed from the elements in \a data before the row at
1132
\a before in the specified \a parent, and returns whether the insertion was
1133
successful.
1134
\include qrangemodeladapter.qdoc insert-row-appends
1135
1136
\constraints \c Range is a tree that supports insertion of elements, and if
1137
rows can be constructed from the elements in \a data.
1138
1139
\sa insertRow(), removeRows(), insertColumns()
1140
*/
1141
1142
/*!
1143
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::insert(const_iterator pos, const value_type &value)
1144
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::insert(const_iterator pos, value_type &&value)
1145
\since 6.13
1146
1147
Inserts \a value before the row at \a pos, and returns an iterator
1148
pointing to the inserted row. If \a pos is end(), then the row is appended.
1149
1150
//! [insert-at-iterator]
1151
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeInserted()}
1152
and \l{QAbstractItemModel::}{rowsInserted()} signals. If the insertion
1153
fails, then this function returns end().
1154
1155
\a pos must be a valid iterator into this adapter's rows. If the adapter
1156
operates on a tree, then the rows are inserted as siblings of the row at
1157
\a pos. To insert child rows, use the adapter returned by
1158
\l{QRangeModelAdapter::RowReference::}{children()}.
1159
1160
Iterators into the adapter refer to a row number, not to an element of
1161
\c Range, and the insertion doesn't invalidate them. However, after the
1162
insertion, an iterator to a row at or after \a pos refers to the row that
1163
now has that row number, which is a different element than before. This
1164
is also the case if \c Range is a \c{std::list}.
1165
//! [insert-at-iterator]
1166
1167
\constraints \c Range supports insertion of elements.
1168
1169
\sa insertRow()
1170
*/
1171
1172
/*!
1173
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertCopies<I>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::insert(const_iterator pos, size_type count, const value_type &value)
1174
\since 6.13
1175
\overload
1176
1177
Inserts \a count copies of \a value before the row at \a pos, and returns
1178
an iterator pointing to the first inserted row, or \a pos if \a count is 0.
1179
1180
\include qrangemodeladapter.qdoc insert-at-iterator
1181
1182
\constraints \c Range supports insertion of elements, and the row type is
1183
copyable, but not a raw pointer.
1184
1185
\sa insertRows()
1186
*/
1187
1188
/*!
1189
\fn template <typename Range, typename Protocol, typename Model> template <typename InputIterator, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_compatible_row_iterator<InputIterator>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::insert(const_iterator pos, InputIterator first, InputIterator last)
1190
\since 6.13
1191
\overload
1192
1193
Inserts the rows in the range [\a first, \a last) before the row at \a pos,
1194
and returns an iterator pointing to the first inserted row, or \a pos if the
1195
range is empty.
1196
1197
\include qrangemodeladapter.qdoc insert-at-iterator
1198
1199
\constraints \c Range supports insertion of elements, and \c InputIterator
1200
is a forward iterator that dereferences to a type convertible to the row
1201
type.
1202
1203
\sa insertRows()
1204
*/
1205
1206
/*!
1207
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::insert(const_iterator pos, std::initializer_list<value_type> values)
1208
\since 6.13
1209
\overload
1210
1211
Inserts the rows in \a values before the row at \a pos, and returns an
1212
iterator pointing to the first inserted row, or \a pos if \a values is
1213
empty.
1214
1215
\include qrangemodeladapter.qdoc insert-at-iterator
1216
1217
\constraints \c Range supports insertion of elements.
1218
1219
\sa insertRows()
1220
*/
1221
1222
/*!
1223
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::push_back(const value_type &value)
1224
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::push_back(value_type &&value)
1225
\since 6.13
1226
1227
Appends \a value as a new row. This is the same as calling
1228
\c{insert(cend(), value)}.
1229
1230
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeInserted()}
1231
and \l{QAbstractItemModel::}{rowsInserted()} signals. If the adapter
1232
operates on a tree, then the new row is appended to the level of the tree
1233
that the adapter operates on.
1234
1235
Provided for STL compatibility; for example, this makes it possible to use
1236
\c{std::back_inserter} with a QRangeModelAdapter.
1237
1238
\constraints \c Range supports insertion of elements.
1239
1240
\sa emplace_back(), insert(), insertRow()
1241
*/
1242
1243
/*!
1244
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::push_front(const value_type &value)
1245
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::push_front(value_type &&value)
1246
\since 6.13
1247
1248
Prepends \a value as a new row. This is the same as calling
1249
\c{insert(cbegin(), value)}.
1250
1251
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeInserted()}
1252
and \l{QAbstractItemModel::}{rowsInserted()} signals. If the adapter
1253
operates on a tree, then the new row is prepended to the level of the
1254
tree that the adapter operates on.
1255
1256
Provided for STL compatibility; for example, this makes it possible to use
1257
\c{std::front_inserter} with a QRangeModelAdapter. Unlike the standard
1258
containers, this function is available for all ranges that support
1259
insertion of elements, such as \c{std::vector}.
1260
1261
\constraints \c Range supports insertion of elements.
1262
1263
\sa push_back(), emplace_front(), insert(), insertRow()
1264
*/
1265
1266
/*!
1267
\fn template <typename Range, typename Protocol, typename Model> template <typename ...Args, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_emplaceable<Args...>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::emplace(const_iterator pos, Args &&...args)
1268
\since 6.13
1269
1270
Inserts a new row before the row at \a pos, and returns an iterator
1271
pointing to the new row. The row is constructed in place from \a args.
1272
1273
//! [emplace-default-row]
1274
If no \a args are given, then the model creates the new row in the same
1275
way as insertRow() does. For example, if the rows of a table are
1276
themselves ranges with a dynamic size, then the new row will have
1277
columnCount() elements, and if the rows are pointers, then the model
1278
allocates the new row.
1279
//! [emplace-default-row]
1280
1281
\include qrangemodeladapter.qdoc insert-at-iterator
1282
1283
\constraints \c Range supports insertion of elements, and the row type can
1284
be constructed from \a args.
1285
1286
\sa emplace_back(), emplace_front(), insert(), insertRow()
1287
*/
1288
1289
/*!
1290
\fn template <typename Range, typename Protocol, typename Model> template <typename ...Args, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_emplaceable<Args...>> QRangeModelAdapter<Range, Protocol, Model>::reference QRangeModelAdapter<Range, Protocol, Model>::emplace_back(Args &&...args)
1291
\since 6.13
1292
1293
Appends a new row constructed in place from \a args, and returns a
1294
reference wrapper for the new row.
1295
1296
\include qrangemodeladapter.qdoc emplace-default-row
1297
1298
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeInserted()}
1299
and \l{QAbstractItemModel::}{rowsInserted()} signals. If the adapter
1300
operates on a tree, then the new row is appended to the level of the tree
1301
that the adapter operates on.
1302
1303
\constraints \c Range supports insertion of elements, and the row type can
1304
be constructed from \a args.
1305
1306
\sa emplace(), emplace_front()
1307
*/
1308
1309
/*!
1310
\fn template <typename Range, typename Protocol, typename Model> template <typename ...Args, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_emplaceable<Args...>> QRangeModelAdapter<Range, Protocol, Model>::reference QRangeModelAdapter<Range, Protocol, Model>::emplace_front(Args &&...args)
1311
\since 6.13
1312
1313
Prepends a new row constructed in place from \a args, and returns a
1314
reference wrapper for the new row.
1315
1316
\include qrangemodeladapter.qdoc emplace-default-row
1317
1318
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeInserted()}
1319
and \l{QAbstractItemModel::}{rowsInserted()} signals. If the adapter
1320
operates on a tree, then the new row is prepended to the level of the
1321
tree that the adapter operates on.
1322
1323
\constraints \c Range supports insertion of elements, and the row type can
1324
be constructed from \a args.
1325
1326
\sa emplace(), emplace_back()
1327
*/
1328
1329
/*!
1330
\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)
1331
\overload
1332
1333
Removes the given \a row and returns whether the removal was successful.
1334
1335
\constraints \c Range supports the removal of elements.
1336
1337
\sa removeRows(), removeColumn(), insertRow()
1338
*/
1339
1340
/*!
1341
\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)
1342
\overload
1343
1344
Removes the row at the given \a path, including all children of that row,
1345
and returns whether the removal was successful.
1346
1347
\constraints \c Range is a tree that supports the removal of elements.
1348
1349
\sa removeRows(), removeColumn(), insertRow()
1350
*/
1351
1352
/*!
1353
\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(int row, const QModelIndex &parent)
1354
\overload
1355
1356
Removes the specified \a row from the \a parent, including all children of
1357
that row, and returns whether the removal was successful.
1358
1359
\constraints \c Range is a tree that supports the removal of elements.
1360
1361
\sa removeRows(), removeColumn(), insertRow()
1362
*/
1363
1364
/*!
1365
\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)
1366
\overload
1367
1368
Removes \a count rows starting at \a row, and returns whether the removal
1369
was successful.
1370
1371
\constraints \c Range supports the removal of elements.
1372
1373
\sa removeRow(), removeColumns(), insertRows()
1374
*/
1375
1376
/*!
1377
\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)
1378
\overload
1379
1380
Removes \a count rows starting at the row specified by \a path, and returns
1381
whether the removal was successful.
1382
1383
\constraints \c Range is a tree that supports the removal of elements.
1384
1385
\sa removeRow(), removeColumns(), insertRows()
1386
*/
1387
1388
/*!
1389
\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(int row, int count, const QModelIndex &parent)
1390
\overload
1391
1392
Removes \a count rows from the \a parent starting at the specified \a row,
1393
and returns whether the removal was successful.
1394
1395
\constraints \c Range is a tree that supports the removal of elements.
1396
1397
\sa removeRow(), removeColumns(), insertRows()
1398
*/
1399
1400
/*!
1401
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::erase(const_iterator pos)
1402
\since 6.13
1403
1404
Removes the row at \a pos, and returns an iterator pointing to the row
1405
that followed the removed row, which is end() if the last row was removed.
1406
\a pos must be a valid and dereferenceable iterator into this adapter's
1407
rows.
1408
1409
//! [erase-signals]
1410
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeRemoved()}
1411
and \l{QAbstractItemModel::}{rowsRemoved()} signals. If the removal fails,
1412
then this function returns end(). If the adapter operates on a tree, then
1413
all children of the removed rows are removed as well.
1414
1415
Iterators into the adapter refer to a row number, not to an element of
1416
\c Range. After the removal, an iterator to a row after the removed rows
1417
refers to the row that now has that row number, which is a different
1418
element than before, and iterators that are past the new end() must not
1419
be dereferenced. This is also the case if \c Range is a \c{std::list}.
1420
//! [erase-signals]
1421
1422
\constraints \c Range supports the removal of elements.
1423
1424
\sa removeRow(), insert()
1425
*/
1426
1427
/*!
1428
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> QRangeModelAdapter<Range, Protocol, Model>::iterator QRangeModelAdapter<Range, Protocol, Model>::erase(const_iterator first, const_iterator last)
1429
\since 6.13
1430
\overload
1431
1432
Removes the rows in the range [\a first, \a last), and returns an iterator
1433
pointing to the row that followed the last removed row. If the range is
1434
empty, then no row is removed, and an iterator pointing to the same row as
1435
\a first is returned.
1436
1437
\include qrangemodeladapter.qdoc erase-signals
1438
1439
\constraints \c Range supports the removal of elements.
1440
1441
\sa removeRows(), insert()
1442
*/
1443
1444
/*!
1445
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::pop_back()
1446
\since 6.13
1447
1448
Removes the last row. This is the same as calling \c{erase(cend() - 1)}.
1449
The model must not be empty.
1450
1451
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeRemoved()}
1452
and \l{QAbstractItemModel::}{rowsRemoved()} signals. If the adapter
1453
operates on a tree, then all children of the removed row are removed as
1454
well.
1455
1456
\constraints \c Range supports the removal of elements.
1457
1458
\sa erase(), removeRow(), push_back()
1459
*/
1460
1461
/*!
1462
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::pop_front()
1463
\since 6.13
1464
1465
Removes the first row. This is the same as calling \c{erase(cbegin())}.
1466
The model must not be empty.
1467
1468
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeRemoved()}
1469
and \l{QAbstractItemModel::}{rowsRemoved()} signals. If the adapter
1470
operates on a tree, then all children of the removed row are removed as
1471
well.
1472
1473
Unlike the standard containers, this function is available for all ranges
1474
that support the removal of elements, such as \c{std::vector}.
1475
1476
\constraints \c Range supports the removal of elements.
1477
1478
\sa erase(), removeRow(), push_front()
1479
*/
1480
1481
/*!
1482
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::clear()
1483
\since 6.13
1484
1485
Removes all rows. This is the same as calling
1486
\c{erase(cbegin(), cend())}.
1487
1488
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeRemoved()}
1489
and \l{QAbstractItemModel::}{rowsRemoved()} signals if the model was not
1490
empty. If the adapter operates on a tree, then all children of the
1491
removed rows are removed as well. To clear the rows of a branch in the
1492
tree, call this function on the adapter returned by
1493
\l{QRangeModelAdapter::RowReference::}{children()}.
1494
1495
\constraints \c Range supports the removal of elements.
1496
1497
\sa erase(), removeRows(), empty()
1498
*/
1499
1500
/*!
1501
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertRows<I>, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::resize(size_type newSize)
1502
\since 6.13
1503
1504
Changes the number of rows to \a newSize. If \a newSize is smaller than
1505
the current rowCount(), then the rows at the end are removed. If \a newSize
1506
is larger, then new rows are appended, which the model creates in the same
1507
way as insertRow() does.
1508
1509
//! [resize-signals]
1510
The model() emits the \l{QAbstractItemModel::}{rowsAboutToBeRemoved()}
1511
and \l{QAbstractItemModel::}{rowsRemoved()}, or the
1512
\l{QAbstractItemModel::}{rowsAboutToBeInserted()} and
1513
\l{QAbstractItemModel::}{rowsInserted()} signals. If the adapter operates
1514
on a tree, then this function changes the number of rows at the level of
1515
the tree that the adapter operates on, and all children of removed rows are
1516
removed as well.
1517
//! [resize-signals]
1518
1519
\constraints \c Range supports insertion and removal of elements.
1520
1521
\sa rowCount(), clear(), insertRows(), removeRows()
1522
*/
1523
1524
/*!
1525
\fn template <typename Range, typename Protocol, typename Model> template <typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canInsertCopies<I>, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> void QRangeModelAdapter<Range, Protocol, Model>::resize(size_type newSize, const value_type &value)
1526
\since 6.13
1527
\overload
1528
1529
Changes the number of rows to \a newSize. If \a newSize is smaller than
1530
the current rowCount(), then the rows at the end are removed. If \a newSize
1531
is larger, then copies of \a value are appended.
1532
1533
\include qrangemodeladapter.qdoc resize-signals
1534
1535
\constraints \c Range supports insertion and removal of elements, and the
1536
row type is copyable, but not a raw pointer.
1537
1538
\sa rowCount(), clear(), insert()
1539
*/
1540
1541
/*!
1542
\fn template <typename Range, typename Protocol, typename Model> template <typename Predicate, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> QRangeModelAdapter<Range, Protocol, Model>::size_type QRangeModelAdapter<Range, Protocol, Model>::removeIf(Predicate pred)
1543
\since 6.13
1544
1545
Removes all rows for which the predicate \a pred returns \c true, and
1546
returns the number of removed rows.
1547
1548
The predicate is called exactly once for each row, in order, with a const
1549
reference to the row as stored in \c Range, before any row is removed. For
1550
a list, this is the item; for tables and trees, this is the row.
1551
1552
//! [remove-if-signals]
1553
The rows are then removed through the model(), starting at the end, and
1554
with one removal for each contiguous block of matching rows. For each
1555
block, the model emits the \l{QAbstractItemModel::}{rowsAboutToBeRemoved()}
1556
and \l{QAbstractItemModel::}{rowsRemoved()} signals. If the adapter
1557
operates on a tree, then all children of the removed rows are removed as
1558
well; to remove child rows of a tree row, call this function on the
1559
adapter returned by \l{QRangeModelAdapter::RowReference::}{children()}.
1560
//! [remove-if-signals]
1561
1562
\constraints \c Range supports the removal of elements.
1563
1564
\note Use this function instead of the \c{std::remove_if()} and erase()
1565
idiom, which must not be used with the adapter. That idiom moves the rows
1566
that are not removed to the front by assigning to them, so the model()
1567
emits the \l{QAbstractItemModel::}{dataChanged()} signal for each of
1568
those rows before it removes the rows at the end, and persistent model
1569
indexes don't follow the moved rows. This function doesn't modify the
1570
rows that are not removed, and works with all ranges that support the
1571
removal of elements, including trees with move-only rows.
1572
1573
\sa removeAll(), erase(), removeRows()
1574
*/
1575
1576
/*!
1577
\fn template <typename Range, typename Protocol, typename Model> template <typename AT, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> QRangeModelAdapter<Range, Protocol, Model>::size_type QRangeModelAdapter<Range, Protocol, Model>::removeAll(const AT &value)
1578
\since 6.13
1579
1580
Removes all rows that compare equal to \a value, and returns the number of
1581
removed rows.
1582
1583
\include qrangemodeladapter.qdoc remove-if-signals
1584
1585
\constraints \c Range supports the removal of elements.
1586
1587
\sa removeIf(), erase(), removeRows()
1588
*/
1589
1590
/*!
1591
\fn template <typename Range, typename Protocol, typename Model> template <typename AT, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> QRangeModelAdapter<Range, Protocol, Model>::size_type QRangeModelAdapter<Range, Protocol, Model>::erase(QRangeModelAdapter &adapter, const AT &value)
1592
\since 6.13
1593
1594
Removes all rows that compare equal to \a value from \a adapter, and
1595
returns the number of removed rows. This is the same as calling
1596
\c{adapter.removeAll(value)}.
1597
1598
\constraints \c Range supports the removal of elements.
1599
1600
\sa removeAll(), erase_if()
1601
*/
1602
1603
/*!
1604
\fn template <typename Range, typename Protocol, typename Model> template <typename Predicate, typename I, QRangeModelAdapter<Range, Protocol, Model>::if_canRemoveRows<I>> QRangeModelAdapter<Range, Protocol, Model>::size_type QRangeModelAdapter<Range, Protocol, Model>::erase_if(QRangeModelAdapter &adapter, Predicate pred)
1605
\since 6.13
1606
1607
Removes all rows for which the predicate \a pred returns \c true from
1608
\a adapter, and returns the number of removed rows. This is the same as
1609
calling \c{adapter.removeIf(pred)}.
1610
1611
\constraints \c Range supports the removal of elements.
1612
1613
\sa removeIf(), erase()
1614
*/
1615
1616
/*!
1617
\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)
1618
\overload
1619
1620
Moves the row at \a source to the position at \a destination, and returns
1621
whether the row was successfully moved.
1622
1623
\constraints \c Range supports moving of elements.
1624
1625
\sa insertRow(), removeRow(), moveColumn()
1626
*/
1627
1628
/*!
1629
\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)
1630
\overload
1631
1632
Moves the tree branch at \a source to the position at \a destination, and
1633
returns whether the branch was successfully moved.
1634
1635
\constraints \c Range is a tree that supports moving of elements.
1636
1637
\sa insertRow(), removeRow(), moveColumn()
1638
*/
1639
1640
/*!
1641
\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(const QModelIndex &sourceParent, int sourceRow, const QModelIndex &destinationParent, int destinationChild)
1642
\overload
1643
1644
Moves the branch at \a sourceRow from the \a sourceParent to the position
1645
at \a destinationChild in the \a destinationParent, and returns whether the
1646
branch was successfully moved.
1647
1648
\constraints \c Range is a tree that supports moving of elements.
1649
1650
\sa insertRow(), removeRow(), moveColumn()
1651
*/
1652
1653
/*!
1654
\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)
1655
\overload
1656
1657
Moves \a count rows starting at \a source to the position at \a destination,
1658
and returns whether the rows were successfully moved.
1659
1660
\constraints \c Range supports moving of elements.
1661
1662
\sa insertRows(), removeRows(), moveColumns()
1663
*/
1664
1665
/*!
1666
\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)
1667
\overload
1668
1669
Moves \a count tree branches starting at \a source to the position at
1670
\a destination, and returns whether the rows were successfully moved.
1671
1672
\constraints \c Range is a tree that supports moving of elements.
1673
1674
\sa insertRows(), removeRows(), moveColumns()
1675
*/
1676
1677
/*!
1678
\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(const QModelIndex &sourceParent, int sourceRow, int count, const QModelIndex &destinationParent, int destinationChild)
1679
\overload
1680
1681
Moves \a count branches starting at \a sourceRow from the \a sourceParent
1682
to the position at \a destinationChild in the \a destinationParent, and
1683
returns whether the branch was successfully moved.
1684
1685
\constraints \c Range is a tree that supports moving of elements.
1686
1687
\sa insertRows(), removeRows(), moveColumns()
1688
*/
1689
1690
/*!
1691
\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)
1692
\overload
1693
1694
Inserts a single empty column before the column specified by \a before into
1695
all rows, and returns whether the insertion was successful.
1696
//! [insert-column-appends]
1697
If \a before is the same value as columnCount(), then the column will be
1698
appended to each row.
1699
//! [insert-column-appends]
1700
1701
\constraints \c Range has rows that support insertion of elements.
1702
1703
\sa removeColumn(), insertColumns(), insertRow()
1704
*/
1705
1706
/*!
1707
\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)
1708
\overload
1709
1710
Inserts a single column constructed from \a data before the column specified
1711
by \a before into all rows, and returns whether the insertion was successful.
1712
//! [insert-column-appends]
1713
If \a before is the same value as columnCount(), then the column will be
1714
appended to each row.
1715
//! [insert-column-appends]
1716
1717
If \a data is a single value, then the new entry in all rows will be constructed
1718
from that single value.
1719
1720
If \a data is a container, then the elements in that container will be used
1721
sequentially to construct the column for each subsequent row. If there are
1722
fewer elements in \a data than there are rows, then function wraps around
1723
and starts again from the first element.
1724
1725
\code
1726
\endcode
1727
1728
\constraints \c Range has rows that support insertion of elements, and the
1729
elements can be constructed from the entries in \a data.
1730
1731
\sa removeColumn(), insertColumns(), insertRow()
1732
*/
1733
1734
/*!
1735
\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)
1736
1737
Inserts columns constructed from the elements in \a data before the column
1738
specified by \a before into all rows, and returns whether the insertion was
1739
successful.
1740
//! [insert-column-appends]
1741
If \a before is the same value as columnCount(), then the column will be
1742
appended to each row.
1743
//! [insert-column-appends]
1744
1745
If the elements in \a data are values, then the new entries in all rows will
1746
be constructed from those values.
1747
1748
If the elements in \a data are containers, then the entries in the outer
1749
container will be used sequentially to construct the new entries for each
1750
subsequent row. If there are fewer elements in \a data than there are rows,
1751
then the function wraps around and starts again from the first element.
1752
1753
\code
1754
\endcode
1755
1756
\constraints \c Range has rows that support insertion of elements, and the
1757
elements can be constructed from the entries in \a data.
1758
1759
\sa removeColumns(), insertColumn(), insertRows()
1760
*/
1761
1762
/*!
1763
\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)
1764
1765
Removes the given \a column from each row, and returns whether the removal
1766
was successful.
1767
1768
\constraints \c Range has rows that support removal of elements.
1769
1770
\sa insertColumn(), removeColumns(), removeRow()
1771
*/
1772
1773
/*!
1774
\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)
1775
1776
Removes \a count columns starting by the given \a column from each row, and
1777
returns whether the removal was successful.
1778
1779
\constraints \c Range has rows that support removal of elements.
1780
1781
\sa insertColumns(), removeColumn(), removeRow()
1782
*/
1783
1784
/*!
1785
\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)
1786
1787
Moves the column at \a from to the column at \a to, and returns whether the
1788
column was successfully moved.
1789
1790
\constraints \c Range has rows that support moving of elements.
1791
1792
\sa insertColumn(), removeColumn(), moveColumns(), moveRow()
1793
*/
1794
1795
/*!
1796
\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)
1797
1798
Moves \a count columns starting at \a from to the position at \a to, and
1799
returns whether the columns were successfully moved.
1800
1801
\constraints \c Range has rows that support moving of elements.
1802
1803
\sa insertColumns(), removeColumns(), moveColumn(), moveRows()
1804
*/
1805
1806
/*!
1807
\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)
1808
\internal Not possible to create a tree from a row type that can rotate/splice?
1809
*/
1810
1811
/*!
1812
\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)
1813
\internal Not possible to create a tree from a row type that can rotate/splice?
1814
*/
1815
1816
/*!
1817
\class QRangeModelAdapter::DataReference
1818
\inmodule QtCore
1819
\since 6.11
1820
\preliminary
1821
\ingroup model-view
1822
\brief DataReference is a reference wrapper around an item in a QRangeModel.
1823
\compares equality
1824
\compareswith equality value_type
1825
\endcompareswith
1826
1827
Accessing an item in the model using the non-const overloads of at(),
1828
subscript \l{QRangeModelAdapter::operator[]()}{operator[]}, or
1829
dereferencing a non-const \l{QRangeModelAdapter::RowIterator}{iterator},
1830
returns a DataReference wrapper around the item in the model.
1831
1832
Assigning to that reference wrapper changes the data in the model using
1833
QAbstractItemModel API.
1834
1835
\code
1836
adapter[0] = newValue;
1837
\endcode
1838
1839
A const version of the value itself can be accessed using get() or
1840
operator->().
1841
1842
\code
1843
QRangeModelAdapter adapter(QList<Gadget>{ ~~~ });
1844
auto value = adapter[0]->value();
1845
// adapter[0]->setValue(); // not allowed - would not emit dataChanged()
1846
\endcode
1847
1848
In contrast to \c{std::reference_wrapper}, assigning one DataReference to
1849
another does not rebind the reference, but sets the value using copy-
1850
semantics.
1851
1852
\code
1853
adapter[0] = adapter[1]; // items at row 0 and row 1 now have the same value
1854
\endcode
1855
1856
DataReference objects can't be swapped; see the \l{Iterator API}.
1857
1858
Two DataReference objects are equal if they refer to the same item, or if
1859
the values of the items they refer to are equal. A DataReference is equal
1860
to a \c value_type if the value of the item it refers to is equal to it.
1861
1862
If \c value_type provides \c{operator<()}, then DataReference also
1863
provides the relational operators \c{<}, \c{<=}, \c{>}, and \c{>=} for
1864
comparing with another DataReference or with a \c value_type. They
1865
compare the values of the items, so that standard algorithms like
1866
\c{std::max_element()} or \c{std::lower_bound()} can be used without a
1867
comparator.
1868
1869
\sa RowReference, ConstRowReference
1870
*/
1871
1872
/*!
1873
\typedef QRangeModelAdapter::DataReference::value_type
1874
1875
An alias for the type of the items stored in the underlying range.
1876
If different columns in the model hold different types, then this is an
1877
alias to QVariant.
1878
*/
1879
1880
/*!
1881
\typedef QRangeModelAdapter::DataReference::const_value_type
1882
1883
An alias for the const type of the items stored in the underlying range.
1884
If different columns in the model hold different types, then this is an
1885
alias to \c{const QVariant}.
1886
*/
1887
1888
/*!
1889
\typedef QRangeModelAdapter::DataReference::pointer
1890
1891
An alias for the pointer type returned by operator->().
1892
*/
1893
1894
/*!
1895
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::DataReference(const QModelIndex &index) noexcept
1896
1897
Constructs a DataReference wrapper for the item at \a index.
1898
*/
1899
1900
/*!
1901
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::DataReference(const DataReference &other)
1902
1903
Constructs a copy of \a other.
1904
*/
1905
1906
/*!
1907
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::DataReference(DataReference &&other)
1908
1909
Constructs a DataReference by moving from \a other.
1910
*/
1911
1912
/*!
1913
\fn template <typename Range, typename Protocol, typename Model> QDataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(const DataReference &other)
1914
1915
Assigns the item value referred to by \a other to the value referenced by
1916
this wrapper. This copies the value also if \a other is an rvalue, as
1917
\a other doesn't own the value.
1918
*/
1919
1920
/*!
1921
\fn template <typename Range, typename Protocol, typename Model> DataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(const value_type &value)
1922
1923
Assigns \a value to the underlying model item.
1924
*/
1925
1926
/*!
1927
\fn template <typename Range, typename Protocol, typename Model> DataReference &QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator=(value_type &&value)
1928
1929
Move-assigns \a value to the underlying model item.
1930
*/
1931
1932
/*!
1933
\fn template <typename Range, typename Protocol, typename Model> const_value_type QRangeModelAdapter<Range, Protocol, Model>::DataReference::get() const
1934
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator const_value_type() const
1935
\return the item value referred to by this DataReference as a const value.
1936
*/
1937
1938
/*!
1939
\fn template <typename Range, typename Protocol, typename Model> pointer QRangeModelAdapter<Range, Protocol, Model>::DataReference::operator->() const
1940
\return a pointer to the value referred to by this DataReference.
1941
*/
1942
1943
/*!
1944
\fn template <typename Range, typename Protocol, typename Model> bool QRangeModelAdapter<Range, Protocol, Model>::DataReference::isValid() const
1945
\return true if this DataReference refers to a valid model index.
1946
*/
1947
1948
/*!
1949
\class QRangeModelAdapter::RowReferenceBase
1950
\inmodule QtCore
1951
\since 6.11
1952
\preliminary
1953
\ingroup model-view
1954
\brief RowReferenceBase provides common API for RowReference and ConstRowReference.
1955
1956
For models that are tables or trees, accessing a row of an adapter using
1957
\l{QRangeModelAdapter::}{at()}, subscript \l{QRangeModelAdapter::operator[]()}
1958
{operator[]}, or dereferencing a RowIterator, returns a RowReference or
1959
ConstRowReference to the specified row.
1960
1961
\sa DataReference
1962
*/
1963
1964
/*!
1965
\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
1966
1967
\return true if the referenced row has one or more child rows, otherwise false.
1968
1969
\constraints \c Range is a tree.
1970
*/
1971
1972
/*!
1973
\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
1974
1975
\return a QRangeModelAdapter operating on the same range and model as this adapter, and with
1976
this row as the root index.
1977
1978
\constraints \c Range is a tree.
1979
*/
1980
1981
/*!
1982
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::cbegin() const
1983
1984
\return a ConstColumnIterator pointing to the first column of this row.
1985
*/
1986
1987
/*!
1988
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::begin() const
1989
1990
\return a ConstColumnIterator pointing to the first column of this row.
1991
*/
1992
1993
/*!
1994
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::cend() const
1995
1996
\return a ConstColumnIterator pointing just after the last column of this row.
1997
*/
1998
1999
/*!
2000
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> ConstColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::end() const
2001
2002
\return a ConstColumnIterator pointing just after the last column of this row.
2003
*/
2004
2005
/*!
2006
\fn template <typename Range, typename Protocol, typename Model> template <typename Reference, typename Adapter> size_type QRangeModelAdapter<Range, Protocol, Model>::RowReferenceBase<Reference, Adapter>::size() const
2007
2008
\return the number of columns in the model.
2009
2010
This returns the same value for all rows in the model.
2011
*/
2012
2013
/*!
2014
\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
2015
\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
2016
2017
\return a reference wrapper to the item at \a column of this row.
2018
2019
Depending on the data structure the adapter operates on, the returned value
2020
is a const reference wrapper, a pointer to a const object, or a QVariant.
2021
*/
2022
2023
/*!
2024
\class QRangeModelAdapter::RowReference
2025
\inmodule QtCore
2026
\since 6.11
2027
\preliminary
2028
\ingroup model-view
2029
\brief RowReference is a reference wrapper around a row in a QRangeModel.
2030
\compares equality
2031
\compareswith equality row_type
2032
\endcompareswith
2033
2034
For ranges that are tables or trees, accessing a row of a QRangeModelAdapter
2035
using the non-const overloads of \l{QRangeModelAdapter::}{at()} or subscript
2036
\l{QRangeModelAdapter::operator[]()}{operator[]}, or by dereferencing a
2037
RowIterator, returns a RowReference for the specified row.
2038
2039
//! [row-reference-comparison]
2040
Two row references are equal if they refer to the same row, or if the rows
2041
they refer to are equal. If \c row_type doesn't provide an equality
2042
operator, then two row references are only equal if they refer to the
2043
same row. A row reference is equal to a \c row_type if the row it refers
2044
to is equal to it.
2045
2046
RowReference and ConstRowReference can also be compared with each other,
2047
and with the row references of other adapters if the rows of both
2048
adapters have the same type, with the same semantics.
2049
2050
Row references are not ordered. To compare the positions of rows, compare
2051
their iterators. Row references can't be swapped; see the
2052
\l{Iterator API}.
2053
//! [row-reference-comparison]
2054
2055
\sa ConstRowReference, DataReference
2056
*/
2057
2058
/*!
2059
\typedef QRangeModelAdapter::RowReference::row_type
2060
2061
An alias for the type of the rows in the underlying range.
2062
*/
2063
2064
/*!
2065
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(const RowReference &other)
2066
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(const ConstRowReference &other)
2067
2068
Assigns the row referenced by \a other to the row referenced by this, emitting
2069
dataChanged for all items in the row.
2070
2071
//! [rowref-assign]
2072
If the model is a tree, and the referenced row has children, then those children
2073
are removed from the model. If the row referenced by \a other has children,
2074
then those children are inserted into the model.
2075
//! [rowref-assign]
2076
*/
2077
2078
/*!
2079
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(const row_type &other)
2080
\fn template <typename Range, typename Protocol, typename Model> RowReference &QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator=(row_type &&other)
2081
2082
Assigns the row \a other to the row referenced by this, emitting dataChanged
2083
for all items in the row.
2084
2085
\include qrangemodeladapter.qdoc rowref-assign
2086
*/
2087
2088
/*!
2089
\fn template <typename Range, typename Protocol, typename Model> QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator ConstRowReference() const
2090
2091
\return a ConstRowReference referencing the same row as this.
2092
*/
2093
2094
/*!
2095
\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()
2096
2097
\return a QRangeModelAdapter operating on the same range and model as this adapter, and with
2098
this row as the root index.
2099
2100
\constraints \c Range is a tree.
2101
*/
2102
2103
/*!
2104
\fn template <typename Range, typename Protocol, typename Model> ColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReference::begin()
2105
2106
\return a ColumnIterator pointing to the first column of this row.
2107
*/
2108
2109
/*!
2110
\fn template <typename Range, typename Protocol, typename Model> ColumnIterator QRangeModelAdapter<Range, Protocol, Model>::RowReference::end()
2111
2112
\return a ColumnIterator pointing just after the last column of this row.
2113
*/
2114
2115
/*!
2116
\fn template <typename Range, typename Protocol, typename Model> auto QRangeModelAdapter<Range, Protocol, Model>::RowReference::at(int column)
2117
\fn template <typename Range, typename Protocol, typename Model> auto QRangeModelAdapter<Range, Protocol, Model>::RowReference::operator[](int column)
2118
2119
\return a reference wrapper to the item at \a column of this row.
2120
*/
2121
2122
2123
/*!
2124
\class QRangeModelAdapter::ConstRowReference
2125
\inmodule QtCore
2126
\since 6.11
2127
\preliminary
2128
\ingroup model-view
2129
\brief ConstRowReference is a reference wrapper around a const row in a QRangeModel.
2130
\compares equality
2131
\compareswith equality row_type
2132
\endcompareswith
2133
2134
For ranges that are tables or trees, accessing a row of a QRangeModelAdapter
2135
using the const overloads of \l{QRangeModelAdapter::}{at()} or subscript
2136
\l{QRangeModelAdapter::operator[]()}{operator[]}, or by dereferencing a
2137
ConstRowIterator, returns a ConstRowReference for the specified row.
2138
2139
\include qrangemodeladapter.qdoc row-reference-comparison
2140
2141
\sa RowReference, DataReference
2142
*/
2143
2144
/*!
2145
\class QRangeModelAdapter::RowIterator
2146
\inmodule QtCore
2147
\since 6.11
2148
\preliminary
2149
\ingroup model-view
2150
\brief Provides an STL-style non-const iterator over the rows of a model.
2151
2152
The iterator models \c{std::random_access_iterator}. If the model is a list,
2153
then dereferencing the iterator returns a DataReference wrapper for the
2154
pointed-to item in the model.
2155
2156
For tables and trees, dereferencing the iterator returns a RowReference for
2157
the pointed-to row.
2158
2159
The \c value_type of the iterator is the type of the items or rows stored
2160
in the range, not the wrapper type. Algorithms that store values in
2161
temporaries, such as \c{std::ranges::max()}, therefore operate on copies,
2162
and don't modify the model.
2163
2164
\note The implementations of \c{std::ranges::min()} and
2165
\c{std::ranges::max()} in libstdc++ before GCC 16 store the wrapper instead
2166
of a copy of the value, and modify the model when called with a mutable
2167
adapter. Call them with a const adapter, for instance using
2168
\c{std::as_const()}.
2169
*/
2170
2171
/*!
2172
\class QRangeModelAdapter::ConstRowIterator
2173
\inmodule QtCore
2174
\since 6.11
2175
\preliminary
2176
\ingroup model-view
2177
\brief Provides an STL-style const iterator over the rows of a model.
2178
2179
The iterator models \c{std::random_access_iterator}. If the model is a list,
2180
then dereferencing the iterator returns the pointed-to item in the model.
2181
2182
For tables and trees, dereferencing the iterator returns a ConstRowReference
2183
for the pointed-to row.
2184
*/
2185
2186
/*!
2187
\class QRangeModelAdapter::ColumnIterator
2188
\inmodule QtCore
2189
\since 6.11
2190
\preliminary
2191
\ingroup model-view
2192
\brief Provides an STL-style non-const iterator over the columns in a model row.
2193
2194
The iterator models \c{std::random_access_iterator}. Dereferencing the iterator
2195
returns a DataReference wrapper for the value at the pointed-to item in
2196
the model. The \c value_type of the iterator is the type of the item.
2197
*/
2198
2199
/*!
2200
\class QRangeModelAdapter::ConstColumnIterator
2201
\inmodule QtCore
2202
\since 6.11
2203
\preliminary
2204
\ingroup model-view
2205
\brief Provides an STL-style non-const iterator over the columns in a model row.
2206
2207
The iterator models \c{std::random_access_iterator}. Dereferencing the iterator
2208
returns the const value at the pointed-to item in the model.
2209
*/
qtbase
src
corelib
itemmodels
qrangemodeladapter.qdoc
Generated on
for Qt by
1.18.0