• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • kasten
  • controllers
  • view
  • structures
modeltest.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2007 Trolltech ASA. All rights reserved.
4 **
5 ** This file is part of the Qt Concurrent project on Trolltech Labs.
6 **
7 ** This file may be used under the terms of the GNU General Public
8 ** License version 2.0 as published by the Free Software Foundation
9 ** and appearing in the file LICENSE.GPL included in the packaging of
10 ** this file. Please review the following information to ensure GNU
11 ** General Public Licensing requirements will be met:
12 ** http://www.trolltech.com/products/qt/opensource.html
13 **
14 ** If you are unsure which license is appropriate for your use, please
15 ** review the following information:
16 ** http://www.trolltech.com/products/qt/licensing.html or contact the
17 ** sales department at sales@trolltech.com.
18 **
19 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
20 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 **
22 ****************************************************************************/
23 
24 #include <QtGui/QtGui>
25 
26 #include "modeltest.h"
27 
28 Q_DECLARE_METATYPE ( QModelIndex )
29 
30 
33 ModelTest::ModelTest ( QAbstractItemModel *_model, QObject *parent ) : QObject ( parent ), model ( _model ), fetchingMore ( false )
34 {
35  Q_ASSERT ( model );
36 
37  connect ( model, SIGNAL ( columnsAboutToBeInserted ( const QModelIndex &, int, int ) ),
38  this, SLOT ( runAllTests() ) );
39  connect ( model, SIGNAL ( columnsAboutToBeRemoved ( const QModelIndex &, int, int ) ),
40  this, SLOT ( runAllTests() ) );
41  connect ( model, SIGNAL ( columnsInserted ( const QModelIndex &, int, int ) ),
42  this, SLOT ( runAllTests() ) );
43  connect ( model, SIGNAL ( columnsRemoved ( const QModelIndex &, int, int ) ),
44  this, SLOT ( runAllTests() ) );
45  connect ( model, SIGNAL ( dataChanged ( const QModelIndex &, const QModelIndex & ) ),
46  this, SLOT ( runAllTests() ) );
47  connect ( model, SIGNAL ( headerDataChanged ( Qt::Orientation, int, int ) ),
48  this, SLOT ( runAllTests() ) );
49  connect ( model, SIGNAL ( layoutAboutToBeChanged () ), this, SLOT ( runAllTests() ) );
50  connect ( model, SIGNAL ( layoutChanged () ), this, SLOT ( runAllTests() ) );
51  connect ( model, SIGNAL ( modelReset () ), this, SLOT ( runAllTests() ) );
52  connect ( model, SIGNAL ( modelAboutToBeReset () ), this, SLOT ( modelAboutToBeReset() ) );
53  connect ( model, SIGNAL ( modelReset () ), this, SLOT ( modelReset() ) );
54  connect ( model, SIGNAL ( rowsAboutToBeInserted ( const QModelIndex &, int, int ) ),
55  this, SLOT ( runAllTests() ) );
56  connect ( model, SIGNAL ( rowsAboutToBeRemoved ( const QModelIndex &, int, int ) ),
57  this, SLOT ( runAllTests() ) );
58  connect ( model, SIGNAL ( rowsInserted ( const QModelIndex &, int, int ) ),
59  this, SLOT ( runAllTests() ) );
60  connect ( model, SIGNAL ( rowsRemoved ( const QModelIndex &, int, int ) ),
61  this, SLOT ( runAllTests() ) );
62 
63  // Special checks for inserting/removing
64  connect ( model, SIGNAL ( layoutAboutToBeChanged() ),
65  this, SLOT ( layoutAboutToBeChanged() ) );
66  connect ( model, SIGNAL ( layoutChanged() ),
67  this, SLOT ( layoutChanged() ) );
68 
69  connect ( model, SIGNAL ( rowsAboutToBeInserted ( const QModelIndex &, int, int ) ),
70  this, SLOT ( rowsAboutToBeInserted ( const QModelIndex &, int, int ) ) );
71  connect ( model, SIGNAL ( rowsAboutToBeRemoved ( const QModelIndex &, int, int ) ),
72  this, SLOT ( rowsAboutToBeRemoved ( const QModelIndex &, int, int ) ) );
73  connect ( model, SIGNAL ( rowsInserted ( const QModelIndex &, int, int ) ),
74  this, SLOT ( rowsInserted ( const QModelIndex &, int, int ) ) );
75  connect ( model, SIGNAL ( rowsRemoved ( const QModelIndex &, int, int ) ),
76  this, SLOT ( rowsRemoved ( const QModelIndex &, int, int ) ) );
77 
78  connect ( model, SIGNAL ( rowsAboutToBeMoved ( const QModelIndex &, int, int, const QModelIndex &, int ) ),
79  this, SLOT ( rowsAboutToBeMoved ( const QModelIndex &, int, int, const QModelIndex &, int ) ) );
80  connect ( model, SIGNAL ( rowsMoved ( const QModelIndex &, int, int, const QModelIndex &, int ) ),
81  this, SLOT ( rowsMoved ( const QModelIndex &, int, int, const QModelIndex &, int ) ) );
82 
83  runAllTests();
84 }
85 
86 void ModelTest::runAllTests()
87 {
88 
89 // qDebug() << "rats";
90  if ( fetchingMore )
91  return;
92  nonDestructiveBasicTest();
93  rowCount();
94  columnCount();
95  hasIndex();
96  index();
97  parent();
98  data();
99 }
100 
105 void ModelTest::nonDestructiveBasicTest()
106 {
107  Q_ASSERT ( model->buddy ( QModelIndex() ) == QModelIndex() );
108 // model->canFetchMore ( QModelIndex() );
109  Q_ASSERT ( model->columnCount ( QModelIndex() ) >= 0 );
110  Q_ASSERT ( model->data ( QModelIndex() ) == QVariant() );
111 // fetchingMore = true;
112 // model->fetchMore ( QModelIndex() );
113 // fetchingMore = false;
114  Qt::ItemFlags flags = model->flags ( QModelIndex() );
115  Q_ASSERT ( flags == Qt::ItemIsDropEnabled || flags == 0 );
116  Q_UNUSED(flags)
117  model->hasChildren ( QModelIndex() );
118  model->hasIndex ( 0, 0 );
119  model->headerData ( 0, Qt::Horizontal );
120  model->index ( 0, 0 );
121  model->itemData ( QModelIndex() );
122  QVariant cache;
123  model->match ( QModelIndex(), -1, cache );
124  model->mimeTypes();
125  Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() );
126  Q_ASSERT ( model->rowCount() >= 0 );
127  QVariant variant;
128  model->setData ( QModelIndex(), variant, -1 );
129  model->setHeaderData ( -1, Qt::Horizontal, QVariant() );
130  model->setHeaderData ( 999999, Qt::Horizontal, QVariant() );
131  QMap<int, QVariant> roles;
132  model->sibling ( 0, 0, QModelIndex() );
133  model->span ( QModelIndex() );
134  model->supportedDropActions();
135 }
136 
142 void ModelTest::rowCount()
143 {
144 // qDebug() << "rc";
145  // check top row
146  QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
147  int rows = model->rowCount ( topIndex );
148  Q_ASSERT ( rows >= 0 );
149  if ( rows > 0 )
150  Q_ASSERT ( model->hasChildren ( topIndex ) == true );
151 
152  QModelIndex secondLevelIndex = model->index ( 0, 0, topIndex );
153  if ( secondLevelIndex.isValid() ) { // not the top level
154  // check a row count where parent is valid
155  rows = model->rowCount ( secondLevelIndex );
156  Q_ASSERT ( rows >= 0 );
157  if ( rows > 0 )
158  Q_ASSERT ( model->hasChildren ( secondLevelIndex ) == true );
159  }
160 
161  // The models rowCount() is tested more extensively in checkChildren(),
162  // but this catches the big mistakes
163 }
164 
168 void ModelTest::columnCount()
169 {
170  // check top row
171  QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
172  Q_ASSERT ( model->columnCount ( topIndex ) >= 0 );
173 
174  // check a column count where parent is valid
175  QModelIndex childIndex = model->index ( 0, 0, topIndex );
176  if ( childIndex.isValid() )
177  Q_ASSERT ( model->columnCount ( childIndex ) >= 0 );
178 
179  // columnCount() is tested more extensively in checkChildren(),
180  // but this catches the big mistakes
181 }
182 
186 void ModelTest::hasIndex()
187 {
188 // qDebug() << "hi";
189  // Make sure that invalid values returns an invalid index
190  Q_ASSERT ( model->hasIndex ( -2, -2 ) == false );
191  Q_ASSERT ( model->hasIndex ( -2, 0 ) == false );
192  Q_ASSERT ( model->hasIndex ( 0, -2 ) == false );
193 
194  int rows = model->rowCount();
195  int columns = model->columnCount();
196 
197  // check out of bounds
198  Q_ASSERT ( model->hasIndex ( rows, columns ) == false );
199  Q_ASSERT ( model->hasIndex ( rows + 1, columns + 1 ) == false );
200 
201  if ( rows > 0 )
202  Q_ASSERT ( model->hasIndex ( 0, 0 ) == true );
203 
204  Q_UNUSED(columns)
205  // hasIndex() is tested more extensively in checkChildren(),
206  // but this catches the big mistakes
207 }
208 
212 void ModelTest::index()
213 {
214 // qDebug() << "i";
215  // Make sure that invalid values returns an invalid index
216  Q_ASSERT ( model->index ( -2, -2 ) == QModelIndex() );
217  Q_ASSERT ( model->index ( -2, 0 ) == QModelIndex() );
218  Q_ASSERT ( model->index ( 0, -2 ) == QModelIndex() );
219 
220  int rows = model->rowCount();
221  int columns = model->columnCount();
222 
223  if ( rows == 0 )
224  return;
225 
226  // Catch off by one errors
227  Q_ASSERT ( model->index ( rows, columns ) == QModelIndex() );
228  Q_ASSERT ( model->index ( 0, 0 ).isValid() == true );
229 
230  // Make sure that the same index is *always* returned
231  QModelIndex a = model->index ( 0, 0 );
232  QModelIndex b = model->index ( 0, 0 );
233  Q_ASSERT ( a == b );
234  Q_UNUSED(columns)
235  // index() is tested more extensively in checkChildren(),
236  // but this catches the big mistakes
237 }
238 
242 void ModelTest::parent()
243 {
244 // qDebug() << "p";
245  // Make sure the model wont crash and will return an invalid QModelIndex
246  // when asked for the parent of an invalid index.
247  Q_ASSERT ( model->parent ( QModelIndex() ) == QModelIndex() );
248 
249  if ( model->rowCount() == 0 )
250  return;
251 
252  // Column 0 | Column 1 |
253  // QModelIndex() | |
254  // \- topIndex | topIndex1 |
255  // \- childIndex | childIndex1 |
256 
257  // Common error test #1, make sure that a top level index has a parent
258  // that is a invalid QModelIndex.
259  QModelIndex topIndex = model->index ( 0, 0, QModelIndex() );
260  Q_ASSERT ( model->parent ( topIndex ) == QModelIndex() );
261 
262  // Common error test #2, make sure that a second level index has a parent
263  // that is the first level index.
264  if ( model->rowCount ( topIndex ) > 0 ) {
265  QModelIndex childIndex = model->index ( 0, 0, topIndex );
266  Q_ASSERT ( model->parent ( childIndex ) == topIndex );
267  }
268 
269  // Common error test #3, the second column should NOT have the same children
270  // as the first column in a row.
271  // Usually the second column shouldn't have children.
272  QModelIndex topIndex1 = model->index ( 0, 1, QModelIndex() );
273  if ( model->rowCount ( topIndex1 ) > 0 ) {
274  QModelIndex childIndex = model->index ( 0, 0, topIndex );
275  QModelIndex childIndex1 = model->index ( 0, 0, topIndex1 );
276  Q_ASSERT ( childIndex != childIndex1 );
277  }
278 
279  // Full test, walk n levels deep through the model making sure that all
280  // parent's children correctly specify their parent.
281  checkChildren ( QModelIndex() );
282 }
283 
298 void ModelTest::checkChildren ( const QModelIndex &parent, int currentDepth )
299 {
300  // First just try walking back up the tree.
301  QModelIndex p = parent;
302  while ( p.isValid() )
303  p = p.parent();
304 
305  // For models that are dynamically populated
306 // if ( model->canFetchMore ( parent ) ) {
307 // fetchingMore = true;
308 // model->fetchMore ( parent );
309 // fetchingMore = false;
310 // }
311 
312  int rows = model->rowCount ( parent );
313  int columns = model->columnCount ( parent );
314 
315  if ( rows > 0 )
316  {
317 
318  Q_ASSERT(parent.column() <= 0);
319  Q_ASSERT ( model->hasChildren ( parent ) );
320  }
321 
322  // Some further testing against rows(), columns(), and hasChildren()
323  Q_ASSERT ( rows >= 0 );
324  Q_ASSERT ( columns >= 0 );
325  if ( rows > 0 )
326  Q_ASSERT ( model->hasChildren ( parent ) == true );
327 
328  //qDebug() << "parent:" << model->data(parent).toString() << "rows:" << rows
329  // << "columns:" << columns << "parent column:" << parent.column();
330 
331  Q_ASSERT ( model->hasIndex ( rows, 0, parent ) == false );
332  Q_ASSERT ( model->index(rows, 0, parent).isValid() == false );
333  for ( int r = 0; r < rows; ++r ) {
334 // if ( model->canFetchMore ( parent ) ) {
335 // fetchingMore = true;
336 // model->fetchMore ( parent );
337 // fetchingMore = false;
338 // }
339  Q_ASSERT ( model->hasIndex ( r, columns, parent ) == false );
340  Q_ASSERT ( model->index(r, columns, parent).isValid() == false );
341  for ( int c = 0; c < columns; ++c ) {
342  Q_ASSERT ( model->hasIndex ( r, c, parent ) == true );
343  QModelIndex index = model->index ( r, c, parent );
344  // rowCount() and columnCount() said that it existed...
345  Q_ASSERT ( index.isValid() == true );
346 
347  // index() should always return the same index when called twice in a row
348  QModelIndex modifiedIndex = model->index ( r, c, parent );
349  Q_ASSERT ( index == modifiedIndex );
350 
351  // Make sure we get the same index if we request it twice in a row
352  QModelIndex a = model->index ( r, c, parent );
353  QModelIndex b = model->index ( r, c, parent );
354  Q_ASSERT ( a == b );
355 
356  // Some basic checking on the index that is returned
357  Q_ASSERT ( index.model() == model );
358  Q_ASSERT ( index.row() == r );
359  Q_ASSERT ( index.column() == c );
360  // While you can technically return a QVariant usually this is a sign
361  // of an bug in data() Disable if this really is ok in your model.
362 // qDebug() << index << index.data() << index.parent();
363  Q_ASSERT ( model->data ( index, Qt::DisplayRole ).isValid() == true );
364 
365  // If the next test fails here is some somewhat useful debug you play with.
366  /*
367  if (model->parent(index) != parent) {
368  qDebug() << r << c << currentDepth << model->data(index).toString()
369  << model->data(parent).toString();
370  qDebug() << index << parent << model->parent(index);
371  // And a view that you can even use to show the model.
372  //QTreeView view;
373  //view.setModel(model);
374  //view.show();
375  }*/
376 
377  // Check that we can get back our real parent.
378  Q_ASSERT ( model->parent ( index ) == parent );
379 
380  // recursively go down the children
381  if ( model->hasChildren ( index ) && currentDepth < 10 ) {
382  //qDebug() << r << c << "has children" << model->rowCount(index);
383  checkChildren ( index, ++currentDepth );
384  }/* else { if (currentDepth >= 10) qDebug() << "checked 10 deep"; };*/
385 
386  // make sure that after testing the children that the index doesn't change.
387  QModelIndex newerIndex = model->index ( r, c, parent );
388  Q_ASSERT ( index == newerIndex );
389  }
390  }
391 }
392 
396 void ModelTest::data()
397 {
398  // Invalid index should return an invalid qvariant
399  Q_ASSERT ( !model->data ( QModelIndex() ).isValid() );
400 
401  if ( model->rowCount() == 0 )
402  return;
403 
404  // A valid index should have a valid QVariant data
405  Q_ASSERT ( model->index ( 0, 0 ).isValid() );
406 
407  // shouldn't be able to set data on an invalid index
408  Q_ASSERT ( model->setData ( QModelIndex(), QLatin1String ( "foo" ), Qt::DisplayRole ) == false );
409 
410  // General Purpose roles that should return a QString
411  QVariant variant = model->data ( model->index ( 0, 0 ), Qt::ToolTipRole );
412  if ( variant.isValid() ) {
413  Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
414  }
415  variant = model->data ( model->index ( 0, 0 ), Qt::StatusTipRole );
416  if ( variant.isValid() ) {
417  Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
418  }
419  variant = model->data ( model->index ( 0, 0 ), Qt::WhatsThisRole );
420  if ( variant.isValid() ) {
421  Q_ASSERT ( qVariantCanConvert<QString> ( variant ) );
422  }
423 
424  // General Purpose roles that should return a QSize
425  variant = model->data ( model->index ( 0, 0 ), Qt::SizeHintRole );
426  if ( variant.isValid() ) {
427  Q_ASSERT ( qVariantCanConvert<QSize> ( variant ) );
428  }
429 
430  // General Purpose roles that should return a QFont
431  QVariant fontVariant = model->data ( model->index ( 0, 0 ), Qt::FontRole );
432  if ( fontVariant.isValid() ) {
433  Q_ASSERT ( qVariantCanConvert<QFont> ( fontVariant ) );
434  }
435 
436  // Check that the alignment is one we know about
437  QVariant textAlignmentVariant = model->data ( model->index ( 0, 0 ), Qt::TextAlignmentRole );
438  if ( textAlignmentVariant.isValid() ) {
439  int alignment = textAlignmentVariant.toInt();
440  Q_ASSERT ( alignment == ( alignment & ( Qt::AlignHorizontal_Mask | Qt::AlignVertical_Mask ) ) );
441  Q_UNUSED(alignment)
442  }
443 
444  // General Purpose roles that should return a QColor
445  QVariant colorVariant = model->data ( model->index ( 0, 0 ), Qt::BackgroundColorRole );
446  if ( colorVariant.isValid() ) {
447  Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) );
448  }
449 
450  colorVariant = model->data ( model->index ( 0, 0 ), Qt::TextColorRole );
451  if ( colorVariant.isValid() ) {
452  Q_ASSERT ( qVariantCanConvert<QColor> ( colorVariant ) );
453  }
454 
455  // Check that the "check state" is one we know about.
456  QVariant checkStateVariant = model->data ( model->index ( 0, 0 ), Qt::CheckStateRole );
457  if ( checkStateVariant.isValid() ) {
458  int state = checkStateVariant.toInt();
459  Q_ASSERT ( state == Qt::Unchecked ||
460  state == Qt::PartiallyChecked ||
461  state == Qt::Checked );
462  Q_UNUSED(state)
463  }
464 }
465 
471 void ModelTest::rowsAboutToBeInserted ( const QModelIndex &parent, int start, int end )
472 {
473 // Q_UNUSED(end);
474  qDebug() << "rowsAboutToBeInserted" << "start=" << start << "end=" << end << "parent=" << model->data ( parent ).value<QString>()
475  << "current count of parent=" << model->rowCount ( parent ); // << "display of last=" << model->data( model->index(start-1, 0, parent) );
476 // qDebug() << model->index(start-1, 0, parent) << model->data( model->index(start-1, 0, parent) );
477  Changing c;
478  c.parent = parent;
479  c.oldSize = model->rowCount ( parent );
480  c.last = model->data ( model->index ( start - 1, 0, parent ) );
481  c.next = model->data ( model->index ( start, 0, parent ) );
482  insert.push ( c );
483 }
484 
490 void ModelTest::rowsInserted ( const QModelIndex & parent, int start, int end )
491 {
492  Changing c = insert.pop();
493  Q_ASSERT ( c.parent == parent );
494  qDebug() << "rowsInserted" << "start=" << start << "end=" << end << "oldsize=" << c.oldSize
495  << "parent=" << model->data ( parent ).value<QString>() << "current rowcount=" << model->rowCount ( parent );
496 
497  for (int ii=start; ii <= end; ii++)
498  {
499  qDebug() << "itemWasInserted:" << model->data ( model->index ( ii, 0, parent ));
500  }
501 
502 
503  Q_ASSERT ( c.oldSize + ( end - start + 1 ) == model->rowCount ( parent ) );
504  Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
505  /*
506  if (c.next != model->data(model->index(end + 1, 0, c.parent))) {
507  qDebug() << start << end;
508  for (int i=0; i < model->rowCount(); ++i)
509  qDebug() << model->index(i, 0).data().toString();
510  qDebug() << c.next << model->data(model->index(end + 1, 0, c.parent));
511  }
512  */
513  Q_ASSERT ( c.next == model->data ( model->index ( end + 1, 0, c.parent ) ) );
514 }
515 
516 
517 void ModelTest::modelAboutToBeReset()
518 {
519  qDebug() << "@@@@@@@@@@@" << "modelAboutToBeReset";
520 }
521 
522 void ModelTest::modelReset()
523 {
524  qDebug() << "@@@@@@@@@@@" << "modelReset";
525 }
526 
527 void ModelTest::layoutAboutToBeChanged()
528 {
529  for ( int i = 0; i < qBound ( 0, model->rowCount(), 100 ); ++i )
530  changing.append ( QPersistentModelIndex ( model->index ( i, 0 ) ) );
531 }
532 
533 void ModelTest::layoutChanged()
534 {
535  for ( int i = 0; i < changing.count(); ++i ) {
536  QPersistentModelIndex p = changing[i];
537  Q_ASSERT ( p == model->index ( p.row(), p.column(), p.parent() ) );
538  }
539  changing.clear();
540 }
541 
542 void ModelTest::rowsAboutToBeMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow )
543 {
544  qDebug() << "rowsAboutToBeMoved" << srcParent << start << end << destParent << destinationRow;
545  Changing cs;
546  cs.parent = srcParent;
547  cs.oldSize = model->rowCount ( srcParent );
548  cs.last = model->data ( model->index ( start - 1, 0, srcParent ) );
549  cs.next = model->data ( model->index ( end + 1, 0, srcParent ) );
550  remove.push ( cs );
551  Changing cd;
552  cd.parent = destParent;
553  cd.oldSize = model->rowCount ( destParent );
554  cd.last = model->data ( model->index ( destinationRow - 1, 0, destParent ) );
555  cd.next = model->data ( model->index ( destinationRow, 0, destParent ) );
556  insert.push ( cd );
557 }
558 
559 void ModelTest::rowsMoved(const QModelIndex &srcParent, int start, int end, const QModelIndex &destParent, int destinationRow )
560 {
561  qDebug() << "rowsMoved" << srcParent << start << end << destParent << destinationRow;
562 
563  Changing cd = insert.pop();
564  Q_ASSERT ( cd.parent == destParent );
565  if (srcParent == destParent)
566  {
567  Q_ASSERT ( cd.oldSize == model->rowCount ( destParent ) );
568 
569  // TODO: Find out what I can assert here about last and next.
570 // Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) );
571 // Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) );
572 
573 
574  }
575  else
576  {
577  Q_ASSERT ( cd.oldSize + ( end - start + 1 ) == model->rowCount ( destParent ) );
578 
579  Q_ASSERT ( cd.last == model->data ( model->index ( destinationRow - 1, 0, cd.parent ) ) );
580  Q_ASSERT ( cd.next == model->data ( model->index ( destinationRow + (end - start + 1), 0, cd.parent ) ) );
581  }
582  Changing cs = remove.pop();
583 
584  Q_ASSERT ( cs.parent == srcParent );
585  if (srcParent == destParent)
586  {
587  Q_ASSERT ( cs.oldSize == model->rowCount ( srcParent ) );
588  }
589  else
590  {
591  Q_ASSERT ( cs.oldSize - ( end - start + 1 ) == model->rowCount ( srcParent ) );
592 
593  Q_ASSERT ( cs.last == model->data ( model->index ( start - 1, 0, srcParent ) ) );
594  qDebug() << cs.next << model->data ( model->index ( start, 0, srcParent ) );
595  Q_ASSERT ( cs.next == model->data ( model->index ( start, 0, srcParent ) ) );
596  }
597 
598 }
599 
605 void ModelTest::rowsAboutToBeRemoved ( const QModelIndex &parent, int start, int end )
606 {
607 qDebug() << "ratbr" << parent << start << end;
608  for (int ii=start; ii <= end; ii++)
609  {
610  qDebug() << "itemwillbe removed:" << model->data ( model->index ( ii, 0, parent ));
611  }
612 
613 
614  Changing c;
615  c.parent = parent;
616  c.oldSize = model->rowCount ( parent );
617  c.last = model->data ( model->index ( start - 1, 0, parent ) );
618  c.next = model->data ( model->index ( end + 1, 0, parent ) );
619  remove.push ( c );
620 }
621 
627 void ModelTest::rowsRemoved ( const QModelIndex & parent, int start, int end )
628 {
629  qDebug() << "rr" << parent << start << end;
630  Changing c = remove.pop();
631  Q_ASSERT ( c.parent == parent );
632  Q_ASSERT ( c.oldSize - ( end - start + 1 ) == model->rowCount ( parent ) );
633  Q_ASSERT ( c.last == model->data ( model->index ( start - 1, 0, c.parent ) ) );
634  Q_ASSERT ( c.next == model->data ( model->index ( start, 0, c.parent ) ) );
635 }
ModelTest::rowsAboutToBeMoved
void rowsAboutToBeMoved(const QModelIndex &, int, int, const QModelIndex &, int)
Definition: modeltest.cpp:542
ModelTest::runAllTests
void runAllTests()
Definition: modeltest.cpp:86
ModelTest::rowsInserted
void rowsInserted(const QModelIndex &parent, int start, int end)
Definition: modeltest.cpp:490
ModelTest::rowsAboutToBeRemoved
void rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
Definition: modeltest.cpp:605
ModelTest::modelReset
void modelReset()
Definition: modeltest.cpp:522
QObject
ModelTest::rowsAboutToBeInserted
void rowsAboutToBeInserted(const QModelIndex &parent, int start, int end)
Definition: modeltest.cpp:471
ModelTest::rowsMoved
void rowsMoved(const QModelIndex &, int, int, const QModelIndex &, int)
Definition: modeltest.cpp:559
ModelTest::modelAboutToBeReset
void modelAboutToBeReset()
Definition: modeltest.cpp:517
modeltest.h
QAbstractItemModel
ModelTest::rowsRemoved
void rowsRemoved(const QModelIndex &parent, int start, int end)
Definition: modeltest.cpp:627
ModelTest::layoutChanged
void layoutChanged()
Definition: modeltest.cpp:533
ModelTest
Definition: modeltest.h:31
ModelTest::layoutAboutToBeChanged
void layoutAboutToBeChanged()
Definition: modeltest.cpp:527
QMap
Definition: charsetconversiontool.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal