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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi, Alessandro Ghersi, Harald Sitter
  • Date: 2009-06-27 04:40:05 UTC
  • mfrom: (1.1.39 upstream)
  • Revision ID: james.westby@ubuntu.com-20090627044005-4y2vm9xz7rvmzi4p
Tags: 4:4.2.95svn20090701-0ubuntu1
[ Alessandro Ghersi ]
* New upstream release
  - Bump build-deps
* Remove akonadi-kde and libmaildir4 packages
  - remove akonadi-kde.install and libmaildir4.install
  - remove libmaildir4 from debian/rules
  - remove akonadi-kde and libmaildir4 from depends
  - remove akonadi-kde and libmaildir4 from installgen
* Update kdepim-dev.install
* Update kpilot.install
* Add akonadi-kde and libmaildir4 transitional packages

[ Harald Sitter ]
* KAddressbook replaces Kontact << 4.2.85 (LP: #378373)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
#include "proxymodeltest.h"
 
3
 
 
4
#include <QSignalSpy>
 
5
 
 
6
#include "dynamictreemodel.h"
 
7
#include "../modeltest.h"
 
8
#include <QItemSelectionModel>
 
9
 
 
10
typedef QList<ModelChangeCommand*> CommandList;
 
11
 
 
12
Q_DECLARE_METATYPE( CommandList )
 
13
 
 
14
ModelSpy::ModelSpy(QObject *parent)
 
15
    : QObject(parent), QList<QVariantList>()
 
16
{
 
17
  qRegisterMetaType<QModelIndex>("QModelIndex");
 
18
  qRegisterMetaType<IndexFinder>("IndexFinder");
 
19
}
 
20
 
 
21
void ModelSpy::setModel(AbstractProxyModel *model)
 
22
{
 
23
  Q_ASSERT(model);
 
24
  m_model = model;
 
25
 
 
26
  connect(m_model, SIGNAL(rowsAboutToBeInserted(const QModelIndex &, int, int)),
 
27
          SLOT(rowsAboutToBeInserted(const QModelIndex &, int, int)));
 
28
  connect(m_model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
 
29
          SLOT(rowsInserted(const QModelIndex &, int, int)));
 
30
  connect(m_model, SIGNAL(rowsAboutToBeRemoved(const QModelIndex &, int, int)),
 
31
          SLOT(rowsAboutToBeRemoved(const QModelIndex &, int, int)));
 
32
  connect(m_model, SIGNAL(rowsRemoved(const QModelIndex &, int, int)),
 
33
          SLOT(rowsRemoved(const QModelIndex &, int, int)));
 
34
  connect(m_model, SIGNAL(rowsAboutToBeMoved(const QModelIndex &, int, int,const QModelIndex &, int)),
 
35
          SLOT(rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
 
36
  connect(m_model, SIGNAL(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)),
 
37
          SLOT(rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)));
 
38
}
 
39
 
 
40
void ModelSpy::rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
 
41
{
 
42
  append(QVariantList() << RowsAboutToBeInserted << QVariant::fromValue(parent) << start << end);
 
43
}
 
44
 
 
45
void ModelSpy::rowsInserted(const QModelIndex &parent, int start, int end)
 
46
{
 
47
  append(QVariantList() << RowsInserted << QVariant::fromValue(parent) << start << end);
 
48
}
 
49
 
 
50
void ModelSpy::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
 
51
{
 
52
  append(QVariantList() << RowsAboutToBeRemoved << QVariant::fromValue(parent) << start << end);
 
53
}
 
54
 
 
55
void ModelSpy::rowsRemoved(const QModelIndex &parent, int start, int end)
 
56
{
 
57
  append(QVariantList() << RowsRemoved << QVariant::fromValue(parent) << start << end);
 
58
}
 
59
 
 
60
void ModelSpy::rowsAboutToBeMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destStart)
 
