LCOV - code coverage report
Current view: top level - sc/source/core/data - documentstreamaccess.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 69 1.4 %
Date: 2014-11-03 Functions: 2 11 18.2 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  */
       9             : 
      10             : #include "documentstreamaccess.hxx"
      11             : #include "document.hxx"
      12             : #include "table.hxx"
      13             : #include "column.hxx"
      14             : #include "mtvelements.hxx"
      15             : 
      16             : #include <svl/sharedstringpool.hxx>
      17             : 
      18             : namespace sc {
      19             : 
      20           0 : struct DocumentStreamAccessImpl
      21             : {
      22             :     ScDocument& mrDoc;
      23             :     ColumnBlockPositionSet maBlockPosSet;
      24             : 
      25           0 :     DocumentStreamAccessImpl( ScDocument& rDoc ) :
      26             :         mrDoc(rDoc),
      27           0 :         maBlockPosSet(rDoc)
      28           0 :     {}
      29             : };
      30             : 
      31           0 : DocumentStreamAccess::DocumentStreamAccess( ScDocument& rDoc ) :
      32           0 :     mpImpl(new DocumentStreamAccessImpl(rDoc)) {}
      33             : 
      34           0 : DocumentStreamAccess::~DocumentStreamAccess()
      35             : {
      36           0 : }
      37             : 
      38           0 : void DocumentStreamAccess::setNumericCell( const ScAddress& rPos, double fVal )
      39             : {
      40           0 :     ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
      41           0 :     if (!pTab)
      42           0 :         return;
      43             : 
      44             :     ColumnBlockPosition* pBlockPos =
      45           0 :         mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col());
      46             : 
      47           0 :     if (!pBlockPos)
      48           0 :         return;
      49             : 
      50             :     // Set the numeric value.
      51           0 :     CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
      52           0 :     pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), fVal);
      53             : 
      54             :     // Be sure to set the corresponding text attribute to the default value.
      55           0 :     CellTextAttrStoreType& rAttrs = pTab->aCol[rPos.Col()].maCellTextAttrs;
      56           0 :     pBlockPos->miCellTextAttrPos = rAttrs.set(pBlockPos->miCellTextAttrPos, rPos.Row(), CellTextAttr());
      57             : }
      58             : 
      59           0 : void DocumentStreamAccess::setStringCell( const ScAddress& rPos, const OUString& rStr )
      60             : {
      61           0 :     ScTable* pTab = mpImpl->mrDoc.FetchTable(rPos.Tab());
      62           0 :     if (!pTab)
      63           0 :         return;
      64             : 
      65             :     ColumnBlockPosition* pBlockPos =
      66           0 :         mpImpl->maBlockPosSet.getBlockPosition(rPos.Tab(), rPos.Col());
      67             : 
      68           0 :     if (!pBlockPos)
      69           0 :         return;
      70             : 
      71           0 :     svl::SharedString aSS = mpImpl->mrDoc.GetSharedStringPool().intern(rStr);
      72           0 :     if (!aSS.getData())
      73           0 :         return;
      74             : 
      75             :     // Set the string.
      76           0 :     CellStoreType& rCells = pTab->aCol[rPos.Col()].maCells;
      77           0 :     pBlockPos->miCellPos = rCells.set(pBlockPos->miCellPos, rPos.Row(), aSS);
      78             : 
      79             :     // Be sure to set the corresponding text attribute to the default value.
      80           0 :     CellTextAttrStoreType& rAttrs = pTab->aCol[rPos.Col()].maCellTextAttrs;
      81           0 :     pBlockPos->miCellTextAttrPos = rAttrs.set(pBlockPos->miCellTextAttrPos, rPos.Row(), CellTextAttr());
      82             : }
      83             : 
      84           0 : void DocumentStreamAccess::reset()
      85             : {
      86           0 :     mpImpl->maBlockPosSet.clear();
      87           0 : }
      88             : 
      89           0 : void DocumentStreamAccess::shiftRangeUp( const ScRange& rRange )
      90             : {
      91           0 :     ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab());
      92           0 :     if (!pTab)
      93           0 :         return;
      94             : 
      95           0 :     SCROW nTopRow = rRange.aStart.Row();
      96           0 :     SCROW nLastRow = rRange.aEnd.Row();
      97             : 
      98           0 :     for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
      99             :     {
     100             :         ColumnBlockPosition* pBlockPos =
     101           0 :             mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol);
     102             : 
     103           0 :         if (!pBlockPos)
     104           0 :             return;
     105             : 
     106           0 :         CellStoreType& rCells = pTab->aCol[nCol].maCells;
     107           0 :         rCells.erase(nTopRow, nTopRow); // Erase the top, and shift the rest up.
     108           0 :         pBlockPos->miCellPos = rCells.insert_empty(nLastRow, 1);
     109             : 
     110             :         // Do the same for the text attribute storage.
     111           0 :         CellTextAttrStoreType& rAttrs = pTab->aCol[nCol].maCellTextAttrs;
     112           0 :         rAttrs.erase(nTopRow, nTopRow);
     113           0 :         pBlockPos->miCellTextAttrPos = rAttrs.insert_empty(nLastRow, 1);
     114             :     }
     115             : }
     116             : 
     117           0 : void DocumentStreamAccess::shiftRangeDown( const ScRange& rRange )
     118             : {
     119           0 :     ScTable* pTab = mpImpl->mrDoc.FetchTable(rRange.aStart.Tab());
     120           0 :     if (!pTab)
     121           0 :         return;
     122             : 
     123           0 :     SCROW nTopRow = rRange.aStart.Row();
     124           0 :     SCROW nLastRow = rRange.aEnd.Row();
     125             : 
     126           0 :     for (SCCOL nCol = rRange.aStart.Col(); nCol <= rRange.aEnd.Col(); ++nCol)
     127             :     {
     128             :         ColumnBlockPosition* pBlockPos =
     129           0 :             mpImpl->maBlockPosSet.getBlockPosition(rRange.aStart.Tab(), nCol);
     130             : 
     131           0 :         if (!pBlockPos)
     132           0 :             return;
     133             : 
     134           0 :         CellStoreType& rCells = pTab->aCol[nCol].maCells;
     135           0 :         rCells.erase(nLastRow, nLastRow); // Erase the bottom.
     136           0 :         pBlockPos->miCellPos = rCells.insert_empty(nTopRow, 1); // insert at the top and shift everything down.
     137             : 
     138             :         // Do the same for the text attribute storage.
     139           0 :         CellTextAttrStoreType& rAttrs = pTab->aCol[nCol].maCellTextAttrs;
     140           0 :         rAttrs.erase(nLastRow, nLastRow);
     141           0 :         pBlockPos->miCellTextAttrPos = rAttrs.insert_empty(nTopRow, 1);
     142             :     }
     143             : }
     144             : 
     145         228 : }
     146             : 
     147             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10