LibreOffice Module sc (master)  1
detdata.cxx
Go to the documentation of this file.
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 <algorithm>
21 #include <memory>
22 #include <detdata.hxx>
23 #include <refupdat.hxx>
24 
26  bHasAddError( false )
27 {
28  size_t nCount = rList.Count();
29 
30  for (size_t i=0; i<nCount; i++)
31  Append( new ScDetOpData( *rList.aDetOpDataVector[i] ) );
32 }
33 
35 {
36  aDetOpDataVector.erase(std::remove_if(aDetOpDataVector.begin(), aDetOpDataVector.end(),
37  [&nTab](const std::unique_ptr<ScDetOpData>& rxDetOpData) {
38  return rxDetOpData->GetPos().Tab() == nTab; // look for operations on the deleted sheet
39  }),
40  aDetOpDataVector.end());
41 }
42 
43 void ScDetOpList::UpdateReference( const ScDocument* pDoc, UpdateRefMode eUpdateRefMode,
44  const ScRange& rRange, SCCOL nDx, SCROW nDy, SCTAB nDz )
45 {
46  for (auto& rxDetOpData : aDetOpDataVector )
47  {
48  ScAddress aPos = rxDetOpData->GetPos();
49  SCCOL nCol1 = aPos.Col();
50  SCROW nRow1 = aPos.Row();
51  SCTAB nTab1 = aPos.Tab();
52  SCCOL nCol2 = nCol1;
53  SCROW nRow2 = nRow1;
54  SCTAB nTab2 = nTab1;
55 
56  ScRefUpdateRes eRes =
57  ScRefUpdate::Update( pDoc, eUpdateRefMode,
58  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
59  rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, nDz,
60  nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
61  if ( eRes != UR_NOTHING )
62  rxDetOpData->SetPos( ScAddress( nCol1, nRow1, nTab1 ) );
63  }
64 }
65 
66 void ScDetOpList::Append( ScDetOpData* pDetOpData )
67 {
68  if ( pDetOpData->GetOperation() == SCDETOP_ADDERROR )
69  bHasAddError = true;
70 
71  aDetOpDataVector.push_back( std::unique_ptr<ScDetOpData>(pDetOpData) );
72 }
73 
74 bool ScDetOpList::operator==( const ScDetOpList& r ) const
75 {
76  // for Ref-Undo
77 
78  size_t nCount = Count();
79  bool bEqual = ( nCount == r.Count() );
80  for (size_t i=0; i<nCount && bEqual; i++) // order has to be the same
81  if ( !(*aDetOpDataVector[i] == *r.aDetOpDataVector[i]) ) // entries are different ?
82  bEqual = false;
83 
84  return bEqual;
85 }
86 
87 const ScDetOpData& ScDetOpList::GetObject( size_t nPos ) const
88 {
89  return *aDetOpDataVector[nPos];
90 }
91 
92 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScDetOpDataVector aDetOpDataVector
Definition: detdata.hxx:66
static ScRefUpdateRes Update(const ScDocument *pDoc, UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz, SCCOL &theCol1, SCROW &theRow1, SCTAB &theTab1, SCCOL &theCol2, SCROW &theRow2, SCTAB &theTab2)
Definition: refupdat.cxx:188
ScAddress aStart
Definition: address.hxx:500
SCROW Row() const
Definition: address.hxx:262
ScAddress aEnd
Definition: address.hxx:501
size_t Count() const
Definition: detdata.hxx:83
int nCount
SCTAB Tab() const
Definition: address.hxx:271
int i
sal_Int16 SCCOL
Definition: types.hxx:22
Reference not affected, no change at all.
Definition: refupdat.hxx:32
SCCOL Col() const
Definition: address.hxx:267
bool operator==(const ScDetOpList &r) const
Definition: detdata.cxx:74
void Append(ScDetOpData *pData)
Definition: detdata.cxx:66
UpdateRefMode
Definition: global.hxx:312
sal_Int32 SCROW
Definition: types.hxx:18
ScDetOpType GetOperation() const
Definition: detdata.hxx:50
void DeleteOnTab(SCTAB nTab)
Definition: detdata.cxx:34
void UpdateReference(const ScDocument *pDoc, UpdateRefMode eUpdateRefMode, const ScRange &rRange, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: detdata.cxx:43
const ScDetOpData & GetObject(size_t nPos) const
Definition: detdata.cxx:87
ScRefUpdateRes
Definition: refupdat.hxx:31
bool bHasAddError
Definition: detdata.hxx:65
sal_Int16 SCTAB
Definition: types.hxx:23