LCOV - code coverage report
Current view: top level - sc/source/core/data - dpoutputgeometry.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 89 119 74.8 %
Date: 2015-06-13 12:38:46 Functions: 13 13 100.0 %
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             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "dpoutputgeometry.hxx"
      21             : #include "address.hxx"
      22             : 
      23             : #include <vector>
      24             : 
      25             : using ::std::vector;
      26             : 
      27          12 : ScDPOutputGeometry::ScDPOutputGeometry(const ScRange& rOutRange, bool bShowFilter) :
      28             :     maOutRange(rOutRange),
      29             :     mnRowFields(0),
      30             :     mnColumnFields(0),
      31             :     mnPageFields(0),
      32             :     mnDataFields(0),
      33             :     meDataLayoutType(None),
      34          12 :     mbShowFilter(bShowFilter)
      35             : {
      36          12 : }
      37             : 
      38          12 : ScDPOutputGeometry::~ScDPOutputGeometry()
      39             : {
      40          12 : }
      41             : 
      42          12 : void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
      43             : {
      44          12 :     mnRowFields = nCount;
      45          12 : }
      46             : 
      47          12 : void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount)
      48             : {
      49          12 :     mnColumnFields = nCount;
      50          12 : }
      51             : 
      52          12 : void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount)
      53             : {
      54          12 :     mnPageFields = nCount;
      55          12 : }
      56             : 
      57          12 : void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount)
      58             : {
      59          12 :     mnDataFields = nCount;
      60          12 : }
      61             : 
      62          11 : void ScDPOutputGeometry::setDataLayoutType(FieldType eType)
      63             : {
      64          11 :     meDataLayoutType = eType;
      65          11 : }
      66             : 
      67           1 : void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
      68             : {
      69             :     sal_uInt32 nColumnFields, nRowFields;
      70           1 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
      71             : 
      72           1 :     vector<ScAddress> aAddrs;
      73           1 :     if (!nColumnFields)
      74             :     {
      75           1 :         rAddrs.swap(aAddrs);
      76           2 :         return;
      77             :     }
      78             : 
      79           0 :     SCROW nCurRow = maOutRange.aStart.Row();
      80             : 
      81           0 :     if (mnPageFields)
      82             :     {
      83           0 :         SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
      84           0 :         SCROW nRowEnd   = nRowStart + static_cast<SCCOL>(mnPageFields-1);
      85           0 :         nCurRow = nRowEnd + 2;
      86             :     }
      87           0 :     else if (mbShowFilter)
      88           0 :         nCurRow += 2;
      89             : 
      90           0 :     SCROW nRow = nCurRow;
      91           0 :     SCTAB nTab = maOutRange.aStart.Tab();
      92           0 :     SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
      93           0 :     SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
      94             : 
      95           0 :     for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
      96           0 :         aAddrs.push_back(ScAddress(nCol, nRow, nTab));
      97           0 :     rAddrs.swap(aAddrs);
      98             : }
      99             : 
     100           1 : void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
     101             : {
     102             :     sal_uInt32 nColumnFields, nRowFields;
     103           1 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
     104             : 
     105           1 :     vector<ScAddress> aAddrs;
     106           1 :     if (!nRowFields)
     107             :     {
     108           0 :         rAddrs.swap(aAddrs);
     109           1 :         return;
     110             :     }
     111             : 
     112           1 :     SCROW nRow = getRowFieldHeaderRow();
     113           1 :     SCTAB nTab = maOutRange.aStart.Tab();
     114           1 :     SCCOL nColStart = maOutRange.aStart.Col();
     115           1 :     SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
     116             : 
     117           3 :     for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
     118           2 :         aAddrs.push_back(ScAddress(nCol, nRow, nTab));
     119           1 :     rAddrs.swap(aAddrs);
     120             : }
     121             : 
     122           1 : void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
     123             : {
     124           1 :     vector<ScAddress> aAddrs;
     125           1 :     if (!mnPageFields)
     126             :     {
     127           1 :         rAddrs.swap(aAddrs);
     128           2 :         return;
     129             :     }
     130             : 
     131           0 :     SCTAB nTab = maOutRange.aStart.Tab();
     132           0 :     SCCOL nCol = maOutRange.aStart.Col();
     133             : 
     134           0 :     SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
     135           0 :     SCROW nRowEnd   = nRowStart + static_cast<SCCOL>(mnPageFields-1);
     136             : 
     137           0 :     for (SCROW nRow = nRowStart; nRow <= nRowEnd; ++nRow)
     138           0 :         aAddrs.push_back(ScAddress(nCol, nRow, nTab));
     139           0 :     rAddrs.swap(aAddrs);
     140             : }
     141             : 
     142           1 : SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
     143             : {
     144           1 :     SCROW nCurRow = maOutRange.aStart.Row();
     145             :     sal_uInt32 nColumnFields, nRowFields;
     146           1 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
     147             : 
     148           1 :     if (mnPageFields)
     149             :     {
     150           0 :         SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
     151           0 :         SCROW nRowEnd   = nRowStart + static_cast<SCCOL>(mnPageFields-1);
     152           0 :         nCurRow = nRowEnd + 2;
     153             :     }
     154           1 :     else if (mbShowFilter)
     155           0 :         nCurRow += 2;
     156             : 
     157           1 :     if (nColumnFields)
     158           0 :         nCurRow += static_cast<SCROW>(nColumnFields);
     159           1 :     else if (nRowFields)
     160           1 :         ++nCurRow;
     161             : 
     162           1 :     return nCurRow;
     163             : }
     164             : 
     165          47 : void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32& rColumnFields, sal_uInt32& rRowFields) const
     166             : {
     167          47 :     rRowFields = mnRowFields;
     168          47 :     rColumnFields = mnColumnFields;
     169             : 
     170          47 :     if (mnDataFields < 2)
     171             :     {
     172             :         // Data layout field can be either row or column field, never page field.
     173          47 :         switch (meDataLayoutType)
     174             :         {
     175             :             case Column:
     176           0 :                 if (rColumnFields > 0)
     177           0 :                     rColumnFields -= 1;
     178           0 :             break;
     179             :             case Row:
     180          38 :                 if (rRowFields > 0)
     181          38 :                     rRowFields -= 1;
     182             :             default:
     183             :                 ;
     184             :         }
     185             :     }
     186          47 : }
     187             : 
     188             : std::pair<ScDPOutputGeometry::FieldType, size_t>
     189          44 : ScDPOutputGeometry::getFieldButtonType(const ScAddress& rPos) const
     190             : {
     191          44 :     SCROW nCurRow = maOutRange.aStart.Row();
     192             :     sal_uInt32 nColumnFields, nRowFields;
     193          44 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
     194             : 
     195          44 :     if (mnPageFields)
     196             :     {
     197          28 :         SCCOL nCol = maOutRange.aStart.Col();
     198          28 :         SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
     199          28 :         SCROW nRowEnd   = nRowStart + static_cast<SCCOL>(mnPageFields-1);
     200          28 :         if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
     201             :         {
     202           6 :             size_t nPos = static_cast<size_t>(rPos.Row() - nRowStart);
     203           6 :             return std::pair<FieldType, size_t>(Page, nPos);
     204             :         }
     205             : 
     206          22 :         nCurRow = nRowEnd + 2;
     207             :     }
     208          16 :     else if (mbShowFilter)
     209          12 :         nCurRow += 2;
     210             : 
     211          38 :     if (nColumnFields)
     212             :     {
     213          31 :         SCROW nRow = nCurRow;
     214          31 :         SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
     215          31 :         SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
     216          31 :         if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
     217             :         {
     218          11 :             size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
     219          11 :             return std::pair<FieldType, size_t>(Column, nPos);
     220             :         }
     221             : 
     222          20 :         nCurRow += static_cast<SCROW>(nColumnFields);
     223             :     }
     224             :     else
     225           7 :         ++nCurRow;
     226             : 
     227          27 :     if (nRowFields)
     228             :     {
     229          26 :         SCCOL nColStart = maOutRange.aStart.Col();
     230          26 :         SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
     231          26 :         if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
     232             :         {
     233          13 :             size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
     234          13 :             return std::pair<FieldType, size_t>(Row, nPos);
     235             :         }
     236             :     }
     237             : 
     238          14 :     return std::pair<FieldType, size_t>(None, 0);
     239             : }
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11