2011-07-29 14:36:35 +02:00
|
|
|
#include "qvaluecombobox.h"
|
|
|
|
|
|
|
|
QValueComboBox::QValueComboBox(QWidget *parent) :
|
|
|
|
QComboBox(parent), role(Qt::UserRole)
|
|
|
|
{
|
|
|
|
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
|
|
|
|
}
|
|
|
|
|
2012-05-08 23:03:41 +02:00
|
|
|
QVariant QValueComboBox::value() const
|
2011-07-29 14:36:35 +02:00
|
|
|
{
|
2012-05-08 23:03:41 +02:00
|
|
|
return itemData(currentIndex(), role);
|
2011-07-29 14:36:35 +02:00
|
|
|
}
|
|
|
|
|
2012-05-08 23:03:41 +02:00
|
|
|
void QValueComboBox::setValue(const QVariant &value)
|
2011-07-29 14:36:35 +02:00
|
|
|
{
|
|
|
|
setCurrentIndex(findData(value, role));
|
|
|
|
}
|
|
|
|
|
|
|
|
void QValueComboBox::setRole(int role)
|
|
|
|
{
|
|
|
|
this->role = role;
|
|
|
|
}
|
|
|
|
|
|
|
|
void QValueComboBox::handleSelectionChanged(int idx)
|
|
|
|
{
|
|
|
|
emit valueChanged();
|
|
|
|
}
|