summaryrefslogtreecommitdiff
path: root/sc/source
diff options
context:
space:
mode:
authorKohei Yoshida <kohei.yoshida@suse.com>2012-03-06 01:38:14 -0500
committerKohei Yoshida <kohei.yoshida@gmail.com>2012-03-09 11:13:31 -0500
commit5e7daf4ab990c4719332e1c6df06cc477bdb3631 (patch)
tree4040b39df68da849712a0eedf477e7bd61671e4b /sc/source
parentc2f8b7a17e71f9379db7d44e763ad831cfd27825 (diff)
Display special first/last date names correctly.
Diffstat (limited to 'sc/source')
-rw-r--r--sc/source/core/data/dpgroup.cxx49
-rw-r--r--sc/source/core/data/dpitemdata.cxx3
-rw-r--r--sc/source/core/data/dpnumgroupinfo.cxx35
-rw-r--r--sc/source/core/data/dptabdat.cxx6
-rw-r--r--sc/source/core/data/dptablecache.cxx71
-rw-r--r--sc/source/core/data/dptabres.cxx8
-rw-r--r--sc/source/core/data/dptabsrc.cxx7
-rw-r--r--sc/source/core/data/dputil.cxx29
8 files changed, 140 insertions, 68 deletions
diff --git a/sc/source/core/data/dpgroup.cxx b/sc/source/core/data/dpgroup.cxx
index 3f628e7ee798..d7cdd9da9176 100644
--- a/sc/source/core/data/dpgroup.cxx
+++ b/sc/source/core/data/dpgroup.cxx
@@ -110,14 +110,6 @@ private:
const sal_uInt16 SC_DP_LEAPYEAR = 1648; // arbitrary leap year for date calculations
-// part values for the extra "<" and ">" entries (same for all parts)
-const sal_Int32 SC_DP_DATE_FIRST = -1;
-const sal_Int32 SC_DP_DATE_LAST = 10000;
-
-ScDPNumGroupInfo::ScDPNumGroupInfo() :
- mbEnable(false), mbDateValues(false), mbAutoStart(false), mbAutoEnd(false),
- mfStart(0.0), mfEnd(0.0), mfStep(0.0) {}
-
namespace {
sal_Bool lcl_Search( SCCOL nSourceDim, const ScDPCache* pCache , const std::vector< SCROW >& vIdx, SCROW nNew , SCROW& rIndex)
@@ -355,10 +347,10 @@ bool ScDPGroupDateFilter::match( const ScDPItemData & rCellData ) const
// is included, while an end date with a time value is not.)
if ( rCellData.GetValue() < mpNumInfo->mfStart && !approxEqual(rCellData.GetValue(), mpNumInfo->mfStart) )
- return static_cast<sal_Int32>(mfMatchValue) == SC_DP_DATE_FIRST;
+ return static_cast<sal_Int32>(mfMatchValue) == ScDPItemData::DateFirst;
if ( rCellData.GetValue() > mpNumInfo->mfEnd && !approxEqual(rCellData.GetValue(), mpNumInfo->mfEnd) )
- return static_cast<sal_Int32>(mfMatchValue) == SC_DP_DATE_LAST;
+ return static_cast<sal_Int32>(mfMatchValue) == ScDPItemData::DateLast;
if (mnDatePart == DataPilotFieldGroupBy::HOURS || mnDatePart == DataPilotFieldGroupBy::MINUTES ||
mnDatePart == DataPilotFieldGroupBy::SECONDS)
@@ -459,9 +451,9 @@ sal_Int32 lcl_GetDatePartValue( double fValue, sal_Int32 nDatePart, SvNumberForm
if ( pNumInfo )
{
if ( fValue < pNumInfo->mfStart && !rtl::math::approxEqual( fValue, pNumInfo->mfStart ) )
- return SC_DP_DATE_FIRST;
+ return ScDPItemData::DateFirst;
if ( fValue > pNumInfo->mfEnd && !rtl::math::approxEqual( fValue, pNumInfo->mfEnd ) )
- return SC_DP_DATE_LAST;
+ return ScDPItemData::DateLast;
}
sal_Int32 nResult = 0;
@@ -522,14 +514,6 @@ sal_Int32 lcl_GetDatePartValue( double fValue, sal_Int32 nDatePart, SvNumberForm
return nResult;
}
-String lcl_GetSpecialDateName( double fValue, bool bFirst, SvNumberFormatter* pFormatter )
-{
- rtl::OUStringBuffer aBuffer;
- aBuffer.append((sal_Unicode)( bFirst ? '<' : '>' ));
- lcl_AppendDateStr( aBuffer, fValue, pFormatter );
- return aBuffer.makeStringAndClear();
-}
-
bool isDateInGroup(const ScDPItemData& rGroupItem, const ScDPItemData& rChildItem)
{
stack_printer __stack_printer__("::isDateInGroup");
@@ -544,8 +528,8 @@ bool isDateInGroup(const ScDPItemData& rGroupItem, const ScDPItemData& rChildIte
fprintf(stdout, "isDateInGroup: group part = %d group values = %d child part = %d child value = %d\n",
nGroupPart, nGroupValue, nChildPart, nChildValue);
- if (nGroupValue == SC_DP_DATE_FIRST || nGroupValue == SC_DP_DATE_LAST ||
- nChildValue == SC_DP_DATE_FIRST || nChildValue == SC_DP_DATE_LAST)
+ if (nGroupValue == ScDPItemData::DateFirst || nGroupValue == ScDPItemData::DateLast ||
+ nChildValue == ScDPItemData::DateFirst || nChildValue == ScDPItemData::DateLast)
{
// first/last entry matches only itself
return nGroupValue == nChildValue;
@@ -652,30 +636,21 @@ void ScDPDateGroupHelper::FillColumnEntries(
OSL_FAIL("invalid date part");
}
- pCache->ResetGroupItems(mnGroupDim);
+ pCache->ResetGroupItems(mnGroupDim, aNumInfo);
fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: source dim = %d group dim = %d\n",
nSourceDim, mnGroupDim);
for ( sal_Int32 nValue = nStart; nValue <= nEnd; nValue++ )
{
- rtl::OUString aName = ScDPUtil::getDateGroupName( nDatePart, nValue, pFormatter );
- fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: name = '%s'\n",
- rtl::OUStringToOString(aName, RTL_TEXTENCODING_UTF8).getStr());
SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, nValue));
rEntries.push_back(nId);
}
// add first/last entry (min/max)
- rtl::OUString aFirstName = lcl_GetSpecialDateName( aNumInfo.mfStart, true, pFormatter );
- fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: first = '%s'\n",
- rtl::OUStringToOString(aFirstName, RTL_TEXTENCODING_UTF8).getStr());
- SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, SC_DP_DATE_LAST));
+ SCROW nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, ScDPItemData::DateFirst));
rEntries.push_back(nId);
- rtl::OUString aLastName = lcl_GetSpecialDateName( aNumInfo.mfEnd, false, pFormatter );
- fprintf(stdout, "ScDPDateGroupHelper::FillColumnEntries: last = '%s'\n",
- rtl::OUStringToOString(aLastName, RTL_TEXTENCODING_UTF8).getStr());
- nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, SC_DP_DATE_LAST));
+ nId = pCache->SetGroupItem(mnGroupDim, ScDPItemData(nDatePart, ScDPItemData::DateLast));
rEntries.push_back(nId);
std::vector<SCROW>::const_iterator it = rEntries.begin(), itEnd = rEntries.end();
@@ -1396,10 +1371,12 @@ void ScDPGroupTableData::FillGroupValues(SCROW* pItemDataIndex, long nCount, con
if ( pData ->IsValue() )
{
SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
+ const ScDPNumGroupInfo& rNumInfo = pDateHelper->GetNumInfo();
sal_Int32 nPartValue = lcl_GetDatePartValue(
pData->GetValue(), pDateHelper->GetDatePart(), pFormatter,
- &pDateHelper->GetNumInfo() );
- rtl::OUString aName = ScDPUtil::getDateGroupName(pDateHelper->GetDatePart(), nPartValue, pFormatter);
+ &rNumInfo);
+ rtl::OUString aName = ScDPUtil::getDateGroupName(
+ pDateHelper->GetDatePart(), nPartValue, pFormatter, rNumInfo.mfStart, rNumInfo.mfEnd);
fprintf(stdout, "ScDPGroupTableData::FillGroupValues: column = %d source dim = %d group by = %d value = %d name = '%s'\n",
nColumn, nSourceDim,
pDateHelper->GetDatePart(), nPartValue,
diff --git a/sc/source/core/data/dpitemdata.cxx b/sc/source/core/data/dpitemdata.cxx
index 97e6a35d94c8..36ee710fd831 100644
--- a/sc/source/core/data/dpitemdata.cxx
+++ b/sc/source/core/data/dpitemdata.cxx
@@ -34,6 +34,9 @@
#include "globstr.hrc"
#include "dptabdat.hxx"
+const sal_Int32 ScDPItemData::DateFirst = -1;
+const sal_Int32 ScDPItemData::DateLast = 10000;
+
sal_Int32 ScDPItemData::Compare(const ScDPItemData& rA, const ScDPItemData& rB)
{
if (rA.meType != rB.meType)
diff --git a/sc/source/core/data/dpnumgroupinfo.cxx b/sc/source/core/data/dpnumgroupinfo.cxx
new file mode 100644
index 000000000000..6d4e4fa250ce
--- /dev/null
+++ b/sc/source/core/data/dpnumgroupinfo.cxx
@@ -0,0 +1,35 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2012 Kohei Yoshida <kohei.yoshida@suse.com>
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "dpnumgroupinfo.hxx"
+
+ScDPNumGroupInfo::ScDPNumGroupInfo() :
+ mbEnable(false), mbDateValues(false), mbAutoStart(false), mbAutoEnd(false),
+ mfStart(0.0), mfEnd(0.0), mfStep(0.0) {}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/dptabdat.cxx b/sc/source/core/data/dptabdat.cxx
index 7757af521ba5..fd78b8bd9603 100644
--- a/sc/source/core/data/dptabdat.cxx
+++ b/sc/source/core/data/dptabdat.cxx
@@ -73,12 +73,6 @@ ScDPTableData::~ScDPTableData()
{
}
-rtl::OUString ScDPTableData::GetFormattedString(const ScDPItemData& rItem) const
-{
- const ScDPCache* pCache = GetCacheTable().getCache();
- return pCache->GetFormattedString(rItem);
-}
-
rtl::OUString ScDPTableData::GetFormattedString(long nDim, const ScDPItemData& rItem) const
{
const ScDPCache* pCache = GetCacheTable().getCache();
diff --git a/sc/source/core/data/dptablecache.cxx b/sc/source/core/data/dptablecache.cxx
index f3b1d41a5ef2..ca44220f04fe 100644
--- a/sc/source/core/data/dptablecache.cxx
+++ b/sc/source/core/data/dptablecache.cxx
@@ -38,6 +38,7 @@
#include "docoptio.hxx"
#include "dpitemdata.hxx"
#include "dputil.hxx"
+#include "dpnumgroupinfo.hxx"
#include <rtl/math.hxx>
#include <unotools/textsearch.hxx>
@@ -220,9 +221,11 @@ ScDPItemData* lcl_GetItemValue(
}
-// -----------------------------------------------------------------------
-//class ScDPTableDataCache
-//To cache the pivot table data source
+ScDPCache::GroupItems::GroupItems() :
+ mfStart(0.0), mfEnd(0.0) {}
+
+ScDPCache::GroupItems::GroupItems(const ScDPNumGroupInfo& rInfo) :
+ mfStart(rInfo.mfStart), mfEnd(rInfo.mfEnd) {}
bool ScDPCache::operator== ( const ScDPCache& r ) const
{
@@ -694,6 +697,21 @@ bool ScDPCache::AddData(long nDim, ScDPItemData* pData, sal_uLong nNumFormat)
return true;
}
+const ScDPCache::GroupItems* ScDPCache::GetGroupItems(long nDim) const
+{
+ if (nDim < 0)
+ return NULL;
+
+ long nSourceCount = static_cast<long>(maFields.size());
+ if (nDim < nSourceCount)
+ return maFields[nDim].mpGroup.get();
+
+ nDim -= nSourceCount;
+ if (nDim < static_cast<long>(maGroupFields.size()))
+ return &maGroupFields[nDim];
+
+ return NULL;
+}
rtl::OUString ScDPCache::GetDimensionName( sal_uInt16 nColumn ) const
{
@@ -1018,21 +1036,13 @@ SCROW ScDPCache::GetIdByItemData(long nDim, const ScDPItemData& rItem) const
return -1;
}
-rtl::OUString ScDPCache::GetFormattedString(const ScDPItemData& rItem) const
-{
- if (rItem.GetType() == ScDPItemData::GroupValue)
- {
- ScDPItemData::GroupValueAttr aAttr = rItem.GetGroupValue();
- return ScDPUtil::getDateGroupName(
- aAttr.mnGroupType, aAttr.mnValue, mpDoc->GetFormatTable());
- }
-
- return rItem.GetString();
-}
-
rtl::OUString ScDPCache::GetFormattedString(long nDim, const ScDPItemData& rItem) const
{
- if (rItem.IsValue())
+ if (nDim < 0)
+ return rItem.GetString();
+
+ ScDPItemData::Type eType = rItem.GetType();
+ if (eType == ScDPItemData::Value)
{
// Format value using the stored number format.
sal_uLong nNumFormat = GetNumberFormat(nDim);
@@ -1046,15 +1056,29 @@ rtl::OUString ScDPCache::GetFormattedString(long nDim, const ScDPItemData& rItem
}
}
- return GetFormattedString(rItem);
+ if (eType == ScDPItemData::GroupValue)
+ {
+ ScDPItemData::GroupValueAttr aAttr = rItem.GetGroupValue();
+ double fStart = 0.0, fEnd = 0.0;
+ const GroupItems* p = GetGroupItems(nDim);
+ if (p)
+ {
+ fStart = p->mfStart;
+ fEnd = p->mfEnd;
+ }
+ return ScDPUtil::getDateGroupName(
+ aAttr.mnGroupType, aAttr.mnValue, mpDoc->GetFormatTable(), fStart, fEnd);
+ }
+
+ return rItem.GetString();
}
void ScDPCache::AppendGroupField()
{
- maGroupFields.push_back(new GroupField);
+ maGroupFields.push_back(new GroupItems);
}
-void ScDPCache::ResetGroupItems(long nDim)
+void ScDPCache::ResetGroupItems(long nDim, const ScDPNumGroupInfo& rNumInfo)
{
if (nDim < 0)
return;
@@ -1062,13 +1086,18 @@ void ScDPCache::ResetGroupItems(long nDim)
long nSourceCount = static_cast<long>(maFields.size());
if (nDim < nSourceCount)
{
- maFields.at(nDim).mpGroup.reset(new GroupItems);
+ maFields.at(nDim).mpGroup.reset(new GroupItems(rNumInfo));
return;
}
nDim -= nSourceCount;
if (nDim < static_cast<long>(maGroupFields.size()))
- maGroupFields[nDim].maItems.clear();
+ {
+ GroupItems& rGI = maGroupFields[nDim];
+ rGI.maItems.clear();
+ rGI.mfStart = rNumInfo.mfStart;
+ rGI.mfEnd = rNumInfo.mfEnd;
+ }
}
SCROW ScDPCache::SetGroupItem(long nDim, const ScDPItemData& rData)
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index 1f8adaad3ceb..6e1504f75b87 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -1439,7 +1439,13 @@ void ScDPResultMember::FillMemberResults( uno::Sequence<sheet::MemberResult>* pS
aName = pResultData->GetSource()->GetData()->GetFormattedString(nDim, aItemData);
}
else
- aName = pResultData->GetSource()->GetData()->GetFormattedString(aItemData);
+ {
+ long nDim = -1;
+ const ScDPMember* pMem = GetDPMember();
+ if (pMem)
+ nDim = pMem->GetDim();
+ aName = pResultData->GetSource()->GetData()->GetFormattedString(nDim, aItemData);
+ }
ScDPItemData::Type eType = aItemData.GetType();
bIsNumeric = eType == ScDPItemData::Value || ScDPItemData::GroupValue;
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index 59ed83780dae..bece98cd78b8 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -2625,9 +2625,14 @@ const OUString* ScDPMember::GetLayoutName() const
return mpLayoutName.get();
}
+long ScDPMember::GetDim() const
+{
+ return nDim;
+}
+
rtl::OUString ScDPMember::GetNameStr() const
{
- return pSource->GetData()->GetFormattedString(GetItemData());
+ return pSource->GetData()->GetFormattedString(nDim, GetItemData());
}
::rtl::OUString SAL_CALL ScDPMember::getName() throw(uno::RuntimeException)
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
index 94e022359807..eb816d8ece5d 100644
--- a/sc/source/core/data/dputil.cxx
+++ b/sc/source/core/data/dputil.cxx
@@ -28,6 +28,7 @@
#include "dputil.hxx"
#include "global.hxx"
+#include "dpitemdata.hxx"
#include "comphelper/string.hxx"
#include "unotools/localedatawrapper.hxx"
@@ -43,7 +44,7 @@ namespace {
const sal_uInt16 SC_DP_LEAPYEAR = 1648; // arbitrary leap year for date calculations
-String getTwoDigitString( sal_Int32 nValue )
+rtl::OUString getTwoDigitString(sal_Int32 nValue)
{
String aRet = String::CreateFromInt32( nValue );
if ( aRet.Len() < 2 )
@@ -51,6 +52,22 @@ String getTwoDigitString( sal_Int32 nValue )
return aRet;
}
+void appendDateStr(rtl::OUStringBuffer& rBuffer, double fValue, SvNumberFormatter* pFormatter)
+{
+ sal_uLong nFormat = pFormatter->GetStandardFormat( NUMBERFORMAT_DATE, ScGlobal::eLnge );
+ rtl::OUString aString;
+ pFormatter->GetInputLineString(fValue, nFormat, aString);
+ rBuffer.append(aString);
+}
+
+rtl::OUString getSpecialDateName(double fValue, bool bFirst, SvNumberFormatter* pFormatter)
+{
+ rtl::OUStringBuffer aBuffer;
+ aBuffer.append(sal_Unicode(bFirst ? '<' : '>'));
+ appendDateStr(aBuffer, fValue, pFormatter);
+ return aBuffer.makeStringAndClear();
+}
+
}
bool ScDPUtil::isDuplicateDimension(const rtl::OUString& rName)
@@ -80,8 +97,14 @@ rtl::OUString ScDPUtil::createDuplicateDimensionName(const rtl::OUString& rOrigi
}
rtl::OUString ScDPUtil::getDateGroupName(
- sal_Int32 nDatePart, sal_Int32 nValue, SvNumberFormatter* pFormatter)
+ sal_Int32 nDatePart, sal_Int32 nValue, SvNumberFormatter* pFormatter,
+ double fStart, double fEnd)
{
+ if (nValue == ScDPItemData::DateFirst)
+ return getSpecialDateName(fStart, true, pFormatter);
+ if (nValue == ScDPItemData::DateLast)
+ return getSpecialDateName(fEnd, false, pFormatter);
+
switch ( nDatePart )
{
case sheet::DataPilotFieldGroupBy::YEARS:
@@ -122,7 +145,7 @@ rtl::OUString ScDPUtil::getDateGroupName(
OSL_FAIL("invalid date part");
}
- return rtl::OUString();
+ return rtl::OUString::createFromAscii("FIXME: unhandled value");
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */