diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2022-04-03 09:02:38 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2022-04-06 02:59:02 +0200 |
commit | c6fecc628a60a3955c022f04020cdb515cc4fb6e (patch) | |
tree | 64debf2d425982dc37cf6b06e305e7707739fe97 /sc/qa/unit/SparklineTest.cxx | |
parent | ec18c7bf707e85d85f362d43454d35b1636de40f (diff) |
sc: add Group and Ungroup to context menu for sparklines
This change allows to group parklines together into a sparkline
group, or ungroup them, so they use their own sparkline group.
This also adds the undo and redo for this actions.
Change-Id: I61b604203afaf2fe8c2d47b80082739ded15d6fb
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132545
Tested-by: Tomaž Vajngerl <quikee@gmail.com>
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc/qa/unit/SparklineTest.cxx')
-rw-r--r-- | sc/qa/unit/SparklineTest.cxx | 239 |
1 files changed, 239 insertions, 0 deletions
diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx index aea9d45152e0..99efd55f8209 100644 --- a/sc/qa/unit/SparklineTest.cxx +++ b/sc/qa/unit/SparklineTest.cxx @@ -56,6 +56,8 @@ public: void testUndoRedoDeleteSparklineGroup(); void testUndoRedoClearContentForSparkline(); void testUndoRedoEditSparklineGroup(); + void testUndoRedoUngroupSparklines(); + void testUndoRedoGroupSparklines(); void testSparklineList(); CPPUNIT_TEST_SUITE(SparklineTest); @@ -68,6 +70,8 @@ public: CPPUNIT_TEST(testUndoRedoDeleteSparklineGroup); CPPUNIT_TEST(testUndoRedoClearContentForSparkline); CPPUNIT_TEST(testUndoRedoEditSparklineGroup); + CPPUNIT_TEST(testUndoRedoUngroupSparklines); + CPPUNIT_TEST(testUndoRedoGroupSparklines); CPPUNIT_TEST(testSparklineList); CPPUNIT_TEST_SUITE_END(); }; @@ -566,6 +570,241 @@ void SparklineTest::testUndoRedoEditSparklineGroup() xDocSh->DoClose(); } +void SparklineTest::testUndoRedoUngroupSparklines() +{ + ScDocShellRef xDocSh = loadEmptyDocument(); + CPPUNIT_ASSERT(xDocSh); + + ScDocument& rDocument = xDocSh->GetDocument(); + ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell); + + auto& rDocFunc = xDocSh->GetDocFunc(); + + // insert test data - A1:A6 + insertTestData(rDocument); + + // Sparkline range + ScRange aDataRange(0, 0, 0, 3, 5, 0); //A1:D6 + ScRange aRange(0, 6, 0, 3, 6, 0); // A7:D7 + + auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); + CPPUNIT_ASSERT(rDocFunc.InsertSparklines(aDataRange, aRange, pSparklineGroup)); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup3); + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup3, pGroup4); + } + + CPPUNIT_ASSERT(rDocFunc.UngroupSparklines(ScRange(2, 6, 0, 3, 6, 0))); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT(pGroup1 != pGroup3); + CPPUNIT_ASSERT(pGroup1 != pGroup4); + CPPUNIT_ASSERT(pGroup3 != pGroup4); + } + + // Undo + rDocument.GetUndoManager()->Undo(); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup3); + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup3, pGroup4); + } + + // Redo + rDocument.GetUndoManager()->Redo(); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT(pGroup1 != pGroup3); + CPPUNIT_ASSERT(pGroup1 != pGroup4); + CPPUNIT_ASSERT(pGroup3 != pGroup4); + } + + xDocSh->DoClose(); +} + +void SparklineTest::testUndoRedoGroupSparklines() +{ + ScDocShellRef xDocSh = loadEmptyDocument(); + CPPUNIT_ASSERT(xDocSh); + + ScDocument& rDocument = xDocSh->GetDocument(); + ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false); + CPPUNIT_ASSERT(pViewShell); + + auto& rDocFunc = xDocSh->GetDocFunc(); + + // insert test data - A1:A6 + insertTestData(rDocument); + + // Sparkline range + ScRange aDataRange(0, 0, 0, 3, 5, 0); //A1:D6 + ScRange aRange(0, 6, 0, 3, 6, 0); // A7:D7 + + auto pSparklineGroup = std::make_shared<sc::SparklineGroup>(); + CPPUNIT_ASSERT(rDocFunc.InsertSparklines(aDataRange, aRange, pSparklineGroup)); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup3); + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup3, pGroup4); + } + + CPPUNIT_ASSERT(rDocFunc.UngroupSparklines(ScRange(2, 6, 0, 3, 6, 0))); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT(pGroup1 != pGroup3); + CPPUNIT_ASSERT(pGroup1 != pGroup4); + CPPUNIT_ASSERT(pGroup3 != pGroup4); + } + + { + auto pGroup = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + CPPUNIT_ASSERT(rDocFunc.GroupSparklines(ScRange(1, 6, 0, 3, 6, 0), pGroup)); + } + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT(pGroup1 != pGroup2); + CPPUNIT_ASSERT(pGroup1 != pGroup3); + CPPUNIT_ASSERT(pGroup1 != pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup2, pGroup3); + CPPUNIT_ASSERT_EQUAL(pGroup2, pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup3, pGroup4); + } + + // Undo + rDocument.GetUndoManager()->Undo(); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT_EQUAL(pGroup1, pGroup2); + CPPUNIT_ASSERT(pGroup1 != pGroup3); + CPPUNIT_ASSERT(pGroup1 != pGroup4); + CPPUNIT_ASSERT(pGroup3 != pGroup4); + } + + // Redo + rDocument.GetUndoManager()->Redo(); + + // Check Sparklines + { + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(0, 6, 0))); // A7 + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(1, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(2, 6, 0))); + CPPUNIT_ASSERT_EQUAL(true, rDocument.HasSparkline(ScAddress(3, 6, 0))); // D7 + + auto pGroup1 = rDocument.GetSparkline(ScAddress(0, 6, 0))->getSparklineGroup(); + auto pGroup2 = rDocument.GetSparkline(ScAddress(1, 6, 0))->getSparklineGroup(); + auto pGroup3 = rDocument.GetSparkline(ScAddress(2, 6, 0))->getSparklineGroup(); + auto pGroup4 = rDocument.GetSparkline(ScAddress(3, 6, 0))->getSparklineGroup(); + + CPPUNIT_ASSERT(pGroup1 != pGroup2); + CPPUNIT_ASSERT(pGroup1 != pGroup3); + CPPUNIT_ASSERT(pGroup1 != pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup2, pGroup3); + CPPUNIT_ASSERT_EQUAL(pGroup2, pGroup4); + CPPUNIT_ASSERT_EQUAL(pGroup3, pGroup4); + } + + xDocSh->DoClose(); +} + void SparklineTest::testSparklineList() { ScDocShellRef xDocSh = loadEmptyDocument(); |