CTK 0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
Loading...
Searching...
No Matches
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
34class QAbstractItemModel;
35class ctkModelTesterPrivate;
36
44class 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);
51public:
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
126protected 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);
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
142protected:
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
166
169 virtual void test(bool result, const QString& errorString)const;
170
171protected:
172 QScopedPointer<ctkModelTesterPrivate> d_ptr;
173
174private:
175 Q_DECLARE_PRIVATE(ctkModelTester);
176 Q_DISABLE_COPY(ctkModelTester);
177};
178
179#endif
void onRowsInserted(const QModelIndex &parent, int start, int end)
void onModelReset()
bool testDataEnabled() const
void onDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void onLayoutAboutToBeChanged()
ctkModelTester(QObject *parent=0)
void onColumnsRemoved(const QModelIndex &parent, int start, int end)
bool verbose() const
virtual void onItemsInserted(const QModelIndex &parent, Qt::Orientation, int start, int end)
virtual void testModel() const
Run all the tests on the model previously set in setModel(...)
virtual void testParent(const QModelIndex &parent) const
ctkModelTester(QAbstractItemModel *model, QObject *parent=0)
virtual ~ctkModelTester()
Destructor.
void onModelAboutToBeReset()
QAbstractItemModel * model() const
virtual void testPersistentModelIndex(const QPersistentModelIndex &index) const
virtual void onItemsRemoved(const QModelIndex &parent, Qt::Orientation, int start, int end)
void onColumnsInserted(const QModelIndex &parent, int start, int end)
void onColumnsAboutToBeInserted(const QModelIndex &parent, int start, int end)
virtual void test(bool result, const QString &errorString) const
Utility function that process the result of a test.
void onHeaderDataChanged(Qt::Orientation orientation, int first, int last)
bool nestedInserts() const
void setNestedInserts(bool enable)
void onRowsRemoved(const QModelIndex &parent, int start, int end)
virtual void testData(const QModelIndex &index) const
virtual void onItemsAboutToBeInserted(const QModelIndex &parent, Qt::Orientation, int start, int end)
virtual void onItemsAboutToBeRemoved(const QModelIndex &parent, Qt::Orientation, int start, int end)
void setTestDataEnabled(bool enable)
void setVerbose(bool enable)
When Verbose is enabled, message will be printed to standard or error output.
void setThrowOnError(bool throwException)
virtual void testModelIndex(const QModelIndex &index) const
Run a collection of tests on a QModelIndex.
void setModel(QAbstractItemModel *model)
QList< QPersistentModelIndex > persistentModelIndexes(const QModelIndex &index) const
Create a list of persistent index of all the index's children.
void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
bool throwOnError() const
void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
QScopedPointer< ctkModelTesterPrivate > d_ptr
void onLayoutChanged()
void onColumnsAboutToBeRemoved(const QModelIndex &parent, int start, int end)