summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sc/Library_sc.mk1
-rw-r--r--sc/inc/dpsave.hxx13
-rw-r--r--sc/inc/dputil.hxx44
-rw-r--r--sc/source/core/data/dpobject.cxx2
-rw-r--r--sc/source/core/data/dpsave.cxx35
-rw-r--r--sc/source/core/data/dputil.cxx47
6 files changed, 128 insertions, 14 deletions
diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 656aa82aea1a..a643b7a511f1 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -116,6 +116,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
sc/source/core/data/dptablecache \
sc/source/core/data/dptabres \
sc/source/core/data/dptabsrc \
+ sc/source/core/data/dputil \
sc/source/core/data/drawpage \
sc/source/core/data/drwlayer \
sc/source/core/data/fillinfo \
diff --git a/sc/inc/dpsave.hxx b/sc/inc/dpsave.hxx
index 3107da8f8985..a699d61c0084 100644
--- a/sc/inc/dpsave.hxx
+++ b/sc/inc/dpsave.hxx
@@ -357,6 +357,19 @@ public:
private:
void CheckDuplicateName(ScDPSaveDimension& rDim);
void RemoveDuplicateNameCount(const rtl::OUString& rName);
+
+ /**
+ * Append a new original dimension. Not to be called to insert a duplicate
+ * dimension.
+ *
+ * @param rName Dimension name. The name must be the original dimension
+ * name; not a duplicate dimension name.
+ * @param bDataLayout true if this is a data layout dimension, false
+ * otherwise.
+ *
+ * @return pointer to the new dimension just inserted.
+ */
+ ScDPSaveDimension* AppendNewDimension(const rtl::OUString& rName, bool bDataLayout);
};
#endif
diff --git a/sc/inc/dputil.hxx b/sc/inc/dputil.hxx
new file mode 100644
index 000000000000..d33d344b6bcb
--- /dev/null
+++ b/sc/inc/dputil.hxx
@@ -0,0 +1,44 @@
+/* -*- 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.
+ */
+
+#ifndef __SC_DPUTIL_HXX__
+#define __SC_DPUTIL_HXX__
+
+#include "rtl/ustring.hxx"
+
+class ScDPUtil
+{
+public:
+ static bool isDuplicateDimension(const rtl::OUString& rName);
+
+ static rtl::OUString getSourceDimensionName(const rtl::OUString& rName);
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 5d4e8bc24b04..25f2c6078d7a 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2124,7 +2124,7 @@ bool ScDPObject::GetMembersNA( sal_Int32 nDim, sal_Int32 nHier, uno::Reference<
namespace {
-String lcl_GetDimName( const uno::Reference<sheet::XDimensionsSupplier>& xSource, long nDim )
+rtl::OUString lcl_GetDimName( const uno::Reference<sheet::XDimensionsSupplier>& xSource, long nDim )
{
rtl::OUString aName;
if ( xSource.is() )
diff --git a/sc/source/core/data/dpsave.cxx b/sc/source/core/data/dpsave.cxx
index 00ff28939899..ef8cb5e1255c 100644
--- a/sc/source/core/data/dpsave.cxx
+++ b/sc/source/core/data/dpsave.cxx
@@ -35,6 +35,8 @@
#include "scerrors.hxx"
#include "unonames.hxx"
#include "global.hxx"
+#include "dptabsrc.hxx"
+#include "dputil.hxx"
#include <sal/types.h>
#include "comphelper/string.hxx"
@@ -52,7 +54,6 @@
#include <com/sun/star/sheet/XMembersSupplier.hpp>
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/util/XCloneable.hpp>
-#include "dptabsrc.hxx"
#include <com/sun/star/sheet/DataPilotFieldReferenceType.hpp>
#include <com/sun/star/sheet/DataPilotFieldReferenceItemType.hpp>
@@ -864,9 +865,7 @@ ScDPSaveDimension* ScDPSaveData::GetDimensionByName(const ::rtl::OUString& rName
return const_cast<ScDPSaveDimension*>(&(*iter));
}
- ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, false );
- aDimList.push_back(pNew);
- return pNew;
+ return AppendNewDimension(rName, false);
}
ScDPSaveDimension* ScDPSaveData::GetExistingDimensionByName(const ::rtl::OUString& rName) const
@@ -889,9 +888,7 @@ ScDPSaveDimension* ScDPSaveData::GetNewDimensionByName(const ::rtl::OUString& rN
return DuplicateDimension(rName);
}
- ScDPSaveDimension* pNew = new ScDPSaveDimension( rName, false );
- aDimList.push_back(pNew);
- return pNew;
+ return AppendNewDimension(rName, false);
}
ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
@@ -900,9 +897,7 @@ ScDPSaveDimension* ScDPSaveData::GetDataLayoutDimension()
if (pDim)
return pDim;
- ScDPSaveDimension* pNew = new ScDPSaveDimension( ::rtl::OUString(), true );
- aDimList.push_back(pNew);
- return pNew;
+ return AppendNewDimension(rtl::OUString(), true);
}
ScDPSaveDimension* ScDPSaveData::GetExistingDataLayoutDimension() const
@@ -1124,7 +1119,7 @@ void ScDPSaveData::WriteToSource( const uno::Reference<sheet::XDimensionsSupplie
for (long i = 0; iter != aDimList.end(); ++iter, ++i)
{
rtl::OUString aName = iter->GetName();
- rtl::OUString aCoreName = comphelper::string::removeTrailingChars(aName, sal_Unicode('*'));
+ rtl::OUString aCoreName = ScDPUtil::getSourceDimensionName(aName);
OSL_TRACE( "%s", aName.getStr() );
@@ -1278,13 +1273,13 @@ bool ScDPSaveData::HasInvisibleMember(const OUString& rDimName) const
void ScDPSaveData::CheckDuplicateName(ScDPSaveDimension& rDim)
{
- const rtl::OUString aName = comphelper::string::removeTrailingChars(rDim.GetName(), sal_Unicode('*'));
+ const rtl::OUString aName = ScDPUtil::getSourceDimensionName(rDim.GetName());
DupNameCountType::iterator it = maDupNameCounts.find(aName);
if (it != maDupNameCounts.end())
{
+ it->second = it->second + 1;
// This is a duplicate name. Up the counter and append '*' to make the name unique.
rtl::OUStringBuffer aBuf(aName);
- it->second = it->second + 1;
for (size_t i = 0, n = it->second; i < n; ++i)
aBuf.append(sal_Unicode('*'));
rDim.SetName(aBuf.makeStringAndClear());
@@ -1299,6 +1294,20 @@ void ScDPSaveData::RemoveDuplicateNameCount(const rtl::OUString& rName)
{
}
+ScDPSaveDimension* ScDPSaveData::AppendNewDimension(const rtl::OUString& rName, bool bDataLayout)
+{
+ if (ScDPUtil::isDuplicateDimension(rName))
+ // This call is for original dimensions only.
+ return NULL;
+
+ ScDPSaveDimension* pNew = new ScDPSaveDimension(rName, bDataLayout);
+ aDimList.push_back(pNew);
+ if (!maDupNameCounts.count(rName))
+ maDupNameCounts.insert(DupNameCountType::value_type(rName, 0));
+
+ return pNew;
+}
+
void ScDPSaveDimension::Refresh( const com::sun::star::uno::Reference<
com::sun::star::sheet::XDimensionsSupplier>& xSource ,
const std::list<rtl::OUString>& deletedDims)
diff --git a/sc/source/core/data/dputil.cxx b/sc/source/core/data/dputil.cxx
new file mode 100644
index 000000000000..f04a5870a2aa
--- /dev/null
+++ b/sc/source/core/data/dputil.cxx
@@ -0,0 +1,47 @@
+/* -*- 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 "dputil.hxx"
+
+#include "comphelper/string.hxx"
+
+bool ScDPUtil::isDuplicateDimension(const rtl::OUString& rName)
+{
+ if (rName.isEmpty())
+ return false;
+
+ sal_Unicode cLast = rName[rName.getLength()-1];
+ return cLast == sal_Unicode('*');
+}
+
+rtl::OUString ScDPUtil::getSourceDimensionName(const rtl::OUString& rName)
+{
+ return comphelper::string::removeTrailingChars(rName, sal_Unicode('*'));
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */