summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Kelly <stephen.kelly@kdab.com>2012-01-27 03:33:13 +0100
committerQt by Nokia <qt-info@nokia.com>2012-01-30 16:25:09 +0100
commitd9468a975210ecb58ff199e931f47df5b99b267f (patch)
treecdcf71215bca02739c80f550e9ddbed635ad38ab
parentbe1867b6c4743da937d269f04c2e108a18d3f400 (diff)
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>
-rw-r--r--dist/changes-5.0.05
-rw-r--r--src/widgets/itemviews/qitemdelegate.cpp7
-rw-r--r--src/widgets/itemviews/qitemeditorfactory.cpp36
-rw-r--r--src/widgets/itemviews/qitemeditorfactory.h8
-rw-r--r--src/widgets/itemviews/qstyleditemdelegate.cpp7
5 files changed, 33 insertions, 30 deletions
diff --git a/dist/changes-5.0.0 b/dist/changes-5.0.0
index ea76901df3..cdab7970ef 100644
--- a/dist/changes-5.0.0
+++ b/dist/changes-5.0.0
@@ -125,6 +125,11 @@ information about a particular change.
* 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,
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp
index aed751848a..a5351301a7 100644
--- a/src/widgets/itemviews/qitemdelegate.cpp
+++ b/src/widgets/itemviews/qitemdelegate.cpp
@@ -527,11 +527,10 @@ QWidget *QItemDelegate::createEditor(QWidget *parent,
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);
}
/*!
@@ -568,7 +567,7 @@ void QItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) con
// ### 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);
@@ -603,7 +602,7 @@ void QItemDelegate::setModelData(QWidget *editor,
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
diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp
index 326207afe8..468929a554 100644
--- a/src/widgets/itemviews/qitemeditorfactory.cpp
+++ b/src/widgets/itemviews/qitemeditorfactory.cpp
@@ -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.
\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();
}
@@ -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
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);
@@ -184,20 +184,20 @@ void QItemEditorFactory::registerEditor(QVariant::Type type, QItemEditorCreatorB
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);
@@ -258,9 +258,9 @@ QWidget *QDefaultItemEditorFactory::createEditor(QVariant::Type type, QWidget *p
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";
diff --git a/src/widgets/itemviews/qitemeditorfactory.h b/src/widgets/itemviews/qitemeditorfactory.h
index 52a5dea25f..aff8de3a4c 100644
--- a/src/widgets/itemviews/qitemeditorfactory.h
+++ b/src/widgets/itemviews/qitemeditorfactory.h
@@ -102,16 +102,16 @@ public:
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
diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp
index e36ee7527a..ca4c684e98 100644
--- a/src/widgets/itemviews/qstyleditemdelegate.cpp
+++ b/src/widgets/itemviews/qstyleditemdelegate.cpp
@@ -468,8 +468,7 @@ QWidget *QStyledItemDelegate::createEditor(QWidget *parent,
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);
}
/*!
@@ -505,7 +504,7 @@ void QStyledItemDelegate::setEditorData(QWidget *editor, const QModelIndex &inde
// ### 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);
@@ -539,7 +538,7 @@ void QStyledItemDelegate::setModelData(QWidget *editor,
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