61
{
 
62
  append(QVariantList() << RowsAboutToBeMoved << QVariant::fromValue(srcParent) << start << end << QVariant::fromValue(destParent) << destStart);
 
63
}
 
64
 
 
65
void ModelSpy::rowsMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destStart)
 
66
{
 
67
  append(QVariantList() << RowsMoved << QVariant::fromValue(srcParent) << start << end << QVariant::fromValue(destParent) << destStart);
 
68
}
 
69
 
 
70
void ModelSpy::dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
 
71
{
 
72
  append(QVariantList() << DataChanged << QVariant::fromValue(topLeft) << QVariant::fromValue(bottomRight));
 
73
}
 
74
 
 
75
 
 
76
ProxyModelTest::ProxyModelTest(QObject *parent)
 
77
: QObject(parent), m_model(new DynamicTreeModel(this)), m_proxyModel(0), m_modelSpy(new ModelSpy(this))
 
78
{
 
79
}
 
80
 
 
81
void ProxyModelTest::initTestCase()
 
82
{
 
83
}
 
84
 
 
85
DynamicTreeModel* ProxyModelTest::sourceModel()
 
86
{
 
87
  return m_model;
 
88
}
 
89
 
 
90
 
 
91
QVariantList ProxyModelTest::getSignal(SignalType type, IndexFinder parentFinder, int start, int end)
 
92
{
 
93
  return QVariantList() << type << QVariant::fromValue(parentFinder) << start << end;
 
94
}
 
95
 
 
96
void ProxyModelTest::signalInsertion(const QString &name, IndexFinder parentFinder, int startRow, int rowsAffected, int rowCount)
 
97
{
 
98
  QVERIFY(startRow >= 0 && rowsAffected > 0);
 
99
  QList<QVariantList> signalList;
 
100
  signalList << getSignal(RowsAboutToBeInserted, parentFinder, startRow, startRow + rowsAffected - 1 );
 
101
  signalList << getSignal(RowsInserted, parentFinder, startRow, startRow + rowsAffected - 1 );
 
102
 
 
103
  QList<PersistentIndexChange> persistentList;
 
104
  if (rowCount > 0)
 
105
    persistentList << getChange(parentFinder, startRow, rowCount - 1, rowsAffected);
 
106
 
 
107
  setExpected(name, signalList, persistentList);
 
108
}
 
109
 
 
110
void ProxyModelTest::signalRemoval(const QString &name, IndexFinder parentFinder, int startRow, int rowsAffected, int rowCount)
 
111
{
 
112
  QVERIFY(startRow >= 0 && rowsAffected > 0);
 
113
  QList<QVariantList> signalList;
 
114
  signalList << getSignal(RowsAboutToBeRemoved, parentFinder, startRow, startRow + rowsAffected - 1 );
 
115
  signalList << getSignal(RowsRemoved, parentFinder, startRow, startRow + rowsAffected - 1 );
 
116
 
 
117
  QList<PersistentIndexChange> persistentList;
 
118
  if (rowCount > 0)
 
119
  {
 
120
    persistentList << getChange(parentFinder, startRow, startRow + rowsAffected - 1, -1, true);
 
121
    persistentList << getChange(parentFinder, startRow + rowsAffected, rowCount - 1, rowsAffected * -1 );
 
122
  }
 
123
 
 
124
  setExpected(name, signalList, persistentList);
 
125
}
 
126
 
 
127
void ProxyModelTest::noSignal(const QString &name)
 
128
{
 
129
  QList<PersistentIndexChange> persistentList;
 
130
  QList<QVariantList> signalList;
 
131
  signalList << (QVariantList() << NoSignal);
 
132
  signalList << (QVariantList() << NoSignal);
 
133
 
 
134
  setExpected(name, signalList, persistentList);
 
135
}
 
136
 
 
137
PersistentIndexChange ProxyModelTest::getChange(IndexFinder parentFinder, int start, int end, int difference, bool toInvalid)
 
