| 643 | } |
| 644 | |
| 645 | void BindingInspectorTest::testModelAdditions() |
| 646 | { |
| 647 | MockObject obj1 { 53, true, 'x', 5.3, "Hello World" }; |
| 648 | provider->data = { { { &obj1, "a", &obj1, "c" } } }; |
| 649 | |
| 650 | bindingExtension->setQObject(&obj1); |
| 651 | QCOMPARE(bindingModel->rowCount(QModelIndex()), 1); |
| 652 | QModelIndex obj1aIndex = bindingModel->index(0, 0, QModelIndex()); |
| 653 | QVERIFY(obj1aIndex.isValid()); |
| 654 | QCOMPARE(obj1aIndex.data().toString(), QStringLiteral("a")); |
| 655 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 53); |
| 656 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("1")); |
| 657 | QCOMPARE(bindingModel->rowCount(obj1aIndex), 1); |
| 658 | |
| 659 | QModelIndex obj1cIndex = bindingModel->index(0, 0, obj1aIndex); |
| 660 | QVERIFY(obj1cIndex.isValid()); |
| 661 | QCOMPARE(obj1cIndex.data().toString(), QStringLiteral("c")); |
| 662 | QCOMPARE(obj1cIndex.sibling(obj1cIndex.row(), BindingModel::ValueColumn).data().toChar(), QChar('x')); |
| 663 | QCOMPARE(obj1cIndex.sibling(obj1cIndex.row(), BindingModel::DepthColumn).data().toString(), QStringLiteral("0")); |
| 664 | QCOMPARE(bindingModel->rowCount(obj1cIndex), 0); |
| 665 | |
| 666 | QSignalSpy rowAddedSpy(bindingModel, &QAbstractItemModel::rowsInserted); |
| 667 | QSignalSpy dataChangedSpy(bindingModel, &QAbstractItemModel::dataChanged); |
| 668 | QVERIFY(rowAddedSpy.isValid()); |
| 669 | QVERIFY(dataChangedSpy.isValid()); |
| 670 | |
| 671 | provider->data.emplace_back(&obj1, "c", &obj1, "a"); |
| 672 | provider->data.emplace_back(&obj1, "c", &obj1, "b"); |
| 673 | provider->data.emplace_back(&obj1, "b", &obj1, "d"); |
| 674 | obj1.setA(12); |
| 675 | |
| 676 | rowAddedSpy.wait(500); |
| 677 | QCOMPARE(rowAddedSpy.size(), 1); |
| 678 | QCOMPARE(rowAddedSpy.front().at(1).toInt(), 0); |
| 679 | QCOMPARE(rowAddedSpy.front().at(2).toInt(), 1); |
| 680 | QCOMPARE(rowAddedSpy.front().front().toModelIndex(), obj1cIndex); |
| 681 | |
| 682 | QCOMPARE(dataChangedSpy.size(), 3); |
| 683 | QCOMPARE(dataChangedSpy.at(0).at(0).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn)); // Fair enough, we did change the value. |
| 684 | QCOMPARE(dataChangedSpy.at(0).at(1).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn)); |
| 685 | QCOMPARE(dataChangedSpy.at(1).at(0).toModelIndex(), obj1cIndex.sibling(obj1cIndex.row(), BindingModel::DepthColumn)); // depth changed |
| 686 | QCOMPARE(dataChangedSpy.at(1).at(1).toModelIndex(), obj1cIndex.sibling(obj1cIndex.row(), BindingModel::DepthColumn)); |
| 687 | QCOMPARE(dataChangedSpy.at(2).at(0).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn)); // depth changed |
| 688 | QCOMPARE(dataChangedSpy.at(2).at(1).toModelIndex(), obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn)); |
| 689 | |
| 690 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 12); |
| 691 | QCOMPARE(obj1aIndex.sibling(obj1aIndex.row(), BindingModel::DepthColumn).data().toString(), QString(QChar(0x221e))); |
| 692 | |
| 693 | QCOMPARE(obj1cIndex.sibling(obj1cIndex.row(), BindingModel::DepthColumn).data().toString(), QString(QChar(0x221e))); |
| 694 | QCOMPARE(bindingModel->rowCount(obj1cIndex), 2); |
| 695 | |
| 696 | auto obj1cChildren = getSortedChildren(obj1cIndex); |
| 697 | QModelIndex node1aIndex = obj1cChildren[0]; |
| 698 | QVERIFY(node1aIndex.isValid()); |
| 699 | QCOMPARE(node1aIndex.data().toString(), QStringLiteral("a")); |
| 700 | QCOMPARE(node1aIndex.sibling(node1aIndex.row(), BindingModel::ValueColumn).data().toInt(), 12); |
| 701 | QCOMPARE(node1aIndex.sibling(node1aIndex.row(), BindingModel::DepthColumn).data().toString(), QString(QChar(0x221e))); |
| 702 | QCOMPARE(bindingModel->rowCount(node1aIndex), 0); |
nothing calls this directly
no test coverage detected