sc/Library_sc.mk                  |    1 
 sc/inc/Sparkline.hxx              |   52 ++++++++++++++++++++++++++++++++++++--
 sc/inc/SparklineCell.hxx          |   47 ++++++++++++++++++++++++++++++++++
 sc/inc/SparklineGroup.hxx         |   28 +++++++++++++++++++-
 sc/inc/column.hxx                 |    4 +-
 sc/inc/document.hxx               |    4 ++
 sc/inc/mtvelements.hxx            |    6 ++--
 sc/inc/table.hxx                  |    9 ++++++
 sc/source/core/data/Sparkline.cxx |   22 ----------------
 sc/source/core/data/column2.cxx   |    8 ++---
 sc/source/core/data/document.cxx  |   34 +++++++++++++++---------
 sc/source/core/data/table2.cxx    |   37 +++++++++++++++++++++++++++
 12 files changed, 203 insertions(+), 49 deletions(-)

New commits:
commit a6a0b8cde3fa8673ea5ded216f9e007a496c9a88
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Fri Mar 4 17:26:34 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Mar 29 04:48:37 2022 +0200

    sc: set default parameters in SparklineGroup
    
    The colors are set to COL_TRANSPARENT except for the series color,
    which is set to COL_BLUE by default. Other parameters are set to
    their default values according to OOXML specs.
    
    Change-Id: I67ceab2ffd723511fbf0616cca661992f0a8cf69
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131920
    Tested-by: Jenkins
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/inc/SparklineGroup.hxx b/sc/inc/SparklineGroup.hxx
index 620a5ae0bf4a..c6df94e1bdc5 100644
--- a/sc/inc/SparklineGroup.hxx
+++ b/sc/inc/SparklineGroup.hxx
@@ -78,7 +78,33 @@ public:
     std::optional<double> m_aManualMin; // if m_sMaxAxisType is "custom"
     OUString m_sUID;
 
-    SparklineGroup() = default;
+    SparklineGroup()
+        : m_aColorSeries(COL_BLUE)
+        , m_aColorNegative(COL_TRANSPARENT)
+        , m_aColorAxis(COL_TRANSPARENT)
+        , m_aColorMarkers(COL_TRANSPARENT)
+        , m_aColorFirst(COL_TRANSPARENT)
+        , m_aColorLast(COL_TRANSPARENT)
+        , m_aColorHigh(COL_TRANSPARENT)
+        , m_aColorLow(COL_TRANSPARENT)
+        , m_eMinAxisType(AxisType::Individual)
+        , m_eMaxAxisType(AxisType::Individual)
+        , m_fLineWeight(0.75)
+        , m_eType(SparklineType::Line)
+        , m_bDateAxis(false)
+        , m_eDisplayEmptyCellsAs(DisplayEmptyCellAs::Zero)
+        , m_bMarkers(false)
+        , m_bHigh(false)
+        , m_bLow(false)
+        , m_bFirst(false)
+        , m_bLast(false)
+        , m_bNegative(false)
+        , m_bDisplayXAxis(false)
+        , m_bDisplayHidden(false)
+        , m_bRightToLeft(false)
+    {
+    }
+
     SparklineGroup(const SparklineGroup&) = delete;
     SparklineGroup& operator=(const SparklineGroup&) = delete;
 };
commit 4e37bb2e7b7c84457e2f44e3a9a0d47b96a603af
Author:     Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk>
AuthorDate: Wed Mar 2 17:44:08 2022 +0900
Commit:     Tomaž Vajngerl <qui...@gmail.com>
CommitDate: Tue Mar 29 04:48:23 2022 +0200

    sc: refactor sparkline struture to store a list of sparklines
    
    We need to access a list of sparklines and sparkline groups for
    a sheet. To preven going through all the columns of a sheet, we
    need to store all the created sparklines in a list. For this it
    is necessary to change the model structrue a bit. A cell now has
    a container that stores a shared_ptr to the sparkline instead of
    storing the sparkline directly. With this we can store a list
    of weak_ptr to the sparklines in a list (vector), which can be
    accessed at any time and is quite fast.
    
    This is needed by the OOXML export.
    
    Change-Id: Iaca0a41e20912775f072ea6e8cab9c44367d6f30
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131919
    Tested-by: Tomaž Vajngerl <qui...@gmail.com>
    Reviewed-by: Tomaž Vajngerl <qui...@gmail.com>

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 11449217edd9..62ab22a797c4 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -185,7 +185,6 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/core/data/sheetevents \
     sc/source/core/data/simpleformulacalc \
     sc/source/core/data/sortparam \
-    sc/source/core/data/Sparkline \
     sc/source/core/data/stlpool \
     sc/source/core/data/stlsheet \
     sc/source/core/data/subtotalparam \
diff --git a/sc/inc/Sparkline.hxx b/sc/inc/Sparkline.hxx
index 89e306a984b1..5ba9d397d083 100644
--- a/sc/inc/Sparkline.hxx
+++ b/sc/inc/Sparkline.hxx
@@ -25,20 +25,68 @@ namespace sc
  */
 class SC_DLLPUBLIC Sparkline
 {
-private:
+    SCCOL m_nColumn;
+    SCROW m_nRow;
+
     ScRangeList m_aInputRange;
     std::shared_ptr<SparklineGroup> m_pSparklineGroup;
 
 public:
-    Sparkline(const std::shared_ptr<SparklineGroup>& pSparklineGroup);
+    Sparkline(SCCOL nColumn, SCROW nRow, std::shared_ptr<SparklineGroup> 
const& pSparklineGroup)
+        : m_nColumn(nColumn)
+        , m_nRow(nRow)
+        , m_pSparklineGroup(pSparklineGroup)
+    {
+    }
 
     Sparkline(const Sparkline&) = delete;
     Sparkline& operator=(const Sparkline&) = delete;
 
     void setInputRange(ScRangeList const& rInputRange) { m_aInputRange = 
rInputRange; }
+
     ScRangeList const& getInputRange() { return m_aInputRange; }
 
     std::shared_ptr<SparklineGroup> const& getSparklineGroup() { return 
m_pSparklineGroup; }
+
+    SCCOL getColumn() { return m_nColumn; }
+
+    SCROW getRow() { return m_nRow; }
+};
+
+/** Contains a list of all created sparklines */
+class SC_DLLPUBLIC SparklineList
+{
+private:
+    std::vector<std::weak_ptr<Sparkline>> m_pSparklines;
+
+public:
+    SparklineList() {}
+
+    void addSparkline(std::shared_ptr<Sparkline> const& pSparkline)
+    {
+        m_pSparklines.push_back(pSparkline);
+    }
+
+    std::vector<std::shared_ptr<Sparkline>> getSparklines()
+    {
+        std::vector<std::shared_ptr<Sparkline>> toReturn;
+
+        std::vector<std::weak_ptr<Sparkline>>::iterator aIter;
+        for (aIter = m_pSparklines.begin(); aIter != m_pSparklines.end();)
+        {
+            if (auto aSparkline = aIter->lock())
+            {
+                toReturn.push_back(aSparkline);
+                aIter++;
+            }
+            else
+            {
+                aIter = m_pSparklines.erase(aIter);
+            }
+        }
+
+        return toReturn;
+    }
 };
 
 } // end sc