138
{
 
139
  PersistentIndexChange change;
 
140
  change.parentFinder = parentFinder;
 
141
  change.startRow = start;
 
142
  change.endRow = end;
 
143
  change.difference = difference;
 
144
  change.toInvalid = toInvalid;
 
145
  return change;
 
146
}
 
147
 
 
148
void ProxyModelTest::handleSignal(QVariantList expected)
 
149
{
 
150
  int signalType = expected.takeAt(0).toInt();
 
151
  if (NoSignal == signalType)
 
152
    return;
 
153
 
 
154
  QVariantList result = getResultSignal();
 
155
  QCOMPARE(result.takeAt(0).toInt(), signalType);
 
156
  switch (signalType)
 
157
  {
 
158
  case RowsAboutToBeInserted:
 
159
  case RowsInserted:
 
160
  case RowsAboutToBeRemoved:
 
161
  case RowsRemoved:
 
162
  {
 
163
    QVERIFY( expected.size() == 3 );
 
164
    IndexFinder parentFinder = qvariant_cast<IndexFinder>(expected.at(0));
 
165
    QModelIndex parent = parentFinder.getIndex();
 
166
    QCOMPARE(qvariant_cast<QModelIndex>(result.at(0)), parent );
 
167
    QCOMPARE(result.at(1), expected.at(1) );
 
168
    QCOMPARE(result.at(2), expected.at(2) );
 
169
    break;
 
170
  }
 
171
  case RowsAboutToBeMoved:
 
172
  case RowsMoved:
 
173
  {
 
174
    QVERIFY( expected.size() == 5 );
 
175
    IndexFinder scrParentFinder = qvariant_cast<IndexFinder>(expected.at(0));
 
176
    QModelIndex srcParent = scrParentFinder.getIndex();
 
177
    QCOMPARE(qvariant_cast<QModelIndex>(result.at(0)), srcParent );
 
178
    QCOMPARE(result.at(1), expected.at(1) );
 
179
    QCOMPARE(result.at(2), expected.at(2) );
 
180
    IndexFinder destParentFinder = qvariant_cast<IndexFinder>(expected.at(3));
 
181
    QModelIndex destParent = destParentFinder.getIndex();
 
182
    QCOMPARE(qvariant_cast<QModelIndex>(result.at(3)), destParent );
 
183
    QCOMPARE(result.at(4), expected.at(4) );
 
184
  }
 
185
  case DataChanged:
 
186
  {
 
187
    QVERIFY( expected.size() == 2 );
 
188
    IndexFinder topLeftFinder = qvariant_cast<IndexFinder>(expected.at(0));
 
189
    QModelIndex topLeft = topLeftFinder.getIndex();
 
190
    IndexFinder bottomRightFinder = qvariant_cast<IndexFinder>(expected.at(1));
 
191
    QModelIndex bottomRight = bottomRightFinder.getIndex();
 
192
 
 
193
    QVERIFY(topLeft.isValid() && bottomRight.isValid());
 
194
 
 
195
    QCOMPARE(qvariant_cast<QModelIndex>(result.at(0)), topLeft );
 
196
    QCOMPARE(qvariant_cast<QModelIndex>(result.at(0)), bottomRight );
 
197
  }
 
198
 
 
199
  }
 
200
}
 
201
 
 
202
QVariantList ProxyModelTest::getResultSignal()
 
203
{
 
204
  return m_modelSpy->takeAt(0);
 
205
}
 
206
 
 
207
void ProxyModelTest::setProxyModel(AbstractProxyModel *proxyModel)
 
208
{
 
209
  m_proxyModel = proxyModel;
 
210
  m_proxyModel->setSourceModel(m_model);
 
211
  m_modelSpy->setModel(m_proxyModel);
 
212
}
 
213
 
 
214
void ProxyModelTest::setExpected(const QString &name, const QList<QVariantList> &list, const QList<PersistentIndexChange> &persistentChanges)
 
215
{
 
216
  m_expectedSignals.insert(name, list);
 
217
  m_persistentChanges.insert(name, persistentChanges);
 
218
}
 
219
 
 
220
QModelIndexList ProxyModelTest::getDescendantIndexes(const QModelIndex &parent)
 
221
{
 
222
  QModelIndexList list;
 
223
  const int column = 0;
 
224
  for(int row = 0; row < m_proxyModel->rowCount(parent); ++row)
 
225
  {
 
226
    QModelIndex idx = m_proxyModel->index(row, column, parent);
 
227
    list << idx;
 
228
    list << getDescendantIndexes(idx);
 
229
  }
 
230
  return list;
 
231
}
 
232
 
 
233
QList< QPersistentModelIndex > ProxyModelTest::toPersistent(QModelIndexList list)
 
234
{
 
235
  QList<QPersistentModelIndex > persistentList;
 
236
  foreach(QModelIndex idx, list)
 
237
  {
 
238
    persistentList << QPersistentModelIndex(idx);
 
239
  }
 
240
  return persistentList;
 
241
}
 
242
 
 
243
 
 
244
QModelIndexList ProxyModelTest::getUnchangedIndexes(const QModelIndex &parent, QList<QItemSelectionRange> ignoredRanges)
 
245
{
 
246
  QModelIndexList list;
 
247
  int rowCount = m_proxyModel->rowCount(parent);
 
248
  for (int row = 0; row < rowCount; )
 
249
  {
 
250
    int column = 0;
 
251
    QModelIndex idx = m_proxyModel->index( row, column, parent);
 
252
    bool found = false;
 
253
    foreach(QItemSelectionRange range, ignoredRanges)
 
254
    {
 
255
      if (range.topLeft().parent() == parent &&  range.topLeft().row() == idx.row())
 
256
      {
 
257
        row = range.bottomRight().row() + 1;
 
258
        found = true;
 
259
        break;
 
260
      }
 
261
    }
 
262
    if (!found)
 
263
    {
 
264
      for (column = 0; column < m_proxyModel->columnCount(); ++column )
 
265
        list << m_proxyModel->index( row, column, parent);
 
266
      list << getUnchangedIndexes(idx, ignoredRanges);
 
267
      ++row;
 
268
    }
 
269
  }
 
270
  return list;
 
271
}
 
272
 
 
273
 
 
274
void ProxyModelTest::doTest()
 
