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);
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
ctkModelTester::onRowsAboutToBeInserted
void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
ctkModelTester::persistentModelIndexes
QList< QPersistentModelIndex > persistentModelIndexes(const QModelIndex &index) const
Create a list of persistent index of all the index's children.
ctkModelTester::onDataChanged
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
ctkModelTester::onHeaderDataChanged
void onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
ctkModelTester::setNestedInserts
void setNestedInserts(bool enable)
ctkModelTester::ctkModelTester
ctkModelTester(QObject *parent=0)
ctkModelTester::onLayoutChanged
void onLayoutChanged()
ctkModelTester::onItemsRemoved
virtual void onItemsRemoved(const QModelIndex &parent, Qt::Orientation, int start, int end)
ctkModelTester::onModelReset
void onModelReset()
ctkModelTester::onModelAboutToBeReset
void onModelAboutToBeReset()
ctkModelTester::testData
virtual void testData(const QModelIndex &index) const
ctkModelTester::testParent
virtual void testParent(const QModelIndex &parent) const
ctkModelTester::onItemsAboutToBeRemoved
virtual void onItemsAboutToBeRemoved(const QModelIndex &parent, Qt::Orientation, int start, int end)
QList
Definition: ctkCmdLineModuleBackend.h:30
ctkModelTester::testModelIndex
virtual void testModelIndex(const QModelIndex &index) const
Run a collection of tests on a QModelIndex.
ctkModelTester::setModel
void setModel(QAbstractItemModel *model)
ctkModelTester::onRowsInserted
void onRowsInserted(const QModelIndex &parent, int start, int end)
ctkModelTester::testModel
virtual void testModel() const
Run all the tests on the model previously set in setModel(...)
ctkModelTester::setThrowOnError
void setThrowOnError(bool throwException)
ctkModelTester::d_ptr
QScopedPointer< ctkModelTesterPrivate > d_ptr
Definition: ctkModelTester.h:172
ctkModelTester::model
QAbstractItemModel * model() const
ctkModelTester::testPersistentModelIndex
virtual void testPersistentModelIndex(const QPersistentModelIndex &index) const
ctkModelTester::throwOnError
bool throwOnError() const
ctkModelTester::onColumnsAboutToBeRemoved
void onColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
ctkModelTester::testDataEnabled
bool testDataEnabled() const
ctkModelTester
Definition: ctkModelTester.h:45
ctkWrapPythonQt.verbose
verbose
Definition: ctkWrapPythonQt.py:235
ctkModelTester::onLayoutAboutToBeChanged
void onLayoutAboutToBeChanged()
ctkModelTester::ctkModelTester
ctkModelTester(QAbstractItemModel *model, QObject *parent=0)
ctkModelTester::setVerbose
void setVerbose(bool enable)
When Verbose is enabled, message will be printed to standard or error output.
ctkModelTester::verbose
bool verbose() const
ctkModelTester::onColumnsInserted
void onColumnsInserted(const QModelIndex &parent, int start, int end)
ctkModelTester::nestedInserts
bool nestedInserts() const
ctkModelTester::onColumnsAboutToBeInserted
void onColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
ctkModelTester::onItemsAboutToBeInserted
virtual void onItemsAboutToBeInserted(const QModelIndex &parent, Qt::Orientation, int start, int end)
ctkPimpl.h
ctkModelTester::onColumnsRemoved
void onColumnsRemoved(const QModelIndex &parent, int start, int end)
ctkModelTester::test
virtual void test(bool result, const QString &errorString) const
Utility function that process the result of a test.
ctkModelTester::onItemsInserted
virtual void onItemsInserted(const QModelIndex &parent, Qt::Orientation, int start, int end)
ctkModelTester::onRowsAboutToBeRemoved
void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
ctkModelTester::onRowsRemoved
void onRowsRemoved(const QModelIndex &parent, int start, int end)
ctkModelTester::setTestDataEnabled
void setTestDataEnabled(bool enable)
ctkModelTester::~ctkModelTester
virtual ~ctkModelTester()
Destructor.