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