275
{
 
276
  QFETCH( CommandList, commandList );
 
277
 
 
278
  const char *currentTag = QTest::currentDataTag();
 
279
 
 
280
  QVERIFY(currentTag != 0);
 
281
  QVERIFY(m_expectedSignals.contains(currentTag));
 
282
  QVERIFY(m_persistentChanges.contains(currentTag));
 
283
 
 
284
  QList<QVariantList> signalList = m_expectedSignals.value(currentTag);
 
285
 
 
286
  // Take persistent indexes.
 
287
  QList<PersistentIndexChange> changeList = m_persistentChanges.value(currentTag);
 
288
 
 
289
  QList<QPersistentModelIndex> persistentIndexes;
 
290
 
 
291
  const int columnCount = m_model->columnCount();
 
292
  QMutableListIterator<PersistentIndexChange> it(changeList);
 
293
 
 
294
  QList<QItemSelectionRange> changedRanges;
 
295
  while (it.hasNext())
 
296
  {
 
297
    PersistentIndexChange change = it.next();
 
298
    QModelIndex parent = change.parentFinder.getIndex();
 
299
 
 
300
    QVERIFY(change.startRow >= 0);
 
301
    QVERIFY(change.endRow < m_proxyModel->rowCount(parent));
 
302
 
 
303
    QModelIndex topLeft = m_proxyModel->index( change.startRow, 0, parent );
 
304
    QModelIndex bottomRight = m_proxyModel->index( change.endRow, columnCount - 1, parent );
 
305
 
 
306
    changedRanges << QItemSelectionRange(topLeft, bottomRight);
 
307
 
 
308
 
 
309
    for (int row = change.startRow; row <= change.endRow; ++row )
 
310
    {
 
311
      for (int column = 0; column < columnCount; ++column)
 
312
      {
 
313
        QModelIndex idx = m_proxyModel->index(row, column, parent);
 
314
        QVERIFY(idx.isValid());
 
315
        change.indexes << idx;
 
316
        change.persistentIndexes << QPersistentModelIndex(idx);
 
317
      }
 
318
      QModelIndex idx = m_proxyModel->index(row, 0, parent);
 
319
      QModelIndexList descs = getDescendantIndexes(idx);
 
320
      change.descendantIndexes << descs;
 
321
      change.persistentDescendantIndexes << toPersistent(descs);
 
322
    }
 
323
    it.setValue(change);
 
324
  }
 
325
 
 
326
  QModelIndexList unchangedIndexes = getUnchangedIndexes(QModelIndex(), changedRanges);
 
327
 
 
328
  QList<QPersistentModelIndex> unchangedPersistentIndexes = toPersistent(unchangedIndexes);
 
329
 
 
330
  foreach(ModelChangeCommand *command, commandList)
 
331
  {
 
332
    command->doCommand();
 
333
  }
 
334
 
 
335
  while (!signalList.isEmpty())
 
336
  {
 
337
    QVariantList expected = signalList.takeAt(0);
 
338
    handleSignal(expected);
 
339
  }
 
340
  QVERIFY(m_modelSpy->isEmpty());
 
341
 
 
342
 
 
343
  foreach (PersistentIndexChange change, changeList)
 
344
  {
 
345
    for (int i = 0; i < change.indexes.size(); i++)
 
346
    {
 
347
      QModelIndex idx = change.indexes.at(i);
 
348
      QPersistentModelIndex persistentIndex = change.persistentIndexes.at(i);
 
349
      if (change.toInvalid)
 
350
      {
 
351
        QVERIFY(!persistentIndex.isValid());
 
352
        continue;
 
353
      }
 
354
      QCOMPARE(idx.row() + change.difference, persistentIndex.row());
 
355
      QCOMPARE(idx.column(), persistentIndex.column());
 
356
      QCOMPARE(idx.parent(), persistentIndex.parent());
 
357
    }
 
358
 
 
359
    for (int i = 0; i < change.descendantIndexes.size(); i++)
 
360
    {
 
361
      QModelIndex idx = change.descendantIndexes.at(i);
 
362
      QPersistentModelIndex persistentIndex = change.persistentDescendantIndexes.at(i);
 
363
      if (change.toInvalid)
 
364
      {
 
365
        QVERIFY(!persistentIndex.isValid());
 
366
        continue;
 
367
      }
 
368
      QCOMPARE(idx.row(), persistentIndex.row());
 
369
      QCOMPARE(idx.column(), persistentIndex.column());
 
370
      QCOMPARE(idx.parent(), persistentIndex.parent());
 
371
    }
 
372
  }
 
373
  for (int i = 0; i < unchangedIndexes.size(); ++i)
 
374
  {
 
375
    QModelIndex unchangedIdx = unchangedIndexes.at(i);
 
376
    QPersistentModelIndex persistentIndex = unchangedPersistentIndexes.at(i);
 
377
    QCOMPARE(unchangedIdx.row(), persistentIndex.row());
 
378
    QCOMPARE(unchangedIdx.column(), persistentIndex.column());
 
379
    QCOMPARE(unchangedIdx.parent(), persistentIndex.parent());
 
380
  }
 
381
}
 
382
 
 
383
 
 
384
void ProxyModelTest::testInsertAndRemove_data()
 
