[Libreoffice-commits] core.git: sw/qa sw/source

aqcoder flw.aquarius at gmail.com
Thu Dec 24 11:45:59 PST 2015


 sw/qa/extras/inc/swmodeltestbase.hxx                  |   14 +++++++++
 sw/qa/extras/odfexport/data/userdefattr-tablecell.odt |binary
 sw/qa/extras/odfexport/odfexport.cxx                  |   11 +++++++
 sw/source/filter/xml/xmltble.cxx                      |   26 +++++++++++++++++-
 4 files changed, 50 insertions(+), 1 deletion(-)

New commits:
commit d3e57ccf2e56a75bd4f004de53793f1742e34bc4
Author: aqcoder <flw.aquarius at gmail.com>
Date:   Thu Dec 17 21:22:34 2015 +0800

    tdf#96412 Fix export text table cell UserDefinedAttributes to xml.
    
    It also export to different Fmt when only have the difference of
    UserDefinedAttributes for the text table cell.
    
    Change-Id: I022b627926870b883eea363567a34b61c34ab353
    Reviewed-on: https://gerrit.libreoffice.org/20765
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: jan iversen <jani at documentfoundation.org>

diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index ce02b3e..dc977f1 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -11,6 +11,7 @@
 #define INCLUDED_SW_QA_EXTRAS_INC_SWMODELTESTBASE_HXX
 
 #include <com/sun/star/container/XContentEnumerationAccess.hpp>
+#include <com/sun/star/container/XNameAccess.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/packages/zip/ZipFileAccess.hpp>
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
@@ -28,6 +29,7 @@
 #include <com/sun/star/sdb/DatabaseContext.hpp>
 #include <com/sun/star/sdb/XDocumentDataSource.hpp>
 #include <com/sun/star/sdbc/XRowSet.hpp>
+#include <com/sun/star/xml/AttributeData.hpp>
 
 #include <test/bootstrapfixture.hxx>
 #include <test/xmltesttools.hxx>
@@ -433,6 +435,18 @@ protected:
         return properties->getPropertySetInfo()->hasPropertyByName(name);
     }
 
+    xml::AttributeData getUserDefineAttribute(const uno::Any& obj, const OUString& name, const OUString& rValue = OUString()) const
+    {
+        uno::Reference<container::XNameContainer> attrsCnt(getProperty<uno::Any>(obj, "UserDefinedAttributes"), uno::UNO_QUERY_THROW);
+
+        xml::AttributeData aValue;
+        attrsCnt->getByName(name) >>= aValue;
+        if (!rValue.isEmpty())
+            CPPUNIT_ASSERT_EQUAL_MESSAGE("attribtes of cell does not contain expected value", rValue, aValue.Value);
+
+        return aValue;
+    }
+
     /// Get number of paragraphs of the document.
     int getParagraphs()
     {
diff --git a/sw/qa/extras/odfexport/data/userdefattr-tablecell.odt b/sw/qa/extras/odfexport/data/userdefattr-tablecell.odt
new file mode 100644
index 0000000..c8f6dcc
Binary files /dev/null and b/sw/qa/extras/odfexport/data/userdefattr-tablecell.odt differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index addf9c5..1226228 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -770,6 +770,17 @@ DECLARE_ODFEXPORT_TEST(testOdtBorderTypes, "border_types.odt")
     } while (xParaEnum->hasMoreElements());
 }
 
+DECLARE_ODFEXPORT_TEST(testCellUserDefineAttr, "userdefattr-tablecell.odt")
+{
+    uno::Reference<text::XTextTable> xTable(getParagraphOrTable(0), uno::UNO_QUERY);
+    uno::Reference<table::XCell> const xCellA1(xTable->getCellByName("A1"), uno::UNO_SET_THROW);
+    uno::Reference<table::XCell> const xCellB1(xTable->getCellByName("B1"), uno::UNO_SET_THROW);
+    uno::Reference<table::XCell> const xCellC1(xTable->getCellByName("C1"), uno::UNO_SET_THROW);
+    getUserDefineAttribute(uno::makeAny(xCellA1), "proName", "v1");
+    getUserDefineAttribute(uno::makeAny(xCellB1), "proName", "v2");
+    getUserDefineAttribute(uno::makeAny(xCellC1), "proName", "v3");
+}
+
 #endif
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx
index 227ea83..6b891a3 100644
--- a/sw/source/filter/xml/xmltble.cxx
+++ b/sw/source/filter/xml/xmltble.cxx
@@ -29,6 +29,7 @@
 #include <svl/zforlist.hxx>
 #include <editeng/brushitem.hxx>
 #include <editeng/boxitem.hxx>
+#include <editeng/xmlcnitm.hxx>
 #include <fmtrowsplt.hxx>
 #include <editeng/frmdiritem.hxx>
 #include <list>
@@ -312,6 +313,7 @@ bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat,
     const SvxBoxItem *pBox = nullptr;
     const SwTableBoxNumFormat *pNumFormat = nullptr;
     const SvxFrameDirectionItem *pFrameDir = nullptr;
+    const SvXMLAttrContainerItem *pAttCnt = nullptr;
 
     const SfxItemSet& rItemSet = rFrameFormat.GetAttrSet();
     const SfxPoolItem *pItem;
@@ -331,9 +333,12 @@ bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat,
     if ( SfxItemState::SET == rItemSet.GetItemState( RES_FRAMEDIR,
                                                 false, &pItem ) )
         pFrameDir = static_cast<const SvxFrameDirectionItem *>(pItem);
+    if ( SfxItemState::SET == rItemSet.GetItemState( RES_UNKNOWNATR_CONTAINER,
+                                                false, &pItem ) )
+        pAttCnt = static_cast<const SvXMLAttrContainerItem *>(pItem);
 
     // empty styles have not to be exported
-    if( !pVertOrient && !pBrush && !pBox && !pNumFormat && !pFrameDir )
+    if( !pVertOrient && !pBrush && !pBox && !pNumFormat && !pFrameDir && !pAttCnt )
         return false;
 
     // order is: -/-/-/num,
@@ -351,6 +356,7 @@ bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat,
         const SvxBoxItem *pTestBox = nullptr;
         const SwTableBoxNumFormat *pTestNumFormat = nullptr;
         const SvxFrameDirectionItem *pTestFrameDir = nullptr;
+        const SvXMLAttrContainerItem *pTestAttCnt = nullptr;
         const SwFrameFormat* pTestFormat = *i;
         const SfxItemSet& rTestSet = pTestFormat->GetAttrSet();
         if( SfxItemState::SET == rTestSet.GetItemState( RES_VERT_ORIENT, false,
@@ -424,6 +430,21 @@ bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat,
 
         }
 
+        if ( SfxItemState::SET == rTestSet.GetItemState( RES_UNKNOWNATR_CONTAINER,
+                                                false, &pItem ) )
+        {
+             if( !pAttCnt )
+                 break;
+
+             pTestAttCnt = static_cast<const SvXMLAttrContainerItem *>(pItem);
+        }
+        else
+        {
+             if ( pAttCnt )
+                 continue;
+
+        }
+
         if( pVertOrient &&
             pVertOrient->GetVertOrient() != pTestVertOrient->GetVertOrient() )
             continue;
@@ -440,6 +461,9 @@ bool SwXMLTableFrameFormatsSort_Impl::AddCell( SwFrameFormat& rFrameFormat,
         if( pFrameDir && pFrameDir->GetValue() != pTestFrameDir->GetValue() )
             continue;
 
+        if( pAttCnt && ( *pAttCnt != *pTestAttCnt ) )
+            continue;
+
         // found!
         rFrameFormat.SetName( pTestFormat->GetName() );
         bInsert = false;


More information about the Libreoffice-commits mailing list