Use a QVector<int> instead of a QSet<int> in itemviews/models.
The QSet<int> is a more expensive container to use and create, so it should be avoided. This is source incompatible compared to earlier Qt 5 for QAbstractItemView subclasses which reimplement dataChanged, but this patch changes nothing compared to already-present SiC compared to Qt 4. Change-Id: Id95391dfd62a0a7f487a8765790b007badefb937 Reviewed-by: Lars Knoll <lars.knoll@nokia.com> Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
This commit is contained in:
parent
3df316e961
commit
f9caf48bee
@ -63,7 +63,7 @@ PieView::PieView(QWidget *parent)
|
||||
|
||||
void PieView::dataChanged(const QModelIndex &topLeft,
|
||||
const QModelIndex &bottomRight,
|
||||
const QSet<int> &)
|
||||
const QVector<int> &)
|
||||
{
|
||||
QAbstractItemView::dataChanged(topLeft, bottomRight);
|
||||
|
||||
|
@ -68,7 +68,7 @@ public:
|
||||
QModelIndex indexAt(const QPoint &point) const;
|
||||
|
||||
protected slots:
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &);
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> & = QVector<int>());
|
||||
void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
||||
|
||||
|
@ -1416,7 +1416,7 @@ QAbstractItemModel::~QAbstractItemModel()
|
||||
*/
|
||||
|
||||
/*!
|
||||
\fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles = QSet<int>())
|
||||
\fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>())
|
||||
|
||||
This signal is emitted whenever the data in an existing item changes.
|
||||
|
||||
@ -1427,9 +1427,10 @@ QAbstractItemModel::~QAbstractItemModel()
|
||||
When reimplementing the setData() function, this signal must be emitted
|
||||
explicitly.
|
||||
|
||||
The optional roles argument can be used to specify which data roles have actually
|
||||
been modified. An empty set in the roles argument means that all roles should be
|
||||
considered modified.
|
||||
The optional \a roles argument can be used to specify which data roles have actually
|
||||
been modified. An empty vector in the roles argument means that all roles should be
|
||||
considered modified. The order of elements in the roles argument does not have any
|
||||
relevance.
|
||||
|
||||
\sa headerDataChanged(), setData(), layoutChanged()
|
||||
*/
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QtCore/qobject.h>
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qset.h>
|
||||
#include <QtCore/qvector.h>
|
||||
|
||||
QT_BEGIN_HEADER
|
||||
|
||||
@ -243,7 +243,7 @@ public:
|
||||
#endif
|
||||
|
||||
Q_SIGNALS:
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles = QSet<int>());
|
||||
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>());
|
||||
|
@ -407,9 +407,9 @@ bool QAbstractItemDelegate::helpEvent(QHelpEvent *event,
|
||||
|
||||
This virtual method is reserved and will be used in Qt 5.1.
|
||||
*/
|
||||
QSet<int> QAbstractItemDelegate::paintingRoles() const
|
||||
QVector<int> QAbstractItemDelegate::paintingRoles() const
|
||||
{
|
||||
return QSet<int>();
|
||||
return QVector<int>();
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -114,7 +114,7 @@ public:
|
||||
const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index);
|
||||
|
||||
virtual QSet<int> paintingRoles() const;
|
||||
virtual QVector<int> paintingRoles() const;
|
||||
|
||||
Q_SIGNALS:
|
||||
void commitData(QWidget *editor);
|
||||
|
@ -673,8 +673,8 @@ void QAbstractItemView::setModel(QAbstractItemModel *model)
|
||||
if (d->model && d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
|
||||
disconnect(d->model, SIGNAL(destroyed()),
|
||||
this, SLOT(_q_modelDestroyed()));
|
||||
disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>)),
|
||||
this, SLOT(dataChanged(QModelIndex,QModelIndex,QSet<int>)));
|
||||
disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
|
||||
this, SLOT(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
|
||||
disconnect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
|
||||
this, SLOT(_q_headerDataChanged()));
|
||||
disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
||||
@ -713,8 +713,8 @@ void QAbstractItemView::setModel(QAbstractItemModel *model)
|
||||
if (d->model != QAbstractItemModelPrivate::staticEmptyModel()) {
|
||||
connect(d->model, SIGNAL(destroyed()),
|
||||
this, SLOT(_q_modelDestroyed()));
|
||||
connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>)),
|
||||
this, SLOT(dataChanged(QModelIndex,QModelIndex,QSet<int>)));
|
||||
connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
|
||||
this, SLOT(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
|
||||
connect(d->model, SIGNAL(headerDataChanged(Qt::Orientation,int,int)),
|
||||
this, SLOT(_q_headerDataChanged()));
|
||||
connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
|
||||
@ -3223,7 +3223,7 @@ void QAbstractItemView::update(const QModelIndex &index)
|
||||
inclusive. If just one item is changed \a topLeft == \a
|
||||
bottomRight.
|
||||
*/
|
||||
void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &)
|
||||
void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &)
|
||||
{
|
||||
// Single item changed
|
||||
Q_D(QAbstractItemView);
|
||||
|
@ -240,7 +240,7 @@ public Q_SLOTS:
|
||||
void update(const QModelIndex &index);
|
||||
|
||||
protected Q_SLOTS:
|
||||
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles = QSet<int>());
|
||||
virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
|
||||
virtual void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||
virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
||||
virtual void selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||
|
@ -104,7 +104,7 @@ public:
|
||||
void populate();
|
||||
|
||||
// private slots
|
||||
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &);
|
||||
void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &);
|
||||
void _q_commitData(QWidget *);
|
||||
void _q_closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint);
|
||||
void _q_modelDestroyed();
|
||||
@ -182,7 +182,7 @@ static bool qContainsIndex(const QModelIndex &idx, const QModelIndex &topLeft,
|
||||
&& idx.column() >= topLeft.column() && idx.column() <= bottomRight.column();
|
||||
}
|
||||
|
||||
void QDataWidgetMapperPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &)
|
||||
void QDataWidgetMapperPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &)
|
||||
{
|
||||
if (topLeft.parent() != rootIndex)
|
||||
return; // not in our hierarchy
|
||||
@ -369,8 +369,8 @@ void QDataWidgetMapper::setModel(QAbstractItemModel *model)
|
||||
return;
|
||||
|
||||
if (d->model) {
|
||||
disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>)), this,
|
||||
SLOT(_q_dataChanged(QModelIndex,QModelIndex,QSet<int>)));
|
||||
disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)), this,
|
||||
SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>)));
|
||||
disconnect(d->model, SIGNAL(destroyed()), this,
|
||||
SLOT(_q_modelDestroyed()));
|
||||
}
|
||||
@ -380,8 +380,8 @@ void QDataWidgetMapper::setModel(QAbstractItemModel *model)
|
||||
|
||||
d->model = model;
|
||||
|
||||
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>)),
|
||||
SLOT(_q_dataChanged(QModelIndex,QModelIndex,QSet<int>)));
|
||||
connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
|
||||
SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector<int>)));
|
||||
connect(model, SIGNAL(destroyed()), SLOT(_q_modelDestroyed()));
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ Q_SIGNALS:
|
||||
private:
|
||||
Q_DECLARE_PRIVATE(QDataWidgetMapper)
|
||||
Q_DISABLE_COPY(QDataWidgetMapper)
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &, const QSet<int> &))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &, const QVector<int> &))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_commitData(QWidget *))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_closeEditor(QWidget *, QAbstractItemDelegate::EndEditHint))
|
||||
Q_PRIVATE_SLOT(d_func(), void _q_modelDestroyed())
|
||||
|
@ -2717,7 +2717,7 @@ void QHeaderView::scrollContentsBy(int dx, int dy)
|
||||
\reimp
|
||||
\internal
|
||||
*/
|
||||
void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &)
|
||||
void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &)
|
||||
{
|
||||
Q_D(QHeaderView);
|
||||
d->invalidateCachedSizeHint();
|
||||
|
@ -226,7 +226,7 @@ protected:
|
||||
void updateGeometries();
|
||||
void scrollContentsBy(int dx, int dy);
|
||||
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles = QSet<int>());
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
|
||||
void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||
|
||||
QRect visualRect(const QModelIndex &index) const;
|
||||
|
@ -728,7 +728,7 @@ QSize QListView::contentsSize() const
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles)
|
||||
void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
{
|
||||
d_func()->commonListView->dataChanged(topLeft, bottomRight);
|
||||
QAbstractItemView::dataChanged(topLeft, bottomRight, roles);
|
||||
|
@ -146,7 +146,7 @@ protected:
|
||||
void resizeContents(int width, int height);
|
||||
QSize contentsSize() const;
|
||||
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles = QSet<int>());
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
|
||||
void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
||||
|
||||
|
@ -664,7 +664,7 @@ void QTreeView::setFirstColumnSpanned(int row, const QModelIndex &parent, bool s
|
||||
/*!
|
||||
\reimp
|
||||
*/
|
||||
void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles)
|
||||
void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles)
|
||||
{
|
||||
Q_D(QTreeView);
|
||||
|
||||
|
@ -143,7 +143,7 @@ public:
|
||||
|
||||
void sortByColumn(int column, Qt::SortOrder order);
|
||||
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet<int> &roles = QSet<int>());
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector<int> &roles = QVector<int>());
|
||||
void selectAll();
|
||||
|
||||
Q_SIGNALS:
|
||||
|
@ -1926,20 +1926,18 @@ public:
|
||||
const QModelIndex bottom = index(2, 0);
|
||||
|
||||
emit dataChanged(top, bottom);
|
||||
emit dataChanged(top, bottom, QSet<int>() << Qt::ToolTipRole);
|
||||
emit dataChanged(top, bottom, QSet<int>() << Qt::ToolTipRole << Custom1);
|
||||
emit dataChanged(top, bottom, QVector<int>() << Qt::ToolTipRole);
|
||||
emit dataChanged(top, bottom, QVector<int>() << Qt::ToolTipRole << Custom1);
|
||||
}
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(QSet<int>)
|
||||
|
||||
void tst_QAbstractItemModel::testDataChanged()
|
||||
{
|
||||
qRegisterMetaType<QSet<int> >();
|
||||
qRegisterMetaType<QVector<int> >();
|
||||
|
||||
CustomRoleModel model;
|
||||
|
||||
QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet<int>)));
|
||||
QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)));
|
||||
QSignalSpy withoutRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex)));
|
||||
|
||||
QVERIFY(withRoles.isValid());
|
||||
@ -1953,8 +1951,8 @@ void tst_QAbstractItemModel::testDataChanged()
|
||||
const QVariantList secondEmission = withRoles.at(1);
|
||||
const QVariantList thirdEmission = withRoles.at(2);
|
||||
|
||||
const QSet<int> secondRoles = secondEmission.at(2).value<QSet<int> >();
|
||||
const QSet<int> thirdRoles = thirdEmission.at(2).value<QSet<int> >();
|
||||
const QVector<int> secondRoles = secondEmission.at(2).value<QVector<int> >();
|
||||
const QVector<int> thirdRoles = thirdEmission.at(2).value<QVector<int> >();
|
||||
|
||||
QCOMPARE(secondRoles.size(), 1);
|
||||
QVERIFY(secondRoles.contains(Qt::ToolTipRole));
|
||||
|
Loading…
Reference in New Issue
Block a user