26 #include <config-kleopatra.h>
38 connect(model, SIGNAL(columnsAboutToBeInserted(
QModelIndex,
int,
int)),
39 this, SLOT(runAllTests()));
40 connect(model, SIGNAL(columnsAboutToBeRemoved(
QModelIndex,
int,
int)),
41 this, SLOT(runAllTests()));
42 connect(model, SIGNAL(columnsInserted(
QModelIndex,
int,
int)),
43 this, SLOT(runAllTests()));
44 connect(model, SIGNAL(columnsRemoved(
QModelIndex,
int,
int)),
45 this, SLOT(runAllTests()));
47 this, SLOT(runAllTests()));
48 connect(model, SIGNAL(headerDataChanged(Qt::Orientation,
int,
int)),
49 this, SLOT(runAllTests()));
50 connect(model, SIGNAL(layoutAboutToBeChanged()),
this, SLOT(runAllTests()));
51 connect(model, SIGNAL(layoutChanged()),
this, SLOT(runAllTests()));
52 connect(model, SIGNAL(modelReset()),
this, SLOT(runAllTests()));
53 connect(model, SIGNAL(rowsAboutToBeInserted(
QModelIndex,
int,
int)),
54 this, SLOT(runAllTests()));
55 connect(model, SIGNAL(rowsAboutToBeRemoved(
QModelIndex,
int,
int)),
56 this, SLOT(runAllTests()));
57 connect(model, SIGNAL(rowsInserted(
QModelIndex,
int,
int)),
58 this, SLOT(runAllTests()));
59 connect(model, SIGNAL(rowsRemoved(
QModelIndex,
int,
int)),
60 this, SLOT(runAllTests()));
63 connect(model, SIGNAL(layoutAboutToBeChanged()),
64 this, SLOT(layoutAboutToBeChanged()));
65 connect(model, SIGNAL(layoutChanged()),
66 this, SLOT(layoutChanged()));
68 connect(model, SIGNAL(rowsAboutToBeInserted(
QModelIndex,
int,
int)),
69 this, SLOT(rowsAboutToBeInserted(
QModelIndex,
int,
int)));
70 connect(model, SIGNAL(rowsAboutToBeRemoved(
QModelIndex,
int,
int)),
71 this, SLOT(rowsAboutToBeRemoved(
QModelIndex,
int,
int)));
72 connect(model, SIGNAL(rowsInserted(
QModelIndex,
int,
int)),
74 connect(model, SIGNAL(rowsRemoved(
QModelIndex,
int,
int)),
84 nonDestructiveBasicTest();
97 void ModelTest::nonDestructiveBasicTest()
105 fetchingMore =
false;
107 Q_ASSERT(flags == Qt::ItemIsDropEnabled || flags == 0);
134 void ModelTest::rowCount()
138 int rows = model->
rowCount(topIndex);
144 if (secondLevelIndex.isValid()) {
146 rows = model->
rowCount(secondLevelIndex);
149 Q_ASSERT(model->
hasChildren(secondLevelIndex) ==
true);
159 void ModelTest::columnCount()
167 if (childIndex.isValid())
177 void ModelTest::hasIndex()
180 Q_ASSERT(model->
hasIndex(-2, -2) ==
false);
181 Q_ASSERT(model->
hasIndex(-2, 0) ==
false);
182 Q_ASSERT(model->
hasIndex(0, -2) ==
false);
188 Q_ASSERT(model->
hasIndex(rows, columns) ==
false);
189 Q_ASSERT(model->
hasIndex(rows + 1, columns + 1) ==
false);
192 Q_ASSERT(model->
hasIndex(0, 0) ==
true);
201 void ModelTest::index()
230 void ModelTest::parent()
251 if (model->
rowCount(topIndex) > 0) {
253 Q_ASSERT(model->
parent(childIndex) == topIndex);
260 if (model->
rowCount(topIndex1) > 0) {
263 Q_ASSERT(childIndex != childIndex1);
285 void ModelTest::checkChildren(
const QModelIndex &parent,
int currentDepth)
296 fetchingMore =
false;
307 Q_ASSERT(columns >= 0);
314 Q_ASSERT(model->
hasIndex(rows + 1, 0, parent) ==
false);
315 for (
int r = 0; r < rows; ++r) {
319 fetchingMore =
false;
321 Q_ASSERT(model->
hasIndex(r, columns + 1, parent) ==
false);
322 for (
int c = 0; c < columns; ++c) {
323 Q_ASSERT(model->
hasIndex(r, c, parent) ==
true);
326 Q_ASSERT(index.isValid() ==
true);
330 Q_ASSERT(index == modifiedIndex);
338 Q_ASSERT(index.model() == model);
339 Q_ASSERT(index.row() == r);
340 Q_ASSERT(index.column() == c);
343 Q_ASSERT(model->
data(index, Qt::DisplayRole).
isValid() ==
true);
358 Q_ASSERT(model->
parent(index) == parent);
361 if (model->
hasChildren(index) && currentDepth < 10 ) {
363 checkChildren(index, ++currentDepth);
368 Q_ASSERT(index == newerIndex);
376 void ModelTest::data()
392 if (variant.isValid()) {
393 Q_ASSERT(qVariantCanConvert<QString>(variant));
395 variant = model->
data(model->
index(0, 0), Qt::StatusTipRole);
396 if (variant.isValid()) {
397 Q_ASSERT(qVariantCanConvert<QString>(variant));
399 variant = model->
data(model->
index(0, 0), Qt::WhatsThisRole);
400 if (variant.isValid()) {
401 Q_ASSERT(qVariantCanConvert<QString>(variant));
405 variant = model->
data(model->
index(0, 0), Qt::SizeHintRole);
406 if (variant.isValid()) {
407 Q_ASSERT(qVariantCanConvert<QSize>(variant));
413 Q_ASSERT(qVariantCanConvert<QFont>(fontVariant));
417 QVariant textAlignmentVariant = model->
data(model->
index(0, 0), Qt::TextAlignmentRole);
418 if (textAlignmentVariant.
isValid()) {
419 int alignment = textAlignmentVariant.
toInt();
420 Q_ASSERT(alignment == Qt::AlignLeft ||
421 alignment == Qt::AlignRight ||
422 alignment == Qt::AlignHCenter ||
423 alignment == Qt::AlignJustify ||
424 alignment == Qt::AlignTop ||
425 alignment == Qt::AlignBottom ||
426 alignment == Qt::AlignVCenter ||
427 alignment == Qt::AlignCenter ||
428 alignment == Qt::AlignAbsolute ||
429 alignment == Qt::AlignLeading ||
430 alignment == Qt::AlignTrailing);
434 QVariant colorVariant = model->
data(model->
index(0, 0), Qt::BackgroundColorRole);
436 Q_ASSERT(qVariantCanConvert<QColor>(colorVariant));
439 colorVariant = model->
data(model->
index(0, 0), Qt::TextColorRole);
441 Q_ASSERT(qVariantCanConvert<QColor>(colorVariant));
445 QVariant checkStateVariant = model->
data(model->
index(0, 0), Qt::CheckStateRole);
446 if (checkStateVariant.
isValid()) {
447 int state = checkStateVariant.
toInt();
448 Q_ASSERT(state == Qt::Unchecked ||
449 state == Qt::PartiallyChecked ||
450 state == Qt::Checked);
464 c.oldSize = model->
rowCount(parent);
465 c.last = model->
data(model->
index(start - 1, 0, parent));
466 c.next = model->
data(model->
index(start, 0, parent));
477 Changing c = insert.
pop();
478 Q_ASSERT(c.parent == parent);
479 Q_ASSERT(c.oldSize + (end - start + 1) == model->
rowCount(parent));
480 Q_ASSERT(c.last == model->
data(model->
index(start - 1, 0, c.parent)));
489 Q_ASSERT(c.next == model->
data(model->
index(end + 1, 0, c.parent)));
494 for (
int i = 0; i < qBound(0, model->
rowCount(), 100); ++i)
500 for (
int i = 0; i < changing.
count(); ++i) {
516 c.oldSize = model->
rowCount(parent);
517 c.last = model->
data(model->
index(start - 1, 0, parent));
518 c.next = model->
data(model->
index(end + 1, 0, parent));
529 Changing c =
remove.pop();
530 Q_ASSERT(c.parent == parent);
531 Q_ASSERT(c.oldSize - (end - start + 1) == model->
rowCount(parent));
532 Q_ASSERT(c.last == model->
data(model->
index(start - 1, 0, c.parent)));
533 Q_ASSERT(c.next == model->
data(model->
index(start, 0, c.parent)));
bool hasIndex(int row, int column, const QModelIndex &parent) const
static const char * flags[]
virtual int rowCount(const QModelIndex &parent) const =0
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const =0
virtual QModelIndex buddy(const QModelIndex &index) const
virtual bool canFetchMore(const QModelIndex &parent) const
virtual QSize span(const QModelIndex &index) const
virtual QMap< int, QVariant > itemData(const QModelIndex &index) const
void rowsInserted(const QModelIndex &parent, int start, int end)
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
virtual QStringList mimeTypes() const
virtual QModelIndexList match(const QModelIndex &start, int role, const QVariant &value, int hits, QFlags< Qt::MatchFlag > flags) const
int count(const T &value) const
void append(const T &value)
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
int toInt(bool *ok) const
QModelIndex sibling(int row, int column, const QModelIndex &index) const
virtual Qt::DropActions supportedDropActions() const
virtual QVariant data(const QModelIndex &index, int role) const =0
QModelIndex parent() const
virtual QModelIndex parent(const QModelIndex &index) const =0
void rowsRemoved(const QModelIndex &parent, int start, int end)
virtual bool hasChildren(const QModelIndex &parent) const
void layoutAboutToBeChanged()
virtual int columnCount(const QModelIndex &parent) const =0
virtual void fetchMore(const QModelIndex &parent)
virtual bool setData(const QModelIndex &index, const QVariant &value, int role)
virtual Qt::ItemFlags flags(const QModelIndex &index) const
QModelIndex parent() const