26 #include <QtGui/QtGui>
28 Q_DECLARE_METATYPE(QModelIndex)
35 : QObject(parent), model(_model), fetchingMore(false)
40 SIGNAL(columnsAboutToBeInserted(
const QModelIndex&,
int,
int)),
41 this, SLOT(runAllTests()));
43 SIGNAL(columnsAboutToBeRemoved(
const QModelIndex&,
int,
int)),
this,
45 connect(model, SIGNAL(columnsInserted(
const QModelIndex&,
int,
int)),
this,
47 connect(model, SIGNAL(columnsRemoved(
const QModelIndex&,
int,
int)),
this,
49 connect(model, SIGNAL(dataChanged(
const QModelIndex&,
const QModelIndex&)),
50 this, SLOT(runAllTests()));
51 connect(model, SIGNAL(headerDataChanged(
Qt::Orientation,
int,
int)),
this,
53 connect(model, SIGNAL(layoutAboutToBeChanged()),
this, SLOT(runAllTests()));
54 connect(model, SIGNAL(layoutChanged()),
this, SLOT(runAllTests()));
55 connect(model, SIGNAL(modelReset()),
this, SLOT(runAllTests()));
56 connect(model, SIGNAL(rowsAboutToBeInserted(
const QModelIndex&,
int,
int)),
57 this, SLOT(runAllTests()));
58 connect(model, SIGNAL(rowsAboutToBeRemoved(
const QModelIndex&,
int,
int)),
59 this, SLOT(runAllTests()));
60 connect(model, SIGNAL(rowsInserted(
const QModelIndex&,
int,
int)),
this,
62 connect(model, SIGNAL(rowsRemoved(
const QModelIndex&,
int,
int)),
this,
66 connect(model, SIGNAL(layoutAboutToBeChanged()),
this,
67 SLOT(layoutAboutToBeChanged()));
68 connect(model, SIGNAL(layoutChanged()),
this, SLOT(layoutChanged()));
70 connect(model, SIGNAL(rowsAboutToBeInserted(
const QModelIndex&,
int,
int)),
71 this, SLOT(rowsAboutToBeInserted(
const QModelIndex&,
int,
int)));
72 connect(model, SIGNAL(rowsAboutToBeRemoved(
const QModelIndex&,
int,
int)),
73 this, SLOT(rowsAboutToBeRemoved(
const QModelIndex&,
int,
int)));
74 connect(model, SIGNAL(rowsInserted(
const QModelIndex&,
int,
int)),
this,
75 SLOT(rowsInserted(
const QModelIndex&,
int,
int)));
76 connect(model, SIGNAL(rowsRemoved(
const QModelIndex&,
int,
int)),
this,
77 SLOT(rowsRemoved(
const QModelIndex&,
int,
int)));
102 Q_ASSERT(
model->buddy(QModelIndex()) == QModelIndex());
103 model->canFetchMore(QModelIndex());
104 Q_ASSERT(
model->columnCount(QModelIndex()) >= 0);
105 Q_ASSERT(
model->data(QModelIndex()) == QVariant());
107 model->fetchMore(QModelIndex());
109 Qt::ItemFlags flags =
model->flags(QModelIndex());
110 Q_ASSERT(flags == Qt::ItemIsDropEnabled || flags == 0);
111 model->hasChildren(QModelIndex());
112 model->hasIndex(0, 0);
113 model->headerData(0, Qt::Horizontal);
115 Q_ASSERT(
model->index(-1, -1) == QModelIndex());
116 model->itemData(QModelIndex());
118 model->match(QModelIndex(), -1, cache);
120 Q_ASSERT(
model->parent(QModelIndex()) == QModelIndex());
121 Q_ASSERT(
model->rowCount() >= 0);
123 model->setData(QModelIndex(), variant, -1);
124 model->setHeaderData(-1, Qt::Horizontal, QVariant());
125 model->setHeaderData(0, Qt::Horizontal, QVariant());
126 model->setHeaderData(999999, Qt::Horizontal, QVariant());
127 QMap<int, QVariant> roles;
128 model->sibling(0, 0, QModelIndex());
129 model->span(QModelIndex());
130 model->supportedDropActions();
142 QModelIndex topIndex =
model->index(0, 0, QModelIndex());
143 int rows =
model->rowCount(topIndex);
146 Q_ASSERT(
model->hasChildren(topIndex) ==
true);
148 QModelIndex secondLevelIndex =
model->index(0, 0, topIndex);
149 if (secondLevelIndex.isValid())
151 rows =
model->rowCount(secondLevelIndex);
154 Q_ASSERT(
model->hasChildren(secondLevelIndex) ==
true);
168 QModelIndex topIndex =
model->index(0, 0, QModelIndex());
169 Q_ASSERT(
model->columnCount(topIndex) >= 0);
172 QModelIndex childIndex =
model->index(0, 0, topIndex);
173 if (childIndex.isValid())
174 Q_ASSERT(
model->columnCount(childIndex) >= 0);
186 Q_ASSERT(
model->hasIndex(-2, -2) ==
false);
187 Q_ASSERT(
model->hasIndex(-2, 0) ==
false);
188 Q_ASSERT(
model->hasIndex(0, -2) ==
false);
190 int rows =
model->rowCount();
191 int columns =
model->columnCount();
194 Q_ASSERT(
model->hasIndex(rows, columns) ==
false);
195 Q_ASSERT(
model->hasIndex(rows + 1, columns + 1) ==
false);
198 Q_ASSERT(
model->hasIndex(0, 0) ==
true);
210 Q_ASSERT(
model->index(-2, -2) == QModelIndex());
211 Q_ASSERT(
model->index(-2, 0) == QModelIndex());
212 Q_ASSERT(
model->index(0, -2) == QModelIndex());
214 int rows =
model->rowCount();
215 int columns =
model->columnCount();
221 Q_ASSERT(
model->index(rows, columns) == QModelIndex());
222 Q_ASSERT(
model->index(0, 0).isValid() ==
true);
225 QModelIndex a =
model->index(0, 0);
226 QModelIndex b =
model->index(0, 0);
240 Q_ASSERT(
model->parent(QModelIndex()) == QModelIndex());
242 if (
model->rowCount() == 0)
252 QModelIndex topIndex =
model->index(0, 0, QModelIndex());
253 Q_ASSERT(
model->parent(topIndex) == QModelIndex());
257 if (
model->rowCount(topIndex) > 0)
259 QModelIndex childIndex =
model->index(0, 0, topIndex);
260 Q_ASSERT(
model->parent(childIndex) == topIndex);
266 QModelIndex topIndex1 =
model->index(0, 1, QModelIndex());
267 if (
model->rowCount(topIndex1) > 0)
269 QModelIndex childIndex =
model->index(0, 0, topIndex);
270 QModelIndex childIndex1 =
model->index(0, 0, topIndex1);
271 Q_ASSERT(childIndex != childIndex1);
316 Q_ASSERT(columns >= 0);
324 Q_ASSERT(
model->hasIndex(rows + 1, 0,
parent) ==
false);
325 for (
int r = 0;
r < rows; ++
r)
333 Q_ASSERT(
model->hasIndex(
r, columns + 1,
parent) ==
false);
334 for (
int c = 0;
c < columns; ++
c)
339 Q_ASSERT(
index.isValid() ==
true);
344 Q_ASSERT(
index == modifiedIndex);
353 Q_ASSERT(
index.row() ==
r);
354 Q_ASSERT(
index.column() ==
c);
382 if (
model->hasChildren(
index) && currentDepth < 10)
392 Q_ASSERT(
index == newerIndex);
403 Q_ASSERT(!
model->data(QModelIndex()).isValid());
405 if (
model->rowCount() == 0)
409 Q_ASSERT(
model->index(0, 0).isValid());
412 Q_ASSERT(
model->setData(QModelIndex(), QLatin1String(
"foo"),
413 Qt::DisplayRole) ==
false);
416 QVariant variant =
model->data(
model->index(0, 0), Qt::ToolTipRole);
417 if (variant.isValid())
418 Q_ASSERT(variant.canConvert(QMetaType::QString)));
419 variant =
model->data(
model->index(0, 0), Qt::StatusTipRole);
420 if (variant.isValid())
421 Q_ASSERT(variant.canConvert(QMetaType::QString)));
422 variant =
model->data(
model->index(0, 0), Qt::WhatsThisRole);
423 if (variant.isValid())
424 Q_ASSERT(variant.canConvert(QMetaType::QString)));
427 variant =
model->data(
model->index(0, 0), Qt::SizeHintRole);
428 if (variant.isValid())
429 Q_ASSERT(variant.canConvert(QMetaType::QString)));
432 QVariant fontVariant =
model->data(
model->index(0, 0), Qt::FontRole);
433 if (fontVariant.isValid())
434 Q_ASSERT(fontVariant.canConvert(QMetaType::QFont)));
437 QVariant textAlignmentVariant =
438 model->data(
model->index(0, 0), Qt::TextAlignmentRole);
439 if (textAlignmentVariant.isValid())
441 int alignment = textAlignmentVariant.toInt();
443 alignment == Qt::AlignLeft || alignment == Qt::AlignRight ||
444 alignment == Qt::AlignHCenter || alignment == Qt::AlignJustify ||
445 alignment == Qt::AlignTop || alignment == Qt::AlignBottom ||
446 alignment == Qt::AlignVCenter || alignment == Qt::AlignCenter ||
447 alignment == Qt::AlignAbsolute || alignment == Qt::AlignLeading ||
448 alignment == Qt::AlignTrailing);
452 QVariant colorVariant =
453 model->data(
model->index(0, 0), Qt::BackgroundColorRole);
454 if (colorVariant.isValid())
455 Q_ASSERT(colorVariant.canConvert(QMetaType::QColor)));
457 colorVariant =
model->data(
model->index(0, 0), Qt::TextColorRole);
458 if (colorVariant.isValid())
459 Q_ASSERT(colorVariant.canConvert(QMetaType::QColor)));
462 QVariant checkStateVariant =
463 model->data(
model->index(0, 0), Qt::CheckStateRole);
464 if (checkStateVariant.isValid())
466 int state = checkStateVariant.toInt();
467 Q_ASSERT(state == Qt::Unchecked || state == Qt::PartiallyChecked ||
468 state == Qt::Checked);
498 Q_ASSERT(
c.oldSize + (end - start + 1) ==
model->rowCount(
parent));
499 Q_ASSERT(
c.last ==
model->data(
model->index(start - 1, 0,
c.parent)));
508 Q_ASSERT(
c.next ==
model->data(
model->index(end + 1, 0,
c.parent)));
513 for (
int i = 0; i < qBound(0,
model->rowCount(), 100); ++i)
519 for (
int i = 0; i <
changing.count(); ++i)
522 Q_ASSERT(
p ==
model->index(
p.row(),
p.column(),
p.parent()));
552 Q_ASSERT(
c.oldSize - (end - start + 1) ==
model->rowCount(
parent));
553 Q_ASSERT(
c.last ==
model->data(
model->index(start - 1, 0,
c.parent)));
554 Q_ASSERT(
c.next ==
model->data(
model->index(start, 0,
c.parent)));
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
void nonDestructiveBasicTest()
QAbstractItemModel * model
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
void layoutAboutToBeChanged()
void checkChildren(const QModelIndex &parent, int currentDepth=0)
QList< QPersistentModelIndex > changing
void rowsRemoved(const QModelIndex &parent, int start, int end)
QStack< Changing > remove
QStack< Changing > insert
void rowsInserted(const QModelIndex &parent, int start, int end)