summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrzej Hunt <andrzej@ahunt.org>2015-05-12 21:16:13 +0100
committerAndrzej Hunt <andrzej@ahunt.org>2015-10-20 18:18:35 +0200
commitef495e554784128105329879e4d359c0e45006d3 (patch)
tree63187d3b454e1879160bb898707d790bb41bbf23
parentc15313d611d42bf4e5a2686abe8ab90ad7e426a9 (diff)
Convert convertCellUnits to handle ranges
Change-Id: Ibe95cbd9ea9efd08a48e0651f469434802bfa40e
-rw-r--r--sc/inc/units.hxx2
-rw-r--r--sc/qa/unit/units.cxx1
-rw-r--r--sc/source/core/units/unitsimpl.cxx40
-rw-r--r--sc/source/core/units/unitsimpl.hxx2
4 files changed, 24 insertions, 21 deletions
diff --git a/sc/inc/units.hxx b/sc/inc/units.hxx
index b5e12da42909..8e15af4a8a00 100644
--- a/sc/inc/units.hxx
+++ b/sc/inc/units.hxx
@@ -107,7 +107,7 @@ public:
* rsInputUnit overrides the automatic determination of input units, i.e. disables
* input unit detection.
*/
- virtual bool convertCellUnits(const ScRange& rRange,
+ virtual bool convertCellUnits(const ScRangeList& rRanges,
ScDocument* pDoc,
const OUString& rsOutputUnit) = 0;
diff --git a/sc/qa/unit/units.cxx b/sc/qa/unit/units.cxx
index 29dfc2b7c626..b35cd4059320 100644
--- a/sc/qa/unit/units.cxx
+++ b/sc/qa/unit/units.cxx
@@ -820,6 +820,7 @@ void UnitsTest::testRangeConversion() {
// TODO: we need to test:
// 1. mixture of units that can't be converted
// 2. mixtures of local and header annotations
+ // 3. actual sensible ranges
}
CPPUNIT_TEST_SUITE_REGISTRATION(UnitsTest);
diff --git a/sc/source/core/units/unitsimpl.cxx b/sc/source/core/units/unitsimpl.cxx
index f2aa9e0e3315..0f79edb9e295 100644
--- a/sc/source/core/units/unitsimpl.cxx
+++ b/sc/source/core/units/unitsimpl.cxx
@@ -799,7 +799,7 @@ bool UnitsImpl::convertCellUnitsForColumnRange(const ScRange& rRange,
return bAllConverted;
}
-bool UnitsImpl::convertCellUnits(const ScRange& rRange,
+bool UnitsImpl::convertCellUnits(const ScRangeList& rRangeList,
ScDocument* pDoc,
const OUString& rsOutputUnit) {
UtUnit aOutputUnit;
@@ -807,26 +807,28 @@ bool UnitsImpl::convertCellUnits(const ScRange& rRange,
return false;
}
- ScRange aRange(rRange);
- aRange.PutInOrder();
-
- SCCOL nStartCol, nEndCol;
- SCROW nStartRow, nEndRow;
- SCTAB nStartTab, nEndTab;
- aRange.GetVars(nStartCol, nStartRow, nStartTab,
- nEndCol, nEndRow, nEndTab);
-
- // Can only handle ranges in a single sheet for now
- assert(nStartTab == nEndTab);
-
- // Each column is independent hence we are able to handle each separately.
bool bAllConverted = true;
- for (SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++) {
- ScRange aSubRange(ScAddress(nCol, nStartRow, nStartTab), ScAddress(nCol, nEndRow, nStartTab));
- bAllConverted = bAllConverted &&
- convertCellUnitsForColumnRange(aSubRange, pDoc, aOutputUnit);
- }
+ for (size_t i = 0; i < rRangeList.size(); i++) {
+ ScRange aRange(*rRangeList[i]);
+
+ aRange.PutInOrder();
+
+ SCCOL nStartCol, nEndCol;
+ SCROW nStartRow, nEndRow;
+ SCTAB nStartTab, nEndTab;
+ aRange.GetVars(nStartCol, nStartRow, nStartTab,
+ nEndCol, nEndRow, nEndTab);
+
+ // Each column is independent hence we are able to handle each separately.
+ for (SCTAB nTab = nStartTab; nTab <= nEndTab; nTab++) {
+ for (SCCOL nCol = nStartCol; nCol <= nEndCol; nCol++) {
+ ScRange aSubRange(ScAddress(nCol, nStartRow, nTab), ScAddress(nCol, nEndRow, nTab));
+ bAllConverted = bAllConverted &&
+ convertCellUnitsForColumnRange(aSubRange, pDoc, aOutputUnit);
+ }
+ }
+ }
return bAllConverted;
}
diff --git a/sc/source/core/units/unitsimpl.hxx b/sc/source/core/units/unitsimpl.hxx
index e7b4597840c0..58e0971cfe68 100644
--- a/sc/source/core/units/unitsimpl.hxx
+++ b/sc/source/core/units/unitsimpl.hxx
@@ -103,7 +103,7 @@ public:
const OUString& rsNewUnit,
const OUString& rsOldUnit) SAL_OVERRIDE;
- virtual bool convertCellUnits(const ScRange& rRange,
+ virtual bool convertCellUnits(const ScRangeList& rRanges,
ScDocument* pDoc,
const OUString& rsOutputUnit) SAL_OVERRIDE;