vtkQtTreeView.h 5.55 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    vtkQtTreeView.h

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

=========================================================================*/
15 16 17 18 19
/*-------------------------------------------------------------------------
  Copyright 2008 Sandia Corporation.
  Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  the U.S. Government retains certain rights in this software.
-------------------------------------------------------------------------*/
20 21 22 23 24 25 26 27 28 29 30
/**
 * @class   vtkQtTreeView
 * @brief   A VTK view based on a Qt tree view.
 *
 *
 * vtkQtTreeView is a VTK view using an underlying QTreeView.
 *
 * @par Thanks:
 * Thanks to Brian Wylie from Sandia National Laboratories for implementing
 * this class
*/
31

32 33
#ifndef vtkQtTreeView_h
#define vtkQtTreeView_h
34

35
#include "vtkViewsQtModule.h" // For export macro
Jeff Baumes's avatar
Jeff Baumes committed
36
#include "vtkQtView.h"
37

38 39 40
#include <QList> // Needed for member variables
#include <QPointer> // Needed for member variables
#include "vtkSmartPointer.h" // Needed for member variables
41

42
class QAbstractItemDelegate;
43
class QAbstractItemView;
44
class QFilterTreeProxyModel;
45
class QColumnView;
Jeff Baumes's avatar
Jeff Baumes committed
46
class QItemSelection;
47
class QModelIndex;
48
class QTreeView;
49
class vtkApplyColors;
50
class QVBoxLayout;
51
class vtkQtTreeModelAdapter;
52
class QItemSelectionModel;
53

54
class VTKVIEWSQT_EXPORT vtkQtTreeView : public vtkQtView
55
{
Jeff Baumes's avatar
Jeff Baumes committed
56 57 58 59 60
Q_OBJECT

signals:
  void expanded(const QModelIndex&);
  void collapsed(const QModelIndex&);
61
  void updatePreviewWidget(const QModelIndex&);
Jeff Baumes's avatar
Jeff Baumes committed
62

63 64
public:
  static vtkQtTreeView *New();
65
  vtkTypeMacro(vtkQtTreeView, vtkQtView);
66
  void PrintSelf(ostream& os, vtkIndent indent) override;
67

68 69 70 71 72 73
  /**
   * Get the main container of this view (a  QWidget).
   * The application typically places the view with a call
   * to GetWidget(): something like this
   * this->ui->box->layout()->addWidget(this->View->GetWidget());
   */
74
  QWidget* GetWidget() override;
75

76 77 78
  /**
   * Have the view show/hide its column headers (default is ON)
   */
79
  void SetShowHeaders(bool);
Jeff Baumes's avatar
Jeff Baumes committed
80

81 82 83
  /**
   * Have the view alternate its row colors (default is OFF)
   */
Jeff Baumes's avatar
Jeff Baumes committed
84
  void SetAlternatingRowColors(bool);
Jeff Baumes's avatar
Jeff Baumes committed
85

86 87 88
  /**
   * Have the view alternate its row colors (default is OFF)
   */
89 90
  void SetEnableDragDrop(bool);

91 92 93
  /**
   * Show the root node of the tree (default is OFF)
   */
94 95
  void SetShowRootNode(bool);

96 97 98
  /**
   * Hide the column of the given index from being shown in the view
   */
99 100
  void HideColumn(int i);

101 102 103
  /**
   * Show the column of the given index in the view
   */
104 105
  void ShowColumn(int i);

106 107 108
  /**
   * Hide all but the first column in the view
   */
109 110
  void HideAllButFirstColumn();

111 112 113
  /**
   * The column used to filter on
   */
114 115
  void SetFilterColumn(int i);

116 117 118
  /**
   * The column used to filter on
   */
119 120
  void SetFilterRegExp(const QRegExp& pattern);

121 122 123
  /**
   * The column used to filter on
   */
124 125
  void SetFilterTreeLevel(int level);

126 127 128
  /**
   * Collapses the model item specified by the index.
   */
129 130
  void Collapse( const QModelIndex & index );

131 132 133
  /**
   * Collapses all expanded items.
   */
134 135
  void CollapseAll();

136 137 138
   /**
    * Expands the model item specified by the index.
    */
139 140
   void Expand ( const QModelIndex & index );

141 142 143 144 145
   /**
    * Expands all expandable items.
    * Warning: if the model contains a large number of items,
    * this function will take some time to execute.
    */
146 147
   void ExpandAll ();

148 149 150
   /**
    * Expands all expandable items to the given depth.
    */
151 152
   void ExpandToDepth ( int depth );

153 154 155
   /**
    * Resizes the column given to the size of its contents.
    */
156 157
   void ResizeColumnToContents ( int column );

158 159 160
  /**
   * Set whether to use a QColumnView (QTreeView is the default)
   */
161 162
  void SetUseColumnView(int state);

163 164 165
  /**
   * Updates the view.
   */
166
  void Update() override;
167

168 169 170
  /**
   * Set item delegate to something custom
   */
171
  void SetItemDelegate(QAbstractItemDelegate* delegate);
172

173 174 175 176
  //@{
  /**
   * The array to use for coloring items in view.  Default is "color".
   */
177 178
  void SetColorArrayName(const char* name);
  const char* GetColorArrayName();
179
  //@}
180

181 182 183 184
  //@{
  /**
   * Whether to color vertices.  Default is off.
   */
185 186 187
  void SetColorByArray(bool vis);
  bool GetColorByArray();
  vtkBooleanMacro(ColorByArray, bool);
188
  //@}
189

190
  void ApplyViewTheme(vtkViewTheme* theme) override;
191

192 193
protected:
  vtkQtTreeView();
194
  ~vtkQtTreeView() override;
195

196 197
  void AddRepresentationInternal(vtkDataRepresentation* rep) override;
  void RemoveRepresentationInternal(vtkDataRepresentation* rep) override;
Jeff Baumes's avatar
Jeff Baumes committed
198 199

private slots:
Jeff Baumes's avatar
Jeff Baumes committed
200
  void slotQtSelectionChanged(const QItemSelection&,const QItemSelection&);
Jeff Baumes's avatar
Jeff Baumes committed
201

202
private:
Jeff Baumes's avatar
Jeff Baumes committed
203
  void SetVTKSelection();
Bill Lorensen's avatar
Bill Lorensen committed
204 205
  vtkMTimeType CurrentSelectionMTime;
  vtkMTimeType LastInputMTime;
206

207 208 209
  vtkSetStringMacro(ColorArrayNameInternal);
  vtkGetStringMacro(ColorArrayNameInternal);

Jeff Baumes's avatar
Jeff Baumes committed
210
  QPointer<QTreeView> TreeView;
211 212 213
  QPointer<QColumnView> ColumnView;
  QPointer<QWidget> Widget;
  QPointer<QVBoxLayout> Layout;
214
  QPointer<QItemSelectionModel> SelectionModel;
215
  QList<int> HiddenColumns;
Jeff Baumes's avatar
Jeff Baumes committed
216
  vtkQtTreeModelAdapter* TreeAdapter;
217
  QAbstractItemView* View;
218
  char* ColorArrayNameInternal;
219
  QFilterTreeProxyModel* TreeFilter;
220

221
  vtkSmartPointer<vtkApplyColors> ApplyColors;
222

223 224
  vtkQtTreeView(const vtkQtTreeView&) = delete;
  void operator=(const vtkQtTreeView&) = delete;
225

226 227 228
};

#endif