Just some precisions.... For now, to allow my editor factory to work, i'm doing like this:
_widget
= f
->createEditor
((QVariant::Type)_param.
value.
userType(),
this);
QItemEditorFactory const *f = QItemEditorFactory::defaultFactory();
_widget = f->createEditor((QVariant::Type)_param.value.userType(), this);
QByteArray vpName = f->valuePropertyName((QVariant::Type)_param.value.userType());
To copy to clipboard, switch view to plain text mode
Then, in my QItemEditorFactory subclass:
// Custom boolean editor.
ed = new WgtBoolEditor(parent);
// Custom QPoint editor.
ed = new WgtPointEditor(false, INT_MIN, INT_MAX, parent);
// Custom QPointF editor.
ed = new WgtPointEditor(true, LONG_MIN, LONG_MAX, parent);
// Custom RelativeRect editor.
else if (type==qMetaTypeId<REA::RelativeRect>())
ed = new WgtRelativeRectEditor(false, INT_MIN, INT_MAX, parent);
// Custom RelativeRectF editor.
else if (type==qMetaTypeId<REA::RelativeRectF>())
ed = new WgtRelativeRectEditor(true, INT_MIN, INT_MAX, parent);
else
ed = _standardFactory->createEditor(type, parent);
return ed;
}
return "value";
else
return _standardFactory->valuePropertyName(type);
}
QWidget* CustomItemEditorFactory::createEditor (QVariant::Type type, QWidget* parent) const {
QWidget *ed;
// Custom boolean editor.
if (type==QVariant::Bool)
ed = new WgtBoolEditor(parent);
// Custom QPoint editor.
else if (type==QVariant::Point)
ed = new WgtPointEditor(false, INT_MIN, INT_MAX, parent);
// Custom QPointF editor.
else if (type==QVariant::PointF)
ed = new WgtPointEditor(true, LONG_MIN, LONG_MAX, parent);
// Custom RelativeRect editor.
else if (type==qMetaTypeId<REA::RelativeRect>())
ed = new WgtRelativeRectEditor(false, INT_MIN, INT_MAX, parent);
// Custom RelativeRectF editor.
else if (type==qMetaTypeId<REA::RelativeRectF>())
ed = new WgtRelativeRectEditor(true, INT_MIN, INT_MAX, parent);
else
ed = _standardFactory->createEditor(type, parent);
return ed;
}
QByteArray CustomItemEditorFactory::valuePropertyName (QVariant::Type type) const {
if (type==QVariant::Bool || type==QVariant::Point || type==QVariant::PointF)
return "value";
else
return _standardFactory->valuePropertyName(type);
}
To copy to clipboard, switch view to plain text mode
Is there any better way to do that (Without casting some ints into QVariant::Type)? Actually, this works pretty good... But i'm not sure if it's the only way to achieve correctly what i'm trying to do... Without being able to get my custom types detailed as QVariant::Type from my custom factory, i really don't see the point of registering custom types.
Thanks,
Pierre.
[EDIT]And for the records, here is my custom types declaration:
#ifndef REATypes_h
#define REATypes_h
#include <QRect>
#include <QRectF>
namespace REA {
// Unsigned integers list.
typedef QList<unsigned int> UIntList;
// Signed integers list.
typedef QList<int> IntList;
// Color to unsigned int hash.
typedef QHash<QRgb,unsigned int> ColorToUIntHash;
// Relative rect class.
class RelativeRect
: public QRect {};
// Relative float rect class.
class RelativeRectF
: public QRectF {};
};
// Declare meta-types.
Q_DECLARE_METATYPE(REA::UIntList);
Q_DECLARE_METATYPE(REA::IntList);
Q_DECLARE_METATYPE(REA::ColorToUIntHash);
Q_DECLARE_METATYPE(REA::RelativeRect);
Q_DECLARE_METATYPE(REA::RelativeRectF);
#endif
#ifndef REATypes_h
#define REATypes_h
#include <QRect>
#include <QRectF>
namespace REA {
// Unsigned integers list.
typedef QList<unsigned int> UIntList;
// Signed integers list.
typedef QList<int> IntList;
// Color to unsigned int hash.
typedef QHash<QRgb,unsigned int> ColorToUIntHash;
// Relative rect class.
class RelativeRect : public QRect {};
// Relative float rect class.
class RelativeRectF : public QRectF {};
};
// Declare meta-types.
Q_DECLARE_METATYPE(REA::UIntList);
Q_DECLARE_METATYPE(REA::IntList);
Q_DECLARE_METATYPE(REA::ColorToUIntHash);
Q_DECLARE_METATYPE(REA::RelativeRect);
Q_DECLARE_METATYPE(REA::RelativeRectF);
#endif
To copy to clipboard, switch view to plain text mode
[/EDIT]
Bookmarks