sc/inc/document.hxx               |   14 +++++++-------
 sc/inc/table.hxx                  |    8 ++++----
 sc/qa/unit/ucalc.cxx              |   19 +++++++++++++++++++
 sc/source/core/data/document.cxx  |   12 ++++++------
 sc/source/core/data/table2.cxx    |    7 +++----
 sc/source/filter/xml/xmlexprt.cxx |    8 ++++----
 6 files changed, 43 insertions(+), 25 deletions(-)

New commits:
commit b8720d1e1f0842d52f1830c48ef7551b1868ae6f
Author:     Luboš Luňák <l.lu...@collabora.com>
AuthorDate: Fri Mar 25 12:42:58 2022 +0100
Commit:     Luboš Luňák <l.lu...@collabora.com>
CommitDate: Fri Mar 25 15:20:58 2022 +0100

    fix ScTable::GetLastChangedCol() for unallocated columns
    
    Column flags and widths are stored separately from ScColumn data,
    and so don't depend on allocated columns count.
    
    Also rename the functions from the misleading generic name to what
    they actually do.
    
    Change-Id: If85ae80efda1d8b382fa3b559aa65be0292e25ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132114
    Tested-by: Jenkins
    Reviewed-by: Luboš Luňák <l.lu...@collabora.com>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index cd7138b3e945..639166319366 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -2025,17 +2025,17 @@ public:
      */
     void                        SyncColRowFlags();
 
-                    /// @return  the index of the last row with any set flags 
(auto-pagebreak is ignored).
+    /// @return  the index of the last row with any set flags (auto-pagebreak 
is ignored).
     SC_DLLPUBLIC SCROW          GetLastFlaggedRow( SCTAB nTab ) const;
 
-                    /// @return  the index of the last changed column (flags 
and column width, auto pagebreak is ignored).
-    SCCOL           GetLastChangedCol( SCTAB nTab ) const;
-                    /// @return  the index of the last changed row (flags and 
row height, auto pagebreak is ignored).
-    SCROW           GetLastChangedRow( SCTAB nTab ) const;
+    /// @return  the index of the last changed column (flags and column width, 
auto pagebreak is ignored).
+    SCCOL           GetLastChangedColFlagsWidth( SCTAB nTab ) const;
+    /// @return  the index of the last changed row (flags and row height, auto 
pagebreak is ignored).
+    SCROW           GetLastChangedRowFlagsWidth( SCTAB nTab ) const;
 
-    SCCOL           GetNextDifferentChangedCol( SCTAB nTab, SCCOL nStart) 
const;
+    SCCOL           GetNextDifferentChangedColFlagsWidth( SCTAB nTab, SCCOL 
nStart) const;
 
-    SCROW           GetNextDifferentChangedRow( SCTAB nTab, SCROW nStart) 
const;
+    SCROW           GetNextDifferentChangedRowFlagsWidth( SCTAB nTab, SCROW 
nStart) const;
 
     // returns whether to export a Default style for this col or not
     // nDefault is set to one position in the current row where the Default 
style is
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 58fb6c4a45ad..a885067f5649 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -870,10 +870,10 @@ public:
                 /// @return  the index of the last row with any set flags 
(auto-pagebreak is ignored).
     SCROW      GetLastFlaggedRow() const;
 
-                /// @return  the index of the last changed column (flags and 
column width, auto pagebreak is ignored).
-    SCCOL      GetLastChangedCol() const;
-                /// @return  the index of the last changed row (flags and row 
height, auto pagebreak is ignored).
-    SCROW      GetLastChangedRow() const;
+    /// @return  the index of the last changed column (flags and column width, 
auto pagebreak is ignored).
+    SCCOL      GetLastChangedColFlagsWidth() const;
+    /// @return  the index of the last changed row (flags and row height, auto 
pagebreak is ignored).
+    SCROW      GetLastChangedRowFlagsWidth() const;
 
     bool       IsDataFiltered(SCCOL nColStart, SCROW nRowStart, SCCOL nColEnd, 
SCROW nRowEnd) const;
     bool       IsDataFiltered(const ScRange& rRange) const;
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index 895d5a96bf89..020e43c6dbde 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -117,6 +117,7 @@ public:
     void testValueIterator();
     void testHorizontalAttrIterator();
     void testIteratorsUnallocatedColumnsAttributes();
