summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNiklas Johansson <sleeping.pillow@gmail.com>2015-10-23 19:52:17 +0200
committerJan Holesovsky <kendy@collabora.com>2015-11-04 14:30:06 +0000
commitaa334d55ee34c125f6f4fdfaadbc1ed8fa33f5bc (patch)
treef92552a5e059c0d1e8791878f521a41b90965fe0
parent6f1c202547d087d1115ab023f9b6ee4c230c6602 (diff)
Make number recognition work in writer tables again
It seems that number recognition in tables are not working properly enter 10-10-10 and it should be converted to a date but it is not. I tracked it down to the fix of bug fdo#32082. It looks like bSetNumFmt was changed to false by mistake. Since then it has changed name to bSetNumFormat. From what I can tell fdo#32082 still works after this patch, but I might have missed some nuance of that bug report. Added two tests, one for the bug mentioned above and one to check that number recognition is working. At least with a simple date. Change-Id: Id58849a223eb602054c66c7379cd56a68a93dea2 Reviewed-on: https://gerrit.libreoffice.org/19563 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r--sw/qa/python/check_table.py70
-rw-r--r--sw/source/core/docnode/ndtbl.cxx2
2 files changed, 71 insertions, 1 deletions
diff --git a/sw/qa/python/check_table.py b/sw/qa/python/check_table.py
index a5a8308e355c..1e361cfa5cd7 100644
--- a/sw/qa/python/check_table.py
+++ b/sw/qa/python/check_table.py
@@ -7,6 +7,8 @@ from com.sun.star.table import BorderLine
from com.sun.star.table import BorderLine2
from com.sun.star.table.BorderLineStyle import (DOUBLE, SOLID, EMBOSSED,\
THICKTHIN_LARGEGAP, DASHED, DOTTED)
+from com.sun.star.util import XNumberFormats
+from com.sun.star.lang import Locale
class CheckTable(unittest.TestCase):
_uno = None
@@ -450,6 +452,74 @@ class CheckTable(unittest.TestCase):
self.assertEqual(
[int(txtval) for txtval in xSeq.TextualData],
[val for val in expectedValues[col]])
+ xDoc.dispose()
+
+ def test_tdf32082(self):
+ xDoc = CheckTable._uno.openEmptyWriterDoc()
+ xDocFrame = xDoc.CurrentController.Frame
+ xContext = CheckTable._uno.getContext()
+ xServiceManager = xContext.ServiceManager
+ xDispatcher = xServiceManager.createInstanceWithContext(
+ 'com.sun.star.frame.DispatchHelper', xContext)
+ xTable = xDoc.createInstance("com.sun.star.text.TextTable")
+ xTable.initialize(1,1)
+ xCursor = xDoc.Text.createTextCursor()
+ xDoc.Text.insertTextContent(xCursor, xTable, False)
+ # Setup numberformat for the cell
+ xNumberFormats = xDoc.NumberFormats
+ xLocale = Locale('en', 'US', '')
+ formatString = '#,##0.00 [$€-407];[RED]-#,##0.00 [$€-407]'
+ key = xNumberFormats.queryKey(formatString, xLocale, True)
+ if key == -1:
+ key = xNumberFormats.addNew(formatString, xLocale)
+ # Apply the format on the first cell
+ xTable.getCellByPosition(0,0).NumberFormat = key
+ xDispatcher.executeDispatch(xDocFrame, '.uno:GoToStartOfDoc', '', 0, ())
+ xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+ (PropertyValue('Text', 0, '3', 0),))
+ xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+ # Check that the formatting we set up is not destroyed
+ self.assertEquals(xTable.getCellByPosition(0,0).getString(), '3.00 €')
+ self.assertEquals(xTable.getCellByPosition(0,0).getValue(), 3)
+ # Verify that it works with number recognition turned on as well
+ xDispatcher.executeDispatch(xDocFrame, '.uno:TableNumberRecognition', '', 0,
+ (PropertyValue('TableNumberRecognition', 0, True, 0),))
+ xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+ (PropertyValue('Text', 0, '4', 0),))
+ xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+ self.assertEquals(xTable.getCellByPosition(0,1).getString(), '4.00 €')
+ self.assertEquals(xTable.getCellByPosition(0,1).getValue(), 4)
+ xDoc.dispose()
+
+ def test_numberRecognition(self):
+ xDoc = CheckTable._uno.openEmptyWriterDoc()
+ xDocFrame = xDoc.CurrentController.Frame
+ xContext = CheckTable._uno.getContext()
+ xServiceManager = xContext.ServiceManager
+ xDispatcher = xServiceManager.createInstanceWithContext(
+ 'com.sun.star.frame.DispatchHelper', xContext)
+ xTable = xDoc.createInstance('com.sun.star.text.TextTable')
+ xTable.initialize(2,1)
+ xCursor = xDoc.Text.createTextCursor()
+ xDoc.Text.insertTextContent(xCursor, xTable, False)
+ xDispatcher.executeDispatch(xDocFrame, '.uno:GoToStartOfDoc', '', 0, ())
+ xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+ (PropertyValue('Text', 0, '15-10-30', 0),))
+ xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+ # Without number recognition 15-10-30 should not be interperated as a date
+ self.assertEquals(xTable.getCellByPosition(0,0).getString(), '15-10-30')
+ self.assertEquals(xTable.getCellByPosition(0,0).getValue(), 0)
+ # Activate number recognition
+ xDispatcher.executeDispatch(xDocFrame, '.uno:TableNumberRecognition', '', 0,
+ (PropertyValue('TableNumberRecognition', 0, True, 0),))
+ xDispatcher.executeDispatch(xDocFrame, '.uno:InsertText', '', 0,
+ (PropertyValue('Text', 0, '15-10-30', 0),))
+ xDispatcher.executeDispatch(xDocFrame, '.uno:JumpToNextCell', '', 0, ())
+ # With number recognition it should now be a date, confirm by checking
+ # the string and value of the cell.
+ self.assertEquals(xTable.getCellByPosition(0,1).getString(), '2015-10-30')
+ self.assertEquals(xTable.getCellByPosition(0,1).getValue(), 42307.0)
+ xDoc.dispose()
if __name__ == '__main__':
unittest.main()
diff --git a/sw/source/core/docnode/ndtbl.cxx b/sw/source/core/docnode/ndtbl.cxx
index 1faddb2c21fd..cef4277322c1 100644
--- a/sw/source/core/docnode/ndtbl.cxx
+++ b/sw/source/core/docnode/ndtbl.cxx
@@ -4060,7 +4060,7 @@ void SwDoc::ChkBoxNumFormat( SwTableBox& rBox, bool bCallUpdate )
SfxItemSet aBoxSet( GetAttrPool(), RES_BOXATR_FORMAT, RES_BOXATR_VALUE );
bool bLockModify = true;
- bool bSetNumberFormat = false;
+ bool bSetNumberFormat = IsInsTableFormatNum();
const bool bForceNumberFormat = IsInsTableFormatNum() && IsInsTableChangeNumFormat();
// if the user forced a number format in this cell previously,