| 809 | } |
| 810 | |
| 811 | void BindingInspectorTest::testModelRemovalAtEnd() |
| 812 | { |
| 813 | MockObject obj1 { 53, true, 'x', 5.3, "Hello World" }; |
| 814 | |
| 815 | provider->data = { { |
| 816 | { &obj1, "a", &obj1, "b" }, |
| 817 | { &obj1, "a", &obj1, "c" }, |
| 818 | { &obj1, "a", &obj1, "d" }, |
| 819 | { &obj1, "d", &obj1, "e" }, |
| 820 | } }; |
| 821 | |
| 822 | bindingExtension->setQObject(&obj1); |
| 823 | QCOMPARE(bindingModel->rowCount(QModelIndex()), 2); |
| 824 | auto topLevelIndices = getSortedChildren(QModelIndex(), bindingModel); |
| 825 | QModelIndex obj1aIndex = topLevelIndices[0]; |
| 826 | QVERIFY(obj1aIndex.isValid()); |
| 827 | QCOMPARE(obj1aIndex.data().toString(), QStringLiteral("a")); |
| 828 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 53); |
| 829 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("2")); |
| 830 | QCOMPARE(bindingModel->rowCount(obj1aIndex), 3); |
| 831 | |
| 832 | QSignalSpy rowRemovedSpy(bindingModel, &QAbstractItemModel::rowsRemoved); |
| 833 | QSignalSpy dataChangedSpy(bindingModel, &QAbstractItemModel::dataChanged); |
| 834 | QVERIFY(rowRemovedSpy.isValid()); |
| 835 | QVERIFY(dataChangedSpy.isValid()); |
| 836 | |
| 837 | provider->data.erase(provider->data.end() - 3, provider->data.end()); |
| 838 | obj1.setA(12); |
| 839 | |
| 840 | rowRemovedSpy.wait(500); |
| 841 | QCOMPARE(rowRemovedSpy.size(), 1); |
| 842 | QCOMPARE(rowRemovedSpy.front().at(1).toInt(), 1); |
| 843 | QCOMPARE(rowRemovedSpy.front().at(2).toInt(), 2); |
| 844 | QCOMPARE(rowRemovedSpy.front().front().toModelIndex(), obj1aIndex); |
| 845 | |
| 846 | QCOMPARE(bindingModel->rowCount(obj1aIndex), 1); |
| 847 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("1")); |
| 848 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 12); |
| 849 | |
| 850 | QModelIndex obj1bIndex = bindingModel->index(0, 0, obj1aIndex); |
| 851 | QVERIFY(obj1bIndex.isValid()); |
| 852 | QCOMPARE(obj1bIndex.data().toString(), QStringLiteral("b")); |
| 853 | QCOMPARE(obj1bIndex.sibling(obj1bIndex.row(), BindingModel::ValueColumn).data().toBool(), true); |
| 854 | QCOMPARE(obj1bIndex.sibling(obj1bIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("0")); |
| 855 | QCOMPARE(bindingModel->rowCount(obj1bIndex), 0); |
| 856 | |
| 857 | QCOMPARE(dataChangedSpy.size(), 2); |
| 858 | QCOMPARE(dataChangedSpy.at(0).at(0).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn)); // Fair enough, we did change the value. |
| 859 | QCOMPARE(dataChangedSpy.at(0).at(1).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn)); |
| 860 | QCOMPARE(dataChangedSpy.at(1).at(0).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn)); // depth changed |
| 861 | QCOMPARE(dataChangedSpy.at(1).at(1).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn)); |
| 862 | } |
| 863 | |
| 864 | void BindingInspectorTest::testModelRemovalInside() |
| 865 | { |
nothing calls this directly
no test coverage detected