LibEngsas
Classes | Public Member Functions | Protected Slots | Private Slots | Private Member Functions | Private Attributes | List of all members
ModelTest Class Reference

Class to test all basic stuff of QAbstractItemModels. More...

#include <modeltest.h>

+ Inheritance diagram for ModelTest:
+ Collaboration diagram for ModelTest:

Classes

struct  Changing
 

Public Member Functions

 ModelTest (QAbstractItemModel *model, QObject *parent=NULL, int verbose=1)
 

Protected Slots

void runAllTests ()
 
void layoutAboutToBeChanged ()
 
void layoutChanged ()
 
void rowsAboutToBeInserted (const QModelIndex &parent, int start, int)
 
void rowsInserted (const QModelIndex &parent, int start, int end)
 
void rowsAboutToBeRemoved (const QModelIndex &parent, int start, int end)
 
void rowsRemoved (const QModelIndex &parent, int start, int end)
 

Private Slots

void nonDestructiveBasicTest ()
 
void rowCount ()
 
void columnCount ()
 
void hasIndex ()
 
void index ()
 
void parent ()
 
void data ()
 

Private Member Functions

void checkChildren (const QModelIndex &parent, int currentDepth=0)
 
void init ()
 

Private Attributes

QAbstractItemModel * model
 
QStack< Changinginsert
 
QStack< Changingremove
 
bool fetchingMore
 
int verboseLevel
 
QList< QPersistentModelIndex > changing
 

Detailed Description

Class to test all basic stuff of QAbstractItemModels.

This class is from QtLabs. It is designed to watch a given model and run some checks after events like inserting or remove items. So use it like this:

YourModel *model = new YourModel(this);
new ModelTest(model, this, 0);
// add and remove some items here, if something goes wrong, ModelTest
// throws asserts.
Todo:
Give more useful output with verbose > 0

Constructor & Destructor Documentation

ModelTest::ModelTest ( QAbstractItemModel *  _model,
QObject *  parent = NULL,
int  verbose = 1 
)

Connect to all of the models signals. Whenever anything happens recheck everything.

+ Here is the call graph for this function:

Member Function Documentation

void ModelTest::checkChildren ( const QModelIndex &  parent,
int  currentDepth = 0 
)
private

Called from the parent() test.

A model that returns an index of parent X should also return X when asking for the parent of the index.

This recursive function does pretty extensive testing on the whole model in an effort to catch edge cases.

This function assumes that rowCount(), columnCount() and index() already work. If they have a bug it will point it out, but the above tests should have already found the basic bugs because it is easier to figure out the problem in those tests then this one.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ModelTest::columnCount ( )
privateslot

Tests model's implementation of QAbstractItemModel::columnCount() and hasChildren()

+ Here is the caller graph for this function:

void ModelTest::data ( )
privateslot

Tests model's implementation of QAbstractItemModel::data()

+ Here is the caller graph for this function:

void ModelTest::hasIndex ( )
privateslot

Tests model's implementation of QAbstractItemModel::hasIndex()

+ Here is the caller graph for this function:

void ModelTest::index ( )
privateslot

Tests model's implementation of QAbstractItemModel::index()

+ Here is the caller graph for this function:

void ModelTest::init ( )
private

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ModelTest::layoutAboutToBeChanged ( )
protectedslot

+ Here is the caller graph for this function:

void ModelTest::layoutChanged ( )
protectedslot

+ Here is the caller graph for this function:

void ModelTest::nonDestructiveBasicTest ( )
privateslot

nonDestructiveBasicTest tries to call a number of the basic functions (not all) to make sure the model doesn't outright segfault, testing the functions that makes sense.

+ Here is the caller graph for this function:

void ModelTest::parent ( )
privateslot

Tests model's implementation of QAbstractItemModel::parent()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ModelTest::rowCount ( )
privateslot

Tests model's implementation of QAbstractItemModel::rowCount() and hasChildren()

Models that are dynamically populated are not as fully tested here.

+ Here is the caller graph for this function:

void ModelTest::rowsAboutToBeInserted ( const QModelIndex &  parent,
int  start,
int   
)
protectedslot

Store what is about to be inserted to make sure it actually happens

See also
rowsInserted()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)
protectedslot

Store what is about to be inserted to make sure it actually happens

See also
rowsRemoved()

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void ModelTest::rowsInserted ( const QModelIndex &  parent,
int  start,
int  end 
)
protectedslot

Confirm that what was said was going to happen actually did

See also
rowsAboutToBeInserted()

+ Here is the caller graph for this function:

void ModelTest::rowsRemoved ( const QModelIndex &  parent,
int  start,
int  end 
)
protectedslot

Confirm that what was said was going to happen actually did

See also
rowsAboutToBeRemoved()

+ Here is the caller graph for this function:

void ModelTest::runAllTests ( )
protectedslot

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

QList<QPersistentModelIndex> ModelTest::changing
private
bool ModelTest::fetchingMore
private
QStack<Changing> ModelTest::insert
private
QAbstractItemModel* ModelTest::model
private
QStack<Changing> ModelTest::remove
private
int ModelTest::verboseLevel
private

The documentation for this class was generated from the following files: