summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2010-10-05 16:03:25 -0400
committerKohei Yoshida <kyoshida@novell.com>2010-10-05 16:03:25 -0400
commit221204d480d925eb497704f71177fead09c9ebf4 (patch)
treeed8cae476dfcfb1a3cadd21109ba6bc8fda9367e /sc/source/ui
parent383cb27aeb9d34a4f7c9b34f81f70ee287c0c9de (diff)
Ported calc-dp-sort-fix.diff from ooo-build.
This change fixes the data pilot field options dialog, to display the name of a data field "<name> - <function>" to be consistent with the rest of the data pilot UI. This change also fixes failure to calculate result when a data field's result is relative to another data field & the referenced data field used custom name. (n#629920)
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/dbgui/pvfundlg.cxx104
-rw-r--r--sc/source/ui/dbgui/pvlaydlg.cxx71
-rw-r--r--sc/source/ui/inc/pvfundlg.hxx18
3 files changed, 156 insertions, 37 deletions
diff --git a/sc/source/ui/dbgui/pvfundlg.cxx b/sc/source/ui/dbgui/pvfundlg.cxx
index 6b04993ba0bc..4c6e5e8ee5f2 100644
--- a/sc/source/ui/dbgui/pvfundlg.cxx
+++ b/sc/source/ui/dbgui/pvfundlg.cxx
@@ -107,15 +107,6 @@ bool lclFillListBox( ListBoxType& rLBox, const vector<ScDPLabelData::Member>& rM
return bEmpty;
}
-/** Searches for a listbox entry, starts search at specified position. */
-USHORT lclFindListBoxEntry( const ListBox& rLBox, const String& rEntry, USHORT nStartPos )
-{
- USHORT nPos = nStartPos;
- while( (nPos < rLBox.GetEntryCount()) && (rLBox.GetEntry( nPos ) != rEntry) )
- ++nPos;
- return (nPos < rLBox.GetEntryCount()) ? nPos : LISTBOX_ENTRY_NOTFOUND;
-}
-
/** This table represents the order of the strings in the resource string array. */
static const USHORT spnFunctions[] =
{
@@ -245,7 +236,7 @@ DataPilotFieldReference ScDPFunctionDlg::GetFieldRef() const
DataPilotFieldReference aRef;
aRef.ReferenceType = maLbTypeWrp.GetControlValue();
- aRef.ReferenceField = maLbBaseField.GetSelectEntry();
+ aRef.ReferenceField = GetBaseFieldName(maLbBaseField.GetSelectEntry());
USHORT nBaseItemPos = maLbBaseItem.GetSelectEntryPos();
switch( nBaseItemPos )
@@ -260,7 +251,7 @@ DataPilotFieldReference ScDPFunctionDlg::GetFieldRef() const
{
aRef.ReferenceItemType = DataPilotFieldReferenceItemType::NAMED;
if( !mbEmptyItem || (nBaseItemPos > SC_BASEITEM_USER_POS) )
- aRef.ReferenceItemName = maLbBaseItem.GetSelectEntry();
+ aRef.ReferenceItemName = GetBaseItemName(maLbBaseItem.GetSelectEntry());
}
}
@@ -291,8 +282,15 @@ void ScDPFunctionDlg::Init( const ScDPLabelData& rLabelData, const ScDPFuncData&
maLbBaseField.SetSelectHdl( LINK( this, ScDPFunctionDlg, SelectHdl ) );
// base field list box
+ OUString aSelectedEntry;
for( ScDPLabelDataVec::const_iterator aIt = mrLabelVec.begin(), aEnd = mrLabelVec.end(); aIt != aEnd; ++aIt )
+ {
maLbBaseField.InsertEntry(aIt->getDisplayName());
+ maBaseFieldNameMap.insert(
+ NameMapType::value_type(aIt->getDisplayName(), aIt->maName));
+ if (aIt->maName == rFuncData.maFieldRef.ReferenceField)
+ aSelectedEntry = aIt->getDisplayName();
+ }
// base item list box
maLbBaseItem.SetSeparatorPos( SC_BASEITEM_USER_POS - 1 );
@@ -302,7 +300,7 @@ void ScDPFunctionDlg::Init( const ScDPLabelData& rLabelData, const ScDPFuncData&
SelectHdl( &maLbType ); // enables base field/item list boxes
// select base field
- maLbBaseField.SelectEntry( rFuncData.maFieldRef.ReferenceField );
+ maLbBaseField.SelectEntry(aSelectedEntry);
if( maLbBaseField.GetSelectEntryPos() >= maLbBaseField.GetEntryCount() )
maLbBaseField.SelectEntryPos( 0 );
SelectHdl( &maLbBaseField ); // fills base item list, selects base item
@@ -326,7 +324,7 @@ void ScDPFunctionDlg::Init( const ScDPLabelData& rLabelData, const ScDPFuncData&
else
{
USHORT nStartPos = mbEmptyItem ? (SC_BASEITEM_USER_POS + 1) : SC_BASEITEM_USER_POS;
- USHORT nPos = lclFindListBoxEntry( maLbBaseItem, rFuncData.maFieldRef.ReferenceItemName, nStartPos );
+ USHORT nPos = FindBaseItemPos( rFuncData.maFieldRef.ReferenceItemName, nStartPos );
if( nPos >= maLbBaseItem.GetEntryCount() )
nPos = (maLbBaseItem.GetEntryCount() > SC_BASEITEM_USER_POS) ? SC_BASEITEM_USER_POS : SC_BASEITEM_PREV_POS;
maLbBaseItem.SelectEntryPos( nPos );
@@ -335,6 +333,36 @@ void ScDPFunctionDlg::Init( const ScDPLabelData& rLabelData, const ScDPFuncData&
}
}
+const OUString& ScDPFunctionDlg::GetBaseFieldName(const OUString& rLayoutName) const
+{
+ NameMapType::const_iterator itr = maBaseFieldNameMap.find(rLayoutName);
+ return itr == maBaseFieldNameMap.end() ? rLayoutName : itr->second;
+}
+
+const OUString& ScDPFunctionDlg::GetBaseItemName(const OUString& rLayoutName) const
+{
+ NameMapType::const_iterator itr = maBaseItemNameMap.find(rLayoutName);
+ return itr == maBaseItemNameMap.end() ? rLayoutName : itr->second;
+}
+
+sal_uInt16 ScDPFunctionDlg::FindBaseItemPos( const String& rEntry, USHORT nStartPos ) const
+{
+ sal_uInt16 nPos = nStartPos;
+ bool bFound = false;
+ while (nPos < maLbBaseItem.GetEntryCount())
+ {
+ // translate the displayed field name back to its original field name.
+ const OUString& rName = GetBaseItemName(maLbBaseItem.GetEntry(nPos));
+ if (rName.equals(rEntry))
+ {
+ bFound = true;
+ break;
+ }
+ ++nPos;
+ }
+ return bFound ? nPos : LISTBOX_ENTRY_NOTFOUND;
+}
+
IMPL_LINK( ScDPFunctionDlg, SelectHdl, ListBox*, pLBox )
{
if( pLBox == &maLbType )
@@ -375,7 +403,16 @@ IMPL_LINK( ScDPFunctionDlg, SelectHdl, ListBox*, pLBox )
mbEmptyItem = false;
size_t nBasePos = maLbBaseField.GetSelectEntryPos();
if( nBasePos < mrLabelVec.size() )
- mbEmptyItem = lclFillListBox( maLbBaseItem, mrLabelVec[ nBasePos ].maMembers, SC_BASEITEM_USER_POS );
+ {
+ const vector<ScDPLabelData::Member>& rMembers = mrLabelVec[nBasePos].maMembers;
+ mbEmptyItem = lclFillListBox( maLbBaseItem, rMembers, SC_BASEITEM_USER_POS );
+ // build cache for base names.
+ NameMapType aMap;
+ vector<ScDPLabelData::Member>::const_iterator itr = rMembers.begin(), itrEnd = rMembers.end();
+ for (; itr != itrEnd; ++itr)
+ aMap.insert(NameMapType::value_type(itr->getDisplayName(), itr->maName));
+ maBaseItemNameMap.swap(aMap);
+ }
// select base item
USHORT nItemPos = (maLbBaseItem.GetEntryCount() > SC_BASEITEM_USER_POS) ? SC_BASEITEM_USER_POS : SC_BASEITEM_PREV_POS;
@@ -547,7 +584,7 @@ void ScDPSubtotalOptDlg::FillLabelData( ScDPLabelData& rLabelData ) const
else
rLabelData.maSortInfo.Mode = DataPilotFieldSortMode::DATA;
- rLabelData.maSortInfo.Field = maLbSortBy.GetSelectEntry();
+ rLabelData.maSortInfo.Field = GetFieldName(maLbSortBy.GetSelectEntry());
rLabelData.maSortInfo.IsAscending = maRbSortAsc.IsChecked();
// *** LAYOUT MODE ***
@@ -560,7 +597,7 @@ void ScDPSubtotalOptDlg::FillLabelData( ScDPLabelData& rLabelData ) const
rLabelData.maShowInfo.IsEnabled = maCbShow.IsChecked();
rLabelData.maShowInfo.ShowItemsMode = maLbShowFromWrp.GetControlValue();
rLabelData.maShowInfo.ItemCount = sal::static_int_cast<sal_Int32>( maNfShow.GetValue() );
- rLabelData.maShowInfo.DataField = maLbShowUsing.GetSelectEntry();
+ rLabelData.maShowInfo.DataField = GetFieldName(maLbShowUsing.GetSelectEntry());
// *** HIDDEN ITEMS ***
@@ -585,16 +622,20 @@ void ScDPSubtotalOptDlg::Init( const ScDPNameVec& rDataFields, bool bEnableLayou
for( ScDPNameVec::const_iterator aIt = rDataFields.begin(), aEnd = rDataFields.end(); aIt != aEnd; ++aIt )
{
- maLbSortBy.InsertEntry( *aIt );
- maLbShowUsing.InsertEntry( *aIt ); // for AutoShow
+ // Cache names for later lookup.
+ maDataFieldNameMap.insert(NameMapType::value_type(aIt->maLayoutName, aIt->maName));
+
+ maLbSortBy.InsertEntry( aIt->maLayoutName );
+ maLbShowUsing.InsertEntry( aIt->maLayoutName ); // for AutoShow
}
+
if( maLbSortBy.GetEntryCount() > SC_SORTDATA_POS )
maLbSortBy.SetSeparatorPos( SC_SORTDATA_POS - 1 );
USHORT nSortPos = SC_SORTNAME_POS;
if( nSortMode == DataPilotFieldSortMode::DATA )
{
- nSortPos = lclFindListBoxEntry( maLbSortBy, maLabelData.maSortInfo.Field, SC_SORTDATA_POS );
+ nSortPos = FindListBoxEntry( maLbSortBy, maLabelData.maSortInfo.Field, SC_SORTDATA_POS );
if( nSortPos >= maLbSortBy.GetEntryCount() )
{
nSortPos = SC_SORTNAME_POS;
@@ -683,6 +724,31 @@ void ScDPSubtotalOptDlg::InitHideListBox()
maLbHide.Enable( bEnable );
}
+const OUString& ScDPSubtotalOptDlg::GetFieldName(const OUString& rLayoutName) const
+{
+ NameMapType::const_iterator itr = maDataFieldNameMap.find(rLayoutName);
+ return itr == maDataFieldNameMap.end() ? rLayoutName : itr->second;
+}
+
+sal_uInt16 ScDPSubtotalOptDlg::FindListBoxEntry(
+ const ListBox& rLBox, const String& rEntry, USHORT nStartPos ) const
+{
+ sal_uInt16 nPos = nStartPos;
+ bool bFound = false;
+ while (nPos < rLBox.GetEntryCount())
+ {
+ // translate the displayed field name back to its original field name.
+ const OUString& rName = GetFieldName(rLBox.GetEntry(nPos));
+ if (rName.equals(rEntry))
+ {
+ bFound = true;
+ break;
+ }
+ ++nPos;
+ }
+ return bFound ? nPos : LISTBOX_ENTRY_NOTFOUND;
+}
+
IMPL_LINK( ScDPSubtotalOptDlg, RadioClickHdl, RadioButton*, pBtn )
{
maLbSortBy.Enable( pBtn != &maRbSortMan );
diff --git a/sc/source/ui/dbgui/pvlaydlg.cxx b/sc/source/ui/dbgui/pvlaydlg.cxx
index ca22d6d694a6..b2a6cba1743d 100644
--- a/sc/source/ui/dbgui/pvlaydlg.cxx
+++ b/sc/source/ui/dbgui/pvlaydlg.cxx
@@ -468,10 +468,14 @@ void ScDPLayoutDlg::InitWnd( PivotField* pArr, long nCount, ScDPFieldType eType
DBG_ASSERT( pData, "ScDPLabelData not found" );
if (pData)
{
- String aStr( GetFuncString( (*pInitArr)[j]->mnFuncMask,
- pData->mbIsValue ) );
+ OUString aStr = pData->maLayoutName;
+ if (!aStr.getLength())
+ {
+ USHORT nInitMask = (*pInitArr)[j]->mnFuncMask;
+ aStr = GetFuncString(nInitMask, pData->mbIsValue);
+ aStr += pData->maName;
+ }
- aStr += GetLabelString( nCol );
pInitWnd->AddField( aStr, j );
pData->mnFuncMask = nMask;
@@ -614,10 +618,14 @@ void ScDPLayoutDlg::AddField( size_t nFromIndex, ScDPFieldType eToType, const Po
}
else
{
+ ScDPLabelData* p = GetLabelData(fData.mnCol);
+ OUString aStr = p->maLayoutName;
USHORT nMask = fData.mnFuncMask;
- OUString aStr = GetFuncString( nMask, rData.mbIsValue );
-
- aStr += rData.getDisplayName();
+ if (!aStr.getLength())
+ {
+ aStr = GetFuncString(nMask);
+ aStr += p->maName;
+ }
if ( toWnd->AddField( aStr,
DlgPos2WndPos( rAtPos, *toWnd ),
@@ -764,10 +772,14 @@ void ScDPLayoutDlg::MoveField( ScDPFieldType eFromType, size_t nFromIndex, ScDPF
}
else
{
- String aStr;
+ ScDPLabelData* p = GetLabelData(fData.mnCol);
+ OUString aStr = p->maLayoutName;
USHORT nMask = fData.mnFuncMask;
- aStr = GetFuncString( nMask );
- aStr += GetLabelString( fData.mnCol );
+ if (!aStr.getLength())
+ {
+ aStr = GetFuncString(nMask);
+ aStr += p->maName;
+ }
if ( toWnd->AddField( aStr,
DlgPos2WndPos( rAtPos, *toWnd ),
@@ -845,10 +857,14 @@ void ScDPLayoutDlg::MoveField( ScDPFieldType eFromType, size_t nFromIndex, ScDPF
}
else
{
- String aStr;
+ ScDPLabelData* p = GetLabelData(fData.mnCol);
+ OUString aStr = p->maLayoutName;
USHORT nMask = fData.mnFuncMask;
- aStr = GetFuncString( nMask );
- aStr += GetLabelString( fData.mnCol );
+ if (!aStr.getLength())
+ {
+ aStr = GetFuncString(nMask);
+ aStr += p->maName;
+ }
if ( theWnd->AddField( aStr,
DlgPos2WndPos( rAtPos, *theWnd ),
@@ -1016,13 +1032,26 @@ void ScDPLayoutDlg::NotifyDoubleClick( ScDPFieldType eType, size_t nFieldIndex )
case TYPE_ROW:
{
// list of names of all data fields
- std::vector< String > aDataFieldNames;
+ vector<ScDPName> aDataFieldNames;
for( ScDPFuncDataVec::const_iterator aIt = aDataArr.begin(), aEnd = aDataArr.end();
(aIt != aEnd) && aIt->get(); ++aIt )
{
- String aName( GetLabelString( (*aIt)->mnCol ) );
- if( aName.Len() )
- aDataFieldNames.push_back( aName );
+ ScDPLabelData* pDFData = GetLabelData((*aIt)->mnCol);
+ if (!pDFData)
+ continue;
+
+ if (!pDFData->maName.getLength())
+ continue;
+
+ OUString aLayoutName = pDFData->maLayoutName;
+ if (!aLayoutName.getLength())
+ {
+ // No layout name exists. Use the stock name.
+ USHORT nMask = (*aIt)->mnFuncMask;
+ OUString aFuncStr = GetFuncString(nMask);
+ aLayoutName = aFuncStr + pDFData->maName;
+ }
+ aDataFieldNames.push_back(ScDPName(pDFData->maName, aLayoutName));
}
bool bLayout = (eType == TYPE_ROW) &&
@@ -1052,8 +1081,14 @@ void ScDPLayoutDlg::NotifyDoubleClick( ScDPFieldType eType, size_t nFieldIndex )
(*pArr)[nFieldIndex]->mnFuncMask = pData->mnFuncMask = pDlg->GetFuncMask();
(*pArr)[nFieldIndex]->maFieldRef = pDlg->GetFieldRef();
- String aStr( GetFuncString ( aDataArr[nFieldIndex]->mnFuncMask ) );
- aStr += GetLabelString( aDataArr[nFieldIndex]->mnCol );
+ ScDPLabelData* p = GetLabelData(aDataArr[nFieldIndex]->mnCol);
+ OUString aStr = p->maLayoutName;
+ if (!aStr.getLength())
+ {
+ // Layout name is not available. Use default name.
+ aStr = GetFuncString (aDataArr[nFieldIndex]->mnFuncMask);
+ aStr += p->maName;
+ }
aWndData.SetFieldText( aStr, nFieldIndex );
}
delete pDlg;
diff --git a/sc/source/ui/inc/pvfundlg.hxx b/sc/source/ui/inc/pvfundlg.hxx
index 1fed120f6116..20ea3602e638 100644
--- a/sc/source/ui/inc/pvfundlg.hxx
+++ b/sc/source/ui/inc/pvfundlg.hxx
@@ -68,6 +68,7 @@ private:
class ScDPFunctionDlg : public ModalDialog
{
+ typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash > NameMapType;
public:
explicit ScDPFunctionDlg( Window* pParent, const ScDPLabelDataVec& rLabelVec,
const ScDPLabelData& rLabelData, const ScDPFuncData& rFuncData );
@@ -78,6 +79,12 @@ public:
private:
void Init( const ScDPLabelData& rLabelData, const ScDPFuncData& rFuncData );
+ const ::rtl::OUString& GetBaseFieldName(const ::rtl::OUString& rLayoutName) const;
+ const ::rtl::OUString& GetBaseItemName(const ::rtl::OUString& rLayoutName) const;
+
+ /** Searches for a listbox entry, starts search at specified position. */
+ sal_uInt16 FindBaseItemPos( const String& rEntry, USHORT nStartPos ) const;
+
DECL_LINK( SelectHdl, ListBox* );
DECL_LINK( DblClickHdl, MultiListBox* );
@@ -98,6 +105,9 @@ private:
HelpButton maBtnHelp;
MoreButton maBtnMore;
+ NameMapType maBaseFieldNameMap; // cache for base field display -> original name.
+ NameMapType maBaseItemNameMap; // cache for base item display -> original name.
+
ScDPListBoxWrapper maLbTypeWrp; /// Wrapper for direct usage of API constants.
const ScDPLabelDataVec& mrLabelVec; /// Data of all labels.
@@ -160,6 +170,11 @@ private:
void Init( const ScDPNameVec& rDataFields, bool bEnableLayout );
void InitHideListBox();
+ const ::rtl::OUString& GetFieldName(const ::rtl::OUString& rLayoutName) const;
+
+ /** Searches for a listbox entry, starts search at specified position. */
+ sal_uInt16 FindListBoxEntry( const ListBox& rLBox, const String& rEntry, USHORT nStartPos ) const;
+
DECL_LINK( RadioClickHdl, RadioButton* );
DECL_LINK( CheckHdl, CheckBox* );
DECL_LINK( SelectHdl, ListBox* );
@@ -195,6 +210,9 @@ private:
ScDPObject& mrDPObj; /// The DataPilot object (for member names).
ScDPLabelData maLabelData; /// Cache for members data.
+
+ typedef ::std::hash_map< ::rtl::OUString, ::rtl::OUString, ::rtl::OUStringHash > NameMapType;
+ NameMapType maDataFieldNameMap; /// Cache for displayed name to field name mapping.
};
// ============================================================================