diff options
author | Ahmad Samir <a.samirh78@gmail.com> | 2023-11-14 17:24:44 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-11-14 21:45:06 +0000 |
commit | 49bd0a8190eac08d630e37f636eb2da1f8d49a4d (patch) | |
tree | 478ba675d77be16a2cef098c471cdb79304c33ed /src | |
parent | 72331b450da77f9af30af497d9c194da656c7296 (diff) |
QStandardItem: add note about reimplementing data/setData() wrt. flags
Extend the unittests.
Drive-by change: add missing include, otherwise static analyzers
(clangd) complain.
Fixes: QTBUG-105150
Pick-to: 6.5 5.15
Change-Id: I312133d5b35119e2e51002dfefe0e141c0708e3d
Reviewed-by: David Faure <david.faure@kdab.com>
(cherry picked from commit 85eebedb16da67d9f2caeb14ed45c2dae8f82837)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.cpp | 17 | ||||
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel_p.h | 2 |
2 files changed, 16 insertions, 3 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index ee01da4bc1..0b741a84d7 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -868,9 +868,15 @@ QStandardItem *QStandardItem::parent() const Sets the item's data for the given \a role to the specified \a value. If you subclass QStandardItem and reimplement this function, your - reimplementation should call emitDataChanged() if you do not call - the base implementation of setData(). This will ensure that e.g. - views using the model are notified of the changes. + reimplementation should: + \list + \li call emitDataChanged() if you do not call the base implementation of + setData(). This will ensure that e.g. views using the model are notified + of the changes + \li call the base implementation for roles you don't handle, otherwise + setting flags, e.g. by calling setFlags(), setCheckable(), setEditable() + etc., will not work. + \endlist \note The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data. @@ -924,6 +930,11 @@ void QStandardItem::clearData() Returns the item's data for the given \a role, or an invalid QVariant if there is no data for the role. + If you reimplement this function, your reimplementation should call + the base implementation for roles you don't handle, otherwise getting + flags, e.g. by calling flags(), isCheckable(), isEditable() etc., + will not work. + \note The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data. */ diff --git a/src/gui/itemmodels/qstandarditemmodel_p.h b/src/gui/itemmodels/qstandarditemmodel_p.h index f25aa44116..a0c3f8a161 100644 --- a/src/gui/itemmodels/qstandarditemmodel_p.h +++ b/src/gui/itemmodels/qstandarditemmodel_p.h @@ -15,6 +15,8 @@ // We mean it. // +#include <QtGui/qstandarditemmodel.h> + #include <QtGui/private/qtguiglobal_p.h> #include "private/qabstractitemmodel_p.h" |