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