Files
edgetx-gx12/companion/src/qautocombobox.h
T
bsongis 2fd1f575ba Telemetry Volts and Current sources (RxBatt, A3, A4) now available in
Companion. QAutoComboBox introduced to simplify code
2014-05-25 09:43:54 +02:00

54 lines
1.1 KiB
C++
Executable File

#ifndef QAUTOCOMBOBOX_H_
#define QAUTOCOMBOBOX_H_
#include <QComboBox>
#include "modeledit/modelpanel.h"
class QUnsignedAutoComboBox: public QComboBox
{
Q_OBJECT
public:
explicit QUnsignedAutoComboBox(QWidget *parent = 0):
QComboBox(parent),
field(NULL),
panel(NULL),
lock(false)
{
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIndexChanged(int)));
}
void addItem(const QString & item, unsigned int value)
{
lock = true;
QComboBox::addItem(item, value);
if (field && *field==value)
setCurrentIndex(count()-1);
lock = false;
}
void setField(unsigned int * field, ModelPanel * panel=NULL)
{
this->field = field;
this->panel = panel;
}
protected slots:
void onCurrentIndexChanged(int index)
{
if (field && !lock) {
*field = itemData(index).toInt();
if (panel) {
emit panel->modified();
}
}
}
protected:
unsigned int * field;
ModelPanel * panel;
bool lock;
};
#endif /* QAUTOCOMBOBOX_H_ */