Add the ability to modify the cylinder use in the UI

Thanks to Tomaz for writing a first draft of the delegate.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2014-11-17 14:03:37 +00:00
parent 1739042f34
commit 0c3f13d128
5 changed files with 53 additions and 2 deletions

View file

@ -277,6 +277,32 @@ QWidget *TankInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
return delegate;
}
TankUseDelegate::TankUseDelegate(QObject *parent)
{
}
QWidget *TankUseDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
QComboBox *comboBox = new QComboBox(parent);
for (int i = 0; i < NUM_GAS_USE; i++)
comboBox->addItem(QString(cylinderuse_text[i]));
return comboBox;
}
void TankUseDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
{
QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
QString indexString = index.data().toString();
comboBox->setCurrentIndex(cylinderuse_from_text(indexString.toUtf8().data()));
}
void TankUseDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
{
QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
model->setData(index, comboBox->currentIndex());
}
struct RevertWeightData {
QString type;
int weight;