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

Jakub Trzebiatowski ubap.dev at gmail.com
Fri Jun 17 07:19:31 UTC 2016


 sw/qa/python/check_styles.py        |   20 +++++++++++++
 sw/source/core/unocore/unostyle.cxx |   54 ++++++++++++++++++++++++++++++++++--
 2 files changed, 72 insertions(+), 2 deletions(-)

New commits:
commit 17f440e7e7f1621edebc58f8be5e85b68ee7dcf4
Author: Jakub Trzebiatowski <ubap.dev at gmail.com>
Date:   Thu Jun 16 13:40:59 2016 +0200

    GSoC Table Styles, TableStyle isInUse, isUserDefined, mutex fixes
    
    Also added:
    + SwXTextCellStyle::IsInUse()
    + check_styles.py
    	SwXTextTableStyle::isUserDefined() tests
    
    Change-Id: I76cb166107f186098599c4a8da6f94f7c40cc545
    Reviewed-on: https://gerrit.libreoffice.org/26366
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/qa/python/check_styles.py b/sw/qa/python/check_styles.py
index d2ea6a9..7a3e80e 100644
--- a/sw/qa/python/check_styles.py
+++ b/sw/qa/python/check_styles.py
@@ -183,6 +183,26 @@ class CheckStyle(unittest.TestCase):
                 xCellStyle.getPropertyValue("foobarbaz")
         xDoc.dispose()
 
+    def test_tableStyleIsInUse(self):
+        # extend when TableStyle insertByName comes
+        xDoc = CheckStyle._uno.openEmptyWriterDoc()
+        xBodyText = xDoc.getText()
+        xCursor = xBodyText.createTextCursor()
+        xTable = xDoc.createInstance("com.sun.star.text.TextTable")
+        xTable.initialize(1, 1)
+        xBodyText.insertTextContent(xCursor, xTable, True)
+        xDefaultTableStyle = xDoc.StyleFamilies.getByName("TableStyles").getByName("Default Style")
+        xDefaultCellStyle = xDoc.StyleFamilies.getByName("CellStyles").getByName("Default Style.1")
+        self.assertFalse(xDefaultTableStyle.isInUse())
+        self.assertFalse(xDefaultCellStyle.isInUse())
+        xTable.setPropertyValue("TableTemplateName", "Default Style")
+        self.assertTrue(xDefaultTableStyle.isInUse())
+        self.assertTrue(xDefaultCellStyle.isInUse())
+        xTable.setPropertyValue("TableTemplateName", "")
+        self.assertFalse(xDefaultTableStyle.isInUse())
+        self.assertFalse(xDefaultCellStyle.isInUse())
+        xDoc.dispose()
+
     def test_CellFamily(self):
         xDoc = CheckStyle._uno.openEmptyWriterDoc()
         xCellStyles = xDoc.StyleFamilies["CellStyles"]
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index ffc9619..ab000ae 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -61,6 +61,7 @@
 #include <sfx2/printer.hxx>
 #include <com/sun/star/style/ParagraphStyleCategory.hpp>
 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
+#include <com/sun/star/text/XTextTablesSupplier.hpp>
 #include <com/sun/star/beans/PropertyAttribute.hpp>
 #include <com/sun/star/beans/NamedValue.hpp>
 #include <com/sun/star/drawing/BitmapMode.hpp>
@@ -4408,11 +4409,36 @@ const CellStyleNameMap& SwXTextTableStyle::GetCellStyleNameMap()
 // XStyle
 sal_Bool SAL_CALL SwXTextTableStyle::isUserDefined() throw (uno::RuntimeException, std::exception)
 {
-    return false;
+    SolarMutexGuard aGuard;
+    // only first style is not user defined
+    if (m_pDocShell->GetDoc()->GetTableStyles()[0].GetName() == m_sTableAutoFormatName)
+        return false;
+
+    return true;
 }
 
 sal_Bool SAL_CALL SwXTextTableStyle::isInUse() throw (uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
+    uno::Reference<text::XTextTablesSupplier> xTablesSupp(m_pDocShell->GetModel(), uno::UNO_QUERY);
+    if (!xTablesSupp.is())
+        return false;
+
+    uno::Reference<container::XIndexAccess> xTables(xTablesSupp->getTextTables(), uno::UNO_QUERY);
+    if (!xTables.is())
+        return false;
+
+    const sal_Int32 nCount = xTables->getCount();
+    for (sal_Int32 i=0; i < nCount; ++i)
+    {
+        uno::Reference<beans::XPropertySet> xTablePropertySet;
+        xTables->getByIndex(i) >>= xTablePropertySet;
+        OUString sTableTemplateName;
+        if (xTablePropertySet.is() && (xTablePropertySet->getPropertyValue("TableTemplateName") >>= sTableTemplateName)
+            && sTableTemplateName == m_sTableAutoFormatName)
+            return true;
+    }
+
     return false;
 }
 
