LibreOffice Module sc (master)  1
undorangename.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 
10 #include <undorangename.hxx>
11 #include <globstr.hrc>
12 #include <scresid.hxx>
13 
14 #include <sfx2/app.hxx>
15 
16 #include <memory>
17 #include <utility>
18 
19 using ::std::unique_ptr;
20 
22  ScDocShell* pDocSh,
23  const std::map<OUString, ScRangeName*>& rOldNames,
24  const std::map<OUString, std::unique_ptr<ScRangeName>>& rNewNames)
25  : ScSimpleUndo(pDocSh)
26 {
27  for (const auto& [rName, pRangeName] : rOldNames)
28  {
29  m_OldNames.insert(std::make_pair(rName, std::make_unique<ScRangeName>(*pRangeName)));
30  }
31 
32  for (auto const& it : rNewNames)
33  {
34  m_NewNames.insert(std::make_pair(it.first, std::make_unique<ScRangeName>(*it.second)));
35  }
36 }
37 
39 {
40 }
41 
43 {
45 }
46 
48 {
50 }
51 
53 {
54 }
55 
57 {
58  return false;
59 }
60 
62 {
63  return ScResId(STR_UNDO_RANGENAMES);
64 }
65 
66 void ScUndoAllRangeNames::DoChange(const std::map<OUString, std::unique_ptr<ScRangeName>>& rNames)
67 {
68  ScDocument& rDoc = pDocShell->GetDocument();
69 
70  rDoc.PreprocessAllRangeNamesUpdate(rNames);
71  rDoc.SetAllRangeNames(rNames);
72  rDoc.CompileHybridFormula();
73 
74  SfxGetpApp()->Broadcast(SfxHint(SfxHintId::ScAreasChanged));
75 }
76 
78  ScSimpleUndo(pDocSh),
79  mpRangeData(new ScRangeData(*pRangeData)),
80  mnTab(nTab)
81 {
82 
83 }
84 
86 {
87 }
88 
90 {
91  ScDocument& rDoc = pDocShell->GetDocument();
92  ScRangeName* pRangeName = nullptr;
93  if (mnTab == -1)
94  {
95  pRangeName = rDoc.GetRangeName();
96  }
97  else
98  {
99  pRangeName = rDoc.GetRangeName( mnTab );
100  }
101  pRangeName->erase(*mpRangeData);
102  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
103 
104 }
105 
107 {
108  ScDocument& rDoc = pDocShell->GetDocument();
109  ScRangeName* pRangeName = nullptr;
110  if (mnTab == -1)
111  {
112  pRangeName = rDoc.GetRangeName();
113  }
114  else
115  {
116  pRangeName = rDoc.GetRangeName( mnTab );
117  }
118  pRangeName->insert(new ScRangeData(*mpRangeData));
119  SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScAreasChanged ) );
120 }
121 
123 {
124 }
125 
127 {
128  return false;
129 }
130 
132 {
133  return ScResId(STR_UNDO_RANGENAMES);
134 }
135 
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void Undo() override
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
virtual ~ScUndoAllRangeNames() override
SC_DLLPUBLIC void CompileHybridFormula()
Call this immediately after updating named ranges.
Definition: document10.cxx:315
virtual void Redo() override
SC_DLLPUBLIC ScRangeName * GetRangeName(SCTAB nTab) const
Definition: documen3.cxx:168
ScUndoAddRangeData(ScDocShell *pDocSh, const ScRangeData *pRangeData, SCTAB nTab)
SfxApplication * SfxGetpApp()
virtual ~ScUndoAddRangeData() override
SC_DLLPUBLIC void PreprocessAllRangeNamesUpdate(const std::map< OUString, std::unique_ptr< ScRangeName >> &rRangeMap)
Call this immediately before updating all named ranges.
Definition: document10.cxx:245
virtual void Redo() override
virtual bool CanRepeat(SfxRepeatTarget &rTarget) const override
std::map< OUString, std::unique_ptr< ScRangeName > > m_OldNames
ScUndoAllRangeNames(ScDocShell *pDocSh, const std::map< OUString, ScRangeName * > &rOldNames, const std::map< OUString, std::unique_ptr< ScRangeName >> &rNewNames)
SC_DLLPUBLIC void SetAllRangeNames(const std::map< OUString, std::unique_ptr< ScRangeName >> &rRangeMap)
Definition: documen3.cxx:121
virtual void Repeat(SfxRepeatTarget &rTarget) override
virtual void Repeat(SfxRepeatTarget &rTarget) override
ScDocShell * pDocShell
Definition: undobase.hxx:47
virtual OUString GetComment() const override
void DoChange(const std::map< OUString, std::unique_ptr< ScRangeName >> &rNames)
void erase(const ScRangeData &r)
Definition: rangenam.cxx:857
std::unique_ptr< ScRangeData > mpRangeData
virtual OUString GetComment() const override
virtual void Undo() override
std::map< OUString, std::unique_ptr< ScRangeName > > m_NewNames
const ScDocument & GetDocument() const
Definition: docsh.hxx:216
std::unique_ptr< ScRangeName > pRangeName
Definition: document.hxx:378
virtual bool CanRepeat(SfxRepeatTarget &rTarget) const override
SC_DLLPUBLIC bool insert(ScRangeData *p, bool bReuseFreeIndex=true)
Insert object into set.
Definition: rangenam.cxx:814
sal_Int16 SCTAB
Definition: types.hxx:22