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

Balazs Santha (via logerrit) logerrit at kemper.freedesktop.org
Thu Jul 15 14:05:30 UTC 2021


 sw/inc/tblafmt.hxx                      |    4 --
 sw/qa/core/uwriter.cxx                  |   12 -------
 sw/qa/uitest/writer_tests7/tdf134452.py |   49 ++++++++++++++++++++++++++++++++
 sw/source/core/doc/tblafmt.cxx          |   22 ++++----------
 4 files changed, 56 insertions(+), 31 deletions(-)

New commits:
commit 554c3692b7e3b51ce6ce7772509ba7a2e8777d3a
Author:     Balazs Santha <santha.balazs at simonyi.bme.hu>
AuthorDate: Wed Jul 14 15:18:47 2021 +0200
Commit:     Michael Stahl <michael.stahl at allotropia.de>
CommitDate: Thu Jul 15 16:04:56 2021 +0200

    tdf#134452 sw: fix page break disappears after applying table style
    
    After setting the break and pagedesc property of a table, applying a table style (autoformat) caused the loss of these settings.
    This was because, when applying a table style, the SwTableAutoFormat::RestoreTableProperties() overrid these settings with its own default settings.
    As the autoformats can never be modified, and they don't really use these two props, the easiest way to prevent any problem was to completely remove these properties and its uses.
    Unfortunately, m_aBreak couldn't be removed entirely, as the autoformats are stored in a binary file, and to be able to read and write these files the offset of the subsequent items must not be changed.
    
    Change-Id: Ieba439d3ba5da892b39f00f8b61c5c8467306635
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118662
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.stahl at allotropia.de>

diff --git a/sw/inc/tblafmt.hxx b/sw/inc/tblafmt.hxx
index 2873f51e9196..ff6abca8baa7 100644
--- a/sw/inc/tblafmt.hxx
+++ b/sw/inc/tblafmt.hxx
@@ -173,8 +173,6 @@ class SW_DLLPUBLIC SwTableAutoFormat
     SwBoxAutoFormat* m_aBoxAutoFormat[ 16 ] = {};
 
     // Writer-specific options
-    std::shared_ptr<SvxFormatBreakItem> m_aBreak;
-    SwFormatPageDesc m_aPageDesc;
     std::shared_ptr<SvxFormatKeepItem> m_aKeepWithNextPara;
     sal_uInt16 m_aRepeatHeading;
     bool m_bLayoutSplit;
@@ -191,11 +189,9 @@ public:
 
     SwTableAutoFormat& operator=( const SwTableAutoFormat& rNew );
 
-    const SvxFormatBreakItem& GetBreak() const { return *m_aBreak; }
     const SvxFormatKeepItem& GetKeepWithNextPara() const { return *m_aKeepWithNextPara; }
     const SvxShadowItem& GetShadow() const { return *m_aShadow; }
 
-    void SetBreak(const SvxFormatBreakItem& rNew) { m_aBreak.reset(rNew.Clone()); }
     void SetKeepWithNextPara(const SvxFormatKeepItem& rNew) { m_aKeepWithNextPara.reset(rNew.Clone()); }
     void SetShadow(const SvxShadowItem& rNew) { m_aShadow.reset(rNew.Clone()); }
 
diff --git a/sw/qa/core/uwriter.cxx b/sw/qa/core/uwriter.cxx
index ade0a9d8170b..4f9ffdb98c40 100644
--- a/sw/qa/core/uwriter.cxx
+++ b/sw/qa/core/uwriter.cxx
@@ -1324,17 +1324,9 @@ void SwDocTest::testTableAutoFormats()
     //Set m_eNumFormatLanguage
     LanguageType aNFLang( LANGUAGE_GERMAN );
     aBoxAF.SetNumFormatLanguage(aNFLang);
-    //Set m_aBreak
-    SvxFormatBreakItem aBreak( SvxBreak::PageBefore, 0 );
-    aTableAF.SetBreak(aBreak);
     //Set m_aKeepWithNextPara
     SvxFormatKeepItem aKWNPara( true, 0 );
     aTableAF.SetKeepWithNextPara(aKWNPara);
-    //Set m_aPageDesc
-    SwFormatPageDesc aPDesc;
-    uno::Any aPDAny( sal_uInt16(3) );
-    aPDesc.PutValue( aPDAny, 0 );
-    aTableAF.m_aPageDesc = aPDesc;
     //Set m_aRepeatHeading
     sal_uInt16 aRHeading = 3;
     aTableAF.m_aRepeatHeading = aRHeading;
