! * \brief testInsertRowsSuppressUpdate * It shall not crash * Testing if in the model begin and end are used properly */
| 2570 | * Testing if in the model begin and end are used properly |
| 2571 | */ |
| 2572 | void SpreadsheetTest::testInsertRowsSuppressUpdate() { |
| 2573 | Project project; |
| 2574 | auto* sheet = new Spreadsheet(QStringLiteral("test"), false); |
| 2575 | project.addChild(sheet); |
| 2576 | |
| 2577 | auto* model = new SpreadsheetModel(sheet); |
| 2578 | |
| 2579 | int rowsAboutToBeInsertedCounter = 0; |
| 2580 | connect(model, &SpreadsheetModel::rowsAboutToBeInserted, [&rowsAboutToBeInsertedCounter]() { |
| 2581 | rowsAboutToBeInsertedCounter++; |
| 2582 | }); |
| 2583 | int rowsInsertedCounter = 0; |
| 2584 | connect(model, &SpreadsheetModel::rowsInserted, [&rowsInsertedCounter]() { |
| 2585 | rowsInsertedCounter++; |
| 2586 | }); |
| 2587 | int rowsAboutToBeRemovedCounter = 0; |
| 2588 | connect(model, &SpreadsheetModel::rowsAboutToBeRemoved, [&rowsAboutToBeRemovedCounter]() { |
| 2589 | rowsAboutToBeRemovedCounter++; |
| 2590 | }); |
| 2591 | int rowsRemovedCounter = 0; |
| 2592 | connect(model, &SpreadsheetModel::rowsRemoved, [&rowsRemovedCounter]() { |
| 2593 | rowsRemovedCounter++; |
| 2594 | }); |
| 2595 | |
| 2596 | int modelResetCounter = 0; |
| 2597 | connect(model, &SpreadsheetModel::modelReset, [&modelResetCounter]() { |
| 2598 | modelResetCounter++; |
| 2599 | }); |
| 2600 | int modelAboutToResetCounter = 0; |
| 2601 | connect(model, &SpreadsheetModel::modelAboutToBeReset, [&modelAboutToResetCounter]() { |
| 2602 | modelAboutToResetCounter++; |
| 2603 | }); |
| 2604 | |
| 2605 | model->suppressSignals(true); |
| 2606 | |
| 2607 | QCOMPARE(sheet->rowCount(), 100); |
| 2608 | sheet->setRowCount(101); // No crash shall happen |
| 2609 | QCOMPARE(sheet->rowCount(), 101); |
| 2610 | |
| 2611 | sheet->undoStack()->undo(); |
| 2612 | QCOMPARE(sheet->rowCount(), 100); |
| 2613 | sheet->undoStack()->redo(); |
| 2614 | QCOMPARE(sheet->rowCount(), 101); |
| 2615 | |
| 2616 | model->suppressSignals(false); |
| 2617 | |
| 2618 | QCOMPARE(rowsAboutToBeInsertedCounter, 0); |
| 2619 | QCOMPARE(rowsInsertedCounter, 0); |
| 2620 | QCOMPARE(rowsAboutToBeRemovedCounter, 0); |
| 2621 | QCOMPARE(rowsRemovedCounter, 0); |
| 2622 | QCOMPARE(modelResetCounter, 1); |
| 2623 | QCOMPARE(modelAboutToResetCounter, 1); |
| 2624 | } |
| 2625 | |
| 2626 | /*! |
| 2627 | * \brief testInsertColumnsSuppressUpdate |
nothing calls this directly
no test coverage detected