ctkDICOMModel.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 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.apache.org/licenses/LICENSE-2.0.txt
  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 __ctkDICOMModel_h
  15. #define __ctkDICOMModel_h
  16. // Qt includes
  17. #include <QAbstractItemModel>
  18. #include <QMetaType>
  19. #include <QSqlDatabase>
  20. #include <QStringList>
  21. #include "ctkDICOMCoreExport.h"
  22. class ctkDICOMModelPrivate;
  23. /// \ingroup DICOM_Core
  24. class CTK_DICOM_CORE_EXPORT ctkDICOMModel
  25. // : public QStandardItemModel
  26. : public QAbstractItemModel
  27. {
  28. Q_OBJECT
  29. typedef QAbstractItemModel Superclass;
  30. Q_ENUMS(IndexType)
  31. /// startLevel contains the hierarchy depth the model contains
  32. Q_PROPERTY(IndexType endLevel READ endLevel WRITE setEndLevel);
  33. public:
  34. enum {
  35. UIDRole = Qt::UserRole,
  36. TypeRole
  37. };
  38. enum IndexType{
  39. RootType,
  40. PatientType,
  41. StudyType,
  42. SeriesType,
  43. ImageType
  44. };
  45. explicit ctkDICOMModel(QObject* parent = 0);
  46. virtual ~ctkDICOMModel();
  47. void setDatabase(const QSqlDatabase& dataBase);
  48. void setDatabase(const QSqlDatabase& dataBase, const QMap<QString,QVariant>& parameters);
  49. /// Set it before populating the model
  50. ctkDICOMModel::IndexType endLevel()const;
  51. void setEndLevel(ctkDICOMModel::IndexType level);
  52. virtual bool canFetchMore ( const QModelIndex & parent ) const;
  53. virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const;
  54. virtual QVariant data ( const QModelIndex & index, int role = Qt::DisplayRole ) const;
  55. virtual void fetchMore ( const QModelIndex & parent );
  56. virtual Qt::ItemFlags flags ( const QModelIndex & index ) const;
  57. // can return true even if rowCount returns 0, you should use canFetchMore/fetchMore to populate
  58. // the children.
  59. virtual bool hasChildren ( const QModelIndex & parent = QModelIndex() ) const;
  60. virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole)const;
  61. virtual QModelIndex index ( int row, int column, const QModelIndex & parent = QModelIndex() ) const;
  62. virtual QModelIndex parent ( const QModelIndex & index ) const;
  63. virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const;
  64. virtual bool setData(const QModelIndex &index, const QVariant &value, int role);
  65. virtual bool setHeaderData ( int section, Qt::Orientation orientation, const QVariant & value, int role = Qt::EditRole );
  66. // Sorting resets the model because fetched/unfetched items could disappear/appear respectively.
  67. virtual void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
  68. public Q_SLOTS:
  69. virtual void reset();
  70. protected:
  71. QScopedPointer<ctkDICOMModelPrivate> d_ptr;
  72. bool setChildData(const QModelIndex &index, const QVariant &value, int role);
  73. bool setParentData(const QModelIndex &index, const QVariant &value, int role);
  74. private:
  75. Q_DECLARE_PRIVATE(ctkDICOMModel);
  76. Q_DISABLE_COPY(ctkDICOMModel);
  77. };
  78. Q_DECLARE_METATYPE(ctkDICOMModel::IndexType)
  79. #endif