File indexing completed on 2024-05-19 05:42:24

0001 // ct_lvtqtc_undo_add_entity_common.cpp                               -*-C++-*-
0002 
0003 /*
0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk>
0005 // SPDX-License-Identifier: Apache-2.0
0006 //
0007 // Licensed under the Apache License, Version 2.0 (the "License");
0008 // you may not use this file except in compliance with the License.
0009 // You may obtain a copy of the License at
0010 //
0011 //     http://www.apache.org/licenses/LICENSE-2.0
0012 //
0013 // Unless required by applicable law or agreed to in writing, software
0014 // distributed under the License is distributed on an "AS IS" BASIS,
0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0016 // See the License for the specific language governing permissions and
0017 // limitations under the License.
0018 */
0019 
0020 #include <ct_lvtqtc_undo_add_entity_common.h>
0021 
0022 namespace Codethink::lvtqtc {
0023 
0024 UndoAddEntityBase::UndoAddEntityBase(GraphicsScene *scene,
0025                                      const QPointF& pos,
0026                                      const std::string& name,
0027                                      const std::string& qualifiedName,
0028                                      const std::string& parentQualifiedName,
0029                                      QtcUtil::UndoActionType undoActionType,
0030                                      lvtldr::NodeStorage& storage):
0031     m_scene(scene->observer_from_this()),
0032     m_undoActionType(undoActionType),
0033     m_addInfo{pos, name, qualifiedName, parentQualifiedName, std::string{}},
0034     m_removeInfo{nullptr},
0035     m_storage(storage)
0036 {
0037 }
0038 
0039 void UndoAddEntityBase::undo()
0040 {
0041     switch (m_undoActionType) {
0042     case QtcUtil::UndoActionType::e_Add:
0043         removeEntity();
0044         break;
0045     case QtcUtil::UndoActionType::e_Remove:
0046         addEntity();
0047         break;
0048     }
0049 }
0050 
0051 void UndoAddEntityBase::redo()
0052 {
0053     IGNORE_FIRST_CALL
0054 
0055     switch (m_undoActionType) {
0056     case QtcUtil::UndoActionType::e_Add:
0057         addEntity();
0058         break;
0059     case QtcUtil::UndoActionType::e_Remove:
0060         removeEntity();
0061         break;
0062     }
0063 }
0064 } // namespace Codethink::lvtqtc