Thanks Wysota!
1) My widgets look kind of "borderless"...
2) Ok, i have done that for now to test, and it's working pretty good:
for (QVariantHash::const_iterator i=_parameters.constBegin(); i!=_parameters.constEnd(); ++i) {
int const uTp = val.userType();
if (uTp>=qMetaTypeId<RE::E::Agressivity>() && uTp<=qMetaTypeId<RE::E::DocumentType>()) {
mtName = mtName.mid(mtName.lastIndexOf(':')+1);
qint32 const iEnum = mo.indexOfEnumerator(mtName.toLatin1());
quint32 const cEnum = en.keyCount();
for (quint32 i=0; i<cEnum; i++) {
const char *key = en.key(i);
cmbBx->addItem (RE::classNameToNaturalString(key));
}
wgt = cmbBx;
}
else
ui.frmMain->addRow (RE::classNameToNaturalString(name), wgt);
for (QVariantHash::const_iterator i=_parameters.constBegin(); i!=_parameters.constEnd(); ++i) {
QString const &name = i.key();
QVariant const &val = i.value();
int const uTp = val.userType();
QWidget *wgt = 0;
if (uTp>=qMetaTypeId<RE::E::Agressivity>() && uTp<=qMetaTypeId<RE::E::DocumentType>()) {
QComboBox *cmbBx = new QComboBox();
QMetaObject const &mo = RE::E::staticMetaObject;
QString mtName = QMetaType::typeName(uTp);
mtName = mtName.mid(mtName.lastIndexOf(':')+1);
qint32 const iEnum = mo.indexOfEnumerator(mtName.toLatin1());
QMetaEnum const &en = mo.enumerator(iEnum);
quint32 const cEnum = en.keyCount();
for (quint32 i=0; i<cEnum; i++) {
const char *key = en.key(i);
cmbBx->addItem (RE::classNameToNaturalString(key));
}
wgt = cmbBx;
}
else
wgt = QItemEditorFactory::defaultFactory()->createEditor((QVariant::Type)val.userType(), this);
ui.frmMain->addRow (RE::classNameToNaturalString(name), wgt);
To copy to clipboard, switch view to plain text mode
This sample piece of code assumes that all the custom enums are registered all after each other, so their metatype id follow each other (Hence the range check at the very begining of the code, to know if a given type ID is an enum or not).
Later i'll subclass the factory to allow creation of the widget more "cleanly"
3) No... i did everything required at compile time and at run time to register my types. The solution i have found is to not put my enums directly in my "fake emulated" namespace, but within a class in that namespace.
Thanks for your answers!
Pierre.
Bookmarks