LCOV - code coverage report
Current view: top level - sc/source/core/data - dpoutputgeometry.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 119 0.0 %
Date: 2014-04-14 Functions: 0 13 0.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           0 : 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           0 :     mbShowFilter(bShowFilter)
      35             : {
      36           0 : }
      37             : 
      38           0 : ScDPOutputGeometry::~ScDPOutputGeometry()
      39             : {
      40           0 : }
      41             : 
      42           0 : void ScDPOutputGeometry::setRowFieldCount(sal_uInt32 nCount)
      43             : {
      44           0 :     mnRowFields = nCount;
      45           0 : }
      46             : 
      47           0 : void ScDPOutputGeometry::setColumnFieldCount(sal_uInt32 nCount)
      48             : {
      49           0 :     mnColumnFields = nCount;
      50           0 : }
      51             : 
      52           0 : void ScDPOutputGeometry::setPageFieldCount(sal_uInt32 nCount)
      53             : {
      54           0 :     mnPageFields = nCount;
      55           0 : }
      56             : 
      57           0 : void ScDPOutputGeometry::setDataFieldCount(sal_uInt32 nCount)
      58             : {
      59           0 :     mnDataFields = nCount;
      60           0 : }
      61             : 
      62           0 : void ScDPOutputGeometry::setDataLayoutType(FieldType eType)
      63             : {
      64           0 :     meDataLayoutType = eType;
      65           0 : }
      66             : 
      67           0 : void ScDPOutputGeometry::getColumnFieldPositions(vector<ScAddress>& rAddrs) const
      68             : {
      69             :     sal_uInt32 nColumnFields, nRowFields;
      70           0 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
      71             : 
      72           0 :     vector<ScAddress> aAddrs;
      73           0 :     if (!nColumnFields)
      74             :     {
      75           0 :         rAddrs.swap(aAddrs);
      76           0 :         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           0 : void ScDPOutputGeometry::getRowFieldPositions(vector<ScAddress>& rAddrs) const
     101             : {
     102             :     sal_uInt32 nColumnFields, nRowFields;
     103           0 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
     104             : 
     105           0 :     vector<ScAddress> aAddrs;
     106           0 :     if (!nRowFields)
     107             :     {
     108           0 :         rAddrs.swap(aAddrs);
     109           0 :         return;
     110             :     }
     111             : 
     112           0 :     SCROW nRow = getRowFieldHeaderRow();
     113           0 :     SCTAB nTab = maOutRange.aStart.Tab();
     114           0 :     SCCOL nColStart = maOutRange.aStart.Col();
     115           0 :     SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
     116             : 
     117           0 :     for (SCCOL nCol = nColStart; nCol <= nColEnd; ++nCol)
     118           0 :         aAddrs.push_back(ScAddress(nCol, nRow, nTab));
     119           0 :     rAddrs.swap(aAddrs);
     120             : }
     121             : 
     122           0 : void ScDPOutputGeometry::getPageFieldPositions(vector<ScAddress>& rAddrs) const
     123             : {
     124           0 :     vector<ScAddress> aAddrs;
     125           0 :     if (!mnPageFields)
     126             :     {
     127           0 :         rAddrs.swap(aAddrs);
     128           0 :         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           0 : SCROW ScDPOutputGeometry::getRowFieldHeaderRow() const
     143             : {
     144           0 :     SCROW nCurRow = maOutRange.aStart.Row();
     145             :     sal_uInt32 nColumnFields, nRowFields;
     146           0 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
     147             : 
     148           0 :     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           0 :     else if (mbShowFilter)
     155           0 :         nCurRow += 2;
     156             : 
     157           0 :     if (nColumnFields)
     158           0 :         nCurRow += static_cast<SCROW>(nColumnFields);
     159           0 :     else if (nRowFields)
     160           0 :         ++nCurRow;
     161             : 
     162           0 :     return nCurRow;
     163             : }
     164             : 
     165           0 : void ScDPOutputGeometry::adjustFieldsForDataLayout(sal_uInt32& rColumnFields, sal_uInt32& rRowFields) const
     166             : {
     167           0 :     rRowFields = mnRowFields;
     168           0 :     rColumnFields = mnColumnFields;
     169             : 
     170           0 :     if (mnDataFields < 2)
     171             :     {
     172             :         // Data layout field can be either row or column field, never page field.
     173           0 :         switch (meDataLayoutType)
     174             :         {
     175             :             case Column:
     176           0 :                 if (rColumnFields > 0)
     177           0 :                     rColumnFields -= 1;
     178           0 :             break;
     179             :             case Row:
     180           0 :                 if (rRowFields > 0)
     181           0 :                     rRowFields -= 1;
     182             :             default:
     183             :                 ;
     184             :         }
     185             :     }
     186           0 : }
     187             : 
     188             : std::pair<ScDPOutputGeometry::FieldType, size_t>
     189           0 : ScDPOutputGeometry::getFieldButtonType(const ScAddress& rPos) const
     190             : {
     191           0 :     SCROW nCurRow = maOutRange.aStart.Row();
     192             :     sal_uInt32 nColumnFields, nRowFields;
     193           0 :     adjustFieldsForDataLayout(nColumnFields, nRowFields);
     194             : 
     195           0 :     if (mnPageFields)
     196             :     {
     197           0 :         SCCOL nCol = maOutRange.aStart.Col();
     198           0 :         SCROW nRowStart = maOutRange.aStart.Row() + int(mbShowFilter);
     199           0 :         SCROW nRowEnd   = nRowStart + static_cast<SCCOL>(mnPageFields-1);
     200           0 :         if (rPos.Col() == nCol && nRowStart <= rPos.Row() && rPos.Row() <= nRowEnd)
     201             :         {
     202           0 :             size_t nPos = static_cast<size_t>(rPos.Row() - nRowStart);
     203           0 :             return std::pair<FieldType, size_t>(Page, nPos);
     204             :         }
     205             : 
     206           0 :         nCurRow = nRowEnd + 2;
     207             :     }
     208           0 :     else if (mbShowFilter)
     209           0 :         nCurRow += 2;
     210             : 
     211           0 :     if (nColumnFields)
     212             :     {
     213           0 :         SCROW nRow = nCurRow;
     214           0 :         SCCOL nColStart = static_cast<SCCOL>(maOutRange.aStart.Col() + nRowFields);
     215           0 :         SCCOL nColEnd = nColStart + static_cast<SCCOL>(nColumnFields-1);
     216           0 :         if (rPos.Row() == nRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
     217             :         {
     218           0 :             size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
     219           0 :             return std::pair<FieldType, size_t>(Column, nPos);
     220             :         }
     221             : 
     222           0 :         nCurRow += static_cast<SCROW>(nColumnFields);
     223             :     }
     224             :     else
     225           0 :         ++nCurRow;
     226             : 
     227           0 :     if (nRowFields)
     228             :     {
     229           0 :         SCCOL nColStart = maOutRange.aStart.Col();
     230           0 :         SCCOL nColEnd = nColStart + static_cast<SCCOL>(nRowFields-1);
     231           0 :         if (rPos.Row() == nCurRow && nColStart <= rPos.Col() && rPos.Col() <= nColEnd)
     232             :         {
     233           0 :             size_t nPos = static_cast<size_t>(rPos.Col() - nColStart);
     234           0 :             return std::pair<FieldType, size_t>(Row, nPos);
     235             :         }
     236             :     }
     237             : 
     238           0 :     return std::pair<FieldType, size_t>(None, 0);
     239             : }
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10