[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - sw/inc sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Sep 1 23:04:29 UTC 2018


 sw/inc/doc.hxx                             |    4 ++
 sw/inc/ndtxt.hxx                           |    6 ++--
 sw/qa/extras/mailmerge/data/tdf118845.fodt |   28 ++++++++++++++++++++
 sw/qa/extras/mailmerge/mailmerge.cxx       |   40 +++++++++++++++++++++++++++++
 sw/source/core/doc/doc.cxx                 |   18 +++++++------
 sw/source/core/text/txtfrm.cxx             |   17 ++++++++----
 sw/source/core/txtnode/thints.cxx          |   24 ++++++++++++-----
 7 files changed, 115 insertions(+), 22 deletions(-)

New commits:
commit 481730bc4c9d63e831c088d9862b0f50f2da209f
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Thu Aug 30 12:23:33 2018 +0300
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Sun Sep 2 01:04:09 2018 +0200

    tdf#118845: make HiddenPara have higher priority deciding visibility
    
    Otherwise, a Database field in a paragraph which is non-empty would
    force the paragraph to be visible, regardless of HiddenPara field
    telling it to be hidden.
    
    Regression from commit db04be037b611e296ef9f2542322c52ed82d7a2b
    
    Change-Id: I21807e22bd339fd1ea0aaa3b382579f688903418
    Reviewed-on: https://gerrit.libreoffice.org/59792
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <Michael.Stahl at cib.de>
    (cherry picked from commit 64cb57c82d9e7f7069821b2e2ef92574ec73ebe2)
    Reviewed-on: https://gerrit.libreoffice.org/59865
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index ab3acf7d9070..f92fbc70fe8b 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -466,7 +466,9 @@ public:
 
     ::sw::DocumentFieldsManager & GetDocumentFieldsManager();
 
-    bool FieldCanHidePara(SwFieldIds eFieldId) const;
+    // Returns 0 if the field cannot hide para, or a positive integer indicating the field type
+    // "weight" when several hiding fields' FieldHidesPara() give conflicting results
+    int FieldCanHideParaWeight(SwFieldIds eFieldId) const;
     bool FieldHidesPara(const SwField& rField) const;
 
     // IDocumentContentOperations
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index e40e056a1964..cc8091547b87 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -709,8 +709,10 @@ public:
     bool IsHiddenByParaField() const
         { return m_pSwpHints && m_pSwpHints->IsHiddenByParaField(); }
 
-    bool FieldCanHidePara(SwFieldIds eFieldId) const
-        { return GetDoc()->FieldCanHidePara(eFieldId); }
+    int FieldCanHideParaWeight(SwFieldIds eFieldId) const
+        {
+            return GetDoc()->FieldCanHideParaWeight(eFieldId);
+        }
     bool FieldHidesPara(const SwField& rField) const
         { return GetDoc()->FieldHidesPara(rField); }
 
diff --git a/sw/qa/extras/mailmerge/data/tdf118845.fodt b/sw/qa/extras/mailmerge/data/tdf118845.fodt
new file mode 100644
index 000000000000..64a5180da718
--- /dev/null
+++ b/sw/qa/extras/mailmerge/data/tdf118845.fodt
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<office:document xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:ooo="http://openoffice.org/2004/office" xmlns:ooow="http://openoffice.org/2004/writer" xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0" office:version="1.2" office:mimetype="application/vnd.oasis.opendocument.text">
+ <office:settings>
+  <config:config-item-set config:name="ooo:configuration-settings">
+   <config:config-item config:name="CurrentDatabaseDataSource" config:type="string">4_v01</config:config-item>
+   <config:config-item config:name="CurrentDatabaseCommand" config:type="string">Tabelle1</config:config-item>
+   <config:config-item config:name="CurrentDatabaseCommandType" config:type="int">0</config:config-item>
+   <config:config-item config:name="EmptyDbFieldHidesPara" config:type="boolean">true</config:config-item>
+  </config:config-item-set>
+ </office:settings>
+ <office:automatic-styles>
+  <style:page-layout style:name="pm1">
+   <style:page-layout-properties fo:page-width="21cm" fo:page-height="29.7cm" style:print-orientation="portrait" fo:margin-top="2cm" fo:margin-bottom="2cm" fo:margin-left="2cm" fo:margin-right="2cm"/>
+  </style:page-layout>
+ </office:automatic-styles>
+ <office:master-styles>
+  <style:master-page style:name="Standard" style:page-layout-name="pm1"/>
+ </office:master-styles>
+ <office:body>
+  <office:text>
+   <text:p><text:hidden-paragraph text:condition="ooow:([4_v01.Tabelle1.Anrede] != "Frau" OR NOT [4_v01.Tabelle1.Nachname]) OR (![4_v01.Tabelle1.Nachname])"/><text:span text:style-name="T1">Dear Mrs. </text:span><text:span text:style-name="T1"><text:database-display text:table-name="Tabelle1" text:table-type="table" text:column-name="Nachname" text:database-name="4_v01"><Nachname></text:database-display></text:span><text:span text:style-name="T1">,</text:span></text:p>
+   <text:p><text:hidden-paragraph text:condition="ooow:[4_v01.Tabelle1.Anrede] == "Frau" OR NOT [4_v01.Tabelle1.Nachname]"/><text:span text:style-name="T1">Dear Mr. </text:span><text:span text:style-name="T1"><text:database-display text:table-name="Tabelle1" text:table-type="table" text:column-name="Nachname" text:database-name="4_v01"><Nachname></text:database-display></text:span><text:span text:style-name="T1">,</text:span></text:p>
+   <text:p><text:hidden-paragraph text:condition="ooow:[4_v01.Tabelle1.Nachname]"/><text:span text:style-name="T1">To whom it may concern,</text:span></text:p>
+   <text:p/>
+  </office:text>
+ </office:body>
+</office:document>
\ No newline at end of file
diff --git a/sw/qa/extras/mailmerge/mailmerge.cxx b/sw/qa/extras/mailmerge/mailmerge.cxx
index b207547fffb5..36ff5c80fafd 100644
--- a/sw/qa/extras/mailmerge/mailmerge.cxx
+++ b/sw/qa/extras/mailmerge/mailmerge.cxx
@@ -818,5 +818,45 @@ DECLARE_FILE_MAILMERGE_TEST(testEmptyValuesNewFODT, "tdf35798-new.fodt", "5-with
     }
 }
 
