diff options
author | Luca Beldi <v.ronin@yahoo.it> | 2018-08-01 16:43:31 +0100 |
---|---|---|
committer | Luca Beldi <v.ronin@yahoo.it> | 2018-08-17 07:17:12 +0000 |
commit | d0069ff8c91e0027a0a1f3ef7767dbb13e0eacc4 (patch) | |
tree | 4305eb9240e4880edda8f355cdc057a92ce6dd6c /src/gui/itemmodels/qstandarditemmodel.cpp | |
parent | 67352c92761fcb2e2c6a98b24e1bf5f33805cb3a (diff) |
Add a method to clear the data to QStandardItemModel
After the behavior of setItemData has been changed following QTBUG-45114,
QStandardItemModel was lacking an interface to clear all the data from a single index.
Task-number: QTBUG-69616
Change-Id: Ide0b5bb6358439fc42c474df8b044fbace6def8d
Reviewed-by: André Hartmann <aha_1980@gmx.de>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'src/gui/itemmodels/qstandarditemmodel.cpp')
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index 235bc5bd7d..a771bffa2f 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -931,6 +931,21 @@ void QStandardItem::setData(const QVariant &value, int role) } /*! + \since 5.12 + Removes all the data from all roles previously set. + \sa data(), setData() +*/ +void QStandardItem::clearData() +{ + Q_D(QStandardItem); + if (d->values.isEmpty()) + return; + d->values.clear(); + if (d->model) + d->model->d_func()->itemChanged(this, QVector<int>{}); +} + +/*! Returns the item's data for the given \a role, or an invalid QVariant if there is no data for the role. @@ -2991,6 +3006,23 @@ bool QStandardItemModel::setData(const QModelIndex &index, const QVariant &value } /*! + \since 5.12 + Removes the data stored in all the roles for the given \a index. + \sa setData(), data() +*/ +bool QStandardItemModel::clearItemData(const QModelIndex &index) +{ + if (!checkIndex(index, CheckIndexOption::IndexIsValid)) + return false; + Q_D(QStandardItemModel); + QStandardItem *item = d->itemFromIndex(index); + if (!item) + return false; + item->clearData(); + return true; +} + +/*! \reimp */ bool QStandardItemModel::setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role) |