summaryrefslogtreecommitdiff
path: root/sc/source/ui/sparklines
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-04-03 15:53:55 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-04-07 10:35:59 +0200
commit93d7fbf73f8be7f09dd36e86f0dd06dfc8daa65c (patch)
tree99bb7585c6603b2b15d629a452395adbd7e73bba /sc/source/ui/sparklines
parentff2f433cdfda74dbf69a11342a98ccbfb5bc6a72 (diff)
sc: improve keeping track of sparklines in SparklineList
Issues can happen when saving a document with sparklines where a sparkline is deleted and then undo-ed. The reason for this is because the SparlineList wasn't correctly updated when deleting, copying or adding sparklines. This change adds hooks when new sparklines are created or when sparklines are deleted to report this into SparlineList. SparklineList garbage-collects itself but this is not enough when we rely that the non-deleted weak pointers to the sparkline groups contain the correct non-deleted weak pointers to the correct sparklines. Change-Id: I976cbe7e6168813d3dd5089c036cc7fe4e357fb2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132554 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc/source/ui/sparklines')
-rw-r--r--sc/source/ui/sparklines/SparklineList.cxx24
1 files changed, 24 insertions, 0 deletions
diff --git a/sc/source/ui/sparklines/SparklineList.cxx b/sc/source/ui/sparklines/SparklineList.cxx
index 7ee52ac74e27..1cae3089616d 100644
--- a/sc/source/ui/sparklines/SparklineList.cxx
+++ b/sc/source/ui/sparklines/SparklineList.cxx
@@ -25,6 +25,30 @@ void SparklineList::addSparkline(std::shared_ptr<Sparkline> const& pSparkline)
m_aSparklineGroups.push_back(pWeakGroup);
}
+void SparklineList::removeSparkline(std::shared_ptr<Sparkline> const& pSparkline)
+{
+ auto pWeakGroup = std::weak_ptr<SparklineGroup>(pSparkline->getSparklineGroup());
+ auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup);
+ if (iteratorGroup != m_aSparklineGroupMap.end())
+ {
+ auto& rWeakSparklines = iteratorGroup->second;
+
+ for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();)
+ {
+ auto pCurrentSparkline = iterator->lock();
+
+ if (pCurrentSparkline && pCurrentSparkline != pSparkline)
+ {
+ iterator++;
+ }
+ else
+ {
+ iterator = rWeakSparklines.erase(iterator);
+ }
+ }
+ }
+}
+
std::vector<std::shared_ptr<SparklineGroup>> SparklineList::getSparklineGroups()
{
std::vector<std::shared_ptr<SparklineGroup>> toReturn;