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