[Libreoffice-commits] core.git: Branch 'feature/gsoc-calc-enhanced-db-range' - 2 commits - sc/inc sc/Library_sc.mk sc/source

Akash Shetye shetyeakash at gmail.com
Sun Aug 18 19:30:19 PDT 2013


 sc/Library_sc.mk                         |    1 
 sc/inc/dbdata.hxx                        |    1 
 sc/inc/dbdataformatting.hxx              |   12 +++
 sc/source/core/tool/dbdata2.cxx          |  112 +++++++++++++++++++++++++++++++
 sc/source/core/tool/dbdataformatting.cxx |   23 +++---
 5 files changed, 139 insertions(+), 10 deletions(-)

New commits:
commit 5085cff67f055ca8f9ea540873962567702aff69
Author: Akash Shetye <shetyeakash at gmail.com>
Date:   Mon Aug 19 07:59:01 2013 +0530

    Added the DB Formatting calculation code
    
    Change-Id: Id617118221b97f4fee3160e30d65225b6316610d

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 4fd1df1..5b24e6b 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -204,6 +204,7 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
 	sc/source/core/tool/compiler \
 	sc/source/core/tool/consoli  \
 	sc/source/core/tool/dbdata \
+    sc/source/core/tool/dbdata2 \
     sc/source/core/tool/dbdataformatting \
 	sc/source/core/tool/ddelink \
 	sc/source/core/tool/defaultsoptions \
diff --git a/sc/inc/dbdata.hxx b/sc/inc/dbdata.hxx
index a87f72f..e6a35ed 100644
--- a/sc/inc/dbdata.hxx
+++ b/sc/inc/dbdata.hxx
@@ -156,6 +156,7 @@ public:
                         SCsCOL nDx, SCsROW nDy, SCsTAB nDz);
 
     void ExtendDataArea(ScDocument* pDoc);
+    const OUString& GetCellStyle( const ScAddress& rPos, bool bRowStripe );
 };
 
 class SC_DLLPUBLIC ScDBCollection
diff --git a/sc/source/core/tool/dbdata2.cxx b/sc/source/core/tool/dbdata2.cxx
new file mode 100644
index 0000000..c34d194
--- /dev/null
+++ b/sc/source/core/tool/dbdata2.cxx
@@ -0,0 +1,112 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * 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/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "dbdata.hxx"
+#include "dbdataformatting.hxx"
+
+const OUString& ScDBData::GetCellStyle( const ScAddress& rPos, bool bRowStripe )
+{
+    //first see if the DB Range has any DB Formatting at all
+    if( !HasFormatting() )
+        return OUString("Default");
+    //Calculating which style sheet is applicable to the give cell begins now
+    //Create a whole row stripe map
+    std::vector< OUString > aRowStripeSeq;
+    //Create a whole column stripe map
+    std::vector< OUString > aColStripeSeq;
+    //The above two vectors represent a whole row/col stripe by
+    //using consecutive entries of stylenames into the vector
+    //just as it would look like in a rendered single stripe.
+    ScDBDataFormatting aDBFormatting;
+    GetTableFormatting( aDBFormatting );
+    sal_Int32 i;
+    sal_Int32 nFirstSize;
+    sal_Int32 nSecondSize;
+    OUString aFirstStyle;
+    OUString aSecondStyle;
+    if ( bRowStripe )
+    {
+        //Fill the row stripe sequence
+        nFirstSize = aDBFormatting.GetFirstRowStripeSize();
+        aFirstStyle = aDBFormatting.GetFirstRowStripeStyle();
+        nSecondSize = aDBFormatting.GetSecondRowStripeSize();
+        aSecondStyle = aDBFormatting.GetSecondRowStripeStyle();
+        for ( i = 1; i <= nFirstSize; ++i )
+        {
+            //Add the first row stripe style to the RowStripeSeq vector nFirstSize
+            //many times.
+            aRowStripeSeq.push_back( aFirstStyle );
+        }
+        for ( i = 1; i<= nSecondSize; ++i )
+        {
+            //Similarly
+            aRowStripeSeq.push_back( aSecondStyle );
+        }
+    }
+    //Fill the column stripe sequence
+    else
+    {
+        nFirstSize = aDBFormatting.GetFirstColStripeSize();
+        aFirstStyle = aDBFormatting.GetFirstColStripeStyle();
+        nSecondSize = aDBFormatting.GetSecondColStripeSize();
+        aSecondStyle = aDBFormatting.GetSecondColStripeStyle();
+        for ( i = 1; i<=nFirstSize; ++i )
+        {
+            aColStripeSeq.push_back( aFirstStyle );
+        }
+        for ( i = 1; i<=nSecondSize; ++i )
+        {
+            aColStripeSeq.push_back( aSecondStyle );
+        }
+    }
+    //This approach of calculating the stripe sequence will be bad
+    //if stripe sizes are huge, they generally aren't.
+    //Now the math.
+    //We used 1-based addressing for this instead of the 0-based used in Calc
+    if ( bRowStripe )
+    {
+        sal_Int32 nStyleIndex = ( rPos.Row() + 1 ) % ( aRowStripeSeq.size() );
+        if ( nStyleIndex == 0 )
+        {
+            //Return the last entry in the vector
+            return aRowStripeSeq[ ( aRowStripeSeq.size() - 1 ) ];
+        }
+        else
+        {
+            //Return the nStyleIndex'th entry
+            return aRowStripeSeq[ ( nStyleIndex - 1) ];
+        }
+    }
+    else
+    {
+        sal_Int32 nStyleIndex = ( rPos.Row() + 1 ) % ( aRowStripeSeq.size() );
+        if ( nStyleIndex == 0 )
+        {
+            //Return the last entry in the vector
+            return aColStripeSeq[ ( aColStripeSeq.size() - 1 ) ];
+        }
+        else
+        {
+            //Return the nStyleIndex'th entry
+            return aColStripeSeq[ ( nStyleIndex - 1 ) ];
+        }
+    }
+}
+
commit c3a6f0390fbfe415ac500f440337c17cb9502c85
Author: Akash Shetye <shetyeakash at gmail.com>
Date:   Mon Aug 19 07:55:38 2013 +0530

    Added stripe size members in db formatting
    
    Change-Id: Ia87cf2ea8f2f8053649b427b55393d525c817374

