summaryrefslogtreecommitdiffstats
path: root/sc/source/ui/sparklines/SparklineList.cxx
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /sc/source/ui/sparklines/SparklineList.cxx
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'sc/source/ui/sparklines/SparklineList.cxx')
-rw-r--r--sc/source/ui/sparklines/SparklineList.cxx103
1 files changed, 103 insertions, 0 deletions
diff --git a/sc/source/ui/sparklines/SparklineList.cxx b/sc/source/ui/sparklines/SparklineList.cxx
new file mode 100644
index 000000000..1cae30896
--- /dev/null
+++ b/sc/source/ui/sparklines/SparklineList.cxx
@@ -0,0 +1,103 @@
+/* -*- 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 <SparklineList.hxx>
+
+namespace sc
+{
+SparklineList::SparklineList() = default;
+
+void SparklineList::addSparkline(std::shared_ptr<Sparkline> const& pSparkline)
+{
+ auto pWeakGroup = std::weak_ptr<SparklineGroup>(pSparkline->getSparklineGroup());
+
+ auto[iterator, bInserted]
+ = m_aSparklineGroupMap.try_emplace(pWeakGroup, std::vector<std::weak_ptr<Sparkline>>());
+ iterator->second.push_back(std::weak_ptr<Sparkline>(pSparkline));
+ if (bInserted)
+ 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;
+
+ for (auto iterator = m_aSparklineGroups.begin(); iterator != m_aSparklineGroups.end();)
+ {
+ auto pWeakGroup = *iterator;
+ if (auto pSparklineGroup = pWeakGroup.lock())
+ {
+ toReturn.push_back(pSparklineGroup);
+ iterator++;
+ }
+ else
+ {
+ iterator = m_aSparklineGroups.erase(iterator);
+ }
+ }
+ return toReturn;
+}
+
+std::vector<std::shared_ptr<Sparkline>>
+SparklineList::getSparklinesFor(std::shared_ptr<SparklineGroup> const& pSparklineGroup)
+{
+ std::vector<std::shared_ptr<Sparkline>> toReturn;
+
+ std::weak_ptr<SparklineGroup> pWeakGroup(pSparklineGroup);
+ auto iteratorGroup = m_aSparklineGroupMap.find(pWeakGroup);
+
+ if (iteratorGroup == m_aSparklineGroupMap.end())
+ return toReturn;
+
+ auto& rWeakSparklines = iteratorGroup->second;
+
+ for (auto iterator = rWeakSparklines.begin(); iterator != rWeakSparklines.end();)
+ {
+ if (auto aSparkline = iterator->lock())
+ {
+ toReturn.push_back(aSparkline);
+ iterator++;
+ }
+ else
+ {
+ iterator = rWeakSparklines.erase(iterator);
+ }
+ }
+
+ return toReturn;
+}
+
+} // end sc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */