From f9caf48beebb935c7c1ca71745b2646b872b65d1 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 7 Jun 2012 10:39:42 +0200 Subject: Use a QVector instead of a QSet in itemviews/models. The QSet 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 Reviewed-by: Olivier Goffart --- examples/itemviews/chart/pieview.cpp | 2 +- examples/itemviews/chart/pieview.h | 2 +- src/corelib/itemmodels/qabstractitemmodel.cpp | 9 +++++---- src/corelib/itemmodels/qabstractitemmodel.h | 4 ++-- src/widgets/itemviews/qabstractitemdelegate.cpp | 4 ++-- src/widgets/itemviews/qabstractitemdelegate.h | 2 +- src/widgets/itemviews/qabstractitemview.cpp | 10 +++++----- src/widgets/itemviews/qabstractitemview.h | 2 +- src/widgets/itemviews/qdatawidgetmapper.cpp | 12 ++++++------ src/widgets/itemviews/qdatawidgetmapper.h | 2 +- src/widgets/itemviews/qheaderview.cpp | 2 +- src/widgets/itemviews/qheaderview.h | 2 +- src/widgets/itemviews/qlistview.cpp | 2 +- src/widgets/itemviews/qlistview.h | 2 +- src/widgets/itemviews/qtreeview.cpp | 2 +- src/widgets/itemviews/qtreeview.h | 2 +- .../qabstractitemmodel/tst_qabstractitemmodel.cpp | 14 ++++++-------- 17 files changed, 37 insertions(+), 38 deletions(-) diff --git a/examples/itemviews/chart/pieview.cpp b/examples/itemviews/chart/pieview.cpp index 7305181b44..30f3255689 100644 --- a/examples/itemviews/chart/pieview.cpp +++ b/examples/itemviews/chart/pieview.cpp @@ -63,7 +63,7 @@ PieView::PieView(QWidget *parent) void PieView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, - const QSet &) + const QVector &) { QAbstractItemView::dataChanged(topLeft, bottomRight); diff --git a/examples/itemviews/chart/pieview.h b/examples/itemviews/chart/pieview.h index 7ee48565e8..208159bf73 100644 --- a/examples/itemviews/chart/pieview.h +++ b/examples/itemviews/chart/pieview.h @@ -68,7 +68,7 @@ public: QModelIndex indexAt(const QPoint &point) const; protected slots: - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector & = QVector()); void rowsInserted(const QModelIndex &parent, int start, int end); void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp index dc53021432..0b390341e4 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.cpp +++ b/src/corelib/itemmodels/qabstractitemmodel.cpp @@ -1416,7 +1416,7 @@ QAbstractItemModel::~QAbstractItemModel() */ /*! - \fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &roles = QSet()) + \fn void QAbstractItemModel::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()) 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() */ diff --git a/src/corelib/itemmodels/qabstractitemmodel.h b/src/corelib/itemmodels/qabstractitemmodel.h index ff96fe53d6..976c1600c6 100644 --- a/src/corelib/itemmodels/qabstractitemmodel.h +++ b/src/corelib/itemmodels/qabstractitemmodel.h @@ -45,7 +45,7 @@ #include #include #include -#include +#include QT_BEGIN_HEADER @@ -243,7 +243,7 @@ public: #endif Q_SIGNALS: - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &roles = QSet()); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void headerDataChanged(Qt::Orientation orientation, int first, int last); void layoutChanged(const QList &parents = QList()); void layoutAboutToBeChanged(const QList &parents = QList()); diff --git a/src/widgets/itemviews/qabstractitemdelegate.cpp b/src/widgets/itemviews/qabstractitemdelegate.cpp index 21c67cb297..92cf0b0c38 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.cpp +++ b/src/widgets/itemviews/qabstractitemdelegate.cpp @@ -407,9 +407,9 @@ bool QAbstractItemDelegate::helpEvent(QHelpEvent *event, This virtual method is reserved and will be used in Qt 5.1. */ -QSet QAbstractItemDelegate::paintingRoles() const +QVector QAbstractItemDelegate::paintingRoles() const { - return QSet(); + return QVector(); } QT_END_NAMESPACE diff --git a/src/widgets/itemviews/qabstractitemdelegate.h b/src/widgets/itemviews/qabstractitemdelegate.h index 89aa1915f6..69eca38562 100644 --- a/src/widgets/itemviews/qabstractitemdelegate.h +++ b/src/widgets/itemviews/qabstractitemdelegate.h @@ -114,7 +114,7 @@ public: const QStyleOptionViewItem &option, const QModelIndex &index); - virtual QSet paintingRoles() const; + virtual QVector paintingRoles() const; Q_SIGNALS: void commitData(QWidget *editor); diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index a53f3f1465..bd70e83aa3 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -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)), - this, SLOT(dataChanged(QModelIndex,QModelIndex,QSet))); + disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), + this, SLOT(dataChanged(QModelIndex,QModelIndex,QVector))); 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)), - this, SLOT(dataChanged(QModelIndex,QModelIndex,QSet))); + connect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), + this, SLOT(dataChanged(QModelIndex,QModelIndex,QVector))); 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 &) +void QAbstractItemView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &) { // Single item changed Q_D(QAbstractItemView); diff --git a/src/widgets/itemviews/qabstractitemview.h b/src/widgets/itemviews/qabstractitemview.h index 5bdd17e3ad..029d60f944 100644 --- a/src/widgets/itemviews/qabstractitemview.h +++ b/src/widgets/itemviews/qabstractitemview.h @@ -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 &roles = QSet()); + virtual void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); 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); diff --git a/src/widgets/itemviews/qdatawidgetmapper.cpp b/src/widgets/itemviews/qdatawidgetmapper.cpp index 4396519810..7e82e614af 100644 --- a/src/widgets/itemviews/qdatawidgetmapper.cpp +++ b/src/widgets/itemviews/qdatawidgetmapper.cpp @@ -104,7 +104,7 @@ public: void populate(); // private slots - void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &); + void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &); 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 &) +void QDataWidgetMapperPrivate::_q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &) { 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)), this, - SLOT(_q_dataChanged(QModelIndex,QModelIndex,QSet))); + disconnect(d->model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), this, + SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector))); 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)), - SLOT(_q_dataChanged(QModelIndex,QModelIndex,QSet))); + connect(model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector)), + SLOT(_q_dataChanged(QModelIndex,QModelIndex,QVector))); connect(model, SIGNAL(destroyed()), SLOT(_q_modelDestroyed())); } diff --git a/src/widgets/itemviews/qdatawidgetmapper.h b/src/widgets/itemviews/qdatawidgetmapper.h index 3cb8f09510..3a7e4fc591 100644 --- a/src/widgets/itemviews/qdatawidgetmapper.h +++ b/src/widgets/itemviews/qdatawidgetmapper.h @@ -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 &)) + Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &, const QModelIndex &, const QVector &)) 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()) diff --git a/src/widgets/itemviews/qheaderview.cpp b/src/widgets/itemviews/qheaderview.cpp index d8c53a3033..2269bde513 100644 --- a/src/widgets/itemviews/qheaderview.cpp +++ b/src/widgets/itemviews/qheaderview.cpp @@ -2717,7 +2717,7 @@ void QHeaderView::scrollContentsBy(int dx, int dy) \reimp \internal */ -void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &) +void QHeaderView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &) { Q_D(QHeaderView); d->invalidateCachedSizeHint(); diff --git a/src/widgets/itemviews/qheaderview.h b/src/widgets/itemviews/qheaderview.h index f3f5b95a04..6069eb99a1 100644 --- a/src/widgets/itemviews/qheaderview.h +++ b/src/widgets/itemviews/qheaderview.h @@ -226,7 +226,7 @@ protected: void updateGeometries(); void scrollContentsBy(int dx, int dy); - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &roles = QSet()); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void rowsInserted(const QModelIndex &parent, int start, int end); QRect visualRect(const QModelIndex &index) const; diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 147187d2ea..315960648b 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -728,7 +728,7 @@ QSize QListView::contentsSize() const /*! \reimp */ -void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &roles) +void QListView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { d_func()->commonListView->dataChanged(topLeft, bottomRight); QAbstractItemView::dataChanged(topLeft, bottomRight, roles); diff --git a/src/widgets/itemviews/qlistview.h b/src/widgets/itemviews/qlistview.h index 7b065b0585..2f864f27c5 100644 --- a/src/widgets/itemviews/qlistview.h +++ b/src/widgets/itemviews/qlistview.h @@ -146,7 +146,7 @@ protected: void resizeContents(int width, int height); QSize contentsSize() const; - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &roles = QSet()); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void rowsInserted(const QModelIndex &parent, int start, int end); void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end); diff --git a/src/widgets/itemviews/qtreeview.cpp b/src/widgets/itemviews/qtreeview.cpp index 62d94d0004..41f7543fd9 100644 --- a/src/widgets/itemviews/qtreeview.cpp +++ b/src/widgets/itemviews/qtreeview.cpp @@ -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 &roles) +void QTreeView::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles) { Q_D(QTreeView); diff --git a/src/widgets/itemviews/qtreeview.h b/src/widgets/itemviews/qtreeview.h index 72cfe1722d..97f1577a57 100644 --- a/src/widgets/itemviews/qtreeview.h +++ b/src/widgets/itemviews/qtreeview.h @@ -143,7 +143,7 @@ public: void sortByColumn(int column, Qt::SortOrder order); - void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QSet &roles = QSet()); + void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight, const QVector &roles = QVector()); void selectAll(); Q_SIGNALS: diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 28babdbacb..7d052b225b 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -1926,20 +1926,18 @@ public: const QModelIndex bottom = index(2, 0); emit dataChanged(top, bottom); - emit dataChanged(top, bottom, QSet() << Qt::ToolTipRole); - emit dataChanged(top, bottom, QSet() << Qt::ToolTipRole << Custom1); + emit dataChanged(top, bottom, QVector() << Qt::ToolTipRole); + emit dataChanged(top, bottom, QVector() << Qt::ToolTipRole << Custom1); } }; -Q_DECLARE_METATYPE(QSet) - void tst_QAbstractItemModel::testDataChanged() { - qRegisterMetaType >(); + qRegisterMetaType >(); CustomRoleModel model; - QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QSet))); + QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector))); 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 secondRoles = secondEmission.at(2).value >(); - const QSet thirdRoles = thirdEmission.at(2).value >(); + const QVector secondRoles = secondEmission.at(2).value >(); + const QVector thirdRoles = thirdEmission.at(2).value >(); QCOMPARE(secondRoles.size(), 1); QVERIFY(secondRoles.contains(Qt::ToolTipRole)); -- cgit v1.2.3