diff options
Diffstat (limited to 'src/corelib/itemmodels')
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.cpp | 52 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractitemmodel.h | 11 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractproxymodel.cpp | 16 | ||||
-rw-r--r-- | src/corelib/itemmodels/qabstractproxymodel.h | 7 | ||||
-rw-r--r-- | src/corelib/itemmodels/qidentityproxymodel.h | 4 | ||||
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.h | 4 | ||||
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.cpp | 3 | ||||
-rw-r--r-- | src/corelib/itemmodels/qsortfilterproxymodel.h | 4 | ||||
-rw-r--r-- | src/corelib/itemmodels/qstringlistmodel.cpp | 4 | ||||
-rw-r--r-- | src/corelib/itemmodels/qstringlistmodel.h | 4 |
10 files changed, 75 insertions, 34 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index 12029f4a23..f152dec5e6 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -866,6 +866,27 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent, } /*! + \since 4.8 + + This slot is called just after the internal data of a model is cleared + while it is being reset. + + This slot is provided the convenience of subclasses of concrete proxy + models, such as subclasses of QSortFilterProxyModel which maintain extra + data. + + \snippet code/src_corelib_kernel_qabstractitemmodel.cpp 12 + + \note Due to a mistake, this slot is missing in Qt 5.0. + + \sa modelAboutToBeReset(), modelReset() +*/ +void QAbstractItemModel::resetInternalData() +{ + +} + +/*! \class QModelIndex \inmodule QtCore @@ -1658,6 +1679,9 @@ bool QAbstractItemModel::hasIndex(int row, int column, const QModelIndex &parent Use rowCount() on the parent to find out the number of children. + Note that it is undefined behavior to report that a particular index hasChildren + with this method if the same index has the flag Qt::ItemNeverHasChildren set. + \sa parent(), index() */ bool QAbstractItemModel::hasChildren(const QModelIndex &parent) const @@ -2088,9 +2112,8 @@ void QAbstractItemModel::fetchMore(const QModelIndex &) The default implementation always returns false. - If canFetchMore() returns true, QAbstractItemView will call fetchMore(). - However, the fetchMore() function is only called when the model is being - populated incrementally. + If canFetchMore() returns true, the fetchMore() function should + be called. This is the behavior of QAbstractItemView, for example. \sa fetchMore() */ @@ -3054,6 +3077,7 @@ void QAbstractItemModel::endResetModel() { Q_D(QAbstractItemModel); d->invalidatePersistentIndexes(); + QMetaObject::invokeMethod(this, "resetInternalData"); emit modelReset(QPrivateSignal()); } @@ -3271,6 +3295,17 @@ bool QAbstractTableModel::hasChildren(const QModelIndex &parent) const } /*! + \reimp + */ +Qt::ItemFlags QAbstractTableModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags f = QAbstractItemModel::flags(index); + if (index.isValid()) + f |= Qt::ItemNeverHasChildren; + return f; +} + +/*! \class QAbstractListModel \inmodule QtCore \brief The QAbstractListModel class provides an abstract model that can be @@ -3391,6 +3426,17 @@ QModelIndex QAbstractListModel::parent(const QModelIndex & /* index */) const } /*! + \reimp + */ +Qt::ItemFlags QAbstractListModel::flags(const QModelIndex &index) const +{ + Qt::ItemFlags f = QAbstractItemModel::flags(index); + if (index.isValid()) + f |= Qt::ItemNeverHasChildren; + return f; +} + +/*! \internal Returns the number of columns in the list with the given \a parent. diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index 793a1ba169..6a57ccaca8 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -47,8 +47,6 @@ #include <QtCore/qhash.h> #include <QtCore/qvector.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -332,6 +330,10 @@ public Q_SLOTS: virtual bool submit(); virtual void revert(); +protected Q_SLOTS: + // Qt 6: Make virtual + void resetInternalData(); + protected: QAbstractItemModel(QAbstractItemModelPrivate &dd, QObject *parent = 0); @@ -421,6 +423,7 @@ public: bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; protected: QAbstractTableModel(QAbstractItemModelPrivate &dd, QObject *parent); @@ -441,6 +444,8 @@ public: QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const; bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent); + + Qt::ItemFlags flags(const QModelIndex &index) const Q_DECL_OVERRIDE; protected: QAbstractListModel(QAbstractItemModelPrivate &dd, QObject *parent); @@ -473,6 +478,4 @@ inline uint qHash(const QModelIndex &index) QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTITEMMODEL_H diff --git a/src/corelib/itemmodels/qabstractproxymodel.cpp b/src/corelib/itemmodels/qabstractproxymodel.cpp index ed5d0e9a85..d435c4bcf5 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.cpp +++ b/src/corelib/itemmodels/qabstractproxymodel.cpp @@ -91,6 +91,7 @@ QT_BEGIN_NAMESPACE //detects the deletion of the source model void QAbstractProxyModelPrivate::_q_sourceModelDestroyed() { + invalidatePersistentIndexes(); model = QAbstractItemModelPrivate::staticEmptyModel(); } @@ -148,6 +149,15 @@ void QAbstractProxyModel::setSourceModel(QAbstractItemModel *sourceModel) } /*! + Clears the roleNames of this proxy model. +*/ +void QAbstractProxyModel::resetInternalData() +{ + Q_D(QAbstractProxyModel); + d->roleNames = d->model->roleNames(); +} + +/*! Returns the model that contains the data that is available through the proxy model. */ QAbstractItemModel *QAbstractProxyModel::sourceModel() const @@ -262,8 +272,7 @@ QVariant QAbstractProxyModel::headerData(int section, Qt::Orientation orientatio */ QMap<int, QVariant> QAbstractProxyModel::itemData(const QModelIndex &proxyIndex) const { - Q_D(const QAbstractProxyModel); - return d->model->itemData(mapToSource(proxyIndex)); + return QAbstractItemModel::itemData(proxyIndex); } /*! @@ -289,8 +298,7 @@ bool QAbstractProxyModel::setData(const QModelIndex &index, const QVariant &valu */ bool QAbstractProxyModel::setItemData(const QModelIndex &index, const QMap< int, QVariant >& roles) { - Q_D(QAbstractProxyModel); - return d->model->setItemData(mapToSource(index), roles); + return QAbstractItemModel::setItemData(index, roles); } /*! diff --git a/src/corelib/itemmodels/qabstractproxymodel.h b/src/corelib/itemmodels/qabstractproxymodel.h index e7a47214f8..9b26d6cead 100644 --- a/src/corelib/itemmodels/qabstractproxymodel.h +++ b/src/corelib/itemmodels/qabstractproxymodel.h @@ -44,8 +44,6 @@ #include <QtCore/qabstractitemmodel.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -103,6 +101,9 @@ Q_SIGNALS: #endif ); +protected Q_SLOTS: + void resetInternalData(); + protected: QAbstractProxyModel(QAbstractProxyModelPrivate &, QObject *parent); @@ -116,6 +117,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QABSTRACTPROXYMODEL_H diff --git a/src/corelib/itemmodels/qidentityproxymodel.h b/src/corelib/itemmodels/qidentityproxymodel.h index 4125683f77..8a416c97bc 100644 --- a/src/corelib/itemmodels/qidentityproxymodel.h +++ b/src/corelib/itemmodels/qidentityproxymodel.h @@ -47,8 +47,6 @@ #ifndef QT_NO_IDENTITYPROXYMODEL -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -113,8 +111,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_IDENTITYPROXYMODEL #endif // QIDENTITYPROXYMODEL_H diff --git a/src/corelib/itemmodels/qitemselectionmodel.h b/src/corelib/itemmodels/qitemselectionmodel.h index dd5f6061cd..2a1a4b0a2d 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.h +++ b/src/corelib/itemmodels/qitemselectionmodel.h @@ -47,8 +47,6 @@ #include <QtCore/qlist.h> #include <QtCore/qabstractitemmodel.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -253,6 +251,4 @@ Q_CORE_EXPORT QDebug operator<<(QDebug, const QItemSelectionRange &); QT_END_NAMESPACE -QT_END_HEADER - #endif // QITEMSELECTIONMODEL_H diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.cpp b/src/corelib/itemmodels/qsortfilterproxymodel.cpp index e5bdd83dc3..67b0d98402 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.cpp +++ b/src/corelib/itemmodels/qsortfilterproxymodel.cpp @@ -295,7 +295,8 @@ typedef QHash<QModelIndex, QSortFilterProxyModelPrivate::Mapping *> IndexMap; void QSortFilterProxyModelPrivate::_q_sourceModelDestroyed() { QAbstractProxyModelPrivate::_q_sourceModelDestroyed(); - _q_clearMapping(); + qDeleteAll(source_index_mapping); + source_index_mapping.clear(); } void QSortFilterProxyModelPrivate::remove_from_mapping(const QModelIndex &source_parent) diff --git a/src/corelib/itemmodels/qsortfilterproxymodel.h b/src/corelib/itemmodels/qsortfilterproxymodel.h index ffebec5283..a37c892c6c 100644 --- a/src/corelib/itemmodels/qsortfilterproxymodel.h +++ b/src/corelib/itemmodels/qsortfilterproxymodel.h @@ -48,8 +48,6 @@ #include <QtCore/qregexp.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -198,8 +196,6 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QT_NO_SORTFILTERPROXYMODEL #endif // QSORTFILTERPROXYMODEL_H diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index c6fabfcaee..31c9137c79 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -170,9 +170,9 @@ QVariant QStringListModel::data(const QModelIndex &index, int role) const Qt::ItemFlags QStringListModel::flags(const QModelIndex &index) const { if (!index.isValid()) - return QAbstractItemModel::flags(index) | Qt::ItemIsDropEnabled; + return QAbstractListModel::flags(index) | Qt::ItemIsDropEnabled; - return QAbstractItemModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; + return QAbstractListModel::flags(index) | Qt::ItemIsEditable | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled; } /*! diff --git a/src/corelib/itemmodels/qstringlistmodel.h b/src/corelib/itemmodels/qstringlistmodel.h index 22e9294f74..3514b27508 100644 --- a/src/corelib/itemmodels/qstringlistmodel.h +++ b/src/corelib/itemmodels/qstringlistmodel.h @@ -45,8 +45,6 @@ #include <QtCore/qabstractitemmodel.h> #include <QtCore/qstringlist.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -86,6 +84,4 @@ private: QT_END_NAMESPACE -QT_END_HEADER - #endif // QSTRINGLISTMODEL_H |