1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkQtAbstractModelAdapter.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   vtkQtAbstractModelAdapter
22  * @brief   Superclass for Qt model adapters.
23  *
24  *
25  * vtkQtAbstractModelAdapter is the superclass for classes that adapt
26  * VTK objects to QAbstractItemModel. This class contains API for converting
27  * between QModelIndex and VTK ids, as well as some additional specialized
28  * functionality such as setting a column of data to use as the Qt header
29  * information.
30  *
31  * @sa
32  * vtkQtTableModelAdapter vtkQtTreeModelAdapter
33 */
34 
35 #ifndef vtkQtAbstractModelAdapter_h
36 #define vtkQtAbstractModelAdapter_h
37 
38 #include "vtkGUISupportQtModule.h" // For export macro
39 #include <QAbstractItemModel>
40 #include <QItemSelection> // Needed for selection methods
41 
42 class vtkDataObject;
43 class vtkSelection;
44 
45 class VTKGUISUPPORTQT_EXPORT vtkQtAbstractModelAdapter : public QAbstractItemModel
46 {
47   Q_OBJECT
48 
49 public:
50 
51   // The view types.
52   enum {
53     FULL_VIEW,
54     DATA_VIEW
55   };
56 
vtkQtAbstractModelAdapter(QObject * p)57   vtkQtAbstractModelAdapter(QObject* p) :
58     QAbstractItemModel(p),
59     ViewType(FULL_VIEW),
60     KeyColumn(-1),
61     ColorColumn(-1),
62     DataStartColumn(-1),
63     DataEndColumn(-1)
64     { }
65 
66   //@{
67   /**
68    * Set/Get the VTK data object as input to this adapter
69    */
70   virtual void SetVTKDataObject(vtkDataObject *data) = 0;
71   virtual vtkDataObject* GetVTKDataObject() const = 0;
72   //@}
73 
74   //@{
75   /**
76    * Selection conversion from VTK land to Qt land
77    */
78   virtual vtkSelection* QModelIndexListToVTKIndexSelection(
79     const QModelIndexList qmil) const = 0;
80   virtual QItemSelection VTKIndexSelectionToQItemSelection(
81     vtkSelection *vtksel) const = 0;
82   //@}
83 
84   /**
85    * Set/Get the view type.
86    * FULL_VIEW gives access to all the data.
87    * DATA_VIEW gives access only to the data columns specified with SetDataColumnRange()
88    * The default is FULL_VIEW.
89    */
SetViewType(int type)90   virtual void SetViewType(int type) { this->ViewType = type; }
GetViewType()91   virtual int GetViewType() { return this->ViewType; }
92 
93   /**
94    * Set/Get the key column.
95    * The key column is used as the row headers in a table view,
96    * and as the first column in a tree view.
97    * Set to -1 for no key column.
98    * The default is no key column.
99    */
SetKeyColumn(int col)100   virtual void SetKeyColumn(int col) { this->KeyColumn = col; }
GetKeyColumn()101   virtual int GetKeyColumn() { return this->KeyColumn; }
102   virtual void SetKeyColumnName(const char* name) = 0;
103 
104   /**
105    * Set/Get the column storing the rgba color values for each row.
106    * The color column is used as the row headers in a table view,
107    * and as the first column in a tree view.
108    * Set to -1 for no key column.
109    * The default is no key column.
110    */
SetColorColumn(int col)111   virtual void SetColorColumn(int col) { this->ColorColumn = col; }
GetColorColumn()112   virtual int GetColorColumn() { return this->ColorColumn; }
113   virtual void SetColorColumnName(const char* name) = 0;
114 
115   /**
116    * Set the range of columns that specify the main data matrix.
117    * The data column range should not include the key column.
118    * The default is no data columns.
119    */
SetDataColumnRange(int c1,int c2)120   virtual void SetDataColumnRange(int c1, int c2)
121     { this->DataStartColumn = c1; this->DataEndColumn = c2; }
122 
123   // We make the reset() method public because it isn't always possible for
124   // an adapter to know when its input has changed, so it must be callable
125   // by an outside entity.
126   /// \sa beginResetModel, endResetModel
127   /// \deprecated
reset()128   void reset() { QAbstractItemModel::beginResetModel(); QAbstractItemModel::endResetModel();}
129 
130   // We make the beginResetModel() and endResetModel() methods public because it
131   // isn't always possible for an adapter to know when its input has changed,
132   // so it must be callable by an outside entity.
beginResetModel()133   void beginResetModel() { QAbstractItemModel::beginResetModel(); }
endResetModel()134   void endResetModel() { QAbstractItemModel::endResetModel(); }
135 
136 
137 signals:
138   void modelChanged();
139 
140 protected:
141 
142   /**
143    * Map a column index in the QAbstractItemModel to a vtkTable column.
144    * If the argument is out of range or cannot be mapped then
145    * this method may return -1.
146    */
147   virtual int ModelColumnToFieldDataColumn(int col) const;
148 
149   int ViewType;
150   int KeyColumn;
151   int ColorColumn;
152   int DataStartColumn;
153   int DataEndColumn;
154 };
155 
156 #endif
157