Kaydet (Commit) bb6bd1ff authored tarafından Miklos Vajna's avatar Miklos Vajna

fdo#53210 SwDoc::UpdateExpFlds don't crash when hiding all sections

Change-Id: I9b7a61f18f987214708195a89f6e346c865c7f9f
üst 369da987
......@@ -1288,6 +1288,15 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
SwNewDBMgr* pMgr = GetNewDBMgr();
pMgr->CloseAll(sal_False);
// Make sure we don't hide all sections, which would lead to a crash. First, count how many of them do we have.
int nShownSections = 0;
for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it )
{
SwSection* pSect = (SwSection*)(*it)->GetSection();
if ( pSect && !pSect->IsCondHidden())
nShownSections++;
}
String aNew;
for( _SetGetExpFlds::const_iterator it = pUpdtFlds->GetSortLst()->begin(); it != pUpdtFlds->GetSortLst()->end(); ++it )
{
......@@ -1298,7 +1307,23 @@ void SwDoc::UpdateExpFlds( SwTxtFld* pUpdtFld, bool bUpdRefFlds )
SwSbxValue aValue = aCalc.Calculate(
pSect->GetCondition() );
if(!aValue.IsVoidValue())
pSect->SetCondHidden( aValue.GetBool() );
{
// Do we want to hide this one?
bool bHide = aValue.GetBool();
if (bHide && !pSect->IsCondHidden())
{
// This section will be hidden, but it wasn't before
if (nShownSections == 1)
{
// This would be the last section, so set its condition to false, and avoid hiding it.
OUString aCond("0");
pSect->SetCondition(aCond);
bHide = false;
}
nShownSections--;
}
pSect->SetCondHidden( bHide );
}
continue;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment