ctkVTKDataSetModel.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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 __ctkVTKDataSetModel_h
  15. #define __ctkVTKDataSetModel_h
  16. // Qt includes
  17. #include <QStandardItemModel>
  18. // CTK includes
  19. #include <ctkVTKObject.h>
  20. // CTK includes
  21. #include "ctkVisualizationVTKWidgetsExport.h"
  22. class vtkDataSet;
  23. class vtkDataArray;
  24. /// \ingroup Visualization_VTK_Widgets
  25. namespace ctkVTK
  26. {
  27. enum ItemDataRole {
  28. PointerRole = Qt::UserRole + 1
  29. };
  30. };
  31. class ctkVTKDataSetModelPrivate;
  32. //------------------------------------------------------------------------------
  33. /// \ingroup Visualization_VTK_Widgets
  34. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKDataSetModel
  35. : public QStandardItemModel
  36. {
  37. Q_OBJECT
  38. QVTK_OBJECT
  39. Q_FLAGS(AttributeType AttributeTypes)
  40. /// This property holds the type of attribute that should be listed in the model.s
  41. /// By default all attributes are considered.
  42. /// \sa ctkVTKDataSetModel::AllAttribute
  43. Q_PROPERTY(AttributeTypes attributeTypes READ attributeTypes WRITE setAttributeTypes)
  44. public:
  45. typedef ctkVTKDataSetModel Self;
  46. typedef QStandardItemModel Superclass;
  47. ctkVTKDataSetModel(QObject *parent=0);
  48. virtual ~ctkVTKDataSetModel();
  49. enum AttributeType
  50. {
  51. NoAttribute = 0x1,
  52. ScalarsAttribute = 0x2,
  53. VectorsAttribute = 0x4,
  54. NormalsAttribute = 0x8,
  55. TCoordsAttribute = 0x10,
  56. TensorsAttribute = 0x20,
  57. GlobalIDsAttribute = 0x40,
  58. PedigreeIDsAttribute = 0x80,
  59. EdgeFlagAttribute = 0x100,
  60. AllAttribute = NoAttribute | ScalarsAttribute | VectorsAttribute | NormalsAttribute | TCoordsAttribute | TensorsAttribute | GlobalIDsAttribute | PedigreeIDsAttribute | EdgeFlagAttribute
  61. };
  62. Q_DECLARE_FLAGS(AttributeTypes, AttributeType)
  63. virtual void setDataSet(vtkDataSet* dataSet);
  64. vtkDataSet* dataSet()const;
  65. AttributeTypes attributeTypes()const;
  66. void setAttributeTypes(const AttributeTypes& attributeTypes);
  67. /// Return the vtkDataArray associated to the index.
  68. /// 0 if the index doesn't contain a vtkDataArray
  69. inline vtkDataArray* arrayFromIndex(const QModelIndex& arrayIndex)const;
  70. vtkDataArray* arrayFromItem(QStandardItem* nodeItem)const;
  71. inline QModelIndex indexFromArray(vtkDataArray* dataArray, int column = 0)const;
  72. QStandardItem* itemFromArray(vtkDataArray* dataArray, int column = 0)const;
  73. QModelIndexList indexes(vtkDataArray* dataArray)const;
  74. protected Q_SLOTS:
  75. void onDataSetModified(vtkObject* dataSet);
  76. void onArrayModified(vtkObject* dataArray);
  77. void onItemChanged(QStandardItem * item);
  78. protected:
  79. ctkVTKDataSetModel(ctkVTKDataSetModelPrivate* pimpl, QObject *parent=0);
  80. virtual void insertArray(vtkDataArray* dataArray);
  81. virtual void insertArray(vtkDataArray* dataArray, int row);
  82. virtual void updateItemFromArray(QStandardItem* item, vtkDataArray* dataArray, int column);
  83. virtual void updateArrayFromItem(vtkDataArray* dataArray, QStandardItem* item);
  84. virtual void updateDataSet();
  85. virtual void populateDataSet();
  86. protected:
  87. QScopedPointer<ctkVTKDataSetModelPrivate> d_ptr;
  88. private:
  89. Q_DECLARE_PRIVATE(ctkVTKDataSetModel);
  90. Q_DISABLE_COPY(ctkVTKDataSetModel);
  91. };
  92. Q_DECLARE_OPERATORS_FOR_FLAGS(ctkVTKDataSetModel::AttributeTypes);
  93. // -----------------------------------------------------------------------------
  94. vtkDataArray* ctkVTKDataSetModel::arrayFromIndex(const QModelIndex &nodeIndex)const
  95. {
  96. return this->arrayFromItem(this->itemFromIndex(nodeIndex));
  97. }
  98. // -----------------------------------------------------------------------------
  99. QModelIndex ctkVTKDataSetModel::indexFromArray(vtkDataArray* dataArray, int column)const
  100. {
  101. QStandardItem* item = this->itemFromArray(dataArray, column);
  102. return item ? item->index() : QModelIndex();
  103. }
  104. #endif