Change the type key for delegate editors to int.
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>
This commit is contained in:
parent
be1867b6c4
commit
d9468a9752
5
dist/changes-5.0.0
vendored
5
dist/changes-5.0.0
vendored
@ -125,6 +125,11 @@ information about a particular change.
|
|||||||
* It is no longer possible to use Q_DECLARE_METATYPE(Foo*) where Foo is only
|
* It is no longer possible to use Q_DECLARE_METATYPE(Foo*) where Foo is only
|
||||||
forward declared - it must be fully defined.
|
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:
|
- QWindowSystemInterface:
|
||||||
|
|
||||||
* The signature of all handleTouchEvent() variants have changed,
|
* The signature of all handleTouchEvent() variants have changed,
|
||||||
|
@ -527,11 +527,10 @@ QWidget *QItemDelegate::createEditor(QWidget *parent,
|
|||||||
Q_D(const QItemDelegate);
|
Q_D(const QItemDelegate);
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType());
|
|
||||||
const QItemEditorFactory *factory = d->f;
|
const QItemEditorFactory *factory = d->f;
|
||||||
if (factory == 0)
|
if (factory == 0)
|
||||||
factory = QItemEditorFactory::defaultFactory();
|
factory = QItemEditorFactory::defaultFactory();
|
||||||
return factory->createEditor(t, parent);
|
return factory->createEditor(index.data(Qt::EditRole).userType(), parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -568,7 +567,7 @@ void QItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con
|
|||||||
|
|
||||||
// ### Qt 5: give QComboBox a USER property
|
// ### Qt 5: give QComboBox a USER property
|
||||||
if (n.isEmpty() && editor->inherits("QComboBox"))
|
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 (!n.isEmpty()) {
|
||||||
if (!v.isValid())
|
if (!v.isValid())
|
||||||
v = QVariant(editor->property(n).userType(), (const void *)0);
|
v = QVariant(editor->property(n).userType(), (const void *)0);
|
||||||
@ -603,7 +602,7 @@ void QItemDelegate::setModelData(QWidget *editor,
|
|||||||
QByteArray n = editor->metaObject()->userProperty().name();
|
QByteArray n = editor->metaObject()->userProperty().name();
|
||||||
if (n.isEmpty())
|
if (n.isEmpty())
|
||||||
n = d->editorFactory()->valuePropertyName(
|
n = d->editorFactory()->valuePropertyName(
|
||||||
static_cast<QVariant::Type>(model->data(index, Qt::EditRole).userType()));
|
model->data(index, Qt::EditRole).userType());
|
||||||
if (!n.isEmpty())
|
if (!n.isEmpty())
|
||||||
model->setData(index, editor->property(n), Qt::EditRole);
|
model->setData(index, editor->property(n), Qt::EditRole);
|
||||||
#endif
|
#endif
|
||||||
|
@ -126,30 +126,30 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
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.
|
and returns it as a QWidget.
|
||||||
|
|
||||||
\sa registerEditor()
|
\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) {
|
if (!creator) {
|
||||||
const QItemEditorFactory *dfactory = defaultFactory();
|
const QItemEditorFactory *dfactory = defaultFactory();
|
||||||
return dfactory == this ? 0 : dfactory->createEditor(type, parent);
|
return dfactory == this ? 0 : dfactory->createEditor(userType, parent);
|
||||||
}
|
}
|
||||||
return creator->createWidget(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) {
|
if (!creator) {
|
||||||
const QItemEditorFactory *dfactory = defaultFactory();
|
const QItemEditorFactory *dfactory = defaultFactory();
|
||||||
return dfactory == this ? QByteArray() : dfactory->valuePropertyName(type);
|
return dfactory == this ? QByteArray() : dfactory->valuePropertyName(userType);
|
||||||
}
|
}
|
||||||
return creator->valuePropertyName();
|
return creator->valuePropertyName();
|
||||||
}
|
}
|
||||||
@ -166,16 +166,16 @@ QItemEditorFactory::~QItemEditorFactory()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
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
|
\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.
|
it if a new creator for the same type is registered later.
|
||||||
|
|
||||||
\sa createEditor()
|
\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()) {
|
if (it != creatorMap.end()) {
|
||||||
QItemEditorCreatorBase *oldCreator = it.value();
|
QItemEditorCreatorBase *oldCreator = it.value();
|
||||||
Q_ASSERT(oldCreator);
|
Q_ASSERT(oldCreator);
|
||||||
@ -184,20 +184,20 @@ void QItemEditorFactory::registerEditor(QVariant::Type type, QItemEditorCreatorB
|
|||||||
delete oldCreator; // if it is no more in use we can delete it
|
delete oldCreator; // if it is no more in use we can delete it
|
||||||
}
|
}
|
||||||
|
|
||||||
creatorMap[type] = creator;
|
creatorMap[userType] = creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
class QDefaultItemEditorFactory : public QItemEditorFactory
|
class QDefaultItemEditorFactory : public QItemEditorFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
inline QDefaultItemEditorFactory() {}
|
inline QDefaultItemEditorFactory() {}
|
||||||
QWidget *createEditor(QVariant::Type type, QWidget *parent) const;
|
QWidget *createEditor(int userType, QWidget *parent) const;
|
||||||
QByteArray valuePropertyName(QVariant::Type) 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
|
#ifndef QT_NO_COMBOBOX
|
||||||
case QVariant::Bool: {
|
case QVariant::Bool: {
|
||||||
QBooleanComboBox *cb = new QBooleanComboBox(parent);
|
QBooleanComboBox *cb = new QBooleanComboBox(parent);
|
||||||
@ -258,9 +258,9 @@ QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *p
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray QDefaultItemEditorFactory::valuePropertyName(QVariant::Type type) const
|
QByteArray QDefaultItemEditorFactory::valuePropertyName(int userType) const
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (userType) {
|
||||||
#ifndef QT_NO_COMBOBOX
|
#ifndef QT_NO_COMBOBOX
|
||||||
case QVariant::Bool:
|
case QVariant::Bool:
|
||||||
return "currentIndex";
|
return "currentIndex";
|
||||||
|
@ -102,16 +102,16 @@ public:
|
|||||||
inline QItemEditorFactory() {}
|
inline QItemEditorFactory() {}
|
||||||
virtual ~QItemEditorFactory();
|
virtual ~QItemEditorFactory();
|
||||||
|
|
||||||
virtual QWidget *createEditor(QVariant::Type type, QWidget *parent) const;
|
virtual QWidget *createEditor(int userType, QWidget *parent) const;
|
||||||
virtual QByteArray valuePropertyName(QVariant::Type type) 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 const QItemEditorFactory *defaultFactory();
|
||||||
static void setDefaultFactory(QItemEditorFactory *factory);
|
static void setDefaultFactory(QItemEditorFactory *factory);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QHash<QVariant::Type, QItemEditorCreatorBase *> creatorMap;
|
QHash<int, QItemEditorCreatorBase *> creatorMap;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // QT_NO_ITEMVIEWS
|
#endif // QT_NO_ITEMVIEWS
|
||||||
|
@ -468,8 +468,7 @@ QWidget *QStyledItemDelegate::createEditor(QWidget *parent,
|
|||||||
Q_D(const QStyledItemDelegate);
|
Q_D(const QStyledItemDelegate);
|
||||||
if (!index.isValid())
|
if (!index.isValid())
|
||||||
return 0;
|
return 0;
|
||||||
QVariant::Type t = static_cast<QVariant::Type>(index.data(Qt::EditRole).userType());
|
return d->editorFactory()->createEditor(index.data(Qt::EditRole).userType(), parent);
|
||||||
return d->editorFactory()->createEditor(t, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -505,7 +504,7 @@ void QStyledItemDelegate::setEditorData(QWidget *editor, const QModelIndex &inde
|
|||||||
|
|
||||||
// ### Qt 5: give QComboBox a USER property
|
// ### Qt 5: give QComboBox a USER property
|
||||||
if (n.isEmpty() && editor->inherits("QComboBox"))
|
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 (!n.isEmpty()) {
|
||||||
if (!v.isValid())
|
if (!v.isValid())
|
||||||
v = QVariant(editor->property(n).userType(), (const void *)0);
|
v = QVariant(editor->property(n).userType(), (const void *)0);
|
||||||
@ -539,7 +538,7 @@ void QStyledItemDelegate::setModelData(QWidget *editor,
|
|||||||
QByteArray n = editor->metaObject()->userProperty().name();
|
QByteArray n = editor->metaObject()->userProperty().name();
|
||||||
if (n.isEmpty())
|
if (n.isEmpty())
|
||||||
n = d->editorFactory()->valuePropertyName(
|
n = d->editorFactory()->valuePropertyName(
|
||||||
static_cast<QVariant::Type>(model->data(index, Qt::EditRole).userType()));
|
model->data(index, Qt::EditRole).userType());
|
||||||
if (!n.isEmpty())
|
if (!n.isEmpty())
|
||||||
model->setData(index, editor->property(n), Qt::EditRole);
|
model->setData(index, editor->property(n), Qt::EditRole);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user