diff --git a/sc/inc/SparklineCell.hxx b/sc/inc/SparklineCell.hxx
new file mode 100644
index 000000000000..0aca857170c9
--- /dev/null
+++ b/sc/inc/SparklineCell.hxx
@@ -0,0 +1,47 @@
+/* -*- 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 "scdllapi.h"
+#include "Sparkline.hxx"
+#include <memory>
+
+namespace sc
+{
+class SC_DLLPUBLIC SparklineCell
+{
+private:
+    std::shared_ptr<Sparkline> m_pSparkline;
+
+public:
+    SparklineCell(std::shared_ptr<Sparkline> const& pSparkline)
+        : m_pSparkline(pSparkline)
+    {
+    }
+
+    SparklineCell(const SparklineCell&) = delete;
+    SparklineCell& operator=(const SparklineCell&) = delete;
+
+    void setInputRange(ScRangeList const& rInputRange) { 
m_pSparkline->setInputRange(rInputRange); }
+
+    ScRangeList const& getInputRange() { return m_pSparkline->getInputRange(); 
}
+
+    std::shared_ptr<SparklineGroup> const& getSparklineGroup()
+    {
+        return m_pSparkline->getSparklineGroup();
+    }
+
+    std::shared_ptr<Sparkline> const& getSparkline() { return m_pSparkline; }
+};
+
+} // end sc
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index f04d54aca739..db72de87bbf1 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -661,8 +661,8 @@ public:
     void BroadcastRows( SCROW nStartRow, SCROW nEndRow, SfxHintId nHint );
 
     // Spaklines
-    sc::Sparkline* GetSparkline(SCROW nRow);
-    void SetSparkline(SCROW nRow, std::unique_ptr<sc::Sparkline> pSparkline);
+    sc::SparklineCell* GetSparklineCell(SCROW nRow);
+    void CreateSparklineCell(SCROW nRow, std::shared_ptr<sc::Sparkline> const& 
pSparkline);
 
     // cell notes
     ScPostIt* GetCellNote( SCROW nRow );
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 639166319366..84199c00de4c 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -103,6 +103,7 @@ class ColumnIterator;
 class ExternalDataMapper;
 class Sparkline;
 class SparklineGroup;
+class SparklineList;
 
 }
 
@@ -1249,7 +1250,8 @@ public:
 
     /** Spaklines */
     SC_DLLPUBLIC sc::Sparkline* GetSparkline(ScAddress const & rPosition);
-    SC_DLLPUBLIC sc::Sparkline* CreateSparkline(ScAddress const & rPosition, 
const std::shared_ptr<sc::SparklineGroup> & pSparklineGroup);
+    SC_DLLPUBLIC sc::Sparkline* CreateSparkline(ScAddress const & rPosition, 
std::shared_ptr<sc::SparklineGroup> const& pSparklineGroup);
+    SC_DLLPUBLIC sc::SparklineList* GetSparklineList(SCTAB nTab);
 
     /** Notes **/
     SC_DLLPUBLIC ScPostIt*       GetNote(const ScAddress& rPos);
diff --git a/sc/inc/mtvelements.hxx b/sc/inc/mtvelements.hxx
index 6de0f3e7ec23..ee669c0a6e6b 100644
--- a/sc/inc/mtvelements.hxx
+++ b/sc/inc/mtvelements.hxx
@@ -15,7 +15,7 @@
 #include <editeng/editobj.hxx>
 #include "calcmacros.hxx"
 #include "postit.hxx"
-#include "Sparkline.hxx"
+#include "SparklineCell.hxx"
 #include "celltextattr.hxx"
 
 #if DEBUG_COLUMN_STORAGE
@@ -59,7 +59,7 @@ const mdds::mtv::element_t element_type_uint16 = 
mdds::mtv::element_type_uint16;
 
 /// Custom element blocks.
 
-typedef mdds::mtv::noncopyable_managed_element_block<element_type_sparkline, 
sc::Sparkline> sparkline_block;
+typedef mdds::mtv::noncopyable_managed_element_block<element_type_sparkline, 
sc::SparklineCell> sparkline_block;
 typedef mdds::mtv::noncopyable_managed_element_block<element_type_cellnote, 
ScPostIt> cellnote_block;
 typedef mdds::mtv::noncopyable_managed_element_block<element_type_broadcaster, 
SvtBroadcaster> broadcaster_block;
 typedef mdds::mtv::default_element_block<element_type_celltextattr, 
