Doc: replace QItemDelegate with QStyledItemDelegate

Since QStyledItemDelegate should be preferred over QItemDelegate the
documentation should point to QStyledItemDelegate instead.
Also mark some internal classes which derive from QItemDelegate so they
will not be forgotten during Qt6 porting.

Change-Id: I2dd17feedf8593afac5ca16d2546e1f0bc0250ae
Reviewed-by: Paul Wicking <paul.wicking@qt.io>
Reviewed-by: Konstantin Shegunov <kshegunov@gmail.com>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
Christian Ehrlicher 2018-12-06 18:13:47 +01:00
parent 3456d51650
commit 283008e123
13 changed files with 28 additions and 23 deletions

View File

@ -58,7 +58,7 @@ QT_REQUIRE_CONFIG(sqlmodel);
#include <QtCore/qmetaobject.h> #include <QtCore/qmetaobject.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
// ### Qt6: QStyledItemDelegate
class QSqlRelationalDelegate: public QItemDelegate class QSqlRelationalDelegate: public QItemDelegate
{ {
static int fieldIndex(const QSqlTableModel *const model, static int fieldIndex(const QSqlTableModel *const model,

View File

@ -693,9 +693,9 @@
\l QAbstractItemDelegate class. \l QAbstractItemDelegate class.
Delegates are expected to be able to render their contents themselves Delegates are expected to be able to render their contents themselves
by implementing the \l{QItemDelegate::paint()}{paint()} by implementing the \l{QStyledItemDelegate::paint()}{paint()}
and \l{QItemDelegate::sizeHint()}{sizeHint()} functions. and \l{QStyledItemDelegate::sizeHint()}{sizeHint()} functions.
However, simple widget-based delegates can subclass \l QItemDelegate However, simple widget-based delegates can subclass \l QStyledItemDelegate
instead of \l QAbstractItemDelegate, and take advantage of the default instead of \l QAbstractItemDelegate, and take advantage of the default
implementations of these functions. implementations of these functions.
@ -709,14 +709,14 @@
\section2 Using an existing delegate \section2 Using an existing delegate
The standard views provided with Qt use instances of \l QItemDelegate The standard views provided with Qt use instances of \l QStyledItemDelegate
to provide editing facilities. This default implementation of the to provide editing facilities. This default implementation of the
delegate interface renders items in the usual style for each of the delegate interface renders items in the usual style for each of the
standard views: \l QListView, \l QTableView, and \l QTreeView. standard views: \l QListView, \l QTableView, and \l QTreeView.
All the standard roles are handled by the default delegate used by All the standard roles are handled by the default delegate used by
the standard views. The way these are interpreted is described in the the standard views. The way these are interpreted is described in the
QItemDelegate documentation. QStyledItemDelegate documentation.
The delegate used by a view is returned by the The delegate used by a view is returned by the
\l{QAbstractItemView::itemDelegate()}{itemDelegate()} function. \l{QAbstractItemView::itemDelegate()}{itemDelegate()} function.
@ -799,7 +799,7 @@
In this case, we ensure that the spin box is up-to-date, and update In this case, we ensure that the spin box is up-to-date, and update
the model with the value it contains using the index specified. the model with the value it contains using the index specified.
The standard \l QItemDelegate class informs the view when it has The standard \l QStyledItemDelegate class informs the view when it has
finished editing by emitting the finished editing by emitting the
\l{QAbstractItemDelegate::closeEditor()}{closeEditor()} signal. \l{QAbstractItemDelegate::closeEditor()}{closeEditor()} signal.
The view ensures that the editor widget is closed and destroyed. In The view ensures that the editor widget is closed and destroyed. In
@ -838,11 +838,11 @@
assist any subsequent editing operations. This is achieved by assist any subsequent editing operations. This is achieved by
emitting the \l{QAbstractItemDelegate::closeEditor()}{closeEditor()} emitting the \l{QAbstractItemDelegate::closeEditor()}{closeEditor()}
signal with a suitable hint. This is taken care of by the default signal with a suitable hint. This is taken care of by the default
QItemDelegate event filter which we installed on the spin box when QStyledItemDelegate event filter which we installed on the spin box when
it was constructed. it was constructed.
The behavior of the spin box could be adjusted to make it more user The behavior of the spin box could be adjusted to make it more user
friendly. In the default event filter supplied by QItemDelegate, if friendly. In the default event filter supplied by QStyledItemDelegate, if
the user hits \uicontrol Return to confirm their choice in the spin box, the user hits \uicontrol Return to confirm their choice in the spin box,
the delegate commits the value to the model and closes the spin box. the delegate commits the value to the model and closes the spin box.
We can change this behavior by installing our own event filter on the We can change this behavior by installing our own event filter on the

View File

@ -88,7 +88,7 @@ QT_BEGIN_NAMESPACE
and is part of Qt's \l{Model/View Programming}{model/view framework}. and is part of Qt's \l{Model/View Programming}{model/view framework}.
To render an item in a custom way, you must implement paint() and To render an item in a custom way, you must implement paint() and
sizeHint(). The QItemDelegate class provides default implementations for sizeHint(). The QStyledItemDelegate class provides default implementations for
these functions; if you do not need custom rendering, subclass that these functions; if you do not need custom rendering, subclass that
class instead. class instead.
@ -115,7 +115,7 @@ QT_BEGIN_NAMESPACE
The second approach is to handle user events directly by reimplementing The second approach is to handle user events directly by reimplementing
editorEvent(). editorEvent().
\sa {model-view-programming}{Model/View Programming}, QItemDelegate, \sa {model-view-programming}{Model/View Programming}, QStyledItemDelegate,
{Pixelator Example}, QStyledItemDelegate, QStyle {Pixelator Example}, QStyledItemDelegate, QStyle
*/ */

View File

@ -3211,7 +3211,7 @@ bool QAbstractItemView::isPersistentEditorOpen(const QModelIndex &index) const
This function should only be used to display static content within the This function should only be used to display static content within the
visible area corresponding to an item of data. If you want to display visible area corresponding to an item of data. If you want to display
custom dynamic content or implement a custom editor widget, subclass custom dynamic content or implement a custom editor widget, subclass
QItemDelegate instead. QStyledItemDelegate instead.
\sa {Delegate Classes} \sa {Delegate Classes}
*/ */

View File

@ -181,6 +181,7 @@ public:
/*! /*!
* This is a delegate that will paint the triangle * This is a delegate that will paint the triangle
*/ */
// ### Qt6: QStyledItemDelegate
class QColumnViewDelegate : public QItemDelegate class QColumnViewDelegate : public QItemDelegate
{ {

View File

@ -324,6 +324,7 @@ void QDataWidgetMapperPrivate::_q_modelDestroyed()
QDataWidgetMapper::QDataWidgetMapper(QObject *parent) QDataWidgetMapper::QDataWidgetMapper(QObject *parent)
: QObject(*new QDataWidgetMapperPrivate, parent) : QObject(*new QDataWidgetMapperPrivate, parent)
{ {
// ### Qt6: QStyledItemDelegate
setItemDelegate(new QItemDelegate(this)); setItemDelegate(new QItemDelegate(this));
} }

View File

@ -122,7 +122,7 @@ Q_SIGNALS:
\inmodule QtWidgets \inmodule QtWidgets
When editing data in an item view, editors are created and When editing data in an item view, editors are created and
displayed by a delegate. QItemDelegate, which is the delegate by displayed by a delegate. QStyledItemDelegate, which is the delegate by
default installed on Qt's item views, uses a QItemEditorFactory to default installed on Qt's item views, uses a QItemEditorFactory to
create editors for it. A default unique instance provided by create editors for it. A default unique instance provided by
QItemEditorFactory is used by all item delegates. If you set a QItemEditorFactory is used by all item delegates. If you set a
@ -156,7 +156,7 @@ Q_SIGNALS:
Additional editors can be registered with the registerEditor() function. Additional editors can be registered with the registerEditor() function.
\sa QItemDelegate, {Model/View Programming}, {Color Editor Factory Example} \sa QStyledItemDelegate, {Model/View Programming}, {Color Editor Factory Example}
*/ */
/*! /*!
@ -375,7 +375,7 @@ void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory)
QItemEditorCreatorBase objects are specialized widget factories that QItemEditorCreatorBase objects are specialized widget factories that
provide editor widgets for one particular QVariant data type. They provide editor widgets for one particular QVariant data type. They
are used by QItemEditorFactory to create editors for are used by QItemEditorFactory to create editors for
\l{QItemDelegate}s. Creator bases must be registered with \l{QStyledItemDelegate}s. Creator bases must be registered with
QItemEditorFactory::registerEditor(). QItemEditorFactory::registerEditor().
An editor should provide a user property for the data it edits. An editor should provide a user property for the data it edits.
@ -457,7 +457,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
\snippet code/src_gui_itemviews_qitemeditorfactory.cpp 1 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 1
The constructor takes the name of the property that contains the The constructor takes the name of the property that contains the
editing data. QItemDelegate can then access the property by name editing data. QStyledItemDelegate can then access the property by name
when it sets and retrieves editing data. Only use this class if when it sets and retrieves editing data. Only use this class if
your editor does not define a user property (using the USER your editor does not define a user property (using the USER
keyword in the Q_PROPERTY macro). If the widget has a user keyword in the Q_PROPERTY macro). If the widget has a user
@ -472,7 +472,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
Constructs an editor creator object using \a valuePropertyName Constructs an editor creator object using \a valuePropertyName
as the name of the property to be used for editing. The as the name of the property to be used for editing. The
property name is used by QItemDelegate when setting and property name is used by QStyledItemDelegate when setting and
getting editor data. getting editor data.
Note that the \a valuePropertyName is only used if the editor Note that the \a valuePropertyName is only used if the editor
@ -508,11 +508,11 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
\snippet code/src_gui_itemviews_qitemeditorfactory.cpp 2 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 2
Setting the \c editorFactory created above in an item delegate via Setting the \c editorFactory created above in an item delegate via
QItemDelegate::setItemEditorFactory() makes sure that all values of type QStyledItemDelegate::setItemEditorFactory() makes sure that all values of type
QVariant::DateTime will be edited in \c{MyFancyDateTimeEdit}. QVariant::DateTime will be edited in \c{MyFancyDateTimeEdit}.
The editor must provide a user property that will contain the The editor must provide a user property that will contain the
editing data. The property is used by \l{QItemDelegate}s to set editing data. The property is used by \l{QStyledItemDelegate}s to set
and retrieve the data (using Qt's \l{Meta-Object and retrieve the data (using Qt's \l{Meta-Object
System}{meta-object system}). You set the user property with System}{meta-object system}). You set the user property with
the USER keyword: the USER keyword:
@ -520,7 +520,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase()
\snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3 \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3
\sa QItemEditorCreatorBase, QItemEditorCreator, \sa QItemEditorCreatorBase, QItemEditorCreator,
QItemEditorFactory, QItemDelegate, {Color Editor Factory Example} QItemEditorFactory, QStyledItemDelegate, {Color Editor Factory Example}
*/ */
/*! /*!

View File

@ -1757,7 +1757,7 @@ QWidget *QListWidget::itemWidget(QListWidgetItem *item) const
This function should only be used to display static content in the place of This function should only be used to display static content in the place of
a list widget item. If you want to display custom dynamic content or a list widget item. If you want to display custom dynamic content or
implement a custom editor widget, use QListView and subclass QItemDelegate implement a custom editor widget, use QListView and subclass QStyledItemDelegate
instead. instead.
\sa itemWidget(), removeItemWidget(), {Delegate Classes} \sa itemWidget(), removeItemWidget(), {Delegate Classes}

View File

@ -1108,7 +1108,7 @@ int QTableViewPrivate::heightHintForIndex(const QModelIndex &index, int hint, QS
\l showGrid property. \l showGrid property.
The items shown in a table view, like those in the other item views, are The items shown in a table view, like those in the other item views, are
rendered and edited using standard \l{QItemDelegate}{delegates}. However, rendered and edited using standard \l{QStyledItemDelegate}{delegates}. However,
for some tasks it is sometimes useful to be able to insert widgets in a for some tasks it is sometimes useful to be able to insert widgets in a
table instead. Widgets are set for particular indexes with the table instead. Widgets are set for particular indexes with the
\l{QAbstractItemView::}{setIndexWidget()} function, and \l{QAbstractItemView::}{setIndexWidget()} function, and

View File

@ -3101,7 +3101,7 @@ QWidget *QTreeWidget::itemWidget(QTreeWidgetItem *item, int column) const
This function should only be used to display static content in the place of This function should only be used to display static content in the place of
a tree widget item. If you want to display custom dynamic content or a tree widget item. If you want to display custom dynamic content or
implement a custom editor widget, use QTreeView and subclass QItemDelegate implement a custom editor widget, use QTreeView and subclass QStyledItemDelegate
instead. instead.
This function cannot be called before the item hierarchy has been set up, This function cannot be called before the item hierarchy has been set up,

View File

@ -194,6 +194,7 @@ private:
const QIndexMapper& iv, QMatchData* m); const QIndexMapper& iv, QMatchData* m);
}; };
// ### Qt6: QStyledItemDelegate
class QCompleterItemDelegate : public QItemDelegate class QCompleterItemDelegate : public QItemDelegate
{ {
public: public:

View File

@ -1555,6 +1555,7 @@ void QCalendarView::mouseReleaseEvent(QMouseEvent *event)
} }
} }
// ### Qt6: QStyledItemDelegate
class QCalendarDelegate : public QItemDelegate class QCalendarDelegate : public QItemDelegate
{ {
Q_OBJECT Q_OBJECT

View File

@ -293,6 +293,7 @@ private:
QComboBox *mCombo; QComboBox *mCombo;
}; };
// ### Qt6: QStyledItemDelegate ?
// Note that this class is intentionally not using QStyledItemDelegate // Note that this class is intentionally not using QStyledItemDelegate
// Vista does not use the new theme for combo boxes and there might // Vista does not use the new theme for combo boxes and there might
// be other side effects from using the new class // be other side effects from using the new class