diff options
author | Stephen Kelly <ske@ableton.com> | 2015-02-25 12:58:23 +0100 |
---|---|---|
committer | Stephen Kelly <steveire@gmail.com> | 2015-03-04 22:38:55 +0000 |
commit | 196fde2ac780774b0e003dbc02bad23e1afc74ce (patch) | |
tree | a651d48a0d0ff9be6929a98f254e8587ce45a6b5 /src | |
parent | 38e64664a226e406a83fd0250584d5c57719a3a7 (diff) |
Make the QItemSelectionModel::selection a property.
QML code like this should be possible:
Text {
text: selModel.selection.contains(modelIndex) ? "blue" : "yellow"
}
If the selection is just a Q_INVOKABLE method, then all consumers need
to set up
Connections {
target: selModel
selectionChanged: foo()
}
That is obviously not the API we want (made more clear by the fact that
the signal is already perfectly named) because it is not declarative but
it can be. So, make it declarative by making selection a property.
Change-Id: Id1a05ae9b91e45e6d462bea4272b8740571e9fc3
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index fe0bd459cd..09fab78214 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -146,6 +146,7 @@ class Q_CORE_EXPORT QItemSelectionModel : public QObject Q_PROPERTY(QAbstractItemModel *model READ model WRITE setModel NOTIFY modelChanged) Q_PROPERTY(bool hasSelection READ hasSelection NOTIFY selectionChanged STORED false DESIGNABLE false) Q_PROPERTY(QModelIndex currentIndex READ currentIndex NOTIFY currentChanged STORED false DESIGNABLE false) + Q_PROPERTY(QItemSelection selection READ selection NOTIFY selectionChanged STORED false DESIGNABLE false) Q_DECLARE_PRIVATE(QItemSelectionModel) @@ -186,7 +187,7 @@ public: Q_INVOKABLE QModelIndexList selectedIndexes() const; Q_INVOKABLE QModelIndexList selectedRows(int column = 0) const; Q_INVOKABLE QModelIndexList selectedColumns(int row = 0) const; - Q_INVOKABLE const QItemSelection selection() const; + const QItemSelection selection() const; // ### Qt 6: Merge these two as "QAbstractItemModel *model() const" const QAbstractItemModel *model() const; |