[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/qa sc/source
Kohei Yoshida
kohei.yoshida at gmail.com
Wed Mar 20 07:20:39 PDT 2013
sc/inc/stringutil.hxx | 21 ++++++++++++++++-----
sc/qa/unit/ucalc.cxx | 4 +---
sc/source/core/data/dbdocutl.cxx | 4 +---
sc/source/core/data/document.cxx | 4 +---
sc/source/core/data/dpoutput.cxx | 13 +++----------
sc/source/core/tool/stringutil.cxx | 14 ++++++++++++++
sc/source/filter/dif/difimp.cxx | 4 +---
sc/source/filter/excel/xihelper.cxx | 4 +---
sc/source/filter/xml/xmlcelli.cxx | 4 +---
sc/source/ui/view/dbfunc3.cxx | 7 ++++++-
10 files changed, 45 insertions(+), 34 deletions(-)
New commits:
commit 8d3c48729768367f2f4e9fb0b4c5f1380b297b67
Author: Kohei Yoshida <kohei.yoshida at gmail.com>
Date: Wed Mar 20 10:16:10 2013 -0400
Add convenience methods to set maximum text input and numeric input modes.
And remove one use of ScDocument::PutCell().
Change-Id: Iaa3c115794894964cb7c9f809235cdb7669be094
diff --git a/sc/inc/stringutil.hxx b/sc/inc/stringutil.hxx
index 132eb92..f5bdf3e 100644
--- a/sc/inc/stringutil.hxx
+++ b/sc/inc/stringutil.hxx
@@ -72,15 +72,26 @@ struct SC_DLLPUBLIC ScSetStringParam
TextFormatPolicy meSetTextNumFormat;
/**
- * When true, treat input with a leading apostrophe / single quote special
- * in that it escapes numeric or date/time input such that it is not
- * interpreted and the input string is taken instead. This can be used
- * during text file import so the leading apostrophe is not lost if it
- * precedes a numeric value.
+ * When true, treat input with a leading apostrophe as an escape character
+ * for a numeric value content, to treat the numeric value as a text. When
+ * false, the whole string input including the leading apostrophe will be
+ * entered literally as string.
*/
bool mbHandleApostrophe;
ScSetStringParam();
+
+ /**
+ * Call this whenever you need to unconditionally set input as text, no
+ * matter what the input is.
+ */
+ void setTextInput();
+
+ /**
+ * Call this whenever you need to maximize the chance of input being
+ * detected as a numeric value (numbers, dates, times etc).
+ */
+ void setNumericInput();
};
// ============================================================================
diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx
index cd8cf1f..4fb751f 100644
--- a/sc/qa/unit/ucalc.cxx
+++ b/sc/qa/unit/ucalc.cxx
@@ -498,9 +498,7 @@ void Test::testInput()
// Customized string handling policy.
ScSetStringParam aParam;
- aParam.mbDetectNumberFormat = false;
- aParam.meSetTextNumFormat = ScSetStringParam::Always;
- aParam.mbHandleApostrophe = false;
+ aParam.setTextInput();
m_pDoc->SetString(0, 0, 0, "000123", &aParam);
test = m_pDoc->GetString(0, 0, 0);
CPPUNIT_ASSERT_MESSAGE("Text content should have been treated as string, not number.", test == "000123");
diff --git a/sc/source/core/data/dbdocutl.cxx b/sc/source/core/data/dbdocutl.cxx
index 167290b..fcdfab5 100644
--- a/sc/source/core/data/dbdocutl.cxx
+++ b/sc/source/core/data/dbdocutl.cxx
@@ -179,9 +179,7 @@ void ScDatabaseDocUtil::PutData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB
else
{
ScSetStringParam aParam;
- aParam.mbDetectNumberFormat = false;
- aParam.mbHandleApostrophe = false;
- aParam.meSetTextNumFormat = ScSetStringParam::Always;
+ aParam.setTextInput();
pDoc->SetString(aPos, aString, &aParam);
if (pStrData)
pStrData->mbSimpleText = true;
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index bdef0e0..15fe129 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -3005,9 +3005,7 @@ void ScDocument::SetTextCell( const ScAddress& rPos, const OUString& rStr )
else
{
ScSetStringParam aParam;
- aParam.mbDetectNumberFormat = false;
- aParam.mbHandleApostrophe = false;
- aParam.meSetTextNumFormat = ScSetStringParam::Always;
+ aParam.setTextInput();
maTabs[rPos.Tab()]->SetString(rPos.Col(), rPos.Row(), rPos.Tab(), rStr, &aParam);
}
}
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index ae3e2eb..645e7b5 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -795,17 +795,10 @@ void ScDPOutput::HeaderCell( SCCOL nCol, SCROW nRow, SCTAB nTab,
bool bNumeric = (nFlags & sheet::MemberResultFlags::NUMERIC) != 0;
ScSetStringParam aParam;
if (bNumeric)
- {
- aParam.mbDetectNumberFormat = true;
- aParam.meSetTextNumFormat = ScSetStringParam::Never;
- aParam.mbHandleApostrophe = true;
- }
+ aParam.setNumericInput();
else
- {
- aParam.mbDetectNumberFormat = false;
- aParam.meSetTextNumFormat = ScSetStringParam::Always;
- aParam.mbHandleApostrophe = false;
- }
+ aParam.setTextInput();
+
pDoc->SetString(nCol, nRow, nTab, rData.Caption, &aParam);
}
diff --git a/sc/source/core/tool/stringutil.cxx b/sc/source/core/tool/stringutil.cxx
index 8924eca..3a997e9 100644
--- a/sc/source/core/tool/stringutil.cxx
+++ b/sc/source/core/tool/stringutil.cxx
@@ -30,6 +30,20 @@ ScSetStringParam::ScSetStringParam() :
{
}
+void ScSetStringParam::setTextInput()
+{
+ mbDetectNumberFormat = false;
+ mbHandleApostrophe = false;
+ meSetTextNumFormat = Always;
+}
+
+void ScSetStringParam::setNumericInput()
+{
+ mbDetectNumberFormat = true;
+ mbHandleApostrophe = true;
+ meSetTextNumFormat = Never;
+}
+
// ============================================================================-
bool ScStringUtil::parseSimpleNumber(
diff --git a/sc/source/filter/dif/difimp.cxx b/sc/source/filter/dif/difimp.cxx
index 4b20016..7e2ae9d 100644
--- a/sc/source/filter/dif/difimp.cxx
+++ b/sc/source/filter/dif/difimp.cxx
@@ -134,9 +134,7 @@ FltError ScFormatFilterPluginImpl::ScImportDif( SvStream& rIn, ScDocument* pDoc,
DATASET eAkt = D_UNKNOWN;
ScSetStringParam aStrParam; // used to set string value without number detection.
- aStrParam.mbDetectNumberFormat = false;
- aStrParam.mbHandleApostrophe = false;
- aStrParam.meSetTextNumFormat = ScSetStringParam::Always;
+ aStrParam.setTextInput();
while( eAkt != D_EOD )
{
diff --git a/sc/source/filter/excel/xihelper.cxx b/sc/source/filter/excel/xihelper.cxx
index 4f114a9..1656634 100644
--- a/sc/source/filter/excel/xihelper.cxx
+++ b/sc/source/filter/excel/xihelper.cxx
@@ -246,9 +246,7 @@ void XclImpStringHelper::SetToDocument(
{
// Normal text cell.
ScSetStringParam aParam;
- aParam.mbDetectNumberFormat = false;
- aParam.mbHandleApostrophe = false;
- aParam.meSetTextNumFormat = ScSetStringParam::Always;
+ aParam.setTextInput();
rDoc.SetString(rPos, aStr, &aParam);
}
}
diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx
index 86abcfb..4c335e7 100644
--- a/sc/source/filter/xml/xmlcelli.cxx
+++ b/sc/source/filter/xml/xmlcelli.cxx
@@ -1037,9 +1037,7 @@ void ScXMLTableRowCellContext::PutTextCell( const ScAddress& rCurrentPos,
{
// This is a normal text without format runs.
ScSetStringParam aParam;
- aParam.mbDetectNumberFormat = false;
- aParam.mbHandleApostrophe = false;
- aParam.meSetTextNumFormat = ScSetStringParam::Always;
+ aParam.setTextInput();
pDoc->SetString(rCurrentPos, mpEditEngine->GetText(), &aParam);
}
else
diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx
index 5e27355..b159103 100644
--- a/sc/source/ui/view/dbfunc3.cxx
+++ b/sc/source/ui/view/dbfunc3.cxx
@@ -65,6 +65,7 @@
#include "userlist.hxx"
#include "queryentry.hxx"
#include "markdata.hxx"
+#include "stringutil.hxx"
#include <boost/unordered_set.hpp>
#include <boost/unordered_map.hpp>
@@ -2029,7 +2030,11 @@ void ScDBFunc::ShowDataPilotSourceData( ScDPObject& rDPObj, const Sequence<sheet
rtl::OUString aStr;
double fVal;
if (rAny >>= aStr)
- pInsDoc->PutCell( ScAddress(nCol, nRow, nNewTab), new ScStringCell(String(aStr)) );
+ {
+ ScSetStringParam aParam;
+ aParam.setTextInput();
+ pInsDoc->SetString(ScAddress(nCol,nRow,nNewTab), aStr);
+ }
else if (rAny >>= fVal)
pInsDoc->SetValue(nCol, nRow, nNewTab, fVal);
}
More information about the Libreoffice-commits
mailing list