[Libreoffice-commits] core.git: 5 commits - bin/extract-tooltip.py sc/qa sc/source sw/source

Ursache Vladimir ursache at collabora.co.uk
Fri Feb 13 16:42:18 PST 2015


 bin/extract-tooltip.py                  |  107 ++++++++++++++++++++++++++++++++
 sc/qa/unit/data/xlsx/check-boolean.xlsx |binary
 sc/qa/unit/subsequent_filters-test.cxx  |   25 +++++++
 sc/source/core/data/document10.cxx      |   58 ++++-------------
 sw/source/core/doc/docfmt.cxx           |   59 +++++------------
 5 files changed, 165 insertions(+), 84 deletions(-)

New commits:
commit 1e475fef47fe6bd9dba6d830aaf0b6c12dc88881
Author: Ursache Vladimir <ursache at collabora.co.uk>
Date:   Fri Feb 13 21:56:43 2015 +0200

    related tdf#89004 improve performance of document data collection
    
    Change-Id: Ieca50aa0920753cd952123e27d5355d32e82c918

diff --git a/sw/source/core/doc/docfmt.cxx b/sw/source/core/doc/docfmt.cxx
index 0dcaa3e..bed21c6 100644
--- a/sw/source/core/doc/docfmt.cxx
+++ b/sw/source/core/doc/docfmt.cxx
@@ -1919,53 +1919,28 @@ void SwDoc::RenameFmt(SwFmt & rFmt, const OUString & sNewName,
         BroadcastStyleOperation(sNewName, eFamily, SFX_STYLESHEET_MODIFIED);
 }
 
-
 std::vector<Color> SwDoc::GetDocColors()
 {
-    std::vector<Color> docColors;
-
-    for(unsigned int i = 0; i < m_pNodes->Count(); ++i)
-    {
-        const SwNode* pNode = (*m_pNodes)[i];
-        if( ! pNode->IsTxtNode() )
-            continue;
-
-        const SfxItemSet* pItemSet = pNode->GetTxtNode()->GetpSwAttrSet();
-        if( pItemSet == 0 )
-            continue;
-
-        SfxWhichIter aIter( *pItemSet );
-        sal_uInt16 nWhich = aIter.FirstWhich();
-        while( nWhich )
+    std::vector<Color> aDocColors;
+    SwAttrPool& rPool = GetAttrPool();
+    const sal_uInt16 pAttribs[] = {RES_CHRATR_COLOR, RES_CHRATR_HIGHLIGHT, RES_BACKGROUND};
+    for (size_t i=0; i<SAL_N_ELEMENTS(pAttribs); i++)
+    {
+        const sal_uInt16 nAttrib = pAttribs[i];
+        const sal_uInt32 nCount = rPool.GetItemCount2(nAttrib);
+        for (sal_uInt32 j=0; j<nCount; j++)
         {
-            const SfxPoolItem *pItem;
-            if( SfxItemState::SET == pItemSet->GetItemState( nWhich, false, &pItem ) )
-            {
-                sal_uInt16 aWhich = pItem->Which();
-                switch (aWhich)
-                {
-                    // list of color attributes to collect
-                    case RES_CHRATR_COLOR:
-                    case RES_CHRATR_HIGHLIGHT:
-                    case RES_BACKGROUND:
-                        {
-                            Color aColor( static_cast<const SvxColorItem*>(pItem)->GetValue() );
-                            if( COL_AUTO != aColor.GetColor() &&
-                                    std::find(docColors.begin(), docColors.end(), aColor) == docColors.end() )
-                            {
-                                docColors.push_back( aColor );
-                            }
-                        }
-                        break;
-                    default:
-                        break;
-                }
-            }
-
-            nWhich = aIter.NextWhich();
+            const SvxColorItem *pItem = static_cast<const SvxColorItem*>(rPool.GetItem2(nAttrib, j));
+            if (pItem == 0)
+                continue;
+            Color aColor( pItem->GetValue() );
+            if (COL_AUTO == aColor.GetColor())
+                continue;
+            if (std::find(aDocColors.begin(), aDocColors.end(), aColor) == aDocColors.end())
+                aDocColors.push_back(aColor);
         }
     }
-    return docColors;
+    return aDocColors;
 }
 
 // #i69627#
commit 6a348503ad504a82778f86d35325737b712c5352
Author: Ursache Vladimir <ursache at collabora.co.uk>
Date:   Fri Feb 13 06:23:53 2015 +0200

    tdf#89004 improve performance of document data collection
    
    Change-Id: Ie74495745b48d721c7dda0b447fc59066c869874

diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx
index 0a2e3cb..362acbf 100644
--- a/sc/source/core/data/document10.cxx
+++ b/sc/source/core/data/document10.cxx
@@ -19,6 +19,7 @@
 #include <poolhelp.hxx>
 #include <bcaslot.hxx>
 #include <cellvalues.hxx>
+#include <docpool.hxx>
 
 #include "dociter.hxx"
 #include "patattr.hxx"
@@ -157,53 +158,26 @@ void ScDocument::CopyCellValuesFrom( const ScAddress& rTopPos, const sc::CellVal
 
 std::vector<Color> ScDocument::GetDocColors()
 {
-    std::vector<Color> docColors;
-
-    for( unsigned int nTabIx = 0; nTabIx < maTabs.size(); ++nTabIx )
+    std::vector<Color> aDocColors;
+    ScDocumentPool *pPool = GetPool();
+    const sal_uInt16 pAttribs[] = {ATTR_BACKGROUND, ATTR_FONT_COLOR};
+    for (size_t i=0; i<SAL_N_ELEMENTS( pAttribs ); i++)
     {
-        ScUsedAreaIterator aIt(this, nTabIx, 0, 0, MAXCOLCOUNT-1, MAXROWCOUNT-1);
-
-        for( bool bIt = aIt.GetNext(); bIt; bIt = aIt.GetNext() )
+        const sal_uInt16 nAttrib = pAttribs[i];
+        const sal_uInt32 nCount = pPool->GetItemCount2(nAttrib);
+        for (sal_uInt32 j=0; j<nCount; j++)
         {
-            const ScPatternAttr* pPattern = aIt.GetPattern();
-
-            if( pPattern == 0 )
+            const SvxColorItem *pItem = static_cast<const SvxColorItem*>(pPool->GetItem2(nAttrib, j));
+            if (pItem == 0)
                 continue;
-
-            const SfxItemSet& rItemSet = pPattern->GetItemSet();
-
-            SfxWhichIter aIter( rItemSet );
-            sal_uInt16 nWhich = aIter.FirstWhich();
-            while( nWhich )
-            {
-                const SfxPoolItem *pItem;
-                if( SfxItemState::SET == rItemSet.GetItemState( nWhich, false, &pItem ) )
-                {
-                    sal_uInt16 aWhich = pItem->Which();
-                    switch (aWhich)
-                    {
-                        // attributes we want to collect
-                        case ATTR_FONT_COLOR:
-                        case ATTR_BACKGROUND:
-                            {
-                                Color aColor( static_cast<const SvxColorItem*>(pItem)->GetValue() );
-                                if( COL_AUTO != aColor.GetColor() &&
-                                        std::find(docColors.begin(), docColors.end(), aColor) == docColors.end() )
-                                {
-                                    docColors.push_back( aColor );
-                                }
-                            }
-                            break;
-                        default:
-                            break;
-                    }
-                }
-
-                nWhich = aIter.NextWhich();
-            }
+            Color aColor( pItem->GetValue() );
+            if (COL_AUTO == aColor.GetColor())
+                continue;
+            if (std::find(aDocColors.begin(), aDocColors.end(), aColor) == aDocColors.end())
+                aDocColors.push_back(aColor);
         }
     }
-    return docColors;
+    return aDocColors;
 }
 
 void ScDocument::SetCalcConfig( const ScCalcConfig& rConfig )
commit 10e3e75ce8b88a0ba5157d17d10f5e9aca4360fa
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Sat Feb 14 01:34:12 2015 +0100

    small stylistic changes for previous commit
    
    Change-Id: Ied363ca05ee1778b401073321588ac00d9b19634

diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index a793239..2012876 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -19,7 +19,6 @@
 #include <sfx2/sfxmodelfactory.hxx>
 #include <svl/stritem.hxx>
 #include <svl/nfkeytab.hxx>
-//#include <zformat.hxx>
 #include <svl/zformat.hxx>
 #include <svx/svdograf.hxx>
 
@@ -361,7 +360,7 @@ void ScFiltersTest::testBooleanFormatXLSX()
 {
     ScDocShellRef xDocSh = loadDoc("check-boolean.", XLSX);
     ScDocument& rDoc = xDocSh->GetDocument();
-    SvNumberFormatter *pNumFormatter = rDoc.GetFormatTable();
+    SvNumberFormatter* pNumFormatter = rDoc.GetFormatTable();
     const OUString aBooleanTypeStr = "\"TRUE\";\"TRUE\";\"FALSE\"";
 
     CPPUNIT_ASSERT_MESSAGE("Failed to load check-boolean.xlsx", xDocSh.Is());
@@ -369,10 +368,10 @@ void ScFiltersTest::testBooleanFormatXLSX()
 
     for (SCROW i = 0; i <= 1; i++)
     {
-         rDoc.GetNumberFormat(0, i, 0, nNumberFormat);
-         const SvNumberformat *pSvnumberFormat = pNumFormatter->GetEntry(nNumberFormat);
-         const OUString &rFormatStr = pSvnumberFormat->GetFormatstring();
-        CPPUNIT_ASSERT_MESSAGE("Number format != boolean", rFormatStr == aBooleanTypeStr);
+        rDoc.GetNumberFormat(0, i, 0, nNumberFormat);
+        const SvNumberformat* pNumberFormat = pNumFormatter->GetEntry(nNumberFormat);
+        const OUString& rFormatStr = pNumberFormat->GetFormatstring();
+        CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format != boolean", rFormatStr, aBooleanTypeStr);
     }
 
     xDocSh->DoClose();
commit 23159e5a23687683d8478a302b5634097e6c518d
Author: Ursache Vladimir <ursache at collabora.co.uk>
Date:   Tue Feb 10 23:06:35 2015 +0200

    tdf#68117 Unit test
    
    Change-Id: I2c1b935648ea2728878f606dfe8a141c3c1ddda2

diff --git a/sc/qa/unit/data/xlsx/check-boolean.xlsx b/sc/qa/unit/data/xlsx/check-boolean.xlsx
new file mode 100644
index 0000000..a7643d1
Binary files /dev/null and b/sc/qa/unit/data/xlsx/check-boolean.xlsx differ
diff --git a/sc/qa/unit/subsequent_filters-test.cxx b/sc/qa/unit/subsequent_filters-test.cxx
index 13c616d..a793239 100644
--- a/sc/qa/unit/subsequent_filters-test.cxx
+++ b/sc/qa/unit/subsequent_filters-test.cxx
@@ -18,6 +18,9 @@
 #include <sfx2/docfile.hxx>
 #include <sfx2/sfxmodelfactory.hxx>
 #include <svl/stritem.hxx>
+#include <svl/nfkeytab.hxx>
+//#include <zformat.hxx>
+#include <svl/zformat.hxx>
 #include <svx/svdograf.hxx>
 
 #include "drwlayer.hxx"
@@ -86,6 +89,7 @@ public:
     virtual void tearDown() SAL_OVERRIDE;
 
     //ods, xls, xlsx filter tests
+    void testBooleanFormatXLSX();
     void testBasicCellContentODS();
     void testRangeNameXLS();
     void testRangeNameLocalXLS();
@@ -186,6 +190,7 @@ public:
     void testEmbeddedImageXLS();
 
     CPPUNIT_TEST_SUITE(ScFiltersTest);
+    CPPUNIT_TEST(testBooleanFormatXLSX);
     CPPUNIT_TEST(testBasicCellContentODS);
     CPPUNIT_TEST(testRangeNameXLS);
     CPPUNIT_TEST(testRangeNameLocalXLS);
@@ -352,6 +357,27 @@ void ScFiltersTest::testBasicCellContentODS()
     xDocSh->DoClose();
 }
 
+void ScFiltersTest::testBooleanFormatXLSX()
+{
+    ScDocShellRef xDocSh = loadDoc("check-boolean.", XLSX);
+    ScDocument& rDoc = xDocSh->GetDocument();
+    SvNumberFormatter *pNumFormatter = rDoc.GetFormatTable();
+    const OUString aBooleanTypeStr = "\"TRUE\";\"TRUE\";\"FALSE\"";
+
+    CPPUNIT_ASSERT_MESSAGE("Failed to load check-boolean.xlsx", xDocSh.Is());
+    sal_uInt32 nNumberFormat;
+
+    for (SCROW i = 0; i <= 1; i++)
+    {
+         rDoc.GetNumberFormat(0, i, 0, nNumberFormat);
+         const SvNumberformat *pSvnumberFormat = pNumFormatter->GetEntry(nNumberFormat);
+         const OUString &rFormatStr = pSvnumberFormat->GetFormatstring();
+        CPPUNIT_ASSERT_MESSAGE("Number format != boolean", rFormatStr == aBooleanTypeStr);
+    }
+
+    xDocSh->DoClose();
+}
+
 void ScFiltersTest::testRangeNameXLS()
 {
     ScDocShellRef xDocSh = loadDoc("named-ranges-global.", XLS);
commit 480de8e23d4fc39e33646eb11987a00c311ee28d
Author: Markus Mohrhard <markus.mohrhard at collabora.co.uk>
Date:   Wed Jan 14 12:56:44 2015 +0100

    add script to extract tooltips
    
    Change-Id: I4c79b944edf246b80a8dd5ea54c3651e3909f54b

diff --git a/bin/extract-tooltip.py b/bin/extract-tooltip.py
new file mode 100755
index 0000000..5397c71
--- /dev/null
+++ b/bin/extract-tooltip.py
@@ -0,0 +1,107 @@
+#!/usr/bin/env python
+import sys
+import os
+import re
+import urlparse
+
+def usage():
+    message = """ usage: {program} inDir outDir
+inDir: directory containing .ht files
+outDir: target for the new files"""
+    print(message.format(program = os.path.basename(sys.argv[0])))
+
+def parseFile(filename):
+    file = open(filename, "r")
+    data = file.readlines()
+    data = [line.rstrip('\n') for line in data]
+
+    pairs = {}
+    regEx = re.compile("^(\S+)\s(\S+)\s(\S+)\s((?:\s*\S*)+)$")
+    old_line = None
+    for line in data:
+        if len(line) > 0:
+            if(old_line != None):
+                print filename
+                #print("failed to parse line")
+                #print(old_line)
+                line = old_line + line
+                print line
+                old_line = None
+            split_line = regEx.split(line)
+            #print(split_line)
+            #print(urlparse.unquote(split_line[2]))
+            #print(split_line[4])
+            if(old_line == None and split_line[4] == "" and split_line[3] != "0"):
+                print(line)
+                print(split_line)
+                old_line = line
+            else:
+                pairs[urlparse.unquote(split_line[2])] = split_line[4]
+                assert(len(split_line) == 6)
+    #print data
+    #print(pairs)
+    return pairs
+
+def parseFiles(dir):
+    strings = []
+    for files in os.listdir(dir):
+        if files.endswith(".ht"):
+            string = parseFile(os.path.join(dir,files))
+            print(files)
+            #print string
+            strings.append([files, string])
+    return strings
+
+def extractSharedEntries(strings):
+    first_dict = strings[0][1]
+    shared_dict = {}
+    #print(first_dict)
+    for key, value in first_dict.iteritems():
+        # check that the entry in the same in all dics
+        is_in_all_dicts = True
+        for dict_file_pair in strings:
+            dict = dict_file_pair[1]
+            if not dict.has_key(key):
+                is_in_all_dicts = False
+            elif not dict[key] == value:
+                print("Element with different values")
+                print(key)
+                is_in_all_dicts = False
+        if is_in_all_dicts:
+            shared_dict[key] = value
+    #print(shared_dict)
+    for dict_file_pair in strings:
+        for key in shared_dict.iterkeys():
+            dict_file_pair[1].pop(key)
+
+    strings.append(["shared.ht", shared_dict])
+    return strings
+
+def writeOutFiles(dir, strings):
+    for string in strings:
+        file_name_base = string[0]
+        file_name_base = file_name_base.replace(".ht", ".properties")
+        file_name = os.path.join(dir, file_name_base)
+        file = open(file_name, "w")
+        for key, value in string[1].iteritems():
+            try:
+                file.write(key)
+                file.write("=")
+                file.write(value)
+                file.write("\n")
+            except UnicodeDecodeError:
+                print key
+                print value
+        file.close()
+
+def main (args):
+    if(len(args) != 3):
+        usage()
+        sys.exit(1)
+
+    strings = parseFiles(args[1])
+    new_strings = extractSharedEntries(strings)
+    writeOutFiles(args[2], new_strings)
+
+if __name__ == "__main__":
+    main(sys.argv)


More information about the Libreoffice-commits mailing list