Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 
19 
20 #include "mapAlgorithmProfileHelper.h"
21 
22 
23 
25  QmitkAlgorithmListModel(QObject *parent) :
26 QAbstractTableModel(parent)
27 {
28 
29 }
30 
31 void
33  SetAlgorithms(::map::deployment::DLLDirectoryBrowser::DLLInfoListType algList)
34 {
35  emit beginResetModel();
36 
37  m_AlgList = algList;
38 
39  emit endResetModel();
40 };
41 
42 int
44  rowCount(const QModelIndex &parent) const
45 {
46  if(parent.isValid())
47  {
48  return 0;
49  }
50 
51  return m_AlgList.size();
52 }
53 
54 int
56  columnCount(const QModelIndex &parent) const
57 {
58  if(parent.isValid())
59  return 0;
60 
61  return 4;
62 }
63 
64 QVariant
66  data(const QModelIndex &index, int role) const
67 {
68  if(!index.isValid())
69  return QVariant();
70 
71  QVariant result;
72 
73  if(index.row()<m_AlgList.size())
74  {
75  const ::map::deployment::DLLInfo* info = m_AlgList[index.row()].GetPointer();
76 
77  if(Qt::DisplayRole == role)
78  {
79  switch(index.column())
80  {
81  case 0:
82  result = QVariant(info->getAlgorithmUID().getName().c_str());
83  break;
84  case 1:
85  result = QVariant(info->getAlgorithmUID().getNamespace().c_str());
86  break;
87  case 2:
88  result = QVariant(info->getAlgorithmUID().getVersion().c_str());
89  break;
90  case 3:
91  std::stringstream descriptionString;
92  ::map::algorithm::profile::ValueListType keys = ::map::algorithm::profile::getKeywords(info->getAlgorithmProfileStr());
93  for (::map::algorithm::profile::ValueListType::const_iterator keyPos = keys.begin(); keyPos!=keys.end();++keyPos)
94  {
95  if (keyPos != keys.begin())
96  {
97  descriptionString << "; ";
98  }
99  descriptionString << *keyPos;
100  }
101  descriptionString << "</p>";
102  result = QVariant(descriptionString.str().c_str());
103  break;
104  }
105  }
106  else if (Qt::UserRole == role)
107  {
108  result = QVariant(index.row());
109  }
110 
111  }
112 
113  return result;
114 }
115 
116 Qt::ItemFlags
118  flags(const QModelIndex &index) const
119 {
120  Qt::ItemFlags flags = QAbstractItemModel::flags(index);
121 
122  return flags;
123 }
124 
125 QVariant
127  headerData(int section, Qt::Orientation orientation, int role) const
128 {
129  if( (Qt::DisplayRole == role) &&
130  (Qt::Horizontal == orientation))
131  {
132  if (section==0)
133  {
134  return QVariant("Name");
135  }
136  else if (section==1)
137  {
138  return QVariant("Namespace");
139  }
140  else if (section==2)
141  {
142  return QVariant("Version");
143  }
144  else if (section==3)
145  {
146  return QVariant("Keywords");
147  }
148  }
149  return QVariant();
150 }
QmitkAlgorithmListModel(QObject *parent=NULL)
virtual int columnCount(const QModelIndex &parent=QModelIndex()) const
static void info(const char *fmt,...)
Definition: svm.cpp:100
virtual Qt::ItemFlags flags(const QModelIndex &index) const
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
virtual QVariant data(const QModelIndex &index, int role) const
void SetAlgorithms(::map::deployment::DLLDirectoryBrowser::DLLInfoListType algList)
virtual int rowCount(const QModelIndex &parent=QModelIndex()) const