ctkModelTester.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*=========================================================================
  2. Library: ctk
  3. Copyright (c) Kitware Inc.
  4. All rights reserved.
  5. Distributed under a BSD License. See LICENSE.txt file.
  6. This software is distributed "AS IS" WITHOUT ANY WARRANTY; without even
  7. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the above copyright notice for more information.
  9. =========================================================================*/
  10. #ifndef __ctkModelTester_h
  11. #define __ctkModelTester_h
  12. /// QT includes
  13. #include <QObject>
  14. #include <QModelIndex>
  15. #include <QPersistentModelIndex>
  16. #include <QList>
  17. /// CTK includes
  18. #include "ctkPimpl.h"
  19. #include "CTKCoreExport.h"
  20. class QAbstractItemModel;
  21. class ctkModelTesterPrivate;
  22. class CTK_CORE_EXPORT ctkModelTester: public QObject
  23. {
  24. Q_OBJECT
  25. Q_PROPERTY(bool nestedInserts READ nestedInserts WRITE setNestedInserts);
  26. public:
  27. ctkModelTester(QAbstractItemModel *model, QObject *parent = 0);
  28. void setModel(QAbstractItemModel* model);
  29. QAbstractItemModel* model()const;
  30. void setThrowOnError(bool throwException);
  31. bool throwOnError()const;
  32. void setNestedInserts(bool enable);
  33. bool nestedInserts()const;
  34. virtual void testData(const QModelIndex& index)const;
  35. virtual void testModel()const;
  36. virtual void testModelIndex(const QModelIndex& index)const;
  37. virtual void testParent(const QModelIndex& parent)const;
  38. virtual void testPersistentModelIndex(const QPersistentModelIndex& index)const;
  39. protected slots:
  40. void onColumnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
  41. void onColumnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
  42. void onColumnsInserted(const QModelIndex & parent, int start, int end);
  43. void onColumnsRemoved(const QModelIndex & parent, int start, int end);
  44. void onDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
  45. void onHeaderDataChanged(Qt::Orientation orientation, int first, int last);
  46. void onLayoutAboutToBeChanged();
  47. void onLayoutChanged();
  48. void onModelAboutToBeReset();
  49. void onModelReset();
  50. void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
  51. void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
  52. void onRowsInserted(const QModelIndex & parent, int start, int end);
  53. void onRowsRemoved(const QModelIndex & parent, int start, int end);
  54. protected:
  55. virtual void onItemsAboutToBeInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
  56. virtual void onItemsAboutToBeRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
  57. virtual void onItemsInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
  58. virtual void onItemsRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
  59. QList<QPersistentModelIndex> persistentModelIndexes(const QModelIndex& index)const;
  60. virtual void test(bool result, const QString& errorString)const;
  61. private:
  62. QCTK_DECLARE_PRIVATE(ctkModelTester);
  63. };
  64. #endif