summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2019-11-20 13:24:48 +0530
committerAndras Timar <andras.timar@collabora.com>2019-11-27 14:51:18 +0100
commit541af6456cd2f0598378f772e25f621d3cf3f6bb (patch)
tree235b36bcf2a230df0cc5318be54a9680184721ef
parente48af2d8ffde46b63b8e42852dda1c2cd514f83b (diff)
tdf#128894: xlsx-import : Do not share tokens between cells...
which are part of a xlsx-shared-formula along a *row*. If we do, any reference-updates on these cells while editing will mess things up. For example a shared formula "=A30+1" used for a few cells in the first row (say, A1, B1, C1 and D1) and on deleting a row, say row#5, the reference update operation will decrement the row index of all tokens in A1, B1, C1 and D1. But if they share tokens, they all end up pointing to row#26 instead of row#29 as each cell is updated which amounts to decrementing 4 times instead of once. However shared formulas along columns are not affected by this bug, when tokens are shared since we use formula-groups which only keeps one copy of token array for the entire group and reference-update code is designed to correctly work with formula-groups. Reviewed-on: https://gerrit.libreoffice.org/83361 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com> Reviewed-by: Eike Rathke <erack@redhat.com> (cherry picked from commit b30251ca0d102ced36799ee18d4bbcd9e8530fa0) (cherry picked from commit 5a1cb68d574e0788a0bad4859acdd5005babb860) Change-Id: Ic0fe84d12fef18fbf21658664e2b2b86409bca27 Reviewed-on: https://gerrit.libreoffice.org/83881 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Andras Timar <andras.timar@collabora.com>
-rw-r--r--sc/source/filter/ftools/sharedformulagroups.cxx16
-rw-r--r--sc/source/filter/inc/sharedformulagroups.hxx22
-rw-r--r--sc/source/filter/oox/formulabuffer.cxx23
3 files changed, 54 insertions, 7 deletions
diff --git a/sc/source/filter/ftools/sharedformulagroups.cxx b/sc/source/filter/ftools/sharedformulagroups.cxx
index 1da53771d16f..47ac4475fbd1 100644
--- a/sc/source/filter/ftools/sharedformulagroups.cxx
+++ b/sc/source/filter/ftools/sharedformulagroups.cxx
@@ -14,13 +14,25 @@ namespace sc {
void SharedFormulaGroups::set( size_t nSharedId, ScTokenArray* pArray )
{
- m_Store.insert(std::make_pair(nSharedId, std::unique_ptr<ScTokenArray>(pArray)));
+ m_Store.emplace(nSharedId,
+ SharedFormulaGroupEntry(pArray, ScAddress(ScAddress::INITIALIZE_INVALID)));
+}
+
+void SharedFormulaGroups::set( size_t nSharedId, ScTokenArray* pArray, const ScAddress& rOrigin )
+{
+ m_Store.emplace(nSharedId, SharedFormulaGroupEntry(pArray, rOrigin));
}
const ScTokenArray* SharedFormulaGroups::get( size_t nSharedId ) const
{
StoreType::const_iterator const it = m_Store.find(nSharedId);
- return it == m_Store.end() ? nullptr : it->second.get();
+ return it == m_Store.end() ? nullptr : it->second.getTokenArray();
+}
+
+const SharedFormulaGroupEntry* SharedFormulaGroups::getEntry( size_t nSharedId ) const
+{
+ StoreType::const_iterator const it = m_Store.find(nSharedId);
+ return it == m_Store.end() ? nullptr : &(it->second);
}
}
diff --git a/sc/source/filter/inc/sharedformulagroups.hxx b/sc/source/filter/inc/sharedformulagroups.hxx
index f59cae1b52ff..5472862a7c90 100644
--- a/sc/source/filter/inc/sharedformulagroups.hxx
+++ b/sc/source/filter/inc/sharedformulagroups.hxx
@@ -10,6 +10,7 @@
#ifndef INCLUDED_SC_SOURCE_FILTER_INC_SHAREDFORMULAGROUPS_HXX
#define INCLUDED_SC_SOURCE_FILTER_INC_SHAREDFORMULAGROUPS_HXX
+#include <address.hxx>
#include <tokenarray.hxx>
#include <memory>
@@ -17,15 +18,34 @@
namespace sc {
+class SharedFormulaGroupEntry
+{
+private:
+ std::unique_ptr<ScTokenArray> mpArray;
+ ScAddress maOrigin;
+
+public:
+ SharedFormulaGroupEntry(ScTokenArray* pArray, const ScAddress& rOrigin)
+ : mpArray(pArray)
+ , maOrigin(rOrigin)
+ {
+ }
+
+ const ScTokenArray* getTokenArray() const { return mpArray.get(); }
+ const ScAddress& getOrigin() const { return maOrigin; }
+};
+
class SharedFormulaGroups
{
private:
- typedef std::map<size_t, std::unique_ptr<ScTokenArray>> StoreType;
+ typedef std::map<size_t, SharedFormulaGroupEntry> StoreType;
StoreType m_Store;
public:
void set( size_t nSharedId, ScTokenArray* pArray );
+ void set( size_t nSharedId, ScTokenArray* pArray, const ScAddress& rOrigin );
const ScTokenArray* get( size_t nSharedId ) const;
+ const SharedFormulaGroupEntry* getEntry( size_t nSharedId ) const;
};
}
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 48758f16e17b..286fd7a2d94f 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -127,7 +127,7 @@ void applySharedFormulas(
if (pArray)
{
aComp.CompileTokenArray(); // Generate RPN tokens.
- aGroups.set(nId, pArray);
+ aGroups.set(nId, pArray, aPos);
}
}
}
@@ -138,11 +138,26 @@ void applySharedFormulas(
for (const FormulaBuffer::SharedFormulaDesc& rDesc : rCells)
{
const ScAddress& aPos = rDesc.maAddress;
- const ScTokenArray* pArray = aGroups.get(rDesc.mnSharedId);
- if (!pArray)
+ const sc::SharedFormulaGroupEntry* pEntry = aGroups.getEntry(rDesc.mnSharedId);
+ if (!pEntry)
continue;
- ScFormulaCell* pCell = new ScFormulaCell(&rDoc.getDoc(), aPos, *pArray);
+ const ScTokenArray* pArray = pEntry->getTokenArray();
+ assert(pArray);
+ const ScAddress& rOrigin = pEntry->getOrigin();
+ assert(rOrigin.IsValid());
+
+ ScFormulaCell* pCell;
+ // In case of shared-formula along a row, do not let
+ // these cells share the same token objects.
+ // If we do, any reference-updates on these cells
+ // (while editing) will mess things up. Pass the cloned array as a
+ // pointer and not as reference to avoid any further allocation.
+ if (rOrigin.Col() != aPos.Col())
+ pCell = new ScFormulaCell(&rDoc.getDoc(), aPos, pArray->Clone());
+ else
+ pCell = new ScFormulaCell(&rDoc.getDoc(), aPos, *pArray);
+
rDoc.setFormulaCell(aPos, pCell);
if (rDesc.maCellValue.isEmpty())
{