summaryrefslogtreecommitdiff
path: root/sc/source/ui/dbgui/pvfundlg.cxx
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/dbgui/pvfundlg.cxx
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/dbgui/pvfundlg.cxx')
-rw-r--r--sc/source/ui/dbgui/pvfundlg.cxx104
1 files changed, 85 insertions, 19 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 );