Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
QmitkPropertiesTableModel.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkPropertiesTableModel_h
14 #define QmitkPropertiesTableModel_h
15 
16 #include <MitkQtWidgetsExports.h>
17 
18 #include "mitkDataNode.h"
19 #include "mitkWeakPointer.h"
20 
21 #include <QAbstractTableModel>
22 #include <string>
23 #include <vector>
24 
31 class MITKQTWIDGETS_EXPORT QmitkPropertiesTableModel : public QAbstractTableModel
32 {
33 public:
34  static const int PROPERTY_NAME_COLUMN = 0;
35  static const int PROPERTY_VALUE_COLUMN = 1;
40  typedef std::pair<std::string, mitk::BaseProperty::Pointer> PropertyDataSet;
41 
45  QmitkPropertiesTableModel(QObject *parent = nullptr, mitk::PropertyList::Pointer _PropertyList = nullptr);
46 
50 
51 public:
55  mitk::PropertyList::Pointer GetPropertyList() const;
56 
59  Qt::ItemFlags flags(const QModelIndex &index) const override;
60 
63  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
64 
67  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
68 
71  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
72 
76  int columnCount(const QModelIndex &parent) const override;
77 
81  void SetPropertyList(mitk::PropertyList *_PropertyList);
82 
86  virtual void PropertyListDelete();
87 
91  virtual void PropertyModified(const itk::Object *caller, const itk::EventObject &event);
92 
96  virtual void PropertyDelete(const itk::Object *caller, const itk::EventObject &event);
97 
101  virtual void SetFilterPropertiesKeyWord(std::string _FilterKeyWord);
102 
106  bool setData(const QModelIndex &index, const QVariant &value, int role) override;
107 
111  void sort(int column, Qt::SortOrder order = Qt::AscendingOrder) override;
112 
113 protected:
120  {
125  {
126  CompareByName = 0,
127  CompareByValue
128  };
129 
134  {
135  Less = 0,
136  Greater
137  };
138 
142  PropertyDataSetCompareFunction(CompareCriteria _CompareCriteria = CompareByName,
143  CompareOperator _CompareOperator = Less);
147  bool operator()(const PropertyDataSet &_Left, const PropertyDataSet &_Right) const;
148 
149  protected:
152  };
153 
158  {
159  PropertyListElementFilterFunction(const std::string &m_FilterKeyWord);
163  bool operator()(const PropertyDataSet &_Elem) const;
164 
165  protected:
166  std::string m_FilterKeyWord;
167  };
168 
173  int FindProperty(const mitk::BaseProperty *_Property) const;
174 
180  void AddSelectedProperty(PropertyDataSet &_PropertyDataSet);
186  void RemoveSelectedProperty(unsigned int _Index);
193  void Reset();
194 
199 
202  std::vector<PropertyDataSet> m_SelectedProperties;
203 
207  std::vector<unsigned long> m_PropertyModifiedObserverTags;
208 
212  std::vector<unsigned long> m_PropertyDeleteObserverTags;
213 
215 
221 
226 
230  std::string m_FilterKeyWord;
231 };
232 
233 #endif
#define MITKQTWIDGETS_EXPORT
A table model for showing and editing mitk::Properties.
bool m_BlockEvents
Indicates if this class should neglect all incoming events because the class itself triggered the eve...
QmitkPropertiesTableModel(QObject *parent=nullptr, mitk::PropertyList::Pointer _PropertyList=nullptr)
virtual void SetFilterPropertiesKeyWord(std::string _FilterKeyWord)
Set a keyword for filtering of properties. Only properties beginning with this string will be shown.
virtual void PropertyModified(const itk::Object *caller, const itk::EventObject &event)
Called when a single property was changed. Send a model changed event to the Qt-outer world.
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view,...
mitk::WeakPointer< mitk::PropertyList > m_PropertyList
void sort(int column, Qt::SortOrder order=Qt::AscendingOrder) override
Reimplemented sort function from QAbstractTableModel to enable sorting on the table.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view,...
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view,...
std::string m_FilterKeyWord
If set to any value, only properties containing the specified keyword in their name will be shown.
std::vector< PropertyDataSet > m_SelectedProperties
Store the properties in a vector so that they may be sorted.
void AddSelectedProperty(PropertyDataSet &_PropertyDataSet)
std::pair< std::string, mitk::BaseProperty::Pointer > PropertyDataSet
virtual void PropertyDelete(const itk::Object *caller, const itk::EventObject &event)
Called when a single property was changed. Send a model changed event to the Qt-outer world.
~QmitkPropertiesTableModel() override
Standard dtor. Nothing to do here.
mitk::PropertyList::Pointer GetPropertyList() const
std::vector< unsigned long > m_PropertyDeleteObserverTags
Holds all tags of Modified Event Listeners. We need it to remove them again.
std::vector< unsigned long > m_PropertyModifiedObserverTags
Holds all tags of Modified Event Listeners. We need it to remove them again.
void SetPropertyList(mitk::PropertyList *_PropertyList)
bool setData(const QModelIndex &index, const QVariant &value, int role) override
Qt::ItemFlags flags(const QModelIndex &index) const override
Overwritten from QAbstractTableModel. Returns the flags what can be done with the items (view,...
int FindProperty(const mitk::BaseProperty *_Property) const
Searches for the specified property and returns the row of the element in this QTableModel....
virtual void PropertyListDelete()
Gets called when the list is about to be deleted.
bool m_SortDescending
The property is true when the property list is sorted in descending order.
void RemoveSelectedProperty(unsigned int _Index)
int columnCount(const QModelIndex &parent) const override
Abstract base class for properties.
Key-value list holding instances of BaseProperty.
A struct that you can use in std::sort algorithm for sorting the property list elements.
CompareCriteria
Specifies field of the property with which it will be sorted.
PropertyDataSetCompareFunction(CompareCriteria _CompareCriteria=CompareByName, CompareOperator _CompareOperator=Less)
Creates a PropertyDataSetCompareFunction. A CompareCriteria and a CompareOperator must be given.
bool operator()(const PropertyDataSet &_Left, const PropertyDataSet &_Right) const
The reimplemented compare function.
PropertyListElementFilterFunction(const std::string &m_FilterKeyWord)
bool operator()(const PropertyDataSet &_Elem) const
The reimplemented compare function.