LCOV - code coverage report
Current view: top level - sc/source/ui/undo - refundo.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 74 86 86.0 %
Date: 2014-04-11 Functions: 6 6 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 "refundo.hxx"
      21             : #include "undobase.hxx"
      22             : #include "document.hxx"
      23             : #include "dbdata.hxx"
      24             : #include "rangenam.hxx"
      25             : #include "pivot.hxx"
      26             : #include "chartarr.hxx"
      27             : #include "stlpool.hxx"
      28             : #include "detdata.hxx"
      29             : #include "prnsave.hxx"
      30             : #include "chartlis.hxx"
      31             : #include "dpobject.hxx"
      32             : #include "areasave.hxx"
      33             : #include "unoreflist.hxx"
      34             : #include <scopetools.hxx>
      35             : #include <refupdatecontext.hxx>
      36             : 
      37          49 : ScRefUndoData::ScRefUndoData( const ScDocument* pDoc ) :
      38          49 :     pUnoRefs( NULL )
      39             : {
      40          49 :     ScDBCollection* pOldDBColl = pDoc->GetDBCollection();
      41          49 :     pDBCollection = pOldDBColl ? new ScDBCollection(*pOldDBColl) : NULL;
      42             : 
      43          49 :     ScRangeName* pOldRanges = ((ScDocument*)pDoc)->GetRangeName();          //! const
      44          49 :     pRangeName = pOldRanges ? new ScRangeName(*pOldRanges) : NULL;
      45             : 
      46          49 :     pPrintRanges = pDoc->CreatePrintRangeSaver();       // recreated
      47             : 
      48             :     // when handling Pivot solely keep the range?
      49             : 
      50          49 :     ScDPCollection* pOldDP = ((ScDocument*)pDoc)->GetDPCollection();        //! const
      51          49 :     pDPCollection = pOldDP ? new ScDPCollection(*pOldDP) : NULL;
      52             : 
      53          49 :     ScDetOpList* pOldDetOp = pDoc->GetDetOpList();
      54          49 :     pDetOpList = pOldDetOp ? new ScDetOpList(*pOldDetOp) : 0;
      55             : 
      56             :     ScChartListenerCollection* pOldChartListenerCollection =
      57          49 :         pDoc->GetChartListenerCollection();
      58             :     pChartListenerCollection = pOldChartListenerCollection ?
      59          49 :         new ScChartListenerCollection( *pOldChartListenerCollection ) : NULL;
      60             : 
      61          49 :     pAreaLinks = ScAreaLinkSaveCollection::CreateFromDoc(pDoc);     // returns NULL if empty
      62             : 
      63          49 :     const_cast<ScDocument*>(pDoc)->BeginUnoRefUndo();
      64          49 : }
      65             : 
      66          41 : ScRefUndoData::~ScRefUndoData()
      67             : {
      68          41 :     delete pDBCollection;
      69          41 :     delete pRangeName;
      70          41 :     delete pPrintRanges;
      71          41 :     delete pDPCollection;
      72          41 :     delete pDetOpList;
      73          41 :     delete pChartListenerCollection;
      74          41 :     delete pAreaLinks;
      75          41 :     delete pUnoRefs;
      76          41 : }
      77             : 
      78          49 : void ScRefUndoData::DeleteUnchanged( const ScDocument* pDoc )
      79             : {
      80          49 :     if (pDBCollection)
      81             :     {
      82          49 :         ScDBCollection* pNewDBColl = pDoc->GetDBCollection();
      83          49 :         if ( pNewDBColl && *pDBCollection == *pNewDBColl )
      84           6 :             DELETEZ(pDBCollection);
      85             :     }
      86          49 :     if (pRangeName)
      87             :     {
      88          49 :         ScRangeName* pNewRanges = ((ScDocument*)pDoc)->GetRangeName();      //! const
      89          49 :         if ( pNewRanges && *pRangeName == *pNewRanges )
      90          46 :             DELETEZ(pRangeName);
      91             :     }
      92             : 
      93          49 :     if (pPrintRanges)
      94             :     {
      95          49 :         ScPrintRangeSaver* pNewRanges = pDoc->CreatePrintRangeSaver();
      96          49 :         if ( pNewRanges && *pPrintRanges == *pNewRanges )
      97          30 :             DELETEZ(pPrintRanges);
      98          49 :         delete pNewRanges;
      99             :     }
     100             : 
     101          49 :     if (pDPCollection)
     102             :     {
     103          49 :         ScDPCollection* pNewDP = ((ScDocument*)pDoc)->GetDPCollection();    //! const
     104          49 :         if ( pNewDP && pDPCollection->RefsEqual(*pNewDP) )
     105          33 :             DELETEZ(pDPCollection);
     106             :     }
     107             : 
     108          49 :     if (pDetOpList)
     109             :     {
     110           0 :         ScDetOpList* pNewDetOp = pDoc->GetDetOpList();
     111           0 :         if ( pNewDetOp && *pDetOpList == *pNewDetOp )
     112           0 :             DELETEZ(pDetOpList);
     113             :     }
     114             : 
     115          49 :     if ( pChartListenerCollection )
     116             :     {
     117             :         ScChartListenerCollection* pNewChartListenerCollection =
     118          49 :             pDoc->GetChartListenerCollection();
     119          98 :         if ( pNewChartListenerCollection &&
     120          49 :                 *pChartListenerCollection == *pNewChartListenerCollection )
     121          49 :             DELETEZ( pChartListenerCollection );
     122             :     }
     123             : 
     124          49 :     if (pAreaLinks)
     125             :     {
     126           0 :         if ( pAreaLinks->IsEqual( pDoc ) )
     127           0 :             DELETEZ(pAreaLinks);
     128             :     }
     129             : 
     130          49 :     if ( pDoc->HasUnoRefUndo() )
     131             :     {
     132          49 :         pUnoRefs = const_cast<ScDocument*>(pDoc)->EndUnoRefUndo();
     133          49 :         if ( pUnoRefs && pUnoRefs->IsEmpty() )
     134             :         {
     135          19 :             DELETEZ( pUnoRefs );
     136             :         }
     137             :     }
     138          49 : }
     139             : 
     140          15 : void ScRefUndoData::DoUndo( ScDocument* pDoc, bool bUndoRefFirst )
     141             : {
     142          15 :     if (pDBCollection)
     143          11 :         pDoc->SetDBCollection( new ScDBCollection(*pDBCollection) );
     144          15 :     if (pRangeName)
     145           2 :         pDoc->SetRangeName( new ScRangeName(*pRangeName) );
     146             : 
     147          15 :     if (pPrintRanges)
     148           1 :         pDoc->RestorePrintRanges(*pPrintRanges);
     149             : 
     150          15 :     if (pDPCollection)
     151             :     {
     152           0 :         ScDPCollection* pDocDP = pDoc->GetDPCollection();
     153           0 :         if (pDocDP)
     154           0 :             pDPCollection->WriteRefsTo( *pDocDP );
     155             :     }
     156             : 
     157          15 :     if (pDetOpList)
     158           0 :         pDoc->SetDetOpList( new ScDetOpList(*pDetOpList) );
     159             : 
     160             :     // bUndoRefFirst is bSetChartRangeLists
     161          15 :     if ( pChartListenerCollection )
     162             :         pDoc->SetChartListenerCollection( new ScChartListenerCollection(
     163           0 :             *pChartListenerCollection ), bUndoRefFirst );
     164             : 
     165          15 :     if (pDBCollection || pRangeName)
     166             :     {
     167          11 :         sc::AutoCalcSwitch aACSwitch(*pDoc, false);
     168          11 :         pDoc->CompileAll();
     169             : 
     170          11 :         sc::SetFormulaDirtyContext aCxt;
     171          11 :         pDoc->SetAllFormulasDirty(aCxt);
     172             :     }
     173             : 
     174          15 :     if (pAreaLinks)
     175           0 :         pAreaLinks->Restore( pDoc );
     176             : 
     177          15 :     if ( pUnoRefs )
     178           0 :         pUnoRefs->Undo( pDoc );
     179         117 : }
     180             : 
     181             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10