LibreOffice Module chart2 (master) 1
UndoActions.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 "UndoActions.hxx"
21#include "ChartModelClone.hxx"
22#include <ChartModel.hxx>
23
24#include <com/sun/star/lang/DisposedException.hpp>
25
26#include <svx/svdundo.hxx>
27
28#include <memory>
29#include <utility>
30
31using namespace ::com::sun::star;
32
33namespace chart::impl
34{
35 using ::com::sun::star::lang::DisposedException;
36
37UndoElement::UndoElement( OUString i_actionString, rtl::Reference<::chart::ChartModel> i_documentModel, std::shared_ptr< ChartModelClone > i_modelClone )
38 :m_sActionString(std::move( i_actionString ))
39 ,m_xDocumentModel(std::move( i_documentModel ))
40 ,m_pModelClone(std::move( i_modelClone ))
41{
42}
43
45{
46}
47
48void UndoElement::disposing(std::unique_lock<std::mutex>&)
49{
50 if ( m_pModelClone )
51 m_pModelClone->dispose();
52 m_pModelClone.reset();
53 m_xDocumentModel.clear();
54}
55
56OUString SAL_CALL UndoElement::getTitle()
57{
58 return m_sActionString;
59}
60
62{
63 // get a snapshot of the current state of our model
64 auto pNewClone = std::make_shared<ChartModelClone>( m_xDocumentModel, m_pModelClone->getFacet() );
65 // apply the previous snapshot to our model
66 m_pModelClone->applyToModel( m_xDocumentModel );
67 // remember the new snapshot, for the next toggle
68 m_pModelClone = pNewClone;
69}
70
71void SAL_CALL UndoElement::undo( )
72{
74}
75
76void SAL_CALL UndoElement::redo( )
77{
79}
80
81// = ShapeUndoElement
82
83ShapeUndoElement::ShapeUndoElement( std::unique_ptr<SdrUndoAction> xSdrUndoAction )
84 :m_xAction( std::move(xSdrUndoAction) )
85{
86}
87
89{
90}
91
92OUString SAL_CALL ShapeUndoElement::getTitle()
93{
94 if ( !m_xAction )
95 throw DisposedException( OUString(), *this );
96 return m_xAction->GetComment();
97}
98
99void SAL_CALL ShapeUndoElement::undo( )
100{
101 if ( !m_xAction )
102 throw DisposedException( OUString(), *this );
103 m_xAction->Undo();
104}
105
107{
108 if ( !m_xAction )
109 throw DisposedException( OUString(), *this );
110 m_xAction->Redo();
111}
112
113} // namespace chart::impl
114
115/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL redo() override
std::unique_ptr< SdrUndoAction > m_xAction
Definition: UndoActions.hxx:95
virtual ~ShapeUndoElement() override
Definition: UndoActions.cxx:88
ShapeUndoElement(std::unique_ptr< SdrUndoAction > xSdrUndoAction)
Definition: UndoActions.cxx:83
virtual void SAL_CALL undo() override
Definition: UndoActions.cxx:99
virtual OUString SAL_CALL getTitle() override
Definition: UndoActions.cxx:92
virtual ~UndoElement() override
Definition: UndoActions.cxx:44
virtual void SAL_CALL undo() override
Definition: UndoActions.cxx:71
UndoElement(OUString i_actionString, rtl::Reference<::chart::ChartModel > i_documentModel, std::shared_ptr< ChartModelClone > i_modelClone)
creates a new undo action
Definition: UndoActions.cxx:37
rtl::Reference<::chart::ChartModel > m_xDocumentModel
Definition: UndoActions.hxx:78
std::shared_ptr< ChartModelClone > m_pModelClone
Definition: UndoActions.hxx:79
virtual void disposing(std::unique_lock< std::mutex > &) override
Definition: UndoActions.cxx:48
virtual OUString SAL_CALL getTitle() override
Definition: UndoActions.cxx:56
virtual void SAL_CALL redo() override
Definition: UndoActions.cxx:76
Base class for all Chart Accessibility objects except the root node (see AccessibleChartView)