@@ -1466,12 +1458,8 @@ void SwDocTest::testTableAutoFormats()
     CPPUNIT_ASSERT( bool( pLoadAF->GetBoxFormat(0).GetSysLanguage() == aSLang ) );
     //Get m_eNumFormatLanguage
     CPPUNIT_ASSERT( bool( pLoadAF->GetBoxFormat(0).GetNumFormatLanguage() == aNFLang ) );
-    //Get m_aBreak
-    CPPUNIT_ASSERT( bool( pLoadAF->GetBreak() == aBreak ) );
     //Get m_aKeepWithNextPara
     CPPUNIT_ASSERT( bool( pLoadAF->GetKeepWithNextPara() == aKWNPara ) );
-    //Get m_aPageDesc
-    CPPUNIT_ASSERT( bool( pLoadAF->m_aPageDesc == aPDesc ) );
     //Get m_aRepeatHeading
     CPPUNIT_ASSERT( bool( pLoadAF->m_aRepeatHeading == aRHeading ) );
     //Get m_bLayoutSplit
diff --git a/sw/qa/uitest/writer_tests7/tdf134452.py b/sw/qa/uitest/writer_tests7/tdf134452.py
new file mode 100644
index 000000000000..ce13e8db2270
--- /dev/null
+++ b/sw/qa/uitest/writer_tests7/tdf134452.py
@@ -0,0 +1,49 @@
+# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+#
+from uitest.framework import UITestCase
+from uitest.uihelper.common import get_state_as_dict
+from libreoffice.uno.propertyvalue import mkPropertyValues
+from uitest.uihelper.common import select_pos
+
+# Bug 134452 - Applying a table style caused the loss of break/pagedesc props of the table
+
+
+class tdf134452(UITestCase):
+    def test_tdf134452(self):
+        with self.ui_test.create_doc_in_start_center("writer"):
+            xWriterDoc = self.xUITest.getTopFocusWindow()
+            xWriterEdit = xWriterDoc.getChild("writer_edit")
+            xWriterEdit.executeAction("TYPE", mkPropertyValues({"KEYCODE": "RETURN"}))
+            with self.ui_test.execute_dialog_through_command(".uno:InsertTable") as xDialog:
+                formatlbinstable = xDialog.getChild("formatlbinstable")
+                entry = formatlbinstable.getChild("1")
+                entry.executeAction("SELECT", tuple())
+            #setting the break and pageDesc properties
+            with self.ui_test.execute_dialog_through_command(".uno:TableDialog") as xDialog:
+                tabcontrol = xDialog.getChild("tabcontrol")
+                select_pos(tabcontrol, "1")
+                xbreak = xDialog.getChild("break")
+                xbreak.executeAction("CLICK", tuple())
+                self.assertEqual("true", get_state_as_dict(xbreak)["Selected"])
+                xpagestyle = xDialog.getChild("pagestyle")
+                xpagestyle.executeAction("CLICK", tuple())
+                self.assertEqual("true", get_state_as_dict(xpagestyle)["Selected"])
+
+            #applying table style on the table
+            #without the fix, break and pageDesc properties would be overriden and lost
+            document = self.ui_test.get_component()
+            tables = document.getTextTables()
+            tables[0].setPropertyValue("TableTemplateName", "Box List Red")
+
+            with self.ui_test.execute_dialog_through_command(".uno:TableDialog") as xDialog:
+                tabcontrol = xDialog.getChild("tabcontrol")
+                select_pos(tabcontrol, "1")
+                xbreak = xDialog.getChild("break")
+                self.assertEqual("true", get_state_as_dict(xbreak)["Selected"])
+                xpagestyle = xDialog.getChild("pagestyle")
+                self.assertEqual("true", get_state_as_dict(xpagestyle)["Selected"])
+# vim: set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/sw/source/core/doc/tblafmt.cxx b/sw/source/core/doc/tblafmt.cxx
index 558c8d6f827d..ec1e7b9ff993 100644
--- a/sw/source/core/doc/tblafmt.cxx
+++ b/sw/source/core/doc/tblafmt.cxx
@@ -366,7 +366,6 @@ bool SwBoxAutoFormat::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
 SwTableAutoFormat::SwTableAutoFormat( const OUString& rName )
     : m_aName( rName )
     , m_nStrResId( USHRT_MAX )
-    , m_aBreak(std::make_shared<SvxFormatBreakItem>(SvxBreak::NONE, RES_BREAK))
     , m_aKeepWithNextPara(std::make_shared<SvxFormatKeepItem>(false, RES_KEEP))
     , m_aRepeatHeading( 0 )
     , m_bLayoutSplit( true )
@@ -385,8 +384,7 @@ SwTableAutoFormat::SwTableAutoFormat( const OUString& rName )
 }
 
 SwTableAutoFormat::SwTableAutoFormat( const SwTableAutoFormat& rNew )