diff --git a/sc/inc/dbdataformatting.hxx b/sc/inc/dbdataformatting.hxx
index 50d62f5..812901b 100644
--- a/sc/inc/dbdataformatting.hxx
+++ b/sc/inc/dbdataformatting.hxx
@@ -29,6 +29,10 @@ class SC_DLLPUBLIC ScDBDataFormatting
         OUString maSecondRowStripeStyle;
         OUString maFirstColStripeStyle;
         OUString maSecondColStripeStyle;
+        sal_Int32 maFirstRowStripeSize;
+        sal_Int32 maSecondRowStripeSize;
+        sal_Int32 maFirstColStripeSize;
+        sal_Int32 maSecondColStripeSize;
         bool bBandedRows;
         bool bBandedColumns;
     public:
@@ -45,6 +49,14 @@ class SC_DLLPUBLIC ScDBDataFormatting
         const OUString& GetSecondRowStripeStyle() const;
         const OUString& GetFirstColStripeStyle() const;
         const OUString& GetSecondColStripeStyle() const;
+        sal_Int32 GetFirstRowStripeSize() const { return maFirstRowStripeSize; }
+        sal_Int32 GetSecondRowStripeSize() const { return maSecondRowStripeSize; }
+        sal_Int32 GetFirstColStripeSize() const { return maFirstColStripeSize; }
+        sal_Int32 GetSecondColStripeSize() const { return maSecondColStripeSize; }
+        void SetFirstRowStripeSize( const sal_Int32 nSize ){ maFirstRowStripeSize = nSize; }
+        void SetSecondRowStripeSize( const sal_Int32 nSize ){ maSecondRowStripeSize = nSize; }
+        void SetFirstColStripeSize( const sal_Int32 nSize ){ maFirstColStripeSize = nSize; }
+        void SetSecondColStripeSize( const sal_Int32 nSize ){ maSecondColStripeSize = nSize; }
         void SetFirstRowStripeStyle( const OUString& aStyleName );
         void SetSecondRowStripeStyle( const OUString& aStyleName );
         void SetFirstColStripeStyle( const OUString& aStyleName );
diff --git a/sc/source/core/tool/dbdataformatting.cxx b/sc/source/core/tool/dbdataformatting.cxx
index 4ca3ef3..c1f11c2 100644
--- a/sc/source/core/tool/dbdataformatting.cxx
+++ b/sc/source/core/tool/dbdataformatting.cxx
@@ -20,16 +20,19 @@
 #include "dbdataformatting.hxx"
 #include "rtl/ustring.hxx"
 
-ScDBDataFormatting::ScDBDataFormatting()
-{
-    //Avoiding problems caused by uninitialized values
-    maTableStyleName = "Default";
-    maFirstRowStripeStyle = "Default";
-    maSecondRowStripeStyle = "Default";
-    maFirstColStripeStyle = "Default";
-    maSecondColStripeStyle = "Default";
-    bBandedRows = false;
-    bBandedColumns = false;
+ScDBDataFormatting::ScDBDataFormatting():
+    maTableStyleName        ( "Default" ),
+    maFirstRowStripeStyle   ( "Default" ),
+    maSecondRowStripeStyle  ( "Default" ),
+    maFirstColStripeStyle   ( "Default" ),
+    maSecondColStripeStyle  ( "Default" ),
+    bBandedRows             ( false ),
+    bBandedColumns          ( false ),
+    maFirstRowStripeSize    ( 1 ),
+    maSecondRowStripeSize   ( 1 ),
+    maFirstColStripeSize    ( 1 ),
+    maSecondColStripeSize   ( 1 )
+{
 }
 
 ScDBDataFormatting::ScDBDataFormatting(const OUString& rTableStyleName, const OUString& rFirstRowStripeStyle, const OUString& rSecondRowStripeStyle, const OUString& rFirstColStripeStyle, const OUString& rSecondColStripeStyle, bool bBRows, bool bBCols) :


More information about the Libreoffice-commits mailing list