[Libreoffice-commits] core.git: sc/inc sc/qa sc/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Thu Jan 7 07:56:48 UTC 2021


 sc/inc/document.hxx                   |    2 +-
 sc/inc/table.hxx                      |    2 +-
 sc/qa/unit/subsequent_export-test.cxx |   12 ++++++------
 sc/source/core/data/documen3.cxx      |    2 +-
 sc/source/core/data/table5.cxx        |    2 +-
 sc/source/filter/xcl97/xcl97rec.cxx   |    2 +-
 sc/source/filter/xml/xmlexprt.cxx     |    2 +-
 sc/source/ui/docshell/docfunc.cxx     |    4 ++--
 sc/source/ui/vba/vbaworksheet.cxx     |   12 +++++++-----
 sc/source/ui/view/gridwin.cxx         |    2 +-
 sc/source/ui/view/select.cxx          |    2 +-
 sc/source/ui/view/tabview2.cxx        |   10 +++++-----
 sc/source/ui/view/tabview3.cxx        |    2 +-
 sc/source/ui/view/tabvwsh3.cxx        |    4 ++--
 14 files changed, 31 insertions(+), 29 deletions(-)

New commits:
commit 85b400482dee5c9da2cf83a755ec37ab149b5b20
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Wed Jan 6 15:02:17 2021 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Thu Jan 7 08:55:55 2021 +0100

    ScTable::GetProtection and ScDocument::GetTabProtection can be const
    
    Change-Id: Ic30a3fe10ae6206e876a05bed5dc189a9516b452
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108851
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <mike.kaganski at collabora.com>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 1dd00f732cbf..e7ebb3653138 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -900,7 +900,7 @@ public:
     SC_DLLPUBLIC bool                  IsDocProtected() const;
     bool                               IsDocEditable() const;
     SC_DLLPUBLIC bool                  IsTabProtected( SCTAB nTab ) const;
-    SC_DLLPUBLIC    ScTableProtection* GetTabProtection( SCTAB nTab ) const;
+    SC_DLLPUBLIC const ScTableProtection* GetTabProtection(SCTAB nTab) const;
     SC_DLLPUBLIC void                  SetTabProtection(SCTAB nTab, const ScTableProtection* pProtect);
     void                               CopyTabProtection(SCTAB nTabSrc, SCTAB nTabDest);
 
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 9edf642f6f46..1962290cb862 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -381,7 +381,7 @@ public:
 
     bool            IsProtected() const;
     void            SetProtection(const ScTableProtection* pProtect);
-    ScTableProtection* GetProtection();
+    const ScTableProtection* GetProtection() const;
     void            GetUnprotectedCells( ScRangeList& rRangeList ) const;
 
     bool IsEditActionAllowed( sc::ColRowEditAction eAction, SCCOLROW nStart, SCCOLROW nEnd ) const;
diff --git a/sc/qa/unit/subsequent_export-test.cxx b/sc/qa/unit/subsequent_export-test.cxx
index 8f471b175148..1f8b648d81c6 100644
--- a/sc/qa/unit/subsequent_export-test.cxx
+++ b/sc/qa/unit/subsequent_export-test.cxx
@@ -770,7 +770,7 @@ void ScExportTest::testProtectionKeyODS_UTF16LErtlSHA1()
     ScDocument& rDoc = xShell->GetDocument();
     ScDocProtection *const pDocProt(rDoc.GetDocProtection());
     CPPUNIT_ASSERT(pDocProt->verifyPassword(password));
-    ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
+    const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
     CPPUNIT_ASSERT(pTabProt->verifyPassword(password));
 
     // we can't assume that the user entered the password; check that we
@@ -793,7 +793,7 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA1()
     ScDocument& rDoc = xShell->GetDocument();
     ScDocProtection *const pDocProt(rDoc.GetDocProtection());
     CPPUNIT_ASSERT(pDocProt->verifyPassword(password));
-    ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
+    const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
     CPPUNIT_ASSERT(pTabProt->verifyPassword(password));
 
     // we can't assume that the user entered the password; check that we