+    void testLastChangedColFlagsWidth();
 
     /**
      * More direct test for cell broadcaster management, used to track formula
@@ -250,6 +251,7 @@ public:
     CPPUNIT_TEST(testValueIterator);
     CPPUNIT_TEST(testHorizontalAttrIterator);
     CPPUNIT_TEST(testIteratorsUnallocatedColumnsAttributes);
+    CPPUNIT_TEST(testLastChangedColFlagsWidth);
     CPPUNIT_TEST(testCellBroadcaster);
     CPPUNIT_TEST(testFuncParam);
     CPPUNIT_TEST(testNamedRange);
@@ -1456,6 +1458,23 @@ void Test::testIteratorsUnallocatedColumnsAttributes()
     m_pDoc->DeleteTab(0);
 }
 
+void Test::testLastChangedColFlagsWidth()
+{
+    m_pDoc->InsertTab(0, "Tab1");
+
+    constexpr SCCOL firstChangedCol = 100;
+    assert( firstChangedCol > INITIALCOLCOUNT );
+    for( SCCOL col = firstChangedCol; col <= m_pDoc->MaxCol(); ++col )
+        m_pDoc->SetColWidth( col, 0, 10 );
+
+    // That shouldn't need allocating more columns, just changing column flags.
+    CPPUNIT_ASSERT_EQUAL(SCCOL(INITIALCOLCOUNT), 
m_pDoc->GetAllocatedColumnsCount(0));
+    // But the flags are changed.
+    CPPUNIT_ASSERT_EQUAL(m_pDoc->MaxCol(), 
m_pDoc->GetLastChangedColFlagsWidth(0));
+
+    m_pDoc->DeleteTab(0);
+}
+
 namespace {
 
 bool broadcasterShifted(const ScDocument& rDoc, const ScAddress& rFrom, const 
ScAddress& rTo)
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 1750ae956b52..a1ac0e0d2ec9 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -4596,21 +4596,21 @@ SCROW ScDocument::GetLastFlaggedRow( SCTAB nTab ) const
     return 0;
 }
 
-SCCOL ScDocument::GetLastChangedCol( SCTAB nTab ) const
+SCCOL ScDocument::GetLastChangedColFlagsWidth( SCTAB nTab ) const
 {
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab] )
-        return maTabs[nTab]->GetLastChangedCol();
+        return maTabs[nTab]->GetLastChangedColFlagsWidth();
     return 0;
 }
 
-SCROW ScDocument::GetLastChangedRow( SCTAB nTab ) const
+SCROW ScDocument::GetLastChangedRowFlagsWidth( SCTAB nTab ) const
 {
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab] )
-        return maTabs[nTab]->GetLastChangedRow();
+        return maTabs[nTab]->GetLastChangedRowFlagsWidth();
     return 0;
 }
 
-SCCOL ScDocument::GetNextDifferentChangedCol( SCTAB nTab, SCCOL nStart) const
+SCCOL ScDocument::GetNextDifferentChangedColFlagsWidth( SCTAB nTab, SCCOL 
nStart) const
 {
     if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && 
maTabs[nTab] )
     {
@@ -4628,7 +4628,7 @@ SCCOL ScDocument::GetNextDifferentChangedCol( SCTAB nTab, 
SCCOL nStart) const
     return 0;
 }
 
-SCROW ScDocument::GetNextDifferentChangedRow( SCTAB nTab, SCROW nStart) const
+SCROW ScDocument::GetNextDifferentChangedRowFlagsWidth( SCTAB nTab, SCROW 
nStart) const
 {
     if (!ValidTab(nTab) || nTab >= static_cast<SCTAB>(maTabs.size()) || 
!maTabs[nTab])
         return 0;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 27ceaddf4097..7ffc82c3569f 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -3845,22 +3845,21 @@ SCROW ScTable::GetLastFlaggedRow() const
     return nLastFound;
 }
 
-SCCOL ScTable::GetLastChangedCol() const
+SCCOL ScTable::GetLastChangedColFlagsWidth() const
 {
     if ( !mpColFlags )
         return 0;
 
     SCCOL nLastFound = 0;
-    const auto nColSize = aCol.size();
     auto colWidthIt = mpColWidth->begin() + 1;
-    for (SCCOL nCol = 1; nCol < nColSize; (++nCol < nColSize) ? ++colWidthIt : 
(void)false)
+    for (SCCOL nCol = 1; nCol <= GetDoc().MaxCol(); (++nCol <= 
GetDoc().MaxCol()) ? ++colWidthIt : (void)false)
         if ((mpColFlags->GetValue(nCol) & CRFlags::All) || (*colWidthIt != 
STD_COL_WIDTH))
             nLastFound = nCol;
 
     return nLastFound;
 }
 
-SCROW ScTable::GetLastChangedRow() const
+SCROW ScTable::GetLastChangedRowFlagsWidth() const
 {
     if ( !pRowFlags )
         return 0;
diff --git a/sc/source/filter/xml/xmlexprt.cxx 
b/sc/source/filter/xml/xmlexprt.cxx
index ab1ba651823d..daee5e716d9e 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2532,7 +2532,7 @@ void ScXMLExport::collectAutoStyles()
                 uno::Reference<table::XTableColumns> 
xTableColumns(xColumnRowRange->getColumns());
                 if (xTableColumns.is())
                 {
-                    sal_Int32 
nColumns(pDoc->GetLastChangedCol(sal::static_int_cast<SCTAB>(nTable)));
+                    sal_Int32 
nColumns(pDoc->GetLastChangedColFlagsWidth(sal::static_int_cast<SCTAB>(nTable)));
                     pSharedData->SetLastColumn(nTable, nColumns);
                     table::CellRangeAddress 
aCellAddress(GetEndAddress(xTable));
                     if (aCellAddress.EndColumn > nColumns)
@@ -2554,7 +2554,7 @@ void ScXMLExport::collectAutoStyles()
                             pColumnStyles->AddFieldStyleName(nTable, nColumn, 
nIndex, bIsVisible);
                         }
                         sal_Int32 nOld(nColumn);
-                        nColumn = 
pDoc->GetNextDifferentChangedCol(sal::static_int_cast<SCTAB>(nTable), 
static_cast<SCCOL>(nColumn));
+                        nColumn = 
pDoc->GetNextDifferentChangedColFlagsWidth(sal::static_int_cast<SCTAB>(nTable), 
static_cast<SCCOL>(nColumn));
                         for (sal_Int32 i = nOld + 1; i < nColumn; ++i)
                             pColumnStyles->AddFieldStyleName(nTable, i, 
nIndex, bIsVisible);
                     }
@@ -2569,7 +2569,7 @@ void ScXMLExport::collectAutoStyles()
                 uno::Reference<table::XTableRows> 
xTableRows(xColumnRowRange->getRows());
                 if (xTableRows.is())
                 {
-                    sal_Int32 
nRows(pDoc->GetLastChangedRow(sal::static_int_cast<SCTAB>(nTable)));
+                    sal_Int32 
nRows(pDoc->GetLastChangedRowFlagsWidth(sal::static_int_cast<SCTAB>(nTable)));
                     pSharedData->SetLastRow(nTable, nRows);
 
                     pRowStyles->AddNewTable(nTable, pDoc->MaxRow());
@@ -2584,7 +2584,7 @@ void ScXMLExport::collectAutoStyles()
                             pRowStyles->AddFieldStyleName(nTable, nRow, 
nIndex);
                         }
                         sal_Int32 nOld(nRow);
-                        nRow = 
pDoc->GetNextDifferentChangedRow(sal::static_int_cast<SCTAB>(nTable), 
static_cast<SCROW>(nRow));
+                        nRow = 
pDoc->GetNextDifferentChangedRowFlagsWidth(sal::static_int_cast<SCTAB>(nTable), 
static_cast<SCROW>(nRow));
                         if (nRow > nOld + 1)
                             pRowStyles->AddFieldStyleName(nTable, nOld + 1, 
nIndex, nRow - 1);
                     }

Reply via email to