ctkModelTester.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #ifndef __ctkModelTester_h
  15. #define __ctkModelTester_h
  16. /// Qt includes
  17. #include <QObject>
  18. #include <QModelIndex>
  19. #include <QPersistentModelIndex>
  20. #include <QList>
  21. /// CTK includes
  22. #include "ctkPimpl.h"
  23. #include "CTKCoreExport.h"
  24. class QAbstractItemModel;
  25. class ctkModelTesterPrivate;
  26. class CTK_CORE_EXPORT ctkModelTester: public QObject
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(bool nestedInserts READ nestedInserts WRITE setNestedInserts);
  30. public:
  31. explicit ctkModelTester(QObject *parent = 0);
  32. ctkModelTester(QAbstractItemModel *model, QObject *parent = 0);
  33. void setModel(QAbstractItemModel* model);
  34. QAbstractItemModel* model()const;
  35. void setThrowOnError(bool throwException);
  36. bool throwOnError()const;
  37. void setNestedInserts(bool enable);
  38. bool nestedInserts()const;
  39. virtual void testData(const QModelIndex& index)const;
  40. virtual void testModel()const;
  41. virtual void testModelIndex(const QModelIndex& index)const;
  42. virtual void testParent(const QModelIndex& parent)const;
  43. virtual void testPersistentModelIndex(const QPersistentModelIndex& index)const;
  44. protected slots:
  45. void onColumnsAboutToBeInserted(const QModelIndex & parent, int start, int end);
  46. void onColumnsAboutToBeRemoved(const QModelIndex & parent, int start, int end);
  47. void onColumnsInserted(const QModelIndex & parent, int start, int end);
  48. void onColumnsRemoved(const QModelIndex & parent, int start, int end);
  49. void onDataChanged(const QModelIndex & topLeft, const QModelIndex & bottomRight);
  50. void onHeaderDataChanged(Qt::Orientation orientation, int first, int last);
  51. void onLayoutAboutToBeChanged();
  52. void onLayoutChanged();
  53. void onModelAboutToBeReset();
  54. void onModelReset();
  55. void onRowsAboutToBeInserted(const QModelIndex &parent, int start, int end);
  56. void onRowsAboutToBeRemoved(const QModelIndex &parent, int start, int end);
  57. void onRowsInserted(const QModelIndex & parent, int start, int end);
  58. void onRowsRemoved(const QModelIndex & parent, int start, int end);
  59. protected:
  60. virtual void onItemsAboutToBeInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
  61. virtual void onItemsAboutToBeRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
  62. virtual void onItemsInserted(const QModelIndex& parent, Qt::Orientation, int start, int end);
  63. virtual void onItemsRemoved(const QModelIndex& parent, Qt::Orientation, int start, int end);
  64. QList<QPersistentModelIndex> persistentModelIndexes(const QModelIndex& index)const;
  65. virtual void test(bool result, const QString& errorString)const;
  66. private:
  67. CTK_DECLARE_PRIVATE(ctkModelTester);
  68. };
  69. #endif