[Libreoffice-commits] core.git: Branch 'libreoffice-5-4' - 2 commits - chart2/qa sc/source sw/source

Caolán McNamara caolanm at redhat.com
Thu Jul 6 21:16:33 UTC 2017


 chart2/qa/extras/PivotChartTest.cxx            |  112 +++++++++++++++++++++----
 sc/source/ui/unoobj/PivotTableDataProvider.cxx |    7 -
 sw/source/filter/ww8/ww8par3.cxx               |    2 
 3 files changed, 100 insertions(+), 21 deletions(-)

New commits:
commit 571dea70574294d75051a37fa4f5eef5e9ed5cbc
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Thu Jul 6 08:51:01 2017 +0100

    ofz: stay inside string
    
    Change-Id: Ia0d0ddfce4ee3d5f8763be6804fe52c514375bb3
    Reviewed-on: https://gerrit.libreoffice.org/39629
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 073a2b2aef5c0b579aea8ed203dd9c1c5790b650)
    Reviewed-on: https://gerrit.libreoffice.org/39644
    Reviewed-by: Michael Stahl <mstahl at redhat.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sw/source/filter/ww8/ww8par3.cxx b/sw/source/filter/ww8/ww8par3.cxx
index af4ef9a58bbc..397c664ad71c 100644
--- a/sw/source/filter/ww8/ww8par3.cxx
+++ b/sw/source/filter/ww8/ww8par3.cxx
@@ -221,7 +221,7 @@ eF_ResT SwWW8ImplReader::Read_F_FormListBox( WW8FieldDesc* pF, OUString& rStr)
 {
     WW8FormulaListBox aFormula(*this);
 
-    if (rStr[pF->nLCode-1]==0x01)
+    if (pF->nLCode > 0 && rStr.getLength() >= pF->nLCode && rStr[pF->nLCode-1] == 0x01)
         ImportFormulaControl(aFormula,pF->nSCode+pF->nLCode-1, WW8_CT_DROPDOWN);
 
     const SvtFilterOptions& rOpt = SvtFilterOptions::Get();
commit 2d66c7d4e710a4407b4d6685b3b41f3841d6da11
Author: Dennis Francis <dennis.francis at collabora.co.uk>
Date:   Wed Jul 5 11:44:58 2017 +0530

    tdf#108923 : Use display string for generating chart labels
    
    Use display string for generating chart labels in
    PivotTableDataProvider::collectPivotTableData as chart2
    does not seem to use number format for labels although it
    does for the data.
    
    Added unit test PivotChartTest::testPivotChartWithDateRowField()
    for this fix.
    
    Change-Id: I668d4c9d7cf8bbb7e4213cce7a6e7cd4d7d07cbe
    Reviewed-on: https://gerrit.libreoffice.org/39548
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
    (cherry picked from commit 5eeed755a2eadbadd7a2e0c06216258af028a96e)
    Reviewed-on: https://gerrit.libreoffice.org/39654
    Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice at googlemail.com>

diff --git a/chart2/qa/extras/PivotChartTest.cxx b/chart2/qa/extras/PivotChartTest.cxx
index f1a345fa964c..8d12782057f2 100644
--- a/chart2/qa/extras/PivotChartTest.cxx
+++ b/chart2/qa/extras/PivotChartTest.cxx
@@ -22,7 +22,12 @@
 #include <com/sun/star/table/XTablePivotChart.hpp>
 #include <com/sun/star/table/XTablePivotCharts.hpp>
 #include <com/sun/star/table/XTablePivotChartsSupplier.hpp>
+#include <com/sun/star/table/XCellRange.hpp>
 #include <com/sun/star/sheet/GeneralFunction.hpp>
+#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
+#include <com/sun/star/util/XNumberFormats.hpp>
+#include <com/sun/star/util/XNumberFormatTypes.hpp>
+#include <com/sun/star/util/NumberFormat.hpp>
 
 #include <com/sun/star/chart2/data/XPivotTableDataProvider.hpp>
 #include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
@@ -43,6 +48,7 @@ public:
     void testPivotChartWithOneRowField();
     void testPivotTableDataProvider_PivotTableFields();
     void testPivotChartRowFieldInOutlineMode();
+    void testPivotChartWithDateRowField();
 
     CPPUNIT_TEST_SUITE(PivotChartTest);
     CPPUNIT_TEST(testRoundtrip);
@@ -51,6 +57,7 @@ public:
     CPPUNIT_TEST(testPivotChartWithOneRowField);
     CPPUNIT_TEST(testPivotTableDataProvider_PivotTableFields);
     CPPUNIT_TEST(testPivotChartRowFieldInOutlineMode);
+    CPPUNIT_TEST(testPivotChartWithDateRowField);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -233,22 +240,22 @@ table::CellRangeAddress lclCreateTestData(uno::Reference<sheet::XSpreadsheetDocu
     CPPUNIT_ASSERT_MESSAGE("no calc document!", xSheetDoc.is());
 
     std::vector<OUString> aHeaders {
-        "Country", "City", "Type", "Sales T1", "Sales T2", "Sales T3", "Sales T4"
+        "Country", "City", "Type", "Sales T1", "Sales T2", "Sales T3", "Sales T4", "Date"
     };
 
     std::vector<std::vector<Value>> aData {
-        { {"FR"}, {"Paris"},     {"A"}, {123.0}, {223.0}, {323.0}, {423.0} },
-        { {"EN"}, {"London"},    {"A"}, {456.0}, {556.0}, {656.0}, {756.0} },
-        { {"DE"}, {"Berlin"},    {"A"}, {468.0}, {568.0}, {668.0}, {768.0} },
-        { {"FR"}, {"Nantes"},    {"A"}, {694.0}, {794.0}, {894.0}, {994.0} },
-        { {"EN"}, {"Glasgow"},   {"A"}, {298.0}, {398.0}, {498.0}, {598.0} },
-        { {"DE"}, {"Munich"},    {"A"}, {369.0}, {469.0}, {569.0}, {669.0} },
-        { {"FR"}, {"Paris"},     {"B"}, {645.0}, {745.0}, {845.0}, {945.0} },
-        { {"EN"}, {"London"},    {"B"}, {687.0}, {787.0}, {887.0}, {987.0} },
-        { {"DE"}, {"Munich"},    {"B"}, {253.0}, {353.0}, {453.0}, {553.0} },
-        { {"FR"}, {"Nantes"},    {"B"}, {474.0}, {574.0}, {674.0}, {774.0} },
-        { {"EN"}, {"Liverpool"}, {"B"}, {562.0}, {662.0}, {762.0}, {862.0} },
-        { {"DE"}, {"Berlin"},    {"B"}, {648.0}, {748.0}, {848.0}, {948.0} }
+        { {"FR"}, {"Paris"},     {"A"}, {123.0}, {223.0}, {323.0}, {423.0}, {"12/14/15"} },
+        { {"EN"}, {"London"},    {"A"}, {456.0}, {556.0}, {656.0}, {756.0}, {"12/11/15"} },
+        { {"DE"}, {"Berlin"},    {"A"}, {468.0}, {568.0}, {668.0}, {768.0}, {"12/11/15"} },
+        { {"FR"}, {"Nantes"},    {"A"}, {694.0}, {794.0}, {894.0}, {994.0}, {"12/11/15"} },
+        { {"EN"}, {"Glasgow"},   {"A"}, {298.0}, {398.0}, {498.0}, {598.0}, {"12/11/15"} },
+        { {"DE"}, {"Munich"},    {"A"}, {369.0}, {469.0}, {569.0}, {669.0}, {"12/11/15"} },
+        { {"FR"}, {"Paris"},     {"B"}, {645.0}, {745.0}, {845.0}, {945.0}, {"12/11/15"} },
+        { {"EN"}, {"London"},    {"B"}, {687.0}, {787.0}, {887.0}, {987.0}, {"03/21/17"} },
+        { {"DE"}, {"Munich"},    {"B"}, {253.0}, {353.0}, {453.0}, {553.0}, {"12/17/15"} },
+        { {"FR"}, {"Nantes"},    {"B"}, {474.0}, {574.0}, {674.0}, {774.0}, {"01/20/16"} },
+        { {"EN"}, {"Liverpool"}, {"B"}, {562.0}, {662.0}, {762.0}, {862.0}, {"01/20/16"} },
+        { {"DE"}, {"Berlin"},    {"B"}, {648.0}, {748.0}, {848.0}, {948.0}, {"01/20/16"} }
     };
 
     // Getting spreadsheet
@@ -282,12 +289,25 @@ table::CellRangeAddress lclCreateTestData(uno::Reference<sheet::XSpreadsheetDocu
         currentRow++;
     }
 
+    sal_Int32 nEndCol = sal_Int32(aHeaders.size() - 1);
+    sal_Int32 nEndRow = sal_Int32(1/*HEADER*/ + aData.size() - 1);
+
+    // Apply date format to the last column
+    uno::Reference<util::XNumberFormatsSupplier> xNumberFormatsSupplier(xSheetDoc, UNO_QUERY_THROW);
+    uno::Reference<util::XNumberFormats> xNumberFormats = xNumberFormatsSupplier->getNumberFormats();
+    uno::Reference<util::XNumberFormatTypes> xNumberFormatTypes(xNumberFormats, UNO_QUERY_THROW);
+    lang::Locale aLocale;
+    sal_Int32 nDateKey = xNumberFormatTypes->getStandardFormat(util::NumberFormat::DATE, aLocale);
+    uno::Reference<table::XCellRange> xCellRange = xSheet->getCellRangeByPosition(nEndCol, 1, nEndCol, nEndRow);
+    uno::Reference<beans::XPropertySet> xCellProp(xCellRange, UNO_QUERY_THROW);
+    xCellProp->setPropertyValue("NumberFormat", uno::makeAny(nDateKey));
+
     table::CellRangeAddress sCellRangeAdress;
     sCellRangeAdress.Sheet = 0;
     sCellRangeAdress.StartColumn = 0;
     sCellRangeAdress.StartRow = 0;
-    sCellRangeAdress.EndColumn = sal_Int32(aHeaders.size() - 1);
-    sCellRangeAdress.EndRow = sal_Int32(1/*HEADER*/ + aData.size() - 1);
+    sCellRangeAdress.EndColumn = nEndCol;
+    sCellRangeAdress.EndRow = nEndRow;
 
     return sCellRangeAdress;
 }
@@ -918,6 +938,68 @@ void PivotChartTest::testPivotChartRowFieldInOutlineMode()
     }
 }
 
