~ubuntu-branches/ubuntu/karmic/kdepim/karmic-backports

« back to all changes in this revision

Viewing changes to akonadi/akonadi_next/tests/selectionproxymodeltest.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christian Mangold
  • Date: 2009-07-10 06:34:50 UTC
  • mfrom: (1.1.40 upstream)
  • Revision ID: james.westby@ubuntu.com-20090710063450-neojgew2fh0n3y0u
Tags: 4:4.2.96-0ubuntu1
* New upstream release
* Bump kde build-deps to 4.2.96

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#include "proxymodeltest.h"
3
 
 
4
 
#include <QTimer>
5
 
 
6
 
#include "../selectionproxymodel.h"
7
 
 
8
 
using namespace Akonadi;
9
 
 
10
 
 
11
 
class ModelWatcher : public QObject
12
 
{
13
 
  Q_OBJECT
14
 
public:
15
 
  ModelWatcher(QObject *parent)
16
 
      : QObject(parent)
17
 
  {
18
 
  }
19
 
 
20
 
  void setWatchedModel(QAbstractItemModel *model)
21
 
  {
22
 
    m_model = model;
23
 
    setWatch(true);
24
 
  }
25
 
 
26
 
  void setSelectionModel(QItemSelectionModel *selectionModel)
27
 
  {
28
 
    m_selectionModel = selectionModel;
29
 
  }
30
 
 
31
 
  void setWatch(bool watch)
32
 
  {
33
 
    Q_ASSERT(m_model);
34
 
    if (watch)
35
 
      connect(m_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
36
 
            SLOT(rowsInserted(const QModelIndex &, int, int)));
37
 
    else
38
 
      disconnect(m_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
39
 
            this, SLOT(rowsInserted(const QModelIndex &, int, int)));
40
 
  }
41
 
 
42
 
  void setWatchedParent(const QModelIndex &parent)
43
 
  {
44
 
    m_parent = parent;
45
 
  }
46
 
 
47
 
  void setWatchedRow(int row)
48
 
  {
49
 
    m_row = row;
50
 
  }
51
 
 
52
 
signals:
53
 
  void newItem(const QModelIndex &idx);
54
 
 
55
 
public slots:
56
 
  void rowsInserted(const QModelIndex &parent, int start, int end)
57
 
  {
58
 
    if (m_parent != parent)
59
 
      return;
60
 
 
61
 
    if (start < m_row || m_row > end)
62
 
      return;
63
 
 
64
 
    QModelIndex idx = m_model->index(m_row, 0, parent);
65
 
 
66
 
    m_selectionModel->select(idx, QItemSelectionModel::SelectCurrent);
67
 
 
68
 
    setWatch(false);
69
 
  }
70
 
 
71
 
private:
72
 
  QAbstractItemModel *m_model;
73
 
  QItemSelectionModel *m_selectionModel;
74
 
  QModelIndex m_parent;
75
 
  int m_row;
76
 
};
77
 
 
78
 
class SelectionProxyModelTest : public ProxyModelTest
79
 
{
80
 
  Q_OBJECT
81
 
public:
82
 
  SelectionProxyModelTest(QObject *parent = 0)
83
 
      : ProxyModelTest( parent ),
84
 
      m_selectionModel(0)
85
 
  {
86
 
  }
87
 
 
88
 
private slots:
89
 
  void initTestCase()
90
 
  {
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);
95
 
 
96
 
    ModelWatcher *watcher = new ModelWatcher(this);
97
 
    watcher->setWatchedModel(sourceModel());
98
 
    watcher->setSelectionModel(m_selectionModel);
99
 
    watcher->setWatchedParent(QModelIndex());
100
 
    watcher->setWatchedRow(0);
101
 
 
102
 
    QList<QVariantList> signalList;
103
 
    QVariantList expected;
104
 
    QList<PersistentIndexChange> persistentList;
105
 
    IndexFinder indexFinder;
106
 
 
107
 
 
108
 
    int startRow = 0;
109
 
    int rowsInserted = 1;
110
 
    int rowCount = 0;
111
 
    // The selection will cause some signals to be emitted.
112
 
    signalInsertion("insert01", indexFinder, startRow, rowsInserted);
113
 
 
114
 
    indexFinder = IndexFinder( m_proxyModel, QList<int>() << 0);
115
 
    rowsInserted = 10;
116
 
    signalInsertion("insert02", indexFinder, startRow, rowsInserted);
117
 
 
118
 
    noSignal("insert03");
119
 
    noSignal("insert04");
120
 
 
121
 
    PersistentIndexChange change;
122
 
 
123
 
    rowCount = 10;
124
 
    signalInsertion("insert05", indexFinder, startRow, rowsInserted, rowCount);
125
 
 
126
 
    startRow = 20;
127
 
    signalInsertion("insert06", indexFinder, startRow, rowsInserted);
128
 
 
129
 
    startRow = 10;
130
 
    rowCount = 30;
131
 
    signalInsertion("insert07", indexFinder, startRow, rowsInserted, rowCount);
132
 
 
133
 
    indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5);
134
 
 
135
 
    startRow = 0;
136
 
    rowCount = 0;
137
 
    signalList << getSignal(RowsAboutToBeInserted, indexFinder, startRow, startRow + rowsInserted - 1);
138
 
    signalList << getSignal(RowsInserted, indexFinder, startRow, startRow + rowsInserted - 1);
139
 
 
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);
143
 
 
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);
147
 
 
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);
151
 
 
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);
155
 
 
156
 
    setExpected("insert08", signalList, persistentList);
157
 
    signalList.clear();
158
 
    persistentList.clear();
159
 
 
160
 
    indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0);
161
 
 
162
 
    int rowsRemoved = 1;
163
 
    rowCount = 40;
164
 
    signalRemoval("remove01", indexFinder, startRow, rowsRemoved, rowCount);
165
 
 
166
 
    startRow = 6;
167
 
    rowCount = 39;
168
 
    signalRemoval("remove02", indexFinder, startRow, rowsRemoved, rowCount);
169
 
 
170
 
    indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5);
171
 
    startRow = 0;
172
 
    rowCount = 10;
173
 
    signalRemoval("remove03", indexFinder, startRow, rowsRemoved, rowCount);
174
 
 
175
 
    startRow = 8;
176
 
    rowCount = 9;
177
 
    signalRemoval("remove04", indexFinder, startRow, rowsRemoved, rowCount);
178
 
 
179
 
    startRow = 3;
180
 
    rowCount = 8;
181
 
    signalRemoval("remove05", indexFinder, startRow, rowsRemoved, rowCount);
182
 
 
183
 
 
184
 
    indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0 << 5);
185
 
    startRow = 0;
186
 
    rowCount = 7;
187
 
    rowsRemoved = 7;
188
 
    signalRemoval("remove06", indexFinder, startRow, rowsRemoved, rowCount);
189
 
 
190
 
    indexFinder = IndexFinder(m_proxyModel, QList<int>() << 0);
191
 
 
192
 
    startRow = 4;
193
 
    rowCount = 38;
194
 
    rowsRemoved = 1;
195
 
    signalRemoval("remove07", indexFinder, startRow, rowsRemoved, rowCount);
196
 
 
197
 
  }
198
 
 
199
 
private:
200
 
  QItemSelectionModel *m_selectionModel;
201
 
  SelectionProxyModel *m_proxyModel;
202
 
};
203
 
 
204
 
 
205
 
QTEST_KDEMAIN(SelectionProxyModelTest, GUI)
206
 
#include "selectionproxymodeltest.moc"
207