diff options
author | Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com> | 2015-01-15 19:19:26 +0100 |
---|---|---|
committer | Caroline Chao <caroline.chao@theqtcompany.com> | 2015-02-03 18:40:19 +0000 |
commit | 7ab29c4ebb5bfc66a544a966da0b49f0e739f08c (patch) | |
tree | ce8ff92cfe4ff87a416c10d07796dc1ccf8ee673 /src/corelib/itemmodels/qitemselectionmodel.h | |
parent | ae9d3f4c6c1a732788cd1f24c6a928cee16c3991 (diff) |
Allow exposing QItemSelectionModel to QML
This requires being able to create a QItemSelectionModel
without specifiying its model, and also setting the model
later. Also, several classes, like QPersistentModelIndex,
need to be declared as meta-type.
Finally, and in order to introduce the 'model' property,
we need to have a type compatible getter. Hence the new,
non-const model() function.
Where needed, meta-type declarations have been removed from
auto-tests.
[ChangeLog][QtCore][Item Models] QItemSelectionModel
can now be created without a model and have one set later.
Change-Id: If49bed061a5d1012331f335ca7f6e3959ecd3f1c
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@theqtcompany.com>
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/corelib/itemmodels/qitemselectionmodel.h')
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index 27243a2b99..f02149b2b7 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -143,6 +143,10 @@ class QItemSelectionModelPrivate; class Q_CORE_EXPORT QItemSelectionModel : public QObject { Q_OBJECT + 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_DECLARE_PRIVATE(QItemSelectionModel) Q_FLAGS(SelectionFlags) @@ -164,27 +168,31 @@ public: Q_DECLARE_FLAGS(SelectionFlags, SelectionFlag) - explicit QItemSelectionModel(QAbstractItemModel *model); + explicit QItemSelectionModel(QAbstractItemModel *model = 0); explicit QItemSelectionModel(QAbstractItemModel *model, QObject *parent); virtual ~QItemSelectionModel(); QModelIndex currentIndex() const; - bool isSelected(const QModelIndex &index) const; - bool isRowSelected(int row, const QModelIndex &parent) const; - bool isColumnSelected(int column, const QModelIndex &parent) const; + Q_INVOKABLE bool isSelected(const QModelIndex &index) const; + Q_INVOKABLE bool isRowSelected(int row, const QModelIndex &parent) const; + Q_INVOKABLE bool isColumnSelected(int column, const QModelIndex &parent) const; - bool rowIntersectsSelection(int row, const QModelIndex &parent) const; - bool columnIntersectsSelection(int column, const QModelIndex &parent) const; + Q_INVOKABLE bool rowIntersectsSelection(int row, const QModelIndex &parent) const; + Q_INVOKABLE bool columnIntersectsSelection(int column, const QModelIndex &parent) const; bool hasSelection() const; - QModelIndexList selectedIndexes() const; - QModelIndexList selectedRows(int column = 0) const; - QModelIndexList selectedColumns(int row = 0) const; - const QItemSelection selection() const; + 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; + // ### Qt 6: Merge these two as "QAbstractItemModel *model() const" const QAbstractItemModel *model() const; + QAbstractItemModel *model(); + + void setModel(QAbstractItemModel *model); public Q_SLOTS: virtual void setCurrentIndex(const QModelIndex &index, QItemSelectionModel::SelectionFlags command); @@ -201,6 +209,7 @@ Q_SIGNALS: void currentChanged(const QModelIndex ¤t, const QModelIndex &previous); void currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous); void currentColumnChanged(const QModelIndex ¤t, const QModelIndex &previous); + void modelChanged(QAbstractItemModel *model); protected: QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model); @@ -243,4 +252,7 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &); QT_END_NAMESPACE +Q_DECLARE_METATYPE(QItemSelectionRange) +Q_DECLARE_METATYPE(QItemSelection) + #endif // QITEMSELECTIONMODEL_H |