+DECLARE_SHELL_MAILMERGE_TEST(testTdf118845, "tdf118845.fodt", "4_v01.ods", "Tabelle1")
+{
+    executeMailMerge();
+
+    // Both male and female greetings were shown, thus each page had 3 paragraphs
+
+    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxMMComponent.get());
+    CPPUNIT_ASSERT(pTextDoc);
+    sal_uInt16 nPhysPages = pTextDoc->GetDocShell()->GetWrtShell()->GetPhyPageNum();
+    CPPUNIT_ASSERT_EQUAL(sal_uInt16(7), nPhysPages); // 4 pages, each odd, and 3 blanks
+
+    uno::Reference<text::XTextDocument> xTextDocument(mxMMComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(8, getParagraphs(xTextDocument->getText()));
+
+    uno::Reference<text::XTextRange> xParagraph(getParagraphOrTable(1, xTextDocument->getText()),
+                                                uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Dear Mrs. Mustermann1,"), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(2, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString(""), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(3, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Dear Mr. Mustermann2,"), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(4, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString(""), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(5, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Dear Mrs. Mustermann3,"), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(6, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString(""), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(7, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString("Dear Mr. Mustermann4,"), xParagraph->getString());
+
+    xParagraph.set(getParagraphOrTable(8, xTextDocument->getText()), uno::UNO_QUERY);
+    CPPUNIT_ASSERT_EQUAL(OUString(""), xParagraph->getString());
+}
+
 CPPUNIT_PLUGIN_IMPLEMENT();
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 450fc3aed05c..4f4fb864512e 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1360,17 +1360,20 @@ bool HandleHidingField(SwFormatField& rFormatField, const SwNodes& rNodes,
 }
 }
 
-bool SwDoc::FieldCanHidePara(SwFieldIds eFieldId) const
+// The greater the returned value, the more weight has this field type on deciding the final
+// paragraph state
+int SwDoc::FieldCanHideParaWeight(SwFieldIds eFieldId) const
 {
     switch (eFieldId)
     {
         case SwFieldIds::HiddenPara:
-            return true;
+            return 20;
         case SwFieldIds::Database:
-            return GetDocumentSettingManager().get(
-                DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA);
+            return GetDocumentSettingManager().get(DocumentSettingId::EMPTY_DB_FIELD_HIDES_PARA)
+                       ? 10
+                       : 0;
         default:
-            return false;
+            return 0;
     }
 }
 
@@ -1381,7 +1384,8 @@ bool SwDoc::FieldHidesPara(const SwField& rField) const
         case SwFieldIds::HiddenPara:
             return static_cast<const SwHiddenParaField&>(rField).IsHidden();
         case SwFieldIds::Database:
-            return FieldCanHidePara(SwFieldIds::Database) && rField.ExpandField(true).isEmpty();
+            return FieldCanHideParaWeight(SwFieldIds::Database)
+                   && rField.ExpandField(true).isEmpty();
         default:
             return false;
     }
@@ -1413,7 +1417,7 @@ bool SwDoc::RemoveInvisibleContent()
         std::vector<std::unique_ptr<FieldTypeGuard>> aHidingFieldTypes;
         for (SwFieldType* pType : *getIDocumentFieldsAccess().GetFieldTypes())
         {
-            if (FieldCanHidePara(pType->Which()))
+            if (FieldCanHideParaWeight(pType->Which()))
                 aHidingFieldTypes.push_back(o3tl::make_unique<FieldTypeGuard>(pType));
         }
         for (const auto& pTypeGuard : aHidingFieldTypes)
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index 27f02f554370..62b281ae6974 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -1045,18 +1045,25 @@ bool SwTextFrame::IsHiddenNow() const
         }
         sw::MergedAttrIter iter(*this);
         SwTextNode const* pNode(nullptr);
