Detect error conditions during initial datapilot construction.

Failure to do so would cause an segfault down the road.
This commit is contained in:
Kohei Yoshida 2011-03-23 17:16:18 -04:00
parent 104d96b443
commit b2d2a3f59d
2 changed files with 23 additions and 5 deletions

View file

@ -1805,7 +1805,7 @@ Resource RID_GLOBSTR
}; };
String STR_PIVOT_FIRSTROWEMPTYERR String STR_PIVOT_FIRSTROWEMPTYERR
{ {
Text [ en-US ] = "The field name cannot be empty. Check the first row of data source to make sure there are no empty cells." ; Text [ en-US ] = "One or more fields appear to have an empty name. Check the first row of the data source to ensure there are no empty cells." ;
}; };
String STR_PIVOT_ONLYONEROWERR String STR_PIVOT_ONLYONEROWERR
{ {

View file

@ -2166,6 +2166,8 @@ void ScCellShell::ExecuteDataPilotDialog()
} }
else // create new table else // create new table
{ {
sal_uLong nSrcErrorId = 0;
// select database range or data // select database range or data
pTabViewShell->GetDBData( true, SC_DB_OLD ); pTabViewShell->GetDBData( true, SC_DB_OLD );
ScMarkData& rMark = GetViewData()->GetMarkData(); ScMarkData& rMark = GetViewData()->GetMarkData();
@ -2241,8 +2243,12 @@ void ScCellShell::ExecuteDataPilotDialog()
OUString aName = pTypeDlg->GetSelectedNamedRange(); OUString aName = pTypeDlg->GetSelectedNamedRange();
ScSheetSourceDesc aShtDesc(pDoc); ScSheetSourceDesc aShtDesc(pDoc);
aShtDesc.SetRangeName(aName); aShtDesc.SetRangeName(aName);
pNewDPObject.reset(new ScDPObject(pDoc)); nSrcErrorId = aShtDesc.CheckSourceRange();
pNewDPObject->SetSheetDesc(aShtDesc); if (!nSrcErrorId)
{
pNewDPObject.reset(new ScDPObject(pDoc));
pNewDPObject->SetSheetDesc(aShtDesc);
}
} }
else // selection else // selection
{ {
@ -2279,8 +2285,12 @@ void ScCellShell::ExecuteDataPilotDialog()
{ {
ScSheetSourceDesc aShtDesc(pDoc); ScSheetSourceDesc aShtDesc(pDoc);
aShtDesc.SetSourceRange(aRange); aShtDesc.SetSourceRange(aRange);
pNewDPObject.reset(new ScDPObject(pDoc)); nSrcErrorId = aShtDesc.CheckSourceRange();
pNewDPObject->SetSheetDesc( aShtDesc ); if (!nSrcErrorId)
{
pNewDPObject.reset(new ScDPObject(pDoc));
pNewDPObject->SetSheetDesc( aShtDesc );
}
// output below source data // output below source data
if ( aRange.aEnd.Row()+2 <= MAXROW - 4 ) if ( aRange.aEnd.Row()+2 <= MAXROW - 4 )
@ -2292,6 +2302,14 @@ void ScCellShell::ExecuteDataPilotDialog()
} }
} }
if (nSrcErrorId)
{
// Error occurred during data creation. Launch an error and bail out.
InfoBox aBox(pTabViewShell->GetDialogParent(), ScGlobal::GetRscString(nSrcErrorId));
aBox.Execute();
return;
}
if ( pNewDPObject ) if ( pNewDPObject )
pNewDPObject->SetOutRange( aDestPos ); pNewDPObject->SetOutRange( aDestPos );
} }