summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSamuel Gaist <samuel.gaist@edeltech.ch>2017-10-05 16:20:36 +0200
committerSamuel Gaist <samuel.gaist@edeltech.ch>2017-10-17 12:28:23 +0000
commit1382374deaa4a854aeb542e6c8f7e1841f2abb10 (patch)
tree872b27c6d22475e70cec47d75f52ce44fe19a60c /tests
parentd0a0a3c0418a0fdd2ed84b2a5f7e6565537715c6 (diff)
Correct QStandardItemModel::setItemData to follow QAbstractItemModel
QStandardItemModel::setItemData replaces the content of an item data with the new values rather than updating/inserting which is the behavior for QAbstractItemModel. This patch aims to unify the behavior. [ChangeLog][QtWidgets][QStandardItemModel] Fixed setItemData() incorrectly deleting unmodified data. That behavior is not following QAbstractItemModel's documented behavior which is no modification of data not provided in parameter. Task-number: QTBUG-45114 Task-number: QTBUG-10872 Change-Id: I2be40cee372b68d9f71c976548ecda6dc3011241 Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp
index 2f5537adfe..a07f45ef1d 100644
--- a/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp
+++ b/tests/auto/gui/itemmodels/qstandarditemmodel/tst_qstandarditemmodel.cpp
@@ -130,6 +130,8 @@ private slots:
void getMimeDataWithInvalidModelIndex();
void supportedDragDropActions();
+ void taskQTBUG_45114_setItemData();
+
private:
QAbstractItemModel *m_model;
QPersistentModelIndex persistent;
@@ -1701,5 +1703,65 @@ void tst_QStandardItemModel::supportedDragDropActions()
QCOMPARE(model.supportedDropActions(), Qt::CopyAction | Qt::MoveAction);
}
+void tst_QStandardItemModel::taskQTBUG_45114_setItemData()
+{
+ QStandardItemModel model;
+ QSignalSpy spy(&model, &QStandardItemModel::itemChanged);
+
+ QStandardItem *item = new QStandardItem("item");
+ item->setData(1, Qt::UserRole + 1);
+ item->setData(2, Qt::UserRole + 2);
+ model.appendRow(item);
+
+ QModelIndex index = item->index();
+ QCOMPARE(model.itemData(index).size(), 3);
+
+ QCOMPARE(spy.count(), 0);
+
+ QMap<int, QVariant> roles;
+
+ roles.insert(Qt::UserRole + 1, 1);
+ roles.insert(Qt::UserRole + 2, 2);
+ model.setItemData(index, roles);
+
+ QCOMPARE(spy.count(), 0);
+
+ roles.insert(Qt::UserRole + 1, 1);
+ roles.insert(Qt::UserRole + 2, 2);
+ roles.insert(Qt::UserRole + 3, QVariant());
+ model.setItemData(index, roles);
+
+ QCOMPARE(spy.count(), 0);
+
+ roles.clear();
+ roles.insert(Qt::UserRole + 1, 10);
+ roles.insert(Qt::UserRole + 3, 12);
+ model.setItemData(index, roles);
+
+ QCOMPARE(spy.count(), 1);
+ QMap<int, QVariant> itemRoles = model.itemData(index);
+
+ QCOMPARE(itemRoles.size(), 4);
+ QCOMPARE(itemRoles[Qt::UserRole + 1].toInt(), 10);
+ QCOMPARE(itemRoles[Qt::UserRole + 2].toInt(), 2);
+ QCOMPARE(itemRoles[Qt::UserRole + 3].toInt(), 12);
+
+ roles.clear();
+ roles.insert(Qt::UserRole + 3, 1);
+ model.setItemData(index, roles);
+
+ QCOMPARE(spy.count(), 2);
+
+ roles.clear();
+ roles.insert(Qt::UserRole + 3, QVariant());
+ model.setItemData(index, roles);
+
+ QCOMPARE(spy.count(), 3);
+
+ itemRoles = model.itemData(index);
+ QCOMPARE(itemRoles.size(), 3);
+ QVERIFY(!itemRoles.keys().contains(Qt::UserRole + 3));
+}
+
QTEST_MAIN(tst_QStandardItemModel)
#include "tst_qstandarditemmodel.moc"