LibreOffice Module dbaccess (master) 1
TableUndo.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 "TableUndo.hxx"
21#include <strings.hrc>
22#include "TEditControl.hxx"
23#include <TableRow.hxx>
24#include <TableController.hxx>
25#include <TableDesignView.hxx>
26#include <FieldDescriptions.hxx>
27#include <svx/svxids.hrc>
28#include <utility>
29
30using namespace dbaui;
31using namespace ::svt;
32
33
34OTableDesignUndoAct::OTableDesignUndoAct(OTableRowView* pOwner, TranslateId pCommentID)
35 : OCommentUndoAction(pCommentID)
36 , m_pTabDgnCtrl(pOwner)
37{
38 m_pTabDgnCtrl->m_nCurUndoActId++;
39}
40
42{
43}
44
46{
47 m_pTabDgnCtrl->m_nCurUndoActId--;
48
49 // doc has not been modified if first undo was reverted
50 if( m_pTabDgnCtrl->m_nCurUndoActId == 0 )
51 {
52 m_pTabDgnCtrl->GetView()->getController().setModified(false);
53 m_pTabDgnCtrl->GetView()->getController().InvalidateFeature(SID_SAVEDOC);
54 }
55}
56
58{
59 m_pTabDgnCtrl->m_nCurUndoActId++;
60
61 // restore Modified-flag after Redo of first Undo-action
62 if( m_pTabDgnCtrl->m_nCurUndoActId > 0 )
63 {
64 m_pTabDgnCtrl->GetView()->getController().setModified(true);
65 m_pTabDgnCtrl->GetView()->getController().InvalidateFeature(SID_SAVEDOC);
66 }
67}
68
69OTableDesignCellUndoAct::OTableDesignCellUndoAct( OTableRowView* pOwner, sal_Int32 nRowID, sal_uInt16 nColumn ) :
70 OTableDesignUndoAct( pOwner ,STR_TABED_UNDO_CELLMODIFIED)
71 ,m_nCol( nColumn )
72 ,m_nRow( nRowID )
73{
74 // read text at position (m_nRow, m_nCol)
75 m_sOldText = m_pTabDgnCtrl->GetCellData( m_nRow, m_nCol );
76}
77
79{
80}
81
83{
84 // store text at old line and restore the old one
85 m_pTabDgnCtrl->ActivateCell( m_nRow, m_nCol );
86 m_sNewText = m_pTabDgnCtrl->GetCellData( m_nRow, m_nCol );
87 m_pTabDgnCtrl->SetCellData( m_nRow, m_nCol, m_sOldText );
88 // line has not been modified if the first Undo was reverted
89 if (m_pTabDgnCtrl->GetCurUndoActId() == 1)
90 {
92 if ( xController.is() )
93 xController->SaveValue();
94 m_pTabDgnCtrl->GetView()->getController().setModified(false);
95
96 }
97
99}
100
102{
103 // restore new text
104 m_pTabDgnCtrl->ActivateCell( m_nRow, m_nCol );
105 m_pTabDgnCtrl->SetCellData( m_nRow, m_nCol, m_sNewText );
106
108}
109
111 : OTableDesignUndoAct(pOwner, pCommentID)
112 , pTabEdCtrl(pOwner)
113{
114}
115
117{
118}
119
120OTableEditorTypeSelUndoAct::OTableEditorTypeSelUndoAct( OTableEditorCtrl* pOwner, sal_Int32 nRowID, sal_uInt16 nColumn, TOTypeInfoSP _pOldType )
121 :OTableEditorUndoAct( pOwner ,STR_TABED_UNDO_TYPE_CHANGED)
122 ,m_nCol( nColumn )
123 ,m_nRow( nRowID )
124 ,m_pOldType(std::move( _pOldType ))
125{
126}
127
129{
130}
131
133{
134 // restore type
135 OFieldDescription* pFieldDesc = pTabEdCtrl->GetFieldDescr(m_nRow);
136 if(pFieldDesc)
137 m_pNewType = pFieldDesc->getTypeInfo();
138 else
140 pTabEdCtrl->SetCellData(m_nRow,m_nCol,m_pOldType);
141 pTabEdCtrl->SwitchType( m_pOldType );
142
144}
145
147{
148 // new type
149 pTabEdCtrl->GoToRowColumnId( m_nRow ,m_nCol);
150 pTabEdCtrl->SetCellData(m_nRow,m_nCol,m_pNewType);
151
153}
154
156 OTableEditorUndoAct( pOwner ,STR_TABED_UNDO_ROWDELETED)
157{
158 // fill DeletedRowList
159 std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pOwner->GetRowList();
160 sal_Int32 nIndex = pOwner->FirstSelectedRow();
161 std::shared_ptr<OTableRow> pOriginalRow;
162 std::shared_ptr<OTableRow> pNewRow;
163
164 while( nIndex != SFX_ENDOFSELECTION )
165 {
166 pOriginalRow = (*pOriginalRows)[nIndex];
167 pNewRow = std::make_shared<OTableRow>( *pOriginalRow, nIndex );
168 m_aDeletedRows.push_back( pNewRow);
169
170 nIndex = pOwner->NextSelectedRow();
171 }
172}
173
175{
176 m_aDeletedRows.clear();
177}
178
180{
181 // Insert the deleted line
182 sal_Int32 nPos;
183
184 std::shared_ptr<OTableRow> pNewOrigRow;
185 std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
186
187 for (auto const& deletedRow : m_aDeletedRows)
188 {
189 pNewOrigRow = std::make_shared<OTableRow>( *deletedRow );
190 nPos = deletedRow->GetPos();
191 pOriginalRows->insert( pOriginalRows->begin()+nPos,pNewOrigRow);
192 }
193
194 pTabEdCtrl->DisplayData(pTabEdCtrl->GetCurRow());
195 pTabEdCtrl->Invalidate();
197}
198
200{
201 // delete line again
202 std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
203
204 for (auto const& deletedRow : m_aDeletedRows)
205 {
206 auto it = pOriginalRows->begin() + deletedRow->GetPos();
207 pOriginalRows->erase(it);
208 }
209
210 pTabEdCtrl->DisplayData(pTabEdCtrl->GetCurRow());
211 pTabEdCtrl->Invalidate();
213}
214
216 tools::Long nInsertPosition ,
217 std::vector< std::shared_ptr<OTableRow> >&& _vInsertedRows)
218 :OTableEditorUndoAct( pOwner,STR_TABED_UNDO_ROWINSERTED )
219 ,m_vInsertedRows(std::move(_vInsertedRows))
220 ,m_nInsPos( nInsertPosition )
221{
222}
223
225{
226 m_vInsertedRows.clear();
227}
228
230{
231 // delete lines again
232 std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
233 pOriginalRows->erase(pOriginalRows->begin() + m_nInsPos, pOriginalRows->begin() + m_nInsPos + m_vInsertedRows.size());
234
235 pTabEdCtrl->RowRemoved( m_nInsPos, m_vInsertedRows.size() );
236 pTabEdCtrl->InvalidateHandleColumn();
237
239}
240
242{
243 // insert lines again
244 sal_Int32 nInsertRow = m_nInsPos;
245 std::shared_ptr<OTableRow> pRow;
246 std::vector< std::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
247 for (auto const& insertedRow : m_vInsertedRows)
248 {
249 pRow = std::make_shared<OTableRow>( *insertedRow );
250 pRowList->insert( pRowList->begin()+nInsertRow ,pRow );
251 nInsertRow++;
252 }
253
254 pTabEdCtrl->RowInserted( m_nInsPos, m_vInsertedRows.size() );
255 pTabEdCtrl->InvalidateHandleColumn();
256
258}
259
260OTableEditorInsNewUndoAct::OTableEditorInsNewUndoAct( OTableEditorCtrl* pOwner, sal_Int32 nInsertPosition, sal_Int32 nInsertedRows ) :
261 OTableEditorUndoAct( pOwner ,STR_TABED_UNDO_NEWROWINSERTED)
262 ,m_nInsPos( nInsertPosition )
263 ,m_nInsRows( nInsertedRows )
264{
265}
266
268{
269}
270
272{
273 // delete inserted lines
274 std::vector< std::shared_ptr<OTableRow> >* pOriginalRows = pTabEdCtrl->GetRowList();
275
276 pOriginalRows->erase(pOriginalRows->begin() + m_nInsPos, pOriginalRows->begin() + m_nInsPos + m_nInsRows);
277
278 pTabEdCtrl->RowRemoved( m_nInsPos, m_nInsRows );
279 pTabEdCtrl->InvalidateHandleColumn();
280
282}
283
285{
286 // insert lines again
287 std::vector< std::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
288
290 pRowList->insert( pRowList->begin()+i,std::make_shared<OTableRow>() );
291
292 pTabEdCtrl->RowInserted( m_nInsPos, m_nInsRows );
293 pTabEdCtrl->InvalidateHandleColumn();
294
296}
297
298OPrimKeyUndoAct::OPrimKeyUndoAct( OTableEditorCtrl* pOwner, const MultiSelection& aDeletedKeys, const MultiSelection& aInsertedKeys) :
299 OTableEditorUndoAct( pOwner ,STR_TABLEDESIGN_UNDO_PRIMKEY)
300 ,m_aDelKeys( aDeletedKeys )
301 ,m_aInsKeys( aInsertedKeys )
302 ,m_pEditorCtrl( pOwner )
303{
304}
305
307{
308}
309
311{
312 std::vector< std::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
313 std::shared_ptr<OTableRow> pRow;
315
316 // delete inserted keys
318 {
319 OSL_ENSURE(nIndex <= static_cast<tools::Long>(pRowList->size()),"Index for undo isn't valid!");
320 pRow = (*pRowList)[nIndex];
321 pRow->SetPrimaryKey( false );
322 }
323
324 // restore deleted keys
326 {
327 OSL_ENSURE(nIndex <= static_cast<tools::Long>(pRowList->size()),"Index for undo isn't valid!");
328 pRow = (*pRowList)[nIndex];
329 pRow->SetPrimaryKey( true );
330 }
331
332 m_pEditorCtrl->InvalidateHandleColumn();
334}
335
337{
338 std::vector< std::shared_ptr<OTableRow> >* pRowList = pTabEdCtrl->GetRowList();
340
341 // delete the deleted keys
343 (*pRowList)[nIndex]->SetPrimaryKey( false );
344
345 // restore the inserted keys
347 (*pRowList)[nIndex]->SetPrimaryKey( true );
348
349 m_pEditorCtrl->InvalidateHandleColumn();
351}
352
353/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 FirstSelected()
sal_Int32 NextSelected()
const TOTypeInfoSP & getTypeInfo() const
virtual void Undo() override
Definition: TableUndo.cxx:310
virtual void Redo() override
Definition: TableUndo.cxx:336
MultiSelection m_aDelKeys
Definition: TableUndo.hxx:124
virtual ~OPrimKeyUndoAct() override
Definition: TableUndo.cxx:306
OPrimKeyUndoAct(OTableEditorCtrl *pOwner, const MultiSelection &aDeletedKeys, const MultiSelection &aInsertedKeys)
Definition: TableUndo.cxx:298
VclPtr< OTableEditorCtrl > m_pEditorCtrl
Definition: TableUndo.hxx:126
MultiSelection m_aInsKeys
Definition: TableUndo.hxx:125
virtual ~OTableDesignCellUndoAct() override
Definition: TableUndo.cxx:78
virtual void Redo() override
Definition: TableUndo.cxx:101
OTableDesignCellUndoAct(OTableRowView *pOwner, sal_Int32 nRowID, sal_uInt16 nColumn)
Definition: TableUndo.cxx:69
virtual void Undo() override
Definition: TableUndo.cxx:82
virtual void Redo() override
Definition: TableUndo.cxx:57
virtual void Undo() override
Definition: TableUndo.cxx:45
VclPtr< OTableRowView > m_pTabDgnCtrl
Definition: TableUndo.hxx:37
virtual ~OTableDesignUndoAct() override
Definition: TableUndo.cxx:41
virtual ~OTableEditorDelUndoAct() override
Definition: TableUndo.cxx:174
virtual void Redo() override
Definition: TableUndo.cxx:199
OTableEditorDelUndoAct(OTableEditorCtrl *pOwner)
Definition: TableUndo.cxx:155
std::vector< std::shared_ptr< OTableRow > > m_aDeletedRows
Definition: TableUndo.hxx:87
virtual void Undo() override
Definition: TableUndo.cxx:179
virtual void Undo() override
Definition: TableUndo.cxx:271
virtual ~OTableEditorInsNewUndoAct() override
Definition: TableUndo.cxx:267
virtual void Redo() override
Definition: TableUndo.cxx:284
OTableEditorInsNewUndoAct(OTableEditorCtrl *pOwner, sal_Int32 nInsertPosition, sal_Int32 nInsertedRows)
Definition: TableUndo.cxx:260
virtual void Redo() override
Definition: TableUndo.cxx:241
OTableEditorInsUndoAct(OTableEditorCtrl *pOwner, tools::Long nInsertPosition, std::vector< std::shared_ptr< OTableRow > > &&_vInsertedRows)
Definition: TableUndo.cxx:215
std::vector< std::shared_ptr< OTableRow > > m_vInsertedRows
Definition: TableUndo.hxx:98
virtual ~OTableEditorInsUndoAct() override
Definition: TableUndo.cxx:224
virtual void Undo() override
Definition: TableUndo.cxx:229
virtual ~OTableEditorTypeSelUndoAct() override
Definition: TableUndo.cxx:128
virtual void Undo() override
Definition: TableUndo.cxx:132
virtual void Redo() override
Definition: TableUndo.cxx:146
OTableEditorTypeSelUndoAct(OTableEditorCtrl *pOwner, sal_Int32 nRowID, sal_uInt16 nColumn, TOTypeInfoSP _pOldType)
Definition: TableUndo.cxx:120
virtual ~OTableEditorUndoAct() override
Definition: TableUndo.cxx:116
VclPtr< OTableEditorCtrl > pTabEdCtrl
Definition: TableUndo.hxx:50
OTableEditorUndoAct(OTableEditorCtrl *pOwner, TranslateId pCommentID)
Definition: TableUndo.cxx:110
sal_Int32 nIndex
SvLinkSource * pOwner
sal_uInt16 nPos
#define SFX_ENDOFSELECTION
std::shared_ptr< OTypeInfo > TOTypeInfoSP
Definition: TypeInfo.hxx:99
int i
long Long
Reference< XController > xController
the controller of the sub component. Must not be <NULL>