summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2022-03-28 22:51:08 +0900
committerTomaž Vajngerl <quikee@gmail.com>2022-04-05 05:16:59 +0200
commit5ff13a0866fe5c408f9e9c7441a9d052b383d99c (patch)
treec8020a3b30b1b971a60765940b12111f9f064ef6 /sc
parent097bcd530c7facde50c7fe21e1cee9b4bf4a7949 (diff)
sc: use GUID for the SparklineGroup ID and use that
This adds tools::Guid as the SparklineGroup ID. At import the Guid is parsed by tools::Guid and later it is used to identify the SparklineGroup. This is useful when copying sparklines so we can preserve to which group it belongs, when that is desired. Change-Id: I4f2b560d5ea74552e8add57bb05469be57cf4a69 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132515 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/inc/SparklineGroup.hxx7
-rw-r--r--sc/inc/document.hxx7
-rw-r--r--sc/qa/unit/SparklineImportExportTest.cxx4
-rw-r--r--sc/qa/unit/SparklineTest.cxx11
-rw-r--r--sc/source/core/data/column2.cxx7
-rw-r--r--sc/source/core/data/column4.cxx7
-rw-r--r--sc/source/core/data/document.cxx16
-rw-r--r--sc/source/filter/excel/export/SparklineExt.cxx2
-rw-r--r--sc/source/filter/oox/SparklineFragment.cxx5
-rw-r--r--sc/source/filter/xml/SparklineGroupsExport.cxx7
-rw-r--r--sc/source/filter/xml/SparklineGroupsImportContext.cxx4
-rw-r--r--sc/source/ui/sparklines/SparklineGroup.cxx7
12 files changed, 61 insertions, 23 deletions
diff --git a/sc/inc/SparklineGroup.hxx b/sc/inc/SparklineGroup.hxx
index 5a3bda62b6ab..c5e917f059f3 100644
--- a/sc/inc/SparklineGroup.hxx
+++ b/sc/inc/SparklineGroup.hxx
@@ -13,6 +13,7 @@
#include "scdllapi.h"
#include "SparklineAttributes.hxx"
#include <tools/color.hxx>
+#include <tools/Guid.hxx>
#include <optional>
namespace sc
@@ -22,15 +23,15 @@ class SC_DLLPUBLIC SparklineGroup
{
private:
SparklineAttributes m_aAttributes;
- OUString m_sUID;
+ tools::Guid m_aGUID;
public:
SparklineAttributes& getAttributes() { return m_aAttributes; }
SparklineAttributes const& getAttributes() const { return m_aAttributes; }
- OUString getID() { return m_sUID; }
+ tools::Guid& getID() { return m_aGUID; }
- void setID(OUString const& rID) { m_sUID = rID; }
+ void setID(tools::Guid const& rGuid) { m_aGUID = rGuid; }
SparklineGroup();
SparklineGroup(SparklineGroup const& pOtherSparkline);
diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index e31900dee7cd..1cde9b95fe4c 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -69,12 +69,12 @@ enum class EEHorizontalTextDirection;
namespace editeng { class SvxBorderLine; }
namespace formula { struct VectorRefArray; }
namespace svl {
-
class SharedString;
class SharedStringPool;
-
}
+namespace tools { class Guid; }
+
namespace sc {
struct FormulaGroupContext;
@@ -208,6 +208,7 @@ typedef o3tl::sorted_vector<sal_uInt32> ScCondFormatIndexes;
struct ScSheetLimits;
struct ScDataAreaExtras;
+
namespace sc {
typedef std::map<OUString, BitmapEx> IconSetBitmapMap;
@@ -1255,6 +1256,8 @@ public:
SC_DLLPUBLIC sc::SparklineList* GetSparklineList(SCTAB nTab);
SC_DLLPUBLIC bool DeleteSparkline(ScAddress const& rPosition);
SC_DLLPUBLIC bool HasOneSparklineGroup(ScRange const& rRange);
+ SC_DLLPUBLIC std::shared_ptr<sc::SparklineGroup> SearchSparklineGroup(tools::Guid const& rGuid);
+
/** Notes **/
SC_DLLPUBLIC ScPostIt* GetNote(const ScAddress& rPos);
SC_DLLPUBLIC ScPostIt* GetNote(SCCOL nCol, SCROW nRow, SCTAB nTab);
diff --git a/sc/qa/unit/SparklineImportExportTest.cxx b/sc/qa/unit/SparklineImportExportTest.cxx
index 6da76fb2dcfb..7060a120c49a 100644
--- a/sc/qa/unit/SparklineImportExportTest.cxx
+++ b/sc/qa/unit/SparklineImportExportTest.cxx
@@ -69,8 +69,8 @@ void checkSparklines(ScDocument& rDocument)
{
auto pSparkline = rDocument.GetSparkline(ScAddress(0, 1, 0)); // A2
CPPUNIT_ASSERT(pSparkline);
- CPPUNIT_ASSERT_EQUAL(OUString("{1C5C5DE0-3C09-4CB3-A3EC-9E763301EC82}"),
- pSparkline->getSparklineGroup()->getID());
+ CPPUNIT_ASSERT_EQUAL(OString("{1C5C5DE0-3C09-4CB3-A3EC-9E763301EC82}"),
+ pSparkline->getSparklineGroup()->getID().getString());
auto& rAttributes = pSparkline->getSparklineGroup()->getAttributes();
CPPUNIT_ASSERT_EQUAL(sc::SparklineType::Line, rAttributes.getType());
diff --git a/sc/qa/unit/SparklineTest.cxx b/sc/qa/unit/SparklineTest.cxx
index ac9c0996ac59..6e203131e9c5 100644
--- a/sc/qa/unit/SparklineTest.cxx
+++ b/sc/qa/unit/SparklineTest.cxx
@@ -153,6 +153,7 @@ void SparklineTest::testCopyPasteSparkline()
ScRange aSourceRange(0, 6, 0, 0, 6, 0);
auto pSparkline = rDocument.GetSparkline(aSourceRange.aStart);
+ auto const& pOriginalGroup = pSparkline->getSparklineGroup();
CPPUNIT_ASSERT(pSparkline);
CPPUNIT_ASSERT_EQUAL(SCCOL(0), pSparkline->getColumn());
@@ -177,6 +178,11 @@ void SparklineTest::testCopyPasteSparkline()
CPPUNIT_ASSERT_EQUAL(SCCOL(0), pSparklineCopy->getColumn());
CPPUNIT_ASSERT_EQUAL(SCROW(7), pSparklineCopy->getRow());
+
+ auto const& pCopyGroup = pSparklineCopy->getSparklineGroup();
+
+ CPPUNIT_ASSERT_EQUAL(pOriginalGroup->getID(), pCopyGroup->getID());
+ CPPUNIT_ASSERT_EQUAL(pOriginalGroup.get(), pCopyGroup.get());
}
// Copy / Paste with a ClipDoc
@@ -198,6 +204,11 @@ void SparklineTest::testCopyPasteSparkline()
CPPUNIT_ASSERT_EQUAL(SCCOL(0), pSparklineCopy->getColumn());
CPPUNIT_ASSERT_EQUAL(SCROW(8), pSparklineCopy->getRow());
+
+ auto const& pCopyGroup = pSparklineCopy->getSparklineGroup();
+
+ CPPUNIT_ASSERT_EQUAL(pOriginalGroup->getID(), pCopyGroup->getID());
+ CPPUNIT_ASSERT_EQUAL(pOriginalGroup.get(), pCopyGroup.get());
}
xDocSh->DoClose();
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index d8e1003beaff..7f1d3a722269 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -2060,9 +2060,10 @@ public:
auto const& pSparkline = pCell->getSparkline();
auto const& pGroup = pCell->getSparklineGroup();
- auto pNewSparklineGroup = std::make_shared<sc::SparklineGroup>(*pGroup); // Copy the group
- auto pNewSparkline = std::make_shared<sc::Sparkline>(mrDestColumn.GetCol(), nDestRow, pNewSparklineGroup);
-
+ auto pDestinationGroup = mrDestColumn.GetDoc().SearchSparklineGroup(pGroup->getID());
+ if (!pDestinationGroup)
+ pDestinationGroup = std::make_shared<sc::SparklineGroup>(*pGroup); // Copy the group
+ auto pNewSparkline = std::make_shared<sc::Sparkline>(mrDestColumn.GetCol(), nDestRow, pDestinationGroup);
pNewSparkline->setInputRange(pSparkline->getInputRange());
miDestPosition = mrDestSparkline.set(miDestPosition, nDestRow, new sc::SparklineCell(pNewSparkline));
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index e6bb2c09db47..3314ed5f5f51 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -375,12 +375,15 @@ void ScColumn::duplicateSparkline(sc::CopyFromClipContext& rContext, sc::ColumnB
{
auto const& pSparklineGroup = pSparkline->getSparklineGroup();
+ auto pDuplicatedGroup = GetDoc().SearchSparklineGroup(pSparklineGroup->getID());
+ if (!pDuplicatedGroup)
+ pDuplicatedGroup = std::make_shared<sc::SparklineGroup>(*pSparklineGroup);
+
std::vector<sc::SparklineCell*> aSparklines(nDestSize, nullptr);
ScAddress aCurrentPosition = aDestPosition;
for (size_t i = 0; i < nDestSize; ++i)
{
- auto pNewSparklineGroup = std::make_shared<sc::SparklineGroup>(*pSparklineGroup);
- auto pNewSparkline = std::make_shared<sc::Sparkline>(aCurrentPosition.Col(), aCurrentPosition.Row(), pNewSparklineGroup);
+ auto pNewSparkline = std::make_shared<sc::Sparkline>(aCurrentPosition.Col(), aCurrentPosition.Row(), pDuplicatedGroup);
pNewSparkline->setInputRange(pSparkline->getInputRange());
aSparklines[i] = new sc::SparklineCell(pNewSparkline);
aCurrentPosition.IncRow();
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index be5037d4ec74..cf72b9e55685 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -86,6 +86,7 @@
#include <tokenstringcontext.hxx>
#include <compressedarray.hxx>
#include <recursionhelper.hxx>
+#include <SparklineGroup.hxx>
#include <formula/vectortoken.hxx>
@@ -6643,6 +6644,21 @@ bool ScDocument::HasOneSparklineGroup(ScRange const& rRange)
return true;
}
+std::shared_ptr<sc::SparklineGroup> ScDocument::SearchSparklineGroup(tools::Guid const& rGuid)
+{
+ for (auto const& rTable : maTabs)
+ {
+ for (auto const& pSparkline : rTable->GetSparklineList().getSparklines())
+ {
+ auto const& pGroup = pSparkline->getSparklineGroup();
+ if (pGroup->getID() == rGuid)
+ return pGroup;
+ }
+ }
+
+ return std::shared_ptr<sc::SparklineGroup>();
+}
+
// Notes
ScPostIt* ScDocument::GetNote(const ScAddress& rPos)
diff --git a/sc/source/filter/excel/export/SparklineExt.cxx b/sc/source/filter/excel/export/SparklineExt.cxx
index 549365dcb003..b4614dd59ea3 100644
--- a/sc/source/filter/excel/export/SparklineExt.cxx
+++ b/sc/source/filter/excel/export/SparklineExt.cxx
@@ -189,7 +189,7 @@ void SparklineExt::addSparklineGroup(XclExpXmlStream& rStream, sc::SparklineGrou
auto pAttrList = sax_fastparser::FastSerializerHelper::createAttrList();
// Write ID
- OString sUID = OUStringToOString(rSparklineGroup.getID(), RTL_TEXTENCODING_UTF8);
+ OString sUID = rSparklineGroup.getID().getString();
pAttrList->addNS(XML_xr2, XML_uid, sUID);
// Write attributes
diff --git a/sc/source/filter/oox/SparklineFragment.cxx b/sc/source/filter/oox/SparklineFragment.cxx
index 94fefc37949f..bb341d4a88bc 100644
--- a/sc/source/filter/oox/SparklineFragment.cxx
+++ b/sc/source/filter/oox/SparklineFragment.cxx
@@ -173,8 +173,9 @@ ContextHandlerRef SparklineGroupsContext::onCreateContext(sal_Int32 nElement,
auto& rLastGroup = m_aSparklineGroups.emplace_back();
auto& rSparklineAttributes = rLastGroup.getSparklineGroup()->getAttributes();
addAttributesToSparklineAttributes(rSparklineAttributes, rAttribs);
- OUString sUID = rAttribs.getString(XR2_TOKEN(uid), OUString());
- rLastGroup.getSparklineGroup()->setID(sUID);
+ OUString sGUID = rAttribs.getString(XR2_TOKEN(uid), OUString());
+ tools::Guid aGuid(OUStringToOString(sGUID, RTL_TEXTENCODING_ASCII_US));
+ rLastGroup.getSparklineGroup()->setID(aGuid);
return this;
}
case XLS14_TOKEN(colorSeries):
diff --git a/sc/source/filter/xml/SparklineGroupsExport.cxx b/sc/source/filter/xml/SparklineGroupsExport.cxx
index 6be8a616a423..4de56fcfaf58 100644
--- a/sc/source/filter/xml/SparklineGroupsExport.cxx
+++ b/sc/source/filter/xml/SparklineGroupsExport.cxx
@@ -187,11 +187,8 @@ void SparklineGroupsExport::addSparklineGroup(SparklineGroup* pSparklineGroup)
{
auto const& rAttributes = pSparklineGroup->getAttributes();
- OUString sID = pSparklineGroup->getID();
- if (!sID.isEmpty())
- {
- m_rExport.AddAttribute(XML_NAMESPACE_CALC_EXT, XML_ID, sID);
- }
+ OUString sID = pSparklineGroup->getID().getOUString();
+ m_rExport.AddAttribute(XML_NAMESPACE_CALC_EXT, XML_ID, sID);
addSparklineGroupAttributes(rAttributes);
diff --git a/sc/source/filter/xml/SparklineGroupsImportContext.cxx b/sc/source/filter/xml/SparklineGroupsImportContext.cxx
index 87acbd047cf9..5720ca8f3382 100644
--- a/sc/source/filter/xml/SparklineGroupsImportContext.cxx
+++ b/sc/source/filter/xml/SparklineGroupsImportContext.cxx
@@ -70,7 +70,9 @@ void SparklineGroupsImportContext::fillSparklineGroupID(
{
case XML_ELEMENT(CALC_EXT, XML_ID):
{
- m_pCurrentSparklineGroup->setID(rIter.toString());
+ OString aString = OUStringToOString(rIter.toString(), RTL_TEXTENCODING_ASCII_US);
+ tools::Guid aGuid(aString);
+ m_pCurrentSparklineGroup->setID(aGuid);
break;
}
}
diff --git a/sc/source/ui/sparklines/SparklineGroup.cxx b/sc/source/ui/sparklines/SparklineGroup.cxx
index 55f52ff4665f..9ef2c7044ab0 100644
--- a/sc/source/ui/sparklines/SparklineGroup.cxx
+++ b/sc/source/ui/sparklines/SparklineGroup.cxx
@@ -12,11 +12,14 @@
namespace sc
{
-SparklineGroup::SparklineGroup() {}
+SparklineGroup::SparklineGroup()
+ : m_aGUID(tools::Guid::Generate)
+{
+}
SparklineGroup::SparklineGroup(SparklineGroup const& pOtherSparkline)
: m_aAttributes(pOtherSparkline.m_aAttributes)
- , m_sUID(pOtherSparkline.m_sUID)
+ , m_aGUID(pOtherSparkline.m_aGUID)
{
}