Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
berryQtItemSelection.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 #include "berryQtItemSelection.h"
14 
15 #include "berryQModelIndexObject.h"
16 
17 namespace berry {
18 
20 {
21 
22 }
23 
24 QtItemSelection::QtItemSelection(const QItemSelection& sel)
25 : m_Selection(new ContainerType())
26 {
27  QModelIndexList indexes = sel.indexes();
28  for (QModelIndexList::const_iterator index = indexes.constBegin(); index != indexes.constEnd(); ++index)
29  {
30  Object::Pointer indexObj(new QModelIndexObject(*index));
31  m_Selection->push_back(indexObj);
32  }
33 }
34 
35 QItemSelection QtItemSelection::GetQItemSelection() const
36 {
37  return m_QItemSelection;
38 }
39 
41 {
42  return m_Selection->empty();
43 }
44 
46 {
47  if (m_Selection->empty()) return Object::Pointer();
48 
49  return *(m_Selection->begin());
50 }
51 
53  {
54  return m_Selection->begin();
55  }
56 
58  {
59  return m_Selection->end();
60  }
61 
63  {
64  return (int) m_Selection->size();
65  }
66 
68  {
69  return m_Selection;
70  }
71 
72  bool QtItemSelection::operator==(const Object* obj) const
73  {
74  if (const IStructuredSelection* other = dynamic_cast<const IStructuredSelection*>(obj))
75  {
76  return m_Selection == other->ToVector();
77  }
78 
79  return false;
80  }
81 
82 }
ContainerType::Pointer ToVector() const override
Light weight base class for most BlueBerry classes.
Definition: berryObject.h:72
ContainerType::const_iterator iterator
iterator End() const override
bool IsEmpty() const override
bool operator==(const Object *obj) const override
iterator Begin() const override
QItemSelection GetQItemSelection() const
Object::Pointer GetFirstElement() const override
int Size() const override