diff options
author | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-05-05 20:50:54 +0100 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2024-05-06 12:23:29 +0200 |
commit | ef2066cdfe86019a3099b3530fb091ca2a4d2446 (patch) | |
tree | 55f514eb6a1c70379a66a376a40631b340e819fb /sc | |
parent | 09c7447e27fcf4b28b51403273b542713006aac8 (diff) |
ScGlobal::GetUserList never returns null
Change-Id: Ibce3fc1b6d85fc6183fc2552a71ead6443b45fad
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167172
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/global.hxx | 2 | ||||
-rw-r--r-- | sc/qa/unit/copy_paste_test.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/global.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/table3.cxx | 6 | ||||
-rw-r--r-- | sc/source/core/data/table4.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/appoptio.cxx | 19 | ||||
-rw-r--r-- | sc/source/filter/excel/excrecds.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/oox/autofilterbuffer.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/app/scmod.cxx | 9 | ||||
-rw-r--r-- | sc/source/ui/dbgui/tpsort.cxx | 11 | ||||
-rw-r--r-- | sc/source/ui/dbgui/tpsubt.cxx | 11 | ||||
-rw-r--r-- | sc/source/ui/unoobj/appluno.cxx | 25 | ||||
-rw-r--r-- | sc/source/ui/view/dbfunc3.cxx | 13 | ||||
-rw-r--r-- | sc/source/ui/view/gridwin2.cxx | 15 |
14 files changed, 61 insertions, 86 deletions
diff --git a/sc/inc/global.hxx b/sc/inc/global.hxx index 5cb782ac14dc..1b512b6a7987 100644 --- a/sc/inc/global.hxx +++ b/sc/inc/global.hxx @@ -571,7 +571,7 @@ public: static void ClearAutoFormat(); //BugId 54209 static LegacyFuncCollection* GetLegacyFuncCollection(); SC_DLLPUBLIC static ScUnoAddInCollection* GetAddInCollection(); - SC_DLLPUBLIC static ScUserList* GetUserList(); + SC_DLLPUBLIC static ScUserList& GetUserList(); static void SetUserList( const ScUserList* pNewList ); /** * Open the specified URL. diff --git a/sc/qa/unit/copy_paste_test.cxx b/sc/qa/unit/copy_paste_test.cxx index 35ed48b6e02e..c64e194de54e 100644 --- a/sc/qa/unit/copy_paste_test.cxx +++ b/sc/qa/unit/copy_paste_test.cxx @@ -609,7 +609,7 @@ void ScCopyPasteTest::tdf137205_autofillDatesInMergedCells() void ScCopyPasteTest::addToUserList(const OUString& rStr) { - ScGlobal::GetUserList()->emplace_back(rStr); + ScGlobal::GetUserList().emplace_back(rStr); } void ScCopyPasteTest::tdf137653_137654_autofillUserlist() @@ -623,9 +623,9 @@ void ScCopyPasteTest::tdf137653_137654_autofillUserlist() ScTabViewShell* pViewShell = ScDocShell::GetViewData()->GetViewShell(); // delete every userlist to make sure there won't be any string that is in 2 different userlist - ScGlobal::GetUserList()->clear(); + ScGlobal::GetUserList().clear(); addToUserList({ "January,February,March,April,May,June,July,August,September,October,November,December" }); - const ScUserListData* pListData = ScGlobal::GetUserList()->GetData("January"); + const ScUserListData* pListData = ScGlobal::GetUserList().GetData("January"); sal_uInt16 nIdx1 = 0, nIdx2 = 0; bool bHasIdx1, bHasIdx2; bool bMatchCase = false; @@ -733,9 +733,9 @@ void ScCopyPasteTest::tdf137625_autofillMergedUserlist() ScTabViewShell* pViewShell = ScDocShell::GetViewData()->GetViewShell(); // delete every userlist to make sure there won't be any string that is in 2 different userlist - ScGlobal::GetUserList()->clear(); + ScGlobal::GetUserList().clear(); addToUserList({ "January,February,March,April,May,June,July,August,September,October,November,December" }); - const ScUserListData* pListData = ScGlobal::GetUserList()->GetData("January"); + const ScUserListData* pListData = ScGlobal::GetUserList().GetData("January"); sal_uInt16 nIdx1 = 0, nIdx2 = 0; bool bHasIdx1, bHasIdx2; bool bMatchCase = false; @@ -794,7 +794,7 @@ void ScCopyPasteTest::tdf137624_autofillMergedMixed() // add 1aa,2bb,3cc,4dd,5ee,6ff to userlist, to test that autofill won't confuse it with 1aa,3aa // delete every userlist to make sure there won't be any string that is in 2 different userlist - ScGlobal::GetUserList()->clear(); + ScGlobal::GetUserList().clear(); addToUserList({ "1aa,2bb,3cc,4dd,5ee,6ff" }); // fillauto mixed (string + number), these areas contain only merged cells diff --git a/sc/source/core/data/global.cxx b/sc/source/core/data/global.cxx index a46f46b3cffb..a4f892b5c766 100644 --- a/sc/source/core/data/global.cxx +++ b/sc/source/core/data/global.cxx @@ -292,7 +292,7 @@ ScUnoAddInCollection* ScGlobal::GetAddInCollection() return comphelper::doubleCheckedInit( pAddInCollection, []() { return new ScUnoAddInCollection(); }); } -ScUserList* ScGlobal::GetUserList() +ScUserList& ScGlobal::GetUserList() { assert(!bThreadedGroupCalcInProgress); // Hack: Load Cfg item at the App @@ -300,7 +300,7 @@ ScUserList* ScGlobal::GetUserList() if (!xUserList) xUserList.reset(new ScUserList()); - return xUserList.get(); + return *xUserList; } void ScGlobal::SetUserList( const ScUserList* pNewList ) diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx index ee00f2d58161..f04bee9432f3 100644 --- a/sc/source/core/data/table3.cxx +++ b/sc/source/core/data/table3.cxx @@ -1494,10 +1494,10 @@ short ScTable::CompareCell( bool bNaturalSort = aSortParam.bNaturalSort; // natural sort bool bCaseSens = aSortParam.bCaseSens; // case sensitivity - ScUserList* pList = ScGlobal::GetUserList(); - if (bUserDef && pList && pList->size() > aSortParam.nUserIndex ) + ScUserList& rList = ScGlobal::GetUserList(); + if (bUserDef && rList.size() > aSortParam.nUserIndex) { - const ScUserListData& rData = (*pList)[aSortParam.nUserIndex]; + const ScUserListData& rData = rList[aSortParam.nUserIndex]; if ( bNaturalSort ) nRes = naturalsort::Compare( aStr1, aStr2, bCaseSens, &rData, pSortCollator ); diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 438608dc8492..a6ddf796a7c6 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -447,7 +447,7 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, OUString aStr = GetString(nColCurr, nRowCurr ); OUString aStr2; - rListData = const_cast<ScUserListData*>(ScGlobal::GetUserList()->GetData(aStr)); + rListData = const_cast<ScUserListData*>(ScGlobal::GetUserList().GetData(aStr)); if (rListData) { bool bMatchCase = false; @@ -684,7 +684,7 @@ void ScTable::FillAnalyse( SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, { OUString aStr = GetString(nCol, nRow); - rListData = const_cast<ScUserListData*>(ScGlobal::GetUserList()->GetData(aStr)); + rListData = const_cast<ScUserListData*>(ScGlobal::GetUserList().GetData(aStr)); if (rListData) { bool bMatchCase = false; diff --git a/sc/source/core/tool/appoptio.cxx b/sc/source/core/tool/appoptio.cxx index 0a4cb09503c1..c35524f9588f 100644 --- a/sc/source/core/tool/appoptio.cxx +++ b/sc/source/core/tool/appoptio.cxx @@ -141,18 +141,13 @@ static void lcl_GetLastFunctions( Any& rDest, const ScAppOptions& rOpt ) static void lcl_GetSortList( Any& rDest ) { - const ScUserList* pUserList = ScGlobal::GetUserList(); - if (pUserList) - { - size_t nCount = pUserList->size(); - Sequence<OUString> aSeq( nCount ); - OUString* pArray = aSeq.getArray(); - for (size_t i=0; i<nCount; ++i) - pArray[i] = (*pUserList)[sal::static_int_cast<sal_uInt16>(i)].GetString(); - rDest <<= aSeq; - } - else - rDest <<= Sequence<OUString>(0); // empty + const ScUserList& rUserList = ScGlobal::GetUserList(); + size_t nCount = rUserList.size(); + Sequence<OUString> aSeq( nCount ); + OUString* pArray = aSeq.getArray(); + for (size_t i=0; i<nCount; ++i) + pArray[i] = rUserList[sal::static_int_cast<sal_uInt16>(i)].GetString(); + rDest <<= aSeq; } constexpr OUStringLiteral CFGPATH_LAYOUT = u"Office.Calc/Layout"; diff --git a/sc/source/filter/excel/excrecds.cxx b/sc/source/filter/excel/excrecds.cxx index f18e9f829bbe..381836c10c12 100644 --- a/sc/source/filter/excel/excrecds.cxx +++ b/sc/source/filter/excel/excrecds.cxx @@ -1061,8 +1061,8 @@ ExcAutoFilterRecs::ExcAutoFilterRecs( const XclExpRoot& rRoot, SCTAB nTab, const ScSortParam aSortParam; pData->GetSortParam( aSortParam ); - ScUserList* pList = ScGlobal::GetUserList(); - if (aSortParam.bUserDef && pList && pList->size() > aSortParam.nUserIndex) + ScUserList& rList = ScGlobal::GetUserList(); + if (aSortParam.bUserDef && rList.size() > aSortParam.nUserIndex) { // get sorted area without headers maSortRef = ScRange( @@ -1070,7 +1070,7 @@ ExcAutoFilterRecs::ExcAutoFilterRecs( const XclExpRoot& rRoot, SCTAB nTab, const aParam.nCol2, aParam.nRow2, aParam.nTab ); // get sorted columns with custom lists - const ScUserListData& rData = (*pList)[aSortParam.nUserIndex]; + const ScUserListData& rData = rList[aSortParam.nUserIndex]; // get column index and sorting direction SCCOLROW nField = 0; diff --git a/sc/source/filter/oox/autofilterbuffer.cxx b/sc/source/filter/oox/autofilterbuffer.cxx index ac1816c6eba6..2aaeae049be1 100644 --- a/sc/source/filter/oox/autofilterbuffer.cxx +++ b/sc/source/filter/oox/autofilterbuffer.cxx @@ -820,12 +820,12 @@ void AutoFilter::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRa aParam.nUserIndex = 0; aParam.bByRow = false; - ScUserList* pUserList = ScGlobal::GetUserList(); + ScUserList& rUserList = ScGlobal::GetUserList(); if (!rSorConditionLoaded.maSortCustomList.isEmpty()) { - for (size_t i=0; pUserList && i < pUserList->size(); i++) + for (size_t i=0; i < rUserList.size(); i++) { - const OUString aEntry((*pUserList)[i].GetString()); + const OUString aEntry(rUserList[i].GetString()); if (aEntry.equalsIgnoreAsciiCase(rSorConditionLoaded.maSortCustomList)) { aParam.bUserDef = true; @@ -837,9 +837,9 @@ void AutoFilter::finalizeImport( const Reference< XDatabaseRange >& rxDatabaseRa if (!aParam.bUserDef) { - pUserList->emplace_back(rSorConditionLoaded.maSortCustomList); + rUserList.emplace_back(rSorConditionLoaded.maSortCustomList); aParam.bUserDef = true; - aParam.nUserIndex = pUserList->size()-1; + aParam.nUserIndex = rUserList.size()-1; } // set sort parameter if we have detected it diff --git a/sc/source/ui/app/scmod.cxx b/sc/source/ui/app/scmod.cxx index 19b521feead9..65d85c499d55 100644 --- a/sc/source/ui/app/scmod.cxx +++ b/sc/source/ui/app/scmod.cxx @@ -1999,7 +1999,7 @@ std::optional<SfxItemSet> ScModule::CreateItemSet( sal_uInt16 nId ) : GetViewOptions(); ScUserListItem aULItem( SCITEM_USERLIST ); - ScUserList* pUL = ScGlobal::GetUserList(); + const ScUserList& rUL = ScGlobal::GetUserList(); // SfxGetpApp()->GetOptions( aSet ); @@ -2048,11 +2048,8 @@ std::optional<SfxItemSet> ScModule::CreateItemSet( sal_uInt16 nId ) pRet->Put( aViewOpt.CreateGridItem() ); // TP_USERLISTS - if ( pUL ) - { - aULItem.SetUserList( *pUL ); - pRet->Put(aULItem); - } + aULItem.SetUserList(rUL); + pRet->Put(aULItem); // TP_COMPATIBILITY pRet->Put( SfxUInt16Item( SID_SC_OPT_KEY_BINDING_COMPAT, diff --git a/sc/source/ui/dbgui/tpsort.cxx b/sc/source/ui/dbgui/tpsort.cxx index a6050ecf8b3f..3cc3e90e3b22 100644 --- a/sc/source/ui/dbgui/tpsort.cxx +++ b/sc/source/ui/dbgui/tpsort.cxx @@ -750,15 +750,12 @@ DeactivateRC ScTabPageSortOptions::DeactivatePage( SfxItemSet* pSetP ) void ScTabPageSortOptions::FillUserSortListBox() { - ScUserList* pUserLists = ScGlobal::GetUserList(); + ScUserList& rUserLists = ScGlobal::GetUserList(); m_xLbSortUser->clear(); - if ( pUserLists ) - { - size_t nCount = pUserLists->size(); - for (size_t i=0; i<nCount; ++i) - m_xLbSortUser->append_text((*pUserLists)[i].GetString()); - } + size_t nCount = rUserLists.size(); + for (size_t i=0; i<nCount; ++i) + m_xLbSortUser->append_text(rUserLists[i].GetString()); } // Handler: diff --git a/sc/source/ui/dbgui/tpsubt.cxx b/sc/source/ui/dbgui/tpsubt.cxx index dd8fabc534e7..4c123f7598c8 100644 --- a/sc/source/ui/dbgui/tpsubt.cxx +++ b/sc/source/ui/dbgui/tpsubt.cxx @@ -537,16 +537,13 @@ bool ScTpSubTotalOptions::FillItemSet( SfxItemSet* rArgSet ) void ScTpSubTotalOptions::FillUserSortListBox() { - ScUserList* pUserLists = ScGlobal::GetUserList(); + ScUserList& rUserLists = ScGlobal::GetUserList(); m_xLbUserDef->freeze(); m_xLbUserDef->clear(); - if ( pUserLists ) - { - size_t nCount = pUserLists->size(); - for ( size_t i=0; i<nCount; ++i ) - m_xLbUserDef->append_text((*pUserLists)[i].GetString() ); - } + size_t nCount = rUserLists.size(); + for ( size_t i=0; i<nCount; ++i ) + m_xLbUserDef->append_text(rUserLists[i].GetString()); m_xLbUserDef->thaw(); } diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx index 26457e43f1b9..3ea47324bf0b 100644 --- a/sc/source/ui/unoobj/appluno.cxx +++ b/sc/source/ui/unoobj/appluno.cxx @@ -248,17 +248,17 @@ void SAL_CALL ScSpreadsheetSettings::setPropertyValue( } else if (aPropertyName == SC_UNONAME_ULISTS) { - ScUserList* pUserList = ScGlobal::GetUserList(); + ScUserList& rUserList = ScGlobal::GetUserList(); uno::Sequence<OUString> aSeq; - if ( pUserList && ( aValue >>= aSeq ) ) + if (aValue >>= aSeq) { // directly change the active list // ScGlobal::SetUseTabCol does not do much else - pUserList->clear(); + rUserList.clear(); for (const OUString& aEntry : aSeq) { - pUserList->emplace_back(aEntry); + rUserList.emplace_back(aEntry); } bSaveApp = true; // List with App-Options are saved } @@ -325,16 +325,13 @@ uno::Any SAL_CALL ScSpreadsheetSettings::getPropertyValue( const OUString& aProp } else if (aPropertyName == SC_UNONAME_ULISTS ) { - ScUserList* pUserList = ScGlobal::GetUserList(); - if (pUserList) - { - size_t nCount = pUserList->size(); - uno::Sequence<OUString> aSeq(nCount); - OUString* pAry = aSeq.getArray(); - for (size_t i=0; i<nCount; ++i) - pAry[i] = (*pUserList)[i].GetString(); - aRet <<= aSeq; - } + const ScUserList& rUserList = ScGlobal::GetUserList(); + size_t nCount = rUserList.size(); + uno::Sequence<OUString> aSeq(nCount); + OUString* pAry = aSeq.getArray(); + for (size_t i=0; i<nCount; ++i) + pAry[i] = rUserList[i].GetString(); + aRet <<= aSeq; } else if (aPropertyName == SC_UNONAME_PRALLSH ) aRet <<= pScMod->GetPrintOptions().GetAllSheets(); diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index 58e02baca533..7a2ba764a3e1 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -1734,17 +1734,12 @@ void ScDBFunc::DataPilotSort(ScDPObject* pDPObj, tools::Long nDimIndex, bool bAs typedef std::unordered_map<OUString, sal_uInt16> UserSortMap; UserSortMap aSubStrs; sal_uInt16 nSubCount = 0; - ScUserList* pUserList = ScGlobal::GetUserList(); - if (!pUserList) + ScUserList& rUserList = ScGlobal::GetUserList(); + size_t nUserListSize = rUserList.size(); + if (!nUserListSize || *pUserListId >= static_cast<sal_uInt16>(nUserListSize)) return; - { - size_t n = pUserList->size(); - if (!n || *pUserListId >= static_cast<sal_uInt16>(n)) - return; - } - - const ScUserListData& rData = (*pUserList)[*pUserListId]; + const ScUserListData& rData = rUserList[*pUserListId]; sal_uInt16 n = rData.GetSubCount(); for (sal_uInt16 i = 0; i < n; ++i) { diff --git a/sc/source/ui/view/gridwin2.cxx b/sc/source/ui/view/gridwin2.cxx index 01f5f39dd7d3..5b85d3c66fd5 100644 --- a/sc/source/ui/view/gridwin2.cxx +++ b/sc/source/ui/view/gridwin2.cxx @@ -656,16 +656,13 @@ void ScGridWindow::DPSetupFieldPopup(std::unique_ptr<ScCheckListMenuControl::Ext if (bDimOrientNotPage) { vector<OUString> aUserSortNames; - ScUserList* pUserList = ScGlobal::GetUserList(); - if (pUserList) + ScUserList& rUserList = ScGlobal::GetUserList(); + size_t nUserListSize = rUserList.size(); + aUserSortNames.reserve(nUserListSize); + for (size_t i = 0; i < nUserListSize; ++i) { - size_t n = pUserList->size(); - aUserSortNames.reserve(n); - for (size_t i = 0; i < n; ++i) - { - const ScUserListData& rData = (*pUserList)[i]; - aUserSortNames.push_back(rData.GetString()); - } + const ScUserListData& rData = rUserList[i]; + aUserSortNames.push_back(rData.GetString()); } // Populate the menus. |