1 /*=========================================================================
2 
3   Program:   Visualization Toolkit
4   Module:    vtkQtListView.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 // .NAME vtkQtListView - A VTK view based on a Qt List view.
21 //
22 // .SECTION Description
23 // vtkQtListView is a VTK view using an underlying QListView.
24 //
25 // .SECTION Thanks
26 // Thanks to Brian Wylie from Sandia National Laboratories for implementing
27 // this class
28 
29 #ifndef vtkQtListView_h
30 #define vtkQtListView_h
31 
32 #include "vtkViewsQtModule.h" // For export macro
33 #include "QVTKWin32Header.h"
34 #include "vtkQtView.h"
35 
36 #include <QPointer>
37 #include <QImage>
38 #include <QSortFilterProxyModel>
39 #include "vtkQtAbstractModelAdapter.h"
40 #include "vtkSmartPointer.h"
41 
42 class vtkApplyColors;
43 class vtkDataObjectToTable;
44 class QItemSelection;
45 class QListView;
46 class vtkQtTableModelAdapter;
47 
48 class VTKVIEWSQT_EXPORT vtkQtListView : public vtkQtView
49 {
50 Q_OBJECT
51 
52 public:
53   static vtkQtListView *New();
54   vtkTypeMacro(vtkQtListView, vtkQtView);
55   void PrintSelf(ostream& os, vtkIndent indent);
56 
57   // Description:
58   // Get the main container of this view (a  QWidget).
59   // The application typically places the view with a call
60   // to GetWidget(): something like this
61   // this->ui->box->layout()->addWidget(this->View->GetWidget());
62   virtual QWidget* GetWidget();
63 
64   enum
65     {
66     FIELD_DATA = 0,
67     POINT_DATA = 1,
68     CELL_DATA = 2,
69     VERTEX_DATA = 3,
70     EDGE_DATA = 4,
71     ROW_DATA = 5,
72     };
73 
74   // Description:
75   // The field type to copy into the output table.
76   // Should be one of FIELD_DATA, POINT_DATA, CELL_DATA, VERTEX_DATA, EDGE_DATA.
77   vtkGetMacro(FieldType, int);
78   void SetFieldType(int);
79 
80   // Description:
81   // Enable drag and drop on this widget
82   void SetEnableDragDrop(bool);
83 
84   // Description:
85   // Have the view alternate its row colors
86   void SetAlternatingRowColors(bool);
87 
88   // Description:
89   // The strategy for how to decorate rows.
90   // Should be one of vtkQtTableModelAdapter::COLORS,
91   // vtkQtTableModelAdapter::ICONS, or
92   // vtkQtTableModelAdapter::NONE. Default is NONE.
93   void SetDecorationStrategy(int);
94 
95   // Description:
96   // The array to use for coloring items in view.  Default is "color".
97   void SetColorArrayName(const char* name);
98   const char* GetColorArrayName();
99 
100   // Description:
101   // Whether to color vertices.  Default is off.
102   void SetColorByArray(bool vis);
103   bool GetColorByArray();
104   vtkBooleanMacro(ColorByArray, bool);
105 
106   // Description:
107   // The column to display
108   void SetVisibleColumn(int col);
109 
110   // Description:
111   // The column used to filter on
112   void SetFilterRegExp(const QRegExp& pattern);
113 
114   // Description:
115   // Set the icon ivars. Only used if the decoration strategy is set to ICONS.
116   void SetIconSheet(QImage sheet);
117   void SetIconSize(int w, int h);
118   void SetIconSheetSize(int w, int h);
119   void SetIconArrayName(const char* name);
120 
121   virtual void ApplyViewTheme(vtkViewTheme* theme);
122 
123   // Description:
124   // Updates the view.
125   virtual void Update();
126 
127 protected:
128   vtkQtListView();
129   ~vtkQtListView();
130 
131   virtual void AddRepresentationInternal(vtkDataRepresentation* rep);
132   virtual void RemoveRepresentationInternal(vtkDataRepresentation* rep);
133 
134 private slots:
135   void slotQtSelectionChanged(const QItemSelection&,const QItemSelection&);
136 
137 private:
138   void SetVTKSelection();
139 
140   unsigned long LastSelectionMTime;
141   unsigned long LastInputMTime;
142   unsigned long LastMTime;
143 
144   vtkSetStringMacro(ColorArrayNameInternal);
145   vtkGetStringMacro(ColorArrayNameInternal);
146   vtkSetStringMacro(IconIndexArrayNameInternal);
147   vtkGetStringMacro(IconIndexArrayNameInternal);
148 
149   QPointer<QListView> ListView;
150   vtkQtTableModelAdapter* TableAdapter;
151   QSortFilterProxyModel* TableSorter;
152   char* ColorArrayNameInternal;
153   char* IconIndexArrayNameInternal;
154   char* VisibleColumnName;
155   bool SortSelectionToTop;
156   bool ApplyRowColors;
157   int FieldType;
158   int VisibleColumn;
159 
160   vtkSmartPointer<vtkDataObjectToTable> DataObjectToTable;
161   vtkSmartPointer<vtkApplyColors> ApplyColors;
162 
163   vtkQtListView(const vtkQtListView&);  // Not implemented.
164   void operator=(const vtkQtListView&);  // Not implemented.
165 
166 };
167 
168 #endif
169