CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkModelTester.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkModelTester_h
22 #define __ctkModelTester_h
23 
25 #include <QObject>
26 #include <QModelIndex>
27 #include <QPersistentModelIndex>
28 #include <QList>
29 
31 #include "ctkPimpl.h"
32 #include "ctkCoreExport.h"
33 
34 class QAbstractItemModel;
35 class ctkModelTesterPrivate;
36 
44 class CTK_CORE_EXPORT ctkModelTester: public QObject
45 {
46  Q_OBJECT
47  Q_PROPERTY(bool nestedInserts READ nestedInserts WRITE setNestedInserts);
48  Q_PROPERTY(bool testDataEnabled READ testDataEnabled WRITE setTestDataEnabled);
49  Q_PROPERTY(bool throwOnError READ throwOnError WRITE setThrowOnError);
50  Q_PROPERTY(bool verbose READ verbose WRITE setVerbose);
51 public:
56  explicit ctkModelTester(QObject *parent = 0);
57 
65  ctkModelTester(QAbstractItemModel *model, QObject *parent = 0);
66 
69  virtual ~ctkModelTester();
70 
74  void setModel(QAbstractItemModel* model);
75  QAbstractItemModel* model()const;
76 
80  void setThrowOnError(bool throwException);
81  bool throwOnError()const;
82 
89  void setNestedInserts(bool enable);
90  bool nestedInserts()const;
91 
97  void setTestDataEnabled(bool enable);
98  bool testDataEnabled()const;
99 
101  void setVerbose(bool enable);
102  bool verbose()const;
103 
107  virtual void testData(const QModelIndex& index)const;
108 
111  virtual void testModel()const;
112 
115  virtual void testModelIndex(const QModelIndex& index)const;
116 
120  virtual void testParent(const QModelIndex& parent)const;
121 
124  virtual void testPersistentModelIndex(const QPersistentModelIndex& index)const;
125 
126 protected Q_SLOTS:
127  void onColumnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
128  void onColumnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
129  void onColumnsInserted(const QModelIndex & parent, int start, int end);
130  void onColumnsRemoved(const QModelIndex & parent, int start, int end);
131  void onDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
132  void onHeaderDataChanged(Qt::Orientation orientation, int first, int last);
133  void onLayoutAboutToBeChanged();
134  void onLayoutChanged();
135  void onModelAboutToBeReset();
136  void onModelReset();
137  void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
138  void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
139  void onRowsInserted(const QModelIndex & parent, int start, int end);
140  void onRowsRemoved(const QModelIndex & parent, int start, int end);
141 
142 protected:
146  virtual void onItemsAboutToBeInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
147 
151  virtual void onItemsAboutToBeRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
152 
156  virtual void onItemsInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
157 
161  virtual void onItemsRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
162 
165  QList<QPersistentModelIndex> persistentModelIndexes(const QModelIndex& index)const;
166 
169  virtual void test(bool result, const QString& errorString)const;
170 
171 protected:
172  QScopedPointer<ctkModelTesterPrivate> d_ptr;
173 
174 private:
175  Q_DECLARE_PRIVATE(ctkModelTester);
176  Q_DISABLE_COPY(ctkModelTester);
177 };
178 
179 #endif
QList
Definition: ctkCmdLineModuleBackend.h:30
ctkModelTester::d_ptr
QScopedPointer< ctkModelTesterPrivate > d_ptr
Definition: ctkModelTester.h:172
ctkModelTester
Definition: ctkModelTester.h:44
ctkWrapPythonQt.verbose
verbose
Definition: ctkWrapPythonQt.py:235
ctkPimpl.h