-    : m_aBreak()
-    , m_aKeepWithNextPara()
+    : m_aKeepWithNextPara()
     , m_aShadow(std::make_shared<SvxShadowItem>(RES_SHADOW))
 {
     for(SwBoxAutoFormat* & rp : m_aBoxAutoFormat)
@@ -420,8 +418,6 @@ SwTableAutoFormat& SwTableAutoFormat::operator=( const SwTableAutoFormat& rNew )
     m_bInclValueFormat = rNew.m_bInclValueFormat;
     m_bInclWidthHeight = rNew.m_bInclWidthHeight;
 
-    m_aBreak.reset(rNew.m_aBreak->Clone());
-    m_aPageDesc = rNew.m_aPageDesc;
     m_aKeepWithNextPara.reset(rNew.m_aKeepWithNextPara->Clone());
     m_aRepeatHeading = rNew.m_aRepeatHeading;
     m_bLayoutSplit = rNew.m_bLayoutSplit;
@@ -683,9 +679,6 @@ void SwTableAutoFormat::RestoreTableProperties(SwTable &table) const
 
     SfxItemSet rSet(pDoc->GetAttrPool(), aTableSetRange);
 
-    if ( m_aBreak->GetBreak() != SvxBreak::NONE )
-        rSet.Put(*m_aBreak);
-    rSet.Put(m_aPageDesc);
     rSet.Put(SwFormatLayoutSplit(m_bLayoutSplit));
     rSet.Put(SfxBoolItem(RES_COLLAPSING_BORDERS, m_bCollapsingBorders));
     if ( m_aKeepWithNextPara->GetValue() )
@@ -717,8 +710,6 @@ void SwTableAutoFormat::StoreTableProperties(const SwTable &table)
 
     const SfxItemSet &rSet = pFormat->GetAttrSet();
 
-    m_aBreak.reset(rSet.Get(RES_BREAK).Clone());
-    m_aPageDesc = rSet.Get(RES_PAGEDESC);
     const SwFormatLayoutSplit &layoutSplit = rSet.Get(RES_LAYOUT_SPLIT);
     m_bLayoutSplit = layoutSplit.GetValue();
     m_bCollapsingBorders = rSet.Get(RES_COLLAPSING_BORDERS).GetValue();
@@ -778,8 +769,9 @@ bool SwTableAutoFormat::Load( SvStream& rStream, const SwAfVersions& rVersions )
 
         if (nVal >= AUTOFORMAT_DATA_ID_31005 && WriterSpecificBlockExists(rStream))
         {
-            legacy::SvxFormatBreak::Create(*m_aBreak, rStream, AUTOFORMAT_FILE_VERSION);
-//unimplemented            READ(m_aPageDesc, SwFormatPageDesc, AUTOFORMAT_FILE_VERSION);
+            //this only exists for file format compat
+            SvxFormatBreakItem aBreak(SvxBreak::NONE, RES_BREAK);
+            legacy::SvxFormatBreak::Create(aBreak, rStream, AUTOFORMAT_FILE_VERSION);
             legacy::SvxFormatKeep::Create(*m_aKeepWithNextPara, rStream, AUTOFORMAT_FILE_VERSION);
 
             rStream.ReadUInt16( m_aRepeatHeading ).ReadCharAsBool( m_bLayoutSplit ).ReadCharAsBool( m_bRowSplit ).ReadCharAsBool( m_bCollapsingBorders );
@@ -822,9 +814,9 @@ bool SwTableAutoFormat::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
 
     {
         WriterSpecificAutoFormatBlock block(rStream);
-
-        legacy::SvxFormatBreak::Store(*m_aBreak, rStream, legacy::SvxFormatBreak::GetVersion(fileVersion));
-//unimplemented        m_aPageDesc.Store(rStream, m_aPageDesc.GetVersion(fileVersion));
+        //this only exists for file format compat
+        SvxFormatBreakItem aBreak(SvxBreak::NONE, RES_BREAK);
+        legacy::SvxFormatBreak::Store(aBreak, rStream, legacy::SvxFormatBreak::GetVersion(fileVersion));
         legacy::SvxFormatKeep::Store(*m_aKeepWithNextPara, rStream, legacy::SvxFormatKeep::GetVersion(fileVersion));
         rStream.WriteUInt16( m_aRepeatHeading ).WriteBool( m_bLayoutSplit ).WriteBool( m_bRowSplit ).WriteBool( m_bCollapsingBorders );
         legacy::SvxShadow::Store(*m_aShadow, rStream, legacy::SvxShadow::GetVersion(fileVersion));


More information about the Libreoffice-commits mailing list