@@ -816,7 +816,7 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA256ODF12()
     ScDocument& rDoc = xShell->GetDocument();
     ScDocProtection *const pDocProt(rDoc.GetDocProtection());
     CPPUNIT_ASSERT(pDocProt->verifyPassword(password));
-    ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
+    const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
     CPPUNIT_ASSERT(pTabProt->verifyPassword(password));
 
     // we can't assume that the user entered the password; check that we
@@ -839,7 +839,7 @@ void ScExportTest::testProtectionKeyODS_UTF8SHA256W3C()
     ScDocument& rDoc = xShell->GetDocument();
     ScDocProtection *const pDocProt(rDoc.GetDocProtection());
     CPPUNIT_ASSERT(pDocProt->verifyPassword(password));
-    ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
+    const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
     CPPUNIT_ASSERT(pTabProt->verifyPassword(password));
 
     // we can't assume that the user entered the password; check that we
@@ -862,7 +862,7 @@ void ScExportTest::testProtectionKeyODS_XL_SHA1()
     ScDocument& rDoc = xShell->GetDocument();
     ScDocProtection *const pDocProt(rDoc.GetDocProtection());
     CPPUNIT_ASSERT(pDocProt->verifyPassword(password));
-    ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
+    const ScTableProtection *const pTabProt(rDoc.GetTabProtection(0));
     CPPUNIT_ASSERT(pTabProt->verifyPassword(password));
 
     // we can't assume that the user entered the password; check that we
@@ -3450,7 +3450,7 @@ namespace {
 void testSheetProtection_Impl(const ScDocument& rDoc)
 {
     CPPUNIT_ASSERT(rDoc.IsTabProtected(0));
-    ScTableProtection* pTabProtection = rDoc.GetTabProtection(0);
+    const ScTableProtection* pTabProtection = rDoc.GetTabProtection(0);
     CPPUNIT_ASSERT(pTabProtection);
     CPPUNIT_ASSERT(pTabProtection->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS));
     CPPUNIT_ASSERT(!pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS));
diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx
index 4b9e06130f38..b7ece0dfbc0a 100644
--- a/sc/source/core/data/documen3.cxx
+++ b/sc/source/core/data/documen3.cxx
@@ -1895,7 +1895,7 @@ bool ScDocument::IsTabProtected( SCTAB nTab ) const
     return false;
 }
 
-ScTableProtection* ScDocument::GetTabProtection( SCTAB nTab ) const
+const ScTableProtection* ScDocument::GetTabProtection(SCTAB nTab) const
 {
     if (ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab])
         return maTabs[nTab]->GetProtection();
diff --git a/sc/source/core/data/table5.cxx b/sc/source/core/data/table5.cxx
index 31171f72e4ce..21d2b11d8c6e 100644
--- a/sc/source/core/data/table5.cxx
+++ b/sc/source/core/data/table5.cxx
@@ -1095,7 +1095,7 @@ void ScTable::SetProtection(const ScTableProtection* pProtect)
     SetStreamValid(false);
 }
 
-ScTableProtection* ScTable::GetProtection() { return pTabProtection.get(); }
+const ScTableProtection* ScTable::GetProtection() const { return pTabProtection.get(); }
 
 Size ScTable::GetPageSize() const
 {
diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx
index fa374c486ac2..24adafbae8a4 100644
--- a/sc/source/filter/xcl97/xcl97rec.cxx
+++ b/sc/source/filter/xcl97/xcl97rec.cxx
@@ -1680,7 +1680,7 @@ XclExpSheetProtectOptions::XclExpSheetProtectOptions( const XclExpRoot& rRoot, S
     };
 
     mnOptions = 0x0000;
-    ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab);
+    const ScTableProtection* pProtect = rRoot.GetDoc().GetTabProtection(nTab);
     if (!pProtect)
         return;
 
