diff options
| author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-08-27 17:01:06 +0200 |
|---|---|---|
| committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-08-29 23:07:13 +0200 |
| commit | 3e2367b5ed9d0bcba663c5b972bf556996b98f63 (patch) | |
| tree | bd3d067212117c6c2d6779bf721e390a4dd36d2b /src/corelib/doc/snippets | |
| parent | 85ec3c5db8628e4557a42aca6d4d941c9f56d29e (diff) | |
QRM docs: clarify direct access to the range, add section on subclassing
Those two are related: if we really didn't allow direct access to the
range after QRangeModel has been constructed, then subclassing would be
practically impossible. We do allow it, as long as no view (or similar)
operates on the model.
Clarify that in the \note, and add a snippet showing how to subclass
QRangeModel to build an encapsulated class that provides type- and
structure-aware APIs.
Pick-to: 6.10
Change-Id: I43836c750e372fd55c63bb75d89109524c87206c
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Diffstat (limited to 'src/corelib/doc/snippets')
| -rw-r--r-- | src/corelib/doc/snippets/qrangemodel/main.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/qrangemodel/main.cpp b/src/corelib/doc/snippets/qrangemodel/main.cpp index 1415d962109..5c1228192ed 100644 --- a/src/corelib/doc/snippets/qrangemodel/main.cpp +++ b/src/corelib/doc/snippets/qrangemodel/main.cpp @@ -267,6 +267,36 @@ void vector_of_multirole_objects() } // namespace object +namespace Subclass +{ + +//! [subclass_header] +class NumbersModel : public QRangeModel +{ + std::vector<int> m_numbers; + +public: + NumbersModel(const std::vector<int> &numbers) + : QRangeModel(std::ref(m_numbers)) + , m_numbers(numbers) + { + } +//! [subclass_header] +//! [subclass_API] + void setNumber(int idx, int number) + { + setData(index(idx, 0), QVariant::fromValue(number)); + } + + int number(int idx) const + { + return m_numbers.at(idx); + } +}; +//! [subclass_API] + +} // namespace Subclass + namespace tree_protocol { //! [tree_protocol_0] |