+void PivotChartTest::testPivotChartWithDateRowField()
+{
+    // SETUP DATA and PIVOT TABLE
+
+    if (!mxComponent.is())
+        mxComponent = loadFromDesktop("private:factory/scalc");
+
+    uno::Reference<sheet::XSpreadsheetDocument> xSheetDoc(mxComponent, uno::UNO_QUERY_THROW);
+
+    OUString sPivotTableName("DataPilotTable");
+
+    table::CellRangeAddress sCellRangeAdress = lclCreateTestData(xSheetDoc);
+
+    uno::Reference<sheet::XDataPilotTables> xDataPilotTables;
+    xDataPilotTables = lclGetDataPilotTables(0, xSheetDoc);
+
+    uno::Reference<sheet::XDataPilotDescriptor> xDataPilotDescriptor;
+    xDataPilotDescriptor = xDataPilotTables->createDataPilotDescriptor();
+    xDataPilotDescriptor->setSourceRange(sCellRangeAdress);
+
+    lclModifyOrientation(xDataPilotDescriptor, "Date", sheet::DataPilotFieldOrientation_ROW);
+    lclModifyOrientation(xDataPilotDescriptor, "City", sheet::DataPilotFieldOrientation_ROW);
+    lclModifyOrientation(xDataPilotDescriptor, "Country", sheet::DataPilotFieldOrientation_ROW);
+    lclModifyOrientation(xDataPilotDescriptor, "Type", sheet::DataPilotFieldOrientation_COLUMN);
+    lclModifyOrientation(xDataPilotDescriptor, "Sales T1", sheet::DataPilotFieldOrientation_DATA);
+    lclModifyFunction(xDataPilotDescriptor, "Sales T1", sheet::GeneralFunction_SUM);
+
+    lclModifyColumnGrandTotal(xDataPilotDescriptor, true);
+    lclModifyRowGrandTotal(xDataPilotDescriptor, true);
+
+    xDataPilotTables->insertNewByName(sPivotTableName, table::CellAddress{1, 0, 0}, xDataPilotDescriptor);
+
+    // TEST
+    Reference<chart2::XChartDocument> xChartDoc;
+
+    // Check we have the Pivot Table
+    uno::Reference<sheet::XDataPilotTable> xDataPilotTable = lclGetPivotTableByName(1, sPivotTableName, mxComponent);
+    CPPUNIT_ASSERT(xDataPilotTable.is());
+
+    // refetch the XDataPilotDescriptor
+    xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
+
+    // Check that we don't have any pivot chart in the document
+    uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1, mxComponent);
+    uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
+
+    // Create a new pivot chart
+    xTablePivotCharts->addNewByName("PivotChart", awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
+    CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
+
+    // Get the pivot chart document so we can access its data
+    xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
+
+    CPPUNIT_ASSERT(xChartDoc.is());
+
+    // Check if Date category is date formatted.
+    lclCheckCategories( { "12/11/15", "", "", "", "", "", "12/14/15", "12/17/15", "01/20/16", "", "", "03/21/17" },
+                        lclGetCategories( xChartDoc )[0]->getValues() );
+}
+
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PivotChartTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
index d412265b033c..050f91122323 100644
--- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
@@ -459,11 +459,8 @@ void PivotTableDataProvider::collectPivotTableData()
                             {
                                 if (!bHasContinueFlag)
                                 {
-                                    double fValue = rMember.Value;
-                                    if (rtl::math::isNan(fValue))
-                                        pItem.reset(new ValueAndFormat(rMember.Caption));
-                                    else
-                                        pItem.reset(new ValueAndFormat(fValue, nNumberFormat));
+                                    // Chart2 does not use number format for labels, so use the display string.
+                                    pItem.reset(new ValueAndFormat(rMember.Caption));
                                 }
 
                                 if (bFound)


More information about the Libreoffice-commits mailing list