diff --git a/sc/source/filter/xml/xmlexprt.cxx b/sc/source/filter/xml/xmlexprt.cxx
index 768e42d4e279..d69fdd784ef7 100644
--- a/sc/source/filter/xml/xmlexprt.cxx
+++ b/sc/source/filter/xml/xmlexprt.cxx
@@ -2798,7 +2798,7 @@ void ScXMLExport::WriteTable(sal_Int32 nTable, const uno::Reference<sheet::XSpre
     AddAttribute(sAttrStyleName, aTableStyles[nTable]);
 
     uno::Reference<util::XProtectable> xProtectable (xTable, uno::UNO_QUERY);
-    ScTableProtection* pProtect = nullptr;
+    const ScTableProtection* pProtect = nullptr;
     if (xProtectable.is() && xProtectable->isProtected())
     {
         AddAttribute(XML_NAMESPACE_TABLE, XML_PROTECTED, XML_TRUE);
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index e3f914620b35..98e07e22df5e 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -3948,7 +3948,7 @@ void ScDocFunc::ProtectSheet( SCTAB nTab, const ScTableProtection& rProtect )
         if (!p)
         {
             // For protection case, use a copy of resulting ScTableProtection for undo
-            ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+            const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
             p = std::make_unique<ScTableProtection>(*pProtect);
         }
         rDocShell.GetUndoManager()->AddUndoAction(
@@ -4051,7 +4051,7 @@ bool ScDocFunc::Unprotect( SCTAB nTab, const OUString& rPassword, bool bApi )
     {
         // sheet protection
 
-        ScTableProtection* pTabProtect = rDoc.GetTabProtection(nTab);
+        const ScTableProtection* pTabProtect = rDoc.GetTabProtection(nTab);
         if (!pTabProtect || !pTabProtect->isProtected())
             // already unprotected (should not happen)!
             return true;
diff --git a/sc/source/ui/vba/vbaworksheet.cxx b/sc/source/ui/vba/vbaworksheet.cxx
index 8fb72057298e..ff626f86d591 100644
--- a/sc/source/ui/vba/vbaworksheet.cxx
+++ b/sc/source/ui/vba/vbaworksheet.cxx
@@ -314,7 +314,7 @@ ScVbaWorksheet::getEnableSelection()
 
     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW );
     ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
-    ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+    const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
     bool bLockedCells = false;
     bool bUnlockedCells = false;
     if( pProtect )
@@ -347,7 +347,7 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection )
 
     uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW );
     ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
-    ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+    const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
     // default is xlNoSelection
     bool bLockedCells = false;
     bool bUnlockedCells = false;
@@ -362,8 +362,10 @@ ScVbaWorksheet::setEnableSelection( sal_Int32 nSelection )
     }
     if( pProtect )
     {
-        pProtect->setOption( ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells );
-        pProtect->setOption( ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells );
+        ScTableProtection aNewProtect(*pProtect);
+        aNewProtect.setOption(ScTableProtection::SELECT_LOCKED_CELLS, bLockedCells);
+        aNewProtect.setOption(ScTableProtection::SELECT_UNLOCKED_CELLS, bUnlockedCells);
+        rDoc.SetTabProtection(nTab, &aNewProtect);
     }
 
 
@@ -484,7 +486,7 @@ ScVbaWorksheet::getProtectDrawingObjects()
     {
         uno::Reference< frame::XModel > xModel( getModel(), uno::UNO_SET_THROW );
         ScDocument& rDoc = excel::getDocShell( xModel )->GetDocument();
-        ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+        const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
         if ( pProtect )
             return pProtect->isOptionEnabled( ScTableProtection::OBJECTS );
     }
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index 9dadd10d5927..b4cc7e3cf84a 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -2150,7 +2150,7 @@ void ScGridWindow::MouseButtonUp( const MouseEvent& rMEvt )
         }
 
         // Check for cell protection attribute.
