diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk index 781867914f7b..ff5964e6c54e 100644 --- a/sc/Library_sc.mk +++ b/sc/Library_sc.mk @@ -536,16 +536,22 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/operation/ApplyAttributesOperation \ sc/source/ui/operation/AutoFormatOperation \ sc/source/ui/operation/ChangeIndentOperation \ + sc/source/ui/operation/ChangeSparklineGroupAttributesOperation \ + sc/source/ui/operation/ChangeSparklineOperation \ sc/source/ui/operation/ClearItemsOperation \ sc/source/ui/operation/ConvertFormulaToValueOperation \ sc/source/ui/operation/DeleteCellOperation \ sc/source/ui/operation/DeleteContentOperation \ + sc/source/ui/operation/DeleteSparklineGroupOperation \ + sc/source/ui/operation/DeleteSparklineOperation \ sc/source/ui/operation/EnterMatrixOperation \ sc/source/ui/operation/FillAutoOperation \ sc/source/ui/operation/FillSeriesOperation \ sc/source/ui/operation/FillSimpleOperation \ + sc/source/ui/operation/GroupSparklinesOperation \ sc/source/ui/operation/InsertCellsOperation \ sc/source/ui/operation/InsertSheetViewOperation \ + sc/source/ui/operation/InsertSparklinesOperation \ sc/source/ui/operation/MultipleOpsOperation \ sc/source/ui/operation/Operation \ sc/source/ui/operation/OperationType \ @@ -558,6 +564,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\ sc/source/ui/operation/SetValueOperation \ sc/source/ui/operation/SortOperation \ sc/source/ui/operation/TransliterateTextOperation \ + sc/source/ui/operation/UngroupSparklinesOperation \ sc/source/ui/pagedlg/areasdlg \ sc/source/ui/pagedlg/tphfedit \ sc/source/ui/sidebar/AlignmentPropertyPanel \ diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 96a948632e8b..8ac886a9df08 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -100,20 +100,14 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include #include #include #include #include #include +#include +#include #include #include #include @@ -123,17 +117,22 @@ #include #include #include +#include +#include #include #include #include #include #include #include +#include #include #include +#include #include #include #include +#include #include #include #include @@ -3931,181 +3930,45 @@ void ScDocFunc::EndListAction() bool ScDocFunc::InsertSparklines(ScRange const& rDataRange, ScRange const& rSparklineRange, const std::shared_ptr& pSparklineGroup) { - if (!CheckSheetViewProtection(sc::OperationType::SparklineInsert)) - return false; - - std::vector aSparklineDataVector; - - if (rSparklineRange.aStart.Col() == rSparklineRange.aEnd.Col()) - { - sal_Int32 nOutputRowSize = rSparklineRange.aEnd.Row() - rSparklineRange.aStart.Row(); - - auto eInputOrientation = sc::calculateOrientation(nOutputRowSize, rDataRange); - - if (eInputOrientation == sc::RangeOrientation::Unknown) - return false; - - sal_Int32 nIndex = 0; - - for (ScAddress aAddress = rSparklineRange.aStart; aAddress.Row() <= rSparklineRange.aEnd.Row(); - aAddress.IncRow()) - { - ScRange aInputRangeSlice = rDataRange; - if (eInputOrientation == sc::RangeOrientation::Row) - { - aInputRangeSlice.aStart.SetRow(rDataRange.aStart.Row() + nIndex); - aInputRangeSlice.aEnd.SetRow(rDataRange.aStart.Row() + nIndex); - } - else - { - aInputRangeSlice.aStart.SetCol(rDataRange.aStart.Col() + nIndex); - aInputRangeSlice.aEnd.SetCol(rDataRange.aStart.Col() + nIndex); - } - - aSparklineDataVector.emplace_back(aAddress, aInputRangeSlice); - - nIndex++; - } - } - else if (rSparklineRange.aStart.Row() == rSparklineRange.aEnd.Row()) - { - sal_Int32 nOutputColSize = rSparklineRange.aEnd.Col() - rSparklineRange.aStart.Col(); - - auto eInputOrientation = sc::calculateOrientation(nOutputColSize, rDataRange); - - if (eInputOrientation == sc::RangeOrientation::Unknown) - return false; - - sal_Int32 nIndex = 0; - - for (ScAddress aAddress = rSparklineRange.aStart; aAddress.Col() <= rSparklineRange.aEnd.Col(); - aAddress.IncCol()) - { - ScRange aInputRangeSlice = rDataRange; - if (eInputOrientation == sc::RangeOrientation::Row) - { - aInputRangeSlice.aStart.SetRow(rDataRange.aStart.Row() + nIndex); - aInputRangeSlice.aEnd.SetRow(rDataRange.aStart.Row() + nIndex); - } - else - { - aInputRangeSlice.aStart.SetCol(rDataRange.aStart.Col() + nIndex); - aInputRangeSlice.aEnd.SetCol(rDataRange.aStart.Col() + nIndex); - } - - aSparklineDataVector.emplace_back(aAddress, aInputRangeSlice); - - nIndex++; - } - } - - if (aSparklineDataVector.empty()) - return false; - - auto pUndoInsertSparkline = std::make_unique(rDocShell, aSparklineDataVector, pSparklineGroup); - // insert the sparkline by "redoing" - pUndoInsertSparkline->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndoInsertSparkline)); - - ScDocument& rDoc = rDocShell.GetDocument(); - if (rSparklineRange.aStart == rSparklineRange.aEnd - && rDoc.HasAttrib(rSparklineRange, HasAttrFlags::Merged)) - { - ScRange aExtendMergeRange(rSparklineRange); - rDoc.ExtendMerge(aExtendMergeRange); - rDocShell.PostPaint(aExtendMergeRange, PaintPartFlags::Grid); - } - - return true; + sc::InsertSparklinesOperation aOperation(rDocShell, rDataRange, rSparklineRange, pSparklineGroup); + return aOperation.run(); } bool ScDocFunc::DeleteSparkline(ScAddress const& rAddress) { - auto& rDocument = rDocShell.GetDocument(); - - if (!rDocument.HasSparkline(rAddress)) - return false; - - if (!CheckSheetViewProtection(sc::OperationType::SparklineDelete)) - return false; - - - auto pUndoDeleteSparkline = std::make_unique(rDocShell, rAddress); - // delete sparkline by "redoing" - pUndoDeleteSparkline->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndoDeleteSparkline)); - - return true; + sc::DeleteSparklineOperation aOperation(rDocShell, rAddress); + return aOperation.run(); } bool ScDocFunc::DeleteSparklineGroup(std::shared_ptr const& pSparklineGroup, SCTAB nTab) { - if (!pSparklineGroup) - return false; - - auto& rDocument = rDocShell.GetDocument(); - - if (!rDocument.HasTable(nTab)) - return false; - - if (!CheckSheetViewProtection(sc::OperationType::SparklineGroupDelete)) - return false; - - auto pUndo = std::make_unique(rDocShell, pSparklineGroup, nTab); - // delete sparkline group by "redoing" - pUndo->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); - return true; + sc::DeleteSparklineGroupOperation aOperation(rDocShell, pSparklineGroup, nTab); + return aOperation.run(); } bool ScDocFunc::ChangeSparklineGroupAttributes(std::shared_ptr const& pExistingSparklineGroup, sc::SparklineAttributes const& rNewAttributes) { - if (!CheckSheetViewProtection(sc::OperationType::SparklineGroupChange)) - return false; - - - auto pUndo = std::make_unique(rDocShell, pExistingSparklineGroup, rNewAttributes); - // change sparkline group attributes by "redoing" - pUndo->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); - return true; + sc::ChangeSparklineGroupAttributesOperation aOperation(rDocShell, pExistingSparklineGroup, rNewAttributes); + return aOperation.run(); } bool ScDocFunc::GroupSparklines(ScRange const& rRange, std::shared_ptr const& rpGroup) { - if (!CheckSheetViewProtection(sc::OperationType::SparklineGroup)) - return false; - - auto pUndo = std::make_unique(rDocShell, rRange, rpGroup); - // group sparklines by "redoing" - pUndo->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); - return true; + sc::GroupSparklinesOperation aOperation(rDocShell, rRange, rpGroup); + return aOperation.run(); } bool ScDocFunc::UngroupSparklines(ScRange const& rRange) { - if (!CheckSheetViewProtection(sc::OperationType::SparklineUngroup)) - return false; - - auto pUndo = std::make_unique(rDocShell, rRange); - // ungroup sparklines by "redoing" - pUndo->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); - return true; + sc::UngroupSparklinesOperation aOperation(rDocShell, rRange); + return aOperation.run(); } bool ScDocFunc::ChangeSparkline(std::shared_ptr const& rpSparkline, SCTAB nTab, ScRangeList const& rDataRange) { - if (!CheckSheetViewProtection(sc::OperationType::SparklineChange)) - return false; - - auto pUndo = std::make_unique(rDocShell, rpSparkline, nTab, rDataRange); - // change sparkline by "redoing" - pUndo->Redo(); - rDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); - return true; + sc::ChangeSparklineOperation aOperation(rDocShell, rpSparkline, nTab, rDataRange); + return aOperation.run(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/ChangeSparklineGroupAttributesOperation.hxx b/sc/source/ui/inc/operation/ChangeSparklineGroupAttributesOperation.hxx new file mode 100644 index 000000000000..cff876705a77 --- /dev/null +++ b/sc/source/ui/inc/operation/ChangeSparklineGroupAttributesOperation.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include +#include + +class ScDocShell; + +namespace sc +{ +class SparklineGroup; + +/** Changes the sparkline's group attributes to the input one. */ +class ChangeSparklineGroupAttributesOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + std::shared_ptr mpExistingSparklineGroup; + SparklineAttributes maNewAttributes; + + bool runImplementation() override; + +public: + ChangeSparklineGroupAttributesOperation( + ScDocShell& rDocShell, std::shared_ptr const& pExistingSparklineGroup, + SparklineAttributes const& rNewAttributes); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/ChangeSparklineOperation.hxx b/sc/source/ui/inc/operation/ChangeSparklineOperation.hxx new file mode 100644 index 000000000000..460eae9587a3 --- /dev/null +++ b/sc/source/ui/inc/operation/ChangeSparklineOperation.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include +#include +#include + +class ScDocShell; + +namespace sc +{ +class Sparkline; + +/** Changes the sparkline's input data range. */ +class ChangeSparklineOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + std::shared_ptr mpSparkline; + SCTAB mnTab; + ScRangeList maDataRange; + + bool runImplementation() override; + +public: + ChangeSparklineOperation(ScDocShell& rDocShell, std::shared_ptr const& rpSparkline, + SCTAB nTab, ScRangeList const& rDataRange); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/DeleteSparklineGroupOperation.hxx b/sc/source/ui/inc/operation/DeleteSparklineGroupOperation.hxx new file mode 100644 index 000000000000..066261f1600b --- /dev/null +++ b/sc/source/ui/inc/operation/DeleteSparklineGroupOperation.hxx @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include +#include + +class ScDocShell; + +namespace sc +{ +class SparklineGroup; + +/** Deletes the whole sparkline group. */ +class DeleteSparklineGroupOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + std::shared_ptr mpSparklineGroup; + SCTAB mnTab; + + bool runImplementation() override; + +public: + DeleteSparklineGroupOperation(ScDocShell& rDocShell, + std::shared_ptr const& pSparklineGroup, + SCTAB nTab); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/DeleteSparklineOperation.hxx b/sc/source/ui/inc/operation/DeleteSparklineOperation.hxx new file mode 100644 index 000000000000..52135958ba3b --- /dev/null +++ b/sc/source/ui/inc/operation/DeleteSparklineOperation.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include + +class ScDocShell; + +namespace sc +{ +/** Deletes one sparkline */ +class DeleteSparklineOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + ScAddress maAddress; + + bool runImplementation() override; + +public: + DeleteSparklineOperation(ScDocShell& rDocShell, ScAddress const& rAddress); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/GroupSparklinesOperation.hxx b/sc/source/ui/inc/operation/GroupSparklinesOperation.hxx new file mode 100644 index 000000000000..505f300c9d72 --- /dev/null +++ b/sc/source/ui/inc/operation/GroupSparklinesOperation.hxx @@ -0,0 +1,38 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include +#include + +class ScDocShell; + +namespace sc +{ +class SparklineGroup; + +/** Groups the sparklines in the input range together. */ +class GroupSparklinesOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + ScRange maRange; + std::shared_ptr mpGroup; + + bool runImplementation() override; + +public: + GroupSparklinesOperation(ScDocShell& rDocShell, ScRange const& rRange, + std::shared_ptr const& rpGroup); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/InsertSparklinesOperation.hxx b/sc/source/ui/inc/operation/InsertSparklinesOperation.hxx new file mode 100644 index 000000000000..0e897d2f7a43 --- /dev/null +++ b/sc/source/ui/inc/operation/InsertSparklinesOperation.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include +#include + +class ScDocShell; + +namespace sc +{ +class SparklineGroup; + +/** Inserts new sparklines at the input range, and add them into the input group. */ +class InsertSparklinesOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + ScRange maDataRange; + ScRange maSparklineRange; + std::shared_ptr mpSparklineGroup; + + bool runImplementation() override; + +public: + InsertSparklinesOperation(ScDocShell& rDocShell, ScRange const& rDataRange, + ScRange const& rSparklineRange, + std::shared_ptr const& pSparklineGroup); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/inc/operation/UngroupSparklinesOperation.hxx b/sc/source/ui/inc/operation/UngroupSparklinesOperation.hxx new file mode 100644 index 000000000000..f0fd93c0a1a0 --- /dev/null +++ b/sc/source/ui/inc/operation/UngroupSparklinesOperation.hxx @@ -0,0 +1,33 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include "Operation.hxx" +#include + +class ScDocShell; + +namespace sc +{ +/** Ungroup all the sparklines in the input range and create a new group for each sparkline. */ +class UngroupSparklinesOperation : public Operation +{ +private: + ScDocShell& mrDocShell; + ScRange maRange; + + bool runImplementation() override; + +public: + UngroupSparklinesOperation(ScDocShell& rDocShell, ScRange const& rRange); +}; +} // end sc namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/ChangeSparklineGroupAttributesOperation.cxx b/sc/source/ui/operation/ChangeSparklineGroupAttributesOperation.cxx new file mode 100644 index 000000000000..820d2da3a7ce --- /dev/null +++ b/sc/source/ui/operation/ChangeSparklineGroupAttributesOperation.cxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +namespace sc +{ +ChangeSparklineGroupAttributesOperation::ChangeSparklineGroupAttributesOperation( + ScDocShell& rDocShell, std::shared_ptr const& pExistingSparklineGroup, + SparklineAttributes const& rNewAttributes) + : Operation(OperationType::SparklineGroupChange, false, false) + , mrDocShell(rDocShell) + , mpExistingSparklineGroup(pExistingSparklineGroup) + , maNewAttributes(rNewAttributes) +{ +} + +bool ChangeSparklineGroupAttributesOperation::runImplementation() +{ + if (!checkSheetViewProtection()) + return false; + + auto pUndo = std::make_unique(mrDocShell, mpExistingSparklineGroup, + maNewAttributes); + // change sparkline group attributes by "redoing" + pUndo->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/ChangeSparklineOperation.cxx b/sc/source/ui/operation/ChangeSparklineOperation.cxx new file mode 100644 index 000000000000..d3370560bcd3 --- /dev/null +++ b/sc/source/ui/operation/ChangeSparklineOperation.cxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +namespace sc +{ +ChangeSparklineOperation::ChangeSparklineOperation(ScDocShell& rDocShell, + std::shared_ptr const& rpSparkline, + SCTAB nTab, ScRangeList const& rDataRange) + : Operation(OperationType::SparklineChange, false, false) + , mrDocShell(rDocShell) + , mpSparkline(rpSparkline) + , mnTab(nTab) + , maDataRange(rDataRange) +{ +} + +bool ChangeSparklineOperation::runImplementation() +{ + if (!checkSheetViewProtection()) + return false; + + auto pUndo = std::make_unique(mrDocShell, mpSparkline, mnTab, maDataRange); + // change sparkline by "redoing" + pUndo->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/DeleteSparklineGroupOperation.cxx b/sc/source/ui/operation/DeleteSparklineGroupOperation.cxx new file mode 100644 index 000000000000..f1f22eb96532 --- /dev/null +++ b/sc/source/ui/operation/DeleteSparklineGroupOperation.cxx @@ -0,0 +1,48 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +namespace sc +{ +DeleteSparklineGroupOperation::DeleteSparklineGroupOperation( + ScDocShell& rDocShell, std::shared_ptr const& pSparklineGroup, SCTAB nTab) + : Operation(OperationType::SparklineGroupDelete, false, false) + , mrDocShell(rDocShell) + , mpSparklineGroup(pSparklineGroup) + , mnTab(nTab) +{ +} + +bool DeleteSparklineGroupOperation::runImplementation() +{ + if (!mpSparklineGroup) + return false; + + auto& rDocument = mrDocShell.GetDocument(); + + if (!rDocument.HasTable(mnTab)) + return false; + + if (!checkSheetViewProtection()) + return false; + + auto pUndo = std::make_unique(mrDocShell, mpSparklineGroup, mnTab); + // delete sparkline group by "redoing" + pUndo->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/DeleteSparklineOperation.cxx b/sc/source/ui/operation/DeleteSparklineOperation.cxx new file mode 100644 index 000000000000..06e7d5f497cd --- /dev/null +++ b/sc/source/ui/operation/DeleteSparklineOperation.cxx @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include + +namespace sc +{ +DeleteSparklineOperation::DeleteSparklineOperation(ScDocShell& rDocShell, ScAddress const& rAddress) + : Operation(OperationType::SparklineDelete, false, false) + , mrDocShell(rDocShell) + , maAddress(rAddress) +{ +} + +bool DeleteSparklineOperation::runImplementation() +{ + auto& rDocument = mrDocShell.GetDocument(); + + if (!rDocument.HasSparkline(maAddress)) + return false; + + if (!checkSheetViewProtection()) + return false; + + auto pUndoDeleteSparkline = std::make_unique(mrDocShell, maAddress); + // delete sparkline by "redoing" + pUndoDeleteSparkline->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndoDeleteSparkline)); + + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/GroupSparklinesOperation.cxx b/sc/source/ui/operation/GroupSparklinesOperation.cxx new file mode 100644 index 000000000000..18ce31d7cf5c --- /dev/null +++ b/sc/source/ui/operation/GroupSparklinesOperation.cxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include + +namespace sc +{ +GroupSparklinesOperation::GroupSparklinesOperation(ScDocShell& rDocShell, ScRange const& rRange, + std::shared_ptr const& rpGroup) + : Operation(OperationType::SparklineGroup, false, false) + , mrDocShell(rDocShell) + , maRange(rRange) + , mpGroup(rpGroup) +{ +} + +bool GroupSparklinesOperation::runImplementation() +{ + if (!checkSheetViewProtection()) + return false; + + auto pUndo = std::make_unique(mrDocShell, maRange, mpGroup); + // group sparklines by "redoing" + pUndo->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/InsertSparklinesOperation.cxx b/sc/source/ui/operation/InsertSparklinesOperation.cxx new file mode 100644 index 000000000000..ed667aa8b015 --- /dev/null +++ b/sc/source/ui/operation/InsertSparklinesOperation.cxx @@ -0,0 +1,113 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include +#include +#include + +namespace sc +{ +InsertSparklinesOperation::InsertSparklinesOperation( + ScDocShell& rDocShell, ScRange const& rDataRange, ScRange const& rSparklineRange, + std::shared_ptr const& pSparklineGroup) + : Operation(OperationType::SparklineInsert, false, false) + , mrDocShell(rDocShell) + , maDataRange(rDataRange) + , maSparklineRange(rSparklineRange) + , mpSparklineGroup(pSparklineGroup) +{ +} + +bool InsertSparklinesOperation::runImplementation() +{ + if (!checkSheetViewProtection()) + return false; + + std::vector aSparklineDataVector; + + if (maSparklineRange.aStart.Col() == maSparklineRange.aEnd.Col()) + { + sal_Int32 nOutputRowSize = maSparklineRange.aEnd.Row() - maSparklineRange.aStart.Row(); + + auto eInputOrientation = calculateOrientation(nOutputRowSize, maDataRange); + + if (eInputOrientation == RangeOrientation::Unknown) + return false; + + sal_Int32 nIndex = 0; + + for (ScAddress aAddress = maSparklineRange.aStart; + aAddress.Row() <= maSparklineRange.aEnd.Row(); aAddress.IncRow()) + { + ScRange aInputRangeSlice = maDataRange; + if (eInputOrientation == RangeOrientation::Row) + { + aInputRangeSlice.aStart.SetRow(maDataRange.aStart.Row() + nIndex); + aInputRangeSlice.aEnd.SetRow(maDataRange.aStart.Row() + nIndex); + } + else + { + aInputRangeSlice.aStart.SetCol(maDataRange.aStart.Col() + nIndex); + aInputRangeSlice.aEnd.SetCol(maDataRange.aStart.Col() + nIndex); + } + + aSparklineDataVector.emplace_back(aAddress, aInputRangeSlice); + + nIndex++; + } + } + else if (maSparklineRange.aStart.Row() == maSparklineRange.aEnd.Row()) + { + sal_Int32 nOutputColSize = maSparklineRange.aEnd.Col() - maSparklineRange.aStart.Col(); + + auto eInputOrientation = calculateOrientation(nOutputColSize, maDataRange); + + if (eInputOrientation == RangeOrientation::Unknown) + return false; + + sal_Int32 nIndex = 0; + + for (ScAddress aAddress = maSparklineRange.aStart; + aAddress.Col() <= maSparklineRange.aEnd.Col(); aAddress.IncCol()) + { + ScRange aInputRangeSlice = maDataRange; + if (eInputOrientation == RangeOrientation::Row) + { + aInputRangeSlice.aStart.SetRow(maDataRange.aStart.Row() + nIndex); + aInputRangeSlice.aEnd.SetRow(maDataRange.aStart.Row() + nIndex); + } + else + { + aInputRangeSlice.aStart.SetCol(maDataRange.aStart.Col() + nIndex); + aInputRangeSlice.aEnd.SetCol(maDataRange.aStart.Col() + nIndex); + } + + aSparklineDataVector.emplace_back(aAddress, aInputRangeSlice); + + nIndex++; + } + } + + if (aSparklineDataVector.empty()) + return false; + + auto pUndoInsertSparkline + = std::make_unique(mrDocShell, aSparklineDataVector, mpSparklineGroup); + // insert the sparkline by "redoing" + pUndoInsertSparkline->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndoInsertSparkline)); + + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/ui/operation/UngroupSparklinesOperation.cxx b/sc/source/ui/operation/UngroupSparklinesOperation.cxx new file mode 100644 index 000000000000..543621ff22c2 --- /dev/null +++ b/sc/source/ui/operation/UngroupSparklinesOperation.cxx @@ -0,0 +1,37 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +#include +#include + +namespace sc +{ +UngroupSparklinesOperation::UngroupSparklinesOperation(ScDocShell& rDocShell, ScRange const& rRange) + : Operation(OperationType::SparklineUngroup, false, false) + , mrDocShell(rDocShell) + , maRange(rRange) +{ +} + +bool UngroupSparklinesOperation::runImplementation() +{ + if (!checkSheetViewProtection()) + return false; + + auto pUndo = std::make_unique(mrDocShell, maRange); + // ungroup sparklines by "redoing" + pUndo->Redo(); + mrDocShell.GetUndoManager()->AddUndoAction(std::move(pUndo)); + return true; +} +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */