diff options
| author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-06-20 15:23:57 +0200 |
|---|---|---|
| committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2025-06-20 20:05:18 +0200 |
| commit | 05c753b041d4a164285aa171885b472ff2aeaabb (patch) | |
| tree | a778b9c85d1b510d2706ff5be9321642100fecfa /src/corelib/doc/snippets | |
| parent | fb7b848fe6103d89ae5590e594d0f28e73a75913 (diff) | |
QRangeModel: documentation improvements
Some restructuring, and include a section on rows as values vs rows as
pointers. That paragraph as written so far was confusing, even for me,
and the subject matter is complex enough to require more than a single
paragraph anyway.
Still work in progress, esp with some pending changes to enforce the
requirement that ranges of pointers cannot be passed by value.
Pick-to: 6.10
Change-Id: Ie4496ffb32b2622835c3cc4662da129e34e3f8c7
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 | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/corelib/doc/snippets/qrangemodel/main.cpp b/src/corelib/doc/snippets/qrangemodel/main.cpp index 962693fca8f..240990e4381 100644 --- a/src/corelib/doc/snippets/qrangemodel/main.cpp +++ b/src/corelib/doc/snippets/qrangemodel/main.cpp @@ -184,6 +184,77 @@ private: //! [gadget] } // namespace gadget +namespace Object +{ +//! [object_0] +class Entry : public QObject +{ + Q_OBJECT + Q_PROPERTY(QString display READ display WRITE setDisplay NOTIFY displayChanged) + Q_PROPERTY(QIcon decoration READ decoration WRITE setDecoration NOTIFY decorationChanged) + Q_PROPERTY(QString toolTip READ toolTip WRITE setToolTip NOTIFY toolTipChanged) + +public: + Entry() = default; + + QString display() const + { + return m_display; + } + + void setDisplay(const QString &display) + { + if (m_display == display) + return; + m_display = display; + emit displayChanged(m_display); + } + +signals: + void displayChanged(const QString &); +//! [object_0] + +private: + QString m_display; + +//! [object_1] +}; +//! [object_1] + +void vector_of_objects() +{ + { + //! [vector_of_objects_0] + std::vector<std::shared_ptr<Entry>> entries = { + //! [vector_of_objects_0] + std::make_shared<Entry>(), + //! [vector_of_objects_1] + }; + //! [vector_of_objects_1] + + //! [vector_of_objects_2] + QRangeModel model(std::ref(entries)); + QListView listView; + listView.setModel(&model); + //! [vector_of_objects_2] + } + + { + //! [vector_of_multirole_objects_0] + std::vector<QRangeModel::SingleColumn<std::shared_ptr<Entry>>> entries = { + //! [vector_of_multirole_objects_0] + {std::make_shared<Entry>()}, + //! [vector_of_multirole_objects_1] + }; + //! [vector_of_multirole_objects_1] + + //! [vector_of_multirole_objects_2] + QRangeModel model(std::ref(entries)); + //! [vector_of_multirole_objects_2] + } +} +} // namespace object + namespace tree_protocol { //! [tree_protocol_0] |
