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