1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkQtTreeModelAdapter.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /*------------------------------------------------------------------------- 16 Copyright 2008 Sandia Corporation. 17 Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 18 the U.S. Government retains certain rights in this software. 19 -------------------------------------------------------------------------*/ 20 /** 21 * @class vtkQtTreeModelAdapter 22 * @brief Adapts a tree to a Qt item model. 23 * 24 * 25 * vtkQtTreeModelAdapter is a QAbstractItemModel with a vtkTree as its 26 * underlying data model. 27 * 28 * @sa 29 * vtkQtAbstractModelAdapter vtkQtTableModelAdapter 30 */ 31 32 #ifndef vtkQtTreeModelAdapter_h 33 #define vtkQtTreeModelAdapter_h 34 35 #include "vtkGUISupportQtModule.h" // For export macro 36 37 #include "vtkQtAbstractModelAdapter.h" 38 #include "vtkType.h" // Needed for vtkIdType 39 #include <QHash> // Needed for the decoration map 40 #include <QVector> // Needed for the index map 41 42 class vtkSelection; 43 class vtkTree; 44 class vtkAdjacentVertexIterator; 45 46 class QMimeData; 47 48 class VTKGUISUPPORTQT_EXPORT vtkQtTreeModelAdapter : public vtkQtAbstractModelAdapter 49 { 50 Q_OBJECT 51 52 public: 53 vtkQtTreeModelAdapter(QObject* parent = nullptr, vtkTree* tree = nullptr); 54 ~vtkQtTreeModelAdapter() override; 55 56 ///@{ 57 /** 58 * Set/Get the VTK data object as input to this adapter 59 */ 60 void SetVTKDataObject(vtkDataObject* data) override; 61 vtkDataObject* GetVTKDataObject() const override; 62 ///@} 63 64 /** 65 * Get the stored VTK data object modification time of when the 66 * adaption to a Qt model was done. This is in general not the 67 * same this as the data objects modification time. It is the mod 68 * time of the object when it was placed into the Qt model adapter. 69 * You can use this mtime as part of the checking to see whether 70 * you need to update the adapter by call SetVTKDataObject again. :) 71 */ 72 vtkMTimeType GetVTKDataObjectMTime() const; 73 74 ///@{ 75 /** 76 * Selection conversion from VTK land to Qt land 77 */ 78 vtkSelection* QModelIndexListToVTKIndexSelection(const QModelIndexList qmil) const override; 79 QItemSelection VTKIndexSelectionToQItemSelection(vtkSelection* vtksel) const override; 80 ///@} 81 82 void SetKeyColumnName(const char* name) override; 83 84 void SetColorColumnName(const char* name) override; 85 86 /** 87 * Set up the model based on the current tree. 88 */ 89 void setTree(vtkTree* t); tree()90 vtkTree* tree() const { return this->Tree; } 91 92 QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; 93 bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; 94 Qt::ItemFlags flags(const QModelIndex& index) const override; 95 QVariant headerData( 96 int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 97 QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; 98 QModelIndex parent(const QModelIndex& index) const override; 99 int rowCount(const QModelIndex& parent = QModelIndex()) const override; 100 int columnCount(const QModelIndex& parent = QModelIndex()) const override; 101 102 ///@{ 103 /** 104 * If drag/drop is enabled in the view, the model will package up the current 105 * pedigreeid vtkSelection into a QMimeData when items are dragged. 106 * Currently only leaves of the tree can be dragged. 107 */ 108 Qt::DropActions supportedDragActions() const override; 109 QMimeData* mimeData(const QModelIndexList& indexes) const override; 110 QStringList mimeTypes() const override; 111 ///@} 112 113 protected: 114 void treeModified(); 115 void GenerateVTKIndexToQtModelIndex(vtkIdType vtk_index, QModelIndex qmodel_index); 116 117 vtkTree* Tree; 118 vtkAdjacentVertexIterator* ChildIterator; 119 vtkMTimeType TreeMTime; 120 QVector<QModelIndex> VTKIndexToQtModelIndex; 121 QHash<QModelIndex, QVariant> IndexToDecoration; 122 123 private: 124 vtkQtTreeModelAdapter(const vtkQtTreeModelAdapter&) = delete; 125 void operator=(const vtkQtTreeModelAdapter&) = delete; 126 }; 127 128 #endif 129 // VTK-HeaderTest-Exclude: vtkQtTreeModelAdapter.h 130