-        ScTableProtection* pProtect = rDoc.GetTabProtection( nTab );
+        const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
         bool bEditAllowed = true;
         if ( pProtect && pProtect->isProtected() )
         {
diff --git a/sc/source/ui/view/select.cxx b/sc/source/ui/view/select.cxx
index 0ef0e2059b2b..6e34ff86a6e8 100644
--- a/sc/source/ui/view/select.cxx
+++ b/sc/source/ui/view/select.cxx
@@ -425,7 +425,7 @@ bool ScViewFunctionSet::SetCursorAtCell( SCCOL nPosX, SCROW nPosY, bool bScroll
         if (nPosX < 0 || nPosY < 0)
             return false;
 
-        ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+        const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
         if (!pProtect)
             return false;
 
diff --git a/sc/source/ui/view/tabview2.cxx b/sc/source/ui/view/tabview2.cxx
index ee7be2a2f65c..787aa64fea71 100644
--- a/sc/source/ui/view/tabview2.cxx
+++ b/sc/source/ui/view/tabview2.cxx
@@ -62,7 +62,7 @@ void moveCursorByProtRule(
 {
     bool bSelectLocked = true;
     bool bSelectUnlocked = true;
-    ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab);
+    const ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab);
     if (pTabProtection && pTabProtection->isProtected())
     {
         bSelectLocked   = pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
@@ -186,7 +186,7 @@ void moveCursorByMergedCell(
     SCCOL nOrigX = rViewData.GetCurX();
     SCROW nOrigY = rViewData.GetCurY();
 
-    ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab);
+    const ScTableProtection* pTabProtection = pDoc->GetTabProtection(nTab);
     bool bSelectLocked = true;
     bool bSelectUnlocked = true;
     if (pTabProtection && pTabProtection->isProtected())
@@ -730,7 +730,7 @@ void ScTabView::SkipCursorHorizontal(SCCOL& rCurX, SCROW& rCurY, SCCOL nOldX, SC
     SCTAB nTab = aViewData.GetTabNo();
 
     bool bSkipProtected = false, bSkipUnprotected = false;
-    ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+    const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
     if (pProtect && pProtect->isProtected())
     {
         bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
@@ -790,7 +790,7 @@ void ScTabView::SkipCursorVertical(SCCOL& rCurX, SCROW& rCurY, SCROW nOldY, SCRO
     SCTAB nTab = aViewData.GetTabNo();
 
     bool bSkipProtected = false, bSkipUnprotected = false;
-    ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+    const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
     if (pProtect && pProtect->isProtected())
     {
         bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
@@ -868,7 +868,7 @@ void ScTabView::ExpandBlock(SCCOL nMovX, SCROW nMovY, ScFollowMode eMode)
 
         bool bSelectLocked = true;
         bool bSelectUnlocked = true;
-        ScTableProtection* pTabProtection = rDoc.GetTabProtection(nRefTab);
+        const ScTableProtection* pTabProtection = rDoc.GetTabProtection(nRefTab);
         if (pTabProtection && pTabProtection->isProtected())
         {
             bSelectLocked   = pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
diff --git a/sc/source/ui/view/tabview3.cxx b/sc/source/ui/view/tabview3.cxx
index 4f3d2eaec6b0..29b699a96eb6 100644
--- a/sc/source/ui/view/tabview3.cxx
+++ b/sc/source/ui/view/tabview3.cxx
@@ -1265,7 +1265,7 @@ void ScTabView::MoveCursorRel( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode,
     SCTAB nTab = aViewData.GetTabNo();
 
     bool bSkipProtected = false, bSkipUnprotected = false;
-    ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+    const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
     if ( pProtect && pProtect->isProtected() )
     {
         bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
diff --git a/sc/source/ui/view/tabvwsh3.cxx b/sc/source/ui/view/tabvwsh3.cxx
index b6e401991684..e4c85491b442 100644
--- a/sc/source/ui/view/tabvwsh3.cxx
+++ b/sc/source/ui/view/tabvwsh3.cxx
@@ -1228,7 +1228,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
             {
                 // Unprotect a protected sheet.
 
-                ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+                const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
                 if (pProtect && pProtect->isProtectedWithPass())
                 {
                     OUString aText( ScResId(SCSTR_PASSWORDOPT) );
@@ -1260,7 +1260,7 @@ void ScTabViewShell::Execute( SfxRequest& rReq )
 
                 ScTableProtectionDlg aDlg(GetFrameWeld());
 
-                ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
+                const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
                 if (pProtect)
                     aDlg.SetDialogData(*pProtect);
 


More information about the Libreoffice-commits mailing list