CellTextAttr> celltextattr_block;
@@ -77,7 +77,7 @@ typedef mdds::mtv::uint16_element_block uint16_block;
 /// For example sc types like sc::CellTextAttr, ScFormulaCell in global 
namespace.
 namespace sc {
 MDDS_MTV_DEFINE_ELEMENT_CALLBACKS(CellTextAttr, element_type_celltextattr, 
CellTextAttr(), celltextattr_block)
-MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(Sparkline, sc::element_type_sparkline, 
nullptr, sc::sparkline_block)
+MDDS_MTV_DEFINE_ELEMENT_CALLBACKS_PTR(SparklineCell, 
sc::element_type_sparkline, nullptr, sc::sparkline_block)
 }
 
 /// These need to be in global namespace just like their respective types are.
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index a885067f5649..996f9a579d70 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -227,6 +227,7 @@ private:
     mutable std::unique_ptr<ScRangeName> mpRangeName;
 
     std::unique_ptr<ScConditionalFormatList> mpCondFormatList;
+    sc::SparklineList maSparklineList;
 
     ScAddress       maLOKFreezeCell;
 
@@ -469,6 +470,14 @@ public:
     void        GetFirstDataPos(SCCOL& rCol, SCROW& rRow) const;
     void        GetLastDataPos(SCCOL& rCol, SCROW& rRow) const;
 
