summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorRegina Henschel <rb.henschel@t-online.de>2020-11-19 21:16:33 +0100
committerRegina Henschel <rb.henschel@t-online.de>2020-11-20 10:17:17 +0100
commitbba0cd79984875124f8d43d05d4cdb7f63517e77 (patch)
treeffd29582615b631486c0e1b84118b44a0ed634db /sc
parentc9568a9800d8609d89fb54912ffb0d445681d18e (diff)
Replace matrix translate with object Move
TR*BaseGeometry is faulty for SdrMeasureObj, fixing these methods is a larger effort and Move is simpler anyway. So I replace the translation using matrices with the Move methods for objects. Backup and restore of the geometry values in state HiddenAsZero is now done with SdrObjGeoData. That is known to work from use in Undo methods. Change-Id: Ic32e8dbc5ae5f1a2f80e428448abc4b4a530b76b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106189 Tested-by: Jenkins Reviewed-by: Regina Henschel <rb.henschel@t-online.de>
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/data/ods/measurelineHideColSave.odsbin0 -> 9641 bytes
-rw-r--r--sc/qa/unit/scshapetest.cxx74
-rw-r--r--sc/source/filter/xml/xmlexprt.cxx28
3 files changed, 87 insertions, 15 deletions
diff --git a/sc/qa/unit/data/ods/measurelineHideColSave.ods b/sc/qa/unit/data/ods/measurelineHideColSave.ods
new file mode 100644
index 000000000000..0cca41897e7a
--- /dev/null
+++ b/sc/qa/unit/data/ods/measurelineHideColSave.ods
Binary files differ
diff --git a/sc/qa/unit/scshapetest.cxx b/sc/qa/unit/scshapetest.cxx
index c8753cb99aa9..5ecd4eef9068 100644
--- a/sc/qa/unit/scshapetest.cxx
+++ b/sc/qa/unit/scshapetest.cxx
@@ -17,6 +17,7 @@
#include <comphelper/propertyvalue.hxx>
#include <sfx2/dispatch.hxx>
#include <svx/svdoashp.hxx>
+#include <svx/svdomeas.hxx>
#include <svx/svdpage.hxx>
#include <unotools/tempfile.hxx>
@@ -37,6 +38,7 @@ public:
ScShapeTest();
void saveAndReload(css::uno::Reference<css::lang::XComponent>& xComponent,
const OUString& rFilter);
+ void testMeasurelineHideColSave();
void testHideColsShow();
void testTdf138138_MoveCellWithRotatedShape();
void testLoadVerticalFlip();
@@ -47,6 +49,7 @@ public:
void testCustomShapeCellAnchoredRotatedShape();
CPPUNIT_TEST_SUITE(ScShapeTest);
+ CPPUNIT_TEST(testMeasurelineHideColSave);
CPPUNIT_TEST(testHideColsShow);
CPPUNIT_TEST(testTdf138138_MoveCellWithRotatedShape);
CPPUNIT_TEST(testLoadVerticalFlip);
@@ -108,6 +111,77 @@ static void lcl_AssertRectEqualWithTolerance(const OString& sInfo,
std::abs(rExpected.GetHeight() - rActual.GetHeight()) <= nTolerance);
}
+static void lcl_AssertPointEqualWithTolerance(const OString& sInfo, const Point rExpected,
+ const Point rActual, const sal_Int32 nTolerance)
+{
+ // X
+ OString sMsg = sInfo + " X expected " + OString::number(rExpected.X()) + " actual "
+ + OString::number(rActual.X()) + " Tolerance " + OString::number(nTolerance);
+ CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.X() - rActual.X()) <= nTolerance);
+ // Y
+ sMsg = sInfo + " Y expected " + OString::number(rExpected.Y()) + " actual "
+ + OString::number(rActual.Y()) + " Tolerance " + OString::number(nTolerance);
+ CPPUNIT_ASSERT_MESSAGE(sMsg.getStr(), std::abs(rExpected.Y() - rActual.Y()) <= nTolerance);
+}
+
+void ScShapeTest::testMeasurelineHideColSave()
+{
+ // The document contains a SdrMeasureObj anchored "To Cell (resive with cell)" with start in cell
+ // D11 and end in cell I5. Error was, that after hiding col A and saving, start and end point
+ // position were lost.
+ OUString aFileURL;
+ createFileURL("measurelineHideColSave.ods", aFileURL);
+ uno::Reference<css::lang::XComponent> xComponent = loadFromDesktop(aFileURL);
+ CPPUNIT_ASSERT(xComponent.is());
+
+ // Get the document model
+ SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
+ CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
+ ScDocShell* pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+ CPPUNIT_ASSERT(pDocSh);
+
+ // Get document and shape
+ ScDocument& rDoc = pDocSh->GetDocument();
+ ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
+ CPPUNIT_ASSERT_MESSAGE("No ScDrawLayer", pDrawLayer);
+ const SdrPage* pPage = pDrawLayer->GetPage(0);
+ CPPUNIT_ASSERT_MESSAGE("No draw page", pPage);
+ SdrObject* pObj = pPage->GetObj(0);
+ CPPUNIT_ASSERT_MESSAGE("No object found", pObj);
+
+ // Make sure loading is correct
+ Point aStartPoint(7500, 15000); // according UI
+ Point aEndPoint(17500, 8000);
+ lcl_AssertPointEqualWithTolerance("Load start: ", aStartPoint, pObj->GetPoint(0), 1);
+ lcl_AssertPointEqualWithTolerance("Load end: ", aEndPoint, pObj->GetPoint(1), 1);
+
+ // Hide column A, save and reload
+ rDoc.SetColHidden(0, 0, 0, true);
+ saveAndReload(xComponent, "calc8");
+ CPPUNIT_ASSERT(xComponent);
+
+ // Get ScDocShell
+ pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
+ CPPUNIT_ASSERT_MESSAGE("Reload: Failed to access document shell", pFoundShell);
+ pDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
+ CPPUNIT_ASSERT(pDocSh);
+
+ // Get document and object
+ ScDocument& rDoc2 = pDocSh->GetDocument();
+ pDrawLayer = rDoc2.GetDrawLayer();
+ CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer);
+ pPage = pDrawLayer->GetPage(0);
+ CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage);
+ pObj = pPage->GetObj(0);
+ CPPUNIT_ASSERT_MESSAGE("Reload: custom shape no longer exists", pObj);
+
+ // Check that start and end point are unchanged
+ lcl_AssertPointEqualWithTolerance("Reload start: ", aStartPoint, pObj->GetPoint(0), 1);
+ lcl_AssertPointEqualWithTolerance("Reload end: ", aEndPoint, pObj->GetPoint(1), 1);
+
+ pDocSh->DoClose();
+}
+
void ScShapeTest::testHideColsShow()
{
// The document contains a shape anchored "To Cell (resive with cell)" with starts in cell C3 and
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 0acd2d6708d5..1f31e5d52c6d 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -3475,12 +3475,12 @@ void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
if( !(rMyCell.bHasShape && !rMyCell.aShapeList.empty() && pDoc) )
return;
- tools::Rectangle aRectFull = pDoc->GetMMRect(rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(),
- rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Tab(),
- false /*bHiddenAsZero*/);
- tools::Rectangle aRectReduced = pDoc->GetMMRect(rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(),
- rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Tab(),
- true /*bHiddenAsZero*/);
+ tools::Rectangle aRectFull = pDoc->GetMMRect(
+ rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Col(),
+ rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Tab(), false /*bHiddenAsZero*/);
+ tools::Rectangle aRectReduced = pDoc->GetMMRect(
+ rMyCell.maCellAddress.Col(), rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Col(),
+ rMyCell.maCellAddress.Row(), rMyCell.maCellAddress.Tab(), true /*bHiddenAsZero*/);
// Reference point
awt::Point aPoint;
@@ -3495,10 +3495,11 @@ void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
{
if (rShape.xShape.is())
{
- basegfx::B2DPolyPolygon aPolyPolygonOrig;
- basegfx::B2DHomMatrix aMatrixOrig;
bool bNeedsRestore = false;
SdrObject* pObj = GetSdrObjectFromXShape(rShape.xShape);
+ SdrObjGeoData* pGeoData = nullptr;
+ if (pObj)
+ pGeoData = pObj->GetGeoData();
if (pObj && aRectFull != aRectReduced)
{
@@ -3507,11 +3508,8 @@ void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
// needs it as if there were no hidden rows or columns.
// We shift the object and restore it later.
bNeedsRestore = true;
- pObj->TRGetBaseGeometry(aMatrixOrig, aPolyPolygonOrig);
- basegfx::B2DHomMatrix aMatrixFull(aMatrixOrig);
- aMatrixFull.translate(aRectFull.Left() - aRectReduced.Left(),
- aRectFull.Top() - aRectReduced.Top());
- pObj->TRSetBaseGeometry(aMatrixFull, aPolyPolygonOrig);
+ pObj->NbcMove(Size(aRectFull.Left() - aRectReduced.Left(),
+ aRectFull.Top() - aRectReduced.Top()));
}
// ToDo: Adapt object skew and rotation to bHiddenAsZero=false, tdf#137033
@@ -3537,8 +3535,8 @@ void ScXMLExport::WriteShapes(const ScMyCell& rMyCell)
ExportShape(rShape.xShape, &aPoint);
// Restore object geometry
- if (bNeedsRestore)
- pObj->TRSetBaseGeometry(aMatrixOrig, aPolyPolygonOrig);
+ if (bNeedsRestore && pObj && pGeoData)
+ pObj->SetGeoData(*pGeoData);
}
}
}