Add hint API to QAIM::layout*Change signals.

Usually layoutChange is used for sorting elements. The parents parameter
to the signal already hints at a localization of what is being sorted, if
it's just one level in the tree. The new hints enum can be used to only
consider how the first column of a table gets sorted, because all other
columns will be sorted the same way.

Change-Id: I65dd2996894bbdb45a2f6288edbeaa49e4053256
Reviewed-by: David Faure <faure@kde.org>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
bb10
Stephen Kelly 2012-09-27 11:08:18 +02:00 committed by The Qt Project
parent 9801b2c996
commit a3ec5d5729
2 changed files with 29 additions and 7 deletions

View File

@ -1322,9 +1322,20 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent,
\sa headerData(), setHeaderData(), dataChanged()
*/
/*!
\fn void QAbstractItemModel::layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>())
\since 4.2
\enum QAbstractItemModel::LayoutChangeHint
This enum describes the way the model changes layout.
\value NoLayoutChangeHint No hint is available.
\value VerticalSortHint Rows are being sorted.
\value HorizontalSortHint Columns are being sorted.
*/
/*!
\fn void QAbstractItemModel::layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint)
\since 5.0
This signal is emitted just before the layout of a model is changed.
Components connected to this signal use it to adapt to changes in the
@ -1335,13 +1346,15 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent,
The optional \a parents parameter is used to give a more specific notification
about what parts of the layout of the model are changing. An empty list indicates
a change to the layout of the entire model.
a change to the layout of the entire model. The order of elements in the \a parents list is not significant. The optional \a hint parameter is used
to give a hint about what is happening while the model is relayouting.
\sa layoutChanged(), changePersistentIndex()
*/
/*!
\fn void QAbstractItemModel::layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>())
\fn void QAbstractItemModel::layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint)
\since 5.0
This signal is emitted whenever the layout of items exposed by the model
has changed; for example, when the model has been sorted. When this signal
@ -1355,7 +1368,8 @@ void QAbstractItemModelPrivate::columnsRemoved(const QModelIndex &parent,
The optional \a parents parameter is used to give a more specific notification
about what parts of the layout of the model are changing. An empty list indicates
a change to the layout of the entire model.
a change to the layout of the entire model. The order of elements in the \a parents list is not significant. The optional \a hint parameter is used
to give a hint about what is happening while the model is relayouting.
Subclasses should update any persistent model indexes before emitting
layoutChanged(). In other words, when the structure changes:

View File

@ -156,6 +156,7 @@ template <class Key, class T> class QMap;
class Q_CORE_EXPORT QAbstractItemModel : public QObject
{
Q_OBJECT
Q_ENUMS(LayoutChangeHints)
friend class QPersistentModelIndexData;
friend class QAbstractItemViewPrivate;
@ -237,11 +238,18 @@ public:
using QObject::parent;
#endif
enum LayoutChangeHint
{
NoLayoutChangeHint,
VerticalSortHint,
HorizontalSortHint
};
Q_SIGNALS:
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
void headerDataChanged(Qt::Orientation orientation, int first, int last);
void layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>());
void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>());
void layoutChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
void layoutAboutToBeChanged(const QList<QPersistentModelIndex> &parents = QList<QPersistentModelIndex>(), QAbstractItemModel::LayoutChangeHint hint = QAbstractItemModel::NoLayoutChangeHint);
void rowsAboutToBeInserted(const QModelIndex &parent, int first, int last
#if !defined(qdoc)