+    // Sparklines
+
+    sc::Sparkline* GetSparkline(SCCOL nCol, SCROW nRow);
+    sc::Sparkline* CreateSparkline(SCCOL nCol, SCROW nRow, 
std::shared_ptr<sc::SparklineGroup> const& pSparklineGroup);
+
+    sc::SparklineList& GetSparklineList();
+
+    // Notes / Comments
     std::unique_ptr<ScPostIt> ReleaseNote( SCCOL nCol, SCROW nRow );
     ScPostIt*                 GetNote( SCCOL nCol, SCROW nRow );
     void                      SetNote( SCCOL nCol, SCROW nRow, 
std::unique_ptr<ScPostIt> pNote );
diff --git a/sc/source/core/data/Sparkline.cxx 
b/sc/source/core/data/Sparkline.cxx
deleted file mode 100644
index 44d5645030d3..000000000000
--- a/sc/source/core/data/Sparkline.cxx
+++ /dev/null
@@ -1,22 +0,0 @@
-/* -*- 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 <memory>
-#include <Sparkline.hxx>
-
-namespace sc
-{
-Sparkline::Sparkline(const std::shared_ptr<SparklineGroup>& pSparklineGroup)
-    : m_pSparklineGroup(pSparklineGroup)
-{
-}
-}
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index 3eabc08a387c..f1a803750002 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -1970,14 +1970,14 @@ void ScColumn::PrepareBroadcastersForDestruction()
     }
 }
 
-sc::Sparkline* ScColumn::GetSparkline(SCROW nRow)
+sc::SparklineCell* ScColumn::GetSparklineCell(SCROW nRow)
 {
-    return maSparklines.get<sc::Sparkline*>(nRow);
+    return maSparklines.get<sc::SparklineCell*>(nRow);
 }
 
-void ScColumn::SetSparkline(SCROW nRow, std::unique_ptr<sc::Sparkline> 
pSparkline)
+void ScColumn::CreateSparklineCell(SCROW nRow, std::shared_ptr<sc::Sparkline> 
const& pSparkline)
 {
-    maSparklines.set(nRow, pSparkline.release());
+    maSparklines.set(nRow, new sc::SparklineCell(pSparkline));
 }
 
 namespace
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index a1ac0e0d2ec9..363bd168fcab 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -6565,33 +6565,41 @@ bool ScDocument::IsInVBAMode() const
     return false;
 }
 
+// Sparklines
 sc::Sparkline* ScDocument::GetSparkline(ScAddress const& rPosition)
 {
     SCTAB nTab = rPosition.Tab();
-    SCCOL nCol = rPosition.Col();
 
-    if (ValidTab(nTab) && nTab < SCTAB(maTabs.size()) &&
-        nCol < maTabs[nTab]->GetAllocatedColumnsCount())
+    if (ValidTab(nTab) && nTab < SCTAB(maTabs.size()))
     {
-        SCROW nRow = rPosition.Row();
-        return maTabs[nTab]->aCol[nCol].GetSparkline(nRow);
+        return maTabs[nTab]->GetSparkline(rPosition.Col(), rPosition.Row());
     }
     return nullptr;
 }
 
-sc::Sparkline* ScDocument::CreateSparkline(ScAddress const & rPosition, const 
std::shared_ptr<sc::SparklineGroup> & pSparklineGroup)
+sc::Sparkline* ScDocument::CreateSparkline(ScAddress const& rPosition, 
std::shared_ptr<sc::SparklineGroup> const& pSparklineGroup)
 {
-    std::unique_ptr<sc::Sparkline> pSparkline(new 
sc::Sparkline(pSparklineGroup));
-    sc::Sparkline* pCreated = pSparkline.get();
-
     SCTAB nTab = rPosition.Tab();
-    SCCOL nCol = rPosition.Col();
-    SCROW nRow = rPosition.Row();
-    maTabs[nTab]->CreateColumnIfNotExists(nCol).SetSparkline(nRow, 
std::move(pSparkline));
 
-    return pCreated;
+    if (ValidTab(nTab) && nTab < SCTAB(maTabs.size()))
+    {
+        return maTabs[nTab]->CreateSparkline(rPosition.Col(), rPosition.Row(), 
pSparklineGroup);
+    }
+
+    return nullptr;
+}
+
+sc::SparklineList* ScDocument::GetSparklineList(SCTAB nTab)
+{
+    if (ValidTab(nTab) && nTab < SCTAB(maTabs.size()))
+    {
+        return &maTabs[nTab]->GetSparklineList();
+    }
+    return nullptr;
 }
 
+// Notes
+
 ScPostIt* ScDocument::GetNote(const ScAddress& rPos)
 {
     return GetNote(rPos.Col(), rPos.Row(), rPos.Tab());
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 7ffc82c3569f..6ac918f34ef5 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1809,6 +1809,43 @@ ScFormulaCell* ScTable::GetFormulaCell( SCCOL nCol, 
SCROW nRow )
     return aCol[nCol].GetFormulaCell(nRow);
 }
 
+// Sparklines
+
+sc::Sparkline* ScTable::GetSparkline(SCCOL nCol, SCROW nRow)
+{
+    if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())
+        return nullptr;
+
+    sc::SparklineCell* pSparklineCell = aCol[nCol].GetSparklineCell(nRow);
+    if (!pSparklineCell)
+        return nullptr;
+
+    std::shared_ptr<sc::Sparkline> pSparkline(pSparklineCell->getSparkline());
+    assert(pSparkline);
+
+    return pSparkline.get();
+}
+
+sc::Sparkline* ScTable::CreateSparkline(SCCOL nCol, SCROW nRow, 
std::shared_ptr<sc::SparklineGroup> const& pSparklineGroup)
+{
+    if (!ValidCol(nCol))
+        return nullptr;
+
+    ScColumn& rColumn = CreateColumnIfNotExists(nCol);
+
+    std::shared_ptr<sc::Sparkline> pSparkline(new sc::Sparkline(nCol, nRow, 
pSparklineGroup));
+    maSparklineList.addSparkline(pSparkline);
+    rColumn.CreateSparklineCell(nRow, pSparkline);
+    return pSparkline.get();
+}
+
+sc::SparklineList& ScTable::GetSparklineList()
+{
+    return maSparklineList;
+}
+
+// Notes
+
 std::unique_ptr<ScPostIt> ScTable::ReleaseNote( SCCOL nCol, SCROW nRow )
 {
     if (!ValidCol(nCol) || nCol >= GetAllocatedColumnsCount())

Reply via email to