[Libreoffice-commits] core.git: sc/inc sc/qa sc/source
Samuel Mehrbrodt
Samuel.Mehrbrodt at cib.de
Fri Jan 26 20:29:37 UTC 2018
sc/inc/drwlayer.hxx | 1
sc/qa/unit/ucalc.hxx | 2 +
sc/qa/unit/ucalc_sort.cxx | 62 +++++++++++++++++++++++++++++++++++++++
sc/source/core/data/column.cxx | 21 +------------
sc/source/core/data/drwlayer.cxx | 24 +++++++++++++++
5 files changed, 91 insertions(+), 19 deletions(-)
New commits:
commit 9f329c08e6b7e87879545c1bd78a4d3435fc44e4
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date: Mon Jan 22 12:46:11 2018 +0100
tdf#98931 Test for sorting images
Change-Id: Ia9bbdfefc4f8ef2948d497391cdc1e9c760f1f64
Reviewed-on: https://gerrit.libreoffice.org/48310
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Eike Rathke <erack at redhat.com>
diff --git a/sc/inc/drwlayer.hxx b/sc/inc/drwlayer.hxx
index 8f33dbebf721..56c820d465d3 100644
--- a/sc/inc/drwlayer.hxx
+++ b/sc/inc/drwlayer.hxx
@@ -183,6 +183,7 @@ public:
static void UpdateCellAnchorFromPositionEnd( const SdrObject &rObj, ScDrawObjData &rAnchor, const ScDocument &rDoc, SCTAB nTab, bool bUseLogicRect = true );
static ScAnchorType GetAnchorType( const SdrObject& );
std::vector<SdrObject*> GetObjectsAnchoredToCell(const ScAddress& rPos);
+ void MoveObject(SdrObject* pObj, ScAddress& rNewPosition);
// positions for detektive lines
static ScDrawObjData* GetObjData( SdrObject* pObj, bool bCreate=false );
diff --git a/sc/qa/unit/ucalc.hxx b/sc/qa/unit/ucalc.hxx
index 74729debe9ea..81d100254f93 100644
--- a/sc/qa/unit/ucalc.hxx
+++ b/sc/qa/unit/ucalc.hxx
@@ -462,6 +462,7 @@ public:
void testSortBroadcastBroadcaster();
void testSortOutOfPlaceResult();
void testSortPartialFormulaGroup();
+ void testSortImages();
void testNoteBasic();
void testNoteDeleteRow();
@@ -764,6 +765,7 @@ public:
CPPUNIT_TEST(testSortBroadcastBroadcaster);
CPPUNIT_TEST(testSortOutOfPlaceResult);
CPPUNIT_TEST(testSortPartialFormulaGroup);
+ CPPUNIT_TEST(testSortImages);
CPPUNIT_TEST(testShiftCells);
CPPUNIT_TEST(testNoteBasic);
CPPUNIT_TEST(testNoteDeleteRow);
diff --git a/sc/qa/unit/ucalc_sort.cxx b/sc/qa/unit/ucalc_sort.cxx
index 922856bcae96..eb7d1b79039e 100644
--- a/sc/qa/unit/ucalc_sort.cxx
+++ b/sc/qa/unit/ucalc_sort.cxx
@@ -21,10 +21,13 @@
#include <docfunc.hxx>
#include <scitems.hxx>
#include <editutil.hxx>
+#include <table.hxx>
#include <sal/config.h>
#include <editeng/wghtitem.hxx>
#include <editeng/postitem.hxx>
+#include <svx/svdocirc.hxx>
+#include <svx/svdpage.hxx>
#include <test/bootstrapfixture.hxx>
void Test::testSort()
@@ -1884,4 +1887,63 @@ void Test::testSortPartialFormulaGroup()
m_pDoc->DeleteTab(0);
}
+void Test::testSortImages()
+{
+ m_pDoc->InsertTab(0, "testSortImages");
+
+ // We need a drawing layer in order to create caption objects.
+ m_pDoc->InitDrawLayer(&getDocShell());
+ ScDrawLayer* pDrawLayer = m_pDoc->GetDrawLayer();
+ CPPUNIT_ASSERT(pDrawLayer);
+
+ ScRange aDataRange;
+ ScAddress aPos(0,0,0);
+ {
+ const char* aData[][1] = {
+ { "2" },
+ { "1" },
+ };
+
+ clearRange(m_pDoc, ScRange(0, 0, 0, 1, SAL_N_ELEMENTS(aData), 0));
+ aDataRange = insertRangeData(m_pDoc, aPos, aData, SAL_N_ELEMENTS(aData));
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("failed to insert range data at correct position", aPos, aDataRange.aStart);
+ }
+
+ // Insert graphic in cell B2.
+ const tools::Rectangle aOrigRect = tools::Rectangle(1000, 1000, 1200, 1200);
+ SdrCircObj* pObj = new SdrCircObj(OBJ_CIRC, aOrigRect);
+ SdrPage* pPage = pDrawLayer->GetPage(0);
+ CPPUNIT_ASSERT(pPage);
+ pPage->InsertObject(pObj);
+ // Anchor to cell
+ ScDrawLayer::SetCellAnchoredFromPosition(*pObj, *m_pDoc, 0);
+ // Move to cell B2
+ ScAddress aCellPos(1, 1, 0);
+ pDrawLayer->MoveObject(pObj, aCellPos);
+
+ std::vector<SdrObject*> pObjects = pDrawLayer->GetObjectsAnchoredToCell(aCellPos);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pObjects.size());
+
+ ScSortParam aSortData;
+ aSortData.nCol1 = 0;
+ aSortData.nCol2 = 1;
+ aSortData.nRow1 = 0;
+ aSortData.nRow2 = 1;
+ aSortData.maKeyState[0].bDoSort = true;
+ aSortData.maKeyState[0].nField = 0;
+ aSortData.maKeyState[0].bAscending = true;
+
+ m_pDoc->Sort(0, aSortData, false, true, nullptr, nullptr);
+
+ double nVal = m_pDoc->GetValue(0,0,0);
+ ASSERT_DOUBLES_EQUAL(nVal, 1.0);
+
+ // check that note is also moved after sorting
+ aCellPos = ScAddress(1, 0, 0);
+ pObjects = pDrawLayer->GetObjectsAnchoredToCell(aCellPos);
+ CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pObjects.size());
+
+ m_pDoc->DeleteTab(0);
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 24d825901483..e8d773f6923f 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -1912,29 +1912,12 @@ void ScColumn::UpdateDrawObjectsForRow( std::vector<SdrObject*>& pObjects, SCCOL
{
for (auto &pObject : pObjects)
{
- // Get anchor data
- ScDrawObjData* pObjData = ScDrawLayer::GetObjData(pObject, false);
- if (!pObjData)
- continue;
- const ScAddress aOldStart = pObjData->maStart;
- const ScAddress aOldEnd = pObjData->maEnd;
-
- // Set start address
- ScAddress aNewStart = ScAddress(nTargetCol, nTargetRow, nTab);
- pObjData->maStart = aNewStart;
-
- // Set end address
- const SCCOL nObjectColSpan = aOldEnd.Col() - aOldStart.Col();
- const SCROW nObjectRowSpan = aOldEnd.Row() - aOldStart.Row();
- ScAddress aNewEnd = aNewStart;
- aNewEnd.IncRow(nObjectRowSpan);
- aNewEnd.IncCol(nObjectColSpan);
- pObjData->maEnd = aNewEnd;
+ ScAddress aNewAddress = ScAddress(nTargetCol, nTargetRow, nTab);
// Update draw object according to new anchor
ScDrawLayer* pDrawLayer = GetDoc()->GetDrawLayer();
if (pDrawLayer)
- pDrawLayer->RecalcPos(pObject, *pObjData, false, false);
+ pDrawLayer->MoveObject(pObject, aNewAddress);
}
}
diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx
index 3d5507bea459..7f2124d98755 100644
--- a/sc/source/core/data/drwlayer.cxx
+++ b/sc/source/core/data/drwlayer.cxx
@@ -2017,6 +2017,30 @@ std::vector<SdrObject*> ScDrawLayer::GetObjectsAnchoredToCell(const ScAddress& r
return pObjects;
}
+void ScDrawLayer::MoveObject(SdrObject* pObject, ScAddress& rNewPosition)
+{
+ // Get anchor data
+ ScDrawObjData* pObjData = GetObjData(pObject, false);
+ if (!pObjData)
+ return;
+ const ScAddress aOldStart = pObjData->maStart;
+ const ScAddress aOldEnd = pObjData->maEnd;
+
+ // Set start address
+ pObjData->maStart = rNewPosition;
+
+ // Set end address
+ const SCCOL nObjectColSpan = aOldEnd.Col() - aOldStart.Col();
+ const SCROW nObjectRowSpan = aOldEnd.Row() - aOldStart.Row();
+ ScAddress aNewEnd = rNewPosition;
+ aNewEnd.IncRow(nObjectRowSpan);
+ aNewEnd.IncCol(nObjectColSpan);
+ pObjData->maEnd = aNewEnd;
+
+ // Update draw object according to new anchor
+ RecalcPos(pObject, *pObjData, false, false);
+}
+
ScDrawObjData* ScDrawLayer::GetNonRotatedObjData( SdrObject* pObj, bool bCreate )
{
sal_uInt16 nCount = pObj ? pObj->GetUserDataCount() : 0;
More information about the Libreoffice-commits
mailing list