@@ -4427,6 +4453,7 @@ void SAL_CALL SwXTextTableStyle::setParentStyle(const OUString& /*aParentStyle*/
 //XNamed
 OUString SAL_CALL SwXTextTableStyle::getName() throw(uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
     OUString sProgName;
     SwStyleNameMapper::FillProgName(m_sTableAutoFormatName, sProgName, nsSwGetPoolIdFromName::GET_POOLID_TABSTYLE, true);
     return m_sTableAutoFormatName;
@@ -4621,6 +4648,7 @@ css::uno::Reference<css::style::XStyle> SwXTextCellStyle::CreateXTextCellStyle(S
 // XStyle
 sal_Bool SAL_CALL SwXTextCellStyle::isUserDefined() throw (css::uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
     // if this cell belong to first table style then its defaut style
     if (&m_pDocShell->GetDoc()->GetTableStyles()[0] == m_pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(m_sParentStyle))
         return false;
@@ -4630,7 +4658,26 @@ sal_Bool SAL_CALL SwXTextCellStyle::isUserDefined() throw (css::uno::RuntimeExce
 
 sal_Bool SAL_CALL SwXTextCellStyle::isInUse() throw (css::uno::RuntimeException, std::exception)
 {
-    return false;
+    SolarMutexGuard aGuard;
+    uno::Reference<style::XStyleFamiliesSupplier> xFamiliesSupplier(m_pDocShell->GetModel(), uno::UNO_QUERY);
+    if (!xFamiliesSupplier.is())
+        return false;
+
+    uno::Reference<container::XNameAccess> xFamilies(xFamiliesSupplier->getStyleFamilies(), uno::UNO_QUERY);
+    if (!xFamilies.is())
+        return false;
+
+    uno::Reference<container::XNameAccess> xTableStyles;
+    xFamilies->getByName("TableStyles") >>= xTableStyles;
+    if (!xTableStyles.is())
+        return false;
+
+    uno::Reference<style::XStyle> xStyle;
+    xTableStyles->getByName(m_sParentStyle) >>= xStyle;
+    if (!xStyle.is())
+        return false;
+
+    return xStyle->isInUse();
 }
 
 OUString SAL_CALL SwXTextCellStyle::getParentStyle() throw (css::uno::RuntimeException, std::exception)
@@ -4640,6 +4687,7 @@ OUString SAL_CALL SwXTextCellStyle::getParentStyle() throw (css::uno::RuntimeExc
 
 void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& sParentStyle) throw (css::container::NoSuchElementException, css::uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
     // Changing parent to one which is unaware of it will lead to a something unexcpected. getName() rely on a parent.
     SAL_INFO("sw.uno", "Changing SwXTextCellStyle parent");
     m_sParentStyle = sParentStyle;
@@ -4648,6 +4696,7 @@ void SAL_CALL SwXTextCellStyle::setParentStyle(const OUString& sParentStyle) thr
 //XNamed
 OUString SAL_CALL SwXTextCellStyle::getName() throw(css::uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
     OUString sName;
 
     // if style is physical then we request a name from doc
@@ -4672,6 +4721,7 @@ OUString SAL_CALL SwXTextCellStyle::getName() throw(css::uno::RuntimeException,
 
 void SAL_CALL SwXTextCellStyle::setName(const OUString& sName) throw(css::uno::RuntimeException, std::exception)
 {
+    SolarMutexGuard aGuard;
     // if style is physical then we can not rename it.
     if (!m_bPhysical)
         m_sName = sName;


More information about the Libreoffice-commits mailing list