Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkComboBoxStepThrough.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 
20  : QComboBox(parent), m_LastMaxIndex(0), m_LastIndex(0)
21 {
22  connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(OnCurrentIndexChanged(int)));
23 }
24 
26 {
27 }
28 
30 {
31  int curIndex = this->currentIndex();
32 
33  // increase index if not already at end
34  if ( curIndex > 0 )
35  {
36  this->setCurrentIndex(curIndex-1);
37  }
38 }
39 
41 {
42  int curIndex = this->currentIndex();
43 
44  // decrease index if not already at begin
45  if ( curIndex < this->count() - 1 )
46  {
47  this->setCurrentIndex(curIndex+1);
48  }
49 }
50 
51 void QmitkComboBoxStepThrough::OnCurrentIndexChanged(int newIndex)
52 {
53  // emit begin reached singal if index is zero now or was zero before
54  if ( m_LastIndex == 0 && newIndex > 0)
55  {
56  emit SignalReachedBegin(false);
57  }
58  else if ( m_LastIndex > 0 && newIndex == 0 )
59  {
60  emit SignalReachedBegin(true);
61  }
62 
63  int maxIndex = this->count() - 1;
64 
65  // emit end reached signal if index is max index now or was max index before
66  if ( (m_LastIndex == maxIndex || m_LastIndex == m_LastMaxIndex) && newIndex < maxIndex)
67  {
68  emit SignalReachedEnd(false);
69  }
70  else if ( m_LastIndex < maxIndex && newIndex == maxIndex )
71  {
72  emit SignalReachedEnd(true);
73  }
74 
75  m_LastIndex = newIndex;
76  m_LastMaxIndex = maxIndex;
77 }
78 
79 void QmitkComboBoxStepThrough::addItem ( const QString & text, const QVariant & userData )
80 {
81  QComboBox::addItem(text, userData);
82 
83  // make sure that begin and end signals are emitted
84  OnCurrentIndexChanged(this->currentIndex());
85 }
86 
87 void QmitkComboBoxStepThrough::addItem ( const QIcon & icon, const QString & text, const QVariant & userData )
88 {
89  QComboBox::addItem(icon, text, userData);
90 
91  // make sure that begin and end signals are emitted
92  OnCurrentIndexChanged(this->currentIndex());
93 }
94 
95 void QmitkComboBoxStepThrough::addItems ( const QStringList & texts )
96 {
97  QComboBox::addItems(texts);
98 
99  // make sure that begin and end signals are emitted
100  OnCurrentIndexChanged(this->currentIndex());
101 }
102 
103 void QmitkComboBoxStepThrough::insertItem( int index, const QString & text, const QVariant & userData )
104 {
105  QComboBox::insertItem(index, text, userData);
106 
107  // make sure that begin and end signals are emitted
108  OnCurrentIndexChanged(this->currentIndex());
109 }
110 
111 void QmitkComboBoxStepThrough::insertItem( int index, const QIcon & icon, const QString & text, const QVariant & userData )
112 {
113  QComboBox::insertItem(index, icon, text, userData);
114 
115  // make sure that begin and end signals are emitted
116  OnCurrentIndexChanged(this->currentIndex());
117 }
118 
119 void QmitkComboBoxStepThrough::insertItems( int index, const QStringList & list )
120 {
121  QComboBox::insertItems(index, list);
122 
123  // make sure that begin and end signals are emitted
124  OnCurrentIndexChanged(this->currentIndex());
125 }
void addItem(const QString &text, const QVariant &userData=QVariant())
void insertItems(int index, const QStringList &list)
void addItems(const QStringList &texts)
QmitkComboBoxStepThrough(QWidget *parent=nullptr)
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())