5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #ifndef _AUTOCOMBOBOX_H_
22 #define _AUTOCOMBOBOX_H_
25 #include "genericpanel.h"
27 class AutoComboBox
: public QComboBox
32 explicit AutoComboBox(QWidget
*parent
= 0):
39 connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
50 virtual void insertItems(int index
, const QStringList
& items
)
52 foreach(QString item
, items
) {
57 virtual void addItem(const QString
& item
)
59 addItem(item
, next
++);
62 virtual void addItem(const QString
& item
, int value
)
65 QComboBox::addItem(item
, value
);
66 if (field
&& *field
==value
) {
67 setCurrentIndex(count()-1);
72 void setField(unsigned int & field
, GenericPanel
* panel
=NULL
)
74 this->field
= (int *)&field
;
76 for (int i
=0; i
<count(); ++i
) {
77 if ((int)field
== itemData(i
))
82 void setField(int & field
, GenericPanel
* panel
=NULL
)
86 for (int i
=0; i
<count(); ++i
) {
87 if ((int)field
== itemData(i
))
94 for (int i
=0; i
<count(); ++i
) {
96 if (*this->field
== i
)
102 void onCurrentIndexChanged(int index
)
104 if (field
&& !lock
) {
105 *field
= itemData(index
).toInt();
107 emit panel
->modified();
114 GenericPanel
* panel
;
119 #endif // _AUTOCOMBOBOX_H_