MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
QmitkComboBoxStepThrough.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found 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
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
47void 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
75void 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
83void 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
91void 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
99void 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
107void 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
115void 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}
QmitkComboBoxStepThrough(QWidget *parent=nullptr)
void addItem(const QString &text, const QVariant &userData=QVariant())
void insertItem(int index, const QString &text, const QVariant &userData=QVariant())
void insertItems(int index, const QStringList &list)
void addItems(const QStringList &texts)