ctkVTKDataSetArrayComboBox.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 __ctkVTKDataSetArrayComboBox_h
  15. #define __ctkVTKDataSetArrayComboBox_h
  16. // Qt includes
  17. #include <QComboBox>
  18. // CTK includes
  19. #include "ctkVisualizationVTKWidgetsExport.h"
  20. #include "ctkVTKDataSetModel.h"
  21. class ctkVTKDataSetArrayComboBoxPrivate;
  22. class vtkAbstractArray;
  23. class vtkDataSet;
  24. /// \ingroup Visualization_VTK_Widgets
  25. ///
  26. /// QComboBox linked to vtkDataSet field arrays
  27. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKDataSetArrayComboBox
  28. : public QComboBox
  29. {
  30. Q_OBJECT
  31. Q_PROPERTY(ctkVTKDataSetModel::AttributeTypes attributeTypes READ attributeTypes WRITE setAttributeTypes)
  32. Q_PROPERTY(bool noneEnabled READ noneEnabled WRITE setNoneEnabled)
  33. public:
  34. /// Superclass typedef
  35. typedef QComboBox Superclass;
  36. /// Constructors
  37. explicit ctkVTKDataSetArrayComboBox(QWidget* parent = 0);
  38. virtual ~ctkVTKDataSetArrayComboBox();
  39. vtkAbstractArray* currentArray()const;
  40. QString currentArrayName()const;
  41. vtkDataSet* dataSet()const;
  42. /// Return the current array location, i.e. whether it's a point data
  43. /// array or a cell data array.
  44. /// \sa currentArrayChanged(int), ctkVTKDataSetModel::locationFromItem()
  45. int currentArrayLocation()const;
  46. ctkVTKDataSetModel::AttributeTypes attributeTypes()const;
  47. void setAttributeTypes(const ctkVTKDataSetModel::AttributeTypes& attributeTypes);
  48. /// Set/Get NoneEnabled flags
  49. /// An additional empty item is added into the list, where the user can select.
  50. /// It is recommended to enable this if the combobox is used to select active scalar of the
  51. /// observed VTK data set, because if there is no None option is available then the combobox selects
  52. /// the first array automatically if an array becomes available, causing unintended change of the VTK data set
  53. /// (and often infinite loop of widget/MRML node updates).
  54. void setNoneEnabled(bool enable);
  55. bool noneEnabled()const;
  56. /// Return a pointer to the model used to populate the combobox.
  57. /// \sa dataSet()
  58. ctkVTKDataSetModel* dataSetModel()const;
  59. public Q_SLOTS:
  60. /// Set the dataset to observe. It is used to as the "model" for the combobox.
  61. /// \sa dataSet(), dataSetModel()
  62. void setDataSet(vtkDataSet* dataSet);
  63. /// The array must exist in the dataset
  64. void setCurrentArray(vtkAbstractArray* dataArray);
  65. /// the array must exist in the dataset
  66. void setCurrentArray(const QString& name);
  67. Q_SIGNALS:
  68. void currentArrayChanged(vtkAbstractArray*);
  69. void currentArrayChanged(const QString& name);
  70. protected Q_SLOTS:
  71. void onCurrentIndexChanged(int);
  72. protected:
  73. QScopedPointer<ctkVTKDataSetArrayComboBoxPrivate> d_ptr;
  74. private:
  75. Q_DECLARE_PRIVATE(ctkVTKDataSetArrayComboBox);
  76. Q_DISABLE_COPY(ctkVTKDataSetArrayComboBox);
  77. };
  78. #endif