Slicer  5.3
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLSortFilterProxyModel.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Julien Finet, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qMRMLSortFilterProxyModel_h
22 #define __qMRMLSortFilterProxyModel_h
23 
24 // Qt includes
25 #include <QSortFilterProxyModel>
26 #include <QStringList>
27 class QStandardItem;
28 
29 // CTK includes
30 #include <ctkVTKObject.h>
31 
32 // qMRML includes
33 #include "qMRMLWidgetsExport.h"
34 
35 class vtkMRMLNode;
36 class vtkMRMLScene;
37 class qMRMLAbstractItemHelper;
38 class qMRMLSceneModel;
39 class qMRMLSortFilterProxyModelPrivate;
40 
43 class QMRML_WIDGETS_EXPORT qMRMLSortFilterProxyModel : public QSortFilterProxyModel
44 {
45  Q_OBJECT
46  QVTK_OBJECT
47 
51  Q_PROPERTY(QStringList nodeTypes READ nodeTypes WRITE setNodeTypes)
52 
53 
54  Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden)
58 
59 
60  Q_PROPERTY(QStringList showHiddenForTypes READ showHiddenForTypes WRITE setShowHiddenForTypes)
63 
64 
65  Q_PROPERTY(bool showChildNodeTypes READ showChildNodeTypes WRITE setShowChildNodeTypes)
69 
70 
71  Q_PROPERTY(QStringList hideChildNodeTypes READ hideChildNodeTypes WRITE setHideChildNodeTypes)
79 
80 
81  Q_PROPERTY(FilterType filterType READ filterType WRITE setFilterType)
85  Q_ENUMS(FilterType)
90  Q_PROPERTY(bool showAll READ showAll WRITE setShowAll STORED false)
94  Q_PROPERTY(bool hideAll READ hideAll WRITE setHideAll STORED false)
95 
100  Q_PROPERTY(QStringList hiddenNodeIDs READ hiddenNodeIDs WRITE setHiddenNodeIDs)
101 
106  Q_PROPERTY(QStringList visibleNodeIDs READ visibleNodeIDs WRITE setVisibleNodeIDs)
107 
111  Q_PROPERTY(QString hideNodesUnaffiliatedWithNodeID READ hideNodesUnaffiliatedWithNodeID WRITE setHideNodesUnaffiliatedWithNodeID)
112 
113 public:
115  {
116  HideAll = 0,
118  UseFilters
119  };
120 
121  typedef QSortFilterProxyModel Superclass;
122  qMRMLSortFilterProxyModel(QObject *parent=nullptr);
123  ~qMRMLSortFilterProxyModel() override;
124 
126  vtkMRMLScene* mrmlScene()const;
127 
129  Q_INVOKABLE QModelIndex mrmlSceneIndex()const;
130 
132  Q_INVOKABLE vtkMRMLNode* mrmlNodeFromIndex(const QModelIndex& index)const;
133 
135  Q_INVOKABLE QModelIndex indexFromMRMLNode(vtkMRMLNode* node, int column = 0)const;
136 
140  QStringList nodeTypes()const;
141  void setNodeTypes(const QStringList& nodeTypes);
142 
146  bool showHidden()const;
147 
152  QStringList showHiddenForTypes()const;
153  void setShowHiddenForTypes(const QStringList& nodeTypes);
154 
158  Q_INVOKABLE void addAttribute(const QString& nodeType,
159  const QString& attributeName,
160  const QVariant& attributeValue = QVariant());
163  Q_INVOKABLE void removeAttribute(const QString& nodeType, const QString& attributeName);
164 
167  Q_INVOKABLE QVariant attributeFilter(
168  const QString& nodeType, const QString& attributeName) const;
169 
173  void setShowChildNodeTypes(bool show);
174  bool showChildNodeTypes()const;
175 
180  void setHideChildNodeTypes(const QStringList& nodeTypes);
182  QStringList hideChildNodeTypes()const;
183 
186  void setHiddenNodeIDs(const QStringList& nodeIDsToHide);
189  QStringList hiddenNodeIDs()const;
190 
193  void setVisibleNodeIDs(const QStringList& nodeIDsToShow);
196  QStringList visibleNodeIDs()const;
197 
201  void setHideNodesUnaffiliatedWithNodeID(const QString& nodeID);
204  QString hideNodesUnaffiliatedWithNodeID()const;
205 
208  FilterType filterType()const;
211  bool showAll()const;
214  bool hideAll()const;
215 
217  Q_INVOKABLE qMRMLSceneModel* sceneModel()const;
218 
219 public slots:
222  void setShowHidden(bool);
223 
226  void setFilterType(FilterType filterType);
229  void setShowAll(bool show);
232  void setHideAll(bool hide);
233 
234  // TODO Add setMRMLScene() to propagate to the scene model
235 protected:
248  {
249  Reject = 0,
253  };
262  bool filterAcceptsRow(int source_row,
263  const QModelIndex &source_parent)const override;
268  virtual AcceptType filterAcceptsNode(vtkMRMLNode* node)const;
269 
270  QStandardItem* sourceItem(const QModelIndex& index)const;
271 
272 protected:
273  QScopedPointer<qMRMLSortFilterProxyModelPrivate> d_ptr;
274 
275 private:
276  Q_DECLARE_PRIVATE(qMRMLSortFilterProxyModel);
277  Q_DISABLE_COPY(qMRMLSortFilterProxyModel);
278 };
279 
280 #endif
QScopedPointer< qMRMLSortFilterProxyModelPrivate > d_ptr
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167