385
{
 
386
  QTest::addColumn<CommandList>("commandList");
 
387
 
 
388
  CommandList commandList;
 
389
 
 
390
  // Insert a single item at the top.
 
391
  ModelInsertCommand *ins;
 
392
  ins = new ModelInsertCommand(sourceModel(), this);
 
393
  ins->setStartRow(0);
 
394
  ins->setEndRow(0);
 
395
  ins->doCommand();
 
396
 
 
397
  QTest::newRow("insert01") << commandList;
 
398
  commandList.clear();
 
399
 
 
400
  // Give the top level item 10 children.
 
401
  ins = new ModelInsertCommand(m_model, this);
 
402
  ins->setAncestorRowNumbers(QList<int>() << 0 );
 
403
  ins->setStartRow(0);
 
404
  ins->setEndRow(9);
 
405
 
 
406
  commandList << ins;
 
407
 
 
408
  QTest::newRow("insert02") << commandList;
 
409
  commandList.clear();
 
410
 
 
411
  // Give the top level item 10 'older' siblings.
 
412
  ins = new ModelInsertCommand(m_model, this);
 
413
  ins->setStartRow(0);
 
414
  ins->setEndRow(9);
 
415
 
 
416
  commandList << ins;
 
417
 
 
418
  QTest::newRow("insert03") << commandList;
 
419
  commandList.clear();
 
420
 
 
421
  // Give the top level item 10 'younger' siblings.
 
422
  ins = new ModelInsertCommand(m_model, this);
 
423
  ins->setStartRow(11);
 
424
  ins->setEndRow(20);
 
425
 
 
426
  commandList << ins;
 
427
 
 
428
  QTest::newRow("insert04") << commandList;
 
429
  commandList.clear();
 
430
 
 
431
  // Add more children to the top level item.
 
432
  // First 'older'
 
433
  ins = new ModelInsertCommand(m_model, this);
 
434
  ins->setAncestorRowNumbers(QList<int>() << 10 );
 
435
  ins->setStartRow(0);
 
436
  ins->setEndRow(9);
 
437
 
 
438
  commandList << ins;
 
439
 
 
440
  QTest::newRow("insert05") << commandList;
 
441
  commandList.clear();
 
442
 
 
443
  // Then younger
 
444
  ins = new ModelInsertCommand(m_model, this);
 
445
  ins->setAncestorRowNumbers(QList<int>() << 10 );
 
446
  ins->setStartRow(20);
 
447
  ins->setEndRow(29);
 
448
 
 
449
  commandList << ins;
 
450
 
 
451
  QTest::newRow("insert06") << commandList;
 
452
  commandList.clear();
 
453
 
 
454
  // Then somewhere in the middle.
 
455
  ins = new ModelInsertCommand(m_model, this);
 
456
  ins->setAncestorRowNumbers(QList<int>() << 10 );
 
457
  ins->setStartRow(10);
 
458
  ins->setEndRow(19);
 
459
 
 
460
  commandList << ins;
 
461
 
 
462
  QTest::newRow("insert07") << commandList;
 
463
  commandList.clear();
 
464
 
 
465
  // Add some more items for removing later.
 
466
  ins = new ModelInsertCommand(m_model, this);
 
467
  ins->setAncestorRowNumbers(QList<int>() << 10 << 5 );
 
468
  ins->setStartRow(0);
 
469
  ins->setEndRow(9);
 
470
  commandList << ins;
 
471
  ins = new ModelInsertCommand(m_model, this);
 
472
  ins->setAncestorRowNumbers(QList<int>() << 10 << 5 << 5 );
 
473
  ins->setStartRow(0);
 
474
  ins->setEndRow(9);
 
475
  commandList << ins;
 
476
  ins = new ModelInsertCommand(m_model, this);
 
477
  ins->setAncestorRowNumbers(QList<int>() << 10 << 5 << 5 << 5 );
 
478
  ins->setStartRow(0);
 
479
  ins->setEndRow(9);
 
480
  commandList << ins;
 
481
  ins = new ModelInsertCommand(m_model, this);
 
482
  ins->setAncestorRowNumbers(QList<int>() << 10 << 6 );
 
483
  ins->setStartRow(0);
 
484
  ins->setEndRow(9);
 
485
  commandList << ins;
 
486
  ins = new ModelInsertCommand(m_model, this);
 
487
  ins->setAncestorRowNumbers(QList<int>() << 10 << 7 );
 
488
  ins->setStartRow(0);
 
489
  ins->setEndRow(9);
 
490
  commandList << ins;
 
491
 
 
492
  QTest::newRow("insert08") << commandList;
 
493
  commandList.clear();
 
494
 
 
495
  ModelRemoveCommand *rem;
 
496
 
 
497
  // Remove a single item without children.
 
498
  rem = new ModelRemoveCommand(m_model, this);
 
499
  rem->setAncestorRowNumbers(QList<int>() << 10 );
 
500
  rem->setStartRow(0);
 
501
  rem->setEndRow(0);
 
502
 
 
503
  commandList << rem;
 
504
 
 
505
  QTest::newRow("remove01") << commandList;
 
506
  commandList.clear();
 
507
 
 
508
  // Remove a single item with 10 children.
 
509
  rem = new ModelRemoveCommand(m_model, this);
 
510
  rem->setAncestorRowNumbers(QList<int>() << 10 );
 
511
  rem->setStartRow(6);
 
512
  rem->setEndRow(6);
 
513
 
 
514
  commandList << rem;
 
515
 
 
516
  QTest::newRow("remove02") << commandList;
 
517
  commandList.clear();
 
518
 
 
519
  // Remove a single item with no children from the top.
 
520
  rem = new ModelRemoveCommand(m_model, this);
 
521
  rem->setAncestorRowNumbers(QList<int>() << 10 << 5 );
 
522
  rem->setStartRow(0);
 
523
  rem->setEndRow(0);
 
524
 
 
525
  commandList << rem;
 
526
 
 
527
  QTest::newRow("remove03") << commandList;
 
528
  commandList.clear();
 
529
 
 
530
  // Remove a single second level item with no children from the bottom.
 
531
  rem = new ModelRemoveCommand(m_model, this);
 
532
  rem->setAncestorRowNumbers(QList<int>() << 10 << 5 );
 
533
  rem->setStartRow(8);
 
534
  rem->setEndRow(8);
 
535
 
 
536
  commandList << rem;
 
537
 
 
538
  QTest::newRow("remove04") << commandList;
 
539
  commandList.clear();
 
540
 
 
541
  // Remove a single second level item with no children from the middle.
 
542
  rem = new ModelRemoveCommand(m_model, this);
 
543
  rem->setAncestorRowNumbers(QList<int>() << 10 << 5 );
 
544
  rem->setStartRow(3);
 
545
  rem->setEndRow(3);
 
546
 
 
547
  commandList << rem;
 
548
 
 
549
  QTest::newRow("remove05") << commandList;
 
550
  commandList.clear();
 
551
 
 
552
  // clear the children of a second level item.
 
553
  rem = new ModelRemoveCommand(m_model, this);
 
554
  rem->setAncestorRowNumbers(QList<int>() << 10 << 5 );
 
555
  rem->setStartRow(0);
 
556
  rem->setEndRow(6);
 
557
 
 
558
  commandList << rem;
 
559
 
 
560
  QTest::newRow("remove06") << commandList;
 
561
  commandList.clear();
 
562
 
 
563
  // Clear a sub-tree;
 
564
  rem = new ModelRemoveCommand(m_model, this);
 
565
  rem->setAncestorRowNumbers(QList<int>() << 10 );
 
566
  rem->setStartRow(4);
 
567
  rem->setEndRow(4);
 
568
 
 
569
  commandList << rem;
 
570
 
 
571
  QTest::newRow("remove07") << commandList;
 
572
  commandList.clear();
 
573
 
 
574
 
 
575
 
 
576
 
 
577
 
 
578
}