Add tests to QAbstractItemModelTester checking only one change in flight
This patch adds checks to QAbstractItemModelTester checking that only one change is in flight at a time. Change-Id: I15fe1ad1274649aa652ed6489a889df72c8a8292 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>bb10
parent
3ab49ee040
commit
2f6faca901
|
|
@ -77,10 +77,28 @@ public:
|
|||
void data();
|
||||
|
||||
void runAllTests();
|
||||
|
||||
void layoutAboutToBeChanged();
|
||||
void layoutChanged();
|
||||
|
||||
void modelAboutToBeReset();
|
||||
void modelReset();
|
||||
|
||||
void columnsAboutToBeInserted(const QModelIndex &parent, int first, int last);
|
||||
void columnsInserted(const QModelIndex &parent, int first, int last);
|
||||
void columnsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd,
|
||||
const QModelIndex &destinationParent, int destinationColumn);
|
||||
void columnsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination,
|
||||
int column);
|
||||
void columnsAboutToBeRemoved(const QModelIndex &parent, int first, int last);
|
||||
void columnsRemoved(const QModelIndex &parent, int first, int last);
|
||||
|
||||
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
|
||||
void rowsInserted(const QModelIndex &parent, int start, int end);
|
||||
void rowsAboutToBeMoved(const QModelIndex &sourceParent, int sourceStart, int sourceEnd,
|
||||
const QModelIndex &destinationParent, int destinationRow);
|
||||
void rowsMoved(const QModelIndex &parent, int start, int end, const QModelIndex &destination,
|
||||
int row);
|
||||
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
|
||||
void rowsRemoved(const QModelIndex &parent, int start, int end);
|
||||
void dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight);
|
||||
|
|
@ -110,6 +128,19 @@ private:
|
|||
|
||||
bool fetchingMore;
|
||||
|
||||
enum class ChangeInFlight {
|
||||
None,
|
||||
ColumnsInserted,
|
||||
ColumnsMoved,
|
||||
ColumnsRemoved,
|
||||
LayoutChanged,
|
||||
ModelReset,
|
||||
RowsInserted,
|
||||
RowsMoved,
|
||||
RowsRemoved
|
||||
};
|
||||
ChangeInFlight changeInFlight = ChangeInFlight::None;
|
||||
|
||||
QList<QPersistentModelIndex> changing;
|
||||
};
|
||||
|
||||
|
|
@ -252,14 +283,45 @@ QAbstractItemModelTester::QAbstractItemModelTester(QAbstractItemModel *model, Fa
|
|||
connect(model, &QAbstractItemModel::layoutChanged,
|
||||
this, [d]{ d->layoutChanged(); });
|
||||
|
||||
// column operations
|
||||
connect(model, &QAbstractItemModel::columnsAboutToBeInserted,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->columnsAboutToBeInserted(parent, start, end); });
|
||||
connect(model, &QAbstractItemModel::columnsAboutToBeMoved,
|
||||
this, [d](const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationColumn) {
|
||||
d->columnsAboutToBeMoved(sourceParent, sourceStart, sourceEnd, destinationParent, destinationColumn); });
|
||||
connect(model, &QAbstractItemModel::columnsAboutToBeRemoved,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->columnsAboutToBeRemoved(parent, start, end); });
|
||||
connect(model, &QAbstractItemModel::columnsInserted,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->columnsInserted(parent, start, end); });
|
||||
connect(model, &QAbstractItemModel::columnsMoved,
|
||||
this, [d](const QModelIndex &parent, int start, int end, const QModelIndex &destination, int col) {
|
||||
d->columnsMoved(parent, start, end, destination, col); });
|
||||
connect(model, &QAbstractItemModel::columnsRemoved,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->columnsRemoved(parent, start, end); });
|
||||
|
||||
// row operations
|
||||
connect(model, &QAbstractItemModel::rowsAboutToBeInserted,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->rowsAboutToBeInserted(parent, start, end); });
|
||||
connect(model, &QAbstractItemModel::rowsAboutToBeMoved,
|
||||
this, [d](const QModelIndex &sourceParent, int sourceStart, int sourceEnd, const QModelIndex &destinationParent, int destinationRow) {
|
||||
d->rowsAboutToBeMoved(sourceParent, sourceStart, sourceEnd, destinationParent, destinationRow); });
|
||||
connect(model, &QAbstractItemModel::rowsAboutToBeRemoved,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->rowsAboutToBeRemoved(parent, start, end); });
|
||||
connect(model, &QAbstractItemModel::rowsInserted,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->rowsInserted(parent, start, end); });
|
||||
connect(model, &QAbstractItemModel::rowsMoved,
|
||||
this, [d](const QModelIndex &parent, int start, int end, const QModelIndex &destination, int row) {
|
||||
d->rowsMoved(parent, start, end, destination, row); });
|
||||
connect(model, &QAbstractItemModel::rowsRemoved,
|
||||
this, [d](const QModelIndex &parent, int start, int end) { d->rowsRemoved(parent, start, end); });
|
||||
|
||||
// reset
|
||||
connect(model, &QAbstractItemModel::modelAboutToBeReset,
|
||||
this, [d]() { d->modelAboutToBeReset(); });
|
||||
connect(model, &QAbstractItemModel::modelReset,
|
||||
this, [d]() { d->modelReset(); });
|
||||
|
||||
// data
|
||||
connect(model, &QAbstractItemModel::dataChanged,
|
||||
this, [d](const QModelIndex &topLeft, const QModelIndex &bottomRight) { d->dataChanged(topLeft, bottomRight); });
|
||||
connect(model, &QAbstractItemModel::headerDataChanged,
|
||||
|
|
@ -631,6 +693,89 @@ void QAbstractItemModelTesterPrivate::data()
|
|||
return;
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::columnsAboutToBeInserted(const QModelIndex &parent, int start,
|
||||
int end)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::ColumnsInserted;
|
||||
|
||||
qCDebug(lcModelTest) << "columnsAboutToBeInserted"
|
||||
<< "start=" << start << "end=" << end << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
<< "current count of parent=" << model->rowCount(parent)
|
||||
<< "last before insertion=" << model->index(start - 1, 0, parent)
|
||||
<< model->data(model->index(start - 1, 0, parent));
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::columnsInserted(const QModelIndex &parent, int first,
|
||||
int last)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::ColumnsInserted);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
qCDebug(lcModelTest) << "columnsInserted"
|
||||
<< "start=" << first << "end=" << last << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
<< "current count of parent=" << model->rowCount(parent);
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::columnsAboutToBeMoved(const QModelIndex &sourceParent,
|
||||
int sourceStart, int sourceEnd,
|
||||
const QModelIndex &destinationParent,
|
||||
int destinationColumn)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::ColumnsMoved;
|
||||
|
||||
qCDebug(lcModelTest) << "columnsAboutToBeMoved"
|
||||
<< "sourceStart=" << sourceStart << "sourceEnd=" << sourceEnd
|
||||
<< "sourceParent=" << sourceParent
|
||||
<< "sourceParent data=" << model->data(sourceParent).toString()
|
||||
<< "destinationParent=" << destinationParent
|
||||
<< "destinationColumn=" << destinationColumn;
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::columnsMoved(const QModelIndex &sourceParent, int sourceStart,
|
||||
int sourceEnd,
|
||||
const QModelIndex &destinationParent,
|
||||
int destinationColumn)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::ColumnsMoved);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
qCDebug(lcModelTest) << "columnsAboutToBeMoved"
|
||||
<< "sourceStart=" << sourceStart << "sourceEnd=" << sourceEnd
|
||||
<< "sourceParent=" << sourceParent
|
||||
<< "sourceParent data=" << model->data(sourceParent).toString()
|
||||
<< "destinationParent=" << destinationParent
|
||||
<< "destinationColumn=" << destinationColumn;
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::columnsAboutToBeRemoved(const QModelIndex &parent, int first,
|
||||
int last)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::ColumnsRemoved;
|
||||
|
||||
qCDebug(lcModelTest) << "columnsAboutToBeRemoved"
|
||||
<< "start=" << first << "end=" << last << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
<< "current count of parent=" << model->rowCount(parent)
|
||||
<< "last before removal=" << model->index(first - 1, 0, parent)
|
||||
<< model->data(model->index(first - 1, 0, parent));
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::columnsRemoved(const QModelIndex &parent, int first, int last)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::ColumnsRemoved);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
qCDebug(lcModelTest) << "columnsRemoved"
|
||||
<< "start=" << first << "end=" << last << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
<< "current count of parent=" << model->rowCount(parent);
|
||||
}
|
||||
|
||||
/*
|
||||
Store what is about to be inserted to make sure it actually happens
|
||||
|
||||
|
|
@ -638,6 +783,9 @@ void QAbstractItemModelTesterPrivate::data()
|
|||
*/
|
||||
void QAbstractItemModelTesterPrivate::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::RowsInserted;
|
||||
|
||||
qCDebug(lcModelTest) << "rowsAboutToBeInserted"
|
||||
<< "start=" << start << "end=" << end << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
|
|
@ -659,6 +807,9 @@ void QAbstractItemModelTesterPrivate::rowsAboutToBeInserted(const QModelIndex &p
|
|||
*/
|
||||
void QAbstractItemModelTesterPrivate::rowsInserted(const QModelIndex &parent, int start, int end)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::RowsInserted);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
qCDebug(lcModelTest) << "rowsInserted"
|
||||
<< "start=" << start << "end=" << end << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
|
|
@ -689,14 +840,51 @@ void QAbstractItemModelTesterPrivate::rowsInserted(const QModelIndex &parent, in
|
|||
}
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::rowsAboutToBeMoved(const QModelIndex &sourceParent,
|
||||
int sourceStart, int sourceEnd,
|
||||
const QModelIndex &destinationParent,
|
||||
int destinationRow)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::RowsMoved;
|
||||
|
||||
qCDebug(lcModelTest) << "rowsAboutToBeMoved"
|
||||
<< "sourceStart=" << sourceStart << "sourceEnd=" << sourceEnd
|
||||
<< "sourceParent=" << sourceParent
|
||||
<< "sourceParent data=" << model->data(sourceParent).toString()
|
||||
<< "destinationParent=" << destinationParent
|
||||
<< "destinationColumn=" << destinationRow;
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::rowsMoved(const QModelIndex &sourceParent, int sourceStart,
|
||||
int sourceEnd, const QModelIndex &destinationParent,
|
||||
int destinationRow)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::RowsMoved);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
qCDebug(lcModelTest) << "rowsMoved"
|
||||
<< "sourceStart=" << sourceStart << "sourceEnd=" << sourceEnd
|
||||
<< "sourceParent=" << sourceParent
|
||||
<< "sourceParent data=" << model->data(sourceParent).toString()
|
||||
<< "destinationParent=" << destinationParent
|
||||
<< "destinationColumn=" << destinationRow;
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::layoutAboutToBeChanged()
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::LayoutChanged;
|
||||
|
||||
for (int i = 0; i < qBound(0, model->rowCount(), 100); ++i)
|
||||
changing.append(QPersistentModelIndex(model->index(i, 0)));
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::layoutChanged()
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::LayoutChanged);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
for (int i = 0; i < changing.count(); ++i) {
|
||||
QPersistentModelIndex p = changing[i];
|
||||
MODELTESTER_COMPARE(model->index(p.row(), p.column(), p.parent()), QModelIndex(p));
|
||||
|
|
@ -704,6 +892,18 @@ void QAbstractItemModelTesterPrivate::layoutChanged()
|
|||
changing.clear();
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::modelAboutToBeReset()
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::ModelReset;
|
||||
}
|
||||
|
||||
void QAbstractItemModelTesterPrivate::modelReset()
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::ModelReset);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
}
|
||||
|
||||
/*
|
||||
Store what is about to be inserted to make sure it actually happens
|
||||
|
||||
|
|
@ -711,6 +911,9 @@ void QAbstractItemModelTesterPrivate::layoutChanged()
|
|||
*/
|
||||
void QAbstractItemModelTesterPrivate::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::None);
|
||||
changeInFlight = ChangeInFlight::RowsRemoved;
|
||||
|
||||
qCDebug(lcModelTest) << "rowsAboutToBeRemoved"
|
||||
<< "start=" << start << "end=" << end << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
|
|
@ -741,6 +944,9 @@ void QAbstractItemModelTesterPrivate::rowsAboutToBeRemoved(const QModelIndex &pa
|
|||
*/
|
||||
void QAbstractItemModelTesterPrivate::rowsRemoved(const QModelIndex &parent, int start, int end)
|
||||
{
|
||||
MODELTESTER_COMPARE(changeInFlight, ChangeInFlight::RowsRemoved);
|
||||
changeInFlight = ChangeInFlight::None;
|
||||
|
||||
qCDebug(lcModelTest) << "rowsRemoved"
|
||||
<< "start=" << start << "end=" << end << "parent=" << parent
|
||||
<< "parent data=" << model->data(parent).toString()
|
||||
|
|
|
|||
Loading…
Reference in New Issue