Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkLevelWindowPresetDefinitionDialog.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 QmitkLevelWindowPresetDefinitionDialog_h
14 #define QmitkLevelWindowPresetDefinitionDialog_h
15 
16 #include <MitkQtWidgetsExports.h>
17 
18 #include <QDialog>
19 #include <QSortFilterProxyModel>
20 
21 #include <map>
22 #include <string>
23 #include <memory>
24 
25 namespace Ui
26 {
27  class QmitkLevelWindowPresetDefinition;
28 }
29 
39 {
40  Q_OBJECT
41 
42 public:
47  QmitkLevelWindowPresetDefinitionDialog(QWidget *parent = nullptr, Qt::WindowFlags f = {});
49 
56  void setPresets(std::map<std::string, double> &level,
57  std::map<std::string, double> &window,
58  QString initLevel,
59  QString initWindow);
60 
64  std::map<std::string, double> getLevelPresets();
65 
69  std::map<std::string, double> getWindowPresets();
70 
71 protected slots:
72 
73  void addPreset();
74  void removePreset();
75  void changePreset();
76 
77  void ListViewSelectionChanged(const QItemSelection &, const QItemSelection &);
78  void sortPresets(int index);
79 
80 protected:
81  class PresetTableModel : public QAbstractTableModel
82  {
83  public:
84  struct Entry
85  {
86  std::string name;
87  double level;
88  double window;
89 
90  Entry(const std::string &n, double l, double w) : name(n), level(l), window(w) {}
91  };
92 
93  PresetTableModel(std::map<std::string, double> &levels,
94  std::map<std::string, double> &windows,
95  QObject *parent = nullptr);
96 
97  int rowCount(const QModelIndex &) const override;
98  int columnCount(const QModelIndex &) const override;
99  QVariant data(const QModelIndex &index, int) const override;
100 
101  QVariant headerData(int section, Qt::Orientation orientation, int) const override;
102 
103  void addPreset(std::string &name, double level, double window);
104  void removePreset(const QModelIndex &);
105  void changePreset(int row, std::string &name, double level, double window);
106 
107  void getLevels(std::map<std::string, double> &levels);
108  void getWindows(std::map<std::string, double> &windows);
109 
110  bool contains(std::string &name);
111 
112  Entry getPreset(const QModelIndex &) const;
113 
114  private:
115  std::vector<Entry> m_Entries;
116  };
117 
118  void resizeEvent(QResizeEvent *event) override;
119  void showEvent(QShowEvent *event) override;
120 
122 
123  std::unique_ptr<Ui::QmitkLevelWindowPresetDefinition> m_Controls;
125  QSortFilterProxyModel m_SortModel;
126 };
127 
128 #endif
#define MITKQTWIDGETS_EXPORT
QVariant headerData(int section, Qt::Orientation orientation, int) const override
int rowCount(const QModelIndex &) const override
QVariant data(const QModelIndex &index, int) const override
int columnCount(const QModelIndex &) const override
void getLevels(std::map< std::string, double > &levels)
void getWindows(std::map< std::string, double > &windows)
void addPreset(std::string &name, double level, double window)
void changePreset(int row, std::string &name, double level, double window)
PresetTableModel(std::map< std::string, double > &levels, std::map< std::string, double > &windows, QObject *parent=nullptr)
Dialog for defining and managing level/window presets.
std::map< std::string, double > getLevelPresets()
Get the edited level presets.
void showEvent(QShowEvent *event) override
QmitkLevelWindowPresetDefinitionDialog(QWidget *parent=nullptr, Qt::WindowFlags f={})
Construct the preset definition dialog.
void resizeEvent(QResizeEvent *event) override
void setPresets(std::map< std::string, double > &level, std::map< std::string, double > &window, QString initLevel, QString initWindow)
Initialize the dialog with existing presets and default values.
void ListViewSelectionChanged(const QItemSelection &, const QItemSelection &)
std::unique_ptr< Ui::QmitkLevelWindowPresetDefinition > m_Controls
std::map< std::string, double > getWindowPresets()
Get the edited window presets.