+        int nNewResultWeight = 0;
         for (SwTextAttr const* pHint = iter.NextAttr(&pNode); pHint; pHint = iter.NextAttr(&pNode))
         {
             if (pHint->Which() == RES_TXTATR_FIELD)
             {
+                // see also SwpHints::CalcHiddenParaField()
                 const SwFormatField& rField = pHint->GetFormatField();
-                if (pNode->FieldCanHidePara(rField.GetField()->GetTyp()->Which()))
+                int nCurWeight = pNode->FieldCanHideParaWeight(rField.GetField()->GetTyp()->Which());
+                if (nCurWeight > nNewResultWeight)
                 {
+                    nNewResultWeight = nCurWeight;
+                    bHiddenParaField = pNode->FieldHidesPara(*rField.GetField());
+                }
+                else if (nCurWeight == nNewResultWeight && bHiddenParaField)
+                {
+                    // Currently, for both supported hiding types (HiddenPara, Database), "Don't hide"
+                    // takes precedence - i.e., if there's a "Don't hide" field of that weight, we only
+                    // care about fields of higher weight.
                     bHiddenParaField = pNode->FieldHidesPara(*rField.GetField());
-                    if (!bHiddenParaField)
-                    {
-                        break; // not hidden, see CalcHiddenParaField()
-                    }
                 }
             }
         }
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index 20a732ba1755..ee8593edb708 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1155,7 +1155,7 @@ void SwTextNode::DestroyAttr( SwTextAttr* pAttr )
                 // certain fields must update the SwDoc's calculation flags
 
                 // Certain fields (like HiddenParaField) must trigger recalculation of visible flag
-                if (FieldCanHidePara(pFieldType->Which()))
+                if (FieldCanHideParaWeight(pFieldType->Which()))
                     SetCalcHiddenParaField();
 
                 switch( pFieldType->Which() )
@@ -1465,7 +1465,8 @@ bool SwTextNode::InsertHint( SwTextAttr * const pAttr, const SetAttrMode nMode )
             case RES_TXTATR_FIELD:
                 {
                     // trigger notification for relevant fields, like HiddenParaFields
-                    if (FieldCanHidePara(pAttr->GetFormatField().GetField()->GetTyp()->Which()))
+                    if (FieldCanHideParaWeight(
+                            pAttr->GetFormatField().GetField()->GetTyp()->Which()))
                     {
                         bHiddenPara = true;
                     }
@@ -2590,6 +2591,7 @@ bool SwpHints::CalcHiddenParaField() const
     m_bCalcHiddenParaField = false;
     const bool bOldHiddenByParaField = m_bHiddenByParaField;
     bool bNewHiddenByParaField = false;
+    int nNewResultWeight = 0;
     const size_t nSize = Count();
     const SwTextAttr* pTextHt;
 
@@ -2600,12 +2602,20 @@ bool SwpHints::CalcHiddenParaField() const
 
         if (RES_TXTATR_FIELD == nWhich)
         {
+            // see also SwTextFrame::IsHiddenNow()
             const SwFormatField& rField = pTextHt->GetFormatField();
-            if (m_rParent.FieldCanHidePara(rField.GetField()->GetTyp()->Which())
-                && !(bNewHiddenByParaField = m_rParent.FieldHidesPara(*rField.GetField())))
+            int nCurWeight = m_rParent.FieldCanHideParaWeight(rField.GetField()->GetTyp()->Which());
+            if (nCurWeight > nNewResultWeight)
             {
-                // If there's at least one field telling not to hide, so be it
-                break;
+                nNewResultWeight = nCurWeight;
+                bNewHiddenByParaField = m_rParent.FieldHidesPara(*rField.GetField());
+            }
+            else if (nCurWeight == nNewResultWeight && bNewHiddenByParaField)
+            {
+                // Currently, for both supported hiding types (HiddenPara, Database), "Don't hide"
+                // takes precedence - i.e., if there's a "Don't hide" field of that weight, we only
+                // care about fields of higher weight.
+                bNewHiddenByParaField = m_rParent.FieldHidesPara(*rField.GetField());
             }
         }
     }
@@ -3287,7 +3297,7 @@ void SwpHints::DeleteAtPos( const size_t nPos )
             pTextField->ChgTextNode(nullptr);
         }
         else if (m_bHiddenByParaField
-                 && m_rParent.FieldCanHidePara(pFieldTyp->Which()))
+                 && m_rParent.FieldCanHideParaWeight(pFieldTyp->Which()))
         {
             m_bCalcHiddenParaField = true;
         }


More information about the Libreoffice-commits mailing list