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