GrahamLabdon
9th March 2011, 11:49
Hi
I am implementing a Item Delegate for my tree based model.
I need to create a different editor depending upon the item being edited.
At the moment I am using switch statements to decide which editor to supply, but as my model grows so do the switch statements.
QWidget* editor;
QModelIndex parentIndex = index.model()->parent(index);
switch (index.model()->parent(index).row())
{
case 0:
{
switch (index.row())
{
case 0:
case 1:
{
editor = new QLineEdit(parent);
}
break;
case 2:
{
QStringList list;
Common::Enumerations::surveyUnits().getDisplayStri ngs(list);
editor = new QComboBox(parent);
((QComboBox*)editor)->addItems(list);
}
break;
}
}
break;
case 1:
{
editor = new QLineEdit(parent);
((QLineEdit*)editor)->setValidator(new QIntValidator());
}
break;
}
return editor;
Is there a better way to achieve this?
TIA
I am implementing a Item Delegate for my tree based model.
I need to create a different editor depending upon the item being edited.
At the moment I am using switch statements to decide which editor to supply, but as my model grows so do the switch statements.
QWidget* editor;
QModelIndex parentIndex = index.model()->parent(index);
switch (index.model()->parent(index).row())
{
case 0:
{
switch (index.row())
{
case 0:
case 1:
{
editor = new QLineEdit(parent);
}
break;
case 2:
{
QStringList list;
Common::Enumerations::surveyUnits().getDisplayStri ngs(list);
editor = new QComboBox(parent);
((QComboBox*)editor)->addItems(list);
}
break;
}
}
break;
case 1:
{
editor = new QLineEdit(parent);
((QLineEdit*)editor)->setValidator(new QIntValidator());
}
break;
}
return editor;
Is there a better way to achieve this?
TIA