summaryrefslogtreecommitdiff
path: root/src/gui/itemmodels
diff options
context:
space:
mode:
authorChristian Ehrlicher <ch.ehrlicher@gmx.de>2017-12-20 21:18:54 +0100
committerChristian Ehrlicher <ch.ehrlicher@gmx.de>2018-01-26 19:58:26 +0000
commit657894624521b580f59ff5f58b9c0e9be159dc1c (patch)
treee272ead0ad252e12bcadbbf5f623d8f559b5f1bb /src/gui/itemmodels
parent52f1692b8451ac5b1e6fc059211e843bacc5c245 (diff)
downloadqtbase-657894624521b580f59ff5f58b9c0e9be159dc1c.tar.gz
QListWidgetItem/QStandardItem: pass role to dataChanged() signal
QAbstractItemModel::dataChanged() gained an optional role parameter with Qt5 which was not filled within QListWidgetItem/QStandardItem setData() functions Task-number: QTBUG-55903 Task-number: QTBUG-63766 Change-Id: I4da9346ef8401cc8633dc4b2ea7d00451d1e3942 Reviewed-by: Luca Beldi <v.ronin@yahoo.it> Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src/gui/itemmodels')
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.cpp33
-rw-r--r--src/gui/itemmodels/qstandarditemmodel.h1
-rw-r--r--src/gui/itemmodels/qstandarditemmodel_p.h2
3 files changed, 28 insertions, 8 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp
index 519995e82a..d1e0604caf 100644
--- a/src/gui/itemmodels/qstandarditemmodel.cpp
+++ b/src/gui/itemmodels/qstandarditemmodel.cpp
@@ -278,8 +278,24 @@ void QStandardItemPrivate::setItemData(const QMap<int, QVariant> &roles)
if (newValues != values) {
values.swap(newValues);
- if (model)
- model->d_func()->itemChanged(q);
+ if (model) {
+ QVector<int> roleKeys;
+ roleKeys.reserve(roles.size() + 1);
+ bool hasEditRole = false;
+ bool hasDisplayRole = false;
+ for (auto it = roles.keyBegin(); it != roles.keyEnd(); ++it) {
+ roleKeys.push_back(*it);
+ if (*it == Qt::EditRole)
+ hasEditRole = true;
+ else if (*it == Qt::DisplayRole)
+ hasDisplayRole = true;
+ }
+ if (hasEditRole && !hasDisplayRole)
+ roleKeys.push_back(Qt::DisplayRole);
+ else if (!hasEditRole && hasDisplayRole)
+ roleKeys.push_back(Qt::EditRole);
+ model->d_func()->itemChanged(q, roleKeys);
+ }
}
}
@@ -554,7 +570,7 @@ bool QStandardItemPrivate::insertColumns(int column, int count, const QList<QSta
/*!
\internal
*/
-void QStandardItemModelPrivate::itemChanged(QStandardItem *item)
+void QStandardItemModelPrivate::itemChanged(QStandardItem *item, const QVector<int> &roles)
{
Q_Q(QStandardItemModel);
Q_ASSERT(item);
@@ -570,8 +586,8 @@ void QStandardItemModelPrivate::itemChanged(QStandardItem *item)
}
} else {
// Normal item
- QModelIndex index = q->indexFromItem(item);
- emit q->dataChanged(index, index);
+ const QModelIndex index = q->indexFromItem(item);
+ emit q->dataChanged(index, index, roles);
}
}
@@ -885,6 +901,9 @@ void QStandardItem::setData(const QVariant &value, int role)
{
Q_D(QStandardItem);
role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
+ const QVector<int> roles((role == Qt::DisplayRole) ?
+ QVector<int>({Qt::DisplayRole, Qt::EditRole}) :
+ QVector<int>({role}));
QVector<QStandardItemData>::iterator it;
for (it = d->values.begin(); it != d->values.end(); ++it) {
if ((*it).role == role) {
@@ -896,13 +915,13 @@ void QStandardItem::setData(const QVariant &value, int role)
d->values.erase(it);
}
if (d->model)
- d->model->d_func()->itemChanged(this);
+ d->model->d_func()->itemChanged(this, roles);
return;
}
}
d->values.append(QStandardItemData(role, value));
if (d->model)
- d->model->d_func()->itemChanged(this);
+ d->model->d_func()->itemChanged(this, roles);
}
/*!
diff --git a/src/gui/itemmodels/qstandarditemmodel.h b/src/gui/itemmodels/qstandarditemmodel.h
index c54e7b27d9..d8f06b629a 100644
--- a/src/gui/itemmodels/qstandarditemmodel.h
+++ b/src/gui/itemmodels/qstandarditemmodel.h
@@ -419,6 +419,7 @@ public:
bool dropMimeData (const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
Q_SIGNALS:
+ // ### Qt 6: add changed roles
void itemChanged(QStandardItem *item);
protected:
diff --git a/src/gui/itemmodels/qstandarditemmodel_p.h b/src/gui/itemmodels/qstandarditemmodel_p.h
index caee3ea34c..bd28ec3029 100644
--- a/src/gui/itemmodels/qstandarditemmodel_p.h
+++ b/src/gui/itemmodels/qstandarditemmodel_p.h
@@ -200,7 +200,7 @@ public:
}
void sort(QStandardItem *parent, int column, Qt::SortOrder order);
- void itemChanged(QStandardItem *item);
+ void itemChanged(QStandardItem *item, const QVector<int> &roles = QVector<int>());
void rowsAboutToBeInserted(QStandardItem *parent, int start, int end);
void columnsAboutToBeInserted(QStandardItem *parent, int start, int end);
void rowsAboutToBeRemoved(QStandardItem *parent, int start, int end);