Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
Helper/QmitkAlgorithmListModel.cpp
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 
15 
16 #include "mapAlgorithmProfileHelper.h"
17 
18 
19 
21  QmitkAlgorithmListModel(QObject *parent) :
22 QAbstractTableModel(parent)
23 {
24 
25 }
26 
27 void
29  SetAlgorithms(::map::deployment::DLLDirectoryBrowser::DLLInfoListType algList)
30 {
31  emit beginResetModel();
32 
33  m_AlgList = algList;
34 
35  emit endResetModel();
36 };
37 
38 int
40  rowCount(const QModelIndex &parent) const
41 {
42  if(parent.isValid())
43  {
44  return 0;
45  }
46 
47  return m_AlgList.size();
48 }
49 
50 int
52  columnCount(const QModelIndex &parent) const
53 {
54  if(parent.isValid())
55  return 0;
56 
57  return 4;
58 }
59 
60 QVariant
62  data(const QModelIndex &index, int role) const
63 {
64  if(!index.isValid())
65  return QVariant();
66 
67  QVariant result;
68 
69  if(index.row()<m_AlgList.size())
70  {
71  const ::map::deployment::DLLInfo* info = m_AlgList[index.row()].GetPointer();
72 
73  if(Qt::DisplayRole == role)
74  {
75  switch(index.column())
76  {
77  case 0:
78  result = QVariant(info->getAlgorithmUID().getName().c_str());
79  break;
80  case 1:
81  result = QVariant(info->getAlgorithmUID().getNamespace().c_str());
82  break;
83  case 2:
84  result = QVariant(info->getAlgorithmUID().getVersion().c_str());
85  break;
86  case 3:
87  std::stringstream descriptionString;
88  ::map::algorithm::profile::ValueListType keys = ::map::algorithm::profile::getKeywords(info->getAlgorithmProfileStr());
89  for (::map::algorithm::profile::ValueListType::const_iterator keyPos = keys.begin(); keyPos!=keys.end();++keyPos)
90  {
91  if (keyPos != keys.begin())
92  {
93  descriptionString << "; ";
94  }
95  descriptionString << *keyPos;
96  }
97  descriptionString << "</p>";
98  result = QVariant(descriptionString.str().c_str());
99  break;
100  }
101  }
102  else if (Qt::UserRole == role)
103  {
104  result = QVariant(index.row());
105  }
106 
107  }
108 
109  return result;
110 }
111 
112 Qt::ItemFlags
114  flags(const QModelIndex &index) const
115 {
116  Qt::ItemFlags flags = QAbstractItemModel::flags(index);
117 
118  return flags;
119 }
120 
121 QVariant
123  headerData(int section, Qt::Orientation orientation, int role) const
124 {
125  if( (Qt::DisplayRole == role) &&
126  (Qt::Horizontal == orientation))
127  {
128  if (section==0)
129  {
130  return QVariant("Name");
131  }
132  else if (section==1)
133  {
134  return QVariant("Namespace");
135  }
136  else if (section==2)
137  {
138  return QVariant("Version");
139  }
140  else if (section==3)
141  {
142  return QVariant("Keywords");
143  }
144  }
145  return QVariant();
146 }
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
static void info(const char *fmt,...)
Definition: svm.cpp:86
int rowCount(const QModelIndex &parent=QModelIndex()) const override
QmitkAlgorithmListModel(QObject *parent=nullptr)
Qt::ItemFlags flags(const QModelIndex &index) const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
QVariant data(const QModelIndex &index, int role) const override
void SetAlgorithms(::map::deployment::DLLDirectoryBrowser::DLLInfoListType algList)