Previous type of QVariant::Type does not allow for custom types.
While technically source incompatible I found no re-implementation
of this class in qttools or qt-creator (most likely to use it for
property editors). The virtual methods are not needed because
registerEditor is all the API that is really needed.
Task-number: QTBUG-1065
Change-Id: I2a9c578c444a80359416f2224a0ee03903bfe779
Reviewed-by: Olivier Goffart <ogoffart@woboq.com>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
* It is no longer possible to use Q_DECLARE_METATYPE(Foo*) where Foo is only
forward declared - it must be fully defined.
+- QItemEditorFactory
+
+ * The signature of the createEditor and valuePropertyName methods
+ have been changed to take arguments of type int instead of QVariant::Type.
+
- QWindowSystemInterface:
* The signature of all handleTouchEvent() variants have changed,
Q_D(const QItemDelegate);
if (!index.isValid())
return 0;
- QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType());
const QItemEditorFactory *factory = d->f;
if (factory == 0)
factory = QItemEditorFactory::defaultFactory();
- return factory->createEditor(t, parent);
+ return factory->createEditor(index.data(Qt::EditRole).userType(), parent);
}
/*!
// ### Qt 5: give QComboBox a USER property
if (n.isEmpty() && editor->inherits("QComboBox"))
- n = d->editorFactory()->valuePropertyName(static_cast<QVariant::Type>(v.userType()));
+ n = d->editorFactory()->valuePropertyName(v.userType());
if (!n.isEmpty()) {
if (!v.isValid())
v = QVariant(editor->property(n).userType(), (const void *)0);
QByteArray n = editor->metaObject()->userProperty().name();
if (n.isEmpty())
n = d->editorFactory()->valuePropertyName(
- static_cast<QVariant::Type>(model->data(index, Qt::EditRole).userType()));
+ model->data(index, Qt::EditRole).userType());
if (!n.isEmpty())
model->setData(index, editor->property(n), Qt::EditRole);
#endif
*/
/*!
- Creates an editor widget with the given \a parent for the specified \a type of data,
+ Creates an editor widget with the given \a parent for the specified \a userType of data,
and returns it as a QWidget.
\sa registerEditor()
*/
-QWidget *QItemEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const
+QWidget *QItemEditorFactory::createEditor(int userType, QWidget *parent) const
{
- QItemEditorCreatorBase *creator = creatorMap.value(type, 0);
+ QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);
if (!creator) {
const QItemEditorFactory *dfactory = defaultFactory();
- return dfactory == this ? 0 : dfactory->createEditor(type, parent);
+ return dfactory == this ? 0 : dfactory->createEditor(userType, parent);
}
return creator->createWidget(parent);
}
/*!
- Returns the property name used to access data for the given \a type of data.
+ Returns the property name used to access data for the given \a userType of data.
*/
-QByteArray QItemEditorFactory::valuePropertyName(QVariant::Type type) const
+QByteArray QItemEditorFactory::valuePropertyName(int userType) const
{
- QItemEditorCreatorBase *creator = creatorMap.value(type, 0);
+ QItemEditorCreatorBase *creator = creatorMap.value(userType, 0);
if (!creator) {
const QItemEditorFactory *dfactory = defaultFactory();
- return dfactory == this ? QByteArray() : dfactory->valuePropertyName(type);
+ return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType);
}
return creator->valuePropertyName();
}
}
/*!
- Registers an item editor creator specified by \a creator for the given \a type of data.
+ Registers an item editor creator specified by \a creator for the given \a userType of data.
\bold{Note:} The factory takes ownership of the item editor creator and will destroy
it if a new creator for the same type is registered later.
\sa createEditor()
*/
-void QItemEditorFactory::registerEditor(QVariant::Type type, QItemEditorCreatorBase *creator)
+void QItemEditorFactory::registerEditor(int userType, QItemEditorCreatorBase *creator)
{
- QHash<QVariant::Type, QItemEditorCreatorBase *>::iterator it = creatorMap.find(type);
+ QHash<int, QItemEditorCreatorBase *>::iterator it = creatorMap.find(userType);
if (it != creatorMap.end()) {
QItemEditorCreatorBase *oldCreator = it.value();
Q_ASSERT(oldCreator);
delete oldCreator; // if it is no more in use we can delete it
}
- creatorMap[type] = creator;
+ creatorMap[userType] = creator;
}
class QDefaultItemEditorFactory : public QItemEditorFactory
{
public:
inline QDefaultItemEditorFactory() {}
- QWidget *createEditor(QVariant::Type type, QWidget *parent) const;
- QByteArray valuePropertyName(QVariant::Type) const;
+ QWidget *createEditor(int userType, QWidget *parent) const;
+ QByteArray valuePropertyName(int) const;
};
-QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *parent) const
+QWidget *QDefaultItemEditorFactory::createEditor(int userType, QWidget *parent) const
{
- switch (type) {
+ switch (userType) {
#ifndef QT_NO_COMBOBOX
case QVariant::Bool: {
QBooleanComboBox *cb = new QBooleanComboBox(parent);
return 0;
}
-QByteArray QDefaultItemEditorFactory::valuePropertyName(QVariant::Type type) const
+QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const
{
- switch (type) {
+ switch (userType) {
#ifndef QT_NO_COMBOBOX
case QVariant::Bool:
return "currentIndex";
inline QItemEditorFactory() {}
virtual ~QItemEditorFactory();
- virtual QWidget *createEditor(QVariant::Type type, QWidget *parent) const;
- virtual QByteArray valuePropertyName(QVariant::Type type) const;
+ virtual QWidget *createEditor(int userType, QWidget *parent) const;
+ virtual QByteArray valuePropertyName(int userType) const;
- void registerEditor(QVariant::Type type, QItemEditorCreatorBase *creator);
+ void registerEditor(int userType, QItemEditorCreatorBase *creator);
static const QItemEditorFactory *defaultFactory();
static void setDefaultFactory(QItemEditorFactory *factory);
private:
- QHash<QVariant::Type, QItemEditorCreatorBase *> creatorMap;
+ QHash<int, QItemEditorCreatorBase *> creatorMap;
};
#endif // QT_NO_ITEMVIEWS
Q_D(const QStyledItemDelegate);
if (!index.isValid())
return 0;
- QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType());
- return d->editorFactory()->createEditor(t, parent);
+ return d->editorFactory()->createEditor(index.data(Qt::EditRole).userType(), parent);
}
/*!
// ### Qt 5: give QComboBox a USER property
if (n.isEmpty() && editor->inherits("QComboBox"))
- n = d->editorFactory()->valuePropertyName(static_cast<QVariant::Type>(v.userType()));
+ n = d->editorFactory()->valuePropertyName(v.userType());
if (!n.isEmpty()) {
if (!v.isValid())
v = QVariant(editor->property(n).userType(), (const void *)0);
QByteArray n = editor->metaObject()->userProperty().name();
if (n.isEmpty())
n = d->editorFactory()->valuePropertyName(
- static_cast<QVariant::Type>(model->data(index, Qt::EditRole).userType()));
+ model->data(index, Qt::EditRole).userType());
if (!n.isEmpty())
model->setData(index, editor->property(n), Qt::EditRole);
#endif