2
#include "proxymodeltest.h"
6
#include "../selectionproxymodel.h"
8
using namespace Akonadi;
11
class ModelWatcher : public QObject
15
ModelWatcher(QObject *parent)
20
void setWatchedModel(QAbstractItemModel *model)
26
void setSelectionModel(QItemSelectionModel *selectionModel)
28
m_selectionModel = selectionModel;
31
void setWatch(bool watch)
35
connect(m_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
36
SLOT(rowsInserted(const QModelIndex &, int, int)));
38
disconnect(m_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
39
this, SLOT(rowsInserted(const QModelIndex &, int, int)));
42
void setWatchedParent(const QModelIndex &parent)
47
void setWatchedRow(int row)
53
void newItem(const QModelIndex &idx);
56
void rowsInserted(const QModelIndex &parent, int start, int end)
58
if (m_parent != parent)
61
if (start < m_row || m_row > end)
64
QModelIndex idx = m_model->index(m_row, 0, parent);
66
m_selectionModel->select(idx, QItemSelectionModel::SelectCurrent);
72
QAbstractItemModel *m_model;
73
QItemSelectionModel *m_selectionModel;
78
class SelectionProxyModelTest : public ProxyModelTest
82
SelectionProxyModelTest(QObject *parent = 0)
83
: ProxyModelTest( parent ),
91
// Make different selections and run all of the tests.
92
m_selectionModel = new QItemSelectionModel(sourceModel());
93
m_proxyModel = new SelectionProxyModel(m_selectionModel, this);
94
setProxyModel(m_proxyModel);
96
ModelWatcher *watcher = new ModelWatcher(this);
97
watcher->setWatchedModel(sourceModel());
98
watcher->setSelectionModel(m_selectionModel);
99
watcher->setWatchedParent(QModelIndex());
100
watcher->setWatchedRow(0);
102
QList<QVariantList> signalList;
103
QVariantList expected;
104
QList<PersistentIndexChange> persistentList;
105
IndexFinder indexFinder;
109
int rowsInserted = 1;
111
// The selection will cause some signals to be emitted.
112
signalInsertion("insert01", indexFinder, startRow, rowsInserted);
114
indexFinder = IndexFinder( m_proxyModel, QList<int>() << 0);
116
signalInsertion("insert02", indexFinder, startRow, rowsInserted);
118
noSignal("insert03");
119
noSignal("insert04");
121
PersistentIndexChange change;
124
signalInsertion("insert05", indexFinder, startRow, rowsInserted, rowCount);
127
signalInsertion("insert06", indexFinder, startRow, rowsInserted);
131
signalInsertion("insert07", indexFinder, startRow, rowsInserted, rowCount);
133
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5);
137
signalList << getSignal(RowsAboutToBeInserted, indexFinder, startRow, startRow + rowsInserted - 1);
138
signalList << getSignal(RowsInserted, indexFinder, startRow, startRow + rowsInserted - 1);
140
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5 << 5);
141
signalList << getSignal(RowsAboutToBeInserted, indexFinder, startRow, startRow + rowsInserted - 1);
142
signalList << getSignal(RowsInserted, indexFinder, startRow, startRow + rowsInserted - 1);
144
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5 << 5 << 5);
145
signalList << getSignal(RowsAboutToBeInserted, indexFinder, startRow, startRow + rowsInserted - 1);
146
signalList << getSignal(RowsInserted, indexFinder, startRow, startRow + rowsInserted - 1);
148
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 6);
149
signalList << getSignal(RowsAboutToBeInserted, indexFinder, startRow, startRow + rowsInserted - 1);
150
signalList << getSignal(RowsInserted, indexFinder, startRow, startRow + rowsInserted - 1);
152
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 7);
153
signalList << getSignal(RowsAboutToBeInserted, indexFinder, startRow, startRow + rowsInserted - 1);
154
signalList << getSignal(RowsInserted, indexFinder, startRow, startRow + rowsInserted - 1);
156
setExpected("insert08", signalList, persistentList);
158
persistentList.clear();
160
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0);
164
signalRemoval("remove01", indexFinder, startRow, rowsRemoved, rowCount);
168
signalRemoval("remove02", indexFinder, startRow, rowsRemoved, rowCount);
170
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5);
173
signalRemoval("remove03", indexFinder, startRow, rowsRemoved, rowCount);
177
signalRemoval("remove04", indexFinder, startRow, rowsRemoved, rowCount);
181
signalRemoval("remove05", indexFinder, startRow, rowsRemoved, rowCount);
184
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5);
188
signalRemoval("remove06", indexFinder, startRow, rowsRemoved, rowCount);
190
indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0);
195
signalRemoval("remove07", indexFinder, startRow, rowsRemoved, rowCount);
200
QItemSelectionModel *m_selectionModel;
201
SelectionProxyModel *m_proxyModel;
205
QTEST_KDEMAIN(SelectionProxyModelTest, GUI)
206
#include "selectionproxymodeltest.moc"