ctkModelTester.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Library:   CTK
00004  
00005   Copyright (c) 2010  Kitware Inc.
00006 
00007   Licensed under the Apache License, Version 2.0 (the "License");
00008   you may not use this file except in compliance with the License.
00009   You may obtain a copy of the License at
00010 
00011       http://www.commontk.org/LICENSE
00012 
00013   Unless required by applicable law or agreed to in writing, software
00014   distributed under the License is distributed on an "AS IS" BASIS,
00015   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00016   See the License for the specific language governing permissions and
00017   limitations under the License.
00018  
00019 =========================================================================*/
00020 
00021 #ifndef __ctkModelTester_h
00022 #define __ctkModelTester_h
00023 
00025 #include <QObject> 
00026 #include <QModelIndex>
00027 #include <QPersistentModelIndex>
00028 #include <QList>
00029 
00031 #include "ctkPimpl.h"
00032 #include "CTKCoreExport.h"
00033 
00034 class QAbstractItemModel;
00035 class ctkModelTesterPrivate;
00036 
00037 class CTK_CORE_EXPORT ctkModelTester: public QObject
00038 {
00039   Q_OBJECT
00040   Q_PROPERTY(bool nestedInserts READ nestedInserts WRITE setNestedInserts);
00041 public:
00042   explicit ctkModelTester(QObject *parent = 0);
00043   ctkModelTester(QAbstractItemModel *model, QObject *parent = 0);
00044 
00045   void setModel(QAbstractItemModel* model);
00046   QAbstractItemModel* model()const;
00047 
00048   void setThrowOnError(bool throwException);
00049   bool throwOnError()const;
00050  
00051   void setNestedInserts(bool enable);
00052   bool nestedInserts()const;
00053 
00054   virtual void testData(const QModelIndex& index)const;
00055   virtual void testModel()const;
00056   virtual void testModelIndex(const QModelIndex& index)const;
00057   virtual void testParent(const QModelIndex& parent)const;
00058   virtual void testPersistentModelIndex(const QPersistentModelIndex& index)const;
00059 
00060 protected slots:
00061   void onColumnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
00062   void onColumnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
00063   void onColumnsInserted(const QModelIndex & parent, int start, int end);
00064   void onColumnsRemoved(const QModelIndex & parent, int start, int end);
00065   void onDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
00066   void onHeaderDataChanged(Qt::Orientation orientation, int first, int last);
00067   void onLayoutAboutToBeChanged();
00068   void onLayoutChanged();
00069   void onModelAboutToBeReset();
00070   void onModelReset();
00071   void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
00072   void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
00073   void onRowsInserted(const QModelIndex & parent, int start, int end);
00074   void onRowsRemoved(const QModelIndex & parent, int start, int end);
00075   
00076 protected:
00077   virtual void onItemsAboutToBeInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
00078   virtual void onItemsAboutToBeRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
00079   virtual void onItemsInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
00080   virtual void onItemsRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
00081   QList<QPersistentModelIndex> persistentModelIndexes(const QModelIndex& index)const;
00082   virtual void test(bool result, const QString& errorString)const;
00083   
00084 private:
00085   CTK_DECLARE_PRIVATE(ctkModelTester);
00086 };
00087 
00088 #endif
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines