fw4spl
SelectorModel.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __UIMEDDATAQT_WIDGET_SELECTORMODEL_HPP__
8 #define __UIMEDDATAQT_WIDGET_SELECTORMODEL_HPP__
9 
10 #include "uiMedDataQt/config.hpp"
11 
12 #include <fwMedData/Series.hpp>
13 #include <fwMedData/Study.hpp>
14 
15 #include <QPointer>
16 #include <QStandardItem>
17 #include <QStandardItemModel>
18 #include <QString>
19 #include <QTreeView>
20 
21 #include <map>
22 
23 namespace uiMedDataQt
24 {
25 namespace widget
26 {
27 
31 class UIMEDDATAQT_CLASS_API SelectorModel : public QStandardItemModel
32 {
33 Q_OBJECT
34 
35 public:
36 
38  typedef enum
39  {
40  ITEM_TYPE = Qt::UserRole,
41  UID
42  }Role;
43 
45  typedef enum
46  {
47  STUDY = 1,
48  SERIES
49  }ItemType;
50 
52  typedef std::map<std::string, std::string> SeriesIconType;
53 
55  UIMEDDATAQT_API SelectorModel(QWidget* parent = 0);
56 
58  UIMEDDATAQT_API ~SelectorModel();
59 
64  UIMEDDATAQT_API void addSeries(::fwMedData::Series::sptr series);
65 
70  UIMEDDATAQT_API void removeSeries(::fwMedData::Series::sptr series);
71 
73  UIMEDDATAQT_API void clear();
74 
76  Qt::ItemFlags flags(const QModelIndex& index) const
77  {
78  return (QStandardItemModel::flags(index) & ~Qt::ItemIsEditable);
79  }
80 
82  UIMEDDATAQT_API ItemType getItemType(const QModelIndex& index);
83 
89  UIMEDDATAQT_API QModelIndex getIndex(const QModelIndex& index, int column );
90 
92  UIMEDDATAQT_API void removeRows(const QModelIndexList indexes);
93 
95  UIMEDDATAQT_API QStandardItem* findSeriesItem(::fwMedData::Series::sptr series);
96 
98  UIMEDDATAQT_API QStandardItem* findStudyItem(::fwMedData::Study::sptr study);
99 
104  UIMEDDATAQT_API void setSeriesIcons(const SeriesIconType& seriesIcons);
105 
107  UIMEDDATAQT_API void setInsertMode(bool insert);
108 
109 private:
110 
111  typedef std::map< ::fwMedData::DicomValueType, QStandardItem* > StudyUidItemMapType;
112 
117  template <typename T>
118  QStandardItem* getInfo(T data, QString separator);
119 
121  bool removeStudyItem(QStandardItem* item);
122 
124  bool removeSeriesItem(QStandardItem* item);
125 
127  void addSeriesIcon(::fwMedData::Series::sptr series, QStandardItem* item);
128 
130  void init();
131 
133  int m_studyRowCount;
134 
139  StudyUidItemMapType m_items;
140 
142  bool m_insert;
143 
145  SeriesIconType m_seriesIcons;
146 };
147 
148 //------------------------------------------------------------------------------
149 
150 template <typename T>
151 QStandardItem* SelectorModel::getInfo(T data, QString separator)
152 {
153  QString dataStr;
154  if(!data.empty())
155  {
156  typename T::iterator itr = data.begin();
157  std::ostringstream str;
158  str << *itr++;
159  dataStr = QString::fromStdString(str.str());
160 
161  for(; itr != data.end(); ++itr)
162  {
163  str.str("");
164  str << *itr;
165  dataStr.append(separator + QString::fromStdString(str.str()));
166  }
167  }
168  QStandardItem* item = new QStandardItem(dataStr);
169  return item;
170 }
171 
172 } // namespace widget
173 } // namespace uiMedDataQt
174 
175 #endif // __UIMEDDATAQT_WIDGET_SELECTORMODEL_HPP__
The namespace uiMedDataQt contains editors for medical data.
ItemType
Defines item type (STUDY or SERIES), it is used in items data (ITEM_TYPE role).
Role
Defines the role of the items data (ITEM_TYPE or UID)
Qt::ItemFlags flags(const QModelIndex &index) const
Returns item flags with non editable flag.
This class represents the Selector Model.
std::map< std::string, std::string > SeriesIconType
Map associating icons to series (map<series classname, icon path>)